protected void saveAnnotation(JCas jcas, Constructor<? extends Annotation> annoConstructor, int begin, int end) { Annotation anno = null; try { anno = annoConstructor.newInstance(jcas, begin, end); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } anno.addToIndexes(); }
/** * Apply the text and annotations to the jCas. * * <p>Once call once. */ public void build() { jCas.setDocumentText(documentText.toString()); for (Annotation a : annotations) { a.addToIndexes(jCas); } } }
/** * Apply the text and annotations to the jCas. * * <p>Once call once. */ public void build() { jCas.setDocumentText(documentText.toString()); for (Annotation a : annotations) { a.addToIndexes(jCas); } } }
private void createParentheticals(JCas jCas, String text, int offset) throws AnalysisEngineProcessException { Stack<Integer> leftRoundedParens = new Stack<Integer>(); leftRoundedParens.clear(); for (int ci = 0; ci < text.length(); ci++) { char c = text.charAt(ci); if (c == leftParen) { leftRoundedParens.push(ci); } if (c == rightParen && !leftRoundedParens.isEmpty()) { int leftOffset = leftRoundedParens.pop(); Annotation ann; try { ann = parentheticalConstructor.newInstance(jCas, offset + leftOffset, offset + ci + 1); } catch (Exception e) { throw new AnalysisEngineProcessException(e); } ann.addToIndexes(); } } }
private void createTokens(List<Token> pojoTokens, int offset, JCas jCas) throws InstantiationException, InvocationTargetException, IllegalAccessException { for (Token pojoToken : pojoTokens) { int tokenBegin = pojoToken.getBegin() + offset; int tokenEnd = pojoToken.getEnd() + offset; tokenConstructor.newInstance(jCas, tokenBegin, tokenEnd).addToIndexes(); } }
protected void saveConcept(JCas jcas, Constructor<? extends Annotation> annoConstructor, int begin, int end, String sectionName, String... rule) { Annotation anno = null; try { anno = annoConstructor.newInstance(jcas, begin, end); if (anno instanceof ConceptBASE) { if (sectionName != null) ((ConceptBASE) anno).setSection(sectionName); if (rule.length > 0) { ((ConceptBASE) anno).setNote(rule[0]); } } } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } anno.addToIndexes(); }
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 { String text = jCas.getDocumentText(); breakIterator.setText(text); int index = breakIterator.first(); int endIndex; while ((endIndex = breakIterator.next()) != BreakIterator.DONE) { String annotationText = text.substring(index, endIndex); if (!annotationText.trim().equals("")) { try { annotationConstructor.newInstance(jCas, index, endIndex).addToIndexes(); } catch (Exception e) { throw new AnalysisEngineProcessException(e); } } index = endIndex; } }
@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; }
@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; }
/** * returns the number of annotations of specified type in the */ public static int countAnnotationsInSpan(JCas jcas, int type, int beginSpan, int endSpan) { Annotation ann = new Annotation(jcas, beginSpan, endSpan); ann.addToIndexes(); AnnotationIndex<?> annIdx = jcas.getAnnotationIndex(type); ann.removeFromIndexes(); return annIdx.size(); }
/** * For correct behavior, requires types to be listed in TypePriorities so that the subiterator works as expected */ public static FSIterator getAnnotationsIteratorInSpan(JCas jcas, int type, int beginSpan, int endSpan) { Annotation ann = new Annotation(jcas, beginSpan, endSpan); ann.addToIndexes(); AnnotationIndex<?> annIdx = jcas.getAnnotationIndex(type); FSIterator<?> itr = annIdx.subiterator(ann); ann.removeFromIndexes(); return itr; }
/** * returns the number of annotations of specified type in the */ public static int countAnnotationsInSpan(JCas jcas, int type, int beginSpan, int endSpan) { Annotation ann = new Annotation(jcas, beginSpan, endSpan); ann.addToIndexes(); AnnotationIndex<?> annIdx = jcas.getAnnotationIndex(type); ann.removeFromIndexes(); return annIdx.size(); }
/** * For correct behavior, requires types to be listed in TypePriorities so that the subiterator works as expected */ public static FSIterator getAnnotationsIteratorInSpan(JCas jcas, int type, int beginSpan, int endSpan) { Annotation ann = new Annotation(jcas, beginSpan, endSpan); ann.addToIndexes(); AnnotationIndex<?> annIdx = jcas.getAnnotationIndex(type); FSIterator<?> itr = annIdx.subiterator(ann); ann.removeFromIndexes(); return itr; }
@Override public void process(JCas aJCas) throws AnalysisEngineProcessException { // Do nothing Pattern p = Pattern.compile("\\d+"); Matcher m = p.matcher(aJCas.getDocumentText()); while (m.find()) { Annotation a = new Annotation(aJCas); a.setBegin(m.start()); a.setEnd(m.end()); a.addToIndexes(); } } }
private void addAnnotation(final int start, final int end) { final Annotation a = new WordToken(jCas); a.setBegin(start); a.setEnd(end); a.addToIndexes(); }
/** * Add an annotation to the JCas index, notifying UimaMonitor of the fact we have done so * * @param annot Annotation(s) to add */ public void add(Collection<? extends Annotation> annotations) { for (Annotation annot : annotations) { annot.addToIndexes(); monitor.entityAdded(annot.getType().getName()); if (annot instanceof Entity) { Entity entity = (Entity) annot; // Add in a value if it doesn't have one if (Strings.isNullOrEmpty(entity.getValue())) { entity.setValue(annot.getCoveredText()); } addToHistory(annot.getCAS(), HistoryEvents.createAdded((Recordable) annot, referrer)); } } }
protected Annotation createAnnotation(AnnotationFS annotation, MatchContext context, RutaStream stream) { Type t = type.getType(context, stream); AnnotationFS newAnnotationFS = stream.getCas().createAnnotation(t, annotation.getBegin(), annotation.getEnd()); Annotation newAnnotation = null; if (newAnnotationFS instanceof Annotation) { newAnnotation = (Annotation) newAnnotationFS; newAnnotation.addToIndexes(); } else { return null; } stream.addAnnotation(newAnnotation, context.getRuleMatch()); return newAnnotation; }
protected Annotation createAnnotation(AnnotationFS matchedAnnotation, RuleElement element, TextMarkerStream stream, RuleMatch match) { Type t = type.getType(element.getParent()); AnnotationFS newAnnotationFS = stream.getCas().createAnnotation(t, matchedAnnotation.getBegin(), matchedAnnotation.getEnd()); Annotation newAnnotation = null; if (newAnnotationFS instanceof Annotation) { newAnnotation = (Annotation) newAnnotationFS; newAnnotation.addToIndexes(); } else { return null; } stream.addAnnotation(newAnnotation, match); return newAnnotation; }
/** * Add an annotation to the JCas index, notifying UimaMonitor of the fact we have done so * * @param annot Annotation(s) to add */ public void add(Collection<? extends Annotation> annotations) { for (Annotation annot : annotations) { annot.addToIndexes(); monitor.entityAdded(annot.getType().getName()); if (annot instanceof Entity) { Entity entity = (Entity) annot; // Add in a value if it doesn't have one if (Strings.isNullOrEmpty(entity.getValue())) { entity.setValue(annot.getCoveredText()); } addToHistory(annot.getCAS(), HistoryEvents.createAdded((Recordable) annot, referrer)); } } }