Implementing a general contextual search - how to approach it?

I am currently developing desktop software, and I always wanted to implement an intuitive search function. For example, I need to write an algorithm that analyzes a search query, for example, "next Monday between 2 and 3 o’clock" or "anytime after 2 on Friday", or even "how can I use". Thus, the context may be completely different, but ask the same thing as me.

Should I tokenize the request (which I am doing so far), or should I treat the string as a complete template and compare with some library?

I'm not sure if SO is the right place for this, so if necessary, point me in the right direction. Basically, I just would like to give advice on the approach I should take.

Thanks.

+4
source share
2 answers

Temporary extraction (i.e., extracting date and time objects from free-form text). How? can give you some pointers.

"Entity extract" is the process of extracting human-recognized objects (names, places, dates, etc.) from unstructured text. This article is specifically about temporary entities, but reading “extracting entities” in general is a good place to start.

Extraction of entities must be done in each language, so expect difficulties when you try to internationalize your product to other locales. For Google Calendar, we spent a lot of time retrieving a temporary object and a relationship of repeating expressions in a human-readable form ("every last Friday of November"), and each of the 40 locales we work with has its own quirks.

+1
source

If you plan on using a predefined grammar, you should consider using a state machine. For example, the Ragel State Machine Compiler , which allows you to use simple regular expressions to define a state machine and allows you to generate the actual source code for different target languages.

Here is a simple parser that I wrote to get all table names from an SQL select query. You could do something like this ( https://gist.github.com/1524986 ).

0
source

Source: https://habr.com/ru/post/1387708/


All Articles