/** Adds dependency heads. */
  private void addDEPHeads(DEPTree dTree, CTTree cTree) {
    int currId, headId, size = dTree.size(), rootCount = 0;
    DEPNode dNode;
    CTNode cNode;
    String label;

    for (currId = 1; currId < size; currId++) {
      dNode = dTree.get(currId);
      cNode = cTree.getToken(currId - 1);
      headId = cNode.c2d.d_head.getTokenId() + 1;

      if (currId == headId) // root
      {
        dNode.setHead(dTree.get(DEPLib.ROOT_ID), DEPLibKr.DEP_ROOT);
        rootCount++;
      } else {
        label = cNode.c2d.s_label;
        dNode.setHead(dTree.get(headId), label);
      }
    }

    if (rootCount > 1) System.err.println("Warning: multiple roots exist");
  }
Esempio n. 2
0
  @Test
  public void testCTTree() {
    String filename = "src/test/resources/constituent/CTReaderTest.parse";
    CTReader reader = new CTReader(UTInput.createBufferedFileReader(filename));

    CTTree tree = reader.nextTree();
    assertEquals("I pray that I will be allowed *-1 to come to you .", tree.toForms());
    assertEquals("I_pray_that_I_will_be_allowed_to_come_to_you_.", tree.toForms(false, "_"));

    CTNode root = tree.getRoot();
    assertEquals(tree.toString(), root.toString());

    CTNode node = tree.getNode(0, 1);
    assertEquals(true, node.isTag("NP", "-SBJ"));
    node = tree.getTerminal(7);
    assertEquals("*-1", node.form);
    node = tree.getToken(7);
    assertEquals("to", node.form);

    node = node.getParent();
    assertEquals("[8, 9, 10, 11]", node.getSubTerminalIdList().toString());

    tree.setPBLocs();
    assertEquals("3:1", tree.getCoIndexedAntecedent(1).getPBLoc().toString());
    assertEquals("[(-NONE- *-1)]", tree.getCoIndexedEmptyCategories(1).toString());

    assertEquals(true, tree.isRange(0, 3));
    assertEquals(false, tree.isRange(0, 4));
  }
 @Override
 public DEPTree toDEPTree(CTTree cTree) {
   setHeads(cTree.getRoot());
   return getDEPTree(cTree);
 }