Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service to use multiple pipeline types #25

Closed
MatthewVita opened this issue Dec 10, 2017 · 4 comments
Closed

Service to use multiple pipeline types #25

MatthewVita opened this issue Dec 10, 2017 · 4 comments
Assignees

Comments

@MatthewVita
Copy link
Member

Email from Sean F:

You could actually run 1 service with multiple available pipeline types.  In other words, instead of running one service with default clinical, one with temporal, one with coref ...  You could run one service and just feed it an extra post parameter to choose which pipeline to run.  By default it would be clinical.

What do you think?  Obviously we should just make sure that it is working as-is, but after that it is really easy to add the extra functionality.

You can actually read as many piper files as you want and create multiple pipelines from them.  There are now thread safe versions of the most common annotators.  These could be used to minimize memory requirements by preventing multiple copies of models and dictionaries.  The service should still be serial.

Basically, the code would be as follows:

Static private final class PipelineRunner {
        Private final AnalysisEngineDescription _engine;
        Private final JCasPool _pool;
        Private PipelineRunner( final String piperPath ) {
                PiperFileReader reader = new PiperFileReader( piperPath );
                PipelineBuilder builder = reader.getBuilder();
                AnalysisEngineDescription pipeline = builder. getAnalysisEngineDesc();
                _engine = UIMAFramework.produceAnalysisEngine( pipeline );
                _pool = new JCasPool( 10, _engine );
        }
        Public void process( final String text ) {
                JCas jcas = _pool.getJCas( -1 );
                jcas.setDocumentText( text );
                _engine.process( jcas );
                _pool.releaseJCas( jcas );
        }
}

Static private Final Map<String,PipelineRunner> _pipelineRunners = new HashMap<>();
_pipelineRunners.put( "Default", new PipelineRunner( "TsDefaultClinicalPiperPath" ) );
_pipelineRunners.put( "Relations", new PipelineRunner( "TsRelationPiperPath" ) );
_pipelineRunners.put( "Temporal", new PipelineRunner( "TsTemporalPiperPath" ) );
_pipelineRunners.put( "Coreference", new PipelineRunner( "TsCoreferencePiperPath" ) );
_pipelineRunners.put( "Full", new PipelineRunner( "TsFullPiperPath" ) );

For each post:
String pipelineName = request.getParameter( "pipeline" );
If (pipelineName == null ) {
        pipelineName = "default";
}
Final PipelineRunner runner = _pipelineRunners.get( pipelineName );
If ( runner == null ) {
        handleError();
}
Final String text = request.getParameter( "text" );
runner.run( text );


It should be that simple.  You could also swap the map with an enum and fetch by pipeline name, but I don't think that it would gain anything.
@gandhirajan gandhirajan self-assigned this Dec 10, 2017
@gandhirajan
Copy link
Member

Will start on this by next week

@MatthewVita
Copy link
Member Author

@gandhirajan I think we should do this in version 2. Are you okay with pushing this back?

@gandhirajan
Copy link
Member

@MatthewVita If I could get the exact piper files for each option from Sean, I can push this on this version too as I have only on thing pending on this module now. (adding sample JSP to test REST service within the module)

@MatthewVita
Copy link
Member Author

Piper support is possible now (if I understand correctly). Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants