以下虽然不理想,但那应该让你开始。 它使用nltk首先将文本拆分为单词,然后生成包含所有单词词干的集合来过滤停止词。 这是对示例文本和示例查询都完成的。 在
如果两个集合的交叉点包含查询中的所有单词,则将其视为匹配。 在import nltk上
fromn ltk.stemimportporterstemmer
fromn ltk.tokenizeimportword _ tokenize
from nltk.corpus import stopwords
stop _ words=stop words.words (English ) )。
ps=PorterStemmer ()
defget_word_set(text ) :
returnset(PS.stem(word ) forword in word _ tokenize (text ) if word not in stop_words ) ) )。
text1=' thearterialhighbloodpressuremayengagetheprognosisforsurvivalofthepatientasaresultofcomplications.tenstatenerswion eatment(processing ).his(her,Its ) report (relationship ) efficiency/effectsunwantedisimpoort medicineoffirstintintention
text2=' thearterialhighbloodpressuremayengagetheforsurvivalofthepatientasaresultofcomplications.tenstatenerswithinthefrethinthefrethefrepomathinthed processing ).his ) her,Its ) report ) relationship ) efficiency/effectsunwantedisimportant.d disc medicineoffirstintintintention
query=' engagetheprognosisforsurvival '
set_query=get_word_set(query )
for text in [text1,text2]:
set_text=get_word_set(text )
intersection=set_query set_text
打印' query : ',set_query
打印测试3360 ',set_text
打印解释: ',解释
打印' match : ',len(intersection )==len(set_query ) )。
打印
脚本提供两个文本。 一个通过,另一个不通过。 它生成以下输出以指示正在做什么。
^{pr2}$