我试图提取使用的规则,如对文本下面提及的那些,其已经POS标签如何编写提取名词短语的高效代码?
1)NNP短语 - > NNP( - >表示随后) 2)NNP - > CC - > NNP 3)VP - > NP etc ..
我已经用这种方式编写代码了,有人能告诉我怎样才能以更好的方式做。
List<String> nounPhrases = new ArrayList<String>();
for (List<HasWord> sentence : documentPreprocessor) {
//System.out.println(sentence.toString());
System.out.println(Sentence.listToString(sentence, false));
List<TaggedWord> tSentence = tagger.tagSentence(sentence);
String lastTag = null, lastWord = null;
for (TaggedWord taggedWord : tSentence) {
if (lastTag != null && taggedWord.tag().equalsIgnoreCase("NNP") && lastTag.equalsIgnoreCase("NNP")) {
nounPhrases.add(taggedWord.word() + " " + lastWord);
//System.out.println(taggedWord.word() + " " + lastWord);
}
lastTag = taggedWord.tag();
lastWord = taggedWord.word();
}
}
在上面的代码,我已经做只为NNP其次NNP提取,我怎么能概括它,这样我可以添加其他的规则了。我知道有这样的库可用来做这件事,但是想要手动做到这一点。
是的。正如我之前所说的,想要手动执行而不使用这些库进行短语检测。 –
是的,对不起。我没有阅读完整的问题。一旦我尝试手动做这个。我创建了一个可以识别葡萄牙语NP的有限状态机。与使用机器学习相比,结果并不好。 – wcolen