Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

boolean text search in python [closed]

i'm looking for an existing module(s) which enabled me to write basic boolean queries for matching and searching texts, WITHOUT writing my own parser etc.

for example,

president AND (ronald OR (george NOT bush))

would match TRUE against "the president ronald ragen" "the president ronald ragen and bush" "max bush was not a president"

but False on "george bush was a president" "i don't know how to spell ronald ragen"

(So far i found Booleano, which seems a bit overkill, but could do the task. However their group is inactive, and i couldn't figure out from the documentation what to do.)

thanks

Edit: the exact style or grammer is not critical. my aim is to provide non-tech users with the ability to search certain texts a bit beyond keyword search.

like image 236
Berry Tsakala Avatar asked Feb 11 '10 17:02

Berry Tsakala


1 Answers

DISCLAIMER: I am the creator of the package presented below.

For the people who might come to this page: I built a package to do just that (still in beta).

pip install eldar

Your query would be translated in the following code:

from eldar import Query

eldar = Query('"president" AND ("ronald" OR ("george" AND NOT "bush"))')

print(eldar("President Bush"))
# >>> False
print(eldar("President George"))
# >>> True

You can use it on some pandas dataframe as well, check the git page for more info: https://github.com/kerighan/eldar

like image 63
Kerighan Avatar answered Sep 19 '22 18:09

Kerighan