我的问题如下。我有一个很长的网址列表,例如:
www.foo.com/davidbobmike1joe
www.foo.com/mikejoe2bobkarl
www.foo.com/joemikebob
www.foo.com/bobjoe
我需要将列表中的所有条目(url)相互比较,在这些url的子域中提取关键字(在本例中:david、joe、bob、mike、karl),并按频率排序。我一直在读一些关于nltk之类的库。然而,这里的问题是没有空格来独立标记每个单词。关于如何完成这项工作有什么建议吗?在
Tags:
概述
您可以使用此代码提取姓名,并传递[david,bob,etc.]的列表:
Is there an easy way generate a probable list of words from an unspaced sentence in python?
然后使用
collections.Counter
得到频率。在代码
结果
^{pr2}$局限性
如果你拒绝使用字典,你的算法将需要大量的计算。除此之外,不可能区分只出现一次的关键字(例如:“karl”)和糟糕的序列(例如:“e2bo”)。我的解决方案将是一个最大的努力,只有当你的网址列表包含关键字多次。在
基本思想
我假设一个单词是一系列频繁出现的字符,至少有3个字符。这就阻止了字母“o”成为最流行的单词。在
基本思路如下。在
在代码中
输出
^{pr2}$对读者的一些挑战
相关问题 更多 >
编程相关推荐