Package edu.stanford.nlp.ling

Examples of edu.stanford.nlp.ling.Label


   * value.
   *
   * @param hf The headfinding algorithm to use
   */
  public void percolateHeads(HeadFinder hf) {
    Label cwt = label();
    if (isLeaf()) {
      if (cwt instanceof HasWord) {
        HasWord w = (HasWord) cwt;
        if (w.word() == null) {
          w.setWord(cwt.value());
        }
      }
    } else {
      Tree[] kids = children();
      for (int i = 0; i < kids.length; i++) {
        kids[i].percolateHeads(hf);
      }
      Tree head = hf.determineHead(this);
      if (head != null) {
        Label headCwt = head.label();
        String headTag = null;
        if (headCwt instanceof HasTag) {
          headTag = ((HasTag) headCwt).tag();
        }
        if (headTag == null && head.isLeaf()) {
          // below us is a leaf
          headTag = cwt.value();
        }
        String headWord = null;
        if (headCwt instanceof HasWord) {
          headWord = ((HasWord) headCwt).word();
        }
        if (headWord == null && head.isLeaf()) {
          // below us is a leaf
          // this might be useful despite case for leaf above in
          // case the leaf label type doesn't support word()
          headWord = headCwt.value();
        }
        if (cwt instanceof HasWord) {
          ((HasWord) cwt).setWord(headWord);
        }
        if (cwt instanceof HasTag) {
View Full Code Here


    for (Tree node : subTrees()) {
      if (node.isLeaf() || node.children().length < 2) {
        continue;
      }
      // every child with a different head (or repeated) is an argument
      Label l = node.label();
      Word w = null;
      if (hf != null) {
        Tree hwt = node.headTerminal(hf);
        if (hwt != null) {
          w = new Word(hwt.label());
        }
      } else {
        if (l instanceof HasWord) {
          w = new Word(((HasWord) l).word());
        }
      }
      Tree[] kids = node.children();
      boolean seenHead = false;
      for (int cNum = 0; cNum < kids.length; cNum++) {
        Tree child = kids[cNum];
        Label dl = child.label();
        Word dw = null;
        if (hf != null) {
          Tree dwt = child.headTerminal(hf);
          if (dwt != null) {
            dw = new Word(dwt.label());
View Full Code Here

    for (Tree node : this) {
      if (node.isLeaf() || node.children().length < 2) {
        continue;
      }
      // every child with a different head (or repeated) is an argument
      Label l = node.label();
      TaggedWord tw = null;
      if (l instanceof HasWord && l instanceof HasTag) {
        tw = new TaggedWord(((HasWord) l).word(), ((HasTag) l).tag());
      }

      boolean seenHead = false;
      for (Tree child : node.children()) {
        Label dl = child.label();
        TaggedWord dtw = null;
        if (dl instanceof HasWord && dl instanceof HasTag) {
          dtw = new TaggedWord(((HasWord) dl).word(), ((HasTag) dl).tag());
        }
        if (tw != null && tw.word() != null && dtw != null && tw.word().equals(dtw.word()) && tw.tag().equals(dtw.tag()) && !seenHead) {
View Full Code Here

    for (Tree node : this) {
      if (node.isLeaf() || node.children().length < 2) {
        continue;
      }
      // every child with a different head (or repeated) is an argument
      Label l = node.label();
      TaggedWord w = null;
      if (hf != null) {
        Tree hwt = node.headPreTerminal(hf);
        if (hwt != null) {
          w = new TaggedWord(hwt.children()[0].label(), hwt.label());
        }
      } else {
        if (l instanceof HasWord && l instanceof HasTag) {
          w = new TaggedWord(((HasWord) l).word(), ((HasTag) l).tag());
        }
      }

      boolean seenHead = false;
      for (Tree child : node.children()) {
        Label dl = child.label();
        TaggedWord dw = null;
        if (hf != null) {
          Tree dwt = child.headPreTerminal(hf);
          if (dwt != null) {
            dw = new TaggedWord(dwt.children()[0].label(), dwt.label());
View Full Code Here

   *           and value(), the last two of which are identical).
   */
  public Set<Dependency<Label, Label, Object>> mapDependencies(Filter<Dependency<Label, Label, Object>> f, HeadFinder hf, String rootName) {
    Set<Dependency<Label, Label, Object>> deps = mapDependencies(f, hf);
    if(rootName != null) {
      Label hl = headTerminal(hf).label();
      CyclicCoreLabel rl = new CyclicCoreLabel();
      rl.set(WordAnnotation.class, rootName);
      rl.set(IndexAnnotation.class, 0);
      deps.add(new NamedDependency(rl, hl, rootName));
    }
View Full Code Here

   * @return a <code>List</code> of the data in the tree's leaves.
   */
  @SuppressWarnings("unchecked")
  public <X extends HasWord> Sentence<X> yield(Sentence<X> y) {
    if (isLeaf()) {
      Label lab = label();
      // cdm: this is new hacked in stuff in Mar 2007 so we can now have a
      // well-typed version of a Sentence, whose objects MUST implement HasWord
      if (lab instanceof HasWord) {
        y.add((X) lab);
      } else {
View Full Code Here

   *           tree structure
   * @return A Tree that is a deep copy of the tree structure and
   *         Labels of the original tree.
   */
  public Tree deeperCopy(TreeFactory tf, LabelFactory lf) {
    Label label = lf.newLabel(label());
    if (isLeaf()) {
      return tf.newLeaf(label);
    }
    Tree[] kids = children();
    List<Tree> newKids = new ArrayList<Tree>(kids.length);
View Full Code Here

  }

  // --- composition methods to implement Label interface

  public String value() {
    Label lab = label();
    if (lab == null) {
      return null;
    }
    return lab.value();
  }
View Full Code Here

    return lab.value();
  }


  public void setValue(String value) {
    Label lab = label();
    if (lab != null) {
      lab.setValue(value);
    }
  }
View Full Code Here

    }
  }


  public void setFromString(String labelStr) {
    Label lab = label();
    if (lab != null) {
      lab.setFromString(labelStr);
    }
  }
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.