@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 { 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 jcas) throws AnalysisEngineProcessException { LinkedList<? extends Annotation> bases = new LinkedList<Annotation>(JCasUtil.select(jcas, baseAnnotation)); int n = bases.size(); double avgLength = (double) n / (double) numberOfWindows; int c = (int) Math.ceil(avgLength); int last = -1; int windows = 0; for (int i = 0; i < n; i++) { if (i % c == 0 && windows < numberOfWindows - 1 && last + 1 != i) { AnnotationFactory.createAnnotation(jcas, bases.get(last + 1).getBegin(), bases.get(i).getEnd(), targetAnnotation); windows++; last = i; } } AnnotationFactory.createAnnotation(jcas, bases.get(last).getBegin(), bases.getLast().getEnd(), targetAnnotation); }
protected void doAnnotations(JCas jcas, Collection<? extends Annotation> baseAnnotations, int end) { int i = 0; int b = 0; LinkedList<Annotation> window = null; if (overlappingWindows) { window = new LinkedList<Annotation>(); } for (final Annotation anno : baseAnnotations) { if (overlappingWindows) { window.add(anno); if (window.size() >= windowSize) { final Annotation firstAnno = window.pop(); AnnotationFactory.createAnnotation(jcas, firstAnno.getBegin(), anno.getEnd(), targetAnnotation); } } else { i++; if ((i % windowSize) == 0) { AnnotationFactory.createAnnotation(jcas, b, anno.getEnd(), targetAnnotation); } if ((i % windowSize) == 1) { b = anno.getBegin(); } } } if (!overlappingWindows) AnnotationFactory.createAnnotation(jcas, b, end, targetAnnotation); }
@Override public void process(JCas jcas) throws AnalysisEngineProcessException { if (baseAnnotation != null) { for (final Annotation anno : JCasUtil.select(jcas, baseAnnotation)) { if ((caseIndependent && anno.getCoveredText().equalsIgnoreCase(word)) || anno.getCoveredText().equals(word)) { AnnotationFactory.createAnnotation(jcas, anno.getBegin(), anno.getEnd(), targetAnnotation); } } } else { final Pattern pattern = Pattern.compile(word, Pattern.UNICODE_CASE | (caseIndependent ? Pattern.CASE_INSENSITIVE : 0)); final Matcher matcher = pattern.matcher(jcas.getDocumentText()); while (matcher.find()) { AnnotationFactory.createAnnotation(jcas, matcher.start(), matcher.end(), targetAnnotation); } } } }
@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); } }
public static void fixFigureAnnotations(JCas jcas) { for (Figure figure : new HashSet<Figure>(JCasUtil.select(jcas, Figure.class))) { String s = figure.getCoveredText(); if (s.contains(",")) { int oldEnd = figure.getEnd(); int i = s.indexOf(','); figure.setEnd(figure.getBegin() + i); FigureDescription fd = AnnotationUtil.trim( AnnotationFactory.createAnnotation(jcas, figure.getEnd() + 1, oldEnd, FigureDescription.class)); figure.setDescription(fd); } } }
@Deprecated public static <T extends Annotation> T selectRange2Annotation(JCas jcas, Element rootElement, Map<String, XMLElement> annoMap, String beginCssSelector, String endCssSelector, Class<T> annoClass) { Elements elms = rootElement.select(beginCssSelector); int begin = jcas.size(); for (Element elm : elms) { XMLElement hAnno = annoMap.get(elm.cssSelector()); if (hAnno.getBegin() < begin) begin = hAnno.getBegin(); } elms = rootElement.select(endCssSelector); int end = 0; for (Element elm : elms) { XMLElement hAnno = annoMap.get(elm.cssSelector()); if (hAnno.getEnd() > end) end = hAnno.getEnd(); } return AnnotationFactory.createAnnotation(jcas, begin, end, annoClass); }
@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(); } } }
if (mergedAnno == null) { if (insitu) mergedAnno = AnnotationFactory.createAnnotation(jCas, anno.getBegin(), anno.getEnd(), conceptMergedConceptMap.get(conceptName)); else { mergedAnno = AnnotationFactory.createAnnotation(jCas, i, i + 3, conceptMergedConceptMap.get(conceptName)); i += 3;
Annotation token = AnnotationFactory.createAnnotation(aJCas, start, offset, tokenClass); tokenAnnotations.add(token); int begin = tokenAnnotations.get(0).getBegin(); int end = tokenAnnotations.get(tokenAnnotations.size() - 1).getEnd(); AnnotationFactory.createAnnotation(aJCas, begin, end, sentenceClass);
public void export(JCas jcas, Graph<Figure, ?> graph) throws IOException { StringWriter sw = new StringWriter(); sw.write(" \n"); for (Figure figure1 : graph.vertexSet()) { for (Figure figure2 : graph.vertexSet()) { if (graph.containsEdge(figure1, figure2)) { sw.write(figure1.getBegin() + " " + figure2.getBegin()); Object edge = graph.getEdge(figure1, figure2); try { @SuppressWarnings("unchecked") double w = ((WeightedGraph<Figure, Object>) graph).getEdgeWeight(edge); sw.write(" " + w); } catch (ClassCastException e) { // we try to cast, but ignore it if impossible } sw.write("\n"); } } } sw.flush(); sw.close(); jcas.setDocumentText(sw.toString()); jcas.setDocumentLanguage(""); GraphMetaData graphAnnotation = AnnotationFactory.createAnnotation(jcas, 0, 1, GraphMetaData.class); graphAnnotation.setGraphClassName(graph.getClass().getCanonicalName()); if (!graph.edgeSet().isEmpty()) graphAnnotation.setEdgeClassName(graph.edgeSet().iterator().next().getClass().getCanonicalName()); } }
public static FigureType assignFigureType(JCas jcas, Figure figure, String cl, String value) { FigureType ft = AnnotationFactory.createAnnotation(jcas, figure.getBegin(), figure.getBegin() + 1, FigureType.class); ft.setTypeClass(cl); ft.setTypeValue(value); return ft; }
begin = s.getBegin(); } else if (!map.get(s) && begin >= 0) { AnnotationFactory.createAnnotation(jcas, begin, lastSentence.getEnd(), targetAnnotation); begin = -1;
@Deprecated public static <T extends Annotation> Collection<T> select2Annotation(JCas jcas, Element rootElement, Map<String, XMLElement> annoMap, String cssSelector, Class<T> annoClass, Annotation coveringAnnotation, Select2AnnotationCallback<T> callback) { HashSet<T> set = new HashSet<T>(); Elements elms = rootElement.select(cssSelector); for (Element elm : elms) { XMLElement hAnno = annoMap.get(elm.cssSelector()); if (elm.hasText() || elm.childNodeSize() > 0) { if (coveringAnnotation == null || (coveringAnnotation.getBegin() <= hAnno.getBegin() && coveringAnnotation.getEnd() >= hAnno.getEnd())) { T annotation = AnnotationFactory.createAnnotation(jcas, hAnno.getBegin(), hAnno.getEnd(), annoClass); if (callback != null) callback.call(annotation, elm); set.add(annotation); } } } return set; }
@Override public void process(JCas jcas) throws AnalysisEngineProcessException { long startTimestamp = System.currentTimeMillis(); WordListDescription desc = AnnotationFactory.createAnnotation(jcas, 0, 0, WordListDescription.class); desc.setLength(wordList.getLength(caseIndependent)); desc.setName(wordList.listName); Annotation newAnno = AnnotationFactory.createAnnotation(jcas, begin, end, targetAnnotation); if (feature != null) newAnno.setFeatureValueFromString(feature, wordList.listName);
@Override public void process(JCas jcas) throws AnalysisEngineProcessException { WordListDescription desc = AnnotationFactory.createAnnotation(jcas, 0, 0, WordListDescription.class); desc.setLength(wordList.getLength(caseIndependent)); desc.setName(wordList.listName); final Annotation newAnno = AnnotationFactory.createAnnotation(jcas, anno.getBegin(), anno.getEnd(), targetAnnotation); if (feature != null) final Matcher matcher = pattern.matcher(jcas.getDocumentText()); while (matcher.find()) { final Annotation newAnno = AnnotationFactory.createAnnotation(jcas, matcher.start(), matcher.end(), targetAnnotation); if (feature != null)
for (Annotation exc : except) { if (exc.getBegin() > b) { AnnotationUtil.trim(AnnotationFactory.createAnnotation(jcas, b, exc.getBegin(), Speech.class)); AnnotationUtil.trim(AnnotationFactory.createAnnotation(jcas, b, utterance.getEnd(), Speech.class));
for (XMLElement anno : JCasUtil.select(jcas, XMLElement.class)) { if (anno.getTag().equals("h2") && !anno.getCls().contains("author")) { AnnotationFactory.createAnnotation(jcas, anno.getBegin(), anno.getEnd(), SceneHeading.class); if (currentSceneBegin >= 0) { AnnotationFactory.createAnnotation(jcas, currentSceneBegin, anno.getBegin() - 1, Scene.class); AnnotationFactory.createAnnotation(jcas, anno.getBegin(), anno.getEnd(), ActHeading.class); if (currentActBegin >= 0) { AnnotationFactory.createAnnotation(jcas, currentActBegin, anno.getBegin() - 1, Act.class); if (currentSceneBegin >= 0) { AnnotationFactory.createAnnotation(jcas, currentSceneBegin, anno.getBegin() - 1, Scene.class); currentSceneBegin = -1; AnnotationFactory.createAnnotation(jcas, currentActBegin, mainMatter.getEnd(), Act.class); AnnotationFactory.createAnnotation(jcas, currentSceneBegin, mainMatter.getEnd(), Scene.class);
for (Annotation a : JCasUtil.select(jcas, annotationType)) { try { Annotation newAnnotation = AnnotationFactory.createAnnotation(goldView, a.getBegin(), a.getEnd(), a.getClass()); for (Feature f : a.getType().getFeatures()) {