java如何从解析树创建子树的排列?
我试着像这样把句子分开;例如:
"I ate here a week ago and found most dishes average at best and too expensive but the waitress was really nice."
应该成为
"I ate here a week ago and found most dishes average at best."
"I ate here a week ago and found most dishes too expensive."
"I ate here a week ago and the waitress was really nice."
基本上,我从Stanfort解析器中获得了所需的所有信息
props.put("annotators", "tokenize, ssplit, pos, lemma, ner, parse")
但问题是我在API方面遇到了麻烦。看下面的句子,我基本上需要的是某种置换算法,取决于条件,比如“子树是否通过amod
关系连接;如果是,我们可以按照
".. average at best and too expensive .."
有人能帮我完成吗?我所有的尝试都以“好吧,我现在如何获得^{Scala
(首选)和/或Java
可以
我最近的尝试如下所示:
for(iw <- allWords) {
println(iw.get(classOf[TextAnnotation]))
val out = semanticGraph.getOutEdgesSorted(iw)
for(edge <- out) {
if(edge.getRelation.getShortName.startsWith("amod")) {
val tree = edge.getTarget.get(classOf[TreeAnnotation])
val lbl = new CoreLabel()
val treeGraphNodes = new TreeGraphNode(lbl, tree.getChildrenAsList)
val relNodes = edge.getRelation.getRelatedNodes(treeGraphNodes, treeGraphNodes, null)
println("")
}
}
}
这里我试图从amod
关系中获取所有受影响的节点,如上图所示。它应该返回相关的节点,但是因为tree
总是null
,所以恐怕不能这样做
共 (0) 个答案