private static boolean isRoleAgree(FeatureStructure aMergeFs, Map<String, ArrayFS> aAnnosPerUser) { for (String user : aAnnosPerUser.keySet()) { boolean agree = false; if (aAnnosPerUser.get(user) == null) { return false; } for (FeatureStructure usrFs : aAnnosPerUser.get(user).toArray()) { // same on all non slot feature values if (isSameAnno(aMergeFs, usrFs)) { if (!agree) { // this anno is the same with the others agree = true; } } } // do not match in at least one user annotation in this position if (!agree) { return false; } } return true; }
public static ArrayFS fillArrayFS(ArrayFS aArrayFs, FeatureStructure[] aArray) { aArrayFs.copyFromArray(aArray, 0, 0, aArrayFs.size()); return aArrayFs; }
/** * Copies one array of fs references to another. * * @param from the array to copy from * @param to the array to copy to */ private void copyFsArray(FeatureStructure from, FeatureStructure to) { ArrayFS sourceFses = (ArrayFS) from; ArrayFS targetFses = (ArrayFS) to; for (int index = 0; index < sourceFses.size(); index++) { FeatureStructure arrayMember = sourceFses.get(index); FeatureStructure toFs = featureStructureEncounteredCallback.apply(arrayMember); targetFses.set(index, toFs); } }
/** * Fetch all annotations of the given type or its sub-types from the given FS array. * * @param aArray * the FS array * @param aType * the CAS type. * @return a new collection of all feature structures of the given type. */ public static Collection<FeatureStructure> create(ArrayFS aArray, Type aType) { TypeSystem ts = aArray.getCAS().getTypeSystem(); List<FeatureStructure> data = new ArrayList<FeatureStructure>(aArray.size()); for (int i = 0; i < aArray.size(); i++) { FeatureStructure value = aArray.get(i); if (value != null && (aType == null || ts.subsumes(aType, value.getType()))) { data.add(value); } } return asList(data.toArray(new FeatureStructure[data.size()])); }
@Override public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) { if (FeatureStructure.class.equals(adapter)) { if (arrayFS instanceof ArrayFS) { ArrayFS array = (ArrayFS) arrayFS; return array.get(slot()); } } if (AnnotationFS.class.equals(adapter)) { FeatureStructure fs = (FeatureStructure) getAdapter(FeatureStructure.class); if (fs instanceof AnnotationFS) { return fs; } } return null; }
roleFeature); List<FeatureStructure> linkFSes = new LinkedList<>( Arrays.asList(roleFss.toArray())); for (FeatureStructure roleFs : roleFss.toArray()) { if (isRoleAgree(roleFs, roleAnnosPerUser)) { for (Feature targetFeature : roleFs.getType().getFeatures()) { array.copyFromArray(linkFSes.toArray(new FeatureStructure[linkFSes.size()]), 0, 0, linkFSes.size()); baseFs.setFeatureValue(roleFeature, array);
public String toString() { Object v = getValue(); if (v instanceof StringArrayFS) v = "StringArrayFS[" + ((StringArrayFS) v).size() + "]"; else if (v instanceof FloatArrayFS) v = "FloatArrayFS[" + ((FloatArrayFS) v).size() + "]"; else if (v instanceof IntArrayFS) v = "IntArrayFS[" + ((IntArrayFS) v).size() + "]"; else if (v instanceof ArrayFS) v = "ArrayFS[" + ((ArrayFS) v).size() + "]"; return getName() + ": " + v; }
public static <T extends ArrayFS> T fillArrayFS(T aArrayFs, Iterable<? extends FeatureStructure> aCollection) { int i = 0; for (FeatureStructure fs : aCollection) { aArrayFs.set(i, fs); i++; } return aArrayFs; }
protected AnnotationFS createAnnotation(CAS cas, int offset, Parse parse) { Parse[] parseChildren = parse.getChildren(); AnnotationFS[] parseChildAnnotations = new AnnotationFS[parseChildren.length]; // do this for all children for (int i = 0; i < parseChildren.length; i++) { parseChildAnnotations[i] = createAnnotation(cas, offset, parseChildren[i]); } AnnotationFS parseAnnotation = cas.createAnnotation(mParseType, offset + parse.getSpan().getStart(), offset + parse.getSpan().getEnd()); parseAnnotation.setStringValue(mTypeFeature, parse.getType()); if (probabilityFeature != null) { parseAnnotation.setDoubleValue(probabilityFeature, parse.getProb()); } ArrayFS childrenArray = cas.createArrayFS(parseChildAnnotations.length); childrenArray.copyFromArray(parseChildAnnotations, 0, 0, parseChildAnnotations.length); parseAnnotation.setFeatureValue(childrenFeature, childrenArray); cas.getIndexRepository().addFS(parseAnnotation); return parseAnnotation; }
FeatureStructure link = links.get(cfg.getAID(user).index);
roleFeature); List<FeatureStructure> linkFSes = new LinkedList<>( Arrays.asList(roleFss.toArray())); for (FeatureStructure roleFs : roleFss.toArray()) { if (isRoleAgree(roleFs, roleAnnosPerUser)) { for (Feature targetFeature : roleFs.getType().getFeatures()) { array.copyFromArray(linkFSes.toArray(new FeatureStructure[linkFSes.size()]), 0, 0, linkFSes.size()); baseFs.setFeatureValue(roleFeature, array);
/** * Array size. * * @param value the value * @return the int */ private int arraySize(FeatureStructure value) { if (!value.getType().isArray()) { throw new IllegalArgumentException(); } int size; if (value instanceof ArrayFS) { ArrayFS array = (ArrayFS) value; size = array.size(); } else if (value instanceof CommonArrayFS) { CommonArrayFS array = (CommonArrayFS) value; size = array.size(); } else if (value instanceof StringArrayFS) { StringArrayFS array = (StringArrayFS) value; size = array.size(); } else { throw new CasEditorError("Unkown array type!"); } return size; }
public static FeatureStructure toCompatibleCollection(CAS cas, Feature targetFeat, Collection<? extends FeatureStructure> srcCol) { if (srcCol == null) { return null; } // TODO handle lists if (targetFeat.getRange().isArray()) { ArrayFS result = cas.createArrayFS(srcCol.size()); int i = 0; for (FeatureStructure elemFS : srcCol) { result.set(i, elemFS); i++; } return result; } else { throw new UnsupportedOperationException(); } }
/** * update a base annotation with slot annotations * * @param linkFSesPerAnno * contains list of slot annotations per a base annotation * @param aLinkeF * The link slot annotation feature */ private void addSlotAnnotations(Map<AnnotationFS, List<FeatureStructure>> linkFSesPerAnno, Feature aLinkeF) { for (AnnotationFS anno : linkFSesPerAnno.keySet()) { ArrayFS array = anno.getCAS().createArrayFS(linkFSesPerAnno.get(anno).size()); array.copyFromArray( linkFSesPerAnno.get(anno) .toArray(new FeatureStructure[linkFSesPerAnno.get(anno).size()]), 0, 0, linkFSesPerAnno.get(anno).size()); anno.setFeatureValue(aLinkeF, array); anno.getCAS().addFsToIndexes(anno); } }
private static boolean isRoleAgree(FeatureStructure aMergeFs, Map<String, ArrayFS> aAnnosPerUser) { for (String user : aAnnosPerUser.keySet()) { boolean agree = false; if (aAnnosPerUser.get(user) == null) { return false; } for (FeatureStructure usrFs : aAnnosPerUser.get(user).toArray()) { // same on all non slot feature values if (isSameAnno(aMergeFs, usrFs)) { if (!agree) { // this anno is the same with the others agree = true; } } } // do not match in at least one user annotation in this position if (!agree) { return false; } } return true; }
public static void setLinkFeatureValue(FeatureStructure aFS, Feature aFeature, List<FeatureStructure> linkFSes) { // Create a new array if size differs otherwise re-use existing one ArrayFS array = (ArrayFS) WebAnnoCasUtil.getFeatureFS(aFS, aFeature.getShortName()); if (array == null || (array.size() != linkFSes.size())) { array = aFS.getCAS().createArrayFS(linkFSes.size()); } // Fill in links array.copyFromArray(linkFSes.toArray(new FeatureStructure[linkFSes.size()]), 0, 0, linkFSes.size()); aFS.setFeatureValue(aFeature, array); }
return hasChildren(array.get(value.slot()));