edu.stanford.nlp.ling.Label Java Examples

The following examples show how to use edu.stanford.nlp.ling.Label. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ParserAnnotatorUtils.java    From Heracles with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Set the tags of the original tokens and the leaves if they
 * aren't already set.
 */
public static void setMissingTags(CoreMap sentence, Tree tree) {
  List<TaggedWord> taggedWords = null;
  List<Label> leaves = null;
  List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class);
  for (int i = 0, size = tokens.size(); i < size; ++i) {
    CoreLabel token = tokens.get(i);
    if (token.tag() == null) {
      if (taggedWords == null) {
        taggedWords = tree.taggedYield();
      }
      if (leaves == null) {
        leaves = tree.yield();
      }
      token.setTag(taggedWords.get(i).tag());
      Label leaf = leaves.get(i);
      if (leaf instanceof HasTag) {
        ((HasTag) leaf).setTag(taggedWords.get(i).tag());
      }
    }
  }
}
 
Example #2
Source File: ClauseTypeLabeller.java    From phrasal with GNU General Public License v3.0 6 votes vote down vote up
private int getClauseStart(List<Label> posTags, List<Label> gloss) {
  Label npLabel = null;
  int start = -1;
  /* Find the first NP child. */
  for (Tree child : tree.getChildrenAsList()) {
    if (child.value().equals("NP")) {
      npLabel = child.getLeaves().get(0).label();
      break;
    }
  }
  /* Get its index in the clause. */
  if (npLabel != null) {
    int i = 0;
    for (Label word : gloss) {
      if (word.equals(npLabel)) {
        start = i;
        break;
      }
      i++;
    }
  }
  return start;
}
 
Example #3
Source File: ClauseTypeLabeller.java    From phrasal with GNU General Public License v3.0 6 votes vote down vote up
private int getClauseEnd(List<Label> posTags, List<Label> gloss) {
  int end = gloss.size() - 1;
  for (int i = 0; i < gloss.size(); i++) {
    if (gloss.get(i).value().startsWith("--C-") || gloss.get(i).value().equals(":")) {
      if (!finiteVerbIndices.isEmpty() && finiteVerbIndices.get(0) < i) {
        if (i > 0 && (!isWord(gloss.get(i - 1).value()) || posTags.get(i - 1).value().equals("IN")))
          i--;
      
        end = i - 1;
        break;
      }
    }
  }
  if (end == gloss.size() - 1) {
    for (int i = gloss.size() - 1; i > 0; i--) {
      if (isWord(gloss.get(i).value()))
        break;
      end--;
    }
  }
  return end;
}
 
Example #4
Source File: DependencyBnBPreorderer.java    From phrasal with GNU General Public License v3.0 6 votes vote down vote up
private static int computeCrossingLinks(List<Label> sourceWords, SymmetricalWordAlignment alignment) {
  
  int sourceLen = sourceWords.size();
  
  int score = 0;
  
  for (int i = 0; i < sourceLen; i++) {
    IndexedWord iw1 = (IndexedWord) sourceWords.get(i);
    Set<Integer> aAlignment = new HashSet<Integer>();
    aAlignment.addAll(alignment.f2e(iw1.index() - 1));
    for (int j = i + 1; j < sourceLen; j++) {
      IndexedWord iw2 = (IndexedWord) sourceWords.get(j);
      Set<Integer> bAlignment = new HashSet<Integer>();
      bAlignment.addAll(alignment.f2e(iw2.index() - 1));
      for (int k : aAlignment) {
        for (int l : bAlignment) {
          if (k > l)
            score++;
        }
      }
    }
  }
  
  return score;
  
}
 
Example #5
Source File: SourceTextAnalyzer.java    From phrasal with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Syntactic complexity as defined by Lin (1996).
 * 
 * @param tree
 * @return
 */
private static int complexityOf(Tree tree) {
  tree.indexLeaves();
  tree.percolateHeads(new CollinsHeadFinder());
  tree.percolateHeadIndices();
  
  Set<Dependency<Label,Label,Object>> deps = tree.dependencies();
  int complexity = 0;
  for (Dependency<Label,Label,Object> dep : deps) {
    if (!(dep instanceof UnnamedConcreteDependency)) {
      throw new RuntimeException("Cannot measure syntactic complexity.");
    }
    UnnamedConcreteDependency uDep = (UnnamedConcreteDependency) dep;
    int headIndex = uDep.getGovernorIndex();
    int depIndex = uDep.getDependentIndex();
    complexity += Math.abs(headIndex - depIndex);
  }
  
  return complexity;
}
 
Example #6
Source File: ClauseTypeLabeller.java    From phrasal with GNU General Public License v3.0 5 votes vote down vote up
private boolean isFiniteVerbParticle(List<Label> posTags, List<Label> gloss, int i) {
  String pos = posTags.get(i).value();
  String word = gloss.get(i).value();
  return (i > 0
          && pos.equals("RP") //is particle?
          && !isNot(word) //not a negative particle
          && isFiniteVerb(posTags.get(i-1).value(), gloss.get(i-1).value()));
}
 
Example #7
Source File: ClauseTypeLabeller.java    From phrasal with GNU General Public License v3.0 5 votes vote down vote up
private void extractVerbIndices(List<Label> posTags, List<Label> gloss) {
  boolean hasFoundVerbComplex = false;
  for (int i = 0; i < posTags.size(); i++) {
    Label pos = posTags.get(i);
    String word = gloss.get(i).value();
    /* Extract finite verb indices. */
    if (isFiniteVerb (pos.value(), word)
        || isFiniteVerbParticle(posTags, gloss, i)
        || isFiniteGerund(posTags, gloss, i)) {
     
      finiteVerbIndices.add(i);
      hasFoundVerbComplex = true;
      
    } else if (pos.value().startsWith("VB") /* All other verbs are main verbs. */
               || (pos.value().equals("RP") /* Particles that are attached to main verbs. */
                   && !isNot(word) )) {
      
      /* Don't add gerund verbs without preceding finite or main verb. */
      if (!pos.value().equals("VBG") || (i > 0 &&  (posTags.get(i-1).value().startsWith("VB")))) {
        mainVerbIndices.add(i);
        hasFoundVerbComplex = true;
      }
    } else if ((pos.value().equals("RP") || pos.value().equals("RB")) && isNot(word)) {
      /* Set negative particle index. */
      negativeParticlePos = i;
      
    /* Only extract one verb complex per clause. */
    } else if (hasFoundVerbComplex 
               && !type.equals("S-INT") 
               && !pos.value().equals("RB")) {
      break;
    }
  }
  
  
  if (finiteVerbIndices.isEmpty()) {
    finiteVerbIndices.addAll(mainVerbIndices);
    mainVerbIndices.clear();
  }
}
 
Example #8
Source File: ClauseTypeLabeller.java    From phrasal with GNU General Public License v3.0 5 votes vote down vote up
public String toString(){
  List<Label> gloss = tree.yield();
  StringBuilder sb = new StringBuilder();
  sb.append("[").append(this.type).append("] ");
  for (int i = 0; i < gloss.size(); i++) {
    sb.append(gloss.get(i).toString());
    sb.append(" ");
  }
  sb.append("\n");
  return sb.toString();
}
 
Example #9
Source File: DependencyBnBPreorderer.java    From phrasal with GNU General Public License v3.0 5 votes vote down vote up
FeatureNode(Tree node, IndexedWord hw) {
  
  List<Label> yield = node.yield();
  
  this.word = (IndexedWord) node.label();
  this.hw = hw;
  this.lm = (IndexedWord) yield.get(0);
  this.rm = (IndexedWord) yield.get(yield.size() - 1);
  this.dst = hw.index() - this.word.index();
}
 
Example #10
Source File: DependencyTree.java    From UDepLambda with Apache License 2.0 4 votes vote down vote up
public DependencyTree(Label label) {
  super(label);
}
 
Example #11
Source File: ClauseTypeLabeller.java    From phrasal with GNU General Public License v3.0 4 votes vote down vote up
private boolean isFiniteGerund(List<Label> posTags, List<Label> gloss, int i) {
  String pos = posTags.get(i).value();
  return (i > 0
          && pos.equals("VBG") 
          && isFiniteVerb(posTags.get(i-1).value(), gloss.get(i-1).value()));
}