/** * 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; }
/** * create a new constituent with token offsets shifted by the specified amount * @param newTA TextAnnotation which will contain the new Constituent * @param c original Constituent to copy * @param offset the offset to shift token indexes of new Constituent. Can be negative. * @return the new Constituent */ public static Constituent copyConstituentWithNewTokenOffsets(TextAnnotation newTA, Constituent c, int offset) { int newStart = c.getStartSpan() + offset; int newEnd = c.getEndSpan() + offset; assert(newStart >= 0 && newStart <= newTA.size()); assert(newEnd >= 0 && newEnd <= newTA.size()); Constituent newCon = null; if (null != c.getLabelsToScores()) newCon = new Constituent(c.getLabelsToScores(), c.viewName, newTA, newStart, newEnd); else newCon = new Constituent(c.getLabel(), c.getConstituentScore(), c.viewName, newTA, newStart, newEnd); copyAttributesFromTo(c, newCon); return newCon; }
/** * create a new constituent with token offsets shifted by the specified amount * @param newTA TextAnnotation which will contain the new Constituent * @param c original Constituent to copy * @param offset the offset to shift token indexes of new Constituent. Can be negative. * @return the new Constituent */ public static Constituent copyConstituentWithNewTokenOffsets(TextAnnotation newTA, Constituent c, int offset) { int newStart = c.getStartSpan() + offset; int newEnd = c.getEndSpan() + offset; assert(newStart >= 0 && newStart <= newTA.size()); assert(newEnd >= 0 && newEnd <= newTA.size()); Constituent newCon = null; if (null != c.getLabelsToScores()) newCon = new Constituent(c.getLabelsToScores(), c.viewName, newTA, newStart, newEnd); else newCon = new Constituent(c.getLabel(), c.getConstituentScore(), c.viewName, newTA, newStart, newEnd); copyAttributesFromTo(c, newCon); return newCon; }
/** * 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; }