Java Code Examples for org.apache.uima.cas.TypeSystem#getType()
The following examples show how to use
org.apache.uima.cas.TypeSystem#getType() .
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: CASArtifact.java From biomedicus with Apache License 2.0 | 6 votes |
CASArtifact( @Nullable LabelAdapters labelAdapters, CAS cas ) { this.labelAdapters = labelAdapters; this.cas = cas; TypeSystem typeSystem = cas.getTypeSystem(); metadataType = typeSystem.getType("ArtifactMetadata"); keyFeature = metadataType.getFeatureByBaseName("key"); valueFeature = metadataType.getFeatureByBaseName("value"); metadataCas = cas.getView("metadata"); Type idType = typeSystem.getType("ArtifactID"); Feature idFeat = idType.getFeatureByBaseName("artifactID"); FSIndexRepository indexRepository = metadataCas.getIndexRepository(); artifactID = indexRepository.getIndex("artifactID", idType).iterator().get() .getStringValue(idFeat); metadataIndex = indexRepository.getIndex("metadata", metadataType); casMetadata = new CASMetadata(); }
Example 2
Source File: AnnotationFeaturesViewer.java From uima-uimaj with Apache License 2.0 | 6 votes |
/** * Gets the feature names for type. * * @param aTypeName the a type name * @param cas the cas * @return the feature names for type */ // untimely ripped from UIMA since it does not work with a taeDescription private String[] getFeatureNamesForType(String aTypeName, CAS cas) { TypeSystem ts = cas.getTypeSystem(); Type t = ts.getType(aTypeName); if (t != null) { List features = t.getFeatures(); String[] featNames = new String[features.size()]; for (int i = 0; i < features.size(); i++) { Feature f = (Feature) features.get(i); featNames[i] = f.getShortName(); } return featNames; } else { return null; } }
Example 3
Source File: DebugFSLogicalStructure.java From uima-uimaj with Apache License 2.0 | 6 votes |
public static Object integerListToArray(FeatureStructure fs) { List<Integer> list = new ArrayList<>(); TypeSystem ts = fs.getCAS().getTypeSystem(); Type emptyFSList = ts.getType("uima.cas.EmptyIntegerList"); Feature headFeature = ts.getFeatureByFullName("uima.cas.NonEmptyIntegerList:head"); Feature tailFeature = ts.getFeatureByFullName("uima.cas.NonEmptyIntegerList:tail"); Set<FeatureStructure> alreadySeen = new HashSet<>(); FeatureStructure nextFs; for (FeatureStructure currentFs = fs; currentFs.getType() != emptyFSList; currentFs = nextFs) { list.add(currentFs.getIntValue(headFeature)); nextFs = currentFs.getFeatureValue(tailFeature); if (alreadySeen.contains(nextFs)) { return loopInList(list); } alreadySeen.add(nextFs); } int[] intArray = new int[list.size()]; for (int i = 0; i < intArray.length; i++) { intArray[i] = list.get(i); } return intArray; }
Example 4
Source File: XCasToCasDataSaxHandlerTest.java From uima-uimaj with Apache License 2.0 | 6 votes |
/** * @param casData * @param system */ private void assertValidCasData(CasData casData, TypeSystem typeSystem) { Type annotType = typeSystem.getType(CAS.TYPE_NAME_ANNOTATION); Type arrayType = typeSystem.getType(CAS.TYPE_NAME_ARRAY_BASE); Iterator<FeatureStructure> fsIter = casData.getFeatureStructures(); while (fsIter.hasNext()) { org.apache.uima.cas_data.FeatureStructure fs = fsIter.next(); String typeName = fs.getType(); // don't do tests on the "fake" document text FS if (XCASSerializer.DEFAULT_DOC_TYPE_NAME.equals(typeName)) continue; Type type = typeSystem.getType(typeName); Assert.assertNotNull(type); if (typeSystem.subsumes(annotType, type)) { // annotation type - check for presence of begin/end FeatureValue beginVal = fs.getFeatureValue("begin"); Assert.assertTrue(beginVal instanceof PrimitiveValue); Assert.assertTrue(((PrimitiveValue) beginVal).toInt() >= 0); FeatureValue endVal = fs.getFeatureValue("end"); Assert.assertTrue(endVal instanceof PrimitiveValue); Assert.assertTrue(((PrimitiveValue) endVal).toInt() >= 0); } } }
Example 5
Source File: DebugFSLogicalStructure.java From uima-uimaj with Apache License 2.0 | 6 votes |
public static Object floatListToArray(FeatureStructure fs) { List<Float> list = new ArrayList<>(); TypeSystem ts = fs.getCAS().getTypeSystem(); Type emptyFSList = ts.getType("uima.cas.EmptyFloatList"); Feature headFeature = ts.getFeatureByFullName("uima.cas.NonEmptyFloatList:head"); Feature tailFeature = ts.getFeatureByFullName("uima.cas.NonEmptyFloatList:tail"); Set<FeatureStructure> alreadySeen = new HashSet<>(); FeatureStructure nextFs; for (FeatureStructure currentFs = fs; currentFs.getType() != emptyFSList; currentFs = nextFs) { list.add(currentFs.getFloatValue(headFeature)); nextFs = currentFs.getFeatureValue(tailFeature); if (alreadySeen.contains(nextFs)) { return loopInList(list); } alreadySeen.add(nextFs); } float[] floatArray = new float[list.size()]; for (int i = 0; i < floatArray.length; i++) { floatArray[i] = list.get(i); } return floatArray; }
Example 6
Source File: TypeSystemAnalysis.java From webanno with Apache License 2.0 | 6 votes |
private void analyzeFeatures(AnnotationLayer aLayer, TypeSystem aTS, TypeDescription aTD, Optional<? extends LayerDetails> aDetails) { Type type = aTS.getType(aTD.getName()); for (FeatureDescription fd : aTD.getFeatures()) { Feature feat = type.getFeatureByBaseName(fd.getName()); // We do not need to set up built-in features if (isBuiltInFeature(feat)) { continue; } if (aDetails.isPresent() && aDetails.get().isHiddenFeature(feat)) { continue; } AnnotationFeature f = analyzeFeature(aTS, fd, feat); features.put(aLayer.getName(), f); } }
Example 7
Source File: CASTestSetup.java From uima-uimaj with Apache License 2.0 | 6 votes |
public void initIndexes(FSIndexRepositoryMgr irm, TypeSystem ts) { FSIndexComparator comp = irm.createComparator(); Type annotation = ts.getType(CAS.TYPE_NAME_ANNOTATION); comp.setType(annotation); comp.addKey(annotation.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_BEGIN), FSIndexComparator.STANDARD_COMPARE); comp.addKey(annotation.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_END), FSIndexComparator.REVERSE_STANDARD_COMPARE); irm.createIndex(comp, ANNOT_BAG_INDEX, FSIndex.BAG_INDEX); irm.createIndex(comp, ANNOT_SET_INDEX, FSIndex.SET_INDEX); comp = irm.createComparator(); comp.setType(ts.getType("uima.cas.TOP")); irm.createIndex(comp, "all", FSIndex.BAG_INDEX); }
Example 8
Source File: StringSubtypeTest.java From uima-uimaj with Apache License 2.0 | 6 votes |
public void testCas() { CAS cas = this.jcas.getCas(); TypeSystem ts = cas.getTypeSystem(); Type annotType = ts.getType(annotationTypeName); FeatureStructure fs = cas.createFS(annotType); Feature stringSetFeat = ts.getFeatureByFullName(annotationTypeName + TypeSystem.FEATURE_SEPARATOR + stringSetFeatureName); fs.setStringValue(stringSetFeat, definedValue1); fs.setStringValue(stringSetFeat, definedValue2); fs.setStringValue(stringSetFeat, definedValue3); // next should be ok https://issues.apache.org/jira/browse/UIMA-1839 fs.setStringValue(stringSetFeat, null); boolean exCaught = false; try { fs.setStringValue(stringSetFeat, undefinedValue); } catch (CASRuntimeException e) { exCaught = true; } assertTrue(exCaught); }
Example 9
Source File: RegExAnnotator.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * Acquires references to CAS Type and Feature objects that are later used during the * {@link #process(CAS)} method. * * @see CasAnnotator_ImplBase#typeSystemInit(TypeSystem) */ public void typeSystemInit(TypeSystem aTypeSystem) throws AnalysisEngineProcessException { // get references to annotation types we will create mCASTypes = new Type[mTypeNames.size()]; for (int i = 0; i < mTypeNames.size(); i++) { String curTypeName = (String) mTypeNames.get(i); mCASTypes[i] = aTypeSystem.getType(curTypeName); if (mCASTypes[i] == null) { throw new AnalysisEngineProcessException(AnnotatorInitializationException.TYPE_NOT_FOUND, new Object[] { this.getClass().getName(), curTypeName }); } } // get references to Containing Annotation Types if (mContainingAnnotationTypeNames == null) { mContainingAnnotationTypes = null; } else { mContainingAnnotationTypes = new Type[mContainingAnnotationTypeNames.length]; for (int i = 0; i < mContainingAnnotationTypes.length; i++) { mContainingAnnotationTypes[i] = aTypeSystem.getType(mContainingAnnotationTypeNames[i]); if (mContainingAnnotationTypes[i] == null) { throw new AnalysisEngineProcessException(AnnotatorInitializationException.TYPE_NOT_FOUND, new Object[] { getClass().getName(), mContainingAnnotationTypeNames[i] }); } } } }
Example 10
Source File: PropertyCasMapping.java From biomedicus with Apache License 2.0 | 5 votes |
@Nullable AnnotationFS getAnnotation(CAS cas, int begin, int end, int value) { if (begin < 0) { throw new IllegalArgumentException("Begin: " + begin + "before 0."); } if (end < begin) { throw new IllegalArgumentException( annotationClassName + " - illegal annotation span at begin: " + begin + " end: " + end); } if (!zeroLengthEmitted && end == begin) { return null; } TypeSystem typeSystem = cas.getTypeSystem(); Type type = typeSystem.getType(annotationClassName); if (type == null) { throw new IllegalStateException("Annotation class not found: " + annotationClassName); } AnnotationFS annotation = cas.createAnnotation(type, begin, end); if (valueIncluded) { Feature valueFeature = type.getFeatureByBaseName("value"); annotation.setIntValue(valueFeature, value); } return annotation; }
Example 11
Source File: XmiCompare.java From uima-uimaj with Apache License 2.0 | 5 votes |
void canonicalizeStringFirstVariant(String t, String f, String v, CASImpl cas) { TypeSystem ts = cas.getTypeSystem(); Type type = ts.getType(t); Feature feat = ts.getFeatureByFullName(t + ":" + f); Feature featv = ts.getFeatureByFullName(t + ":" + v); // v is the variant array cas.select(type).allViews().forEach(fs -> { StringArray sa = (StringArray) fs.getFeatureValue(featv); if (sa != null && sa.size() > 2) { String item = fs.getStringValue(feat); if (sa.contains(item)) { fs.setStringValue(feat, sa.get(0)); } } }); }
Example 12
Source File: FSCollectionFactory.java From uima-uimafit with Apache License 2.0 | 5 votes |
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 13
Source File: FSCollectionFactory.java From uima-uimafit with Apache License 2.0 | 5 votes |
public static <T extends FeatureStructure> T createFloatList(CAS aCas, float... aValues) { if (aValues == null) { return null; } TypeSystem ts = aCas.getTypeSystem(); Type emptyType = ts.getType(CAS.TYPE_NAME_EMPTY_FLOAT_LIST); if (aValues.length == 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; int i = 0; while (i < aValues.length) { head.setFloatValue(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 14
Source File: FSCollectionFactory.java From uima-uimafit with Apache License 2.0 | 5 votes |
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 15
Source File: XmiCompare.java From uima-uimaj with Apache License 2.0 | 5 votes |
private void v2FixupMentionType_mi(String t, CASImpl cas) { TypeSystem ts = cas.getTypeSystem(); Type type = ts.getType(t); Feature f_mentionType = type.getFeatureByBaseName("mentionType"); Feature f_componentId = type.getFeatureByBaseName("componentId"); cas.select(type) .allViews() .filter(fs -> "R2/2.2.2/Main/UNITOFM/_mi".equals(fs.getStringValue(f_componentId))) .forEach(fs -> { fs.setStringValue(f_componentId, "R2/2.2.2/Main/UNITOFM/_mile"); fs.setStringValue(f_mentionType, "CATEGORY"); }); }
Example 16
Source File: FSCollectionFactory.java From uima-uimafit with Apache License 2.0 | 5 votes |
public static <T extends FeatureStructure> T createStringList(CAS aCas, Collection<String> aValues) { if (aValues == null) { return null; } TypeSystem ts = aCas.getTypeSystem(); Type emptyType = ts.getType(CAS.TYPE_NAME_EMPTY_STRING_LIST); if (aValues.size() == 0) { return aCas.createFS(emptyType); } Type nonEmptyType = ts.getType(CAS.TYPE_NAME_NON_EMPTY_STRING_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<String> i = aValues.iterator(); while (i.hasNext()) { head.setStringValue(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 17
Source File: SerializationReinitTest.java From uima-uimaj with Apache License 2.0 | 4 votes |
/** * @see junit.framework.TestCase#setUp() */ public void setUp() throws Exception { /** * sets up two type systems: * One defined via API calls, and set into the global var cas = casMgr * One defined by parsing ExampleCas/testTypeSystem and setting * typeSystem and indexes */ super.setUp(); casMgr = initCAS(); cas = (CASImpl)casMgr; TypeSystem ts = cas.getTypeSystem(); wordType = ts.getType(WORD_TYPE); // assert(wordType != null); separatorType = ts.getType(SEP_TYPE); eosType = ts.getType(EOS_TYPE); tokenType = ts.getType(TOKEN_TYPE); tokenTypeFeature = ts.getFeatureByFullName(TOKEN_TYPE_FEAT_Q); startFeature = ts.getFeatureByFullName(CAS.FEATURE_FULL_NAME_BEGIN); endFeature = ts.getFeatureByFullName(CAS.FEATURE_FULL_NAME_END); sentenceType = ts.getType(SENT_TYPE); strSub1 = ts.getType(STRING_SUBTYPE_1); assertTrue(strSub1 != null); theTypeType = ts.getType(OSTR_TYPE); theStringFeature = ts.getFeatureByFullName(OSTR_TYPE + TypeSystem.FEATURE_SEPARATOR + OSTR_TYPE_FEAT); theByteFeature = ts.getFeatureByFullName(OSTR_TYPE + TypeSystem.FEATURE_SEPARATOR + OBYTE_TYPE_FEAT); theByteArrayFeature = ts.getFeatureByFullName(OSTR_TYPE + TypeSystem.FEATURE_SEPARATOR + OBYTEA_TYPE_FEAT); theShortFeature = ts.getFeatureByFullName(OSTR_TYPE + TypeSystem.FEATURE_SEPARATOR + OSHORT_TYPE_FEAT); theShortArrayFeature = ts.getFeatureByFullName(OSTR_TYPE + TypeSystem.FEATURE_SEPARATOR + OSHORTA_TYPE_FEAT); theLongFeature = ts.getFeatureByFullName(OSTR_TYPE + TypeSystem.FEATURE_SEPARATOR + OLONG_TYPE_FEAT); theLongArrayFeature = ts.getFeatureByFullName(OSTR_TYPE + TypeSystem.FEATURE_SEPARATOR + OLONGA_TYPE_FEAT); File typeSystemFile = JUnitExtension.getFile("ExampleCas/testTypeSystem.xml"); File indexesFile = JUnitExtension.getFile("ExampleCas/testIndexes.xml"); typeSystem = UIMAFramework.getXMLParser().parseTypeSystemDescription( new XMLInputSource(typeSystemFile)); indexes = UIMAFramework.getXMLParser().parseFsIndexCollection(new XMLInputSource(indexesFile)) .getFsIndexes(); }
Example 18
Source File: ComplexTypeTest.java From webanno with Apache License 2.0 | 4 votes |
@Test public void testCountryType() throws Exception { TypeSystemDescription tsd = TypeSystemDescriptionFactory .createTypeSystemDescription("desc.types.TestTypeSystemDescriptor"); CAS cas = CasCreationUtils.createCas(tsd, null, null); cas.setDocumentText("Asia is the largest continent on Earth. Asia is subdivided into 48 " + "countries, two of them (Russia and Turkey) having part of their land in " + "Europe. The most active place on Earth for tropical cyclone activity lies " + "northeast of the Philippines and south of Japan. The Gobi Desert is in " + "Mongolia and the Arabian Desert stretches across much of the Middle East. " + "The Yangtze River in China is the longest river in the continent. The " + "Himalayas between Nepal and China is the tallest mountain range in the " + "world. Tropical rainforests stretch across much of southern Asia and " + "coniferous and deciduous forests lie farther north."); TypeSystem ts = cas.getTypeSystem(); Type continentType = ts.getType("de.Continent"); Feature continentName = continentType.getFeatureByBaseName("name"); AnnotationFS asiaContinent = cas.createAnnotation(continentType, 0, 4); asiaContinent.setStringValue(continentName, "Asia"); cas.addFsToIndexes(asiaContinent); Type countryType = ts.getType("de.Country"); Feature countryName = countryType.getFeatureByBaseName("name"); AnnotationFS russia = cas.createAnnotation(countryType, 56, 62); russia.setStringValue(countryName, "Russian Federation"); Feature continentFeature = countryType.getFeatureByBaseName("continent"); russia.setFeatureValue(continentFeature, asiaContinent); cas.addFsToIndexes(russia); ConstraintsGrammar parser = new ConstraintsGrammar(new FileInputStream( "src/test/resources/rules/region.rules")); ParsedConstraints constraints = parser.Parse().accept(new ParserVisitor()); Evaluator constraintsEvaluator = new ValuesGenerator(); List<PossibleValue> possibleValues = constraintsEvaluator.generatePossibleValues(russia, "regionType", constraints); List<PossibleValue> exValues = new LinkedList<>(); exValues.add(new PossibleValue("cold", true)); assertEquals(possibleValues, exValues); }
Example 19
Source File: XmlDetagger.java From uima-uimaj with Apache License 2.0 | 4 votes |
public void typeSystemInit(TypeSystem aTypeSystem) throws AnalysisEngineProcessException { sourceDocInfoType = aTypeSystem.getType("org.apache.uima.examples.SourceDocumentInformation"); }
Example 20
Source File: SerializationNoMDTest.java From uima-uimaj with Apache License 2.0 | 4 votes |
private void checkSentences() { TypeSystem ts = cas.getTypeSystem(); Type localSentenceType = ts.getType(SENT_TYPE); // Feature tokenTypeFeature = ts.getFeatureByFullName(TOKEN_TYPE_FEAT); // Feature startFeature = ts.getFeatureByFullName(CAS.FEATURE_BASE_NAME_BEGIN); // Feature endFeature = ts.getFeatureByFullName(CAS.FEATURE_BASE_NAME_END); // Print the first few sentences. // System.out.println("\nThe first 10 sentences:\n"); FSIndex<AnnotationFS> sentenceIndex = cas.getAnnotationIndex(localSentenceType); FSIterator<AnnotationFS> it = sentenceIndex.iterator(); AnnotationFS sentFS; if (it.isValid()) { sentFS = it.get(); assertTrue(sentFS.getCoveredText() != null); } // int counter = 0; String text = cas.getDocumentText(); assertTrue(text != null); // while (it.isValid() && counter < 10) { // sentFS = (AnnotationFS)it.get(); // System.out.println( // "Sentence: " // + sentFS.getCoveredText()); // it.moveToNext(); // ++counter; // } // Now get an iterator over all annotations. FSIndex<AnnotationFS> annotIndex = cas.getAnnotationIndex(); // System.out.println("\nNumber of annotations in index: " + annotIndex.size()); // Print the first few sentences. // System.out.println("The first 50 annotations:\n"); it = annotIndex.iterator(); // assert(it.isValid()); // counter = 0; // AnnotationFS fs; // while (it.isValid() && counter < 50) { // fs = (AnnotationFS)it.get(); // System.out.print(fs.getType().getName() + ": "); // if (fs.getType().getName().equals(CASMgr.DOCUMENT_TYPE)) { // // When we see the document, we don't print the whole text ;-) // System.out.println("..."); // } else { // System.out.println( // fs.getCoveredText()); // } // it.moveToNext(); // ++counter; // } }