Package edu.stanford.nlp.ling

Examples of edu.stanford.nlp.ling.Label


      return Double.class;
    }
  }

  public static double getPredictionError(Tree tree) {
    Label label = tree.label();
    if (!(label instanceof CoreLabel)) {
      throw new IllegalArgumentException("CoreLabels required to get the attached prediction error");
    }
    return ((CoreLabel) label).get(PredictionError.class);
  }
View Full Code Here


    }
    return ((CoreLabel) label).get(PredictionError.class);
  }

  public static void setPredictionError(Tree tree, double error) {
    Label label = tree.label();
    if (!(label instanceof CoreLabel)) {
      throw new IllegalArgumentException("CoreLabels required to set the attached prediction error");
    }
    ((CoreLabel) label).set(PredictionError.class, error);
  }
View Full Code Here

    // scan data
    String word = tw.word();
    String subString = model.getSignature(word, loc);

    Label tag = new Tag(tw.tag());
    if ( ! c.containsKey(tag)) {
      c.put(tag, new ClassicCounter<String>());
    }
    c.get(tag).incrementCount(subString, weight);
View Full Code Here

  @Override
  public float score(IntTaggedWord itw, String word) {
    // Label tagL = itw.tagLabel();
    // String tag = tagL.value();
    String tag = itw.tagString(tagIndex);
    Label tagL = new Tag(tag);

    float logProb;

    if (VERBOSE) EncodingPrintWriter.out.println("Scoring unknown word |" + word + "| with tag " + tag, encoding);
View Full Code Here

  public float score(IntTaggedWord itw, String word) {
    float logProb;

    // Label tag = itw.tagLabel();
    String tagStr = itw.tagString(tagIndex);
    Label tag = new Tag(tagStr);

    // testing
    //EncodingPrintWriter.out.println("Scoring unknown word " + word + " with tag " + tag,encoding);
    // end testing
View Full Code Here

      fail("testDeeperCopy failed to construct tree");
    }
    Tree t2 = t1.deepCopy();
    assertEquals(t1, t2);               // make sure trees are equal
    assertTrue(t1 != t2);               // make sure trees are not ==
    Label l1 = t1.firstChild().firstChild().firstChild().label();
    Label l2 = t2.firstChild().firstChild().firstChild().label();
    assertEquals(l1, l2);               // make sure labels are equal (redundant)
    assertTrue(l1 != l2);               // make sure labels are not ==
  }
View Full Code Here

          cat = cat + "^U";
        }
      } // otherwise, leave the tags alone!

      // Label label = new CategoryWordTag(cat, word, cat);
      Label label = t.label().labelFactory().newLabel(t.label());
      label.setValue(cat);
      if(label instanceof HasCategory)
        ((HasCategory) label).setCategory(cat);
      if(label instanceof HasWord)
        ((HasWord) label).setWord(word);
      if(label instanceof HasTag)
        ((HasTag) label).setTag(cat);


      t.setLabel(label);
      t.setChild(0, childResult)// just in case word is changed
      if (trainOptions.noTagSplit) {
        return t;
      } else {
        // language-specific transforms
        return tlpParams.transformTree(t, root);
      }
    } // end isPreTerminal()

    // handle phrasal categories
    Tree[] kids = t.children();
    for (int childNum = 0; childNum < kids.length; childNum++) {
      Tree child = kids[childNum];
      Tree childResult = transformTreeHelper(child, root); // recursive call
      t.setChild(childNum, childResult);
    }

    Tree headChild = hf.determineHead(t);
    if(headChild == null || headChild.label() == null) {
      throw new RuntimeException("TreeAnnotator: null head found for tree [suggesting incomplete/wrong HeadFinder]:\n" + t);
    }

    Label headLabel = headChild.label();

    if( ! (headLabel instanceof HasWord))
      throw new RuntimeException("TreeAnnotator: Head label lacks a Word annotation!");
    if( ! (headLabel instanceof HasTag))
      throw new RuntimeException("TreeAnnotator: Head label lacks a Tag annotation!");

    String word = ((HasWord) headLabel).word();
    String tag = ((HasTag) headLabel).tag();

    // String baseTag = tlpParams.treebankLanguagePack().basicCategory(tag);
    String baseCat = tlpParams.treebankLanguagePack().basicCategory(cat);

    /* Sister annotation. Potential problem: if multiple sisters are
     * strong indicators for a single category's expansions.  This
     * happens concretely in the Chinese Treebank when NP (object)
     * has left sisters VV and AS.  Could lead to too much
     * sparseness.  The ideal solution would be to give the
     * splitting list an ordering, and take only the highest (~most
     * informative/reliable) sister annotation.
     */
    if (trainOptions.sisterAnnotate && !trainOptions.smoothing && baseParentStr.length() > 0) {
      List<String> leftSis = listBasicCategories(SisterAnnotationStats.leftSisterLabels(t, parent));
      List<String> rightSis = listBasicCategories(SisterAnnotationStats.rightSisterLabels(t, parent));

      List<String> leftAnn = new ArrayList<String>();
      List<String> rightAnn = new ArrayList<String>();

      for (String s : leftSis) {
        //s = baseCat+"=l="+tlpParams.treebankLanguagePack().basicCategory(s);
        leftAnn.add(baseCat + "=l=" + tlpParams.treebankLanguagePack().basicCategory(s));
        //System.out.println("left-annotated test string " + s);
      }
      for (String s : rightSis) {
        //s = baseCat+"=r="+tlpParams.treebankLanguagePack().basicCategory(s);
        rightAnn.add(baseCat + "=r=" + tlpParams.treebankLanguagePack().basicCategory(s));
      }
      for (Iterator<String> j = rightAnn.iterator(); j.hasNext();) {
        //System.out.println("new rightsis " + (String)j.next()); //debugging
      }
      for (String annCat : trainOptions.sisterSplitters) {
        //System.out.println("annotated test string " + annCat);
        if (leftAnn.contains(annCat) || rightAnn.contains(annCat)) {
          cat = cat + annCat.replaceAll("^" + baseCat, "");
          break;
        }
      }
    }

    if (trainOptions.PA && !trainOptions.smoothing && baseParentStr.length() > 0) {
      String cat2 = baseCat + "^" + baseParentStr;
      if (!trainOptions.selectiveSplit || trainOptions.splitters.contains(cat2)) {
        cat = cat + "^" + baseParentStr;
      }
    }
    if (trainOptions.gPA && !trainOptions.smoothing && grandParentStr.length() > 0) {
      if (trainOptions.selectiveSplit) {
        String cat2 = baseCat + "^" + baseParentStr + "~" + baseGrandParentStr;
        if (cat.contains("^") && trainOptions.splitters.contains(cat2)) {
          cat = cat + "~" + baseGrandParentStr;
        }
      } else {
        cat = cat + "~" + baseGrandParentStr;
      }
    }
    if (trainOptions.markUnary > 0) {
      if (trainOptions.markUnary == 1 && kids.length == 1 && kids[0].depth() >= 2) {
        cat = cat + "-U";
      } else if (trainOptions.markUnary == 2 && parent != null && parent.numChildren() == 1 && t.depth() >= 2) {
        cat = cat + "-u";
      }
    }
    if (trainOptions.rightRec && rightRec(t, baseCat)) {
      cat = cat + "-R";
    }
    if (trainOptions.leftRec && leftRec(t, baseCat)) {
      cat = cat + "-L";
    }
    if (trainOptions.splitPrePreT && t.isPrePreTerminal()) {
      cat = cat + "-PPT";
    }

//    Label label = new CategoryWordTag(cat, word, tag);
    Label label = t.label().labelFactory().newLabel(t.label());
    label.setValue(cat);
    if(label instanceof HasCategory)
      ((HasCategory) label).setCategory(cat);
    if(label instanceof HasWord)
      ((HasWord) label).setWord(word);
    if(label instanceof HasTag)
View Full Code Here

      }
      if (maxMultiplicity > 1) {
        maxStrahler++;  // this is the one case where it grows
      }
      cat = cat + '~' + maxStrahler;
      Label label = t.label().labelFactory().newLabel(t.label());
      label.setValue(cat);
      t.setLabel(label);
      return maxStrahler;
    }
  }
View Full Code Here

      if (t.isLeaf()) {
        return t.treeFactory().newLeaf(t.label());
      }
      Tree[] children = t.children();
      if (children.length > 1 || t.isPreTerminal() || t.label().value().startsWith("ROOT")) {
        Label label = t.label();
        Tree[] transformedChildren = new Tree[children.length];
        for (int childIndex = 0; childIndex < children.length; childIndex++) {
          Tree child = children[childIndex];
          transformedChildren[childIndex] = transformTree(child);
        }
        return t.treeFactory().newTreeNode(label, Arrays.asList(transformedChildren));
      }
      Tree tree = t;
      List<String> conjoinedList = new ArrayList<String>();
      while (tree.children().length == 1 && !tree.isPrePreTerminal()) {
        String nodeString = tree.label().value();
        if (!nodeString.startsWith("@")) {
          conjoinedList.add(nodeString);
        }
        tree = tree.children()[0];
      }
      String nodeString = tree.label().value();
      if (!nodeString.startsWith("@")) {
        conjoinedList.add(nodeString);
      }
      String conjoinedLabels;
      if (conjoinedList.size() > 1) {
        StringBuilder conjoinedLabelsBuilder = new StringBuilder();
        for (String s : conjoinedList) {
          conjoinedLabelsBuilder.append("&");
          conjoinedLabelsBuilder.append(s);
        }
        conjoinedLabels = conjoinedLabelsBuilder.toString();
      } else if (conjoinedList.size() == 1) {
        conjoinedLabels = conjoinedList.iterator().next();
      } else {
        return transformTree(t.children()[0]);
      }
      children = tree.children();
      Label label = t.label().labelFactory().newLabel(conjoinedLabels);
      Tree[] transformedChildren = new Tree[children.length];
      for (int childIndex = 0; childIndex < children.length; childIndex++) {
        Tree child = children[childIndex];
        transformedChildren[childIndex] = transformTree(child);
      }
View Full Code Here

      Tree[] transformedChildren = new Tree[children.length];
      for (int childIndex = 0; childIndex < children.length; childIndex++) {
        Tree child = children[childIndex];
        transformedChildren[childIndex] = transformTree(child);
      }
      Label label = t.label();
      if (!label.value().startsWith("&")) {
        return t.treeFactory().newTreeNode(label, Arrays.asList(transformedChildren));
      }
      String[] nodeStrings = label.value().split("&");
      int i = nodeStrings.length - 1;
      label = t.label().labelFactory().newLabel(nodeStrings[i]);
      Tree result = t.treeFactory().newTreeNode(label, Arrays.asList(transformedChildren));
      while (i > 1) {
        i--;
View Full Code Here

TOP

Related Classes of edu.stanford.nlp.ling.Label

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.