org.apache.uima.cas.TypeSystem Java Examples

The following examples show how to use org.apache.uima.cas.TypeSystem. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DebugFSLogicalStructure.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public static Object stringListToArray(FeatureStructure fs) {
  List<String> list = new ArrayList<>();
  TypeSystem ts = fs.getCAS().getTypeSystem();
  Type emptyFSList = ts.getType("uima.cas.EmptyStringList");
  Feature headFeature = ts.getFeatureByFullName("uima.cas.NonEmptyStringList:head");
  Feature tailFeature = ts.getFeatureByFullName("uima.cas.NonEmptyStringList:tail");

  Set<FeatureStructure> alreadySeen = new HashSet<>();
  FeatureStructure nextFs;
  for (FeatureStructure currentFs = fs; currentFs.getType() != emptyFSList; currentFs = nextFs) {
    list.add(currentFs.getStringValue(headFeature));
    nextFs = currentFs.getFeatureValue(tailFeature);
    if (alreadySeen.contains(nextFs)) {
      return loopInList(list);
    }
    alreadySeen.add(nextFs);
  }
  return list.toArray(new String[list.size()]);
}
 
Example #2
Source File: DebugFSLogicalStructure.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public static Object fsListToArray(FeatureStructure fs) {
  List<FeatureStructure> list = new ArrayList<>();
  TypeSystem ts = fs.getCAS().getTypeSystem();
  Type emptyFSList = ts.getType("uima.cas.EmptyFSList");
  Feature headFeature = ts.getFeatureByFullName("uima.cas.NonEmptyFSList:head");
  Feature tailFeature = ts.getFeatureByFullName("uima.cas.NonEmptyFSList:tail");

  Set<FeatureStructure> alreadySeen = new HashSet<>();
  FeatureStructure nextFs;
  for (FeatureStructure currentFs = fs; currentFs.getType() != emptyFSList; currentFs = nextFs) {
    list.add(currentFs.getFeatureValue(headFeature));
    nextFs = currentFs.getFeatureValue(tailFeature);
    if (alreadySeen.contains(nextFs)) {
      return loopInList(list);
    }
    alreadySeen.add(nextFs);
  }
  return list.toArray(new FeatureStructure[list.size()]);
}
 
Example #3
Source File: TypeSystemUtil.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Convert a {@link TypeSystem} to an equivalent {@link TypeSystemDescription}.
 * 
 * @param aTypeSystem
 *          type system object to convert
 * @return a TypeSystemDescription that is equivalent to <code>aTypeSystem</code>
 */
public static TypeSystemDescription typeSystem2TypeSystemDescription(TypeSystem aTypeSystem) {
  ResourceSpecifierFactory fact = UIMAFramework.getResourceSpecifierFactory();
  TypeSystemDescription tsDesc = fact.createTypeSystemDescription();
  Iterator<Type> typeIter = aTypeSystem.getTypeIterator();
  List<TypeDescription> typeDescs = new ArrayList<>();
  while (typeIter.hasNext()) {
    Type type = typeIter.next();
    if (!type.getName().startsWith("uima.cas") && !type.getName().equals("uima.tcas.Annotation") &&
        !type.isArray()) {
      typeDescs.add(type2TypeDescription(type, aTypeSystem));
    }
  }
  TypeDescription[] typeDescArr = new TypeDescription[typeDescs.size()];
  typeDescs.toArray(typeDescArr);
  tsDesc.setTypes(typeDescArr);

  return tsDesc;
}
 
Example #4
Source File: CasConsumerAdapter.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void checkTypeSystemChange(AbstractCas aCAS) throws AnalysisEngineProcessException {
  try {
    TypeSystem typeSystem;
    if (aCAS instanceof JCas) {
      typeSystem = ((JCas) aCAS).getTypeSystem();
    } else // CAS 
    {
      typeSystem = ((CAS) aCAS).getTypeSystem();
    }
    if (typeSystem != mLastTypeSystem) {
      mCasConsumer.typeSystemInit(typeSystem);
      mLastTypeSystem = typeSystem;
    }
  } catch (ResourceInitializationException e) {
    throw new AnalysisEngineProcessException(e);
  }
}
 
Example #5
Source File: AllTypes.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Update.
 */
// create a hash table of all types
private void update() {
  cachedResult.clear();

  CAS tcas = modelRoot.getCurrentView();
  if (null == tcas)
    return;
  TypeSystem typeSystem = tcas.getTypeSystem();

  if (typeSystem == null)
    return;

  Iterator typeIterator = typeSystem.getTypeIterator();

  while (typeIterator.hasNext()) {
    Type type = (Type) typeIterator.next();
    String typeName = type.getName();
    if (null != typeName && !typeName.endsWith("[]")) {
      cachedResult.put(type.getName(), type);
    }
  }
}
 
Example #6
Source File: StringArrayTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void testStringArrayNullValue() throws Exception{
   String lemmaListName = CASTestSetup.TOKEN_TYPE + TypeSystem.FEATURE_SEPARATOR
  + CASTestSetup.LEMMA_LIST_FEAT;
   final Feature lemmaList = this.ts.getFeatureByFullName(lemmaListName);
   assertTrue(lemmaList != null);
   StringArrayFS casArray = this.cas.createStringArrayFS(3);
   ((CASImpl)(casArray.getCAS())).setId2FSsMaybeUnconditionally(casArray);
   casArray.set(0, "1");
   casArray.set(1, null);
   casArray.set(2, "3");
   FeatureStructure token = this.cas.createFS(this.ts.getType(CASTestSetup.TOKEN_TYPE));
   assertTrue(token.getFeatureValue(lemmaList) == null);
   token.setFeatureValue(lemmaList, casArray);
   this.cas.addFsToIndexes(token);
   assertTrue(((StringArrayFS) token.getFeatureValue(lemmaList)).get(0) == "1");
   assertTrue(((StringArrayFS) token.getFeatureValue(lemmaList)).get(1) == null);
   LowLevelCAS llc = casArray.getCAS().getLowLevelCAS();
   assertTrue(llc.ll_getStringArrayValue(llc.ll_getFSRef(casArray), 1) == null);
}
 
Example #7
Source File: TypeSystemAnalysis.java    From webanno with Apache License 2.0 6 votes vote down vote up
private boolean isElevatedType(TypeSystem aTS, Type aType)
{
    // Elevated types do not contribute any new features
    if (aType.getFeatures().stream().anyMatch(f -> f.getDomain().equals(aType))) {
        return false;
    }
    
    // Elevated types have only sub-types which are also elevated types
    if (aTS.getDirectSubtypes(aType).stream().anyMatch(t -> !isElevatedType(aTS, t))) {
        return false;
    }
    
    // Elevated types do not inherit from Annotation
    if (aTS.getParent(aType).equals(aTS.getType(CAS.TYPE_NAME_ANNOTATION))) {
        return false;
    }
    
    // Hm, ok, so this looks like an elevated type
    return true;
}
 
Example #8
Source File: ResultSpecification_impl.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * @see org.apache.uima.analysis_engine.ResultSpecification#addCapabilities(org.apache.uima.resource.metadata.Capability[],
 *      boolean)
 */
public void addCapabilities(Capability[] capabilities, boolean outputs) {
  if (null == capabilities) {
    return;
  }
  for (Capability capability : capabilities) {
    TypeOrFeature[] tofs = outputs ? capability.getOutputs() : capability.getInputs();
    
    for (TypeOrFeature tof : tofs) {
      String typeName = tof.getName();
      if (!tof.isType()) {
        int i = typeName.indexOf(TypeSystem.FEATURE_SEPARATOR);
        String shortFeatName = typeName.substring(i+1);
        typeName = typeName.substring(0, i);
        rsTypesMap.add(typeName, shortFeatName, capability.getLanguagesSupported(), false);
      } else {
        rsTypesMap.add(typeName, tof.isAllAnnotatorFeatures(), capability.getLanguagesSupported(), false);
      }
    }
  }
  setCompileNeeded();
}
 
Example #9
Source File: TypeSystemTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void testGetFeatures() {
  Iterator<Feature> it = this.ts.getFeatures();
  // Put feature names in vector and test for some known features.
  List<String> v = new ArrayList<>();
  while (it.hasNext()) {
    v.add(it.next().getName());
  }
  String annotPrefix = CAS.TYPE_NAME_ANNOTATION + TypeSystem.FEATURE_SEPARATOR;
  String arrayPrefix = CAS.TYPE_NAME_ARRAY_BASE + TypeSystem.FEATURE_SEPARATOR;
  assertTrue(arrayPrefix != null);
  String tokenPrefix = CASTestSetup.TOKEN_TYPE + TypeSystem.FEATURE_SEPARATOR;
  assertTrue(v.contains(annotPrefix + CAS.FEATURE_BASE_NAME_BEGIN));
  assertTrue(v.contains(annotPrefix + CAS.FEATURE_BASE_NAME_END));
  assertTrue(v.contains(tokenPrefix + CASTestSetup.TOKEN_TYPE_FEAT));
  // assertTrue(v.contains(arrayPrefix + CAS.ARRAY_LENGTH_FEAT));
}
 
Example #10
Source File: CasDoctorUtils.java    From webanno with Apache License 2.0 6 votes vote down vote up
public static Map<FeatureStructure, FeatureStructure> getNonIndexedFSesWithOwner(CAS aCas)
{
    TypeSystem ts = aCas.getTypeSystem();
    
    LowLevelCAS llcas = aCas.getLowLevelCAS();

    Set<FeatureStructure> allIndexedFS = collectIndexed(aCas);
    Map<FeatureStructure, FeatureStructure> allReachableFS = new TreeMap<>(
        Comparator.comparingInt(llcas::ll_getFSRef));
    
    FSIterator<FeatureStructure> i = aCas.getIndexRepository().getAllIndexedFS(
            aCas.getTypeSystem().getTopType());

    i.forEachRemaining(fs -> collect(allReachableFS, allIndexedFS, fs, fs));

    // Remove all that are not annotations
    allReachableFS.entrySet().removeIf(e -> 
            !ts.subsumes(aCas.getAnnotationType(), e.getKey().getType()));
    
    // Remove all that are indexed
    allReachableFS.entrySet().removeIf(e -> e.getKey() == e.getValue());

    // All that is left are non-index annotations
    return allReachableFS;
}
 
Example #11
Source File: Primitives.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if is restricted by allowed values.
 *
 * @param ts the ts
 * @param type the type
 * @return true, if is restricted by allowed values
 */
public static boolean isRestrictedByAllowedValues(TypeSystem ts, Type type) {
  
  if (ts.getType(CAS.TYPE_NAME_STRING).equals(type) || 
          ts.subsumes(ts.getType(CAS.TYPE_NAME_STRING), type)) {
    LowLevelTypeSystem lts = ts.getLowLevelTypeSystem();
    final int typeCode = lts.ll_getCodeForType(type);
    String[] strings = lts.ll_getStringSet(typeCode);
    
    return strings.length > 0;
  }
  else {
    return false;
  }
  
}
 
Example #12
Source File: CollectionReaderAdapter.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void checkTypeSystemChange(AbstractCas aCAS) throws AnalysisEngineProcessException {
  try {
    TypeSystem typeSystem;
    if (aCAS instanceof JCas) {
      typeSystem = ((JCas) aCAS).getTypeSystem();
    } else // CAS
    {
      typeSystem = ((CAS) aCAS).getTypeSystem();
    }
    if (typeSystem != mLastTypeSystem) {
      mCollectionReader.typeSystemInit(typeSystem);
      mLastTypeSystem = typeSystem;
    }
  } catch (ResourceInitializationException e) {
    throw new AnalysisEngineProcessException(e);
  }
}
 
Example #13
Source File: AnnotationStyleViewPage.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
  
  if (newInput instanceof TypeSystem) {
    TypeSystem ts = (TypeSystem) newInput;
    
    List<Type> annotationTypeList = 
      ts.getProperlySubsumedTypes(ts.getType(CAS.TYPE_NAME_ANNOTATION));
    annotationTypeList.add(ts.getType(CAS.TYPE_NAME_ANNOTATION));
    
    annotationTypes = new AnnotationTypeNode[annotationTypeList.size()];
    
    for (int i = 0; i < annotationTypeList.size(); i++) {
      annotationTypes[i] = new AnnotationTypeNode(editor, annotationTypeList.get(i));
    }
  }
  else {
    annotationTypes = null;
  }
  
}
 
Example #14
Source File: AbstractRdfEntityGraphConsumer.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Override
public void doInitialize(UimaContext aContext) throws ResourceInitializationException {
  multiValueProperties = true;
  try {
    TypeSystem typeSystem = JCasFactory.createJCas().getTypeSystem();
    OwlSchemaFactory schemaFactory =
        new OwlSchemaFactory(namespace, typeSystem, Arrays.asList(ignoreProperties));
    documentOntology = schemaFactory.createEntityOntology();
  } catch (CASRuntimeException | UIMAException e) {
    throw new ResourceInitializationException(e);
  }
  super.doInitialize(aContext);
}
 
Example #15
Source File: PearCasPoolTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
private void core(int documentCount, int threadCount, int poolSize, 
    ResourceManager resourceManager) throws Exception {
  // setup CPM to process  documents
  CollectionProcessingEngine cpe = setupCpm(documentCount, threadCount, poolSize, resourceManager);

  // create and register a status callback listener
  TestStatusCallbackListener listener = new TestStatusCallbackListener() {
    TypeSystem sts = null;
    public void entityProcessComplete(CAS aCas, EntityProcessStatus aStatus) {
      super.entityProcessComplete(aCas, aStatus);
      if (sts == null) {
        sts = aCas.getTypeSystem();
      } else {
        Assert.assertTrue(sts == aCas.getTypeSystem());
      }
    }      
  };
  cpe.addStatusCallbackListener(listener);

  // run CPM
  cpe.process();

  // wait until CPM has finished
  while (!listener.isFinished()) {
    Thread.sleep(5);
  }
}
 
Example #16
Source File: Primitives.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the primitive value.
 *
 * @param structure the structure
 * @param feature the feature
 * @return the primitive value as object
 */
public static Object getPrimitive(FeatureStructure structure, Feature feature) {
  
  TypeSystem ts = structure.getCAS().getTypeSystem();
  
  Class<?> primitiveClass = getPrimitiveClass(ts, feature);
  
  Object result;

  if (Boolean.class.equals(primitiveClass)) {
    result = structure.getBooleanValue(feature);
  } else if (Byte.class.equals(primitiveClass)) {
    result = structure.getByteValue(feature);
  } else if (Short.class.equals(primitiveClass)) {
    result = structure.getShortValue(feature);
  } else if (Integer.class.equals(primitiveClass)) {
    result = structure.getIntValue(feature);
  } else if (Long.class.equals(primitiveClass)) {
    result = structure.getLongValue(feature);
  } else if (Float.class.equals(primitiveClass)) {
    result = structure.getFloatValue(feature);
  } else if (Double.class.equals(primitiveClass)) {
    result = structure.getDoubleValue(feature);
  } else if (String.class.equals(primitiveClass)) {
    result = structure.getStringValue(feature);
    
    if (result == null)
      result = "";
  } else {
    throw new IllegalStateException("Unexpected type: " 
        + feature.getRange().getName());
  }

  return result;
}
 
Example #17
Source File: AbstractRdfDocumentGraphConsumer.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Override
public void doInitialize(UimaContext aContext) throws ResourceInitializationException {
  outputDocument = true;

  try {
    TypeSystem typeSystem = JCasFactory.createJCas().getTypeSystem();
    OwlSchemaFactory schemaFactory =
        new OwlSchemaFactory(namespace, typeSystem, Arrays.asList(ignoreProperties));
    documentOntology = schemaFactory.createDocumentOntology();
  } catch (CASRuntimeException | UIMAException e) {
    throw new ResourceInitializationException(e);
  }
  super.doInitialize(aContext);
}
 
Example #18
Source File: WhiteboardFlowController2.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public void typeSystemInit(TypeSystem aTypeSystem) throws AnalysisEngineProcessException {
  super.typeSystemInit(aTypeSystem);
  // Iterate over available AEs and get the required input types of each AE.
  // Resolve those to Type handles in the TypeSystem and store this information in
  // the mComponentInfo field for use in routing.
  Iterator aeIter = getContext().getAnalysisEngineMetaDataMap().entrySet().iterator();
  while (aeIter.hasNext()) {
    Map.Entry entry = (Map.Entry) aeIter.next();
    String aeKey = (String) entry.getKey();
    AnalysisEngineMetaData md = (AnalysisEngineMetaData) entry.getValue();
    Capability[] capabilities = md.getCapabilities();

    ComponentInfo compInfo = new ComponentInfo();
    compInfo.key = aeKey;
    compInfo.inputTypesByCapability = new Type[capabilities.length][];

    for (int i = 0; i < capabilities.length; i++) {
      List inputTypes = new ArrayList();
      TypeOrFeature[] inputs = capabilities[i].getInputs();
      for (int j = 0; j < inputs.length; j++) {
        if (inputs[j].isType()) {
          Type typeHandle = aTypeSystem.getType(inputs[j].getName());
          if (typeHandle != null) {
            inputTypes.add(typeHandle);
          }
        }
      }
      compInfo.inputTypesByCapability[i] = new Type[inputTypes.size()];
      inputTypes.toArray(compInfo.inputTypesByCapability[i]);
    }
    mComponentInfo.add(compInfo);
  }
}
 
Example #19
Source File: ConcurrentTokenizer.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes the type system.
 */
public void typeSystemInit(TypeSystem typeSystem) throws AnalysisEngineProcessException {

    super.typeSystemInit(typeSystem);

    probabilityFeature = AnnotatorUtil.getOptionalFeatureParameter(context, tokenType,
                    UimaUtil.PROBABILITY_FEATURE_PARAMETER, CAS.TYPE_NAME_DOUBLE);
}
 
Example #20
Source File: CasPoolTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public void testPool() throws Exception {
  try {
         
    casManager.defineCasPool("uniqueString", 2, null);
    
    CAS c1 = casManager.getCas("uniqueString");
    CAS c2 = casManager.getCas("uniqueString");
    c1.getJCas();
    
    CAS c1v2 = c1.createView("view2");
    CAS c2v2 = c2.createView("view3");
    c2v2.getJCas();
    
    TypeSystem ts = c1.getTypeSystem();
    
    Assert.assertTrue(ts == c2.getTypeSystem());
    Assert.assertTrue(ts == c1v2.getTypeSystem());
    Assert.assertTrue(ts == c2v2.getTypeSystem());
    
    casManager.releaseCas(c1v2);
    casManager.releaseCas(c2);
    
    c1 = casManager.getCas("uniqueString");
    c1.createView("mappedName");
    RootUimaContext_impl rootContext = new RootUimaContext_impl();
    ChildUimaContext_impl context = new ChildUimaContext_impl(rootContext, "abc", Collections.singletonMap(CAS.NAME_DEFAULT_SOFA, "mappedName"));
    c1.setCurrentComponentInfo(context.getComponentInfo());
    casManager.releaseCas(c1);

  } catch (Exception e) {
    JUnitExtension.handleException(e);
  }
}
 
Example #21
Source File: FSCollectionFactory.java    From uima-uimafit with Apache License 2.0 5 votes vote down vote up
/**
 * Create a {@link Collection} of the given type of feature structures. This collection is backed
 * by the CAS, either via an {@link CAS#getAnnotationIndex(Type)} or
 * {@link FSIndexRepository#getAllIndexedFS(Type)}.
 * 
 * @param cas
 *          the CAS to select from.
 * @param type
 *          the type of feature structures to select. All sub-types are returned as well.
 * @return a {@link Collection} of the given type of feature structures backed live by the CAS.
 * @see <a href="package-summary.html#SortOrder">Order of selected feature structures</a>
 * @deprecated Use {@code cas.select(type).asList()}
 */
@Deprecated
@SuppressWarnings({ "unchecked", "rawtypes" })
public static List<FeatureStructure> create(CAS cas, Type type) {
  // If the type is an annotation type, we can use the annotation index, which directly
  // provides us with its size. If not, we have to use getAllIndexedFS() which we have to
  // scan from beginning to end in order to determine its size.
  TypeSystem ts = cas.getTypeSystem();
  if (ts.subsumes(cas.getAnnotationType(), type)) {
    return (List) create(cas.getAnnotationIndex(type));
  } else {
    return (List) cas.select(type).asList();
  }
}
 
Example #22
Source File: FSCollectionFactory.java    From uima-uimafit with Apache License 2.0 5 votes vote down vote up
public static <T extends TOP> FSList<T> createFSList(CAS aCas, Collection<T> aValues) {
  if (aValues == null) {
    return null;
  }
  
  TypeSystem ts = aCas.getTypeSystem();

  if (aValues.size() == 0) {
    return aCas.emptyFSList();
  }
  
  Type nonEmptyType = ts.getType(CAS.TYPE_NAME_NON_EMPTY_FS_LIST);
  Feature headFeature = nonEmptyType.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_HEAD);
  Feature tailFeature = nonEmptyType.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_TAIL);

  FeatureStructure head = aCas.createFS(nonEmptyType);
  FeatureStructure list = head;
  Iterator<? extends FeatureStructure> i = aValues.iterator();
  while (i.hasNext()) {
    head.setFeatureValue(headFeature, i.next());
    if (i.hasNext()) {
      FeatureStructure tail = aCas.createFS(nonEmptyType);
      head.setFeatureValue(tailFeature, tail);
      head = tail;
    } else {
      head.setFeatureValue(tailFeature, aCas.emptyFSList());
    }
  }

  return (FSList<T>) list;
}
 
Example #23
Source File: LinearTypeOrderBuilderImpl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
private static int[] encodeTypeList(String[] typeList, TypeSystem ts) throws CASException {
  int[] a = new int[typeList.length];
  LowLevelTypeSystem llts = (LowLevelTypeSystem) ts;
  for (int i = 0; i < a.length; i++) {
    int t = llts.ll_getCodeForTypeName(typeList[i]);
    if (t == LowLevelTypeSystem.UNKNOWN_TYPE_CODE) {
      throw new CASException(CASException.TYPEORDER_UNKNOWN_TYPE, typeList[i]);
    }
    a[i] = t;
  }
  return a;
}
 
Example #24
Source File: FSCollectionFactory.java    From uima-uimafit with Apache License 2.0 5 votes vote down vote up
public static <T extends FeatureStructure> T createFloatList(CAS aCas, Collection<Float> aValues) {
  if (aValues == null) {
    return null;
  }
  
  TypeSystem ts = aCas.getTypeSystem();

  Type emptyType = ts.getType(CAS.TYPE_NAME_EMPTY_FLOAT_LIST);

  if (aValues.size() == 0) {
    return aCas.createFS(emptyType);
  }
  
  Type nonEmptyType = ts.getType(CAS.TYPE_NAME_NON_EMPTY_FLOAT_LIST);
  Feature headFeature = nonEmptyType.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_HEAD);
  Feature tailFeature = nonEmptyType.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_TAIL);

  FeatureStructure head = aCas.createFS(nonEmptyType);
  FeatureStructure list = head;
  Iterator<Float> i = aValues.iterator();
  while (i.hasNext()) {
    head.setFloatValue(headFeature, i.next());
    if (i.hasNext()) {
      FeatureStructure tail = aCas.createFS(nonEmptyType);
      head.setFeatureValue(tailFeature, tail);
      head = tail;
    } else {
      head.setFeatureValue(tailFeature, aCas.createFS(emptyType));
    }
  }

  return (T) list;
}
 
Example #25
Source File: FSCollectionFactory.java    From uima-uimafit with Apache License 2.0 5 votes vote down vote up
public static <T extends FeatureStructure> T createIntegerList(CAS aCas, int... aValues) {
  if (aValues == null) {
    return null;
  }
  
  TypeSystem ts = aCas.getTypeSystem();

  Type emptyType = ts.getType(CAS.TYPE_NAME_EMPTY_INTEGER_LIST);

  if (aValues.length == 0) {
    return aCas.createFS(emptyType);
  }
  
  Type nonEmptyType = ts.getType(CAS.TYPE_NAME_NON_EMPTY_INTEGER_LIST);
  Feature headFeature = nonEmptyType.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_HEAD);
  Feature tailFeature = nonEmptyType.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_TAIL);

  FeatureStructure head = aCas.createFS(nonEmptyType);
  FeatureStructure list = head;
  int i = 0;
  while (i < aValues.length) {
    head.setIntValue(headFeature, aValues[i]);
    i++;
    if (i < aValues.length) {
      FeatureStructure tail = aCas.createFS(nonEmptyType);
      head.setFeatureValue(tailFeature, tail);
      head = tail;
    } else {
      head.setFeatureValue(tailFeature, aCas.createFS(emptyType));
    }
  }

  return (T) list;
}
 
Example #26
Source File: FSCollectionFactory.java    From uima-uimafit with Apache License 2.0 5 votes vote down vote up
public static <T extends FeatureStructure> T createIntegerList(CAS aCas, Collection<Integer> aValues) {
  if (aValues == null) {
    return null;
  }
  
  TypeSystem ts = aCas.getTypeSystem();

  Type emptyType = ts.getType(CAS.TYPE_NAME_EMPTY_INTEGER_LIST);

  if (aValues.size() == 0) {
    return aCas.createFS(emptyType);
  }
  
  Type nonEmptyType = ts.getType(CAS.TYPE_NAME_NON_EMPTY_INTEGER_LIST);
  Feature headFeature = nonEmptyType.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_HEAD);
  Feature tailFeature = nonEmptyType.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_TAIL);

  FeatureStructure head = aCas.createFS(nonEmptyType);
  FeatureStructure list = head;
  Iterator<Integer> i = aValues.iterator();
  while (i.hasNext()) {
    head.setIntValue(headFeature, i.next());
    if (i.hasNext()) {
      FeatureStructure tail = aCas.createFS(nonEmptyType);
      head.setFeatureValue(tailFeature, tail);
      head = tail;
    } else {
      head.setFeatureValue(tailFeature, aCas.createFS(emptyType));
    }
  }

  return (T) list;
}
 
Example #27
Source File: XmiCompare.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
private void fixupComponentId(String t, String s1, String s2, CASImpl cas) {
  TypeSystem ts = cas.getTypeSystem();
  Type type = ts.getType(t);
  Feature f_componentId = type.getFeatureByBaseName("componentId");
  cas.select(type)
     .allViews()
     .filter(fs -> s1.equals(fs.getStringValue(f_componentId)))
     .forEach(fs -> {
         fs.setStringValue(f_componentId, s2);
       });    
}
 
Example #28
Source File: RsType.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * returns the Features for a type in a result spec 
 * @param ts The type system, may be null
 * @return list of features for a type in a result spec
 */
List<Feature> getAllAppropriateFeatures(final TypeSystem ts) {
  if (null == ts) {
    return EMPTY_FEATURE_LIST;
  }
  Type t = ts.getType(typeName);
  return (null == t) ? EMPTY_FEATURE_LIST : t.getFeatures();
}
 
Example #29
Source File: TypeGroupedContentProvider.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Override
 public void changed() {
	nameAnnotationTypeNodeMap.clear();
	
	TypeSystem typeSystem = mInputDocument.getCAS().getTypeSystem();
	
	List<Type> types = typeSystem.getProperlySubsumedTypes(
			typeSystem.getType(CAS.TYPE_NAME_ANNOTATION));
	
	types.add(typeSystem.getType(CAS.TYPE_NAME_ANNOTATION));
	
	for (Type type : types) {
		
		AnnotationTypeTreeNode typeNode = new AnnotationTypeTreeNode(type);
		
		nameAnnotationTypeNodeMap.put(type.getName(), typeNode);
		
		CAS cas = mInputDocument.getCAS();
		
		AnnotationIndex<AnnotationFS> index = cas.getAnnotationIndex(type);

		for (AnnotationFS annotation : index) {
			if (annotation.getType().equals(type)) {
				typeNode.add(new AnnotationTreeNode(mInputDocument, annotation));
			}
		}
	}

     Display.getDefault().syncExec(new Runnable() {
       @Override
       public void run() {
       	viewer.refresh();
       }
     });
}
 
Example #30
Source File: IntVectorTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public void testPool() throws Exception {
  try {
    
    AnalysisEngineDescription aed = (AnalysisEngineDescription)UIMAFramework.getXMLParser().parse(
            new XMLInputSource(JUnitExtension
                    .getFile("TextAnalysisEngineImplTest/TestPrimitiveTae1.xml")));
    
    AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(aed);

    // define a caspool of size 2
    CasManager cm = ((UimaContext_ImplBase)ae.getUimaContext()).getResourceManager().getCasManager();
    cm.defineCasPool("uniqueString", 2, null);
    
    CAS c1 = cm.getCas("uniqueString");
    CAS c2 = cm.getCas("uniqueString");
    c1.getJCas();
    
    CAS c1v2 = c1.createView("view2");
    CAS c2v2 = c2.createView("view3");
    c2v2.getJCas();
    
    TypeSystem ts = c1.getTypeSystem();
    
    Assert.assertTrue(ts == c2.getTypeSystem());
    Assert.assertTrue(ts == c1v2.getTypeSystem());
    Assert.assertTrue(ts == c2v2.getTypeSystem());

  } catch (Exception e) {
    JUnitExtension.handleException(e);
  }
}