@Test public void testAnnotateAcronymsWithFullFormEntity() throws Exception { ExternalResourceDescription extDesc = ExternalResourceFactory.createExternalResourceDescription( ChunkerProviderImplAlt.class, new File("src/test/resources/normalizegazetteer.properties")); TypeSystemDescription tsDesc = TypeSystemDescriptionFactory .createTypeSystemDescription("de.julielab.jcore.types.jcore-semantics-mention-types"); AnalysisEngine annotator = AnalysisEngineFactory.createPrimitive(GazetteerAnnotator.class, tsDesc, GazetteerAnnotator.PARAM_OUTPUT_TYPE, "de.julielab.jcore.types.EntityMention", GazetteerAnnotator.CHUNKER_RESOURCE_NAME, extDesc); JCas jCas = annotator.newJCas(); jCas.setDocumentText("Here we have the short form isnotin dictionary (TSFOTEINITD) indeed."); Abbreviation abbr; AbbreviationLongform v; abbr = new Abbreviation(jCas, 52, 63); abbr.setDefinedHere(true); abbr.setExpan("short form isnotin dictionary"); v = new AbbreviationLongform(jCas, 17, 50); v.addToIndexes(); abbr.setTextReference(v); abbr.addToIndexes(); annotator.process(jCas); FSIterator<org.apache.uima.jcas.tcas.Annotation> it = jCas.getAnnotationIndex(EntityMention.type).iterator(); Integer counter = 0; while (it.hasNext()) { it.next(); counter++; } assertEquals("Wrong entity count: ", new Integer(1), counter); jCas.reset(); jCas.setDocumentText( "Herein we report the cDNA cloning of a human brain 25 kDa lysophospholipid-specific lysophospholipase (hLysoPLA)."); abbr = new Abbreviation(jCas, 103, 111); abbr.setDefinedHere(true); abbr.setExpan("human brain 25 kDa lysophospholipid-specific lysophospholipase"); v = new AbbreviationLongform(jCas, 39, 101); v.addToIndexes(); abbr.setTextReference(v); abbr.addToIndexes(); abbr = new Abbreviation(jCas, 104, 111); abbr.setDefinedHere(true); abbr.setExpan("lysophospholipase"); v = new AbbreviationLongform(jCas, 84, 101); v.addToIndexes(); abbr.setTextReference(v); abbr.addToIndexes(); annotator.process(jCas); it = jCas.getAnnotationIndex(EntityMention.type).iterator(); counter = 0; while (it.hasNext()) { EntityMention next = (EntityMention) it.next(); counter++; if (counter == 1) { assertEquals("lysophospholipid-specific lysophospholipase", next.getCoveredText()); } else if (counter == 2) { assertEquals("hLysoPLA", next.getCoveredText()); } assertEquals("GENE", next.getSpecificType()); } assertEquals("Wrong entity count: ", new Integer(1), counter); }
private void annotateAcronymsWithFullFormEntity(JCas aJCas, JCoReHashMapAnnotationIndex<Long, ConceptMention> conceptMentionIndex) throws AnalysisEngineProcessException { JFSIndexRepository indexes = aJCas.getJFSIndexRepository(); FSIterator<Annotation> abbrevIter = indexes.getAnnotationIndex(Abbreviation.type).iterator(); IndexTermGenerator<Long> longOffsetTermGenerator = TermGenerators.longOffsetTermGenerator(); while (abbrevIter.hasNext()) { Abbreviation abbrev = (Abbreviation) abbrevIter.next(); AbbreviationLongform fullFormAnnotation = abbrev.getTextReference(); LOGGER.debug("annotateAcronymsWithFullFormEntity() - checking abbreviation: " + abbrev.getCoveredText()); ConceptMention emFullform = null; emFullform = conceptMentionIndex.getFirst(fullFormAnnotation); String type = null; if (emFullform != null) type = emFullform.getClass().getCanonicalName(); ConceptMention emAcronym = null; emAcronym = conceptMentionIndex.getFirst(abbrev); if (type != null && type.equals(outputType)) { if (emFullform == null) { LOGGER.debug( "annotateAcronymsWithFullFormEntity() - fullform of abbreviation has no ConceptMention\n"); continue; } if (emFullform.getComponentId() != null && emFullform.getComponentId().equals(COMPONENT_ID) && (emAcronym == null || !emAcronym.getClass().getName().equals(emFullform.getClass().getName()))) { try { LOGGER.debug("annotateAcronymsWithFullFormEntity() - fullform of abbreviation (" + abbrev.getCoveredText() + " [begin=" + abbrev.getBegin() + "; end=" + abbrev.getEnd() + "]) has ConceptMention: " + emFullform.toString()); ConceptMention newEntityOnAcronym = (ConceptMention) JCoReAnnotationTools .getAnnotationByClassName(aJCas, outputType); newEntityOnAcronym.setBegin(abbrev.getBegin()); newEntityOnAcronym.setEnd(abbrev.getEnd()); newEntityOnAcronym.setTextualRepresentation(newEntityOnAcronym.getCoveredText()); newEntityOnAcronym.setSpecificType(emFullform.getSpecificType()); newEntityOnAcronym.setComponentId(COMPONENT_ID + "+acronym"); newEntityOnAcronym.setConfidence(emFullform.getConfidence() + ""); newEntityOnAcronym.addToIndexes(); } catch (Exception e) { LOGGER.error("process() - could not generate output type: " + e.getMessage()); e.printStackTrace(); throw new AnalysisEngineProcessException(AnalysisEngineProcessException.ANNOTATOR_EXCEPTION, null); } } else { if (emAcronym == null) LOGGER.debug("annotateAcronymsWithFullFormEntity() - emAcronym != null"); else if (emAcronym.getClass().getName().equals(emFullform.getClass().getName())) LOGGER.debug("annotateAcronymsWithFullFormEntity() - emAcroType=" + emAcronym.getClass().getCanonicalName() + " == emFullformType=" + emFullform.getClass().getCanonicalName()); } } } }
GazetteerAnnotator extends JCasAnnotator_ImplBase { private void annotateAcronymsWithFullFormEntity(JCas aJCas, JCoReHashMapAnnotationIndex<Long, ConceptMention> conceptMentionIndex) throws AnalysisEngineProcessException { JFSIndexRepository indexes = aJCas.getJFSIndexRepository(); FSIterator<Annotation> abbrevIter = indexes.getAnnotationIndex(Abbreviation.type).iterator(); IndexTermGenerator<Long> longOffsetTermGenerator = TermGenerators.longOffsetTermGenerator(); while (abbrevIter.hasNext()) { Abbreviation abbrev = (Abbreviation) abbrevIter.next(); AbbreviationLongform fullFormAnnotation = abbrev.getTextReference(); LOGGER.debug("annotateAcronymsWithFullFormEntity() - checking abbreviation: " + abbrev.getCoveredText()); ConceptMention emFullform = null; emFullform = conceptMentionIndex.getFirst(fullFormAnnotation); String type = null; if (emFullform != null) type = emFullform.getClass().getCanonicalName(); ConceptMention emAcronym = null; emAcronym = conceptMentionIndex.getFirst(abbrev); if (type != null && type.equals(outputType)) { if (emFullform == null) { LOGGER.debug( "annotateAcronymsWithFullFormEntity() - fullform of abbreviation has no ConceptMention\n"); continue; } if (emFullform.getComponentId() != null && emFullform.getComponentId().equals(COMPONENT_ID) && (emAcronym == null || !emAcronym.getClass().getName().equals(emFullform.getClass().getName()))) { try { LOGGER.debug("annotateAcronymsWithFullFormEntity() - fullform of abbreviation (" + abbrev.getCoveredText() + " [begin=" + abbrev.getBegin() + "; end=" + abbrev.getEnd() + "]) has ConceptMention: " + emFullform.toString()); ConceptMention newEntityOnAcronym = (ConceptMention) JCoReAnnotationTools .getAnnotationByClassName(aJCas, outputType); newEntityOnAcronym.setBegin(abbrev.getBegin()); newEntityOnAcronym.setEnd(abbrev.getEnd()); newEntityOnAcronym.setTextualRepresentation(newEntityOnAcronym.getCoveredText()); newEntityOnAcronym.setSpecificType(emFullform.getSpecificType()); newEntityOnAcronym.setComponentId(COMPONENT_ID + "+acronym"); newEntityOnAcronym.setConfidence(emFullform.getConfidence() + ""); newEntityOnAcronym.addToIndexes(); } catch (Exception e) { LOGGER.error("process() - could not generate output type: " + e.getMessage()); e.printStackTrace(); throw new AnalysisEngineProcessException(AnalysisEngineProcessException.ANNOTATOR_EXCEPTION, null); } } else { if (emAcronym == null) LOGGER.debug("annotateAcronymsWithFullFormEntity() - emAcronym != null"); else if (emAcronym.getClass().getName().equals(emFullform.getClass().getName())) LOGGER.debug("annotateAcronymsWithFullFormEntity() - emAcroType=" + emAcronym.getClass().getCanonicalName() + " == emFullformType=" + emFullform.getClass().getCanonicalName()); } } } } }
GazetteerAnnotator extends JCasAnnotator_ImplBase { private void annotateAcronymsWithFullFormEntity(JCas aJCas, JCoReHashMapAnnotationIndex<Long, ConceptMention> conceptMentionIndex) throws AnalysisEngineProcessException { JFSIndexRepository indexes = aJCas.getJFSIndexRepository(); FSIterator<Annotation> abbrevIter = indexes.getAnnotationIndex(Abbreviation.type).iterator(); IndexTermGenerator<Long> longOffsetTermGenerator = TermGenerators.longOffsetTermGenerator(); while (abbrevIter.hasNext()) { Abbreviation abbrev = (Abbreviation) abbrevIter.next(); AbbreviationLongform fullFormAnnotation = abbrev.getTextReference(); LOGGER.debug("annotateAcronymsWithFullFormEntity() - checking abbreviation: " + abbrev.getCoveredText()); ConceptMention emFullform = null; emFullform = conceptMentionIndex.getFirst(fullFormAnnotation); String type = null; if (emFullform != null) type = emFullform.getClass().getCanonicalName(); ConceptMention emAcronym = null; emAcronym = conceptMentionIndex.getFirst(abbrev); if (type != null && type.equals(outputType)) { if (emFullform == null) { LOGGER.debug( "annotateAcronymsWithFullFormEntity() - fullform of abbreviation has no ConceptMention\n"); continue; } if (emFullform.getComponentId() != null && emFullform.getComponentId().equals(COMPONENT_ID) && (emAcronym == null || !emAcronym.getClass().getName().equals(emFullform.getClass().getName()))) { try { LOGGER.debug("annotateAcronymsWithFullFormEntity() - fullform of abbreviation (" + abbrev.getCoveredText() + " [begin=" + abbrev.getBegin() + "; end=" + abbrev.getEnd() + "]) has ConceptMention: " + emFullform.toString()); ConceptMention newEntityOnAcronym = (ConceptMention) JCoReAnnotationTools .getAnnotationByClassName(aJCas, outputType); newEntityOnAcronym.setBegin(abbrev.getBegin()); newEntityOnAcronym.setEnd(abbrev.getEnd()); newEntityOnAcronym.setTextualRepresentation(newEntityOnAcronym.getCoveredText()); newEntityOnAcronym.setSpecificType(emFullform.getSpecificType()); newEntityOnAcronym.setComponentId(COMPONENT_ID + "+acronym"); newEntityOnAcronym.setConfidence(emFullform.getConfidence() + ""); newEntityOnAcronym.addToIndexes(); } catch (Exception e) { LOGGER.error("process() - could not generate output type: " + e.getMessage()); e.printStackTrace(); throw new AnalysisEngineProcessException(AnalysisEngineProcessException.ANNOTATOR_EXCEPTION, null); } } else { if (emAcronym == null) LOGGER.debug("annotateAcronymsWithFullFormEntity() - emAcronym != null"); else if (emAcronym.getClass().getName().equals(emFullform.getClass().getName())) LOGGER.debug("annotateAcronymsWithFullFormEntity() - emAcroType=" + emAcronym.getClass().getCanonicalName() + " == emFullformType=" + emFullform.getClass().getCanonicalName()); } } } }  }
GazetteerAnnotator extends JCasAnnotator_ImplBase { private void annotateAcronymsWithFullFormEntity(JCas aJCas, JCoReHashMapAnnotationIndex<Long, ConceptMention> conceptMentionIndex) throws AnalysisEngineProcessException { JFSIndexRepository indexes = aJCas.getJFSIndexRepository(); FSIterator<Annotation> abbrevIter = indexes.getAnnotationIndex(Abbreviation.type).iterator(); IndexTermGenerator<Long> longOffsetTermGenerator = TermGenerators.longOffsetTermGenerator(); while (abbrevIter.hasNext()) { Abbreviation abbrev = (Abbreviation) abbrevIter.next(); AbbreviationLongform fullFormAnnotation = abbrev.getTextReference(); LOGGER.debug("annotateAcronymsWithFullFormEntity() - checking abbreviation: " + abbrev.getCoveredText()); ConceptMention emFullform = null; emFullform = conceptMentionIndex.getFirst(fullFormAnnotation); String type = null; if (emFullform != null) type = emFullform.getClass().getCanonicalName(); ConceptMention emAcronym = null; emAcronym = conceptMentionIndex.getFirst(abbrev); if (type != null && type.equals(outputType)) { if (emFullform == null) { LOGGER.debug( "annotateAcronymsWithFullFormEntity() - fullform of abbreviation has no ConceptMention\n"); continue; } if (emFullform.getComponentId() != null && emFullform.getComponentId().equals(COMPONENT_ID) && (emAcronym == null || !emAcronym.getClass().getName().equals(emFullform.getClass().getName()))) { try { LOGGER.debug("annotateAcronymsWithFullFormEntity() - fullform of abbreviation (" + abbrev.getCoveredText() + " [begin=" + abbrev.getBegin() + "; end=" + abbrev.getEnd() + "]) has ConceptMention: " + emFullform.toString()); ConceptMention newEntityOnAcronym = (ConceptMention) JCoReAnnotationTools .getAnnotationByClassName(aJCas, outputType); newEntityOnAcronym.setBegin(abbrev.getBegin()); newEntityOnAcronym.setEnd(abbrev.getEnd()); newEntityOnAcronym.setTextualRepresentation(newEntityOnAcronym.getCoveredText()); newEntityOnAcronym.setSpecificType(emFullform.getSpecificType()); newEntityOnAcronym.setComponentId(COMPONENT_ID + "+acronym"); newEntityOnAcronym.setConfidence(emFullform.getConfidence() + ""); newEntityOnAcronym.addToIndexes(); } catch (Exception e) { LOGGER.error("process() - could not generate output type: " + e.getMessage()); e.printStackTrace(); throw new AnalysisEngineProcessException(AnalysisEngineProcessException.ANNOTATOR_EXCEPTION, null); } } else { if (emAcronym == null) LOGGER.debug("annotateAcronymsWithFullFormEntity() - emAcronym != null"); else if (emAcronym.getClass().getName().equals(emFullform.getClass().getName())) LOGGER.debug("annotateAcronymsWithFullFormEntity() - emAcroType=" + emAcronym.getClass().getCanonicalName() + " == emFullformType=" + emFullform.getClass().getCanonicalName()); } } } }  void initialize(UimaContext aContext); void process(JCas aJCas); }
GazetteerAnnotator extends JCasAnnotator_ImplBase { private void annotateAcronymsWithFullFormEntity(JCas aJCas, JCoReHashMapAnnotationIndex<Long, ConceptMention> conceptMentionIndex) throws AnalysisEngineProcessException { JFSIndexRepository indexes = aJCas.getJFSIndexRepository(); FSIterator<Annotation> abbrevIter = indexes.getAnnotationIndex(Abbreviation.type).iterator(); IndexTermGenerator<Long> longOffsetTermGenerator = TermGenerators.longOffsetTermGenerator(); while (abbrevIter.hasNext()) { Abbreviation abbrev = (Abbreviation) abbrevIter.next(); AbbreviationLongform fullFormAnnotation = abbrev.getTextReference(); LOGGER.debug("annotateAcronymsWithFullFormEntity() - checking abbreviation: " + abbrev.getCoveredText()); ConceptMention emFullform = null; emFullform = conceptMentionIndex.getFirst(fullFormAnnotation); String type = null; if (emFullform != null) type = emFullform.getClass().getCanonicalName(); ConceptMention emAcronym = null; emAcronym = conceptMentionIndex.getFirst(abbrev); if (type != null && type.equals(outputType)) { if (emFullform == null) { LOGGER.debug( "annotateAcronymsWithFullFormEntity() - fullform of abbreviation has no ConceptMention\n"); continue; } if (emFullform.getComponentId() != null && emFullform.getComponentId().equals(COMPONENT_ID) && (emAcronym == null || !emAcronym.getClass().getName().equals(emFullform.getClass().getName()))) { try { LOGGER.debug("annotateAcronymsWithFullFormEntity() - fullform of abbreviation (" + abbrev.getCoveredText() + " [begin=" + abbrev.getBegin() + "; end=" + abbrev.getEnd() + "]) has ConceptMention: " + emFullform.toString()); ConceptMention newEntityOnAcronym = (ConceptMention) JCoReAnnotationTools .getAnnotationByClassName(aJCas, outputType); newEntityOnAcronym.setBegin(abbrev.getBegin()); newEntityOnAcronym.setEnd(abbrev.getEnd()); newEntityOnAcronym.setTextualRepresentation(newEntityOnAcronym.getCoveredText()); newEntityOnAcronym.setSpecificType(emFullform.getSpecificType()); newEntityOnAcronym.setComponentId(COMPONENT_ID + "+acronym"); newEntityOnAcronym.setConfidence(emFullform.getConfidence() + ""); newEntityOnAcronym.addToIndexes(); } catch (Exception e) { LOGGER.error("process() - could not generate output type: " + e.getMessage()); e.printStackTrace(); throw new AnalysisEngineProcessException(AnalysisEngineProcessException.ANNOTATOR_EXCEPTION, null); } } else { if (emAcronym == null) LOGGER.debug("annotateAcronymsWithFullFormEntity() - emAcronym != null"); else if (emAcronym.getClass().getName().equals(emFullform.getClass().getName())) LOGGER.debug("annotateAcronymsWithFullFormEntity() - emAcroType=" + emAcronym.getClass().getCanonicalName() + " == emFullformType=" + emFullform.getClass().getCanonicalName()); } } } }  void initialize(UimaContext aContext); void process(JCas aJCas); static final String CHUNKER_RESOURCE_NAME; final static String PARAM_CHECK_ACRONYMS; final static String PARAM_OUTPUT_TYPE; }