Hi John, You are not wrong. You may want to take an approach similar to what is done in the ctakes-web-rest project. In CtakesRestController, which can create one or more PipelineRunners to process text. You can call runner.process( text ); as many times as you want and get results.
static private final class PipelineRunner { private final AnalysisEngine _engine; private final JCasPool _pool; private PipelineRunner(final String piperPath) throws ServletException { try { PiperFileReader reader = new PiperFileReader(piperPath); PipelineBuilder builder = reader.getBuilder(); AnalysisEngineDescription pipeline = builder.getAnalysisEngineDesc(); _engine = UIMAFramework.produceAnalysisEngine(pipeline); _pool = new JCasPool(10, _engine); } catch (Exception e) { LOGGER.error("Error loading pipers"); throw new ServletException(e); } } public MyResponseClass process(final String text) throws ServletException { JCas jcas = null; MyResponseClass myResponseObject = null; if (text != null) { try { jcas = _pool.getJCas(-1); jcas.setDocumentText(text); _engine.process(jcas); myReposonseObject = createMyResponseObject( jcas ); _pool.releaseJCas(jcas); } catch (Exception e) { LOGGER.error("Error processing Analysis engine"); throw new ServletException(e); } } return myResponseObject; } } Sean ________________________________________ From: John Doe <lucanus...@gmail.com> Sent: Thursday, April 22, 2021 2:24 PM To: dev@ctakes.apache.org Subject: Re: Running cTAKES Default Clinical Pipeline from Code [EXTERNAL] * External Email - Caution * Hi Sean, I tried this piper builder approach below and it also didn't work. PipelineBuilder pipelineBuilder = new PipelineBuilder(); pipelineBuilder.set(UmlsUserApprover.KEY_PARAM, "<my-key>"); AnalysisEngineDescription aed = ClinicalPipelineFactory.getDefaultPipeline(); pipelineBuilder.addDescription(aed); pipelineBuilder.run("text"); Mainly, I just want to understand what the issue is. But the reason it came up is because I want to set up ctakes to work in real time. So I want clients to be able to send in notes and have them get processed using the default clinical pipeline on one of several nodes running ctakes. The reason I don't want to use builder.run("text") is because it recreates the jCas every time, which I don't think will scale well. I would rather each node create the jCas once and call jCas.reset() after each note is done getting processed rather than have it get instantiated again. I think creating the jCas is expensive but correct me if I'm wrong. On Thu, Apr 22, 2021 at 1:58 PM Finan, Sean < sean.fi...@childrens.harvard.edu> wrote: > Hi John, > > Just out of curiosity, if you have one method that works then why do you > want to use a different method to do the same thing? > > I personally use the PIpelineBuilder as you have in your second example > when I need to work with code - though that is extremely rare as piper > files can handle everything that I normally want to do. > > If you want an example of how to build a pipeline using only code (no > piper file) then check the ctakes-examples module, class > ProcessDirBuilderRunner. It recreates the default clinical pipeline > without dictionary lookup. Adding in the lookup is fairly simple: > > builder > ... > .set( UmlsUserApprover.KEY_PARAM, "my-umls-key" ) > .add( DefaultJCasTermAnnotator.class ) > ... > > or the single line > .add( DefaultJCasTermAnnotator.class, Collections.emptyList(), > UmlsUserApprover.KEY_PARAM, "my-umls-key" ) > > The code above is just off the top of my head, so I apologize for any > typos or slight misdirection. Hopefully it is enough to point a way for > you. > > Sean > > ________________________________________ > From: John Doe <lucanus...@gmail.com> > Sent: Thursday, April 22, 2021 1:09 PM > To: dev@ctakes.apache.org > Subject: Running cTAKES Default Clinical Pipeline from Code [EXTERNAL] > > * External Email - Caution * > > > Hello, > > I'm having trouble running the default clinical pipeline from code. It > keeps giving me the error message that I have an invalid UMLS License. > However, I know my license is valid and I have managed to get the default > pipeline to run using the PiperFileReader with the same credentials. > > This is the code that doesn't work that I would like to get working: > > System.setProperty(UmlsUserApprover.KEY_PARAM, "my-umls-key"); > JCas jCas = JCasFactory.createJCas(); > jCas.setDocumentText("My text"); > AnalysisEngineDescription aed = > ClinicalPipelineFactory.getDefaultPipeline(); > SimplePipeline.runPipeline(jCas, aed); > > This is the code that I managed to get to work. This just demonstrates to > me that it isn't really a credential issue. > PiperFileReader piperReader = new PiperFileReader(); > PipelineBuilder builder = piperReader.getBuilder(); > builder.set( UmlsUserApprover.KEY_PARAM , "the-same-umls-key"); > piperReader.loadPipelineFile("path/to/default.piper"); > builder.run("test text"); > > default.piper just loads the default pipeline: > load > ./resources/org/apache/ctakes/clinical/pipeline/DefaultFastPipeline.piper > > Does anyone know what the issue might be here? >