/** * required: consMap *must* contain the source and target constituents for r as keys, and their values * must be non-null * @param r relation to copy * @param consMap map from original constituents to new counterparts * @return new relation with all info copied from original, but with new source and target constituents */ public static Relation copyRelation(Relation r, Map<Constituent, Constituent> consMap) { Relation newRel = null; if ( null == r.getLabelsToScores() ) newRel = new Relation(r.getRelationName(), consMap.get(r.getSource()), consMap.get(r.getTarget()), r.getScore()); else newRel = new Relation(r.getLabelsToScores(), consMap.get(r.getSource()), consMap.get(r.getTarget())); copyAttributesFromTo(r, newRel); return newRel; }
public static String printRelation(Relation c) { StringBuilder output = new StringBuilder(); output.append( "Relation has type: " ); output.append( c.getRelationName() ); output.append( "Attributes: "); for ( String attType : c.getAttributeKeys() ) { String val = c.getAttribute( attType ); output.append( "[").append( attType ).append( ", " ).append( val ).append( "], " ); } output.append("\nFirst argument:\n"); output.append(printConstituent(c.getSource())); output.append("\n\nSecond argument:\n"); output.append(printConstituent(c.getTarget())); return output.toString(); }
@Override public int hashCode() { int hashCode = this.getRelationName().hashCode() * 79 + this.getSource().hashCode() * 7 + this.getTarget().hashCode() * 13 + (new Double(this.getScore())).hashCode() * 17; hashCode += (this.attributes == null ? 0 : this.attributes.hashCode() * 13); hashCode += (this.labelsToScores == null ? 0 : this.labelsToScores.hashCode() * 23); return hashCode; }
@Override public String toString() { StringBuilder bldr = new StringBuilder( source.toString() ); bldr.append( "--" ).append( getRelationName() ).append("--> "); bldr.append( target ).append("(").append( getScore() ).append( ")" ); return bldr.toString(); }
private static Constituent getNewConstituent(TextAnnotation ta, Constituent predicate, int start, int end) { Constituent newConstituent = new Constituent("", 1.0, viewName, ta, start, end); new Relation("ChildOf", predicate, newConstituent, 1.0); return newConstituent; } }
private static List<Constituent> getModifiers(Constituent input, TreeView dependency) { List<Constituent> constituentsCovering = dependency.getConstituentsCovering(input); if (constituentsCovering.size() == 0) return new ArrayList<>(); Constituent c = constituentsCovering.get(0); List<Relation> outgoingRelations = c.getOutgoingRelations(); if (outgoingRelations == null || outgoingRelations.size() == 0) return new ArrayList<>(); else { for (Relation r : outgoingRelations) { if (r.getRelationName().contains("mod")) return Collections.singletonList(addPointerToSource(input, r.getTarget())); } return Collections.singletonList(addPointerToSource(input, outgoingRelations.get(0) .getTarget())); } }
@Override public Constituent transform(Relation arg0) { return arg0.getTarget(); } };
public String discreteValue(Object __example) { if (!(__example instanceof Relation)) { String type = __example == null ? "null" : __example.getClass().getName(); System.err.println("Classifier 'afterHead(Relation)' defined on line 26 of extent.lbj received '" + type + "' as input."); new Exception().printStackTrace(); System.exit(1); } Relation r = (Relation) __example; if (r.getSource().getStartSpan() >= r.getTarget().getEndSpan()) { return "true"; } return "false"; }
RelationProto.Builder relationBuilder = RelationProto.newBuilder(); Constituent src = relation.getSource(); Constituent tgt = relation.getTarget(); relationBuilder.setRelationName(relation.getRelationName()); relationBuilder.setScore(relation.getScore()); relationBuilder.setSrcConstituent(srcId); relationBuilder.setTargetConstituent(tgtId); if (!relation.getAttributeKeys().isEmpty()) { for (String key: Sorters.sortSet(relation.getAttributeKeys())) { relationBuilder.putProperties(key, relation.getAttribute(key)); Map<String, Double> labelsToScores = relation.getLabelsToScores(); if (labelsToScores != null) { relationBuilder.putAllLabelScoreMap(labelsToScores);
/** * Gets the parent of a constituent. It is assumed that the input constiutent is a member of a * TreeView. */ public static Constituent getParent(Constituent constituent) { return constituent.getIncomingRelations().get(0).getSource(); }
@Override public int compare(Relation arg0, Relation arg1) { return arg0.getRelationName().compareTo(arg1.getRelationName()); } });
public String[] getRightToLeftDependencies() { TreeView depTreeView = (TreeView) s.ta.getView(ViewNames.DEPENDENCY_STANFORD); List<Constituent> constituentsOnLeft = depTreeView.getConstituentsCoveringSpan(0, commaPosition); List<Relation> rtols = new ArrayList<>(); for (Constituent constituent : constituentsOnLeft) { for (Relation relation : constituent.getIncomingRelations()) { Constituent target = relation.getSource(); if (target.getStartSpan() > commaPosition) rtols.add(relation); } } String[] rtolNames = new String[rtols.size()]; for (int i = 0; i < rtolNames.length; i++) rtolNames[i] = rtols.get(i).getRelationName(); return rtolNames; }
public String discreteValue(Object __example) { if (!(__example instanceof Relation)) { String type = __example == null ? "null" : __example.getClass().getName(); System.err.println("Classifier 'relation_label(Relation)' defined on line 18 of re.lbj received '" + type + "' as input."); new Exception().printStackTrace(); System.exit(1); } Relation r = (Relation) __example; return "" + (r.getAttribute("RelationType")); }
@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 Set<Feature> getFeatures(Constituent c) throws EdisonException { List<Constituent> parents = dependencyHeadIdentifier.transform(c); Set<Feature> features = new LinkedHashSet<>(); if (parents.size() == 0) { Constituent parent = parents.get(0); for (Relation out : parent.getOutgoingRelations()) { String label = out.getRelationName(); if (label.contains("det") || label.contains("mod") || label.contains("number")) { features.addAll(FeatureUtilities.prefix(label, baseFex.getFeatures(out.getTarget()))); } } } return features; }
@Override public Constituent transform(Relation arg0) { return arg0.getTarget(); } };
public String discreteValue(Object __example) { if (!(__example instanceof Relation)) { String type = __example == null ? "null" : __example.getClass().getName(); System.err.println("Classifier 'beforeHead(Relation)' defined on line 19 of extent.lbj received '" + type + "' as input."); new Exception().printStackTrace(); System.exit(1); } Relation r = (Relation) __example; if (r.getSource().getStartSpan() < r.getTarget().getStartSpan()) { return "true"; } return "false"; }
@Override public int hashCode() { int hashCode = this.getRelationName().hashCode() * 79 + this.getSource().hashCode() * 7 + this.getTarget().hashCode() * 13 + (new Double(this.getScore())).hashCode() * 17; hashCode += (this.attributes == null ? 0 : this.attributes.hashCode() * 13); hashCode += (this.labelsToScores == null ? 0 : this.labelsToScores.hashCode() * 23); return hashCode; }
/** * Gets the parent of a constituent. It is assumed that the input constiutent is a member of a * TreeView. */ public static Constituent getParent(Constituent constituent) { return constituent.getIncomingRelations().get(0).getSource(); }
@Override public int compare(Relation arg0, Relation arg1) { return arg0.getRelationName().compareTo(arg1.getRelationName()); } });