Package org.apache.uima.cas

Examples of org.apache.uima.cas.TypeSystem


      a.setEnd(((AnnotationFS) fs).getEnd());
    }
    if (withFeatures) {
      CAS testCas = fs.getCAS();
      CAS runCas = newFS.getCAS();
      TypeSystem testTS = testCas.getTypeSystem();
      TypeSystem runTS = runCas.getTypeSystem();
      Type annotationType = testCas.getAnnotationType();
      List<Feature> features = fs.getType().getFeatures();
      for (Feature feature : features) {
        Type range = feature.getRange();
        if (testTS.subsumes(annotationType, range)) {
          FeatureStructure valueTest = fs.getFeatureValue(feature);
          if (valueTest instanceof AnnotationFS) {
            AnnotationFS a1 = (AnnotationFS) valueTest;
            Feature feature2 = newFS.getType().getFeatureByBaseName(feature.getShortName());
            if (feature2 != null) {
              Type range2 = runTS.getType(range.getName());
              AnnotationFS createAnnotation = runCas.createAnnotation(range2, a1.getBegin(),
                      a1.getEnd());
              newFS.setFeatureValue(feature2, createAnnotation);
            }
          }
View Full Code Here


    }
  }

 
  private Collection<FeatureStructure> getFeatureStructures(List<Type> types, CAS cas) {
    TypeSystem typeSystem = cas.getTypeSystem();
    Type annotationType = cas.getAnnotationType();
    Collection<FeatureStructure> result = new HashSet<FeatureStructure>();
    AnnotationIndex<AnnotationFS> annotationIndex = cas.getAnnotationIndex();
    for (AnnotationFS each : annotationIndex) {
      Type type = each.getType();
      for (Type eachType : types) {
        if(typeSystem.subsumes(eachType, type)) {
          List<Feature> features = each.getType().getFeatures();
          for (Feature feature : features) {
            Type range = feature.getRange();
            if (typeSystem.subsumes(annotationType, range)) {
              result.add(each);
              break;
            }
          }
        }
View Full Code Here

      if (!(a11.getBegin() == a22.getBegin() && a11.getEnd() == a22.getEnd())) {
        return false;
      }
    }
    CAS cas = a1.getCAS();
    TypeSystem typeSystem = cas.getTypeSystem();
    Type annotationType = cas.getAnnotationType();
    List<Feature> features1 = type1.getFeatures();
    boolean result = true;
    boolean allEmpty1 = true;
    boolean allEmpty2 = true;
    for (Feature eachFeature1 : features1) {
      Type range = eachFeature1.getRange();
      if (typeSystem.subsumes(annotationType, range)) {
        String name = eachFeature1.getShortName();
        Feature eachFeature2 = type2.getFeatureByBaseName(name);
        FeatureStructure featureValue1 = a1.getFeatureValue(eachFeature1);
        FeatureStructure featureValue2 = a2.getFeatureValue(eachFeature2);
        allEmpty1 &= featureValue1 == null;
View Full Code Here

  public List<TextRulerExample> createSlotInstancesForCAS(CAS aCas, TextRulerTarget target,
          boolean createFromRawTypeName) {
    List<TextRulerExample> result = new ArrayList<TextRulerExample>();

    if (target.isMultiSlot()) {
      TypeSystem ts = aCas.getTypeSystem();
      int currentSlotIndex = 0;
      TextRulerAnnotation[] currentAnnotations = new TextRulerAnnotation[target.slotNames.length];
      List<Type> slotTypes = new ArrayList<Type>();
      for (String s : target.slotNames)
        slotTypes.add(ts.getType(s));

      for (FSIterator<AnnotationFS> it = aCas.getAnnotationIndex().iterator(true); it.isValid(); it
              .moveToNext()) {
        AnnotationFS fs = (AnnotationFS) it.get();
        Type theType = fs.getType();
        if (slotTypes.contains(theType)) {
          int idx = slotTypes.indexOf(theType);
          if (idx < currentSlotIndex) // the previous example was not
          // complete, so we have to write
          // it down:
          {
            result.add(new TextRulerExample(this, currentAnnotations, true, target));
            currentAnnotations = new TextRulerAnnotation[target.slotNames.length];
          }
          currentAnnotations[idx] = new TextRulerAnnotation(fs, this);
          if (idx >= target.slotNames.length - 1) {
            result.add(new TextRulerExample(this, currentAnnotations, true, target));
            currentAnnotations = new TextRulerAnnotation[target.slotNames.length];
            currentSlotIndex = 0;
          } else
            currentSlotIndex = idx + 1;
        }
      }
      if (currentSlotIndex > 0) {
        result.add(new TextRulerExample(this, currentAnnotations, true, target));
      }

    } else if (target.isLeftCorrection() || target.isRightCorrection()) {
      // TODO
      TextRulerBasicLearner learner = target.getLearner();
      Set<String> filterSet = learner.getFilterSet();
      CAS testCAS = learner.getTestCAS();
      TextRulerStatisticsCollector c = new TextRulerStatisticsCollector();
      resetAndFillTestCAS(testCAS, target);
      CAS docCAS = getCAS();
      TypeSystem ts = docCAS.getTypeSystem();
      Type tokensRootType = ts.getType(TextRulerToolkit.RUTA_ANY_TYPE_NAME);
      AnalysisEngine analysisEngine = learner.getAnalysisEngine();
      try {
        analysisEngine.process(testCAS);
      } catch (AnalysisEngineProcessException e) {
        // TODO add log here
View Full Code Here

    CasCopier cc = new CasCopier(docCas, testCas);
    testCas.setDocumentText(docCas.getDocumentText());

    // copy all annotations except the target-annotations:
    TypeSystem ts = docCas.getTypeSystem();

    List<Type> slotTypes = new ArrayList<Type>();

    for (String s : target.getSlotTypeNames())
      slotTypes.add(ts.getType(s));

    if (target.isBoundary()) {
      // add the base types (without START and END markers) also !
      for (String s : target.slotNames)
        slotTypes.add(ts.getType(s));
    }

    for (AnnotationFS fs : docCas.getAnnotationIndex()) {
      if (!slotTypes.contains(fs.getType())
              && !fs.getType().equals(docCas.getDocumentAnnotation().getType())) {
View Full Code Here

  }

  public static void createBoundaryAnnotationsForCas(CAS aCas, String slotName,
          Set<String> tokenFilterSet) {
    List<AnnotationFS> slots = TextRulerToolkit.extractAnnotationsForSlotName(aCas, slotName);
    TypeSystem ts = aCas.getTypeSystem();
    for (AnnotationFS a : slots) {

      List<AnnotationFS> slotTokens = TextRulerToolkit.getAnnotationsWithinBounds(aCas,
              a.getBegin(), a.getEnd(),
              TextRulerToolkit.getFilterSetWithSlotName(slotName, tokenFilterSet),
              ts.getType(TextRulerToolkit.RUTA_ANY_TYPE_NAME));
      if (!slotTokens.isEmpty()) {
        AnnotationFS first = slotTokens.get(0);
        AnnotationFS last = slotTokens.get(slotTokens.size() - 1);
        Type typeLB = ts.getType(slotName + TextRulerToolkit.LEFT_BOUNDARY_EXTENSION);
        aCas.addFsToIndexes(aCas.createAnnotation(typeLB, first.getBegin(), first.getEnd()));
        Type typeRB = ts.getType(slotName + TextRulerToolkit.RIGHT_BOUNDARY_EXTENSION);
        aCas.addFsToIndexes(aCas.createAnnotation(typeRB, last.getBegin(), last.getEnd()));
      }
    }
  }
View Full Code Here

    }
  }

  public static void removeBoundaryAnnotationsFromCas(CAS aCas, String slotName) {
    // this method is not tested yet!
    TypeSystem ts = aCas.getTypeSystem();
    Type startType = ts.getType(slotName + TextRulerToolkit.LEFT_BOUNDARY_EXTENSION);
    Type endType = ts.getType(slotName + TextRulerToolkit.RIGHT_BOUNDARY_EXTENSION);
    List<AnnotationFS> removeList = new ArrayList<AnnotationFS>();
    for (FSIterator<AnnotationFS> it = aCas.getAnnotationIndex(startType).iterator(true); it
            .isValid(); it.moveToNext()) {
      AnnotationFS fs = it.get();
      removeList.add(fs);
View Full Code Here

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

    if (interTupelSeparatorsCache.containsKey(key)) {
      return interTupelSeparatorsCache.get(key);
    } else {
      List<TextRulerRulePattern> result = new ArrayList<TextRulerRulePattern>();
      CAS cas = doc.getCAS();
      TypeSystem ts = cas.getTypeSystem();
      Type tokenType = ts.getType(TextRulerToolkit.RUTA_ALL_TYPE_NAME);
      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();
View Full Code Here

  protected List<TextRulerRulePattern> getRightContextForSlot(TextRulerExampleDocument doc,
          int slotIndex) {
    List<TextRulerRulePattern> result = new ArrayList<TextRulerRulePattern>();
    CAS cas = doc.getCAS();
    TypeSystem ts = cas.getTypeSystem();
    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);
View Full Code Here

TOP

Related Classes of org.apache.uima.cas.TypeSystem

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.