/** Equality expressions to aid in converting between DepNodes and CAS objects */ public static boolean equalCoverage(Annotation annot1,Annotation annot2) { return annot1.getBegin()==annot2.getBegin() && annot1.getEnd()==annot2.getEnd() && annot1.getCoveredText()==annot2.getCoveredText(); } // public static boolean equalCoverage(Annotation annot,UimaDepNode udNode) {
@Override public Annotation convert(JCas view, TopTreebankNode topNode) { Annotation annotation = new Annotation(view); List<Annotation> subAnnotations = new ArrayList<Annotation>(); for (PropbankRelation rel : this.relations) { subAnnotations.add(rel.convert(view, topNode)); } // annotation.setAnnotations(UIMAUtil.toFSArray(view, subAnnotations)); int[] span = AnnotationUtil.getAnnotationsExtent(subAnnotations); annotation.setBegin(span[0]); annotation.setEnd(span[1]); annotation.addToIndexes(); return annotation; }
static private String getDebugText( final Annotation a ) { return a.getType().getShortName() + "(" + a.getBegin() + "-" + a.getEnd() + "): " + a.getCoveredText(); }
public static int[] getAnnotationsExtent(List<? extends Annotation> annotations) { int start = Integer.MAX_VALUE; int end = 0; for (Annotation annotation : annotations) { if (annotation.getBegin() < start) start = annotation.getBegin(); if (annotation.getEnd() > end) end = annotation.getEnd(); } return new int[] { start, end }; } }
private static void postprocess(int spanBegin, Annotation anno, int begin, int end) { anno.setBegin(spanBegin + begin); anno.setEnd(spanBegin + end); anno.addToIndexes(); } }
@Override public void process(JCas jcas) throws AnalysisEngineProcessException { int e = 0; for (final Annotation anno : JCasUtil.select(jcas, segmentAnnotationType)) { final int b = anno.getBegin(); AnnotationFactory.createAnnotation(jcas, b, b, boundaryAnnotationType); e = anno.getEnd(); } AnnotationFactory.createAnnotation(jcas, e, e, boundaryAnnotationType); }
@Override public void process(JCas jCas) throws AnalysisEngineProcessException { if (windowClass != null) { for (Annotation window : JCasUtil.select(jCas, windowClass)) { String text = window.getCoveredText(); createParentheticals(jCas, text, window.getBegin()); } } else { String text = jCas.getDocumentText(); createParentheticals(jCas, text, 0); } }
@Override public void process(JCas jcas) throws AnalysisEngineProcessException { if (segmentAnnotationClass != null) { for (final Annotation segAnno : JCasUtil.select(jcas, segmentAnnotationClass)) { doAnnotations(jcas, JCasUtil.selectCovered(jcas, baseAnnotation, segAnno), segAnno.getEnd()); } } else { doAnnotations(jcas, JCasUtil.select(jcas, baseAnnotation), jcas.getDocumentText().length()); } }
@Override public void process(JCas aJCas) throws AnalysisEngineProcessException { DocumentMetaData meta = iterate(aJCas, DocumentMetaData.class).iterator().next(); System.out.println("=== METADATA ========================================"); System.out.println("URI : "+meta.getDocumentUri()); System.out.println("Language: "+aJCas.getDocumentLanguage()); System.out.println("=== TEXT ============================================"); System.out.println(aJCas.getDocumentText()); System.out.println("=== ANNOTATIONS ====================================="); for (Annotation a : iterate(aJCas, Annotation.class)) { System.out.println(a.getType().getName() + "(" + a.getBegin() + "," + a.getEnd() + ") [" + a.getCoveredText() + "]"); } } }
@Override public void process(JCas jcas) throws AnalysisEngineProcessException { int i = 0; int index = 0; for (final Annotation anno : JCasUtil.select(jcas, boundaryAnnotationType)) { if ((index > 0) || beginAndSegment) AnnotationFactory.createAnnotation(jcas, i, anno.getBegin(), segmentAnnotationType); i = anno.getBegin(); index++; } if (beginAndSegment) AnnotationFactory.createAnnotation(jcas, i, jcas.getDocumentText().length(), segmentAnnotationType); }
@Override public void process(JCas aJCas) throws AnalysisEngineProcessException { JCas srcView, tgtView; try { srcView = aJCas.getView(sourceViewName); tgtView = aJCas.getView(targetViewName); for (Annotation a : JCasUtil.select(srcView, clazz)) { AnnotationFactory.createAnnotation(tgtView, a.getBegin(), a.getEnd(), clazz); } } catch (CASException e) { throw new AnalysisEngineProcessException(e); } }
@Override public void process(JCas jcas) throws AnalysisEngineProcessException { Set<Annotation> toDelete = null; if (deleteSource) { toDelete = new HashSet<Annotation>(); } for (Annotation anno : JCasUtil.select(jcas, sourceClass)) { Annotation newAnnotation = AnnotationFactory.createAnnotation(jcas, anno.getBegin(), anno.getEnd(), targetClass); if (deleteSource) toDelete.add(anno); if (!(targetFeatureName.isEmpty() || targetFeatureValue.isEmpty())) { Feature feature = newAnnotation.getType().getFeatureByBaseName(targetFeatureName); if (feature != null) newAnnotation.setFeatureValueFromString(feature, targetFeatureValue); } } if (deleteSource) { for (Annotation a : toDelete) { a.removeFromIndexes(); } } }
public static <T extends Annotation> List<T> selectMatching( JCas jCas, Class<T> selectedType, Annotation annotation) { List<T> result = new ArrayList<T>(); for (T selected : JCasUtil.selectCovered(jCas, selectedType, annotation)) { if (selected.getBegin() == annotation.getBegin() && selected.getEnd() == annotation.getEnd()) { result.add(selected); } } return result; }
/** * Trim the offsets of the given annotation to remove leading/trailing whitespace. * <p> * <b>Note:</b> use this method if the document text of the CAS has not been set yet but you * have it available in a buffer. * <p> * <b>Note:</b> best use this method before adding the annotation to the indexes. * * @param aText * the document text (available so far). * @param aAnnotation * the annotation to trim. Offsets are updated. */ public static void trim(CharSequence aText, Annotation aAnnotation) { int[] offsets = { aAnnotation.getBegin(), aAnnotation.getEnd() }; trim(aText, offsets); aAnnotation.setBegin(offsets[0]); aAnnotation.setEnd(offsets[1]); }
public static double getRelativeDist(Annotation a, Annotation b, JCas jcas) { final double dist; if (a.getEnd() < b.getBegin()) { dist = b.getBegin() - a.getEnd(); } else if (b.getEnd() < a.getBegin()) { dist = a.getBegin() - b.getEnd(); } else { dist = 0; } return dist / (double) jcas.getDocumentText().length(); }
public boolean calcNPHead () { Annotation a = m1.getContent(); // return (a.getEnd()==m1.getEnd() && a.getBegin()>m1.getBegin()) ? "yes" : "no"; FSIterator iter = jcas.getJFSIndexRepository().getAnnotationIndex(LookupWindowAnnotation.type).iterator(); while (iter.hasNext()) { LookupWindowAnnotation lwa = (LookupWindowAnnotation) iter.next(); if (lwa.getBegin()<=a.getBegin() && lwa.getEnd()==a.getEnd()) return true; } return false; }
protected <T extends TOP> T getFeatureStructure(JCas jcas, XMLElement hAnno, Element elm, Rule<T> mapping) { T annotation = null; if (mapping.isUnique()) { annotation = getOrCreate(jcas, mapping.getTargetClass()); } else { annotation = (T) jcas.getCas().createFS(JCasUtil.getType(jcas, mapping.getTargetClass())); jcas.getCas().addFsToIndexes(annotation); if (Annotation.class.isAssignableFrom(mapping.getTargetClass())) { ((Annotation) annotation).setBegin(hAnno.getBegin()); ((Annotation) annotation).setEnd(hAnno.getEnd()); } if (elm.hasAttr("xml:id") && !exists(elm.attr("xml:id"))) { String id = elm.attr("xml:id"); idRegistry.put(id, new AbstractMap.SimpleEntry<Element, FeatureStructure>(elm, annotation)); } } return annotation; }
private boolean isWhitespaceBefore(JCas cas, Annotation anno) { if (anno.getBegin() == 0) { return true; } char charBefore = cas.getDocumentText().charAt(anno.getBegin() - 1); return Character.isWhitespace(charBefore); }
private void indexAnnotations(JCas jCas) { for (Class conceptType : evidenceAnnotationTree.keySet()) { FSIndex annoIndex = jCas.getAnnotationIndex(conceptType); Iterator annoIter = annoIndex.iterator(); IntervalST<Annotation> intervalST = new IntervalST<>(); while (annoIter.hasNext()) { Annotation anno = (Annotation) annoIter.next(); intervalST.put(new Interval1D(anno.getBegin(), anno.getEnd()), anno); } evidenceAnnotationTree.put(conceptType, intervalST); } }
/** * Given an annotation, retrieve its last word. */ public static String getLastWord(JCas systemView, Annotation annotation) { List<WordToken> tokens = JCasUtil.selectCovered(systemView, WordToken.class, annotation); if(tokens.size() == 0) { return annotation.getCoveredText(); } WordToken lastToken = tokens.get(tokens.size() - 1); return lastToken.getCoveredText(); }