2017-07-17 25 views
0

我有非常大的数字和字母数字集的集合,我想用python 2.7在其中找到常见的单词/短语。跨大型数据集的短语/多字和计数匹配

示例数据,与我的真实数据没有任何关系,但是它很好地表示它。

'this is a test of the hosting', 
'test is a test', 
'we have more tests to run before we can trust it', 
'if it true, can trust it', 
'tom is on time for ounce', 
'what do you mean tom is out sick again' 

以下类型匹配的我要寻找

'is' x 5 
'test' x 3 
'is a test' x 2 
'is a' x2 
'we' x2 
'trust it' x 2 
'tom' x 2 
..etc.. 

有一个常见的lib或我需要写一个?我可以用蛮力做到这一点,但在我的一些大型文件中这可能需要几年时间。我'假设'这是一个普遍的问题,一些聪明的饼干找到了解决方案。希望这不是一个旅行推销员。

+0

你在寻找unigram,bigram,trigram等数字吗? – Gingerbread

+0

我不得不承认,我不知道你的意思是unigram,bigram,trigram ...但是快速查找我想到了单词级别bigram/trigram/etc ..匹配。任何匹配集我认为4字匹配将是我想要处理的最大集。 – JustBroken

回答

0

我认为你正在寻找unigram,bigram,trigram的数量。你可以使用Python中的NLTK库来做你想做的事。

此外,请检查此link了。

+0

只要我看到你的unigram,bigram,trigram并搜索了'python unigram bigram trigram',我就发现了很多。谢谢! – JustBroken

+0

@JustBroken:任何时候:)很多时候,只是一个小小的提示会让你得到你想要的! – Gingerbread