@Override public List<Constituent> transform(Constituent c) { Constituent c1 = c.cloneForNewView(c.getViewName()); new Relation("", c, c1, 0.0); return Collections.singletonList(c1); }
@Override public List<Constituent> transform(Constituent c) { Constituent c1 = c.cloneForNewView(c.getViewName()); new Relation("", c, c1, 0.0); return Collections.singletonList(c1); }
private static Constituent addPointerToSource(Constituent source, Constituent c) { Constituent c1 = c.cloneForNewView(c.getViewName()); new Relation("", source, c1, 0.0); return c1; }
private static Constituent addPointerToSource(Constituent source, Constituent c) { Constituent c1 = c.cloneForNewView(c.getViewName()); new Relation("", source, c1, 0.0); return c1; }
public static String printConstituent( Constituent c ) { StringBuilder output = new StringBuilder(); output.append( "Constituent: Surface form: " ).append("'").append( c.getSurfaceForm() ).append( "'" ); // output.append( "\ns-exp: " ); // output.append( c_.toSExpression( true ) ); output.append( "\nLabel: " ).append( c.getLabel() ).append( "; view: " ).append( c.getViewName() ); output.append( "\n" ).append( "char offsets: " ).append( c.getStartCharOffset() ).append( ", " ); output.append( c.getEndCharOffset() ).append( "\ntoken offsets: " ).append( c.getStartSpan() ); output.append( ", " ).append( c.getEndSpan() ); output.append( "\nAttributes: "); for ( String attType : c.getAttributeKeys() ) { String val = c.getAttribute( attType ); output.append( "[").append( attType ).append( ", " ).append( val ).append( "], " ); } output.append( "\nLabel Scores: " ); Map<String, Double> labelsToScores = c.getLabelsToScores(); if ( null != labelsToScores ) for ( Map.Entry<String, Double> e : labelsToScores.entrySet() ) output.append(e.getKey()).append(": ").append(e.getValue()).append(", "); else output.append(c.getLabel()).append(": ").append(c.getConstituentScore()); output.append( "\n" ); return output.toString(); }
public static String printConstituent( Constituent c ) { StringBuilder output = new StringBuilder(); output.append( "Constituent: Surface form: " ).append("'").append( c.getSurfaceForm() ).append( "'" ); // output.append( "\ns-exp: " ); // output.append( c_.toSExpression( true ) ); output.append( "\nLabel: " ).append( c.getLabel() ).append( "; view: " ).append( c.getViewName() ); output.append( "\n" ).append( "char offsets: " ).append( c.getStartCharOffset() ).append( ", " ); output.append( c.getEndCharOffset() ).append( "\ntoken offsets: " ).append( c.getStartSpan() ); output.append( ", " ).append( c.getEndSpan() ); output.append( "\nAttributes: "); for ( String attType : c.getAttributeKeys() ) { String val = c.getAttribute( attType ); output.append( "[").append( attType ).append( ", " ).append( val ).append( "], " ); } output.append( "\nLabel Scores: " ); Map<String, Double> labelsToScores = c.getLabelsToScores(); if ( null != labelsToScores ) for ( Map.Entry<String, Double> e : labelsToScores.entrySet() ) output.append(e.getKey()).append(": ").append(e.getValue()).append(", "); else output.append(c.getLabel()).append(": ").append(c.getConstituentScore()); output.append( "\n" ); return output.toString(); }
public SRLPredicateInstance(Constituent predicate, SRLManager manager) { this.manager = manager; //XXX Generate a clone of the predicate to avoid changing the gold TA Constituent predicateClone = predicate.cloneForNewView(predicate.getViewName()); senseInstance = new SRLMulticlassInstance(predicateClone, predicateClone, manager); List<SRLMulticlassInstance> list = new ArrayList<>(); ArgumentCandidateGenerator candidateGenerator = manager.getArgumentCandidateGenerator(); List<Constituent> cands = candidateGenerator.generateCandidates(predicate); for (Constituent c : cands) { list.add(new SRLMulticlassInstance(c, predicateClone, manager)); } this.candidates = Collections.unmodifiableList(list); }
hashCode += (this.labelsToScores == null ? 0 : this.labelsToScores.hashCode() * 23); hashCode += (new Double(this.constituentScore)).hashCode() * 67; hashCode += this.getViewName().hashCode();
public SRLPredicateInstance(Constituent predicate, SRLManager manager, ArgumentIdentifier identifier) { this.manager = manager; //XXX Generate a clone of the predicate to avoid changing the gold TA Constituent predicateClone = predicate.cloneForNewView(predicate.getViewName()); senseInstance = new SRLMulticlassInstance(predicateClone, predicateClone, manager); ArgumentCandidateGenerator candidateGenerator = manager.getArgumentCandidateGenerator(); List<SRLMulticlassInstance> allCandidates = new ArrayList<>(); for (Constituent c : candidateGenerator.generateCandidates(predicate)) { allCandidates.add(new SRLMulticlassInstance(c, predicateClone, manager)); } cacheIdentifierFeatures(allCandidates); List<SRLMulticlassInstance> list = new ArrayList<>(); for (SRLMulticlassInstance c : allCandidates) { if (identifier.getIdentifierScaledDecision(c)) list.add(c); } this.candidates = Collections.unmodifiableList(list); }
public String getNotation(Constituent c) { if (c == null) return "NULL"; String notation = c.getLabel(); if (c.getOutgoingRelations().size() > 0 && (c.getViewName().equals(ViewNames.PARSE_GOLD) || c.getViewName().equals( CONSTITUENT_PARSER))) notation += c.getOutgoingRelations().get(0).getTarget().getLabel(); if (NERlexicalise) notation += "-" + getNamedEntityTag(c); if (POSlexicalise) { notation += "-"; IntPair span = c.getSpan(); TextAnnotation ta = c.getTextAnnotation(); for (int tokenId = span.getFirst(); tokenId < span.getSecond(); tokenId++) notation += " " + POSUtils.getPOS(ta, tokenId); } return notation; }
public String getNotation(Constituent c) { if (c == null) return "NULL"; String notation = c.getLabel(); if (c.getOutgoingRelations().size() > 0 && (c.getViewName().equals(ViewNames.PARSE_GOLD) || c.getViewName().equals( CONSTITUENT_PARSER))) notation += c.getOutgoingRelations().get(0).getTarget().getLabel(); if (NERlexicalise) notation += "-" + getNamedEntityTag(c); if (POSlexicalise) { notation += "-"; IntPair span = c.getSpan(); TextAnnotation ta = c.getTextAnnotation(); for (int tokenId = span.getFirst(); tokenId < span.getSecond(); tokenId++) notation += " " + POSUtils.getPOS(ta, tokenId); } return notation; }
public Constituent nearestBefore(Constituent word) { IQueryable<Constituent> constituentsInWindow = word.getTextAnnotation().select(word.getViewName()); IQueryable<Constituent> constituentsBefore = constituentsInWindow.where(Queries.before(word)); constituentsBefore.orderBy(new Comparator<Constituent>() { @Override public int compare(Constituent o1, Constituent o2) { // Descending order to find the nearest before return o2.getEndSpan() - o1.getEndSpan(); } }); Constituent nearestConstituent = null; Iterator<Constituent> it = constituentsBefore.iterator(); if (it.hasNext()) { nearestConstituent = it.next(); } return nearestConstituent; } }
public ILPInference(ILPSolverFactory solverFactory, SenseManager manager, List<Constituent> predicates) throws Exception { super(solverFactory, false); this.manager = manager; this.outputGenerator = new ILPOutput(manager); List<SenseInstance> instances = new ArrayList<>(); for (Constituent predicate : predicates) { Constituent predicateClone = predicate.cloneForNewView(predicate.getViewName()); SenseInstance x; assert predicateClone.hasAttribute(PredicateArgumentView.LemmaIdentifier); x = new SenseInstance(predicateClone, manager); x.cacheAllFeatureVectors(); instances.add(x); } ta = predicates.get(0).getTextAnnotation(); viewName = SenseManager.getPredictedViewName(); instance = new SentenceInstance(instances); numPredicates = instance.numPredicates(); }
public ILPInference(ILPSolverFactory solverFactory, SenseManager manager, List<Constituent> predicates) throws Exception { super(solverFactory, false); this.manager = manager; this.outputGenerator = new ILPOutput(manager); List<SenseInstance> instances = new ArrayList<>(); for (Constituent predicate : predicates) { Constituent predicateClone = predicate.cloneForNewView(predicate.getViewName()); SenseInstance x; assert predicateClone.hasAttribute(PredicateArgumentView.LemmaIdentifier); x = new SenseInstance(predicateClone, manager); x.cacheAllFeatureVectors(); instances.add(x); } ta = predicates.get(0).getTextAnnotation(); viewName = SenseManager.getPredictedViewName(); instance = new SentenceInstance(instances); numPredicates = instance.numPredicates(); }
public SRLILPInference(ILPSolverFactory solverFactory, SRLManager manager, List<Constituent> predicates) throws Exception { super(solverFactory, DEBUG); this.manager = manager; this.outputGenerator = new ILPOutput(manager); List<SRLPredicateInstance> instances = new ArrayList<>(); for (Constituent predicate : predicates) { Constituent predicateClone = predicate.cloneForNewView(predicate.getViewName()); SRLPredicateInstance x; assert predicateClone.hasAttribute(PredicateArgumentView.LemmaIdentifier); x = new SRLPredicateInstance(predicateClone, manager, manager.getArgumentIdentifier()); x.cacheAllFeatureVectors(false); instances.add(x); } ta = predicates.get(0).getTextAnnotation(); viewName = manager.getPredictedViewName(); instance = new SRLSentenceInstance(instances); numPredicates = instance.numPredicates(); }
/** * @return */ @Override public int hashCode() { int hashCode = this.getTextAnnotation().getText().hashCode() * 37; hashCode += this.getStartSpan() * 41; hashCode += this.getEndSpan() * 43; hashCode += this.getLabel().hashCode() * 91; hashCode += (this.attributes == null ? 0 : this.attributes.hashCode() * 7); hashCode += (this.labelsToScores == null ? 0 : this.labelsToScores.hashCode() * 23); hashCode += (new Double(this.constituentScore)).hashCode() * 67; hashCode += this.getViewName().hashCode(); for (Relation relation : this.getIncomingRelations()) { hashCode += relation.getRelationName().hashCode() * 3; hashCode += relation.getSource().getStartSpan() * 11; hashCode += relation.getSource().getEndSpan() * 17; } for (Relation relation : this.getOutgoingRelations()) { hashCode += relation.getRelationName().hashCode() * 5; hashCode += relation.getTarget().getStartSpan() * 13; hashCode += relation.getTarget().getEndSpan() * 19; } return hashCode; }
/** * 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; }
if (start >= end) { logger.debug("Constituent with incorrect span found in " + root.getViewName()); } else { childConstituent = createNewConstituent(start, end, constituentLabel, 1.0);
/** * Transforms a scored input tree into the constituent-relation graph */ protected void addScoredParseTree(Tree<Pair<String, IntPair>> spanLabeledTree, Tree<Double> scores, Constituent root, int sentenceStartPosition) { for (int childId = 0; childId < spanLabeledTree.getNumberOfChildren(); childId++) { Tree<Pair<String, IntPair>> child = spanLabeledTree.getChild(childId); String edgeLabel; double edgeScore = 0; edgeLabel = PARENT_OF_STRING; double constituentScore = scores.getChild(childId).getLabel(); int start = child.getLabel().getSecond().getFirst() + sentenceStartPosition; int end = child.getLabel().getSecond().getSecond() + sentenceStartPosition; String constituentLabel = child.getLabel().getFirst(); Constituent childConstituent; if (start >= end) { // Ignore constituents with incorrect span bounds logger.debug("Constituent with incorrect span found in " + root.getViewName()); } else { childConstituent = createNewConstituent(start, end, constituentLabel, constituentScore); this.addConstituent(childConstituent); this.addRelation(new Relation(edgeLabel, root, childConstituent, edgeScore)); Tree<Double> scoresChild = scores.getChild(childId); this.addScoredParseTree(child, scoresChild, childConstituent, sentenceStartPosition); } } }
/** * Transforms a scored input tree into the constituent-relation graph */ protected void addScoredParseTree(Tree<Pair<String, IntPair>> spanLabeledTree, Tree<Double> scores, Constituent root, int sentenceStartPosition) { for (int childId = 0; childId < spanLabeledTree.getNumberOfChildren(); childId++) { Tree<Pair<String, IntPair>> child = spanLabeledTree.getChild(childId); String edgeLabel; double edgeScore = 0; edgeLabel = PARENT_OF_STRING; double constituentScore = scores.getChild(childId).getLabel(); int start = child.getLabel().getSecond().getFirst() + sentenceStartPosition; int end = child.getLabel().getSecond().getSecond() + sentenceStartPosition; String constituentLabel = child.getLabel().getFirst(); Constituent childConstituent; if (start >= end) { // Ignore constituents with incorrect span bounds logger.debug("Constituent with incorrect span found in " + root.getViewName()); } else { childConstituent = createNewConstituent(start, end, constituentLabel, constituentScore); this.addConstituent(childConstituent, true); this.addRelation(new Relation(edgeLabel, root, childConstituent, edgeScore)); Tree<Double> scoresChild = scores.getChild(childId); this.addScoredParseTree(child, scoresChild, childConstituent, sentenceStartPosition); } } }