public Correspondence correspondenceFor(Element e) { for (Correspondence c : descendents()) { T2<Collection<Element>, Collection<Element>> es = c.elements(); if (es.e0.contains(e) || es.e1.contains(e)) return c; } return null; }
public double getConfidenceLowerBound() { double lowerBound = Double.MAX_VALUE; for (Correspondence c : this.getCorrespondences()) { lowerBound = c.getConfidence() < lowerBound ? c.getConfidence() : lowerBound; } return lowerBound; }
public double getConfidenceUpperBound() { double upperBound = Double.MIN_VALUE; for (Correspondence c : this.getCorrespondences()) { upperBound = c.getConfidence() > upperBound ? c.getConfidence() : upperBound; } return upperBound; }
public double getConfidenceTotal() { double total = 0.0d; for (Correspondence c : this) { total += c.getConfidence(); } return total; }
public static Alignment getJoinedMapping(Alignment[] mappings, double[] weights) throws PCFException, CorrespondenceException { if (mappings.length != weights.length) { throw new PCFException( PCFException.INVALID_PARAM_COMBINATION, "in a mapping join operation you need the same number of mappings and weights"); } HashMap<Correspondence, Double> hashedConfidences = new HashMap<Correspondence, Double>(); for (int m = 0; m < mappings.length; m++) { double weight = weights[m]; for (Correspondence c : mappings[m]) { if (hashedConfidences.containsKey(c)) { hashedConfidences.put(c, c.getConfidence() * weight + hashedConfidences.get(c)); } else { hashedConfidences.put(c, c.getConfidence() * weight); } } } Alignment joinedMapping = new Alignment(); for (Correspondence c : hashedConfidences.keySet()) { c.setConfidence(hashedConfidences.get(c)); joinedMapping.push(c); } return joinedMapping; }
public void removeCorrespondencesWithNSPrefix(String ns) { ArrayList<Correspondence> filteredCorrespondences = new ArrayList<Correspondence>(); for (Correspondence c : this) { if (!(c.getSourceNamespace().startsWith(ns) || c.getTargetNamespace().startsWith(ns))) { filteredCorrespondences.add(c); } } this.setCorrespondences(filteredCorrespondences); }
/** * Applies a threshold on the mapping by removing every correspondence with a confidence below the * threhold. * * @param threshhold The threshold. * @return The number of correspondences that have been removed. */ public int applyThreshhold(float threshhold) { ArrayList<Correspondence> thresholdedCorrespondences = new ArrayList<Correspondence>(); int numOfRemovedCorrespondences = 0; for (Correspondence c : this.correspondences) { if (c.getConfidence() >= threshhold) { thresholdedCorrespondences.add(c); } else { numOfRemovedCorrespondences++; } } this.correspondences = thresholdedCorrespondences; return numOfRemovedCorrespondences; }
/** Returns a string representation of this mapping. */ private String toSomeString(boolean verbose) { if (this.size() == 0) { return "[empty mapping]\n"; } StringBuffer sb = new StringBuffer(); ArrayList<Correspondence> sortedCorrespondences = this.getCorrespondences(); Collections.sort(sortedCorrespondences); Collections.reverse(sortedCorrespondences); // sb.append("Mapping of size " + this.correspondences.size() + "\n"); for (Correspondence c : sortedCorrespondences) { if (verbose) { sb.append(c.toString() + "\n"); } else { sb.append(c.toShortString() + "\n"); } } return sb.toString(); }
/** * Returns different kinds of meta information about this mapping. * * @return Information about this mapping. */ public String getMetaDescription() { StringBuffer sb = new StringBuffer(); HashSet<SemanticRelation> relations = new HashSet<SemanticRelation>(); HashSet<String> sourceNamespaces = new HashSet<String>(); HashSet<String> targetNamespaces = new HashSet<String>(); double lowerBound = this.getConfidenceLowerBound(); double upperBound = this.getConfidenceUpperBound(); for (Correspondence c : this.getCorrespondences()) { relations.add(c.getRelation()); sourceNamespaces.add(c.getSourceNamespace()); targetNamespaces.add(c.getTargetNamespace()); } sb.append("NUMBER OF CORRESPONDENCES: " + this.size() + "\n"); sb.append("SEMANTIC RELATIONS: " + relations + "\n"); sb.append("NAMESPACES FOR SOURCE ENTITIES: " + sourceNamespaces + "\n"); sb.append("NAMESPACES FOR TARGET ENTITIES: " + targetNamespaces + "\n"); sb.append("CONFIDENCE RANGE: [" + lowerBound + ", " + upperBound + "]\n"); sb.append("IS UNIQUE: " + this.isUnique() + "\n"); return sb.toString(); }
/** * Normalizes the confidences of the correspondences to a given range. If all correspondences have * the same confidence, all of them are set to the upper bound of the range. * * @param minBound The lower bound (inclusive) of the range. * @param maxBound The upper bound (inclusive) of the range. */ public void normalize(double minBound, double maxBound) { double min = Double.MAX_VALUE; double max = Double.MIN_VALUE; // store the lowest and greates value of the correspondences. for (Correspondence c : this.correspondences) { min = (c.getConfidence() < min) ? c.getConfidence() : min; max = (c.getConfidence() > max) ? c.getConfidence() : max; } if (this.correspondences.size() > 0) { // if all correspondences had the same confidence, set them to the upper bound if (min == max) { for (int i = 0; i < this.correspondences.size(); i++) { try { this.correspondences.get(i).setConfidence(maxBound); } catch (CorrespondenceException ce) { // can never happen in this method } } } // the normal case else { double sim; for (int i = 0; i < this.correspondences.size(); i++) { sim = this.correspondences.get(i).getConfidence(); sim = ((sim - min) * ((maxBound - minBound) / (max - min))) + minBound; sim = (sim > maxBound) ? maxBound : sim; sim = (sim < minBound) ? minBound : sim; // System.out.println(sim); try { this.correspondences.get(i).setConfidence(sim); } catch (CorrespondenceException ce) { // can never happen in this method } } } } }
/** * Inverts this mapping. This operation changes source and target entities of the correspondences * as well as replaces the semantic relations with inverse relations. */ public void invert() { String sourceEntity; String targetEntity; SemanticRelation semanticRelation; for (Correspondence c : this.correspondences) { sourceEntity = c.getSourceEntityUri(); targetEntity = c.getTargetEntityUri(); semanticRelation = c.getRelation(); try { c.setSourceEntityUri(targetEntity); c.setTargetEntityUri(sourceEntity); } catch (CorrespondenceException e) { // cannot occur in this context } c.setRelation(semanticRelation.getInverse()); } }
public void normalize(double normConfidence) throws AlcomoException { for (Correspondence c : this.correspondences) { c.setConfidence(normConfidence); } }