Package org.apache.uima.cas.text

Examples of org.apache.uima.cas.text.AnnotationFS


      List<AnnotationFS> textsMatched = evaluateMatches.get(evaluateMatches.size() - 1)
              .getTextsMatched();
      if (textsMatched.isEmpty()) {
        return null;
      }
      AnnotationFS backtrackedAnnotation = textsMatched.get(textsMatched.size() - 1);
      return backtrackedAnnotation;
    } else {
      List<AnnotationFS> textsMatched = evaluateMatches.get(0).getTextsMatched();
      if (textsMatched.isEmpty()) {
        return null;
      }
      AnnotationFS backtrackedAnnotation = textsMatched.get(0);
      return backtrackedAnnotation;
    }
  }
View Full Code Here


      match.evaluateInnerMatches(true, stream);
      return;
    }
    int begin = textsMatched.get(0).getBegin();
    int end = textsMatched.get(textsMatched.size() - 1).getEnd();
    AnnotationFS annotation = stream.getCas().createAnnotation(stream.getCas().getAnnotationType(),
            begin, end);

    List<EvaluatedCondition> evaluatedConditions = new ArrayList<EvaluatedCondition>(
            conditions.size());
    for (AbstractRutaCondition condition : conditions) {
View Full Code Here

          RutaRuleElement sideStepOrigin, RuleElement entryPoint, RutaStream stream,
          InferenceCrowd crowd) {
    List<RuleMatch> result = new ArrayList<RuleMatch>();
    if (quantifier.continueMatch(after, annotation, this, ruleMatch, containerMatch, stream, crowd)) {
      boolean stopMatching = false;
      AnnotationFS eachAnchor = annotation;
      AnnotationFS lastAnchor = annotation;
      ComposedRuleElementMatch extendedContainerMatch = containerMatch;
      RuleMatch extendedMatch = ruleMatch;
      while (!stopMatching) {
        if (!quantifier.continueMatch(after, eachAnchor, this, extendedMatch,
                extendedContainerMatch, stream, crowd)) {
View Full Code Here

          ComposedRuleElementMatch containerMatch, RuleElement entryPoint, RutaStream stream,
          InferenceCrowd crowd) {
    List<RuleMatch> result = new ArrayList<RuleMatch>();
    boolean newDirection = !after;
    List<AnnotationFS> matchedAnnotationsOf = ruleMatch.getMatchedAnnotationsOf(this);
    AnnotationFS annotation = null;
    if (!matchedAnnotationsOf.isEmpty()) {
      if (newDirection) {
        annotation = matchedAnnotationsOf.get(matchedAnnotationsOf.size() - 1);
      } else {
        annotation = matchedAnnotationsOf.get(0);
View Full Code Here

      if (matchInfo.size() == 1) {
        List<RuleElementMatch> list = matchInfo.get(0);
        if (list != null && list.size() == 1) {
          List<AnnotationFS> textsMatched = list.get(0).getTextsMatched();
          if (textsMatched.size() == 1) {
            AnnotationFS firstNormal = getFirstNormal(textsMatched);
            if (firstNormal != null) {
              return textsMatched;
            }
          }
        }
      }
    }

    List<List<List<RuleElementMatch>>> reverseList = new ArrayList<List<List<RuleElementMatch>>>();
    for (Integer index : indexes) {
      if (index > container.getRuleElements().size()) {
        continue;
      }
      RuleElement ruleElement = container.getRuleElements().get(index - 1);
      List<List<RuleElementMatch>> matchInfo = getMatchInfo(ruleElement);
      int i = 0;
      for (List<RuleElementMatch> list : matchInfo) {
        if (reverseList.size() <= i) {
          reverseList.add(new ArrayList<List<RuleElementMatch>>());
        }
        List<List<RuleElementMatch>> l = reverseList.get(i);
        l.add(list);
        i++;
      }
    }
    CAS cas = null;
    for (List<List<RuleElementMatch>> list : reverseList) {
      int begin = Integer.MAX_VALUE;
      int end = 0;
      for (List<RuleElementMatch> list2 : list) {
        if (list2 != null) {
          for (RuleElementMatch ruleElementMatch : list2) {
            List<AnnotationFS> textsMatched = ruleElementMatch.getTextsMatched();
            if (textsMatched != null && !textsMatched.isEmpty()) {
              AnnotationFS first = getFirstNormal(textsMatched);
              if (first != null) {
                begin = Math.min(first.getBegin(), begin);
              }
              AnnotationFS last = getLastNormal(textsMatched);
              if (last != null) {
                end = Math.max(last.getEnd(), end);
              }
              if (cas == null && first != null) {
                cas = first.getCAS();
              }
            }
          }
        }
      }
      if (cas != null && end != 0) {
        AnnotationFS annotation = cas.createAnnotation(cas.getAnnotationType(), begin, end);
        result.add(annotation);
      }
    }
    return result;
  }
View Full Code Here

  }

  private AnnotationFS getFirstNormal(List<AnnotationFS> textsMatched) {
    // hotfix for invisible dummy matches
    int pointer = 0;
    AnnotationFS annotationFS = null;
   
    if(textsMatched.size() == 0) {
      return null;
    } else if(textsMatched.size() ==1) {
      AnnotationFS fs = textsMatched.get(0);
      if(fs.getType().getName().equals(RutaEngine.OPTIONAL_TYPE)) {
        return null;
      }
    }
   
    while (pointer < textsMatched.size() && (annotationFS = textsMatched.get(pointer)) != null
View Full Code Here

  }

  private AnnotationFS getLastNormal(List<AnnotationFS> textsMatched) {
    // hotfix for invisible dummy matches
    int pointer = textsMatched.size() - 1;
    AnnotationFS annotationFS = null;
    while (pointer >= 0 && (annotationFS = textsMatched.get(pointer)) != null
            && annotationFS.getType().getName().equals(RutaEngine.OPTIONAL_TYPE)) {
      pointer--;
    }
    if (pointer >= 0) {
      return annotationFS;
    }
View Full Code Here

public class RuleMatch extends AbstractRuleMatch<RutaRule> {

  private static class RuleMatchComparator implements Comparator<RuleElementMatch> {

    public int compare(RuleElementMatch rem1, RuleElementMatch rem2) {
      AnnotationFS fs1 = rem1.getTextsMatched().get(0);
      AnnotationFS fs2 = rem2.getTextsMatched().get(0);

      return fs1.getBegin() < fs2.getBegin() ? -1 : 1;
    }
View Full Code Here

      FSIndex ind3 = irep.getIndex("Index3");
      Assert.assertNotNull(ind3);
      Assert.assertEquals("uima.tcas.Annotation", ind3.getType().getName());
      Assert.assertEquals(FSIndex.SORTED_INDEX, ind3.getIndexingStrategy());

      AnnotationFS fs5 = cas.createAnnotation(t1, 0, 0);
      AnnotationFS fs6 = cas.createAnnotation(t2, 0, 0);
      AnnotationFS fs7 = cas.createAnnotation(t1, 0, 0);
      Assert.assertTrue(ind3.compare(fs5, fs6) < 0);
      Assert.assertTrue(ind3.compare(fs6, fs7) > 0);

      // only way to check if allowed values is correct is to try to set an
      // invalid value?
View Full Code Here

      CAS outCas = iter.next();
      assertEquals("This is one.", outCas.getDocumentText());
      // -- check SourceDocumentInformation FSs
      Iterator<AnnotationFS> sdiIter = outCas.getAnnotationIndex(sdiType).iterator();
      assertTrue(sdiIter.hasNext());
      AnnotationFS outSdiFs = (AnnotationFS) sdiIter.next();
      assertEquals("This is", outSdiFs.getCoveredText());
      assertEquals("cas1", outSdiFs.getStringValue(uriFeat));
      assertTrue(sdiIter.hasNext());
      outSdiFs = (AnnotationFS) sdiIter.next();
      assertEquals(" one.", outSdiFs.getCoveredText());
      assertEquals("cas2", outSdiFs.getStringValue(uriFeat));
      assertFalse(sdiIter.hasNext());
      // --
      assertFalse(iter.hasNext());

      // input third CAS. We should get back one more segment.
      iter = ae.processAndOutputNewCASes(inputCas3);
      assertTrue(iter.hasNext());
      outCas = iter.next();
      assertEquals("This is two.", outCas.getDocumentText());
      // -- check SourceDocumentInformation FSs
      sdiIter = outCas.getAnnotationIndex(sdiType).iterator();
      assertTrue(sdiIter.hasNext());
      outSdiFs = (AnnotationFS) sdiIter.next();
      assertEquals("This is", outSdiFs.getCoveredText());
      assertEquals("cas2", outSdiFs.getStringValue(uriFeat));
      assertTrue(sdiIter.hasNext());
      outSdiFs = (AnnotationFS) sdiIter.next();
      assertEquals(" two.", outSdiFs.getCoveredText());
      assertEquals("cas3", outSdiFs.getStringValue(uriFeat));
      assertFalse(sdiIter.hasNext());
      // --
      assertFalse(iter.hasNext());
    } catch (Exception e) {
      JUnitExtension.handleException(e);
View Full Code Here

TOP

Related Classes of org.apache.uima.cas.text.AnnotationFS

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.