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

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


    slotMaximumTokenCountMap.put(slotName, histogram.size() - 1); // -1 since the
    // zero-histogram point
    // also needs a place!

    TextRulerRuleList ctxRules = new TextRulerRuleList();
    TextRulerRuleList bestRules = learnTaggingRules(new TextRulerTarget(slotName,
            MLTargetType.SINGLE_LEFT_BOUNDARY, this), ctxRules); // learn
    // left
    // boundary
    // best
    // rules
    if (bestRules != null) {
      leftBoundaryBestRulesMap.put(slotName, bestRules.getRulesString(""));
      leftBoundaryContextualRulesMap.put(slotName, ctxRules.getRulesString("\t"));
      bestRules.clear(); // free som memory/references
    }
    if (shouldAbort())
      return;
    ctxRules.clear();
    bestRules = learnTaggingRules(new TextRulerTarget(slotName, MLTargetType.SINGLE_RIGHT_BOUNDARY,
            this), ctxRules); // learn
    // right
    // boundary best
    // rules
    if (bestRules != null) {
      rightBoundaryBestRulesMap.put(slotName, bestRules.getRulesString(""));
      rightBoundaryContextualRulesMap.put(slotName, ctxRules.getRulesString("\t"));
    }

    // TODO add correction rule learn stuff
    // testTaggingRulesAndCreateCorrectionRulesExamples(null, STANDARD_MAX_CONTEXTUAL_RULES_COUNT)

    // correct left start
    TextRulerTarget lsTarget = new TextRulerTarget(slotName, MLTargetType.SINGLE_LEFT_CORRECTION,
            this);
    lsTarget.setMaxShiftDistance(shiftSize);
    TextRulerRuleList correctLeftRules = learnTaggingRules(lsTarget, null);

    // resultString = "CAP{REGEXP(\"PM\")} ALL{->MARKONCE(stimeEND)};";
    // try {
    // FileUtils.saveString2File(resultString, file);
View Full Code Here


          sb.append(contextRulesPool.getRulesString(""));
      }
    }

    for (String eachSlot : slotNames) {
      String leftBoundary = TextRulerToolkit.getTypeShortName((new TextRulerTarget(eachSlot,
              MLTargetType.SINGLE_LEFT_BOUNDARY, this)).getSingleSlotTypeName());
      String rightBoundary = TextRulerToolkit.getTypeShortName((new TextRulerTarget(eachSlot,
              MLTargetType.SINGLE_RIGHT_BOUNDARY, this)).getSingleSlotTypeName());
      String slotMarkName = TextRulerToolkit.getTypeShortName(eachSlot);
      int maxInnerLength = (getMaxTokens(eachSlot) * 3) - 2;
      sb.append("\n//slot-building rules:\n");
      sb.append(leftBoundary + "{IS(" + rightBoundary + ")->UNMARK(" + leftBoundary + "), UNMARK("
View Full Code Here

//    GlobalCASSource.releaseCAS(someCas);
    // check if all helper types are present:
    List<String> list = new ArrayList<String>();

    for (String eachSlot : slotNames) {
      list.add(new TextRulerTarget(eachSlot, MLTargetType.SINGLE_LEFT_BOUNDARY, this)
              .getSingleSlotTypeName());
      list.add(new TextRulerTarget(eachSlot, MLTargetType.SINGLE_RIGHT_BOUNDARY, this)
              .getSingleSlotTypeName());
    }

    boolean result = true;
    List<String> missingTypes = new ArrayList<String>();
View Full Code Here

    interTupelSeparatorsCache.clear();

    for (int i = 0; i < slotNames.length; i++)
      patternPairs.add(new PatternPair());

    TextRulerTarget target = new TextRulerTarget(slotNames, this);

    exampleDocuments.createExamplesForTarget(target); // new multislot
    // target examples

    for (TextRulerExample e : exampleDocuments.getAllPositiveExamples()) {
View Full Code Here

    cachedTestedRuleStatistics.clear();
    ruleList = new TextRulerRuleList();
    coveredExamples = new HashSet<TextRulerExample>();

    sendStatusUpdateToDelegate("Creating examples...", TextRulerLearnerState.ML_RUNNING, false);
    TextRulerTarget target = new TextRulerTarget(slotNames[0], this); // only
    // single-slot-target
    // for now
    exampleDocuments.createExamplesForTarget(target);

    TextRulerExampleDocument[] docs = exampleDocuments.getSortedDocumentsInCacheOptimizedOrder();
View Full Code Here

      int compressionFailCount = 0;

      // only working for one slot yet !
      currentSlotName = slotNames[i];
      cachedTestedRuleStatistics.clear();
      exampleDocuments.createExamplesForTarget(new TextRulerTarget(currentSlotName, this));
      examples = exampleDocuments.getAllPositiveExamples();

      if (shouldAbort())
        return;
View Full Code Here

        docIterator = docs.iterator();
        while (!matches.contains(a) && docIterator.hasNext()) {
          b = docIterator.next();
          if (!matches.contains(b)) {
            if (b.getBegin() == a.getBegin() && b.getEnd() == a.getEnd()) {
              TextRulerTarget target = new TextRulerTarget(b.getType().getName(), this);
              TextRulerExample error = new TextRulerExample(b.getDocument(), b, false, target);
              TextRulerExample truth = new TextRulerExample(a.getDocument(), a, true, target);
              result.add(new AnnotationError(error, truth, AnnotationErrorType.CORRECTION));
              matches.add(a);
              matches.add(b);
              break;
            }
          }
        }
      }
      // create shifting type errors
      iterator = gold.iterator();
      docIterator = docs.iterator();
      List<AnnotationError> tempErrors;
      int distance;
      while (iterator.hasNext()) {
        a = iterator.next();
        docIterator = docs.iterator();
        tempErrors = new ArrayList<AnnotationError>();
        while (!matches.contains(a) && docIterator.hasNext()) {
          b = docIterator.next();
          if (!matches.contains(b)) {
            if (b.getType().getShortName().equals(a.getType().getShortName())
                    && b.getEnd() >= a.getBegin() && b.getBegin() <= a.getEnd()) {
              TextRulerTarget target = new TextRulerTarget(a.getType().getName(), this);
              TextRulerExample error = new TextRulerExample(b.getDocument(), b, false, target);
              TextRulerExample truth = new TextRulerExample(a.getDocument(), a, true, target);
              AnnotationErrorType type;
              if ((b.getBegin() == a.getBegin() && b.getEnd() < a.getEnd())
                      || (b.getBegin() > a.getBegin() && b.getEnd() == a.getEnd())) {
                type = AnnotationErrorType.EXPANSION;
              } else if (b.getBegin() > a.getBegin() || b.getEnd() > a.getEnd()) {
                type = AnnotationErrorType.SHIFTING_LEFT;
              } else {
                type = AnnotationErrorType.SHIFTING_RIGHT;
              }
              AnnotationError err = new AnnotationError(error, truth, type);
              if (!tempErrors.contains(err))
                tempErrors.add(err);
            }
          }
        }
        if (tempErrors.size() > 0) {
          AnnotationError err = tempErrors.get(0);
          int begin = err.getError().getAnnotation().getBegin();
          int end = err.getError().getAnnotation().getEnd();
          distance = Math.abs(begin - a.getBegin()) + Math.abs(end - a.getEnd());
          for (int j = 1; j < tempErrors.size(); j++) {
            int begin2 = tempErrors.get(j).getError().getAnnotation().getBegin();
            int end2 = tempErrors.get(j).getError().getAnnotation().getEnd();
            if (Math.abs(begin2 - a.getBegin()) + Math.abs(end2 - a.getEnd()) < distance) {
              distance = Math.abs(begin2 - a.getBegin()) + Math.abs(end2 - a.getEnd());
              err = tempErrors.get(j);
            }
          }
          result.add(err);
          matches.add((TrabalAnnotation) err.getTruth().getAnnotation());
          matches.add((TrabalAnnotation) err.getError().getAnnotation());
        }
      }
      // creating shifting + correction errors
      iterator = gold.iterator();
      docIterator = docs.iterator();
      while (iterator.hasNext()) {
        a = iterator.next();
        docIterator = docs.iterator();
        tempErrors = new ArrayList<AnnotationError>();
        while (!matches.contains(a) && docIterator.hasNext()) {
          b = docIterator.next();
          if (!matches.contains(b)) {
            if (b.getEnd() >= a.getBegin() && b.getBegin() <= a.getEnd()) {
              TextRulerTarget target = new TextRulerTarget(b.getType().getName(), this);
              TextRulerExample error = new TextRulerExample(b.getDocument(), b, false, target);
              TextRulerExample truth = new TextRulerExample(a.getDocument(), a, true, target);
              AnnotationErrorType type;
              if ((b.getBegin() == a.getBegin() && b.getEnd() < a.getEnd())
                      || (b.getBegin() > a.getBegin() && b.getEnd() == a.getEnd())) {
                type = AnnotationErrorType.EXPANSION;
              } else if (b.getBegin() > a.getBegin() || b.getEnd() > a.getEnd()) {
                type = AnnotationErrorType.SHIFTING_LEFT;
              } else {
                type = AnnotationErrorType.SHIFTING_RIGHT;
              }
              AnnotationError err = new AnnotationError(error, truth, type);
              if (!tempErrors.contains(err))
                tempErrors.add(err);
            }
          }
        }
        if (tempErrors.size() > 0) {
          AnnotationError err = tempErrors.get(0);
          int begin = err.getError().getAnnotation().getBegin();
          int end = err.getError().getAnnotation().getEnd();
          distance = Math.abs(begin - a.getBegin()) + Math.abs(end - a.getEnd());
          for (int j = 1; j < tempErrors.size(); j++) {
            int begin2 = tempErrors.get(j).getError().getAnnotation().getBegin();
            int end2 = tempErrors.get(j).getError().getAnnotation().getEnd();
            if (Math.abs(begin2 - a.getBegin()) + Math.abs(end2 - a.getEnd()) < distance) {
              distance = Math.abs(begin2 - a.getBegin()) + Math.abs(end2 - a.getEnd());
              err = tempErrors.get(j);
            }
          }
          result.add(err);
          matches.add((TrabalAnnotation) err.getTruth().getAnnotation());
          matches.add((TrabalAnnotation) err.getError().getAnnotation());
        }
      }
      // create deleting type errors
      docIterator = docs.iterator();
      while (docIterator.hasNext()) {
        b = docIterator.next();
        if (!matches.contains(b)) {
          TextRulerTarget target = new TextRulerTarget(b.getType().getName(), this);
          TextRulerExample error = new TextRulerExample(b.getDocument(), b, false, target);
          result.add(new AnnotationError(error, null, AnnotationErrorType.DELETION));
          matches.add(b);
        }
      }
      // create annotation type errors
      iterator = gold.iterator();
      while (iterator.hasNext()) {
        a = iterator.next();
        if (!matches.contains(a)) {
          TextRulerTarget target = new TextRulerTarget(a.getType().getName(), this);
          TextRulerExample truth = new TextRulerExample(a.getDocument(), a, true, target);
          result.add(new AnnotationError(null, truth, AnnotationErrorType.ANNOTATION));
          matches.add(a);
        }
      }
View Full Code Here

    TextRulerExampleDocument document = error.getDocument();
    CAS cas = error.getDocumentCAS();
    List<TrabalRuleItem> truthLeftBorder = getBorderOfExample(truth, document, cas, true);
    List<TrabalRuleItem> truthRightBorder = getBorderOfExample(truth, document, cas, false);
    List<TrabalRuleItem> errorLeftBorder = getBorderOfExample(error, document, cas, true);
    TextRulerTarget target = error.getTarget();
    TrabalAnnotation errorAnnotation = (TrabalAnnotation) error.getAnnotation();
    TrabalAnnotation truthAnnotation = (TrabalAnnotation) truth.getAnnotation();
    // boolean shiftToLeft = error.getAnnotation().getBegin() > truth.getAnnotation().getBegin();
    // if (shiftToLeft) {
    for (TrabalRuleItem a : truthLeftBorder) {
View Full Code Here

    TextRulerExampleDocument document = additionalDocuments.getDocuments().get(
            exampleDocuments.getDocuments().indexOf(truth.getDocument()));
    CAS cas = document.getCAS();
    List<TrabalRuleItem> truthLeftBorder = getBorderOfExample(truth, document, cas, true);
    List<TrabalRuleItem> truthRightBorder = getBorderOfExample(truth, document, cas, false);
    TextRulerTarget target = truth.getTarget();
    TrabalAnnotation truthAnnotation = (TrabalAnnotation) truth.getAnnotation();
    for (TrabalRuleItem front : truthLeftBorder) {
      for (TrabalRuleItem rear : truthRightBorder) {
        AnnotationRule newRule = new AnnotationRule(this, target, truthAnnotation);
        newRule.setFrontBoundary(front);
View Full Code Here

      removeBasics(testCas);
      if (TextRulerToolkit.DEBUG) {
        TextRulerToolkit.writeCAStoXMIFile(testCas, tempDirectory() + "testCasProcessed.xmi");
      }
      if (rule.getAnnotation() != null && rule.getTargetAnnotation() != null) {
        compareOriginalDocumentWithTestCAS(goldDoc, additionalDoc, testCas, new TextRulerTarget(
                rule.getAnnotation().getType().getName(), this), c, false);
        if (rule.getAnnotation().getType() != rule.getTargetAnnotation().getType()) {
          compareOriginalDocumentWithTestCAS(goldDoc, additionalDoc, testCas, new TextRulerTarget(
                  rule.getTargetAnnotation().getType().getName(), this), c, false);
        }
      } else if (rule.getTargetAnnotation() != null) {
        compareOriginalDocumentWithTestCAS(goldDoc, additionalDoc, testCas, new TextRulerTarget(
                rule.getTargetAnnotation().getType().getName(), this), c, false);
      } else {
        compareOriginalDocumentWithTestCAS(goldDoc, additionalDoc, testCas, new TextRulerTarget(
                rule.getAnnotation().getType().getName(), this), c, false);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
View Full Code Here

TOP

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

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.