Java Code Examples for org.apache.uima.cas.TypeSystem#getFeatureByFullName()
The following examples show how to use
org.apache.uima.cas.TypeSystem#getFeatureByFullName() .
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 |
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 2
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 3
Source File: DebugFSLogicalStructure.java From uima-uimaj with Apache License 2.0 | 6 votes |
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 4
Source File: DebugFSLogicalStructure.java From uima-uimaj with Apache License 2.0 | 6 votes |
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 5
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 6
Source File: IndexSerializationTest.java From uima-uimaj with Apache License 2.0 | 6 votes |
/** * @see junit.framework.TestCase#setUp() */ protected void setUp() throws Exception { 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); annotationType = ts.getType(CAS.TYPE_NAME_ANNOTATION); assertTrue(annotationType != null); }
Example 7
Source File: SerializationNoMDTest.java From uima-uimaj with Apache License 2.0 | 6 votes |
/** * @see junit.framework.TestCase#setUp() */ public void setUp() throws Exception { 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); }
Example 8
Source File: XmiCompare.java From uima-uimaj with Apache License 2.0 | 5 votes |
private List<Runnable> sortFSArray(String typename, String featurename, CASImpl cas) { TypeSystem ts = cas.getTypeSystem(); Type type = ts.getType(typename); Feature feat = ts.getFeatureByFullName(typename + ":" + featurename); return cas.select(type).allViews().map(fs -> cc.sortFSArray((FSArray)fs.getFeatureValue(feat))).collect(Collectors.toList()); }
Example 9
Source File: XmiCompare.java From uima-uimaj with Apache License 2.0 | 5 votes |
private void sortStringArray(String t, String f, CASImpl cas) { TypeSystem ts = cas.getTypeSystem(); Type type = ts.getType(t); Feature feat = ts.getFeatureByFullName(t + ":" + f); cas.select(type).allViews().forEach(fs -> { StringArray sa = (StringArray) fs.getFeatureValue(feat); if (sa != null && sa.size() > 2) { Arrays.sort(sa._getTheArray()); } }); }
Example 10
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 11
Source File: XmiCompare.java From uima-uimaj with Apache License 2.0 | 5 votes |
void canonicalizeString(String t, String f, String[] filter, String cv, CASImpl cas) { TypeSystem ts = cas.getTypeSystem(); Type type = ts.getType(t); Feature feat = ts.getFeatureByFullName(t + ":" + f); cas.select(type).allViews().forEach(fs -> { String item = fs.getStringValue(feat); if (Misc.contains(filter, item)) { fs.setStringValue(feat, cv); } }); }
Example 12
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(); }