/** * Adds the constituents provided in the arguments, with {@link Relation}s connecting the * canonical mention to the coreferent mentions. * @param canonicalMention the 'most explicit' descriptor of the underlying entity * @param coreferentMentions mentions that co-refer with the canonical mention */ public void addCorefEdges(Constituent canonicalMention, List<Constituent> coreferentMentions) { double[] scores = new double[coreferentMentions.size()]; Arrays.fill(scores, 1.0); addCorefEdges(canonicalMention, coreferentMentions, scores); }
this.gold = (CoreferenceView) goldView; this.prediction = (CoreferenceView) predictionView; List<Constituent> allGoldConstituents = gold.getConstituents(); for (Constituent cons : allGoldConstituents) { HashSet<Constituent> overlappingGoldCanonicalCons = gold.getOverlappingChainsCanonicalMentions(cons); HashSet<Constituent> overlappingPredCanonicalCons = prediction.getOverlappingChainsCanonicalMentions(cons); for (Constituent predCanonicalCons : overlappingPredCanonicalCons) { HashSet<Constituent> consInPredCluster = new HashSet(prediction.getCoreferentMentionsViaRelations(predCanonicalCons)); for (Constituent goldCanonicalCons : overlappingGoldCanonicalCons) { HashSet<Constituent> consInGoldCluster = new HashSet(gold.getCoreferentMentionsViaRelations(goldCanonicalCons));
/** * given the canonical constituent, returns back the constitunts connected to it. * * @param mention canonical mention * @return the connected constituents */ @Deprecated public List<Constituent> getCoreferentMentions(Constituent mention) { List<Constituent> myMentions = (List<Constituent>) this.where(Queries.sameSpanAsConstituent(mention)); if (myMentions.size() == 0) return Collections.singletonList(mention); // TODO: this would create problem in overlapping mentions Constituent myMention = myMentions.get(0); Constituent canonicalEntity = getCanonicalEntity(myMention); return Mappers.map(getFilteredOutgoingRelations(canonicalEntity), relationsToConstituents); }
public Set<Constituent> getCanonicalEntitiesViaRelations() { HashSet<Constituent> canonicalConstituents = new HashSet<>(); for (Constituent cc : this.getConstituents()) { canonicalConstituents.add(getCanonicalEntityViaRelation(cc)); } return canonicalConstituents; }
@Override protected void addView(TextAnnotation ta) throws AnnotatorException { Annotation document = new Annotation(ta.text); pipeline.annotate(document); CoreferenceView vu = new CoreferenceView(viewName, ta); Map corefChain = document.get(CorefCoreAnnotations.CorefChainAnnotation.class); for (Object key : corefChain.keySet()) { CorefChain chain = (CorefChain) corefChain.get(key); Constituent representative = createConstituentGivenMention(document,chain,chain.getRepresentativeMention(), ta); List<Constituent> consList = new ArrayList<>(); for(CorefChain.CorefMention m : chain.getMentionsInTextualOrder()) { consList.add(createConstituentGivenMention(document, chain, m, ta)); } consList.remove(representative); // remove the representative itself vu.addCorefEdges(representative, consList); } ta.addView(viewName, vu); }
CoreferenceView corefView = new CoreferenceView(VIEW_NAME, VIEW_NAME, resultTA, 0.0); for (Entry<String, ArrayList<CorefMention>> entry : chains.entrySet()) { ArrayList<CorefMention> mentions = entry.getValue(); logger.debug(" "+cm+" -> "+cm.constituent.getSurfaceForm()); corefView.addCorefEdges(headconst, referants, attributes); for (Constituent c : corefView.getConstituents()) { this.setMentionType(c, tv, posView);
private void addCorefView(XmlTextAnnotation xmlTa) { CoreferenceView cView = new CoreferenceView(getCorefViewName(), ta); for (String eId : entityIdToMentionIds.keySet()) { Set<String> mentionIds = entityIdToMentionIds.get(eId); otherMents.add(corefMent); cView.addCorefEdges(canonical, otherMents); ta.addView(cView.getViewName(), cView);
newVu = new SpanLabelView(vu.viewName, vu.viewGenerator, newTA, vu.score); } else if (vu instanceof CoreferenceView) { newVu = new CoreferenceView(vu.viewName, vu.viewGenerator, newTA, vu.score); } else if (vu instanceof PredicateArgumentView) { newVu = new PredicateArgumentView(vu.viewName, vu.viewGenerator, newTA, vu.score);
private void buildIndexFromRealCoref () { CoreferenceView corefView = (CoreferenceView)globalTA.getTa().getView(ViewNames.COREF); for(Constituent source : corefView.getConstituents()) { Constituent target = corefView.getCanonicalEntity(source); // String mention = source.getSurfaceString(); int start = source.getStartCharOffset(); int end = source.getEndCharOffset(); // String coreMention = target.getSurfaceString(); int corefStart = target.getStartCharOffset(); int corefEnd = target.getEndCharOffset(); predCorefStartMap.put(start, new Pair<Integer, Integer>(corefStart, corefEnd)); predCorefEndMap.put(end, new Pair<Integer, Integer>(corefStart, corefEnd)); if (isDebug) { String checkCoreference = contentRemovingTags.substring(corefStart, corefEnd); String checkMention = contentRemovingTags.substring(start, end); System.out.println ("[Mention] " + checkMention + " [Coref org] " + checkCoreference); } } }
/** * Finds the representative elements for each cluster */ @Deprecated private void findCanonicalEntries() { if (this.canonicalEntitiesMap.size() > 0 || !this.modified) return; // The assumption is that all nodes with no parent are canonical entities. for (Constituent cc : this.getConstituents()) { int ccId = this.constituents.indexOf(cc); if (getFilteredIncomingRelations(cc).size() == 0) { canonicalEntitiesMap.put(ccId, ccId); for (Relation r : getFilteredOutgoingRelations(cc)) { int tId = this.constituents.indexOf(r.getTarget()); canonicalEntitiesMap.put(tId, ccId); } } } modified = false; }
public void addCorefEdges(Constituent canonicalMention, List<Constituent> coreferentMentions, double[] scores) { this.addConstituent(canonicalMention); int canonicalMentionId = this.constituents.indexOf(canonicalMention); canonicalEntitiesMap.put(canonicalMentionId, canonicalMentionId); int i = 0; for (Constituent c : coreferentMentions) { if (c != canonicalMention) { this.addConstituent(c); Relation relation = new Relation(viewName, canonicalMention, c, scores[i]); this.addRelation(relation); int cId = this.constituents.indexOf(c); canonicalEntitiesMap.put(cId, canonicalMentionId); } i++; } }
double score = clustering.getScore(); CoreferenceView view = new CoreferenceView(viewName, generator, ta, score); view.addCorefEdges(canonicalMention, coreferentMentions, scores);
CoreferenceView corefView = new CoreferenceView(VIEW_NAME, VIEW_NAME, resultTA, 0.0); for (Entry<String, ArrayList<CorefMention>> entry : chains.entrySet()) { ArrayList<CorefMention> mentions = entry.getValue(); logger.debug(" "+cm+" -> "+cm.constituent.getSurfaceForm()); corefView.addCorefEdges(headconst, referants, attributes); for (Constituent c : corefView.getConstituents()) { this.setMentionType(c, tv, posView);
private void addCorefView(XmlTextAnnotation xmlTa) { CoreferenceView cView = new CoreferenceView(getCorefViewName(), ta); for (String eId : entityIdToMentionIds.keySet()) { Set<String> mentionIds = entityIdToMentionIds.get(eId); otherMents.add(corefMent); cView.addCorefEdges(canonical, otherMents); ta.addView(cView.getViewName(), cView);
newVu = new SpanLabelView(vu.viewName, vu.viewGenerator, newTA, vu.score); } else if (vu instanceof CoreferenceView) { newVu = new CoreferenceView(vu.viewName, vu.viewGenerator, newTA, vu.score); } else if (vu instanceof PredicateArgumentView) { newVu = new PredicateArgumentView(vu.viewName, vu.viewGenerator, newTA, vu.score);
private void buildIndexFromRealCoref () { CoreferenceView corefView = (CoreferenceView)globalTA.getTa().getView(ViewNames.COREF); for(Constituent source : corefView.getConstituents()) { Constituent target = corefView.getCanonicalEntity(source); // String mention = source.getSurfaceString(); int start = source.getStartCharOffset(); int end = source.getEndCharOffset(); // String coreMention = target.getSurfaceString(); int corefStart = target.getStartCharOffset(); int corefEnd = target.getEndCharOffset(); predCorefStartMap.put(start, new Pair<Integer, Integer>(corefStart, corefEnd)); predCorefEndMap.put(end, new Pair<Integer, Integer>(corefStart, corefEnd)); if (isDebug) { String checkCoreference = contentRemovingTags.substring(corefStart, corefEnd); String checkMention = contentRemovingTags.substring(start, end); System.out.println ("[Mention] " + checkMention + " [Coref org] " + checkCoreference); } } }
/** * Finds the representative elements for each cluster */ @Deprecated private void findCanonicalEntries() { if (this.canonicalEntitiesMap.size() > 0 || !this.modified) return; // The assumption is that all nodes with no parent are canonical entities. for (Constituent cc : this.getConstituents()) { int ccId = this.constituents.indexOf(cc); if (getFilteredIncomingRelations(cc).size() == 0) { canonicalEntitiesMap.put(ccId, ccId); for (Relation r : getFilteredOutgoingRelations(cc)) { int tId = this.constituents.indexOf(r.getTarget()); canonicalEntitiesMap.put(tId, ccId); } } } modified = false; }
public Set<Constituent> getCanonicalEntitiesViaRelations() { HashSet<Constituent> canonicalConstituents = new HashSet<>(); for (Constituent cc : this.getConstituents()) { canonicalConstituents.add(getCanonicalEntityViaRelation(cc)); } return canonicalConstituents; }
public void addCorefEdges(Constituent canonicalMention, List<Constituent> coreferentMentions, double[] scores) { this.addConstituent(canonicalMention); int canonicalMentionId = this.constituents.indexOf(canonicalMention); canonicalEntitiesMap.put(canonicalMentionId, canonicalMentionId); int i = 0; for (Constituent c : coreferentMentions) { if (c != canonicalMention) { this.addConstituent(c); Relation relation = new Relation(viewName, canonicalMention, c, scores[i]); this.addRelation(relation); int cId = this.constituents.indexOf(c); canonicalEntitiesMap.put(cId, canonicalMentionId); } i++; } }
double score = clustering.getScore(); CoreferenceView view = new CoreferenceView(viewName, generator, ta, score); view.addCorefEdges(canonicalMention, coreferentMentions, scores);