gifts_py
1.0.0
搜索具有查询具有共同特征的元素。
query = [ 'A' , 'B' ]
elements = [
[ 'N' , 'A' , 'M' ], # common features: 'A'
[ 'C' , 'B' , 'A' ], # common features: 'A', 'B'
[ 'X' , 'Y' ] # no common features
]在这种情况下,返回['C', 'B', 'A']和['N', 'A', 'M']的搜索以该特定顺序。
查找包含查询单词的文档。
from gifts import SmoothFts
fts = SmoothFts ()
fts . add ([ "wait" , "mister" , "postman" ],
doc_id = "doc1" )
fts . add ([ "please" , "mister" , "postman" , "look" , "and" , "see" ],
doc_id = "doc2" )
fts . add ([ "oh" , "yes" , "wait" , "a" , "minute" , "mister" , "postman" ],
doc_id = "doc3" )
# print IDs of documents in which at least one word of the query occurs,
# starting with the most relevant matches
for doc_id in fts . search ([ 'postman' , 'wait' ]):
print ( doc_id )在上面的示例中,单词实际上是字符串。但是它们可以是适合dict Keys的任何对象。
from gifts import SmoothFts
fts = SmoothFts ()
fts . add ([ 3 , 1 , 4 , 1 , 5 , 9 , 2 ], doc_id = "doc1" )
fts . add ([ 6 , 5 , 3 , 5 ], doc_id = "doc2" )
fts . add ([ 8 , 9 , 7 , 9 , 3 , 2 ], doc_id = "doc3" )
for doc_id in fts . search ([ 5 , 3 , 7 ]):
print ( doc_id )在排名结果时,算法会考虑::
from gifts import SmoothFts它使用对数TF-IDF来加权单词和余弦相似性来评分比赛。
from gifts import SimpleFts简约方法:称重,乘以,比较。该对象明显比SmoothFts更快。
pip3 install git+https://github.com/rtmigo/gifts_py#egg=gifts install_requires = [
"gifts@ git+https://github.com/rtmigo/gifts_py"
]Skifts软件包进行了相同的搜索,但是使用Scikit-Learn和Numpy来更好地性能。实际上,它更快了数百次。