【问题标题】:How to cluster Named Entity using StanfordNER using python如何使用 Python 使用 StanfordNER 对命名实体进行集群
【发布时间】:2018-11-17 02:37:21
【问题描述】:

Stanford NER 为其提供 NER jars 来检测 POS 标签和 NER。但是在尝试解析时,我遇到了其中一个句子的问题。句子如下:

Joseph E. Seagram & Sons, INC said on Thursday that it is merging its two United States based wine companies

下面是我的代码

st = StanfordNERTagger('./stanford- ner/classifiers/english.all.3class.distsim.crf.ser.gz',
                       './stanford-ner/stanford-ner.jar',
                       encoding='utf-8')
ne_in_sent = []
with open("./CCAT/2551newsML.txt") as fd:
    lines = fd.readlines()
    for line in lines:
        print(line)
        tokenized_text = word_tokenize(line)
        classified_text = st.tag(tokenized_text)
        ne_tree = stanfordNE2tree(classified_text)
        for subtree in ne_tree:
            # If subtree is a noun chunk, i.e. NE != "O"
            if type(subtree) == Tree:
                ne_label = subtree.label()
                ne_string = " ".join([token for token, pos in subtree.leaves()])
                ne_in_sent.append((ne_string, ne_label))
                print(ne_in_sent)

当我解析它时,我得到以下实体作为组织。 (Joseph E. Seagram & Sons,组织)和(Inc,组织)

也适用于文件中的一些其他文本,例如

TransCo has a very big plane. Transco is moving south.

它因资本化而区分组织,因此我得到 2 个实体(TransCo,组织)和(Transco,组织)。

是否可以将它们转换为一个实体?

【问题讨论】:

    标签: python nlp nltk stanford-nlp named-entity-recognition


    【解决方案1】:

    使用余弦相似度检查器检查相似度

    参考:Calculate cosine similarity given 2 sentence strings

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-19
      • 1970-01-01
      • 1970-01-01
      • 2015-01-27
      • 1970-01-01
      • 2013-05-02
      • 1970-01-01
      • 2013-07-06
      相关资源
      最近更新 更多