public static void expandAbbreviations(JCas jCas) { String pmId = getHeaderDocId(jCas); // otherwise was very slow Map<Abbreviation, List<Annotation>> cache = newHashMap(); List<Abbreviation> tmp = newLinkedList(select(jCas, Abbreviation.class)); for (Abbreviation abrev : tmp) { Annotation reference = abrev.getTextReference(); if (reference != null && reference instanceof Abbreviation) { Abbreviation aRef = (Abbreviation) reference; List<Annotation> covereds; if (cache.containsKey(aRef)) covereds = cache.get(aRef); else { covereds = getCovered(jCas, aRef, pmId); cache.put(aRef, covereds); } // copy them to the other abbreviation short-forms for (Annotation covered : covereds) { Annotation clone = (Annotation) covered.clone(); clone.setBegin(abrev.getBegin()); clone.setEnd(abrev.getEnd()); clone.addToIndexes(jCas); if (!clone.getCoveredText().equals(aRef.getCoveredText())) LOG.warn("'{}' not matching2 '{}' in " + pmId, clone.getCoveredText(), aRef.getCoveredText()); } } } }
Abbreviation a = (Abbreviation) o; return "Abbreviation[" + a.getCoveredText() + "] expan:" + a.getExpan() + " textRef:" + a.getTextReference();