gpt4 book ai didi

java - 如何在openNLP chunker中识别PP-tags/NP-tags/VP-tags?

转载 作者:行者123 更新时间:2023-12-01 04:38:02 27 4
gpt4 key购买 nike

我想计算文本中 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

最佳答案

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

看这篇文章

grouping all Named entities in a Document

关于java - 如何在openNLP chunker中识别PP-tags/NP-tags/VP-tags?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17035913/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com