by ori_b · 13y ago · 0 comments
The problem is that there are an huge number of possible solutions for any given input. For example, you could always give a trivial solution: ".*"
For something like that to work, you'd need a large dictionary of common patterns, and then you'd want to compare against the dictionary to see if it matches a sequence of common patterns.
I can't imagine that sort of thing being too useful.
(Finding the actual minimal regex, instead of just a reasonable guess, might be a computationally tough problem. I guess it's in coNP and might be in NP, too. An algorithm in P would be nice to find.)
Update: Finding any separating regex would be in P. A separating finite automaton is easy to find, and then you just convert that into a regex. Now, how do you find the minimal regex?
preferably python but a link to theory is useful too.
I found my code and it wasn't exactly it (it just enumerated all regexes in order of size), but here's a crude solution now: https://github.com/darius/sketchbook/blob/master/regex/find_...
(In defense of my memory, I had written superoptimizers for other things.)
[1] http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.16.6...
You can rank candidates afterwards. However, it's a good solution for finding words that are closed to a mistyped word.
I have successfully used such techniques in a spellchecker and various search engines.
https://www.lri.fr/~hansen/proceedings/2012/GECCO/companion/...