有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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可以

enter image description here

enter image description here


我最近的尝试如下所示:

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) 个答案