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
]この場合、return ['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キーとして適したオブジェクトにすることができます。
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を使用してパフォーマンスを向上させます。文字通り数百倍速いです。