Package org.apache.uima.cas

Examples of org.apache.uima.cas.Type


            kind = FSIndex.SET_INDEX;
          else if (kindStr.equals(FsIndexDescription.KIND_SORTED))
            kind = FSIndex.SORTED_INDEX;
        }

        Type type = tsm.getType(aIndexes[i].getTypeName());
        if (type == null) {
          throw new ResourceInitializationException(
                  ResourceInitializationException.UNDEFINED_TYPE_FOR_INDEX, new Object[] {
                      aIndexes[i].getTypeName(), aIndexes[i].getLabel(),
                      aIndexes[i].getSourceUrlString() });
        }
        FSIndexComparator comparator = irm.createComparator();
        comparator.setType(type);

        FsIndexKeyDescription[] keys = aIndexes[i].getKeys();
        if (keys != null) {
          for (int j = 0; j < keys.length; j++) {
            if (keys[j].isTypePriority()) {
              comparator.addKey(irm.getDefaultTypeOrder(), FSIndexComparator.STANDARD_COMPARE);
            } else {
              Feature feature = type.getFeatureByBaseName(keys[j].getFeatureName());
              if (feature == null) {
                throw new ResourceInitializationException(
                        ResourceInitializationException.INDEX_KEY_FEATURE_NOT_FOUND, new Object[] {
                            keys[j].getFeatureName(), aIndexes[i].getLabel(),
                            aIndexes[i].getSourceUrlString() });
View Full Code Here


        FeatureStructureImpl fs = (FeatureStructureImpl) aSofa.getLocalFSData();

        int arrayStart = 0;
        int arraySize = this.ll_getArraySize(fs.getAddress());
        ByteBuffer buf = null;
        Type type = fs.getType();
        if (type.getName().equals(CAS.TYPE_NAME_INTEGER_ARRAY)) {
          arrayStart = getArrayStartAddress(fs.getAddress());
          buf = ByteBuffer.allocate(arraySize * 4);
          IntBuffer intbuf = buf.asIntBuffer();
          intbuf.put(this.getHeap().heap, arrayStart, arraySize);
          ByteArrayInputStream bis = new ByteArrayInputStream(buf.array());
          return bis;
        } else if (type.getName().equals(CAS.TYPE_NAME_FLOAT_ARRAY)) {
          arrayStart = getArrayStartAddress(fs.getAddress());
          buf = ByteBuffer.allocate(arraySize * 4);
          FloatBuffer floatbuf = buf.asFloatBuffer();
          float[] floatArray = new float[arraySize];
          for (int i = arrayStart; i < arrayStart + arraySize; i++) {
            floatArray[i - arrayStart] = Float.intBitsToFloat(this.getHeap().heap[i]);
          }
          floatbuf.put(floatArray);
          ByteArrayInputStream bis = new ByteArrayInputStream(buf.array());
          return bis;
        } else if (type.getName().equals(CAS.TYPE_NAME_BOOLEAN_ARRAY)
            || type.getName().equals(CAS.TYPE_NAME_BYTE_ARRAY)) {
          arrayStart = this.getHeap().heap[getArrayStartAddress(fs.getAddress())];
          buf = ByteBuffer.allocate(arraySize);
          buf.put(this.getByteHeap().heap, arrayStart, arraySize);
          ByteArrayInputStream bis = new ByteArrayInputStream(buf.array());
          return bis;
        } else if (type.getName().equals(CAS.TYPE_NAME_SHORT_ARRAY)) {
          arrayStart = this.getHeap().heap[getArrayStartAddress(fs.getAddress())];
          buf = ByteBuffer.allocate(arraySize * 2);
          ShortBuffer shortbuf = buf.asShortBuffer();
          shortbuf.put(this.getShortHeap().heap, arrayStart, arraySize);

          ByteArrayInputStream bis = new ByteArrayInputStream(buf.array());
          return bis;
        } else if (type.getName().equals(CAS.TYPE_NAME_LONG_ARRAY)) {
          arrayStart = this.getHeap().heap[getArrayStartAddress(fs.getAddress())];
          buf = ByteBuffer.allocate(arraySize * 8);
          LongBuffer longbuf = buf.asLongBuffer();
          longbuf.put(this.getLongHeap().heap, arrayStart, arraySize);
          ByteArrayInputStream bis = new ByteArrayInputStream(buf.array());
          return bis;
        } else if (type.getName().equals(CAS.TYPE_NAME_DOUBLE_ARRAY)) {
          arrayStart = this.getHeap().heap[getArrayStartAddress(fs.getAddress())];
          buf = ByteBuffer.allocate(arraySize * 8);
          DoubleBuffer doublebuf = buf.asDoubleBuffer();
          double[] doubleArray = new double[arraySize];
          for (int i = arrayStart; i < arrayStart + arraySize; i++) {
View Full Code Here

    int[] featcodes = getTypeSystem().getLowLevelTypeSystem().ll_getAppropriateFeatures(typeCode);
    for (int i = 0; i < featcodes.length; i++) {

      // get range type of this feature
      Feature feature = getTypeSystem().getLowLevelTypeSystem().ll_getFeatureForCode(featcodes[i]);
      Type rangeType = feature.getRange();
      // get feature code
      int featCode = ((FeatureImpl) feature).getCode();
      // get the value for this feature offset in src fs
      int val = getHeapValue(srcAddr + this.svd.casMetadata.featureOffset[featCode]);
      // if this is a string, create a new reference in the string
View Full Code Here

    //        ts.ll_isPrimitiveType -> ll_isRefType ->ll_getTypeClass -> ll_subsumes
    //        and along the way these are testing / comparing against type codes
    //        for built-in types which need to have been set.
   
    // Create top type.
    Type top = ts.addTopType(CAS.TYPE_NAME_TOP);
    // Add basic data types.
    Type intT = ts.addType(CAS.TYPE_NAME_INTEGER, top);
    Type floatT = ts.addType(CAS.TYPE_NAME_FLOAT, top);
    Type stringT = ts.addType(CAS.TYPE_NAME_STRING, top);
    // Add arrays.
    Type array = ts.addType(CAS.TYPE_NAME_ARRAY_BASE, top);
    ts.arrayBaseType = (TypeImpl)array;         // do here - used in next
    ts.arrayBaseTypeCode = ts.arrayBaseType.getCode();
    TypeImpl fsArray = (TypeImpl) ts.addType(CAS.TYPE_NAME_FS_ARRAY, array);
    ts.fsArrayType = fsArray;                   // do here - used in next
    ts.fsArrayTypeCode = fsArray.getCode();
    TypeImpl floatArray = (TypeImpl) ts.addType(CAS.TYPE_NAME_FLOAT_ARRAY, array);
    TypeImpl intArray = (TypeImpl) ts.addType(CAS.TYPE_NAME_INTEGER_ARRAY, array);
    TypeImpl stringArray = (TypeImpl) ts.addType(CAS.TYPE_NAME_STRING_ARRAY, array);
    // Add lists.
    Type list = ts.addType(CAS.TYPE_NAME_LIST_BASE, top);
    // FS lists.
    Type fsList = ts.addType(CAS.TYPE_NAME_FS_LIST, list);
    Type fsEList = ts.addType(CAS.TYPE_NAME_EMPTY_FS_LIST, fsList);
    Type fsNeList = ts.addType(CAS.TYPE_NAME_NON_EMPTY_FS_LIST, fsList);
    ts.addFeature(CAS.FEATURE_BASE_NAME_HEAD, fsNeList, top);
    ts.addFeature(CAS.FEATURE_BASE_NAME_TAIL, fsNeList, fsList);
    // Float lists.
    Type floatList = ts.addType(CAS.TYPE_NAME_FLOAT_LIST, list);
    Type floatEList = ts.addType(CAS.TYPE_NAME_EMPTY_FLOAT_LIST, floatList);
    Type floatNeList = ts.addType(CAS.TYPE_NAME_NON_EMPTY_FLOAT_LIST, floatList);
    ts.addFeature(CAS.FEATURE_BASE_NAME_HEAD, floatNeList, floatT);
    ts.addFeature(CAS.FEATURE_BASE_NAME_TAIL, floatNeList, floatList);
    // Integer lists.
    Type intList = ts.addType(CAS.TYPE_NAME_INTEGER_LIST, list);
    Type intEList = ts.addType(CAS.TYPE_NAME_EMPTY_INTEGER_LIST, intList);
    Type intNeList = ts.addType(CAS.TYPE_NAME_NON_EMPTY_INTEGER_LIST, intList);
    ts.addFeature(CAS.FEATURE_BASE_NAME_HEAD, intNeList, intT);
    ts.addFeature(CAS.FEATURE_BASE_NAME_TAIL, intNeList, intList);
    // String lists.
    Type stringList = ts.addType(CAS.TYPE_NAME_STRING_LIST, list);
    Type stringEList = ts.addType(CAS.TYPE_NAME_EMPTY_STRING_LIST, stringList);
    Type stringNeList = ts.addType(CAS.TYPE_NAME_NON_EMPTY_STRING_LIST, stringList);
    ts.addFeature(CAS.FEATURE_BASE_NAME_HEAD, stringNeList, stringT);
    ts.addFeature(CAS.FEATURE_BASE_NAME_TAIL, stringNeList, stringList);

    Type booleanT = ts.addType(CAS.TYPE_NAME_BOOLEAN, top);
    Type byteT = ts.addType(CAS.TYPE_NAME_BYTE, top);
    Type shortT = ts.addType(CAS.TYPE_NAME_SHORT, top);
    Type longT = ts.addType(CAS.TYPE_NAME_LONG, top);
    Type doubleT = ts.addType(CAS.TYPE_NAME_DOUBLE, top);

    // array type initialization must follow the component type it's based on
    TypeImpl booleanArray = (TypeImpl) ts.addType(CAS.TYPE_NAME_BOOLEAN_ARRAY, array);
    TypeImpl byteArray = (TypeImpl) ts.addType(CAS.TYPE_NAME_BYTE_ARRAY, array);
    TypeImpl shortArray = (TypeImpl) ts.addType(CAS.TYPE_NAME_SHORT_ARRAY, array);
    TypeImpl longArray = (TypeImpl) ts.addType(CAS.TYPE_NAME_LONG_ARRAY, array);
    TypeImpl doubleArray = (TypeImpl) ts.addType(CAS.TYPE_NAME_DOUBLE_ARRAY, array);

    // Sofa Stuff
    Type sofa = ts.addType(CAS.TYPE_NAME_SOFA, top);
    ts.addFeature(CAS.FEATURE_BASE_NAME_SOFANUM, sofa, intT);
    ts.addFeature(CAS.FEATURE_BASE_NAME_SOFAID, sofa, stringT);
    ts.addFeature(CAS.FEATURE_BASE_NAME_SOFAMIME, sofa, stringT);
    // Type localSofa = ts.addType(CAS.TYPE_NAME_LOCALSOFA, sofa);
    ts.addFeature(CAS.FEATURE_BASE_NAME_SOFAARRAY, sofa, top);
    ts.addFeature(CAS.FEATURE_BASE_NAME_SOFASTRING, sofa, stringT);
    // Type remoteSofa = ts.addType(CAS.TYPE_NAME_REMOTESOFA, sofa);
    ts.addFeature(CAS.FEATURE_BASE_NAME_SOFAURI, sofa, stringT);

    // Annotations
    Type annotBaseType = ts.addType(CAS.TYPE_NAME_ANNOTATION_BASE, top);
    ts.addFeature(CAS.FEATURE_BASE_NAME_SOFA, annotBaseType, sofa);
    Type annotType = ts.addType(CAS.TYPE_NAME_ANNOTATION, annotBaseType);
    ts.addFeature(CAS.FEATURE_BASE_NAME_BEGIN, annotType, intT);
    ts.addFeature(CAS.FEATURE_BASE_NAME_END, annotType, intT);
    Type docType = ts.addType(CAS.TYPE_NAME_DOCUMENT_ANNOTATION, annotType);
    ts.addFeature(CAS.FEATURE_BASE_NAME_LANGUAGE, docType, stringT);

    // Lock individual types.
    setTypeFinal(intT);
    setTypeFinal(floatT);
View Full Code Here

  //   "end" feature to be the length of the sofa string
  public void updateDocumentAnnotation() {
    if (!mySofaIsValid()) {
      return;
    }
    final Type SofaType = this.svd.casMetadata.ts.sofaType;
    final Feature sofaString = SofaType.getFeatureByBaseName(FEATURE_BASE_NAME_SOFASTRING);
    String newDoc = getSofa(this.mySofaRef).getStringValue(sofaString);
    if (null != newDoc) {
      getDocumentAnnotation().setIntValue(getEndFeature(), newDoc.length());
    }
  }
View Full Code Here

    return getNumberValue(parent, annotation, stream).floatValue();
  }

  private Number getNumberValue(RutaBlock parent, AnnotationFS annotation, RutaStream stream) {
    Number result = null;
    Type type = fe.getTypeExpr().getType(parent);
    Feature feature = fe.getFeature(parent);
    Type range = feature.getRange();
    List<AnnotationFS> list = getTargetAnnotation(annotation, type, stream);
    Collection<AnnotationFS> featureAnnotations = fe.getFeatureAnnotations(list, stream, parent,
            false);
    if (!featureAnnotations.isEmpty()) {
      AnnotationFS next = featureAnnotations.iterator().next();
      if (UIMAConstants.TYPE_BYTE.equals(range.getName())) {
        result = next.getByteValue(feature);
      } else if (UIMAConstants.TYPE_DOUBLE.equals(range.getName())) {
        result = next.getDoubleValue(feature);
      } else if (UIMAConstants.TYPE_FLOAT.equals(range.getName())) {
        result = next.getFloatValue(feature);
      } else if (UIMAConstants.TYPE_INTEGER.equals(range.getName())) {
        result = next.getIntValue(feature);
      } else if (UIMAConstants.TYPE_LONG.equals(range.getName())) {
        result = next.getLongValue(feature);
      } else if (UIMAConstants.TYPE_SHORT.equals(range.getName())) {
        result = next.getShortValue(feature);
      }
    }
    return result;
  }
View Full Code Here

    this.fe = fe;
  }

  @Override
  public String getStringValue(RutaBlock parent, AnnotationFS annotation, RutaStream stream) {
    Type type = fe.getTypeExpr().getType(parent);
    Feature feature = fe.getFeature(parent);
    List<AnnotationFS> list = getTargetAnnotation(annotation, type, stream);
    Collection<AnnotationFS> featureAnnotations = fe.getFeatureAnnotations(list, stream, parent,
            false);
    if (!featureAnnotations.isEmpty()) {
View Full Code Here

  }

  @Override
  public List<Feature> getFeatures(RutaBlock parent) {
    List<Feature> result = new ArrayList<Feature>();
    Type type = typeExpr.getType(parent);
    Feature feature = null;
    for (String each : features) {
      feature = type.getFeatureByBaseName(each);
      result.add(feature);
      type = feature.getRange();
    }
    return result;
  }
View Full Code Here

    }
    crowd.finished(stream);

    if (removeBasics) {
      List<AnnotationFS> toRemove = new ArrayList<AnnotationFS>();
      Type basicType = cas.getTypeSystem().getType(BASIC_TYPE);
      AnnotationIndex<AnnotationFS> basicIndex = cas.getAnnotationIndex(basicType);
      for (AnnotationFS fs : basicIndex) {
        toRemove.add(fs);
      }
      for (Type seedType : seedTypes) {
View Full Code Here

  private RutaStream initializeStream(CAS cas, InferenceCrowd crowd)
          throws AnalysisEngineProcessException {
    Collection<Type> filterTypes = new ArrayList<Type>();
    TypeSystem typeSystem = cas.getTypeSystem();
    for (String each : defaultFilteredTypes) {
      Type type = typeSystem.getType(each);
      if (type != null) {
        filterTypes.add(type);
      }
    }
    FilterManager filter = new FilterManager(filterTypes, cas);
    Type basicType = typeSystem.getType(BASIC_TYPE);
    seedTypes = seedAnnotations(cas);
    RutaStream stream = new RutaStream(cas, basicType, filter, lowMemoryProfile,
            simpleGreedyForComposed, crowd);

    stream.initalizeBasics();
View Full Code Here

TOP

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

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.