【问题标题】:How to identify PP-tags/NP-tags/VP-tags in openNLP chunker?如何在 openNLP 分块器中识别 PP-tags/NP-tags/VP-tags?
【发布时间】:2013-06-06 19:39:24
【问题描述】:

我想计算文本中 pp/np/vp 的数量,但我不知道如何在 openNLP chunker 中识别 PP-tags/NP-tags/VP-tags?我已经尝试过这段代码,但它不起作用。

ChunkerModel cModel = new ChunkerModel(modelIn);
ChunkerME chunkerME = new ChunkerME(cModel);  
String result[] = chunkerME.chunk(whitespaceTokenizerLine, tags); 
HashMap<Integer,String> phraseLablesMap = new HashMap<Integer, String>();  
Integer wordCount = 1;  
Integer phLableCount = 0;  
for (String phLable : result) {  
    if(phLable.equals("O")) phLable += "-Punctuation"; //The phLable of the last word is OP  
    if(phLable.split("-")[0].equals("B")) phLableCount++;  
    phLable = phLable.split("-")[1] + phLableCount;  
    System.out.println(wordCount + ":" + phLable);  
    phraseLablesMap.put(wordCount, phLable);  
    wordCount++;  
}

Integer noPP=0;
Integer TotalPP=0;
for (String PPattach: result) {
    if (PPattach.equals("PP")) {
        for (int i=0;i<result.length;i++)
            TotalPP = noPP +1;
        }
    }
System.out.println(TotalPP); 

输出:

1:NP1
2:VP2
3:NP3
4:NP3
5:VP4
6:PP5
7:NP6
8:NP6
9:NP6
10:NP6
11:PP7
12:NP8
13:NP8
14:NP8
15:PP9
16:NP10
17:NP10
18:PP11
19:NP12
20:NP12
21:VP13
22:VP13
23:NP14
24:NP14
25:PP15
26:NP16
27:NP16
28:Punctuation16
0

【问题讨论】:

    标签: java opennlp chunked


    【解决方案1】:

    最好的方法是使用 span 对象,它们有一个 getType() 方法返回块类型。

    看这篇文章

    grouping all Named entities in a Document

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-09
      • 1970-01-01
      相关资源
      最近更新 更多