Examples of indexSpans()


Examples of edu.stanford.nlp.trees.Tree.indexSpans()

    for(CoreMap sent: corpus.get(SentencesAnnotation.class)){
      List<CoreLabel> tokens = sent.get(TokensAnnotation.class);
      assert(tokens != null);
      Tree tree = sent.get(TreeAnnotation.class);
      if (MachineReadingProperties.forceGenerationOfIndexSpans) {
        tree.indexSpans(0)
      }
      assert(tree != null);
      if(sent.get(EntityMentionsAnnotation.class) != null){
        for(EntityMention e: sent.get(EntityMentionsAnnotation.class)){
          reader.assignSyntacticHead(e, tree, tokens, true);
View Full Code Here

Examples of edu.stanford.nlp.trees.Tree.indexSpans()

  }

  protected void findHead(CoreMap s, List<Mention> mentions) {
    Tree tree = s.get(TreeCoreAnnotations.TreeAnnotation.class);
    List<CoreLabel> sent = s.get(CoreAnnotations.TokensAnnotation.class);
    tree.indexSpans(0);
    for (Mention m : mentions){
      Tree head = findSyntacticHead(m, tree, sent);
      m.headIndex = ((CoreLabel) head.label()).get(CoreAnnotations.IndexAnnotation.class)-1;
      m.headWord = sent.get(m.headIndex);
      m.headString = m.headWord.get(CoreAnnotations.TextAnnotation.class).toLowerCase(Locale.ENGLISH);
View Full Code Here

Examples of edu.stanford.nlp.trees.Tree.indexSpans()

      // are VP and S ones
      ParserConstraint constraint = new ParserConstraint(ADDED_WORDS, extentTokens.size() - 1, Pattern.compile(".*"));
      List<ParserConstraint> constraints = Collections.singletonList(constraint);
      Tree tree = parse(extentTokens, constraints);
      convertToCoreLabels(tree)// now unnecessary, as parser uses CoreLabels?
      tree.indexSpans(m.startIndex - ADDED_WORDS)// remember it has ADDED_WORDS extra words at the beginning
      Tree subtree = findPartialSpan(tree, m.startIndex);
      // There was a possible problem that with a crazy parse, extentHead could be one of the added words, not a real word!
      // Now we make sure in findPartialSpan that it can't be before the real start, and in safeHead, we disallow something
      // passed the right end (that is, just that final period).
      Tree extentHead = safeHead(subtree, endIdx);
View Full Code Here

Examples of edu.stanford.nlp.trees.Tree.indexSpans()

      } else {
        setUnknownLabels(collapsedUnary, mainLabel);
      }

      Trees.convertToCoreLabels(collapsedUnary);
      collapsedUnary.indexSpans();

      for (Pair<Integer, Integer> span : spanToLabels.keySet()) {
        setSpanLabel(collapsedUnary, span, spanToLabels.get(span));
      }
View Full Code Here

Examples of edu.stanford.nlp.trees.Tree.indexSpans()

 
  public void annotate(Annotation document) {
    for (CoreMap sentence: document.get(CoreAnnotations.SentencesAnnotation.class)) {
      final List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class);
      Tree tree = sentence.get(TreeCoreAnnotations.TreeAnnotation.class);
      tree.indexSpans(0);
     
      // add a tree to each timex annotation
      for (CoreMap timexAnn: sentence.get(TimeAnnotations.TimexAnnotations.class)) {
        Tree subtree;
        final int timexBegin = beginOffset(timexAnn);
View Full Code Here

Examples of edu.stanford.nlp.trees.Tree.indexSpans()

      //
      for (Mention mention: mentions) {
        mention.contextParseTree = tree;
        mention.sentenceWords = sentence;
        mention.originalSpan = new ArrayList<CoreLabel>(mention.sentenceWords.subList(mention.startIndex, mention.endIndex));
        if(!((CoreLabel)tree.label()).has(CoreAnnotations.BeginIndexAnnotation.class)) tree.indexSpans(0);
        if(mention.headWord==null) {
          Tree headTree = ((RuleBasedCorefMentionFinder) mentionFinder).findSyntacticHead(mention, tree, sentence);
          mention.headWord = (CoreLabel)headTree.label();
          mention.headIndex = mention.headWord.get(CoreAnnotations.IndexAnnotation.class) - 1;
        }
View Full Code Here

Examples of edu.stanford.nlp.trees.Tree.indexSpans()

      convertToCoreLabels(tree);

      // store the tree spans, if not present already
      CoreLabel l = (CoreLabel) tree.label();
      if(forceGenerationOfIndexSpans || (! l.containsKey(CoreAnnotations.BeginIndexAnnotation.class) && ! l.containsKey(CoreAnnotations.EndIndexAnnotation.class))){
        tree.indexSpans(0);
        logger.fine("Index spans were generated.");
      } else {
        logger.fine("Index spans were NOT generated.");
      }
      logger.fine("Parse tree using CoreLabel:\n" + tree.pennString());
View Full Code Here

Examples of edu.stanford.nlp.trees.Tree.indexSpans()

    ParserConstraint constraint = new ParserConstraint(ADDED_WORDS, extentTokens.size() - 1, ".*");
    List<ParserConstraint> constraints = Collections.singletonList(constraint);
    Tree tree = parse(extentTokens, constraints);
    logger.fine("No exact match found. Local parse:\n" + tree.pennString());
    convertToCoreLabels(tree);
    tree.indexSpans(ent.getExtentTokenStart() - ADDED_WORDS)// remember it has ADDED_WORDS extra words at the beginning
    Tree subtree = findPartialSpan(tree, ent.getExtentTokenStart());
    Tree extentHead = safeHead(subtree);
    logger.fine("Head is: " + extentHead);
    assert(extentHead != null);
    // extentHead is a child in the local extent parse tree. we need to find the corresponding node in the main tree
View Full Code Here

Examples of edu.stanford.nlp.trees.Tree.indexSpans()

      extentTokens.add(tokens.get(i));

    Tree tree = parse(extentTokens);
    logger.fine("No exact match found. Local parse:\n" + tree.pennString());
    convertToCoreLabels(tree);
    tree.indexSpans(ent.getExtentTokenStart());
    Tree extentHead = safeHead(tree);
    assert (extentHead != null);
    // extentHead is a child in the local extent parse tree. we need to find the
    // corresponding node in the main tree
    CoreLabel l = (CoreLabel) extentHead.label();
View Full Code Here

Examples of edu.stanford.nlp.trees.Tree.indexSpans()

* @author John Bauer
*/
public class RuleBasedCorefMentionFinderTest extends TestCase {
  public void testFindTreeWithSmallestSpan() {
    Tree tree = Tree.valueOf("(ROOT (S (NP (PRP$ My) (NN dog)) (ADVP (RB also)) (VP (VBZ likes) (S (VP (VBG eating) (NP (NN sausage))))) (. .)))");
    tree.indexSpans();
    Tree subtree = RuleBasedCorefMentionFinder.findTreeWithSmallestSpan(tree, 0, 2);
    assertEquals("(NP (PRP$ My) (NN dog))", subtree.toString());

    subtree = RuleBasedCorefMentionFinder.findTreeWithSmallestSpan(tree, 0, 1);
    assertEquals("My", subtree.toString());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.