Examples of TextRulerExample


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

    List<TextRulerExample> testPositives = goldDoc
            .createSlotInstancesForCAS(testCas, target, false);

    List<TextRulerExample> baseFP = new ArrayList<TextRulerExample>();
    for (TextRulerExample e : additionalPositives) {
      TextRulerExample example = TextRulerToolkit.exampleListContainsAnnotation(goldPositives,
              e.getAnnotation());
      if (example == null) {
        baseFP.add(e);
      }
    }
    List<TextRulerExample> baseFN = new ArrayList<TextRulerExample>();
    for (TextRulerExample e : goldPositives) {
      TextRulerExample example = TextRulerToolkit.exampleListContainsAnnotation(
              additionalPositives, e.getAnnotation());
      if (example == null) {
        baseFN.add(e);
      }
    }

    List<TextRulerExample> testFP = new ArrayList<TextRulerExample>();
    for (TextRulerExample e : testPositives) {
      TextRulerExample example = TextRulerToolkit.exampleListContainsAnnotation(goldPositives,
              e.getAnnotation());
      if (example == null) {
        testFP.add(e);
      }
    }
    List<TextRulerExample> testFN = new ArrayList<TextRulerExample>();
    for (TextRulerExample e : goldPositives) {
      TextRulerExample example = TextRulerToolkit.exampleListContainsAnnotation(testPositives,
              e.getAnnotation());
      if (example == null) {
        testFN.add(e);
      }
    }

    for (TextRulerExample e : baseFP) {
      TextRulerExample example = TextRulerToolkit.exampleListContainsAnnotation(testFP,
              e.getAnnotation());
      if (example == null) {
        c.addCoveredPositive(e);
      }
    }

    for (TextRulerExample e : baseFN) {
      TextRulerExample example = TextRulerToolkit.exampleListContainsAnnotation(testFN,
              e.getAnnotation());
      TextRulerExample coveredExample = TextRulerToolkit.exampleListContainsAnnotation(
              goldPositives, e.getAnnotation());
      if (example == null) {
        c.addCoveredPositive(coveredExample);
      }
    }

    for (TextRulerExample e : testFN) {
      TextRulerExample example = TextRulerToolkit.exampleListContainsAnnotation(baseFN,
              e.getAnnotation());
      if (example == null) {
        if (collectNegativeExamples) {
          e.setPositive(false);
          c.addCoveredNegative(e);
        } else {
          c.incCoveredNegatives(1);
        }
      }
    }

    for (TextRulerExample e : testFP) {
      TextRulerExample example = TextRulerToolkit.exampleListContainsAnnotation(baseFP,
              e.getAnnotation());
      if (example == null) {
        c.incCoveredNegatives(1);
      }
    }
View Full Code Here

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

    List<TextRulerExample> originalPositives = originalDoc.getPositiveExamples();
    List<TextRulerExample> testPositives = originalDoc.createSlotInstancesForCAS(testCas, target,
            true);

    for (TextRulerExample e : testPositives) {
      TextRulerExample coveredExample = TextRulerToolkit.exampleListContainsAnnotation(
              originalPositives, e.getAnnotation());
      if (coveredExample != null) {
        originalPositives.remove(coveredExample);
        theScore.tp++;
      } else
View Full Code Here

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

      PatternPair p = headTailCache.get(key);
      head.addAll(p.l);
      tail.addAll(p.r);
    } else {
      CAS cas = doc.getCAS();
      TextRulerExample firstExample = doc.getPositiveExamples().get(0);
      TextRulerExample lastExample = doc.getPositiveExamples().get(
              doc.getPositiveExamples().size() - 1);
      TypeSystem ts = cas.getTypeSystem();
      Type tokenType = ts.getType(TextRulerToolkit.RUTA_ALL_TYPE_NAME);
      List<AnnotationFS> headTokens = TextRulerToolkit.getAnnotationsBeforePosition(cas,
              firstExample.getAnnotations()[0].getBegin(), 0, TextRulerToolkit
                      .getFilterSetWithSlotNames(slotNames, filterSet), tokenType);
      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)));
View Full Code Here

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

    Type tokenType = ts.getType(TextRulerToolkit.RUTA_ALL_TYPE_NAME);
    List<TextRulerExample> examples = doc.getPositiveExamples();
    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
View Full Code Here

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

    List<TextRulerExample> examples = doc.getPositiveExamples();

    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;
View Full Code Here

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

          // TODO stop after the first found match or create one bad
          // example for each found occurence ??!!
          // for now: stop after one ! so create only ONE bad
          // 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;
          }

          TextRulerExample theCorrectTag = null;
          if (rightDistance < leftDistance && rightCorrectTag != null)
            theCorrectTag = rightCorrectTag;
          else if (rightDistance > leftDistance && leftCorrectTag != null)
            theCorrectTag = leftCorrectTag;
          else // use the one that would lie in the slot filler:
          {
            if (target.type == MLTargetType.SINGLE_LEFT_BOUNDARY && rightCorrectTag != null)
              theCorrectTag = rightCorrectTag;
            else
              theCorrectTag = leftCorrectTag;
          }

          if (theCorrectTag != null) {
            TextRulerToolkit.log("FOUND BAD EXAMPLE FOR SHIFTING !!");
            TextRulerShiftExample shiftExample = new TextRulerShiftExample(doc,
                    wrongTag.getAnnotation(), theCorrectTag.getAnnotation(), true, target);
            newExamples.add(shiftExample);
          }
        }
        TextRulerToolkit
                .writeCAStoXMIFile(testCAS, dir + File.pathSeparator + doc.getCasFileName());
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.