@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(); }
@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(); }
@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 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 boolean equals(Object obj) { if (this == obj) return true; if (!(obj instanceof Relation)) return false; Relation r = (Relation) obj; if (this.attributes == null && r.attributes != null) return false; if (this.attributes != null && r.attributes == null) return false; if (this.attributes != null && r.attributes != null) if (!this.attributes.equals(r.attributes)) return false; if (this.labelsToScores == null && r.labelsToScores != null) return false; if (this.labelsToScores != null && r.labelsToScores == null) return false; if (this.labelsToScores != null && r.labelsToScores != null) if (!this.labelsToScores.equals(r.labelsToScores)) return false; return r.getRelationName().equals(this.relationName) && r.getSource().equals(this.getSource()) && r.getTarget().equals(this.getTarget()) && r.getScore() == this.getScore(); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (!(obj instanceof Relation)) return false; Relation r = (Relation) obj; if (this.attributes == null && r.attributes != null) return false; if (this.attributes != null && r.attributes == null) return false; if (this.attributes != null && r.attributes != null) if (!this.attributes.equals(r.attributes)) return false; if (this.labelsToScores == null && r.labelsToScores != null) return false; if (this.labelsToScores != null && r.labelsToScores == null) return false; if (this.labelsToScores != null && r.labelsToScores != null) if (!this.labelsToScores.equals(r.labelsToScores)) return false; return r.getRelationName().equals(this.relationName) && r.getSource().equals(this.getSource()) && r.getTarget().equals(this.getTarget()) && r.getScore() == this.getScore(); }
/** * 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; }
/** * 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; }
relationBuilder.setScore(relation.getScore()); relationBuilder.setSrcConstituent(srcId); relationBuilder.setTargetConstituent(tgtId);
relationBuilder.setScore(relation.getScore()); relationBuilder.setSrcConstituent(srcId); relationBuilder.setTargetConstituent(tgtId);
/** * 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 list containing pairs that 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, List<Pair<Constituent, Constituent>> consMap) { Relation newRel = null; Constituent src = null; Constituent tgt = null; // the equality check here is VERY important. Sometimes duplicate constituents are allowed, // and we want to check OBJECT equality, not attribute equality. for(Pair<Constituent,Constituent> p : consMap){ if(r.getSource() == p.getFirst()){ src = p.getSecond(); } if(r.getTarget() == p.getFirst()){ tgt = p.getSecond(); } } if ( null == r.getLabelsToScores() ) newRel = new Relation(r.getRelationName(), src, tgt, r.getScore()); else newRel = new Relation(r.getLabelsToScores(), src, tgt); copyAttributesFromTo(r, newRel); return newRel; }