[英]Use variables as keywords for functions with pre-defined keywords (Python)
[英]Python package to find pre-defined keywords/tags in a file / url / string
是否有任何python軟件包可以采用關鍵字/標簽列表,並將其與給定的字符串/文件/ URL相匹配?
具體地使用詞干和/或某些其他同義詞匹配方式。
即我預先保存的關鍵字:
Ski, Bike, Climb
我的文字:
Skiing in the mountains is great
應該被標記為Ski
Skiing and mountain biking is fun
應該被標記為Ski
And Bike
如果我在將Bike
映射到MTB
某個地方有同義詞文件
MTB is a great way to spend the day
應該被標記為Bike
我不知道有任何軟件包可以做到這一點,但是實際上,使用純Python來說這非常簡單。 使用re(regex)標准軟件包。 就像是
import re
key_words =['ski','bike','climb']
input = "Skiing and mountain biking is fun"
input_words = input.split()#split on space
[word.lower() for word in input_words]
input_tags =[]
for word in input_words:
for key in key_words:
if re.search(key,word):
input_tags.append(key)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.