Python中的布尔文本搜索
eldar的Python项目详细描述
使用Eldar的布尔文本搜索
入门
这些说明将为您提供一个项目的副本,并在本地计算机上运行,以便进行开发和测试。在
先决条件
- 单解码
安装
可以通过键入以下命令安装该方法:
pip install unidecode -U
pip install eldar
基本用法
^{pr2}$您还可以使用它来屏蔽Pandas数据帧:
fromeldarimportbuild_queryimportpandasaspd# build dataframedf=pd.DataFrame(["Gandalf is a fictional character in Tolkien's The Lord of the Rings","Frodo is the main character in The Lord of the Rings","Ian McKellen interpreted Gandalf in Peter Jackson's movies","Elijah Wood was cast as Frodo Baggins in Jackson's adaptation","The Lord of the Rings is an epic fantasy novel by J. R. R. Tolkien"],columns=['content'])# build query objecteldar=build_query('("gandalf" OR "frodo") AND NOT ("movie" OR "adaptation")')# eldar's call returns True if the text matches the query.# You can filter a dataframe using pandas mask syntax:df=df[df.content.apply(eldar)]print(df)
参数
在查询生成器中可以调整三个参数。 默认情况下:
Query(...,ignore_case=True,ignore_accent=True,match_word=True)
让查询为query = '"movie"'
:
- 如果
ignore_case
为真,则文档“Movie”和“Movie”将匹配。如果为False,则只匹配“movie”。在 - 如果
ignore_accent
为真,则将匹配文档“mövie”。在 - 如果
match_word
为真,则文档将被标记化,并且查询项必须完全匹配。如果设置为False,将匹配文档“movies”和“movie”。将此选项设置为True可能会减慢查询速度。在
作者
陈内保先生
- 项目
标签: