从网址中提取命名实体

我正在处理一个自然语言处理问题(使用Python 2.7),目的是从新闻报道文本中提取报道地点。为此,我使用了Clavin API,这个API的效果还不错。

然而,我注意到报道地点的名称通常也会出现在报道本身的URL中,我希望找到一种方法从域名中提取这个实体,以通过在请求中提供额外的命名实体来提高Clavin的准确性。

在理想的情况下,我希望能够输入这样的内容:www.britainnews.net

并返回这样的输出,或类似的输出:[www,britain,news,net]

当然,我可以使用.split()功能来分离wwwnet这些不重要的标记,但是对于如何分割中间的短语,我还没有找到合适的方法,除非进行大量的词典查找。

我并不是要求有人帮我解决这个问题或为我编写代码——但这是对理想的NLP库(如果存在的话)的公开建议征集,或者关于如何解决这个问题的任何想法。


回答:

检查 – 单词分割任务 来自 Norvig 的工作。

from __future__ import divisionfrom collections import Counterimport re, nltkWORDS = nltk.corpus.reuters.words()COUNTS = Counter(WORDS)def pdist(counter):    "Make a probability distribution, given evidence from a Counter."    N = sum(counter.values())    return lambda x: counter[x]/NP = pdist(COUNTS)def Pwords(words):    "Probability of words, assuming each word is independent of others."    return product(P(w) for w in words)def product(nums):    "Multiply the numbers together.  (Like `sum`, but with multiplication.)"    result = 1    for x in nums:        result *= x    return resultdef splits(text, start=0, L=20):    "Return a list of all (first, rest) pairs; start <= len(first) <= L."    return [(text[:i], text[i:])             for i in range(start, min(len(text), L)+1)]def segment(text):    "Return a list of words that is the most probable segmentation of text."    if not text:         return []    else:        candidates = ([first] + segment(rest)                       for (first, rest) in splits(text, 1))        return max(candidates, key=Pwords)print segment('britainnews')     # ['britain', 'news']

更多示例请见: 单词分割任务

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注