Package org.apache.uima.ruta.textruler.core

Examples of org.apache.uima.ruta.textruler.core.TextRulerAnnotation


          // example...
          int leftDistance = 0;
          TextRulerExample leftCorrectTag = null;
          for (int i = left.size() - 1; i >= 0; i--) {
            leftDistance++;
            TextRulerAnnotation needle = TextRulerToolkit.convertToTargetAnnotation(left.get(i),
                    doc, target, docCAS.getTypeSystem());
            leftCorrectTag = TextRulerToolkit.exampleListContainsAnnotation(correctTags, needle);
            if (leftCorrectTag != null)
              break;
          }

          int rightDistance = 0;
          TextRulerExample rightCorrectTag = null;
          for (AnnotationFS fs : right) {
            rightDistance++;
            TextRulerAnnotation needle = TextRulerToolkit.convertToTargetAnnotation(fs, doc,
                    target, docCAS.getTypeSystem());
            rightCorrectTag = TextRulerToolkit.exampleListContainsAnnotation(correctTags, needle);
            if (rightCorrectTag != null)
              break;
          }
View Full Code Here


      TextRulerAnnotation[] lastExampleAnnotations = lastExample.getAnnotations();
      List<AnnotationFS> tailTokens = TextRulerToolkit.getAnnotationsAfterPosition(cas,
              lastExampleAnnotations[lastExampleAnnotations.length - 1].getEnd(), 0,
              TextRulerToolkit.getFilterSetWithSlotNames(slotNames, filterSet), tokenType);
      for (AnnotationFS afs : headTokens)
        head.add(new WienRuleItem(new TextRulerAnnotation(afs, doc)));
      for (AnnotationFS afs : tailTokens)
        tail.add(new WienRuleItem(new TextRulerAnnotation(afs, doc)));
      PatternPair p = new PatternPair();
      p.l.addAll(head);
      p.r.addAll(tail);
      headTailCache.put(key, p);
    }
View Full Code Here

      List<TextRulerExample> examples = doc.getPositiveExamples();
      for (int i = 0; i < examples.size() - 1; i++) {
        // get separator between i'th and (i+1)'th example:
        TextRulerAnnotation[] exampleAnnotations1 = examples.get(i).getAnnotations();
        TextRulerAnnotation[] exampleAnnotations2 = examples.get(i + 1).getAnnotations();
        TextRulerAnnotation lastOf1 = exampleAnnotations1[exampleAnnotations1.length - 1];
        TextRulerAnnotation firstOf2 = exampleAnnotations2[0];
        List<AnnotationFS> theTokens = TextRulerToolkit.getAnnotationsWithinBounds(cas, lastOf1
                .getEnd(), firstOf2.getBegin(), TextRulerToolkit.getFilterSetWithSlotNames(
                slotNames, filterSet), tokenType);
        TextRulerRulePattern thePattern = new TextRulerRulePattern();
        for (AnnotationFS afs : theTokens)
          thePattern.add(new WienRuleItem(new TextRulerAnnotation(afs, doc)));
        if (thePattern.size() > 0)
          result.add(thePattern);

      }
      interTupelSeparatorsCache.put(key, result);
View Full Code Here

    boolean isLastSlot = slotIndex >= slotNames.length - 1;
    for (int ei = 0; ei < examples.size(); ei++) {
      boolean isLastExample = ei == examples.size() - 1;
      TextRulerExample e = examples.get(ei);
      // get stuff between slot slotIndex and slotIndex+1
      TextRulerAnnotation slotAnnotation = e.getAnnotations()[slotIndex];
      TextRulerAnnotation nextSlotAnnotation;

      if (!isLastSlot)
        nextSlotAnnotation = e.getAnnotations()[slotIndex + 1];
      else {
        if (!isLastExample) // the next slot annotation is the first
          // example annotation of the next template:
          nextSlotAnnotation = examples.get(ei + 1).getAnnotations()[0];
        else
          nextSlotAnnotation = null;
      }

      List<AnnotationFS> theTokens;
      if (nextSlotAnnotation == null)
        theTokens = TextRulerToolkit.getAnnotationsAfterPosition(cas, slotAnnotation.getEnd(), 0,
                TextRulerToolkit.getFilterSetWithSlotNames(slotNames, filterSet), tokenType);
      else
        theTokens = TextRulerToolkit.getAnnotationsWithinBounds(cas, slotAnnotation.getEnd(),
                nextSlotAnnotation.getBegin(), TextRulerToolkit.getFilterSetWithSlotNames(
                        slotNames, filterSet), tokenType);
      TextRulerRulePattern thePattern = new TextRulerRulePattern();
      for (AnnotationFS afs : theTokens)
        thePattern.add(new WienRuleItem(new TextRulerAnnotation(afs, doc)));
      if (thePattern.size() > 0)
        result.add(thePattern);
    }
    return result;
  }
View Full Code Here

    boolean isFirstSlot = slotIndex == 0;
    for (int ei = 0; ei < examples.size(); ei++) {
      boolean isFirstExample = ei == 0;
      TextRulerExample e = examples.get(ei);
      // get stuff between slot slotIndex and slotIndex+1
      TextRulerAnnotation slotAnnotation = e.getAnnotations()[slotIndex];
      TextRulerAnnotation prevSlotAnnotation;

      if (!isFirstSlot)
        prevSlotAnnotation = e.getAnnotations()[slotIndex - 1];
      else {
        if (!isFirstExample)
          prevSlotAnnotation = examples.get(ei - 1).getAnnotations()[slotNames.length - 1];
        else
          prevSlotAnnotation = null;
      }

      List<AnnotationFS> theTokens;
      if (prevSlotAnnotation == null)
        theTokens = TextRulerToolkit.getAnnotationsBeforePosition(cas, slotAnnotation.getBegin(),
                0, TextRulerToolkit.getFilterSetWithSlotNames(slotNames, filterSet), tokenType);
      else
        theTokens = TextRulerToolkit.getAnnotationsWithinBounds(cas, prevSlotAnnotation.getEnd(),
                slotAnnotation.getBegin(), TextRulerToolkit.getFilterSetWithSlotNames(slotNames,
                        filterSet), tokenType);
      TextRulerRulePattern thePattern = new TextRulerRulePattern();
      for (AnnotationFS afs : theTokens)
        thePattern.add(new WienRuleItem(new TextRulerAnnotation(afs, doc), true));
      if (thePattern.size() > 0)
        result.add(thePattern);
    }
    return result;
  }
View Full Code Here

    CAS cas = doc.getCAS();
    TypeSystem ts = cas.getTypeSystem();
    Type tokenType = ts.getType(TextRulerToolkit.RUTA_ALL_TYPE_NAME);
    List<TextRulerExample> examples = doc.getPositiveExamples();
    for (TextRulerExample e : examples) {
      TextRulerAnnotation slotAnnotation = e.getAnnotations()[slotIndex];
      List<AnnotationFS> theTokens = TextRulerToolkit.getAnnotationsWithinBounds(cas,
              slotAnnotation.getBegin(), slotAnnotation.getEnd(), TextRulerToolkit
                      .getFilterSetWithSlotNames(slotNames, filterSet), tokenType);
      TextRulerRulePattern thePattern = new TextRulerRulePattern();
      for (AnnotationFS afs : theTokens)
        thePattern.add(new WienRuleItem(new TextRulerAnnotation(afs, doc)));
      if (thePattern.size() > 0)
        result.add(thePattern);
    }
    return result;
  }
View Full Code Here

  private void fillSlotRulesWithMostSpecificRules() {
    slotRules.clear();
    for (TextRulerExample example : examples) {
      RapierRule rule = new RapierRule(this, example.getTarget());
      TextRulerAnnotation slotAnnotation = example.getAnnotation();
      CAS docCas = example.getDocumentCAS();
      TypeSystem ts = docCas.getTypeSystem();
      Type tokensRootType = ts.getType(TextRulerToolkit.RUTA_ANY_TYPE_NAME);

      // first, get all words/tokens:
      List<AnnotationFS> before = TextRulerToolkit.getAnnotationsBeforePosition(
              example.getDocumentCAS(), slotAnnotation.getBegin(), -1,
              TextRulerToolkit.getFilterSetWithSlotNames(slotNames, filterSet), tokensRootType);
      List<AnnotationFS> after = TextRulerToolkit.getAnnotationsAfterPosition(
              example.getDocumentCAS(), slotAnnotation.getEnd(), -1,
              TextRulerToolkit.getFilterSetWithSlotNames(slotNames, filterSet), tokensRootType);
      List<AnnotationFS> inside = TextRulerToolkit.getAnnotationsWithinBounds(
              example.getDocumentCAS(), slotAnnotation.getBegin(), slotAnnotation.getEnd(),
              TextRulerToolkit.getFilterSetWithSlotNames(slotNames, filterSet), tokensRootType);

      // the before annotations have to be reversed:
      for (int i = before.size() - 1; i >= 0; i--) {
        AnnotationFS afs = before.get(i);
        RapierRuleItem ruleItem = new RapierRuleItem();
        ruleItem.addWordConstraint(new TextRulerWordConstraint(new TextRulerAnnotation(afs, example
                .getDocument())));
        addAvailablePosTagConstraintToItem(ruleItem, afs, example);
        rule.addPreFillerItem(ruleItem);
      }

      for (AnnotationFS afs : inside) {
        RapierRuleItem ruleItem = new RapierRuleItem();
        ruleItem.addWordConstraint(new TextRulerWordConstraint(new TextRulerAnnotation(afs, example
                .getDocument())));
        addAvailablePosTagConstraintToItem(ruleItem, afs, example);
        rule.addFillerItem(ruleItem);
      }
      for (AnnotationFS afs : after) {
        RapierRuleItem ruleItem = new RapierRuleItem();
        ruleItem.addWordConstraint(new TextRulerWordConstraint(new TextRulerAnnotation(afs, example
                .getDocument())));
        addAvailablePosTagConstraintToItem(ruleItem, afs, example);
        rule.addPostFillerItem(ruleItem);
      }
View Full Code Here

      // tags:
      // this is not very nice code and not dynamic feature capable, but
      // for testpurposes
      // in order to test WHISK with PosTag Terms...
      if (posTagRootTypeName != null && posTagRootTypeName.length() > 0) {
        TextRulerAnnotation tokenAnnotation = term.getWordConstraint().getTokenAnnotation();
        CAS cas = example.getDocumentCAS();
        TypeSystem ts = cas.getTypeSystem();
        Type posTagsRootType = ts.getType(posTagRootTypeName);
        if (ts != null) {
          // POS-Tags created by our test hmm tagger.
          List<AnnotationFS> posTagAnnotations = TextRulerToolkit.getAnnotationsWithinBounds(cas,
                  tokenAnnotation.getBegin(), tokenAnnotation.getEnd(), null, posTagsRootType);
          if (posTagAnnotations.size() > 0) {
            AnnotationFS posTag = posTagAnnotations.get(0);
            if (posTag.getBegin() == tokenAnnotation.getBegin()
                    && posTag.getEnd() == tokenAnnotation.getEnd()) {
              TextRulerAnnotation posTagAnnotation = new TextRulerAnnotation(posTag, doc);

              // 1. most specific term with all constraints we
              // have:
              WhiskRule proposedRule3 = proposedRule.copy();
              WhiskRuleItem t3 = proposedRule3.searchItemWithTermNumber(term
View Full Code Here

      return newRule;
  }

  protected WhiskRule anchor(WhiskRule rule, TextRulerExampleDocument doc,
          TextRulerExample example, List<WhiskRuleItem> allTerms, int slotIndex) {
    TextRulerAnnotation slotAnnotation = example.getAnnotations()[slotIndex];
    List<WhiskRuleItem> inside = getTermsWithinBounds(allTerms, slotAnnotation.getBegin(),
            slotAnnotation.getEnd());

    if (rule == null || inside.isEmpty()) {
      return null;
    }
    // create base 1 and base 2:
View Full Code Here

            filterSet), tokensRootType);

    List<WhiskRuleItem> result = new ArrayList<WhiskRuleItem>();
    int i = 0;
    for (AnnotationFS afs : all) {
      WhiskRuleItem term = new WhiskRuleItem(new TextRulerAnnotation(afs, example.getDocument()));
      term.setTermNumberInExample(i);
      i++;
      result.add(term);
    }
    return result;
View Full Code Here

TOP

Related Classes of org.apache.uima.ruta.textruler.core.TextRulerAnnotation

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.