2013-05-03 30 views
1

我对NLTK非常陌生,正在尝试做某些事情。在NLTK中查找两个文本语料库之间的常见词

在两个文本主体之间找到常用词的最佳方式是什么?基本上,我有一个长文本文件说text1,另一个说text2。我想找到使用NLTK出现在这两个文件中的常见词汇。

有没有直接的方法来做到这一点?最好的方法是什么?

谢谢!

+0

通常,语料库是指文本的集合。你正在处理两个文本,而不是两个集合。 – Spaceghost 2013-05-03 16:17:02

+0

噢,好的。谢谢! – Apoorva 2013-05-05 08:32:12

回答

0

在我看来,除非你需要做一些特别的东西与问候语言处理,你不需要NLTK:

words1 = "This is a simple test of set intersection".lower().split() 
words2 = "Intersection of sets is easy using Python".lower().split() 

intersection = set(words1) & set(words2) 

>>> set(['of', 'is', 'intersection']) 
+1

太好了。我也是python的新手。这有帮助。感谢西蒙! – Apoorva 2013-05-05 08:31:40

相关问题