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 키로 적합한 객체 일 수 있습니다.
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를 사용하여 더 나은 성능을 제공합니다. 말 그대로 수백 배 더 빠릅니다.