【问题标题】:Extracting multi word named entities using CoreNLP使用 CoreNLP 提取多词命名实体
【发布时间】:2014-04-12 11:27:22
【问题描述】:

我正在使用 CoreNLP 进行命名实体提取,但遇到了一些问题。 问题是,每当命名实体由多个标记组成时,例如“Han Solo”,注释器不会将“Han Solo”作为单个命名实体返回,而是作为两个独立实体返回,“Han”“Solo” .

是否可以将命名实体作为一个令牌获取?我知道我可以将 CRFClassifier 与classifyWithInlineXML 一起使用到这种程度,但我的解决方案要求我使用CoreNLP,因为我还需要知道单词编号。

以下是我目前的代码:

    Properties props = new Properties();
    props.put("annotators", "tokenize,ssplit,pos,lemma,ner,parse");
    props.setProperty("ner.model", "edu/stanford/nlp/models/ner/english.conll.4class.distsim.crf.ser.gz");
    pipeline = new StanfordCoreNLP(props);
    Annotation document = new Annotation(text);
    pipeline.annotate(document);
    List<CoreMap> sentences = document.get(SentencesAnnotation.class);
    for (CoreMap sentence : sentences) {
        for (CoreLabel token : sentence.get(TokensAnnotation.class)) {
                System.out.println(token.get(NamedEntityTagAnnotation.class));
        }
    }

帮助我欧比旺克诺比。你是我唯一的希望。

【问题讨论】:

    标签: stanford-nlp named-entity-recognition


    【解决方案1】:
    PrintWriter writer = null;
     try {  
         String inputLine = "Several possible plans emerged from the talks, held at the Federal Reserve Bank of New York" + " and led by Timothy R. Geithner, the president of the New York Fed, and Treasury Secretary Henry M. Paulson Jr.";
    
         String serializedClassifier = "english.all.3class.distsim.crf.ser.gz";
         AbstractSequenceClassifier<CoreLabel> classifier = CRFClassifier.getClassifierNoExceptions(serializedClassifier);
    
         writer = new PrintWriter(new File("output.xml"));
         writer.println("<Sentences>");
         writer.flush();
         String output ="<Sentence>"+classifier.classifyToString(inputLine, "xml", true)+"</Sentence>"; 
         writer.println(output);
         writer.flush();
         writer.println("</Sentences>");
         writer.flush(); 
     } catch (FileNotFoundException ex) {
         ex.printStackTrace();
     } finally {
         writer.close();
     }
    

    我能够想出这个解决方案。我正在将输出写入 XML 文件“output.xml”。从获得的输出中,您可以将 xml 中具有“PERSON”或“ORGANIZATION”或“LOCATION”属性的连续节点合并为一个实体。这种格式默认产生字数。

    这是 xml 输出的快照。

    <wi num="11" entity="ORGANIZATION">Federal</wi>
    <wi num="12" entity="ORGANIZATION">Reserve</wi>
    <wi num="13" entity="ORGANIZATION">Bank</wi>
    <wi num="14" entity="ORGANIZATION">of</wi>
    <wi num="15" entity="ORGANIZATION">New</wi>
    <wi num="16" entity="ORGANIZATION">Yorkand</wi>
    

    从上面的输出你可以看到连续的单词被识别为“ORGANIZATION”。所以这些词可以组合成一个实体。

    【讨论】:

    • 呸。傻我。很好的解决方案!
    【解决方案2】:

    我使用一个 temp 变量来保存前一个 ner 标签并检查当前 ner 标签是否等于 temp,它将两个单词组合在一起。迭代通过将 temp 分配给当前的 ner 标签来进行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多