private void removeSubSet(AnnotationSet theSet, Map<String,List<List<Integer>>> matchMap) { AnnotationSet toRemove = theSet.get(new HashSet<String>(annotationTypes)); if (toRemove == null || toRemove.isEmpty()) return; theSet.removeAll(toRemove); removeAnnotationsFromCorefData(toRemove, theSet.getName(), matchMap); }//removeSubSet
/** * Get all the annots of the right type that are within the span of * this annot. */ @Override public AnnotationSet doMatch(Annotation annot, AnnotationSet as) { return as.getContained(annot.getStartNode().getOffset(), annot.getEndNode().getOffset()).get(annotType); }
@SuppressWarnings("unchecked") private JButton processChildrenAnnots(Annotation annot, Map<Integer, JButton> processed) { selection.clear(); Vector<JButton> childrenButtons = new Vector<JButton>(); java.util.List<Integer> children = (java.util.List<Integer>) annot.getFeatures().get(NODE_CONSISTS_FEATURE_NAME); for (Iterator<Integer> i = children.iterator(); i.hasNext(); ) { Integer childId = i.next(); Annotation child = treeAnnotations.get(childId); JButton childButton; if (processed.containsKey(child.getId())) childButton = processed.get(child.getId()); else childButton = processChildrenAnnots(child, processed); childrenButtons.add(childButton); } selection = (Vector<JButton>) childrenButtons.clone(); STreeNode parent = createParentNode( (String) annot.getFeatures().get(NODE_CAT_FEATURE_NAME), annot); nonTerminals.put(parent.getID(), parent); JButton parentButton = createCentralButton(parent); addLines(parent); processed.put(annot.getId(), parentButton); selection.clear(); return parentButton; }// private JButton processChildrenAnnots
nameAllAnnots.get(OrthoMatcher.LOOKUP_ANNOTATION_TYPE, tempMap); if((nameAnnots == null) || nameAnnots.isEmpty()) return cdg; Iterator<Annotation> iter = nameAnnots.iterator();
protected Map<String, Collection<Annotation>> collectAnnotations(Document document) { // build the map of annotations that we are interested in Map<String, Collection<Annotation>> annotationSetsMap = new HashMap<String, Collection<Annotation>>(); if(annSetDefinitions != null && annSetDefinitions.size() > 0) { for(AnnotationSetDefinition asDef : annSetDefinitions) { AnnotationSet annotationSet = document.getAnnotations( asDef.getAnnotationSetName()); // restrict to specified types, if necessary if(asDef.getAnnotationTypes() != null && !asDef.getAnnotationTypes().isEmpty()) { Set<String> types = new HashSet<String>(asDef.getAnnotationTypes()); annotationSet = annotationSet.get(types); } // map "" name to null annotationSetsMap.put(("".equals(asDef.getAnnotationSetName()) ? null : asDef.getAnnotationSetName()), annotationSet); } } else { annotationSetsMap.put(null, document.getAnnotations()); if(document.getNamedAnnotationSets() != null) { annotationSetsMap.putAll(document.getNamedAnnotationSets()); } } return annotationSetsMap; }
@SuppressWarnings("unchecked") protected void docCleanup() { Object matchesValue = document.getFeatures().get(DOCUMENT_COREF_FEATURE_NAME); if (matchesValue != null && (matchesValue instanceof Map)) ((Map<String,List<List<Integer>>>)matchesValue).remove(nameAllAnnots.getName()); else if (matchesValue != null) { document.getFeatures().put(DOCUMENT_COREF_FEATURE_NAME, new HashMap<String,List<List<Integer>>>()); } //get all annotations that have a matches feature HashSet<String> fNames = new HashSet<String>(); fNames.add(ANNOTATION_COREF_FEATURE_NAME); AnnotationSet annots = nameAllAnnots.get(null, fNames); // Out.prln("Annots to cleanup" + annots); if (annots == null || annots.isEmpty()) return; Iterator<Annotation> iter = annots.iterator(); while (iter.hasNext()) { while (iter.hasNext()) iter.next().getFeatures().remove(ANNOTATION_COREF_FEATURE_NAME); } //while }//cleanup
/** --- */ private String findPersonGender(Annotation person) { String result = (String)person.getFeatures().get(PERSON_GENDER_FEATURE_NAME); if (null==result) { //gender is unknown - try to find it from the ortho coreferences @SuppressWarnings("unchecked") List<Integer> orthoMatches = (List<Integer>)person.getFeatures().get(ANNOTATION_COREF_FEATURE_NAME); if (null != orthoMatches) { Iterator<Integer> itMatches = orthoMatches.iterator(); while (itMatches.hasNext()) { Integer correferringID = itMatches.next(); Annotation coreferringEntity = this.defaultAnnotations.get(correferringID); if (coreferringEntity != null) { assert (coreferringEntity.getType().equalsIgnoreCase(PERSON_ANNOTATION_TYPE)); String correferringGender = (String)coreferringEntity.getFeatures().get(PERSON_GENDER_FEATURE_NAME); if (null != correferringGender) { result = correferringGender; break; } } } } } return result; }
/** Get a sorted array of the tokens that make up a given annotation. */ private Annotation[] getSortedTokens(Annotation a) { Annotation[] annotationTokens = this.defaultAnnotations.get(TOKEN_ANNOTATION_TYPE, a.getStartNode().getOffset(), a.getEndNode().getOffset()).toArray(new Annotation[0]); java.util.Arrays.sort(annotationTokens, new OffsetComparator()); return annotationTokens; }
Rule:PojemId ( {PojemD} ):pojem --> { AnnotationSet matchedAnns = bindings.get("pojem"); Annotation ann = matchedAnns.get("PojemD").iterator().next(); FeatureMap pojemFeatures = ann.getFeatures(); gate.FeatureMap features = Factory.newFeatureMap(); features.putAll(pojemFeatures); features.put("annId", ann.getId()); inputAS.remove(ann); Integer id = outputAS.add(matchedAnns.firstNode(), matchedAnns.lastNode(), "PojemD", features); features.put("id", id); }
protected void propagatePropertyToExactMatchingMatches(Annotation updateAnnot,String featureName,Object value) { try { @SuppressWarnings("unchecked") List<Integer> matchesList = (List<Integer>) updateAnnot.getFeatures().get(ANNOTATION_COREF_FEATURE_NAME); if ((matchesList == null) || matchesList.isEmpty()) { return; } else { String updateAnnotString = orthoAnnotation.getStringForAnnotation(updateAnnot, document).toLowerCase(); for (Integer nextId : matchesList) { Annotation a = nameAllAnnots.get(nextId); if (orthoAnnotation.fuzzyMatch(orthoAnnotation.getStringForAnnotation(a, document),updateAnnotString)) { if (DEBUG) { log.debug("propogateProperty: " + featureName + " " + value + " from: " + updateAnnot.getId() + " to: " + a.getId()); } a.getFeatures().put(featureName, value); } } } } catch (Exception e) { log.error("Error in propogatePropertyToExactMatchingMatches", e); } }
AnnotationSet sentences = defaultAS.get("Sentence");
AnnotationSet annots = allAnnots.get(annotationTypes.get(i)); if(annots == null || annots.isEmpty()) continue; statsPerType.put(annotationTypes.get(i), new HashMap<String, Integer>());
fNames.add(gate.creole.ANNIEConstants.ANNOTATION_COREF_FEATURE_NAME); AnnotationSet allMatchesAnnots = nameAllAnnots.get(null, fNames);
AnnotationSet annots2Export = allAnnots.get(types2Export);
AnnotationSet resultAS = GATEAnnotionSet.get(filters.getTypes());
@Override protected Annotation[] getAnnotsToProcess(GATEDocument gateDocument) throws IndexException { Document document = gateDocument.getDocument(); Annotation[] semanticAnnots; AnnotationSet semAnnSet = (indexConfig.getSemanticAnnotationSetName() == null || indexConfig.getSemanticAnnotationSetName().length() == 0) ? document.getAnnotations() : document.getAnnotations(indexConfig.getSemanticAnnotationSetName()); if(semAnnSet.size() > 0){ AnnotationSet semAnns = null; synchronized(semAnnSet) { semAnns = semAnnSet.get(annotationHelpers.keySet()); } semanticAnnots = semAnns.toArray(new Annotation[semAnns.size()]); Arrays.sort(semanticAnnots, offsetComparator); } else { semanticAnnots = new Annotation[0]; } return semanticAnnots; }
if(tokenSet != null) { synchronized(tokenSet) { allTokens = tokenSet.get(indexConfig .getTokenAnnotationType());
defaultAnnotSet= defaultAnnotSet.get(annotTypesRequired); if(defaultAnnotSet==null) return null;
public String annotate(String original) { DocumentImpl doc; AnnotationSet defaultAnnotSet; try{ doc = new DocumentImpl(); doc.setStringContent(original); doc.init(); corpus.clear(); corpus.add(doc); annieController.setCorpus(corpus); annieController.execute(); defaultAnnotSet = doc.getAnnotations(); defaultAnnotSet= defaultAnnotSet.get(annotTypesRequired); return "<?xml version=\"1.0\" encoding=\"windows-1252\"?>\n<doc>"+doc.toXml(defaultAnnotSet, false)+"</doc>"; } catch(Exception e){ e.printStackTrace(); return null; } }
document.getAnnotations() : document.getAnnotations(outputASName); AnnotationSet annotations = outputAS.get(outputAnnotationType); if(annotations == null || annotations.size() == 0) { List<Annotation> tempList = new ArrayList<Annotation>(annotations.get()); boolean found = false; for(int i=0;i<tempList.size();i++) {