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); }
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(); }
@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); } }
private static AnnotationFS makeLinkHostFS(JCas aJCas, String aType, int aBegin, int aEnd, FeatureStructure... aLinks) { Type hostType = aJCas.getTypeSystem().getType(aType); AnnotationFS hostA1 = aJCas.getCas().createAnnotation(hostType, aBegin, aEnd); if (aLinks != null) { hostA1.setFeatureValue(hostType.getFeatureByBaseName("links"), FSCollectionFactory.createFSArray(aJCas, asList(aLinks))); } aJCas.getCas().addFsToIndexes(hostA1); return hostA1; }
private void addTCSequenceAnnotation(JCas jcas) { Type type = jcas.getCas().getTypeSystem().getType(nameSequence); Collection<AnnotationFS> sequenceAnnotation = CasUtil.select(jcas.getCas(), type); for (AnnotationFS seq : sequenceAnnotation) { TextClassificationSequence tcs = new TextClassificationSequence(jcas, seq.getBegin(), seq.getEnd()); tcs.addToIndexes(); } }
private static FeatureStructure makeLinkFS(JCas aJCas, String aType, String aSlotLabel, AnnotationFS aTarget) { Type linkType = aJCas.getTypeSystem().getType(aType); FeatureStructure linkA1 = aJCas.getCas().createFS(linkType); linkA1.setStringValue(linkType.getFeatureByBaseName("role"), aSlotLabel); linkA1.setFeatureValue(linkType.getFeatureByBaseName("target"), aTarget); aJCas.getCas().addFsToIndexes(linkA1); return linkA1; }
public static void addSourceDocumentInformation(CAS cas, File each) { Type sdiType = cas.getTypeSystem() .getType("org.apache.uima.examples.SourceDocumentInformation"); if (sdiType != null) { if (cas.getAnnotationIndex(sdiType).size() == 0) { AnnotationFS sdi = cas.createAnnotation(sdiType, cas.getDocumentAnnotation().getBegin(), cas.getDocumentAnnotation().getEnd()); Feature uriFeature = sdiType.getFeatureByBaseName("uri"); sdi.setStringValue(uriFeature, each.toURI().getPath()); cas.addFsToIndexes(sdi); } } }
private AnnotationFS createPOSAnno(JCas aJCas, String aValue, int aBegin, int aEnd) { Type type = aJCas.getTypeSystem().getType(POS.class.getTypeName()); AnnotationFS clickedFs = aJCas.getCas().createAnnotation(type, aBegin, aEnd); Feature posValue = type.getFeatureByBaseName("PosValue"); clickedFs.setStringValue(posValue, aValue); aJCas.addFsToIndexes(clickedFs); return clickedFs; }
@Test public void testSimpleChain() throws Exception { JCas jcas = makeJCasOneSentence(); CAS cas = jcas.getCas(); List<Token> tokens = new ArrayList<>(select(jcas, Token.class)); Token t1 = tokens.get(0); Token t2 = tokens.get(1); Token t3 = tokens.get(2); Type head = cas.getTypeSystem().getType("webanno.custom.SimpleChain"); Type link = cas.getTypeSystem().getType("webanno.custom.SimpleLink"); makeChainHead(head, makeChainLink(link, cas, t1.getBegin(), t1.getEnd(), null, null, makeChainLink(link, cas, t2.getBegin(), t2.getEnd(), null, null, makeChainLink(link, cas, t3.getBegin(), t3.getEnd(), null, null, null)))); writeAndAssertEquals(jcas, WebannoTsv3Writer.PARAM_CHAIN_LAYERS, asList("webanno.custom.Simple")); }
public static <T extends TOP> T getOrCreate(JCas jcas, Class<T> targetClass) { if (JCasUtil.exists(jcas, targetClass)) { return JCasUtil.selectSingle(jcas, targetClass); } else { T annotation = jcas.getCas().createFS(JCasUtil.getType(jcas, targetClass)); jcas.getCas().addFsToIndexes(annotation); return annotation; } } }
/** * Create a new chain head feature structure. Already adds the chain to the CAS. */ private FeatureStructure newChain(JCas aJCas, AnnotationFS aFirstLink) { Type chainType = getAnnotationType(aJCas.getCas()); FeatureStructure newChain = aJCas.getCas().createFS(chainType); newChain.setFeatureValue(chainType.getFeatureByBaseName(chainFirstFeatureName), aFirstLink); aJCas.addFsToIndexes(newChain); return newChain; }
@Override public void process(JCas jcas) throws AnalysisEngineProcessException { CAS cas = jcas.getCas(); Type sdiType = cas.getTypeSystem().getType(RutaEngine.SOURCE_DOCUMENT_INFORMATION); FSIterator<AnnotationFS> sdiit = cas.getAnnotationIndex(sdiType).iterator(); if (sdiit.isValid()) { AnnotationFS annotationFS = sdiit.get(); Feature uriFeature = sdiType.getFeatureByBaseName("uri"); String stringValue = annotationFS.getStringValue(uriFeature); File f = new File(stringValue); String name = f.getName(); CAS inView = cas.getView(inputView); if (outView == null) { outView = getContext().getEmptyCas(CAS.class); outView.reset(); CasCopier cc = new CasCopier(inView, outView, true); cc.copyCasView(inView, outputView, true);
@Override public void initialize(UimaContext context) throws ResourceInitializationException { super.initialize(context); outputFile = new File(targetFolder, DeepLearningConstants.FILENAME_MAXIMUM_LENGTH); try { JCas typeFactory = JCasFactory.createJCas(); Type type = JCasUtil.getType(typeFactory, Class.forName(instanceTypeName)); AnnotationFS createAnnotation = typeFactory.getCas().createAnnotation(type, 0, 0); instanceType = createAnnotation.getType(); } catch (Exception e) { throw new ResourceInitializationException(e); } }
/** * Function for creating generic UIMA {@code FeatureStructure}s. * * @param featureStructure {@code FeatureStructure} to create a new object of the same type in the * target cas. * @return newly created {@code FeatureStructure} matching the type of the parameter {@code * FeatureStructure} */ private FeatureStructure defaultCreateType(FeatureStructure featureStructure) { String typeName = featureStructure.getType().getName(); Type targetType = targetCas.getTypeSystem().getType(typeName); return targetCas.createFS(targetType); }
@Override public void process(JCas jCas) throws AnalysisEngineProcessException { modelProvider.configure(jCas.getCas()); mappingProvider.configure(jCas.getCas()); List<Token> tokens = selectCovered(jCas, Token.class, 0, jCas.getDocumentText().length()); List<TaggedToken> taggedTokens = tagTweetTokens(tokens, modelProvider.getResource()); for (TaggedToken taggedToken : taggedTokens) { Type posType = mappingProvider.getTagType(taggedToken.tag); POS pos = (POS) jCas.getCas().createAnnotation(posType, taggedToken.getBegin(), taggedToken.getEnd()); pos.setPosValue(taggedToken.tag.intern()); pos.addToIndexes(); taggedToken.token.setPos(pos); } }
CASArtifact( @Nullable LabelAdapters labelAdapters, CAS cas, String artifactID ) { this.labelAdapters = labelAdapters; this.cas = cas; TypeSystem typeSystem = cas.getTypeSystem(); metadataType = typeSystem.getType("ArtifactMetadata"); keyFeature = metadataType.getFeatureByBaseName("key"); valueFeature = metadataType.getFeatureByBaseName("value"); metadataCas = cas.createView("metadata"); metadataCas.setDocumentText(""); Type idType = typeSystem.getType("ArtifactID"); Feature idFeat = idType.getFeatureByBaseName("artifactID"); this.artifactID = artifactID; FeatureStructure documentIdFs = metadataCas.createFS(idType); documentIdFs.setStringValue(idFeat, artifactID); metadataCas.addFsToIndexes(documentIdFs); metadataIndex = metadataCas.getIndexRepository().getIndex("metadata", metadataType); casMetadata = new CASMetadata(); }
cas.removeFsFromIndexes(annotation); sentenceTokenList.add(tokenAnnotation.getCoveredText()); names[i].getStart()).getBegin(); names[i].getEnd() - 1).getEnd(); nameAnnotations[i] = cas.createAnnotation(nameType, startIndex, endIndex); cas.getIndexRepository().addFS(nameAnnotations[i]);
.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]);
@Override public void process(JCas jcas) throws AnalysisEngineProcessException { try { converter.add(jcas, inputPaths, jcas.getCas().getTypeSystem().getType(contextType)); } catch (IOException e) { throw new AnalysisEngineProcessException(e); } }
protected void process(CAS cas, AnnotationFS sentenceAnnotation) { FSIndex<AnnotationFS> allTokens = cas.getAnnotationIndex(mTokenType); ContainingConstraint containingConstraint = new ContainingConstraint(sentenceAnnotation); String sentence = sentenceAnnotation.getCoveredText(); Iterator<AnnotationFS> containingTokens = cas.createFilteredIterator( allTokens.iterator(), containingConstraint); List<Span> tokenSpans = new LinkedList<>(); while (containingTokens.hasNext()) { AnnotationFS token = containingTokens.next(); tokenSpans.add(new Span(token.getBegin() - sentenceAnnotation.getBegin(), token.getEnd() - sentenceAnnotation.getBegin())); } ParseConverter converter = new ParseConverter(sentence, tokenSpans.toArray(new Span[tokenSpans.size()])); Parse unparsedTree = converter.getParseForTagger(); if (unparsedTree.getChildCount() > 0) { Parse parse = mParser.parse(unparsedTree); // TODO: We need a strategy to handle the case that a full // parse could not be found. What to do in this case? parse = converter.transformParseFromTagger(parse); if (mLogger.isLoggable(Level.INFO)) { StringBuffer parseString = new StringBuffer(); parse.show(parseString); mLogger.log(Level.INFO, parseString.toString()); } createAnnotation(cas, sentenceAnnotation.getBegin(), parse); } }