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來更好地性能。實際上,它更快了數百次。