Java Code Examples for org.apache.uima.cas.FeatureStructure#getType()
The following examples show how to use
org.apache.uima.cas.FeatureStructure#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: AbstractJsonConsumer.java From baleen with Apache License 2.0 | 6 votes |
/** * Write an annotation to the file. * * @param generator the generator * @param annotation the annotation * @throws IOException Signals that an I/O exception has occurred. */ private void writeFS(JsonGenerator generator, FeatureStructure annotation) throws IOException { generator.writeStartObject(); Type type = annotation.getType(); generator.writeStringField("type", type.getName()); List<Feature> features = type.getFeatures(); if (annotation instanceof AnnotationFS) { AnnotationFS annotationFS = (AnnotationFS) annotation; if (!(annotationFS.getEnd() == 0 && annotationFS.getBegin() == 0)) { generator.writeStringField("coveredText", annotationFS.getCoveredText()); } } if (!features.isEmpty()) { writeFS(generator, annotation, features); } generator.writeEndObject(); }
Example 2
Source File: ConstraintsVerifier.java From webanno with Apache License 2.0 | 6 votes |
@Override public boolean verify(FeatureStructure featureStructure, ParsedConstraints parsedConstraints) { boolean isOk = false; Type type = featureStructure.getType(); for (Feature feature : type.getFeatures()) { if (feature.getRange().isPrimitive()) { String scopeName = featureStructure.getFeatureValueAsString(feature); List<Rule> rules = parsedConstraints.getScopeByName(scopeName).getRules(); // Check if all the feature values are ok according to the // rules; } else { // Here some recursion would be in order } } return isOk; }
Example 3
Source File: FeatureStructureBrowserViewPage.java From uima-uimaj with Apache License 2.0 | 6 votes |
@Override public void added(Collection<FeatureStructure> structures) { final LinkedList<ModelFeatureStructure> featureStructureList = new LinkedList<>(); for (FeatureStructure structure : structures) { if (structure.getType() == mCurrentType) { featureStructureList.add(new ModelFeatureStructure(mDocument, structure)); } } Display.getDefault().syncExec(new Runnable() { @Override public void run() { mFSList.add(featureStructureList.toArray()); } }); }
Example 4
Source File: FeatureStructureBrowserViewPage.java From uima-uimaj with Apache License 2.0 | 6 votes |
@Override public void removed(Collection<FeatureStructure> structures) { final List<ModelFeatureStructure> featureStructureList = new LinkedList<>(); for (FeatureStructure structure : structures) { if (structure.getType() == mCurrentType) { featureStructureList.add(new ModelFeatureStructure(mDocument, structure)); } } Display.getDefault().syncExec(new Runnable() { @Override public void run() { mFSList.remove(featureStructureList.toArray()); } }); }
Example 5
Source File: IteratorTest.java From uima-uimaj with Apache License 2.0 | 6 votes |
private void tstWord(FSIndex<FeatureStructure> index) { FSIterator<FeatureStructure> it = index.iterator(); assertEquals(20, it.size()); // test size it.moveToLast(); FeatureStructure fs = this.cas.createFS(wType); fs.setStringValue(wordFeat, "word1"); // TEST moveTo() and get() it.moveTo(fs); assertSame(fs.getType(), it.get().getType()); Type t1 = fs.getType(); Type t2 = wordSetIndex.find(fs).getType(); assertSame(t1, t2); }
Example 6
Source File: RelationDiffAdapter.java From webanno with Apache License 2.0 | 5 votes |
@Override public Position getPosition(int aCasId, FeatureStructure aFS, String aFeature, String aRole, int aLinkTargetBegin, int aLinkTargetEnd, LinkCompareBehavior aLinkCompareBehavior) { Type type = aFS.getType(); AnnotationFS sourceFS = (AnnotationFS) aFS.getFeatureValue(type .getFeatureByBaseName(sourceFeature)); AnnotationFS targetFS = (AnnotationFS) aFS.getFeatureValue(type .getFeatureByBaseName(targetFeature)); String collectionId = null; String documentId = null; try { FeatureStructure dmd = WebAnnoCasUtil.getDocumentMetadata(aFS.getCAS()); collectionId = FSUtil.getFeature(dmd, "collectionId", String.class); documentId = FSUtil.getFeature(dmd, "documentId", String.class); } catch (IllegalArgumentException e) { // We use this information only for debugging - so we can ignore if the information // is missing. } String linkTargetText = null; if (aLinkTargetBegin != -1 && aFS.getCAS().getDocumentText() != null) { linkTargetText = aFS.getCAS().getDocumentText() .substring(aLinkTargetBegin, aLinkTargetEnd); } return new RelationPosition(collectionId, documentId, aCasId, getType(), sourceFS != null ? sourceFS.getBegin() : -1, sourceFS != null ? sourceFS.getEnd() : -1, sourceFS != null ? sourceFS.getCoveredText() : null, targetFS != null ? targetFS.getBegin() : -1, targetFS != null ? targetFS.getEnd() : -1, targetFS != null ? targetFS.getCoveredText() : null, aFeature, aRole, aLinkTargetBegin, aLinkTargetEnd, linkTargetText, aLinkCompareBehavior); }
Example 7
Source File: FSUtil.java From uima-uimafit with Apache License 2.0 | 5 votes |
private static Feature getMandatoryFeature(FeatureStructure aFS, String aFeature) { Feature feat = aFS.getType().getFeatureByBaseName(aFeature); if (feat == null) { throw new IllegalArgumentException("Type [" + aFS.getType() + "] has no feature with name [" + aFeature + "]"); } return feat; }
Example 8
Source File: FeatureStructureContentProvider.java From uima-uimaj with Apache License 2.0 | 5 votes |
@Override public Object[] getElements(Object inputElement) { if (inputElement != null) { FeatureStructure featureStructure = (FeatureStructure) inputElement; Type type = featureStructure.getType(); if (!type.isArray()) { Collection<FeatureValue> featureValues = new LinkedList<>(); for (Feature feature : type.getFeatures()) { featureValues.add(new FeatureValue(mDocument, featureStructure, feature)); } return featureValues.toArray(); } else { int size = arraySize(featureStructure); ArrayValue arrayValues[] = new ArrayValue[size]; for (int i = 0; i < size; i++) { arrayValues[i] = new ArrayValue(featureStructure, i); } return arrayValues; } } else { return new Object[0]; } }
Example 9
Source File: FsAccessor.java From biomedicus with Apache License 2.0 | 4 votes |
public FsAccessor(FeatureStructure featureStructure) { this.featureStructure = featureStructure; type = featureStructure.getType(); }
Example 10
Source File: DebugFSLogicalStructure.java From uima-uimaj with Apache License 2.0 | 4 votes |
public static Object getDebugLogicalStructure_FeatureStructure(FeatureStructure fs) { if (fs instanceof StringArrayFS) { return ((StringArrayFS) fs).toArray(); } if (fs instanceof FloatArrayFS) { return ((FloatArrayFS) fs).toArray(); } if (fs instanceof IntArrayFS) { return ((IntArrayFS) fs).toArray(); } if (fs instanceof ArrayFS) { return ((ArrayFS) fs).toArray(); } CASImpl cas = (CASImpl) fs.getCAS(); TypeSystem ts = cas.getTypeSystem(); Type fsType = fs.getType(); if (ts.subsumes(ts.getType("uima.cas.FloatList"), fsType)) { return (floatListToArray(fs)); } if (ts.subsumes(ts.getType("uima.cas.IntegerList"), fsType)) { return (integerListToArray(fs)); } if (ts.subsumes(ts.getType("uima.cas.StringList"), fsType)) { return (stringListToArray(fs)); } if (ts.subsumes(ts.getType("uima.cas.FSList"), fsType)) { return (fsListToArray(fs)); } DebugNameValuePair[] result; String typeName = fsType.getName(); List<Feature> features = fsType.getFeatures(); int nbrFeats = features.size(); boolean isAnnotation = false; boolean isJCasClass = false; if (fs.getClass().getName().equals(typeName)) { // true for JCas cover classes isJCasClass = true; } if (ts.subsumes(cas.getAnnotationType(), fsType)) { isAnnotation = true; } result = new DebugNameValuePair[(isJCasClass ? 0 : 1) // slot for type name if not JCas + (isAnnotation ? 3 : nbrFeats) // annotations have 4 slot display ]; int i = 0; if (!isJCasClass) { result[i++] = new DebugNameValuePair("CasType", typeName); } if (isAnnotation) { DebugNameValuePair[] featResults = new DebugNameValuePair[nbrFeats]; fillFeatures(featResults, 0, fs, features); result[i++] = new DebugNameValuePair("Features", featResults); result[i++] = new DebugNameValuePair("Covered Text", ((AnnotationFS) fs).getCoveredText()); result[i++] = new DebugNameValuePair("SubAnnotations", new UnexpandedFeatureStructures( (AnnotationFS) fs)); } else { fillFeatures(result, isJCasClass ? 0 : 1, fs, features); } return result; }
Example 11
Source File: SerDesTest6.java From uima-uimaj with Apache License 2.0 | 4 votes |
/** get feature for type of FS, + one of feature value kinds: Int, Fs, Float, Afloat, Astring */ Feature getFeature(FeatureStructure fs, String featNameRoot) { Type t = fs.getType(); return getFeature(Types.valueOf(t.getShortName()), featNameRoot); }