Ali*_*989 8 java nlp phrase stanford-nlp
我将使用Stanford Corenlp 2013找到短语标题.我看到了这个帖子.
但是,答案对我来说并不清楚,我无法添加任何评论来继续该线程.所以,我很抱歉重复.
我现在所拥有的是一个句子的解析树(使用Stanford Corenlp)(我也尝试过由Stanford Corenlp创建的CONLL格式).而我所需要的只是名词短语的头部.
我不知道如何使用依赖关系和解析树来提取名词短语的头部.我所知道的是,如果我有nsubj (x, y),y是主题的头.如果我有dobj(x,y),y是直接对象的头部.我有iobj(x,y),y是间接对象的头.
但是,我不确定这种方式是否是查找所有词组头的正确方法.如果是,我应该添加哪些规则来获取所有名词短语?
也许,值得一提的是,我需要在java代码中使用名词短语的头部.
由于我不能评论Chaitanya给出的答案,所以在这里补充更多答案.
斯坦福CoreNLP套件实现了Collins头部探测器启发式和语义头部探测器启发式的形式
您只需要实例化三个中的一个并执行以下操作.
Tree tree = sentence.get(TreeCoreAnnotations.TreeAnnotation.class);
headFinder.determineHead(tree).pennPrint(out);
Run Code Online (Sandbox Code Playgroud)
您可以遍历树的节点并在需要的地方确定头部单词.
PS:我的答案基于截至20140104年发布的StanfordCoreNLP套件.
这是一个简单的dfs,可以让你为一个句子中的所有名词短语提取头部单词
public static void dfs(Tree node, Tree parent, HeadFinder headFinder) {
if (node == null || node.isLeaf()) {
return;
}
//if node is a NP - Get the terminal nodes to get the words in the NP
if(node.value().equals("NP") ) {
System.out.println(" Noun Phrase is ");
List<Tree> leaves = node.getLeaves();
for(Tree leaf : leaves) {
System.out.print(leaf.toString()+" ");
}
System.out.println();
System.out.println(" Head string is ");
System.out.println(node.headTerminal(headFinder, parent));
}
for(Tree child : node.children()) {
dfs(child, node, headFinder);
}
}
Run Code Online (Sandbox Code Playgroud)