public static int intMaxBy(Iterable<? extends FeatureStructure> fsCollection, Feature intFeat) { Integer max = Integer.MIN_VALUE; boolean hasResult = false; for (FeatureStructure fs : fsCollection) { int intValue = fs.getIntValue(intFeat); hasResult = true; if (intValue > max) { max = intValue; } } if (!hasResult) { throw new IllegalArgumentException("fsCollection is empty"); } return max; }
public static int intMinBy(Iterable<? extends FeatureStructure> fsCollection, Feature intFeat) { Integer min = Integer.MAX_VALUE; boolean hasResult = false; for (FeatureStructure fs : fsCollection) { int intValue = fs.getIntValue(intFeat); hasResult = true; if (intValue < min) { min = intValue; } } if (!hasResult) { throw new IllegalArgumentException("fsCollection is empty"); } return min; }
public int getIntValue(String name) { return featureStructure.getIntValue(getFeature(name)); }
private Object getPrimitive(FeatureStructure fs, Feature feature) { String s = feature.getRange().getName(); if (s.equals("uima.cas.String")) return fs.getStringValue(feature); else if (s.equals("uima.cas.Integer")) return fs.getIntValue(feature); else if (s.equals("uima.cas.Double")) return fs.getDoubleValue(feature); return null; }
public static Object integerListToArray(FeatureStructure fs) { List<Integer> list = new ArrayList<Integer>(); 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>(); FeatureStructure nextFs; for (FeatureStructure currentFs = fs; currentFs.getType() != emptyFSList; currentFs = nextFs) { list.add(Integer.valueOf(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).intValue(); } return intArray; }
public boolean match(FeatureStructure fs) { // compile(((FeatureStructureImpl) fs).getCAS().getTypeSystem()); final int max = this.featNames.size() - 1; // The last position in the // path! if (max < 0) { // If the path is empty, we can't get an int, and therefore the // constraint is not satisfied. return false; } Feature feat; for (int i = 0; i < max; i++) { feat = fs.getType().getFeatureByBaseName(this.featNames.get(i)); if (feat == null) { return false; } fs = fs.getFeatureValue(feat); } feat = fs.getType().getFeatureByBaseName(this.featNames.get(max)); if (feat == null) { return false; } return this.intConstraint.match(fs.getIntValue(feat)); }
result = structure.getShortValue(feature); } else if (Integer.class.equals(primitiveClass)) { result = structure.getIntValue(feature); } else if (Long.class.equals(primitiveClass)) { result = structure.getLongValue(feature);
private static void fillFeatures(DebugNameValuePair[] result, int startOffset, FeatureStructure fs, List<Feature> features) { int nbrFeats = features.size(); int i = startOffset; for (int j = 0; j < nbrFeats; j++) { Feature feat = features.get(j); DebugNameValuePair nv = new DebugNameValuePair(feat.getShortName(), null); String rangeTypeName = feat.getRange().getName(); if ("uima.cas.Integer".equals(rangeTypeName)) nv.setValue(Integer.valueOf(fs.getIntValue(feat))); else if ("uima.cas.Float".equals(rangeTypeName)) nv.setValue(Float.valueOf(fs.getFloatValue(feat))); else if ("uima.cas.Boolean".equals(rangeTypeName)) nv.setValue(Boolean.valueOf(fs.getBooleanValue(feat))); else if ("uima.cas.Byte".equals(rangeTypeName)) nv.setValue(Byte.valueOf(fs.getByteValue(feat))); else if ("uima.cas.Short".equals(rangeTypeName)) nv.setValue(Short.valueOf(fs.getShortValue(feat))); else if ("uima.cas.Long".equals(rangeTypeName)) nv.setValue(Long.valueOf(fs.getLongValue(feat))); else if ("uima.cas.Double".equals(rangeTypeName)) nv.setValue(Double.valueOf(fs.getDoubleValue(feat))); else if ("uima.cas.String".equals(rangeTypeName)) nv.setValue(fs.getStringValue(feat)); else nv.setValue(fs.getFeatureValue(feat)); result[i++] = nv; } }
/** * Gets the feature as int. * * @param aCas the a cas * @param aFeature the a feature * @param aName the a name * @return the feature as int * @throws Exception the exception */ public static int getFeatureAsInt(CAS aCas, Feature aFeature, String aName) throws Exception { Feature seqNo2 = aFeature.getRange().getFeatureByBaseName(aName); FeatureStructure documentMetaData = aCas.getView(CAS.NAME_DEFAULT_SOFA).getDocumentAnnotation() .getFeatureValue(aFeature); return documentMetaData.getIntValue(seqNo2); }
switch (range) { case CAS.TYPE_NAME_INTEGER: generator.writeNumber(annotation.getIntValue(feature)); break; case CAS.TYPE_NAME_FLOAT:
return featureStructure.getShortValue(feature); else if (type.equals(typeSystem.getType("uima.cas.Integer"))) return featureStructure.getIntValue(feature); else if (type.equals(typeSystem.getType("uima.cas.Long"))) return featureStructure.getLongValue(feature);
private Number getNumberValue(MatchContext context, RutaStream stream) { AnnotationFS annotation = context.getAnnotation(); Number result = null; List<AnnotationFS> list = this.getTargetAnnotation(annotation, this.fe, context, stream); Collection<? extends FeatureStructure> featureStructures = this.fe.getFeatureStructures(list, false, context, stream); if (!featureStructures.isEmpty()) { Feature feature = this.fe.getFeature(context, stream); Type range = feature.getRange(); FeatureStructure next = featureStructures.iterator().next(); if (next instanceof AnnotationFS && !next.getType().equals(annotation.getType())) { feature = this.fe.getFeature(new MatchContext((AnnotationFS) next, context.getElement(), context.getRuleMatch(), context.getDirection()), stream); } if (CAS.TYPE_NAME_BYTE.equals(range.getName())) { result = next.getByteValue(feature); } else if (CAS.TYPE_NAME_DOUBLE.equals(range.getName())) { result = next.getDoubleValue(feature); } else if (CAS.TYPE_NAME_FLOAT.equals(range.getName())) { result = next.getFloatValue(feature); } else if (CAS.TYPE_NAME_INTEGER.equals(range.getName())) { result = next.getIntValue(feature); } else if (CAS.TYPE_NAME_LONG.equals(range.getName())) { result = next.getLongValue(feature); } else if (CAS.TYPE_NAME_SHORT.equals(range.getName())) { result = next.getShortValue(feature); } } return result; }
public static <T> T getFeature(FeatureStructure aFS, String aFeatureName) { Feature feature = aFS.getType().getFeatureByBaseName(aFeatureName); if (feature == null) { throw new IllegalArgumentException("Type [" + aFS.getType().getName() + "] has no feature called [" + aFeatureName + "]"); } switch (feature.getRange().getName()) { case CAS.TYPE_NAME_STRING: return (T) aFS.getStringValue(feature); case CAS.TYPE_NAME_BOOLEAN: return (T) (Boolean) aFS.getBooleanValue(feature); case CAS.TYPE_NAME_FLOAT: return (T) (Float) aFS.getFloatValue(feature); case CAS.TYPE_NAME_INTEGER: return (T) (Integer) aFS.getIntValue(feature); default: throw new IllegalArgumentException("Cannot get value of feature [" + feature.getName() + "] with type [" + feature.getRange().getName() + "]"); } }
public static <T> T getFeature(FeatureStructure aFS, String aFeatureName) { Feature feature = aFS.getType().getFeatureByBaseName(aFeatureName); if (feature == null) { throw new IllegalArgumentException("Type [" + aFS.getType().getName() + "] has no feature called [" + aFeatureName + "]"); } switch (feature.getRange().getName()) { case CAS.TYPE_NAME_STRING: return (T) aFS.getStringValue(feature); case CAS.TYPE_NAME_BOOLEAN: return (T) (Boolean) aFS.getBooleanValue(feature); case CAS.TYPE_NAME_FLOAT: return (T) (Float) aFS.getFloatValue(feature); case CAS.TYPE_NAME_INTEGER: return (T) (Integer) aFS.getIntValue(feature); default: throw new IllegalArgumentException("Cannot get value of feature [" + feature.getName() + "] with type [" + feature.getRange().getName() + "]"); } }
public static int getIntFeatValue(CAS aCasView, String aTypeS, String aFeatS) { int result = 0; Type type = aCasView.getTypeSystem().getType(aTypeS); if (type != null) { FSIterator<AnnotationFS> idIter = aCasView.getAnnotationIndex(type).iterator(); while (idIter.isValid()) { org.apache.uima.cas.FeatureStructure idFS = idIter.get(); result = idFS .getIntValue(aCasView.getTypeSystem().getFeatureByFullName(aTypeS + ":" + aFeatS)); idIter.moveToNext(); } } return result; }
/** * Returns an int value of a given Feature Structure. * * @param aCasView - * CAS instance to retrieve data from * @param aTypeS - * Feature Type * @param aFeatS - * Feature Structure * @return - feature value as int */ public static int getIntFeatValue(CAS aCasView, String aTypeS, String aFeatS) { int result = 0; FSIterator idIter = aCasView.getAnnotationIndex(aCasView.getTypeSystem().getType(aTypeS)).iterator(); while (idIter != null && idIter.isValid()) { org.apache.uima.cas.FeatureStructure idFS = idIter.get(); result = idFS.getIntValue(aCasView.getTypeSystem().getFeatureByFullName(aTypeS + ":" + aFeatS)); idIter.moveToNext(); } return result; }
/** * Get the feature value of this {@code Feature} on this annotation */ private static Object getFeatureValue(FeatureStructure aFS, Feature aFeature) { switch (aFeature.getRange().getName()) { case CAS.TYPE_NAME_STRING: return aFS.getFeatureValueAsString(aFeature); case CAS.TYPE_NAME_BOOLEAN: return aFS.getBooleanValue(aFeature); case CAS.TYPE_NAME_FLOAT: return aFS.getFloatValue(aFeature); case CAS.TYPE_NAME_INTEGER: return aFS.getIntValue(aFeature); case CAS.TYPE_NAME_BYTE: return aFS.getByteValue(aFeature); case CAS.TYPE_NAME_DOUBLE: return aFS.getDoubleValue(aFeature); case CAS.TYPE_NAME_LONG: aFS.getLongValue(aFeature); case CAS.TYPE_NAME_SHORT: aFS.getShortValue(aFeature); default: return null; // return aFS.getFeatureValue(aFeature); } }
/** * Get the feature value of this {@code Feature} on this annotation */ private static Object getFeatureValue(FeatureStructure aFS, Feature aFeature) { switch (aFeature.getRange().getName()) { case CAS.TYPE_NAME_STRING: return aFS.getFeatureValueAsString(aFeature); case CAS.TYPE_NAME_BOOLEAN: return aFS.getBooleanValue(aFeature); case CAS.TYPE_NAME_FLOAT: return aFS.getFloatValue(aFeature); case CAS.TYPE_NAME_INTEGER: return aFS.getIntValue(aFeature); case CAS.TYPE_NAME_BYTE: return aFS.getByteValue(aFeature); case CAS.TYPE_NAME_DOUBLE: return aFS.getDoubleValue(aFeature); case CAS.TYPE_NAME_LONG: aFS.getLongValue(aFeature); case CAS.TYPE_NAME_SHORT: aFS.getShortValue(aFeature); default: return null; // return aFS.getFeatureValue(aFeature); } }
newFS.setStringValue(feature, stringValue); } else if (oldRange.getShortName().equals("Integer")) { Integer intValue = oldFS.getIntValue(oldFeature); newFS.setIntValue(feature, intValue); } else if (oldRange.getShortName().equals("Float")) {
newFS.setStringValue(feature, stringValue); } else if (oldRange.getShortName().equals("Integer")) { Integer intValue = oldFS.getIntValue(oldFeature); newFS.setIntValue(feature, intValue); } else if (oldRange.getShortName().equals("Float")) {