Java Code Examples for org.apache.uima.jcas.JCas#reset()
The following examples show how to use
org.apache.uima.jcas.JCas#reset() .
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: TearlineContentExtractorTest.java From baleen with Apache License 2.0 | 6 votes |
@Test public void testTearline() throws Exception { JCas jCas = JCasSingleton.getJCasInstance(); BaleenContentExtractor contentExtractor = new TearlineContentExtractor(); contentExtractor.initialize(new CustomResourceSpecifier_impl(), Collections.emptyMap()); String[] files = new String[] {"1.docx", "2.docx", "3.docx", "4.docx", "5.doc", "6.pdf"}; for (String file : files) { File f = new File(getClass().getResource("tearline/" + file).getPath()); try (InputStream is = new FileInputStream(f); ) { contentExtractor.processStream(is, f.getPath(), jCas); assertEquals("This is the first tearline.", jCas.getDocumentText()); jCas.reset(); } } contentExtractor.destroy(); }
Example 2
Source File: TearlineContentExtractorTest.java From baleen with Apache License 2.0 | 6 votes |
@Test public void testNoTearline() throws Exception { JCas jCas = JCasSingleton.getJCasInstance(); BaleenContentExtractor contentExtractor = new TearlineContentExtractor(); contentExtractor.initialize(new CustomResourceSpecifier_impl(), Collections.emptyMap()); File f = new File(getClass().getResource("tearline/notearline.docx").getPath()); try (InputStream is = new FileInputStream(f); ) { contentExtractor.processStream(is, f.getPath(), jCas); assertEquals("This document has no tearline.", jCas.getDocumentText()); jCas.reset(); } contentExtractor.destroy(); }
Example 3
Source File: TearlineContentExtractorTest.java From baleen with Apache License 2.0 | 6 votes |
@Test public void testBoilerplate() throws Exception { JCas jCas = JCasSingleton.getJCasInstance(); Map<String, Object> params = new HashMap<>(); params.put("boilerplate", new String[] {"[aeiou]"}); BaleenContentExtractor contentExtractor = new TearlineContentExtractor(); contentExtractor.initialize(new CustomResourceSpecifier_impl(), params); File f = new File(getClass().getResource("tearline/notearline.docx").getPath()); try (InputStream is = new FileInputStream(f); ) { contentExtractor.processStream(is, f.getPath(), jCas); assertEquals("Ths dcmnt hs n trln.", jCas.getDocumentText()); jCas.reset(); } contentExtractor.destroy(); }
Example 4
Source File: TearlineContentExtractorTest.java From baleen with Apache License 2.0 | 6 votes |
@Test public void testCustomTearline() throws Exception { JCas jCas = JCasSingleton.getJCasInstance(); Map<String, Object> params = new HashMap<>(); params.put("tearline", "Customer Form:"); BaleenContentExtractor contentExtractor = new TearlineContentExtractor(); contentExtractor.initialize(new CustomResourceSpecifier_impl(), params); File f = new File(getClass().getResource("tearline/customtearline.docx").getPath()); try (InputStream is = new FileInputStream(f); ) { contentExtractor.processStream(is, f.getPath(), jCas); assertEquals("This is the first tearline.", jCas.getDocumentText()); jCas.reset(); } contentExtractor.destroy(); }
Example 5
Source File: ParseAnnotatorTest.java From bluima with Apache License 2.0 | 6 votes |
public void initCas(JCas jcas) { jcas.reset(); jcas.setDocumentText(text); Sentence s = new Sentence(jcas); s.setBegin(0); s.setEnd(text.length()); s.addToIndexes(jcas); String[] tokens = text.split(" "); int j = 0; for (int i = 0; i < tokens.length; i++) { Token token = new Token(jcas); token.setBegin(j); token.setEnd(j + tokens[i].length()); j = j + tokens[i].length() + 1; token.addToIndexes(jcas); } }
Example 6
Source File: JCasPool.java From uima-uimaj with Apache License 2.0 | 6 votes |
/** * Checks in a JCas to the pool. This automatically calls the {@link JCas#reset()} method, to * ensure that when the JCas is later retrieved from the pool it will be ready to use. Also * notifies other Threads that may be waiting for an instance to become available. * * @param aJCas * the JCas to release */ public synchronized void releaseJCas(JCas aJCas) { // make sure this CAS actually belongs to this pool and is checked out if (!mAllInstances.contains(aJCas) || mFreeInstances.contains(aJCas)) { UIMAFramework.getLogger(CLASS_NAME).logrb(Level.WARNING, CLASS_NAME.getName(), "releaseJCas", LOG_RESOURCE_BUNDLE, "UIMA_return_jcas_to_pool__WARNING"); } else { // reset CAS aJCas.reset(); // Add the CAS to the end of the free instances List mFreeInstances.add(aJCas); } // Notify any threads waiting on this object notifyAll(); }
Example 7
Source File: BlacklistTest.java From baleen with Apache License 2.0 | 5 votes |
private void createDocument(JCas jCas) { jCas.reset(); jCas.setDocumentText("Simon was born in November 1980 in London, UK"); Person p = new Person(jCas); p.setValue("Simon"); p.setBegin(0); p.setEnd(5); p.addToIndexes(); Temporal d = new Temporal(jCas); d.setValue(NOVEMBER); d.setBegin(18); d.setEnd(26); d.addToIndexes(); Location l = new Location(jCas); l.setValue(LONDON); l.setBegin(35); l.setEnd(41); l.addToIndexes(); // entity value different to covering text "UK" Location l2 = new Location(jCas); l2.setValue(UNITED_KINGDOM); l2.setBegin(43); l2.setEnd(45); l2.addToIndexes(); assertEquals(1, JCasUtil.select(jCas, Person.class).size()); assertEquals(1, JCasUtil.select(jCas, Temporal.class).size()); assertEquals(2, JCasUtil.select(jCas, Location.class).size()); }
Example 8
Source File: SharedIdGeneratorTest.java From baleen with Apache License 2.0 | 4 votes |
@Test public void testAfterClearDifferentUUID() throws UIMAException { final SharedIdGenerator generator = createSharedIdGenerator(); final JCas jCas = JCasSingleton.getJCasInstance(); jCas.setDocumentText("test"); final String p1id = "1234"; final String firstUUID = generator.generateForExternalId(p1id); assertEquals(firstUUID, generator.generateForExternalId(p1id)); jCas.reset(); jCas.setDocumentText("next"); generator.resetIfNewJCas(jCas); final String secondUUID = generator.generateForExternalId(p1id); assertNotEquals(firstUUID, secondUUID); assertEquals(secondUUID, generator.generateForExternalId(p1id)); }