首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何识别openNLP chunker中的PP-tags/NP-tags/VP-tags?

如何识别openNLP chunker中的PP-tags/NP-tags/VP-tags?
EN

Stack Overflow用户
提问于 2013-06-11 11:04:28
回答 1查看 383关注 0票数 1

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

代码语言:javascript
复制
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); 

输出:

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2014-02-05 08:00:45

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

请看这篇文章

grouping all Named entities in a Document

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17035913

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档