/** * This method adds a new Mention and associated concepts to a SofaText, there can be overlap * between concept names and multiple concepts can match a string, instead of choosing one * concept, we record them all. * * @param m * @param concepts */ public void addMentionAndConcepts(Mention m, List<Concept> concepts) { // System.out.println("Mention Text: " + m.getText()); ArrayList<SofaTextMention> toRemove = new ArrayList<SofaTextMention>(); // check all SofaTextMentions for (SofaTextMention stm : sofaTextMention) { // if new mention is subsumed by existing mention, add associated concepts to subsuming // mention // and then return // test for overlap if (isOverlapping(stm, m)) { // there is overlap, keep the larger of the two mentions if (stm.getMentionEnd() - stm.getMentionStart() < m.getEnd() - m.getStart()) // mention is larger { System.out.println("1"); concepts.addAll(stm.getConcepts()); toRemove.add(stm); } else { System.out.println("2"); stm.addConcepts(concepts); return; } } } // remove mentions from remove list sofaTextMention.removeAll(toRemove); // add new mention to sofatext sofaTextMention.add(new SofaTextMention(this, m, concepts)); }
private boolean isOverlapping(SofaTextMention stm, Mention m) { if (stm.getMentionStart() == m.getStart() // same start token || stm.getMentionEnd() == m.getEnd() // same end token || (stm.getMentionStart() <= m.getStart() && stm.getMentionEnd() >= m.getStart()) || (stm.getMentionStart() >= m.getStart() && stm.getMentionStart() <= m.getEnd())) { return true; } return false; }