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

Provide example of how to wrap a ClearTK AE into a simple API that any java program can call #403

Open
bethard opened this issue Apr 15, 2015 · 0 comments
Labels
🐛 Bug Something isn't working Priority-Medium

Comments

@bethard
Copy link
Contributor

bethard commented Apr 15, 2015

Original issue 405 created by ClearTK on 2014-06-22T20:02:32.000Z:

We should provide an example of how to create a ClearTK wrapper that would allow one to call a ClearTK-based analysis engine from any java program. An example of this could be used for something like NER in which a java program simply wants to call an NER routine with some text and get back some results. Here's a sketch of what such an example might look like.

NER myNer = new NER()
List<MyNerPojo> nerResults = myNer.doNer(myText)

Where doNer() has a signature something like this:

public List<MyNerPojo> doNer(String myText)

The implementation of doNer() would look something like this:

1: AnalysisEngine nerAE = builder.createAggregate;
2: JCas myJcas = nerAE.newJCas();
3: myJcas.setDocumentText(text);
4: nerAE.process(myJcas);
5: for (NamedEntityMention mention : JCasUtil.select(jCas, NamedEntityMention.class)) {
6: //collect whatever you want from each mention into your pojo return type
7: }

Line 1 makes use of an AggregateBuilder. See RunNamedEntityChunker.main for a nice example of this
Line 2 is an expensive call (~100 ms) so you may want to pass in the JCas instance to doNer() or have it be a member variable. You can reset a JCas instance with the reset() method. Note that this would have synchronization implications - i.e. doNer() should be marked as synchronized.

Some of the above text was copied from a recent post on the cleartk-users list.

@bethard bethard modified the milestone: 2.1 Apr 16, 2015
@reckart reckart added 🐛 Bug Something isn't working and removed Type-Defect labels Nov 4, 2022
@reckart reckart modified the milestones: 2.1.0, 🐛 Bug backlog Nov 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug Something isn't working Priority-Medium
Projects
None yet
Development

No branches or pull requests

2 participants