Java Code Examples for org.apache.uima.cas.CAS#setDocumentText()
The following examples show how to use
org.apache.uima.cas.CAS#setDocumentText() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnalysisEngine_implTest.java From uima-uimaj with Apache License 2.0 | 6 votes |
public void testMultiViewAnnotatorInput() throws Exception { try { AnalysisEngineDescription transAnnotatorDesc = UIMAFramework.getXMLParser().parseAnalysisEngineDescription( new XMLInputSource(JUnitExtension .getFile("TextAnalysisEngineImplTest/MultiViewAnnotator.xml"))); PrimitiveAnalysisEngine_impl ae = new PrimitiveAnalysisEngine_impl(); ae.initialize(transAnnotatorDesc, null); CAS tcas = ae.newCAS(); tcas.setDocumentText("this beer is good"); assertTrue(tcas.getView("_InitialView").getDocumentText().equals("this beer is good")); ae.process(tcas); assertTrue(tcas.getView("GermanDocument").getViewName().equals("GermanDocument")); assertTrue(tcas.getView("GermanDocument").getDocumentText().equals("das bier ist gut")); } catch (Exception e) { JUnitExtension.handleException(e); } }
Example 2
Source File: CasDiffTest.java From webanno with Apache License 2.0 | 6 votes |
@Test public void singleEmptyCasTest() throws Exception { String text = ""; CAS user1Cas = JCasFactory.createJCas().getCas(); user1Cas.setDocumentText(text); Map<String, List<CAS>> casByUser = new LinkedHashMap<>(); casByUser.put("user1", asList(user1Cas)); List<SpanDiffAdapter> diffAdapters = asList(new SpanDiffAdapter(Token.class.getName())); DiffResult result = doDiff(diffAdapters, LINK_TARGET_AS_LABEL, casByUser).toResult(); // result.print(System.out); assertEquals(0, result.size()); assertEquals(0, result.getDifferingConfigurationSets().size()); }
Example 3
Source File: SerDesTest6.java From uima-uimaj with Apache License 2.0 | 6 votes |
public void testDocText() { try { CAS cas = CasCreationUtils.createCas((TypeSystemDescription) null, null, null); cas.setDocumentLanguage("latin"); cas.setDocumentText("test"); ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); Serialization.serializeWithCompression(cas, baos, cas.getTypeSystem()); CAS cas2 = CasCreationUtils.createCas((TypeSystemDescription) null, null, null); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); Serialization.deserializeCAS(cas2, bais); assertEquals("latin", cas2.getDocumentLanguage()); assertEquals("test", cas2.getDocumentText()); } catch (Exception e) { throw new RuntimeException(e); } }
Example 4
Source File: CASArtifact.java From biomedicus with Apache License 2.0 | 5 votes |
@Nonnull @Override public Document addDocument(@Nonnull String name, @Nonnull String text) { CAS view = cas.createView(name); view.setDocumentText(text); return new CASDocument(view, labelAdapters); }
Example 5
Source File: BratAnnotatorUtility.java From webanno with Apache License 2.0 | 5 votes |
public static CAS clearAnnotations(CAS aCas) throws IOException { CAS target; try { target = CasFactory.createCas((TypeSystemDescription) null); } catch (UIMAException e) { throw new IOException(e); } // Copy the CAS - basically we do this just to keep the full type system information CASCompleteSerializer serializer = serializeCASComplete((CASImpl) getRealCas(aCas)); deserializeCASComplete(serializer, (CASImpl) getRealCas(target)); // Remove all annotations from the target CAS but we keep the type system! target.reset(); // Copy over essential information if (exists(aCas, getType(aCas, DocumentMetaData.class))) { copyDocumentMetadata(aCas, target); } else { WebAnnoCasUtil.createDocumentMetadata(aCas); } target.setDocumentLanguage(aCas.getDocumentLanguage()); // DKPro Core Issue 435 target.setDocumentText(aCas.getDocumentText()); // Transfer token boundaries for (AnnotationFS t : selectTokens(aCas)) { target.addFsToIndexes(createToken(target, t.getBegin(), t.getEnd())); } // Transfer sentence boundaries for (AnnotationFS s : selectSentences(aCas)) { target.addFsToIndexes(createSentence(target, s.getBegin(), s.getEnd())); } return target; }
Example 6
Source File: SubjectObjectFeatureSupportTest.java From inception with Apache License 2.0 | 5 votes |
@Test public void testWrapUnwrap() throws Exception { CAS cas = JCasFactory.createJCasFromPath("src/test/resources/desc/type/webannoTestTypes.xml") .getCas(); SubjectObjectFeatureSupport sut = new SubjectObjectFeatureSupport(); AnnotationFeature feat1 = new AnnotationFeature("slot", "webanno.custom.SimpleSpan"); feat1.setLinkTypeName("webanno.custom.LinkType"); feat1.setLinkMode(LinkMode.WITH_ROLE); feat1.setLinkTypeRoleFeatureName("role"); feat1.setLinkTypeTargetFeatureName("target"); feat1.setMode(MultiValueMode.ARRAY); List<LinkWithRoleModel> links = new ArrayList<>(); links.add(new LinkWithRoleModel("role", "label", 3)); cas.setDocumentText("label"); Type targetType = cas.getTypeSystem().getType(feat1.getType()); Type linkType = cas.getTypeSystem().getType(feat1.getLinkTypeName()); AnnotationFS targetFS = cas.createAnnotation(targetType, 0, cas.getDocumentText().length()); ArrayFS array = cas.createArrayFS(1); FeatureStructure linkFS = cas.createFS(linkType); FSUtil.setFeature(linkFS, feat1.getLinkTypeRoleFeatureName(), "role"); FSUtil.setFeature(linkFS, feat1.getLinkTypeTargetFeatureName(), targetFS); array.set(0, linkFS); assertThat(sut.wrapFeatureValue(feat1, cas, array)).isEqualTo(links); assertThat(sut.wrapFeatureValue(feat1, cas, null)).isEmpty(); assertThatThrownBy(() -> sut.wrapFeatureValue(feat1, cas, new Object())) .isInstanceOf(IllegalArgumentException.class); assertThat(sut.unwrapFeatureValue(feat1, cas, links)).isSameAs(links); assertThat(sut.unwrapFeatureValue(feat1, cas, null)).isNull(); assertThatThrownBy(() -> sut.unwrapFeatureValue(feat1, cas, new Object())) .isInstanceOf(IllegalArgumentException.class); }
Example 7
Source File: FeaturePathTest.java From uima-uimaj with Apache License 2.0 | 5 votes |
public void testInitializeWithAddAPI() throws Exception { XMLInputSource in = new XMLInputSource(JUnitExtension .getFile("featurePathTests/FeaturePathTestTypeSystem.xml")); TypeSystemDescription typeSystemDescription = UIMAFramework .getXMLParser().parseTypeSystemDescription(in); CAS cas = CasCreationUtils.createCas(typeSystemDescription, null, null); cas.setDocumentText("Sample Text"); Feature stringFeat = cas.getDocumentAnnotation().getType() .getFeatureByBaseName("stringFeature"); Feature refFeat = cas.getDocumentAnnotation().getType() .getFeatureByBaseName("refFeature2"); cas.getDocumentAnnotation().setStringValue(stringFeat, "MyExample"); cas.getDocumentAnnotation().setFeatureValue(refFeat, cas.getDocumentAnnotation()); FeaturePath featurePath = new FeaturePathImpl(); featurePath.initialize("/refFeature2"); featurePath.addFeature(stringFeat); assertEquals("MyExample", featurePath.getValueAsString(cas .getDocumentAnnotation())); assertEquals("/refFeature2/stringFeature", featurePath.getFeaturePath()); assertTrue(featurePath.size() == 2); // test case change: new impl sets features as paths are traversed; assertTrue(featurePath.getFeature(1) == stringFeat); featurePath.typeInit(cas.getDocumentAnnotation().getType()); assertEquals("MyExample", featurePath.getValueAsString(cas .getDocumentAnnotation())); assertEquals("MyExample", featurePath.getStringValue(cas .getDocumentAnnotation())); assertTrue(featurePath.size() == 2); assertTrue(featurePath.getFeature(1) == stringFeat); }
Example 8
Source File: CasMultiplierTest.java From uima-uimafit with Apache License 2.0 | 5 votes |
@Override public AbstractCas next() throws AnalysisEngineProcessException { outputCreated = true; inputReceived = false; CAS output = getEmptyCAS(); output.setDocumentText(Integer.toString(value+1)); value = -1; // System.out.printf(" Out : %s%n", output.getDocumentText()); return output; }
Example 9
Source File: CasHeapSizeTestCollectionReader.java From uima-uimaj with Apache License 2.0 | 5 votes |
public void getNext(CAS aCAS) throws IOException, CollectionException { int actualHeapSize = CasTestUtil.getHeapSize(aCAS); // in v3 the actualHeap is always 500,000, so this test always miscompares // Assert.assertEquals(EXPECTED_HEAP_SIZE, actualHeapSize); numChecks--; // populate with doc to avoid error aCAS.setDocumentText("This is a test"); }
Example 10
Source File: AnnotatorTester.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * does configuration parameter test. * * @param configDescFilePath the config desc file path * @return AnalysisEngine * @throws Exception passthru */ public static AnalysisEngine doConfigurationTest(String configDescFilePath) throws Exception { try { AnalysisEngine ae = null; // Create an XML input source from the specifier file. XMLInputSource in = new XMLInputSource(configDescFilePath); // Parse the specifier. ResourceSpecifier specifier = UIMAFramework.getXMLParser() .parseResourceSpecifier(in); // Create the Text Analysis Engine. ae = UIMAFramework.produceAnalysisEngine(specifier, null, null); // Create a new CAS. CAS cas = ae.newCAS(); // Set the document text on the CAS. cas .setDocumentText("This is a simple text to check if the configuration works"); cas.setDocumentLanguage("en"); // Process the sample document. ae.process(cas); return ae; } catch (Exception ex) { JUnitExtension.handleException(ex); } return null; }
Example 11
Source File: StreamingCollectionReader.java From termsuite-core with Apache License 2.0 | 5 votes |
@Override public void getNext(CAS cas) throws IOException, CollectionException { this.cumulatedLength += currentDoc.getText().length(); logger.info("[Stream {}] Processing document {}: {} (total length processed: {})", this.streamName, this.mCurrentIndex, this.currentDoc.getUri(), this.cumulatedLength); SourceDocumentInformation sdi; try { sdi = new SourceDocumentInformation(cas.getJCas()); sdi.setUri(currentDoc.getUri()); cas.setDocumentLanguage(mLanguage.getCode()); cas.setDocumentText(currentDoc.getText()); sdi.setDocumentSize(currentDoc.getText().length()); sdi.setCumulatedDocumentSize(this.cumulatedLength); sdi.setBegin(0); sdi.setEnd(currentDoc.getText().length()); sdi.setOffsetInSource(0); sdi.setDocumentIndex(mCurrentIndex); /* * Cannot be known in case of streaming */ sdi.setCorpusSize(-1); sdi.setNbDocuments(-1); // Cannot know if this is the last sdi.setLastSegment(false); sdi.addToIndexes(); this.mCurrentIndex++; } catch (CASException e) { throw new CollectionException(e); } }
Example 12
Source File: SequencerFixedTest.java From uima-uimaj with Apache License 2.0 | 4 votes |
public void testSequencerFixedEn() throws Exception { AnalysisEngine ae = null; try { // create TempFile for test File outputReferenceFile = new File(this.testBaseDir, "SequencerTest.txt"); outputReferenceFile.delete(); // delete file if exist outputReferenceFile.createNewFile(); // create new file outputReferenceFile.deleteOnExit(); // delete file after closing VM // Create an XML input source from the specifier file. XMLInputSource in = new XMLInputSource(JUnitExtension .getFile("SequencerTest/SequencerFixedAggregate.xml")); // Parse the specifier. ResourceSpecifier specifier = UIMAFramework.getXMLParser().parseResourceSpecifier(in); // Create the Text Analysis Engine. ae = UIMAFramework.produceAnalysisEngine(specifier, null, null); // Create a new CAS. CAS cas = ae.newCAS(); // Our sample text. String text = "Hello world!"; // System.out.println("Processing text: \"" + text + "\""); // Set the document text on the CAS. cas.setDocumentText(text); cas.setDocumentLanguage("en"); // Process the sample document. ResultSpecification resultSpec = UIMAFramework.getResourceSpecifierFactory() .createResultSpecification(); resultSpec.addCapabilities(ae.getAnalysisEngineMetaData().getCapabilities()); ae.process(cas, resultSpec); // check fileoutput Assert.assertTrue(FileCompare.compare(outputReferenceFile, JUnitExtension .getFile("SequencerTest/SequencerFixedExpected.txt"))); outputReferenceFile.delete(); ((CASImpl)cas).traceFSflush(); } catch (Exception ex) { JUnitExtension.handleException(ex); } finally { // Destroy the CAS, releasing resources. if (ae != null) { ae.destroy(); } } }
Example 13
Source File: XmiCasDeserializerTest.java From uima-uimaj with Apache License 2.0 | 4 votes |
public void testMultipleSofas() throws Exception { try { CAS cas = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(), new FsIndexDescription[0]); // set document text for the initial view cas.setDocumentText("This is a test"); // create a new view and set its document text CAS cas2 = cas.createView("OtherSofa"); cas2.setDocumentText("This is only a test"); // Change this test to create an instance of TOP because you cannot add an annotation to other than // the view it is created in. https://issues.apache.org/jira/browse/UIMA-4099 // create a TOP and add to index of both views Type topType = cas.getTypeSystem().getTopType(); FeatureStructure aTOP = cas.createFS(topType); cas.getIndexRepository().addFS(aTOP); cas2.getIndexRepository().addFS(aTOP); FSIterator<FeatureStructure> it = cas.getIndexRepository().getAllIndexedFS(topType); FSIterator<FeatureStructure> it2 = cas2.getIndexRepository().getAllIndexedFS(topType); it.next(); it.next(); it2.next(); it2.next(); assertFalse(it.hasNext()); assertFalse(it2.hasNext()); // serialize StringWriter sw = new StringWriter(); XMLSerializer xmlSer = new XMLSerializer(sw, false); XmiCasSerializer xmiSer = new XmiCasSerializer(cas.getTypeSystem()); xmiSer.serialize(cas, xmlSer.getContentHandler()); String xml = sw.getBuffer().toString(); // deserialize into another CAS (repeat twice to check it still works after reset) CAS newCas = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(), new FsIndexDescription[0]); for (int i = 0; i < 2; i++) { XmiCasDeserializer newDeser = new XmiCasDeserializer(newCas.getTypeSystem()); ContentHandler newDeserHandler = newDeser.getXmiCasHandler(newCas); SAXParserFactory fact = SAXParserFactory.newInstance(); SAXParser parser = fact.newSAXParser(); XMLReader xmlReader = parser.getXMLReader(); xmlReader.setContentHandler(newDeserHandler); xmlReader.parse(new InputSource(new StringReader(xml))); // check sofas assertEquals("This is a test", newCas.getDocumentText()); CAS newCas2 = newCas.getView("OtherSofa"); assertEquals("This is only a test", newCas2.getDocumentText()); // check that annotation is still indexed in both views // check that annotation is still indexed in both views it = newCas.getIndexRepository().getAllIndexedFS(topType); it2 = newCas2.getIndexRepository().getAllIndexedFS(topType); it.next(); it.next(); it2.next(); it2.next(); assertFalse(it.hasNext()); // assertFalse(it2.hasNext()); assertTrue(tIndex.size() == 2); // document annot and this one // assertTrue(t2Index.size() == 2); // ditto newCas.reset(); } } catch (Exception e) { JUnitExtension.handleException(e); } }
Example 14
Source File: JsonCasDeserializer.java From termsuite-core with Apache License 2.0 | 4 votes |
public static void deserialize(InputStream inputStream, CAS cas, String encoding) { Preconditions.checkNotNull(inputStream, "Paramater input stream is null"); Preconditions.checkNotNull(inputStream, "Paramater CAS is null"); try { JsonFactory factory = new JsonFactory(); parser = factory.createParser(inputStream); SourceDocumentInformation sdi = (SourceDocumentInformation) cas.createAnnotation(cas.getJCas().getCasType(SourceDocumentInformation.type), 0, 0); WordAnnotation wa = (WordAnnotation) cas.createAnnotation(cas.getJCas().getCasType(WordAnnotation.type), 0, 0); TermOccAnnotation toa = (TermOccAnnotation) cas.createAnnotation(cas.getJCas().getCasType(TermOccAnnotation.type), 0, 0); FixedExpression fe = (FixedExpression) cas.createAnnotation(cas.getJCas().getCasType(FixedExpression.type), 0, 0); boolean inSdi = false; boolean inWa = false; boolean inToa = false; boolean inFe = false; boolean inCoveredText = false; while ((token=parser.nextToken()) != null) { if (inSdi){ if (token == JsonToken.END_OBJECT) { inSdi = false; } else { fillSdi(parser,token,sdi); } } else if (inWa){ if (token == JsonToken.END_ARRAY) { inWa = false; } else if (token == JsonToken.END_OBJECT) { wa.addToIndexes(); wa = (WordAnnotation) cas.createAnnotation(cas.getJCas().getCasType(WordAnnotation.type), 0, 0); } fillWordAnnotations(parser, token, wa); } else if (inToa){ if (token == JsonToken.END_ARRAY && Objects.equals(parser.getParsingContext().getCurrentName(), "term_occ_annotations")) { inToa = false; } else if (token == JsonToken.END_OBJECT) { toa.addToIndexes(); toa = (TermOccAnnotation) cas.createAnnotation(cas.getJCas().getCasType(TermOccAnnotation.type), 0, 0); } FillTermOccAnnotations(parser, token, toa, cas); } else if (inFe){ if (token == JsonToken.END_ARRAY && Objects.equals(parser.getParsingContext().getCurrentName(), "fixed_expressions")) { inFe = false; } else if (token == JsonToken.END_OBJECT) { fe.addToIndexes(); fe = (FixedExpression) cas.createAnnotation(cas.getJCas().getCasType(FixedExpression.type), 0, 0); } FillFixedExpressions(parser, token, fe, cas); } else if (inCoveredText){ if (token == JsonToken.VALUE_STRING) { String text = parser.getText(); cas.setDocumentText(text); } } else if ("sdi".equals(parser.getParsingContext().getCurrentName())) { inSdi = true; } else if ("word_annotations".equals(parser.getParsingContext().getCurrentName())) { inWa = true; } else if ("term_occ_annotations".equals(parser.getParsingContext().getCurrentName())) { inToa = true; } else if ("fixed_expressions".equals(parser.getParsingContext().getCurrentName())) { inFe = true; } else if ("covered_text".equals(parser.getParsingContext().getCurrentName())) { inCoveredText = true; } } sdi.addToIndexes(); } catch (IOException | CASException e) { logger.error("An error occurred during TermSuite Json Cas parsing", e); } }
Example 15
Source File: PearInstallerTest.java From uima-uimaj with Apache License 2.0 | 4 votes |
public void testPearInstall() throws Exception { // check temporary working directory if (this.tempInstallDir == null) throw new FileNotFoundException("temp directory not found"); // check sample PEAR files //get pear file to install File pearFile = JUnitExtension.getFile("pearTests/DateTime.pear"); Assert.assertNotNull(pearFile); // Install PEAR package PackageBrowser instPear = PackageInstaller.installPackage( this.tempInstallDir, pearFile, true); //check pear PackageBrowser object Assert.assertNotNull(instPear); //check PEAR component ID String componentID = instPear.getInstallationDescriptor().getMainComponentId(); Assert.assertEquals("uima.example.DateTimeAnnotator", componentID); //check PEAR datapath setting //pear file contains (uima.datapath = $main_root/my/test/data/path) File datapath = new File(this.tempInstallDir, "uima.example.DateTimeAnnotator/my/test/data/path"); File pearDatapath = new File(instPear.getComponentDataPath()); Assert.assertEquals(datapath, pearDatapath); // Create resouce manager and set PEAR package classpath ResourceManager rsrcMgr = UIMAFramework.newDefaultResourceManager(); // Create analysis engine from the installed PEAR package XMLInputSource in = new XMLInputSource(instPear.getComponentPearDescPath()); ResourceSpecifier specifier = UIMAFramework.getXMLParser() .parseResourceSpecifier(in); AnalysisEngine ae = UIMAFramework.produceAnalysisEngine( specifier, rsrcMgr, null); Assert.assertNotNull(ae); // Create a CAS with a sample document text and process the CAS CAS cas = ae.newCAS(); cas.setDocumentText("Sample text to process with a date 05/29/07 and a time 9:45 AM"); cas.setDocumentLanguage("en"); ae.process(cas); }
Example 16
Source File: AggregateWithReaderTest.java From uima-uimafit with Apache License 2.0 | 4 votes |
public void getNext(CAS aCAS) throws IOException, CollectionException { aCAS.setDocumentText("Anyone up for a game of Foosball?"); done = true; }
Example 17
Source File: SequencerFixedTest.java From uima-uimaj with Apache License 2.0 | 4 votes |
public void testSequencerFixedFooBar() throws Exception { AnalysisEngine ae = null; try { // create TempFile for test File outputReferenceFile = new File(this.testBaseDir, "SequencerTest.txt"); outputReferenceFile.delete(); // delete file if exist outputReferenceFile.createNewFile(); // create new file outputReferenceFile.deleteOnExit(); // delete file after closing VM // Create an XML input source from the specifier file. XMLInputSource in = new XMLInputSource(JUnitExtension .getFile("SequencerTest/SequencerFixedAggregate.xml")); // Parse the specifier. ResourceSpecifier specifier = UIMAFramework.getXMLParser().parseResourceSpecifier(in); // Create the Text Analysis Engine. ae = UIMAFramework.produceAnalysisEngine(specifier, null, null); // Create a new CAS. CAS cas = ae.newCAS(); // Our sample text. String text = "Hello world!"; // System.out.println("Processing text: \"" + text + "\""); // Set the document text on the CAS. cas.setDocumentText(text); cas.setDocumentLanguage("foo-BAR"); // Process the sample document. ResultSpecification resultSpec = UIMAFramework.getResourceSpecifierFactory() .createResultSpecification(); resultSpec.addCapabilities(ae.getAnalysisEngineMetaData().getCapabilities()); ae.process(cas, resultSpec); // check fileoutput Assert.assertTrue(FileCompare.compare(outputReferenceFile, JUnitExtension .getFile("SequencerTest/SequencerFixedExpected.txt"))); outputReferenceFile.delete(); ((CASImpl)cas).traceFSflush(); } catch (Exception ex) { JUnitExtension.handleException(ex); } finally { // Destroy the CAS, releasing resources. if (ae != null) { ae.destroy(); } } }
Example 18
Source File: FeaturePathTest.java From uima-uimaj with Apache License 2.0 | 4 votes |
public void testAddAPI() throws Exception { XMLInputSource in = new XMLInputSource(JUnitExtension .getFile("featurePathTests/FeaturePathTestTypeSystem.xml")); TypeSystemDescription typeSystemDescription = UIMAFramework .getXMLParser().parseTypeSystemDescription(in); CAS cas = CasCreationUtils.createCas(typeSystemDescription, null, null); cas.setDocumentText("Sample Text"); Feature stringFeat = cas.getDocumentAnnotation().getType() .getFeatureByBaseName("stringFeature"); Feature refFeat = cas.getDocumentAnnotation().getType() .getFeatureByBaseName("refFeature"); cas.getDocumentAnnotation().setStringValue(stringFeat, "MyExample"); cas.getDocumentAnnotation().setFeatureValue(refFeat, cas.getDocumentAnnotation()); // create featurePath with add() API FeaturePath featurePath = new FeaturePathImpl(); featurePath.addFeature(refFeat); featurePath.addFeature(stringFeat); assertEquals("MyExample", featurePath.getValueAsString(cas .getDocumentAnnotation())); assertEquals("/refFeature/stringFeature", featurePath.getFeaturePath()); assertTrue(featurePath.size() == 2); assertTrue(featurePath.getFeature(1) == stringFeat); featurePath.typeInit(cas.getDocumentAnnotation().getType()); assertEquals("MyExample", featurePath.getValueAsString(cas .getDocumentAnnotation())); assertEquals("MyExample", featurePath.getStringValue(cas .getDocumentAnnotation())); assertTrue(featurePath.size() == 2); assertTrue(featurePath.getFeature(1) == stringFeat); // test path always valid after addFeature() featurePath = new FeaturePathImpl(); featurePath.initialize("/refFeature2"); featurePath.typeInit(cas.getDocumentAnnotation().getType()); featurePath.addFeature(stringFeat); // test path possible valid after addFeature() featurePath = new FeaturePathImpl(); featurePath.initialize("/refFeature2"); featurePath.typeInit(cas.getDocumentAnnotation().getType()); featurePath.addFeature(refFeat); featurePath.addFeature(stringFeat); }
Example 19
Source File: NewPrimitiveTypesTest.java From uima-uimaj with Apache License 2.0 | 4 votes |
private FeatureStructure createExampleFS(CAS parmCas) throws Exception { // Create a view CAS englishView = parmCas.createView("EnglishDocument"); // Set the document text englishView.setDocumentText("this beer is good"); // create an FS of exampleType and index it AnnotationFS fs = englishView.createAnnotation(exampleType, 1, 5); // create Array FSs StringArrayFS strArrayFS = parmCas.createStringArrayFS(5); strArrayFS.set(0, "zzzzzz"); strArrayFS.set(1, "yyyyyy"); strArrayFS.set(2, "xxxxxx"); strArrayFS.set(3, "wwwwww"); strArrayFS.set(4, "vvvvvv"); IntArrayFS intArrayFS = parmCas.createIntArrayFS(5); intArrayFS.set(0, Integer.MAX_VALUE); intArrayFS.set(1, Integer.MAX_VALUE - 1); intArrayFS.set(2, 42); intArrayFS.set(3, Integer.MIN_VALUE + 1); intArrayFS.set(4, Integer.MIN_VALUE); FloatArrayFS floatArrayFS = parmCas.createFloatArrayFS(5); floatArrayFS.set(0, Float.MAX_VALUE); floatArrayFS.set(1, (float) (Float.MAX_VALUE / 1000.0)); floatArrayFS.set(2, 42); floatArrayFS.set(3, (float) (Float.MIN_VALUE * 1000.0)); floatArrayFS.set(4, Float.MIN_VALUE); ByteArrayFS byteArrayFS = parmCas.createByteArrayFS(5); byteArrayFS.set(0, (byte) 8); byteArrayFS.set(1, (byte) 16); byteArrayFS.set(2, (byte) 64); byteArrayFS.set(3, (byte) 128); byteArrayFS.set(4, (byte) 255); BooleanArrayFS boolArrayFS = parmCas.createBooleanArrayFS(20); boolean val = false; for (int i = 0; i < 20; i++) { boolArrayFS.set(i, val = !val); } ShortArrayFS shortArrayFS = parmCas.createShortArrayFS(5); shortArrayFS.set(0, Short.MAX_VALUE); shortArrayFS.set(1, (short) (Short.MAX_VALUE - 1)); shortArrayFS.set(2, (short) (Short.MAX_VALUE - 2)); shortArrayFS.set(3, (short) (Short.MAX_VALUE - 3)); shortArrayFS.set(4, (short) (Short.MAX_VALUE - 4)); LongArrayFS longArrayFS = parmCas.createLongArrayFS(5); longArrayFS.set(0, Long.MAX_VALUE); longArrayFS.set(1, Long.MAX_VALUE - 1); longArrayFS.set(2, Long.MAX_VALUE - 2); longArrayFS.set(3, Long.MAX_VALUE - 3); longArrayFS.set(4, Long.MAX_VALUE - 4); DoubleArrayFS doubleArrayFS = parmCas.createDoubleArrayFS(5); doubleArrayFS.set(0, Double.MAX_VALUE); doubleArrayFS.set(1, Double.MIN_VALUE); doubleArrayFS.set(2, Double.parseDouble("1.5555")); doubleArrayFS.set(3, Double.parseDouble("99.000000005")); doubleArrayFS.set(4, Double.parseDouble("4.44444444444444444")); // set features of fs fs.setStringValue(stringFeature, "aaaaaaa"); fs.setFloatValue(floatFeature, (float) 99.99); fs.setFeatureValue(intArrayFeature, intArrayFS); fs.setFeatureValue(floatArrayFeature, floatArrayFS); fs.setFeatureValue(stringArrayFeature, strArrayFS); // fs.setByteValue(byteFeature, Byte.MAX_VALUE); fs.setByteValue(byteFeature, (byte) 'z'); fs.setFeatureValue(byteArrayFeature, byteArrayFS); fs.setBooleanValue(booleanFeature, true); fs.setFeatureValue(booleanArrayFeature, boolArrayFS); fs.setShortValue(shortFeature, Short.MIN_VALUE); fs.setFeatureValue(shortArrayFeature, shortArrayFS); fs.setLongValue(longFeature, Long.MIN_VALUE); fs.setFeatureValue(longArrayFeature, longArrayFS); fs.setDoubleValue(doubleFeature, Double.MAX_VALUE); fs.setFeatureValue(doubleArrayFeature, doubleArrayFS); englishView.getIndexRepository().addFS(fs); return fs; }
Example 20
Source File: PearMergerTest.java From uima-uimaj with Apache License 2.0 | 4 votes |
/** * Runs test for org.apache.uima.pear.merger.PMController class by merging 2 sample input PEARs * into the output aggregate PEAR. Then, the output PEAR is installed by using * org.apache.uima.pear.tools.InstallationController, and the installed component is verified by * instantiating the aggregate TAE and creating CAS object. * * @throws Exception - */ public void testPearMerger() throws Exception { // check temporary working directory if (_tempWorkingDir == null) throw new FileNotFoundException("temp directory not found"); // check sample PEAR files File[] inpPearFiles = new File[2]; inpPearFiles[0] = JUnitExtension.getFile(TEST_FOLDER + File.separator + INP_PEAR_1_FILE); if (!inpPearFiles[0].isFile()) throw new FileNotFoundException("sample PEAR 1 not found"); inpPearFiles[1] = JUnitExtension.getFile(TEST_FOLDER + File.separator + INP_PEAR_2_FILE); if (!inpPearFiles[1].isFile()) throw new FileNotFoundException("sample PEAR 2 not found"); // specify output aggregate PEAR file File outPearFile = new File(_tempWorkingDir, OUT_PEAR_ID + ".pear"); // create PMController instance and perform merging operation PMController.setLogFileEnabled(false); PMController pmController = new PMController(inpPearFiles, OUT_PEAR_ID, outPearFile); boolean done = pmController.mergePears(); // check merging results Assert.assertTrue(done); Assert.assertTrue(outPearFile.isFile()); // install the output PEAR file and check the results InstallationController insController = new InstallationController(OUT_PEAR_ID, outPearFile, _tempWorkingDir); InstallationDescriptor insDesc = insController.installComponent(); Assert.assertTrue(insDesc != null); Assert.assertTrue(OUT_PEAR_ID.equals(insDesc.getMainComponentId())); // verify the installed component // customize ResourceManager by adding component CLASSPATH ResourceManager resMngr = UIMAFramework.newDefaultResourceManager(); String compClassPath = InstallationController.buildComponentClassPath(insDesc .getMainComponentRoot(), insDesc, false); // instantiate the aggregate AE resMngr.setExtensionClassPath(compClassPath, true); String compDescFilePath = insDesc.getMainComponentDesc(); XMLParser xmlPaser = UIMAFramework.getXMLParser(); XMLInputSource xmlInput = new XMLInputSource(compDescFilePath); AnalysisEngineDescription aeSpec = xmlPaser.parseAnalysisEngineDescription(xmlInput); AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(aeSpec, resMngr, null); Assert.assertTrue(ae != null); // create CAS object CAS cas = ae.newCAS(); Assert.assertTrue(cas != null); //process CAS cas.setDocumentText("Sample text for testing"); ae.process(cas); // clean-up the results pmController.cleanUp(); }