예제 #1
0
 private static Map<String, String> generatePOSTags(Question q) {
   ParseTree parse = new ParseTree();
   DEPTree tree = parse.process(q);
   // TODO this is horribly wrong, the same label CAN have different pos
   // tags
   Map<String, String> label2pos = Maps.newHashMap();
   Stack<DEPNode> stack = new Stack<DEPNode>();
   stack.push(tree.getFirstRoot());
   while (!stack.isEmpty()) {
     DEPNode tmp = stack.pop();
     label2pos.put(tmp.form, tmp.pos);
     for (DEPNode child : tmp.getDependentNodeList()) {
       stack.push(child);
     }
   }
   return label2pos;
 }
예제 #2
0
  /** 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");
  }