python - 查找文本中单词列表中单词的出现次数

标签 python nlp

Possible Duplicate:
Check if multiple strings exist in another string

假设我有一个允许使用的单词/短语的列表:

'Stack'
'Overflow'
'Stack Overflow'
'Stack Exchange'
'Exchange'

以及要解析的以下文本:

'Hello, and welcome to Stack Overflow. 
 Here are some words which should match: Stack, Exchange.'

我想获取在允许列表中找到的单词列表:

  • “堆栈溢出”
  • “堆栈”
  • “交换”

实现这一结果的最佳方法是什么?

我将使用的允许列表可能至少有一千个单词/短语。

最佳答案

将单词放入列表中并在使用后

def intersect(x, y):
    return list(set(x) & set(y))
word_list_text=string.split(text)
words_found={}
words_found=intersect(word_list_text, words)

关于python - 查找文本中单词列表中单词的出现次数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14087336/

相关文章:

python - NLTK:conllstr2tree 无法正常工作(Python3)

java - 如何在文本中定义人名(Java)

python - 感知器分类

python - 如何返回一个由Python中另一个列表中提取的元素组成的列表?

python - 如何在 Scikit 中使用交叉验证进行多输出回归?

python - 在 Python 中将终端置于前端

python - 如何下载sklearn的数据集? - Python

用于对关键字进行分类的 Python 包

Python:从命名空间中提取变量

python - NLP:检查检测到的句子是否是完整的句子