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; } } }
@Override public void process(JCas aJCas) throws AnalysisEngineProcessException { DocumentMetaData dmd = JCasUtil.selectSingle(aJCas, DocumentMetaData.class); try { bw.write(dmd.getDocumentId() + "\t" + aJCas.getDocumentText() + "\n"); } catch (IOException e) { throw new AnalysisEngineProcessException(e); } }
@Override public void process( JCas jCas ) throws AnalysisEngineProcessException { try { JCas goldView = jCas.getView( GOLD_VIEW_NAME ); goldView.setDocumentText( jCas.getDocumentText() ); } catch ( CASException e ) { throw new AnalysisEngineProcessException( e ); } } }
/** * Serializes a CAS in the given format. * * @param jcas * CAS (Common Analysis System) to be serialized. * @param type * type of cTAKES (UIMA) serializer used to write CAS. * @param prettyPrint * {@code true} to do pretty printing of output. * @param stream * {@link OutputStream} object used to print out information * extracted by using cTAKES. * @throws SAXException * if there was a SAX exception. * @throws IOException * if any I/O error occurs. */ public static void serialize(JCas jcas, CTAKESSerializer type, boolean prettyPrint, OutputStream stream) throws SAXException, IOException { if (type == CTAKESSerializer.XCAS) { XCASSerializer.serialize(jcas.getCas(), stream, prettyPrint); } else if (type == CTAKESSerializer.XMI) { XmiCasSerializer.serialize(jcas.getCas(), jcas.getTypeSystem(), stream, prettyPrint, new XmiSerializationSharedData()); } else { XmlCasSerializer.serialize(jcas.getCas(), jcas.getTypeSystem(), stream); } }
@Override public void getNext(JCas sJCas) throws IOException { isDone = true; sJCas.setDocumentLanguage(language); sJCas.setDocumentText(documentText); }
@Test public void testAllCapitals() throws Exception { AnalysisEngine ae = AnalysisEngineFactory.createEngine(TestAnnotator.class); jCas.setDocumentText("PERSON JOHN SMITH WAS SEEN ENTERING THE WAREHOUSE"); ae.process(jCas); assertEquals(0, JCasUtil.select(jCas, Person.class).size()); }
@Test public void testSingleTokenRelationWithoutFeatureValue() throws Exception { JCas jcas = makeJCasOneSentence(); CAS cas = jcas.getCas(); List<Token> tokens = new ArrayList<>(select(jcas, Token.class)); Token gov = tokens.get(0); Token dep = tokens.get(tokens.size() - 1); Type relationType = cas.getTypeSystem().getType("webanno.custom.Relation"); // One at the beginning // WebAnno legacy conventions // AnnotationFS fs1 = cas.createAnnotation(relationType, // min(dep.getBegin(), gov.getBegin()), // max(dep.getEnd(), gov.getEnd())); // DKPro Core conventions AnnotationFS fs1 = cas.createAnnotation(relationType, dep.getBegin(), dep.getEnd()); FSUtil.setFeature(fs1, "Governor", gov); FSUtil.setFeature(fs1, "Dependent", dep); cas.addFsToIndexes(fs1); writeAndAssertEquals(jcas, WebannoTsv3Writer.PARAM_RELATION_LAYERS, asList("webanno.custom.Relation")); }
@Test public void testMultiTokenChain() 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); Token t4 = tokens.get(3); Type head = cas.getTypeSystem().getType("webanno.custom.SimpleChain"); Type link = cas.getTypeSystem().getType("webanno.custom.SimpleLink"); makeChainHead(head, makeChainLink(link, cas, t1.getBegin(), t2.getEnd(), null, null, makeChainLink(link, cas, t3.getBegin(), t4.getEnd(), null, null, null))); writeAndAssertEquals(jcas, WebannoTsv3Writer.PARAM_CHAIN_LAYERS, asList("webanno.custom.Simple")); } @Test
/** initialize variables to correspond with Cas Type and Features * @generated * @param jcas JCas * @param casType Type */ public Stem_Type(JCas jcas, Type casType) { super(jcas, casType); casImpl.getFSClassRegistry().addGeneratorForType((TypeImpl)this.casType, getFSGenerator()); casFeat_value = jcas.getRequiredFeatureDE(casType, "value", "uima.cas.String", featOkTst); casFeatCode_value = (null == casFeat_value) ? JCas.INVALID_FEATURE_CODE : ((FeatureImpl)casFeat_value).getCode(); } }
@Override public void process(JCas jCas) throws AnalysisEngineProcessException { JCas sourceView; try { sourceView = jCas.getView(this.sourceViewName); } catch (CASException e) { throw new AnalysisEngineProcessException(e); } CasCopier copier = new CasCopier(sourceView.getCas(), jCas.getCas()); Feature sofaFeature = jCas.getTypeSystem().getFeatureByFullName(CAS.FEATURE_FULL_NAME_SOFA); // copy document text jCas.setDocumentText(sourceView.getDocumentText()); // copy text annotation Text sourceText = JCasUtil.selectSingle(sourceView, Text.class); Text text = (Text) copier.copyFs(sourceText); text.setFeatureValue(sofaFeature, jCas.getSofa()); text.addToIndexes(); // copy document creation time DocumentCreationTime sourceTime = JCasUtil.selectSingle( sourceView, DocumentCreationTime.class); DocumentCreationTime time = (DocumentCreationTime) copier.copyFs(sourceTime); time.setFeatureValue(sofaFeature, jCas.getSofa()); time.addToIndexes(); } }
@Override public void process(JCas jCas) throws AnalysisEngineProcessException { JCas sourceView; try { sourceView = jCas.getView(this.sourceViewName); } catch (CASException e) { throw new AnalysisEngineProcessException(e); } CasCopier copier = new CasCopier(sourceView.getCas(), jCas.getCas()); Feature sofaFeature = jCas.getTypeSystem().getFeatureByFullName(CAS.FEATURE_FULL_NAME_SOFA); for (Event sourceEvent : JCasUtil.select(sourceView, Event.class)) { Event event = (Event) copier.copyFs(sourceEvent); event.setFeatureValue(sofaFeature, jCas.getSofa()); if (event.getEventInstanceID() == null) { event.setEventInstanceID(event.getId().replaceAll("^e", "ei")); } event.addToIndexes(); } for (Time sourceTime : JCasUtil.select(sourceView, Time.class)) { if (!(sourceTime instanceof DocumentCreationTime)) { Time time = (Time) copier.copyFs(sourceTime); time.setFeatureValue(sofaFeature, jCas.getSofa()); time.addToIndexes(); } } } }
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; }
@Override public void process(JCas aJCas) throws AnalysisEngineProcessException { try{ logger.debug("Entering annotator WSDAnnotatorBaseDocumentCollective."); Map<WSDItem, Map<String, Double>> disambiguationResults = getDisambiguation(JCasUtil .select(aJCas, WSDItem.class), aJCas.getDocumentText()); for (WSDItem wsdItem : disambiguationResults.keySet()) { if (maxItemsAttempted >= 0 && numItemsAttempted++ >= maxItemsAttempted) { return; } setWSDItem(aJCas, wsdItem, disambiguationResults.get(wsdItem)); } } catch (SenseInventoryException e) { throw new AnalysisEngineProcessException(e); } } }
@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); } }
public String getMarkdownString(JCas jcas) { Feature feat = jcas.getTypeSystem().getType(type).getFeatureByBaseName(featureName); SortedSet<Insertion> insertions = new TreeSet<Insertion>(); for (Annotation a : JCasUtil.select(jcas, clazz)) { insertions.add(new Insertion(beginMark, a.getBegin())); insertions.add(new Insertion(endMark + "~" + a.getFeatureValueAsString(feat) + "~", a.getEnd())); } StringBuilder exportString = new StringBuilder(jcas.getDocumentText()); for (Insertion ins : insertions) { exportString.insert(ins.position, ins.content); } if (doubleNewline) return exportString.toString().replaceAll("\n", "\n\n"); else return exportString.toString().replaceAll("\n", " \n"); }
@Override public void process(JCas aJCas) throws AnalysisEngineProcessException { try (OutputStream docOS = getOutputStream(aJCas, filenameSuffix)) { IOUtils.write(aJCas.getDocumentText(), docOS, targetEncoding); } catch (Exception e) { throw new AnalysisEngineProcessException(e); } } }
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; }
private void processDocument(JCas aJCas) throws AnalysisEngineProcessException { if (!JCasUtil.exists(aJCas, TextClassificationTarget.class)) { TextClassificationTarget aTarget = new TextClassificationTarget(aJCas, 0, aJCas.getDocumentText().length()); aTarget.addToIndexes(); } // we need an outcome annotation to be present if (!JCasUtil.exists(aJCas, TextClassificationOutcome.class)) { TextClassificationOutcome outcome = new TextClassificationOutcome(aJCas); outcome.setOutcome(""); outcome.addToIndexes(); } // create new UIMA annotator in order to separate the parameter spaces // this annotator will get initialized with its own set of parameters // loaded from the model try { engine.process(aJCas); } catch (Exception e) { throw new AnalysisEngineProcessException(e); } }
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; }
jcas.setDocumentText(metaText.toString() + sb.toString()); ae.process(jcas); Collection<IdentifiedAnnotation> collection = JCasUtil.select(jcas, IdentifiedAnnotation.class); Iterator<IdentifiedAnnotation> iterator = collection.iterator(); while (iterator.hasNext()) {