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 เพื่อประสิทธิภาพที่ดีขึ้น มันเร็วขึ้นหลายร้อยเท่า