请帮我一下。你知道吗
到目前为止,我已经完成了步骤1(参见下面的代码)。效果很好:
stopwords=['what','hello','and','at','is','am','i']
search_list=['where is north and northern side',
'ask in the community at western environmental',
'my name is alan and i am coming from london southeast']
dictionary = {'n': ['north','northern'],
's': ['south','southern'],
'e': ['east','eastern'],
'w': ['west','western'],
'env': ['environ.','enviornment','environmental']}
result = [' '.join(w for w in place.split() if w.lower() not in stopwords)
for place in search_list]
print (result)
我需要以下理想的最终输出来完成步骤2。为了得到我想要的最终输出,我应该在上面的一行代码中更改/包括什么?任何其他替代方法也欢迎。你知道吗
['where n n side', 'ask in the community w env', 'my name alan coming from london s']
您必须“反转”词典,因为查找是相反的:
现在更换方便了:
再次拆分字符串(您可以保持单词列表的原样以避免拆分),并替换为默认值作为单词,以防不匹配:
或同时删除和替换停止词:
在这两种情况下,结果:
相关问题 更多 >
编程相关推荐