2017-03-01 124 views
1

我想將具有相同命名實體註釋的連續記號(比如,STANFORD UNIVERSITY,其中記號「stanford」和「university」具有NE「ORGANIZATION」)合併爲一個記號,以便我只擁有「斯坦福大學」與NE「組織」。有沒有辦法做到這一點與令牌正則表達式?有沒有一種方法可以將TokenRegex中的多個標記重新標記爲一個標記?

所以,這確實是一個問題兩個部分:

1)你會如何寫令牌與同NER一個完整序列的格局?

2)如何編寫將捕獲的令牌合併爲一個動作(基本上,與Split功能相反)?

謝謝!

回答

1

你想使用entitymentions註釋器,它會爲你做這件事,並從文本中提取完整的實體。

示例代碼:

package edu.stanford.nlp.examples; 

import edu.stanford.nlp.pipeline.*; 
import edu.stanford.nlp.ling.*; 
import edu.stanford.nlp.util.*; 

import java.util.*; 

public class EntityMentionsExample { 

    public static void main(String[] args) { 
    Annotation document = 
     new Annotation("John Smith visted Los Angeles on Tuesday."); 
    Properties props = new Properties(); 
    props.setProperty("annotators", "tokenize,ssplit,pos,lemma,ner,entitymentions"); 
    StanfordCoreNLP pipeline = new StanfordCoreNLP(props); 
    pipeline.annotate(document); 

    for (CoreMap entityMention : document.get(CoreAnnotations.MentionsAnnotation.class)) { 
     System.out.println(entityMention); 
    } 
    } 
} 
相關問題