@Test public void testSimpleSpeciesRecognition() throws Exception { JCas jCas = JCasFactory.createJCas("de.julielab.jcore.types.jcore-semantics-biology-types"); jCas.setDocumentText("In this text we talk about humans and mice. Because a mouse is no killifish nor a caenorhabditis elegans. Thus, c. elegans is now abbreviated as well as n. furzeri."); final ExternalResourceDescription testConfiguration = ExternalResourceFactory.createExternalResourceDescription("TestConfiguration", LinnaeusMatcherProviderImpl.class, "file:linnaeus-properties-test.conf"); AnalysisEngine annotator = AnalysisEngineFactory.createEngine(LinnaeusSpeciesAnnotator.class, LinnaeusSpeciesAnnotator.RES_KEY_LINNAEUS_MATCHER, testConfiguration); annotator.process(jCas); FSIterator<Annotation> orgaIt = jCas.getAnnotationIndex(Organism.type).iterator(); Organism org; ResourceEntry resourceEntry; assertTrue(orgaIt.hasNext()); org = (Organism) orgaIt.next(); assertEquals("humans", org.getCoveredText()); resourceEntry = org.getResourceEntryList(0); assertEquals("9606", resourceEntry.getEntryId()); assertTrue(orgaIt.hasNext()); org = (Organism) orgaIt.next(); assertEquals("mice", org.getCoveredText()); resourceEntry = org.getResourceEntryList(0); assertEquals("10090", resourceEntry.getEntryId()); assertTrue(orgaIt.hasNext()); org = (Organism) orgaIt.next(); assertEquals("mouse", org.getCoveredText()); resourceEntry = org.getResourceEntryList(0); assertEquals("10090", resourceEntry.getEntryId()); assertTrue(orgaIt.hasNext()); org = (Organism) orgaIt.next(); assertEquals("killifish", org.getCoveredText()); resourceEntry = org.getResourceEntryList(0); assertEquals("34780", resourceEntry.getEntryId()); assertTrue(orgaIt.hasNext()); org = (Organism) orgaIt.next(); assertEquals("caenorhabditis elegans", org.getCoveredText()); resourceEntry = org.getResourceEntryList(0); assertEquals("6239", resourceEntry.getEntryId()); assertTrue(orgaIt.hasNext()); org = (Organism) orgaIt.next(); assertEquals("c. elegans", org.getCoveredText()); resourceEntry = org.getResourceEntryList(0); assertEquals("6239", resourceEntry.getEntryId()); assertTrue(orgaIt.hasNext()); org = (Organism) orgaIt.next(); assertEquals("n. furzeri", org.getCoveredText()); resourceEntry = org.getResourceEntryList(0); assertEquals("105023", resourceEntry.getEntryId()); }
@Override public void process(JCas cas) throws AnalysisEngineProcessException { String text = cas.getDocumentText(); List<Mention> mentions = matcher.match(text); for (Mention mention : mentions) { String mostProbableID = mention.getMostProbableID(); if (mostProbableID.startsWith(linnaeusIdPrefix)) mostProbableID = mostProbableID.substring(linnaeusIdPrefix.length()); Double[] probabilities = mention.getProbabilities(); double maxprob = 0; if (probabilities != null) { for (int i = 0; i < probabilities.length; i++) if (probabilities[i] != null && probabilities[i] > maxprob) { maxprob = probabilities[i]; } } int start = mention.getStart(); int end = mention.getEnd(); try { Organism species = null; species = new Organism(cas); species.setBegin(mention.getStart()); species.setEnd(mention.getEnd()); species.setSpecificType("organism"); species.addToIndexes(); ResourceEntry resourceEntry = new ResourceEntry(cas); resourceEntry.setBegin(start); resourceEntry.setEnd(end); resourceEntry.setSource("NCBI Taxonomy"); resourceEntry.setComponentId(getClass().getCanonicalName()); resourceEntry.setEntryId(mostProbableID); resourceEntry.setConfidence(String.valueOf(maxprob)); resourceEntry.addToIndexes(); FSArray resourceEntryList = species.getResourceEntryList(); if (null == resourceEntryList) { resourceEntryList = new FSArray(cas, 1); resourceEntryList.set(0, resourceEntry); } else { resourceEntryList = JCoReTools.addToFSArray(resourceEntryList, resourceEntry); } species.setResourceEntryList(resourceEntryList); } catch (SecurityException | IllegalArgumentException e) { throw new AnalysisEngineProcessException(e); } } }
LinnaeusSpeciesAnnotator extends JCasAnnotator_ImplBase { @Override public void process(JCas cas) throws AnalysisEngineProcessException { String text = cas.getDocumentText(); List<Mention> mentions = matcher.match(text); for (Mention mention : mentions) { String mostProbableID = mention.getMostProbableID(); if (mostProbableID.startsWith(linnaeusIdPrefix)) mostProbableID = mostProbableID.substring(linnaeusIdPrefix.length()); Double[] probabilities = mention.getProbabilities(); double maxprob = 0; if (probabilities != null) { for (int i = 0; i < probabilities.length; i++) if (probabilities[i] != null && probabilities[i] > maxprob) { maxprob = probabilities[i]; } } int start = mention.getStart(); int end = mention.getEnd(); try { Organism species = null; species = new Organism(cas); species.setBegin(mention.getStart()); species.setEnd(mention.getEnd()); species.setSpecificType("organism"); species.addToIndexes(); ResourceEntry resourceEntry = new ResourceEntry(cas); resourceEntry.setBegin(start); resourceEntry.setEnd(end); resourceEntry.setSource("NCBI Taxonomy"); resourceEntry.setComponentId(getClass().getCanonicalName()); resourceEntry.setEntryId(mostProbableID); resourceEntry.setConfidence(String.valueOf(maxprob)); resourceEntry.addToIndexes(); FSArray resourceEntryList = species.getResourceEntryList(); if (null == resourceEntryList) { resourceEntryList = new FSArray(cas, 1); resourceEntryList.set(0, resourceEntry); } else { resourceEntryList = JCoReTools.addToFSArray(resourceEntryList, resourceEntry); } species.setResourceEntryList(resourceEntryList); } catch (SecurityException | IllegalArgumentException e) { throw new AnalysisEngineProcessException(e); } } } }
LinnaeusSpeciesAnnotator extends JCasAnnotator_ImplBase { @Override public void process(JCas cas) throws AnalysisEngineProcessException { String text = cas.getDocumentText(); List<Mention> mentions = matcher.match(text); for (Mention mention : mentions) { String mostProbableID = mention.getMostProbableID(); if (mostProbableID.startsWith(linnaeusIdPrefix)) mostProbableID = mostProbableID.substring(linnaeusIdPrefix.length()); Double[] probabilities = mention.getProbabilities(); double maxprob = 0; if (probabilities != null) { for (int i = 0; i < probabilities.length; i++) if (probabilities[i] != null && probabilities[i] > maxprob) { maxprob = probabilities[i]; } } int start = mention.getStart(); int end = mention.getEnd(); try { Organism species = null; species = new Organism(cas); species.setBegin(mention.getStart()); species.setEnd(mention.getEnd()); species.setSpecificType("organism"); species.addToIndexes(); ResourceEntry resourceEntry = new ResourceEntry(cas); resourceEntry.setBegin(start); resourceEntry.setEnd(end); resourceEntry.setSource("NCBI Taxonomy"); resourceEntry.setComponentId(getClass().getCanonicalName()); resourceEntry.setEntryId(mostProbableID); resourceEntry.setConfidence(String.valueOf(maxprob)); resourceEntry.addToIndexes(); FSArray resourceEntryList = species.getResourceEntryList(); if (null == resourceEntryList) { resourceEntryList = new FSArray(cas, 1); resourceEntryList.set(0, resourceEntry); } else { resourceEntryList = JCoReTools.addToFSArray(resourceEntryList, resourceEntry); } species.setResourceEntryList(resourceEntryList); } catch (SecurityException | IllegalArgumentException e) { throw new AnalysisEngineProcessException(e); } } }  }
LinnaeusSpeciesAnnotator extends JCasAnnotator_ImplBase { @Override public void process(JCas cas) throws AnalysisEngineProcessException { String text = cas.getDocumentText(); List<Mention> mentions = matcher.match(text); for (Mention mention : mentions) { String mostProbableID = mention.getMostProbableID(); if (mostProbableID.startsWith(linnaeusIdPrefix)) mostProbableID = mostProbableID.substring(linnaeusIdPrefix.length()); Double[] probabilities = mention.getProbabilities(); double maxprob = 0; if (probabilities != null) { for (int i = 0; i < probabilities.length; i++) if (probabilities[i] != null && probabilities[i] > maxprob) { maxprob = probabilities[i]; } } int start = mention.getStart(); int end = mention.getEnd(); try { Organism species = null; species = new Organism(cas); species.setBegin(mention.getStart()); species.setEnd(mention.getEnd()); species.setSpecificType("organism"); species.addToIndexes(); ResourceEntry resourceEntry = new ResourceEntry(cas); resourceEntry.setBegin(start); resourceEntry.setEnd(end); resourceEntry.setSource("NCBI Taxonomy"); resourceEntry.setComponentId(getClass().getCanonicalName()); resourceEntry.setEntryId(mostProbableID); resourceEntry.setConfidence(String.valueOf(maxprob)); resourceEntry.addToIndexes(); FSArray resourceEntryList = species.getResourceEntryList(); if (null == resourceEntryList) { resourceEntryList = new FSArray(cas, 1); resourceEntryList.set(0, resourceEntry); } else { resourceEntryList = JCoReTools.addToFSArray(resourceEntryList, resourceEntry); } species.setResourceEntryList(resourceEntryList); } catch (SecurityException | IllegalArgumentException e) { throw new AnalysisEngineProcessException(e); } } }  @Override void initialize(UimaContext aContext); @Override void process(JCas cas); @Override void collectionProcessComplete(); }
LinnaeusSpeciesAnnotator extends JCasAnnotator_ImplBase { @Override public void process(JCas cas) throws AnalysisEngineProcessException { String text = cas.getDocumentText(); List<Mention> mentions = matcher.match(text); for (Mention mention : mentions) { String mostProbableID = mention.getMostProbableID(); if (mostProbableID.startsWith(linnaeusIdPrefix)) mostProbableID = mostProbableID.substring(linnaeusIdPrefix.length()); Double[] probabilities = mention.getProbabilities(); double maxprob = 0; if (probabilities != null) { for (int i = 0; i < probabilities.length; i++) if (probabilities[i] != null && probabilities[i] > maxprob) { maxprob = probabilities[i]; } } int start = mention.getStart(); int end = mention.getEnd(); try { Organism species = null; species = new Organism(cas); species.setBegin(mention.getStart()); species.setEnd(mention.getEnd()); species.setSpecificType("organism"); species.addToIndexes(); ResourceEntry resourceEntry = new ResourceEntry(cas); resourceEntry.setBegin(start); resourceEntry.setEnd(end); resourceEntry.setSource("NCBI Taxonomy"); resourceEntry.setComponentId(getClass().getCanonicalName()); resourceEntry.setEntryId(mostProbableID); resourceEntry.setConfidence(String.valueOf(maxprob)); resourceEntry.addToIndexes(); FSArray resourceEntryList = species.getResourceEntryList(); if (null == resourceEntryList) { resourceEntryList = new FSArray(cas, 1); resourceEntryList.set(0, resourceEntry); } else { resourceEntryList = JCoReTools.addToFSArray(resourceEntryList, resourceEntry); } species.setResourceEntryList(resourceEntryList); } catch (SecurityException | IllegalArgumentException e) { throw new AnalysisEngineProcessException(e); } } }  @Override void initialize(UimaContext aContext); @Override void process(JCas cas); @Override void collectionProcessComplete(); static final String RES_KEY_LINNAEUS_MATCHER; static final String PARAM_CONFIG_FILE; }