private void addChunkAnnotation(CAS tcas, AnnotationFS[] tokenAnnotations, String tag, int start, int end) { AnnotationFS chunk = tcas.createAnnotation(mChunkType, tokenAnnotations[start].getBegin(), tokenAnnotations[end - 1].getEnd()); chunk.setStringValue(mChunkFeature, tag); tcas.getIndexRepository().addFS(chunk); }
public boolean hasNext() { return this.upperIt.hasNext(); }
@Override protected void setBestCategory(CAS tcas, String bestCategory) { FSIndex<AnnotationFS> categoryIndex = tcas.getAnnotationIndex(mCategoryType); AnnotationFS categoryAnnotation; if (categoryIndex.size() > 0) { categoryAnnotation = categoryIndex.iterator().next(); } else { categoryAnnotation = tcas.createAnnotation(mCategoryType, 0, tcas.getDocumentText().length()); tcas.getIndexRepository().addFS(categoryAnnotation); } categoryAnnotation.setStringValue(mCategoryFeature, bestCategory); } }
/** * Create a new combo iterator. * * @param cas * The CAS we're operating on. * @param upper * The type of the upper iterator, e.g., sentence. * @param lower * The type of the lower iterator, e.g., token. */ public AnnotationComboIterator(CAS cas, Type upper, Type lower) { this.upperIt = cas.getAnnotationIndex(upper).iterator(); this.lowerIt = cas.getAnnotationIndex(lower).iterator(); this.upperIt.moveToFirst(); this.lowerIt.moveToFirst(); if (this.upperIt.isValid()) { final AnnotationFS upperFS = this.upperIt.get(); this.upperBegin = upperFS.getBegin(); this.upperEnd = upperFS.getEnd(); } else { this.nextLowerChecked = true; } }
.getAnnotationIndex(containerType); String text = containerAnnotation.getCoveredText(); sentences[i] = cas.createAnnotation(sentenceType, sentPositions[i].getStart() + containerAnnotation.getBegin(), sentPositions[i].getEnd() + containerAnnotation.getBegin()); cas.getIndexRepository().addFS(sentences[i]); logger.log(Level.FINER, "\"" + sentences[i].getCoveredText() + "\"");
public void process(CAS cas) { FSIterator<AnnotationFS> tokenAnnotations = cas.getAnnotationIndex(mTokenType).iterator(); List<String> tokensList = new ArrayList<>(); while (tokenAnnotations.hasNext()) { tokensList.add(tokenAnnotations.next().getCoveredText()); } double[] result = mCategorizer.categorize(tokensList.toArray(new String[tokensList.size()])); String bestCategory = mCategorizer.getBestCategory(result); setBestCategory(cas, bestCategory); } }
public AnnotationIteratorPair next() { if (!this.upperIt.hasNext()) { throw new NoSuchElementException(); } final AnnotationFS upperFS = this.upperIt.next(); this.upperBegin = upperFS.getBegin(); this.upperEnd = upperFS.getEnd(); this.nextLowerChecked = false; return new AnnotationIteratorPair(upperFS, new AnnotationIterator()); }
public boolean hasNext() { if (AnnotationComboIterator.this.nextLowerChecked) { return AnnotationComboIterator.this.nextLowerAvailable; } AnnotationComboIterator.this.nextLowerChecked = true; AnnotationComboIterator.this.nextLowerAvailable = false; if (AnnotationComboIterator.this.lowerIt.isValid()) { AnnotationFS lowerFS = AnnotationComboIterator.this.lowerIt.get(); int lowerBegin = lowerFS.getBegin(); while (lowerBegin < AnnotationComboIterator.this.upperBegin) { AnnotationComboIterator.this.lowerIt.moveToNext(); if (AnnotationComboIterator.this.lowerIt.isValid()) { lowerFS = AnnotationComboIterator.this.lowerIt.get(); lowerBegin = lowerFS.getBegin(); } else { return false; } } if (AnnotationComboIterator.this.upperEnd >= lowerFS.getEnd()) { AnnotationComboIterator.this.nextLowerAvailable = true; } } return AnnotationComboIterator.this.nextLowerAvailable; }
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; }
protected void documentDone(CAS cas) { // TODO: Create confidence FS // contains String name type // contains Double prob if (documentConfidenceType != null) { FeatureStructure confidenceFS = cas.createFS(documentConfidenceType); confidenceFS.setDoubleValue(documentConfidenceFeature, documentConfidence.mean()); confidenceFS.setStringValue(documentConfidenceNameTypeFeature, mNameType.getName()); cas.addFsToIndexes(confidenceFS); } // Clears the adaptive data which was created for the current document mNameFinder.clearAdaptiveData(); documentConfidence = new Mean(); }
public static Feature getRequiredFeature(Type type, String featureName) throws AnalysisEngineProcessException { Feature feature = type.getFeatureByBaseName(featureName); if (feature == null) { throw new OpenNlpAnnotatorProcessException( ExceptionMessages.FEATURE_NOT_FOUND, new Object[] {type.getName(), featureName}); } return feature; }
/** * Checks if the given feature has the expected type otherwise * an exception is thrown. * * @param feature * @param expectedType * @throws AnalysisEngineProcessException - if type does not match */ private static void checkFeatureType(Feature feature, String expectedType) throws AnalysisEngineProcessException { if (!feature.getRange().getName().equals(expectedType)) { throw new OpenNlpAnnotatorProcessException( ExceptionMessages.WRONG_FEATURE_TYPE, new Object[] {feature.getName(), expectedType }); } }
/** * Initializes the type system. */ public void typeSystemInit(TypeSystem typeSystem) throws AnalysisEngineProcessException { // sentence type // String sentenceTypeName = // AnnotatorUtil.getRequiredStringParameter(mContext, // UimaUtil.SENTENCE_TYPE_PARAMETER); // mSentenceType = AnnotatorUtil.getType(typeSystem, sentenceTypeName); // name type mNameType = AnnotatorUtil.getRequiredTypeParameter(context, typeSystem, NameFinder.NAME_TYPE_PARAMETER); mStructureFeature = AnnotatorUtil.getRequiredFeatureParameter(context, mNameType, "opennlp.uima.normalizer.StructureFeature"); if (!SUPPORTED_TYPES.contains(mStructureFeature.getRange().getName())) { throw new AnalysisEngineProcessException( ExceptionMessages.MESSAGE_CATALOG, "range_type_unsupported", new Object[] {mStructureFeature.getRange().getName()}); } }
/** * Retrieves a type of the given name from the given type system. * * @param typeSystem * @param name * @return the type * @throws AnalysisEngineProcessException */ public static Type getType(TypeSystem typeSystem, String name) throws AnalysisEngineProcessException { Type type = typeSystem.getType(name); if (type == null) { throw new OpenNlpAnnotatorProcessException( ExceptionMessages.TYPE_NOT_FOUND, new Object[] {name}); } return type; }
public static Feature getOptionalFeature(Type type, String featureName, String rangeType) throws AnalysisEngineProcessException { Feature feature = type.getFeatureByBaseName(featureName); checkFeatureType(feature, rangeType); return feature; }
.getAnnotationIndex(removeAnnotationType); Iterator<AnnotationFS> containingTokens = cas.createFilteredIterator( allRemoveAnnotations.iterator(), containingConstraint); cas.removeFsFromIndexes(it.next());
public AnnotationFS next() { if (AnnotationComboIterator.this.nextLowerChecked) { if (!AnnotationComboIterator.this.nextLowerAvailable) { throw new NoSuchElementException(); } } else if (!hasNext()) { throw new NoSuchElementException(); } AnnotationComboIterator.this.nextLowerChecked = false; final AnnotationFS rv = AnnotationComboIterator.this.lowerIt.get(); AnnotationComboIterator.this.lowerIt.moveToNext(); return rv; }
/** * Performs parsing on the given {@link CAS} object. */ public void process(CAS cas) { FSIndex<AnnotationFS> sentences = cas.getAnnotationIndex(mSentenceType); for (AnnotationFS sentence : sentences) { process(cas, sentence); } }
@Override public void process(CAS cas) throws AnalysisEngineProcessException { FSIndex<AnnotationFS> sentences = cas.getAnnotationIndex(sentenceType); int sentenceOffset = sentence.getBegin(); .createAnnotation(tokenType, sentenceOffset + tokenSpans[i].getStart(), sentenceOffset + tokenSpans[i].getEnd()); cas.getIndexRepository().addFS(tokenAnnotations[i]); tokeninzedSentenceLog.append(tokenAnnotations[i].getCoveredText()); tokeninzedSentenceLog.append(' ');
@Override public void typeSystemInit(TypeSystem typeSystem) throws AnalysisEngineProcessException { super.typeSystemInit(typeSystem); containerType = AnnotatorUtil.getOptionalTypeParameter(context, typeSystem, "opennlp.uima.ContainerType"); if (containerType == null) { containerType = typeSystem.getType(CAS.TYPE_NAME_DOCUMENT_ANNOTATION); } sentenceType = AnnotatorUtil.getRequiredTypeParameter(context, typeSystem, UimaUtil.SENTENCE_TYPE_PARAMETER); }