/** * Convenience method for addConstituent(constituent, false) * @param constituent */ public void addConstituent(Constituent constituent){ this.addConstituent(constituent, false); }
@Override public void addConstituent(Constituent constituent) { this.modified = true; super.addConstituent(constituent); }
@Override public void addConstituent(Constituent constituent) { this.modified = true; super.addConstituent(constituent); }
public View getViewCoveringTokens(Collection<Integer> tokens, ITransformer<View, Double> scoreTransformer) { View restriction = createRestrictedView(scoreTransformer); if (restriction == null) return null; Queue<Constituent> constituentsToConsider = new LinkedList<>(); for (Constituent c : getConstituentsCoveringTokens(tokens)) { restriction.addConstituent(c); constituentsToConsider.add(c); } addRelatedConstituents(restriction, constituentsToConsider); return restriction; }
public View getRestrictedView(Predicate<Constituent> constituentPredicate, ITransformer<View, Double> scoreTransformer) { View restriction = createRestrictedView(scoreTransformer); if (restriction == null) return null; Queue<Constituent> constituentsToConsider = new LinkedList<>(); for (Constituent c : getFilteredConstituents(constituentPredicate)) { restriction.addConstituent(c); constituentsToConsider.add(c); } addRelatedConstituents(restriction, constituentsToConsider); return restriction; }
public View getRestrictedView(Predicate<Constituent> constituentPredicate, ITransformer<View, Double> scoreTransformer) { View restriction = createRestrictedView(scoreTransformer); if (restriction == null) return null; Queue<Constituent> constituentsToConsider = new LinkedList<>(); for (Constituent c : getFilteredConstituents(constituentPredicate)) { restriction.addConstituent(c); constituentsToConsider.add(c); } addRelatedConstituents(restriction, constituentsToConsider); return restriction; }
public View getViewCoveringSpan(int start, int end, ITransformer<View, Double> scoreTransformer) { View restriction = createRestrictedView(scoreTransformer); if (restriction == null) return null; Queue<Constituent> constituentsToConsider = new LinkedList<>(); for (Constituent c : getConstituentsCoveringSpan(start, end)) { restriction.addConstituent(c); constituentsToConsider.add(c); } addRelatedConstituents(restriction, constituentsToConsider); // logger.info(restriction); return restriction; }
public View getViewCoveringSpan(int start, int end, ITransformer<View, Double> scoreTransformer) { View restriction = createRestrictedView(scoreTransformer); if (restriction == null) return null; Queue<Constituent> constituentsToConsider = new LinkedList<>(); for (Constituent c : getConstituentsCoveringSpan(start, end)) { restriction.addConstituent(c); constituentsToConsider.add(c); } addRelatedConstituents(restriction, constituentsToConsider); // logger.info(restriction); return restriction; }
public View getViewCoveringTokens(Collection<Integer> tokens, ITransformer<View, Double> scoreTransformer) { View restriction = createRestrictedView(scoreTransformer); if (restriction == null) return null; Queue<Constituent> constituentsToConsider = new LinkedList<>(); for (Constituent c : getConstituentsCoveringTokens(tokens)) { restriction.addConstituent(c); constituentsToConsider.add(c); } addRelatedConstituents(restriction, constituentsToConsider); return restriction; }
/** * Consolidate {@link TextAnnotation}s that have the same text but separate gold views. This is * required because of the nature of the Semeval annotations (one annotation per example). * * @param tas The list of {@link TextAnnotation}s with the Semeval annotations * @return The consolidated list of {@link TextAnnotation}s */ private List<TextAnnotation> consolidate(List<TextAnnotation> tas) { List<TextAnnotation> consolidatedTAs = new ArrayList<>(); Map<Integer, List<TextAnnotation>> taMap = new HashMap<>(); for (TextAnnotation ta : tas) { int key = ta.getText().hashCode(); List<TextAnnotation> annotations = taMap.getOrDefault(key, new ArrayList<>()); annotations.add(ta); taMap.put(key, annotations); } for (int key : taMap.keySet()) { List<TextAnnotation> annotations = taMap.get(key); TextAnnotation ta1 = annotations.get(0); View view1 = ta1.getView(viewName); for (int i = 1; i < annotations.size(); i++) { TextAnnotation taI = annotations.get(i); View viewI = taI.getView(viewName); for (Constituent c : viewI.getConstituents()) view1.addConstituent(c); } consolidatedTAs.add(ta1); } return consolidatedTAs; }
private void addHeuristicPredicateView(TextAnnotation ta) throws Exception { View view = new View(heuristicPredicateView, "", ta, 1.0); List<Constituent> predicates = heuristic.getPredicates(ta); for (Constituent c : predicates) view.addConstituent(c); ta.addView(heuristicPredicateView, view); } }
/** * remove overlapping entities, put them in a View and add them to ta * @param ta * @param neConstituents */ private static void processEntities(TextAnnotation ta, List<Constituent> neConstituents, String viewName ) { neConstituents = removeOverlappingEntities( neConstituents ); View nerView = new View( viewName, NAME, ta, 1.0 ); for ( Constituent c : neConstituents ) nerView.addConstituent( c ); ta.addView( viewName, nerView ); }
@Override public void addConstituent(Constituent constituent) { super.addConstituent(constituent); // this sort is grossly inefficient when appending contiguous tokens one at a time. // we add a check so we only do the sort if the constituents are added out of order. // Better yet use an ordered tree map representation, do an insertion sort. int size = this.constituents.size(); if (size > 1) { Constituent before = this.constituents.get(size-2); Constituent after = this.constituents.get(size-1); if (before.getStartSpan() > after.getStartSpan()) { Collections.sort(this.constituents, TextAnnotationUtilities.constituentStartComparator); } } }
@Override public void addConstituent(Constituent constituent) { super.addConstituent(constituent); // this sort is grossly inefficient when appending contiguous tokens one at a time. // we add a check so we only do the sort if the constituents are added out of order. // Better yet use an ordered tree map representation, do an insertion sort. int size = this.constituents.size(); if (size > 1) { Constituent before = this.constituents.get(size-2); Constituent after = this.constituents.get(size-1); if (before.getStartSpan() > after.getStartSpan()) { Collections.sort(this.constituents, TextAnnotationUtilities.constituentStartComparator); } } }
@Override protected void addView(TextAnnotation ta) throws AnnotatorException { View v = new TokenLabelView(ViewNames.TRANSLITERATION, this.getClass().getName(), ta, 1.0); int index = 0; for(String tok : ta.getTokens()){ try { TopList<Double, String> ll = model.Generate(tok.toLowerCase()); if(ll.size() > 0) { Pair<Double, String> toppair = ll.getFirst(); Constituent c = new Constituent(toppair.getSecond(), toppair.getFirst(), ViewNames.TRANSLITERATION, ta, index, index + 1); v.addConstituent(c); } } catch (Exception e) { // print that this word has failed... e.printStackTrace(); } index++; } ta.addView(ViewNames.TRANSLITERATION, v); } }
@Override protected void addView(TextAnnotation ta) throws AnnotatorException { View v = new TokenLabelView(ViewNames.TRANSLITERATION, this.getClass().getName(), ta, 1.0); int index = 0; for(String tok : ta.getTokens()){ try { TopList<Double, String> ll = model.Generate(tok.toLowerCase()); if(ll.size() > 0) { Pair<Double, String> toppair = ll.getFirst(); Constituent c = new Constituent(toppair.getSecond(), toppair.getFirst(), ViewNames.TRANSLITERATION, ta, index, index + 1); v.addConstituent(c); } } catch (Exception e) { // print that this word has failed... e.printStackTrace(); } index++; } ta.addView(ViewNames.TRANSLITERATION, v); } }
private void addRelatedConstituents(View restriction, Queue<Constituent> constituentsToConsider) { while (!constituentsToConsider.isEmpty()) { Constituent top = constituentsToConsider.remove(); for (Relation r : top.getIncomingRelations()) { Constituent source = r.getSource(); if (source.getStartSpan() < 0 && !restriction.containsConstituent(source)) { restriction.addConstituent(source); constituentsToConsider.add(source); } } } for (Relation r : this.relations) { if (restriction.containsConstituent(r.getSource()) && restriction.containsConstituent(r.getTarget())) { restriction.addRelation(r); } } }
private void addRelatedConstituents(View restriction, Queue<Constituent> constituentsToConsider) { while (!constituentsToConsider.isEmpty()) { Constituent top = constituentsToConsider.remove(); for (Relation r : top.getIncomingRelations()) { Constituent source = r.getSource(); if (source.getStartSpan() < 0 && !restriction.containsConstituent(source)) { restriction.addConstituent(source); constituentsToConsider.add(source); } } } for (Relation r : this.relations) { if (restriction.containsConstituent(r.getSource()) && restriction.containsConstituent(r.getTarget())) { restriction.addRelation(r); } } }
/** * add constituent, creating view if needed (using constituent's viewname) * @param ta * @param c */ private static void addConstituentToTextAnnotation(TextAnnotation ta, Constituent c) { String viewName = c.getViewName(); View v = null; if ( !ta.hasView( viewName ) ) { v = new SpanLabelView( viewName, NAME, ta, 1.0 ); ta.addView( viewName, v ); } else v = ta.getView( viewName ); v.addConstituent( c ); return; }
@Override protected void addView(TextAnnotation ta) throws AnnotatorException { assert ta.hasView(ViewNames.SENTENCE): "Sentences view didn't find . . . "; List<Constituent> sentences = ta.getView(ViewNames.SENTENCE).getConstituents(); View vu = new View(viewName, "ClausIEAnnotator", ta, 1.0); assert sentences.size() == ta.getNumberOfSentences(); for(Constituent sent : sentences) { String[] clausieResults = ClausieSplitter.split(sent.getSurfaceForm()); Constituent sentenceCons = new Constituent("sent-" + sent.getSentenceId(), viewName, ta, sent.getStartSpan(), sent.getEndSpan()); int propId = 0; for(String clausieSent : clausieResults) { sentenceCons.addAttribute("clauseIe:" + propId, clausieSent); propId++; } vu.addConstituent(sentenceCons); } ta.addView(viewName, vu); } }