/** * Returns a new JCas () appropriate for the given Analysis Engine. This * method ensures that only one instance of a JCas is created. A Jcas is a * Java Cover Classes based Object-oriented CAS (Common Analysis System) * API. * * <p> * Important: It is highly recommended that you reuse CAS objects rather * than creating new CAS objects prior to each analysis. This is because CAS * objects may be expensive to create and may consume a significant amount * of memory. * </p> * * @param ae * AnalysisEngine used to create an appropriate JCas object. * @return a JCas object appropriate for the given AnalysisEngine. * @throws ResourceInitializationException * if a CAS could not be created because this AnalysisEngine's * CAS metadata (type system, type priorities, or FS indexes) * are invalid. */ public static JCas getJCas(AnalysisEngine ae) throws ResourceInitializationException { JCas jcas = ae.newJCas(); return jcas; }
/** * Returns a new JCas () appropriate for the given Analysis Engine. This * method ensures that only one instance of a JCas is created. A Jcas is a * Java Cover Classes based Object-oriented CAS (Common Analysis System) * API. * * <p> * Important: It is highly recommended that you reuse CAS objects rather * than creating new CAS objects prior to each analysis. This is because CAS * objects may be expensive to create and may consume a significant amount * of memory. * </p> * * @param ae * AnalysisEngine used to create an appropriate JCas object. * @return a JCas object appropriate for the given AnalysisEngine. * @throws ResourceInitializationException * if a CAS could not be created because this AnalysisEngine's * CAS metadata (type system, type priorities, or FS indexes) * are invalid. */ public static JCas getJCas(AnalysisEngine ae) throws ResourceInitializationException { JCas jcas = ae.newJCas(); return jcas; }
/** * Returns a new JCas () appropriate for the given Analysis Engine. This * method ensures that only one instance of a JCas is created. A Jcas is a * Java Cover Classes based Object-oriented CAS (Common Analysis System) * API. * * <p> * Important: It is highly recommended that you reuse CAS objects rather * than creating new CAS objects prior to each analysis. This is because CAS * objects may be expensive to create and may consume a significant amount * of memory. * </p> * * @param ae * AnalysisEngine used to create an appropriate JCas object. * @return a JCas object appropriate for the given AnalysisEngine. * @throws ResourceInitializationException * if a CAS could not be created because this AnalysisEngine's * CAS metadata (type system, type priorities, or FS indexes) * are invalid. */ public static JCas getJCas(AnalysisEngine ae) throws ResourceInitializationException { JCas jcas = ae.newJCas(); return jcas; }
public JCas borrowJCas() throws ResourceInitializationException { synchronized (this) { if (!mJCasList.isEmpty()) { int last = mJCasList.size() - 1; JCas res = mJCasList.get(last); mJCasList.remove(last); res.reset(); return res; } return mEngine.newJCas(); } }
public JCas createNewJCas() throws LAPException { // get a new JCAS JCas aJCas = null; try { aJCas = typeAE.newJCas(); } catch (ResourceInitializationException e) { throw new LAPException("Unable to create new JCas", e); } return aJCas; }
private JCas processText(String textFieldValue) throws ResourceInitializationException, AnalysisEngineProcessException { logger.info(new StringBuffer("Analazying text").toString()); /* * get the UIMA analysis engine */ AnalysisEngine ae = aeProvider.getAE(); /* * create a JCas which contain the text to analyze */ JCas jcas = ae.newJCas(); jcas.setDocumentText(textFieldValue); /* * perform analysis on text field */ ae.process(jcas); logger.info(new StringBuilder("Text processing completed").toString()); return jcas; }
@Override public JCas generateSingleTHPairCAS(String arg0, String arg1) throws LAPException { // generate a new CAS //JCas aJCas = CASUtils.createNewInputCas(); JCas aJCas = null; try { aJCas = this.typeAE.newJCas(); } catch (ResourceInitializationException e) { throw new LAPException("Unable to create new JCas", e); } // actual work is done here, with all caching. annotateSingleTHPairCAS(arg0, arg1, aJCas); return aJCas; }
JCas jCas = ae.newJCas(); jCas.setDocumentText(text); ae.process(jCas);
JCas jCas = ae.newJCas(); jCas.setDocumentText(text); ae.process(jCas);
File knowtatorTextDirectory = new File(knowtatorTextDirectoryPath); for (File textFile : knowtatorTextDirectory.listFiles()) { JCas jCas = engine.newJCas(); jCas.setDocumentText(Files.toString(textFile, Charsets.US_ASCII)); DocumentID documentID = new DocumentID(jCas);
File knowtatorTextDirectory = new File(knowtatorTextDirectoryPath); for (File textFile : knowtatorTextDirectory.listFiles()) { JCas jCas = engine.newJCas(); jCas.setDocumentText(Files.toString(textFile, Charsets.US_ASCII)); DocumentID documentID = new DocumentID(jCas);
JCas jCas = ae.newJCas();
LOGGER.info("Processing " + i + " knowtator text source files for this directory."); for (File textFile : knowtatorTextSourceFiles) { JCas jCas = mipacqReader.newJCas(); jCas.setDocumentText(Files.toString(textFile, Charsets.US_ASCII)); DocumentID documentID = new DocumentID(jCas);
public JCas generateSingleTHPairCAS(String text, String hypothesis, String goldAnswer) throws LAPException { // get a new JCAS JCas aJCas = null; try { aJCas = typeAE.newJCas(); } catch (ResourceInitializationException e) { throw new LAPException("Unable to create new JCas", e); } // prepare it with Views and Entailment.* annotations. addTEViewAndAnnotations(aJCas, text, hypothesis, null, null, goldAnswer); // last three args are PairId, task, and golden Answer // now aJCas has TextView, HypothesisView and Entailment.* types. (Pair, T and H) // it is time to add linguistic annotations addAnnotationOn(aJCas, TEXTVIEW); addAnnotationOn(aJCas, HYPOTHESISVIEW); return aJCas; }
@Override public JCas generateSingleTHPairCAS(String text, String hypothesis) throws LAPException { // get a new JCAS JCas aJCas = null; try { aJCas = typeAE.newJCas(); } catch (ResourceInitializationException e) { throw new LAPException("Unable to create new JCas", e); } // prepare it with Views and Entailment.* annotations. addTEViewAndAnnotations(aJCas, text, hypothesis, null, null, null); // last three args are PairId, task, and golden Answer -- which we don't fill here // now aJCas has TextView, HypothesisView and Entailment.* types. (Pair, T and H) // it is time to add linguistic annotations addAnnotationOn(aJCas, TEXTVIEW); addAnnotationOn(aJCas, HYPOTHESISVIEW); return aJCas; }
private Collection<String> getLemmas(String text) throws ResourceInitializationException, AnalysisEngineProcessException { AnalysisEngine ae = AnalysisEngineFactory.createEngine( createEngineDescription( createEngineDescription(BreakIteratorSegmenter.class), createEngineDescription(OpenNlpPosTagger.class, OpenNlpPosTagger.PARAM_LANGUAGE, originalLanguage.toString().toLowerCase()), createEngineDescription(GateLemmatizer.class))); JCasBuilder cb = new JCasBuilder(ae.newJCas()); cb.add(text); cb.close(); JCas jcas = cb.getJCas(); ae.process(jcas); // Get the lemmas Collection<Lemma> lemmas = JCasUtil.select(jcas, Lemma.class); // Convert to strings Collection<String> strings = new ArrayList<String>(); for (Lemma lemma : lemmas) { strings.add(lemma.getValue().toLowerCase()); } return strings; }
JCas jcas = aEngine.newJCas();
AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(specifier); aJCas = ae.newJCas();
@Test public void test() throws Exception { AnalysisEngine ae = AnalysisEngineFactory.createPrimitive( JavaAnnotator.class, createTypeSystemDescription()); JCas jcas = ae.newJCas(); jcas.setDocumentText("public class Dummy { public static void main(String[] args) { return; } }"); ae.process(jcas); Iterator<MethodDeclaration> i = iterate(jcas, MethodDeclaration.class).iterator(); assertEquals("public static void main(String[] args) { return; }", i.next().getCoveredText()); assertFalse(i.hasNext()); } }
@Test public void test() throws Exception { AnalysisEngine ae = AnalysisEngineFactory.createPrimitive( TokenAnnotator.class, createTypeSystemDescription()); JCas jcas = ae.newJCas(); jcas.setDocumentText("Ubi est Cornelia?"); ae.process(jcas); Iterator<Token> i = iterate(jcas, Token.class).iterator(); assertEquals("Ubi", i.next().getCoveredText()); assertEquals("est", i.next().getCoveredText()); assertEquals("Cornelia", i.next().getCoveredText()); assertEquals("?", i.next().getCoveredText()); assertFalse(i.hasNext()); } }