コード例 #1
0
 /**
  * Create a mock node, to be added to the dependency tree but which is not part of the original
  * sentence.
  *
  * @param toCopy The CoreLabel to copy from initially.
  * @param word The new word to add.
  * @param POS The new part of speech to add.
  * @return A CoreLabel copying most fields from toCopy, but with a new word and POS tag (as well
  *     as a new index).
  */
 @SuppressWarnings("UnusedDeclaration")
 private CoreLabel mockNode(CoreLabel toCopy, String word, String POS) {
   CoreLabel mock = new CoreLabel(toCopy);
   mock.setWord(word);
   mock.setLemma(word);
   mock.setValue(word);
   mock.setNER("O");
   mock.setTag(POS);
   mock.setIndex(sentenceLength + 5);
   return mock;
 }
コード例 #2
0
  /**
   * Converts the tree labels to CoreLabels. We need this because we store additional info in the
   * CoreLabel, like token span.
   *
   * @param tree
   */
  public static void convertToCoreLabels(Tree tree) {
    Label l = tree.label();
    if (!(l instanceof CoreLabel)) {
      CoreLabel cl = new CoreLabel();
      cl.setValue(l.value());
      tree.setLabel(cl);
    }

    for (Tree kid : tree.children()) {
      convertToCoreLabels(kid);
    }
  }
コード例 #3
0
  /**
   * Sets the labels on the tree (except the leaves) to be the integer value of the sentiment
   * prediction. Makes it easy to print out with Tree.toString()
   */
  static void setSentimentLabels(Tree tree) {
    if (tree.isLeaf()) {
      return;
    }

    for (Tree child : tree.children()) {
      setSentimentLabels(child);
    }

    Label label = tree.label();
    if (!(label instanceof CoreLabel)) {
      throw new IllegalArgumentException("Required a tree with CoreLabels");
    }
    CoreLabel cl = (CoreLabel) label;
    cl.setValue(Integer.toString(RNNCoreAnnotations.getPredictedClass(tree)));
  }
コード例 #4
0
ファイル: UnaryTransition.java プロジェクト: cyloss/CoreNLP
 static Tree createNode(Tree top, String label, Tree... children) {
   CoreLabel headLabel = (CoreLabel) top.label();
   CoreLabel production = new CoreLabel();
   production.setValue(label);
   production.set(
       TreeCoreAnnotations.HeadWordLabelAnnotation.class,
       headLabel.get(TreeCoreAnnotations.HeadWordLabelAnnotation.class));
   production.set(
       TreeCoreAnnotations.HeadTagLabelAnnotation.class,
       headLabel.get(TreeCoreAnnotations.HeadTagLabelAnnotation.class));
   Tree newTop = new LabeledScoredTreeNode(production);
   for (Tree child : children) {
     newTop.addChild(child);
   }
   return newTop;
 }