/** * Convert a UIMA feature array to a List of Java objects of the correct type, parsing Strings to * objects where possible * * @param f UIMA CAS Feature * @param a UIMA CAS Annotation * @return List of Java objects, or empty if unable to convert */ public static List<Object> featureToList(Feature f, Annotation a) { if (a.getFeatureValue(f) == null) { return Collections.emptyList(); } return Arrays.asList(toArray(f, a)); }
/** * Convert a UIMA feature array to a List of Java objects of the correct type, parsing Strings to * objects where possible * * @param f UIMA CAS Feature * @param a UIMA CAS Annotation * @return List of Java objects, or empty if unable to convert */ public static List<Object> featureToList(Feature f, Annotation a) { if (a.getFeatureValue(f) == null) { return Collections.emptyList(); } return Arrays.asList(toArray(f, a)); }
/** * Convert a UIMA feature array to an array of Java objects of the correct type, parsing Strings * to objects where possible * * @param f UIMA CAS Feature * @param a UIMA CAS Annotation * @return Array of Java objects, or null if unable to convert */ public static Object[] featureToArray(Feature f, Annotation a) { Object[] ret; if (a.getFeatureValue(f) == null) { ret = new Object[0]; } else { ret = toArray(f, a); } return ret; }
/** * Convert a UIMA feature array to an array of Java objects of the correct type, parsing Strings * to objects where possible * * @param f UIMA CAS Feature * @param a UIMA CAS Annotation * @return Array of Java objects, or null if unable to convert */ public static Object[] featureToArray(Feature f, Annotation a) { Object[] ret; if (a.getFeatureValue(f) == null) { ret = new Object[0]; } else { ret = toArray(f, a); } return ret; }
private static Object[] toArray(Feature f, Annotation a) { Object[] ret; try { CommonArrayFS array = (CommonArrayFS) a.getFeatureValue(f); ret = new Object[array.size()]; int index = 0; for (String s : array.toStringArray()) { ret[index] = StringToObject.convertStringToObject(s); index++; } return ret; } catch (ClassCastException cce) { LoggerFactory.getLogger(FeatureUtils.class) .debug("Couldn't cast feature value to array", cce); return new Object[0]; } } }
private static Object[] toArray(Feature f, Annotation a) { Object[] ret; try { CommonArrayFS array = (CommonArrayFS) a.getFeatureValue(f); ret = new Object[array.size()]; int index = 0; for (String s : array.toStringArray()) { ret[index] = StringToObject.convertStringToObject(s); index++; } return ret; } catch (ClassCastException cce) { LoggerFactory.getLogger(FeatureUtils.class) .debug("Couldn't cast feature value to array", cce); return new Object[0]; } } }
/** * add a concept to the map of concepts for the current named entity. * * @param jcas * @param concepts * @param annoCandidate * @param cuiFeature * @param tuiFeature * @param bMedication * @return is this concept a medication concept? only check if * checkMedications is true */ private boolean addConcept(JCas jcas, Map<String, OntologyConcept> concepts, Annotation annoCandidate, Feature cuiFeature, Feature tuiFeature, boolean bMedication) { String cui = annoCandidate.getStringValue(cuiFeature); if (concepts.containsKey(cui)) return bMedication; OntologyConcept oc = new OntologyConcept(jcas); oc.setCode(cui); oc.setCodingScheme("METAMAP"); StringArray tuiArr = (StringArray) annoCandidate .getFeatureValue(tuiFeature); List<String> tuis = null; if (tuiArr != null) tuis = Arrays.asList(tuiArr.toStringArray()); concepts.put(cui, oc); return checkMedications && tuis != null ? !Collections.disjoint( setMedicationAbrs, tuis) : false; }
/** * add a concept to the map of concepts for the current named entity. * * @param jcas * @param concepts * @param annoCandidate * @param cuiFeature * @param tuiFeature * @param bMedication * @return is this concept a medication concept? only check if * checkMedications is true */ private boolean addConcept(JCas jcas, Map<String, OntologyConcept> concepts, Annotation annoCandidate, Feature cuiFeature, Feature tuiFeature, boolean bMedication) { String cui = annoCandidate.getStringValue(cuiFeature); if (concepts.containsKey(cui)) return bMedication; OntologyConcept oc = new OntologyConcept(jcas); oc.setCode(cui); oc.setCodingScheme("METAMAP"); StringArray tuiArr = (StringArray) annoCandidate .getFeatureValue(tuiFeature); List<String> tuis = null; if (tuiArr != null) tuis = Arrays.asList(tuiArr.toStringArray()); concepts.put(cui, oc); return checkMedications && tuis != null ? !Collections.disjoint( setMedicationAbrs, tuis) : false; }
static void writeFieldToDb(String range, BasicDBObject o, Annotation a, String dbKey, Feature f) { if (range.equals("String")) { o.put(dbKey, a.getStringValue(f)); } else if (range.equals("StringArray")) { StringArray sa = (StringArray) a.getFeatureValue(f); if (sa != null) { String[] vals = sa.toArray(); o.put(dbKey, Lists.newArrayList(vals)); } } else if (range.equals("Integer")) { o.put(dbKey, a.getIntValue(f)); } else if (range.equals("Float")) { o.put(dbKey, a.getFloatValue(f)); } else if (range.equals("Boolean")) { o.put(dbKey, a.getBooleanValue(f)); } else { LOG.warn("range not supported " + range); } }
.getFeatureValue(feat); if (fsCol != null && (fsCol instanceof FSArray || fsCol instanceof FSList)) { feat.getRange().getName(), new AnnoFSAttribute(annoId, anno .getFeatureValue(feat), null));
.getFeatureValue(feat); if (fsCol != null && (fsCol instanceof FSArray || fsCol instanceof FSList)) { feat.getRange().getName(), new AnnoFSAttribute(annoId, anno .getFeatureValue(feat), null));
Annotation negAnno = negIter.next(); FSArray spanArr = (FSArray) negAnno .getFeatureValue(spanFeature); if (spanArr != null) { for (int i = 0; i < spanArr.size(); i++) {
Annotation negAnno = negIter.next(); FSArray spanArr = (FSArray) negAnno .getFeatureValue(spanFeature); if (spanArr != null) { for (int i = 0; i < spanArr.size(); i++) {