de.unima.alcomox.mapping
Class Mapping

java.lang.Object
  extended by de.unima.alcomox.mapping.Mapping
All Implemented Interfaces:
java.lang.Comparable<Mapping>, java.lang.Iterable<Correspondence>

public class Mapping
extends java.lang.Object
implements java.lang.Iterable<Correspondence>, java.lang.Comparable<Mapping>

A mapping is a ordered list of correspondences. It provided several set operations on the correspondences. As well as ordering and several operations like normalization and thresholding.


Field Summary
static int FORMAT_RDF
          Standard format of the OAEI.
static int FORMAT_TXT
          Simple text-based proprietary format.
protected  boolean[] idPattern
           
protected  org.apache.log4j.Logger log
           
 
Constructor Summary
Mapping()
          Constructs a mapping with an empty list of correspondences.
Mapping(java.util.ArrayList<Correspondence> correspondences)
          Constructs a mapping with the given list of correspondences.
Mapping(java.util.Set<Correspondence> correspondencesAsSet)
          Constructs a mapping with the given set of correspondences.
Mapping(java.lang.String filepath)
          Constructs a mapping from a mapping given in a file, that has to be formated in the alignment API format.
Mapping(java.lang.String filepath, int format)
          Constructs a mapping from a mapping given in a file.
 
Method Summary
 void activateFastIdentification()
          Activates fast idpattern used for hast identification is e.g. hashsets.
 void adjustConceptConfidence(double factor)
           
 void adjustPropertyConfidence(double factor)
           
 int applyThreshhold(double threshhold)
          Applies a threshold on the mapping by removing every correspondence with a confidence below the threhold.
 void applyThresholdRelative(double rt)
          Applies a threshold such that the fraction of the rt worst correspondences are removed.
 Mapping bind(LocalOntology sourceOntology, LocalOntology targetOntology)
          Binds the mapping (more precise: the uris of the correspondences) to the internal representation of the entities.
 int compareTo(Mapping that)
           
 boolean contains(Correspondence c1)
          Checks if a given correspondence is contained in this mapping.
 int convertToEquivalenceCorrespondences()
          Converts all correspondences from the mapping that express a different semantic relation than equivalence to equivalence.
 boolean equals(java.lang.Object object)
           
 void filterBySourceNamespace(java.lang.String sourceNamespace)
          Filters out every correspondence in this mapping that has not the specified source namespace.
 void filterByTargetNamespace(java.lang.String targetNamespace)
          Filters out every correspondence in this mapping that has not the specified target namespace.
 Correspondence get(int index)
           
 double getConfidenceLowerBound()
           
 double getConfidenceTotal()
           
 double getConfidenceUpperBound()
           
 java.util.Set<ConflictPair> getConflictPairs()
           
 Mapping getCopy()
          Creates and returns a copy of this mapping.
 java.util.ArrayList<Correspondence> getCorrespondences()
          Returns the correspondences of this mapping as list.
 java.util.HashSet<Correspondence> getCorrespondencesAsSet()
          Returns the correspondences of this mapping as set.
 Mapping getDifference(Mapping that)
          Returns the set difference between this mapping and that mapping.
 boolean[] getIdPattern()
           
 Mapping getIntersection(Mapping that)
          Returns the intersection between this mapping and that.
static Mapping getJoinedMapping(Mapping[] mappings)
          Joins the specified mappings into a single mapping that contains all correspondences of the specified mappings.
static Mapping getJoinedMapping(Mapping[] mappings, double[] weights)
           
 java.lang.String getMetaDescription()
          Returns different kinds of meta information about this mapping.
 Mapping getUnion(Mapping that)
          Returns the union of this mapping and that.
 int hashCode()
           
 void invert()
          Inverts this mapping.
 boolean isUnique()
           
 java.util.Iterator<Correspondence> iterator()
           
 void joinToEquivalence()
          Joins all pairs like a < b and a > b into equivalence correspondences a = b in place.
 void modifyToEquivalenceCorrespondences()
           
 void normalize()
          Normalizes the confidences of the correspondences to the range [0.0, 1.0].
 void normalize(double normConfidence)
          Sets all correspondences in this mapping to the same value.
 void normalize(double minBound, double maxBound)
          Normalizes the confidences of the correspondences to a given range.
 Correspondence pop()
          Removes the last correspondence from this mapping.
 void push(Correspondence correspondence)
          Adds a correspondence at the end of a mapping.
 void push(Mapping mapping)
          Adds each correspondence of another mapping at the end of this mapping.
 int reduceToEquivalenceCorrespondences()
          Remove all correspondences from the mapping that express a different semantic relation than equivalence.
 Correspondence remove(int index)
          Removes a correspondence at a specified index.
 void replaceSourceNamespace(java.lang.String namespace)
           
 void replaceSubstring(java.lang.String regExp, java.lang.String newString)
          Helper method for easy working with different version of alignments that encoded version numbers in uris (like for each year of the benchmark track).
 void replaceTargetNamespace(java.lang.String namespace)
           
 void setConflictPairs(java.util.Set<ConflictPair> cps)
           
 void setCorrespondences(java.util.AbstractList<Correspondence> correspondences)
          Sets a list of correspondences as correspondences of the mapping.
 void setCorrespondences(java.util.Set<Correspondence> correspondencesAsSet)
          Sets a set of correspondences as correspondences of the mapping.
 void shrinkTill(Correspondence c)
          Removes every correspondence from the first one till the specified correspondence inclusive.
 int size()
          Returns the size of the mapping.
 void sortDescending()
           
 void splitToSubsumptionCorrespondences()
          Splits all equivalence correspondences in this mapping into subsumption correspondences in both directions.
 Mapping subMapping(int indexInclusive)
          Returns a submapping of this mapping from index 0 to indexInclusive.
 java.lang.String toShortString()
           
 java.lang.String toString()
           
 java.lang.String toVeryShortString()
           
 void write(java.lang.String filepath)
          Writes a mapping in RDF format to a specified path.
 void write(java.lang.String filepath, int format)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

FORMAT_TXT

public static final int FORMAT_TXT
Simple text-based proprietary format. One line per correspondence. Easy to read by a human.

See Also:
Constant Field Values

FORMAT_RDF

public static final int FORMAT_RDF
Standard format of the OAEI. The part in the header where metainformation (e.g. 1:1 mapping) is described is not supported.

See Also:
Constant Field Values

log

protected org.apache.log4j.Logger log

idPattern

protected boolean[] idPattern
Constructor Detail

Mapping

public Mapping()
Constructs a mapping with an empty list of correspondences.


Mapping

public Mapping(java.lang.String filepath,
               int format)
        throws MappingException
Constructs a mapping from a mapping given in a file.

Parameters:
filepath - The path to the file.
format - The format of the mapping file.
Throws:
MappingException - Thrown if the file is not available or caontains invalid format.

Mapping

public Mapping(java.lang.String filepath)
        throws MappingException
Constructs a mapping from a mapping given in a file, that has to be formated in the alignment API format.

Parameters:
filepath - The path to the file.
Throws:
MappingException - Thrown if the file is not available or caontains invalid format.

Mapping

public Mapping(java.util.ArrayList<Correspondence> correspondences)
Constructs a mapping with the given list of correspondences.

Parameters:
correspondences - The correspondences of the mapping as list.

Mapping

public Mapping(java.util.Set<Correspondence> correspondencesAsSet)
Constructs a mapping with the given set of correspondences.

Parameters:
correspondences - The correspondences of the mapping as set.
Method Detail

write

public void write(java.lang.String filepath,
                  int format)
           throws MappingException
Throws:
MappingException

write

public void write(java.lang.String filepath)
           throws MappingException
Writes a mapping in RDF format to a specified path.

Parameters:
filepath -
Throws:
MappingException

activateFastIdentification

public void activateFastIdentification()
Activates fast idpattern used for hast identification is e.g. hashsets. It is used for recognizing the same descendants of a parent mapping in a search tree in different branches, for duplicate elemination.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toShortString

public java.lang.String toShortString()

toVeryShortString

public java.lang.String toVeryShortString()

getMetaDescription

public java.lang.String getMetaDescription()
Returns different kinds of meta information about this mapping.

Returns:
Information about this mapping.

getConfidenceLowerBound

public double getConfidenceLowerBound()

getConfidenceUpperBound

public double getConfidenceUpperBound()

isUnique

public boolean isUnique()

getDifference

public Mapping getDifference(Mapping that)
Returns the set difference between this mapping and that mapping.

Parameters:
that - The mapping to be compared to this mapping.
Returns:
The set difference this without that.

getIntersection

public Mapping getIntersection(Mapping that)
Returns the intersection between this mapping and that.

Parameters:
that - The mapping to be intersected to this mapping.
Returns:
The intersection bewteen this and that.

getUnion

public Mapping getUnion(Mapping that)
Returns the union of this mapping and that. The confidence values of correspondences contained in borth this and that are summed up.

Parameters:
that - The mapping to be unioned with this mapping.
Returns:
The union of this and that.

getCopy

public Mapping getCopy()
Creates and returns a copy of this mapping. Te copy has ist own list of correspondences, but contains references to the same correspondences as are referred to be this mapping.

Returns:
A copy of this mapping.

applyThreshhold

public int applyThreshhold(double threshhold)
Applies a threshold on the mapping by removing every correspondence with a confidence below the threhold.

Parameters:
threshhold - The threshold.
Returns:
The number of correspondences that have been removed.

normalize

public void normalize(double normConfidence)
               throws AlcomoException
Sets all correspondences in this mapping to the same value.

Parameters:
normConfidence - The new confidence value for all correspondences in this mapping.
Throws:
AlcomoException - Thrown if the chosen confidence value is not in the range [0,1].

normalize

public void normalize()
Normalizes the confidences of the correspondences to the range [0.0, 1.0].

Parameters:
minBound - The lower bound (inclusive) of the range.
maxBound - The upper bound (inclusive) of the range.

normalize

public void normalize(double minBound,
                      double maxBound)
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.

Parameters:
minBound - The lower bound (inclusive) of the range.
maxBound - The upper bound (inclusive) of the range.

invert

public void invert()
Inverts this mapping. This operation changes source and target entities of the correspondences as well as replaces the semantic relations with inverse relations.


setCorrespondences

public void setCorrespondences(java.util.AbstractList<Correspondence> correspondences)
Sets a list of correspondences as correspondences of the mapping.


setCorrespondences

public void setCorrespondences(java.util.Set<Correspondence> correspondencesAsSet)
Sets a set of correspondences as correspondences of the mapping.


getCorrespondences

public java.util.ArrayList<Correspondence> getCorrespondences()
Returns the correspondences of this mapping as list.

Returns:
The internally stored list of correspondences.

getCorrespondencesAsSet

public java.util.HashSet<Correspondence> getCorrespondencesAsSet()
Returns the correspondences of this mapping as set.

Returns:
The set of correspondences.

size

public int size()
Returns the size of the mapping.

Returns:
The size of the mapping in number of correspondences.

bind

public Mapping bind(LocalOntology sourceOntology,
                    LocalOntology targetOntology)
             throws MappingException,
                    CorrespondenceException
Binds the mapping (more precise: the uris of the correspondences) to the internal representation of the entities.

Parameters:
sourceOntology - Source ontology.
targetOntology - Target ontology.
Returns:
The part of the mapping that contained referenced that could not be resolved.
Throws:
MappingException - Thrown if a correspondences relates entities of different types that cannot be matched for principle reasons.
CorrespondenceException - Thrown in case of an adjustment of confidences that is not possible.

get

public Correspondence get(int index)

push

public void push(Correspondence correspondence)
Adds a correspondence at the end of a mapping.

Parameters:
correspondence - The correspondence to be added.

push

public void push(Mapping mapping)
Adds each correspondence of another mapping at the end of this mapping.

Parameters:
mapping - The mapping to be added.

pop

public Correspondence pop()
Removes the last correspondence from this mapping.

Returns:
The correspondence that has been removed.

remove

public Correspondence remove(int index)
Removes a correspondence at a specified index.

Parameters:
index - The index of the correspondence.
Returns:
The correspondence that will be removed.

getIdPattern

public final boolean[] getIdPattern()

equals

public boolean equals(java.lang.Object object)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

iterator

public java.util.Iterator<Correspondence> iterator()
Specified by:
iterator in interface java.lang.Iterable<Correspondence>

sortDescending

public void sortDescending()

shrinkTill

public void shrinkTill(Correspondence c)
Removes every correspondence from the first one till the specified correspondence inclusive.


subMapping

public Mapping subMapping(int indexInclusive)
Returns a submapping of this mapping from index 0 to indexInclusive.

Parameters:
indexInclusive - The index of the last correspondence to be part of the sub mapping
Returns:
The submapping.

reduceToEquivalenceCorrespondences

public int reduceToEquivalenceCorrespondences()
Remove all correspondences from the mapping that express a different semantic relation than equivalence.

Returns:
The number of correspondences removed.

modifyToEquivalenceCorrespondences

public void modifyToEquivalenceCorrespondences()

getJoinedMapping

public static Mapping getJoinedMapping(Mapping[] mappings)
                                throws PCFException,
                                       CorrespondenceException
Joins the specified mappings into a single mapping that contains all correspondences of the specified mappings. The new confidence value is computed as the normalized sum of all confidences. If for example we join two mappings and there is a correspondence c1 in both we compute the new confidence as the sum of both confidences each divided by two. If its only ibn one of the them, the new confidence will be between 0 and 0.5. It is recommended to normalize the mappings before joining them.

Parameters:
mappings - The mappings to be joined.
Returns:
The joined mapping.
Throws:
PCFException
CorrespondenceException

getJoinedMapping

public static Mapping getJoinedMapping(Mapping[] mappings,
                                       double[] weights)
                                throws PCFException,
                                       CorrespondenceException
Throws:
PCFException
CorrespondenceException

adjustPropertyConfidence

public void adjustPropertyConfidence(double factor)

adjustConceptConfidence

public void adjustConceptConfidence(double factor)

getConfidenceTotal

public double getConfidenceTotal()

compareTo

public int compareTo(Mapping that)
Specified by:
compareTo in interface java.lang.Comparable<Mapping>
Returns:
-1 if this is less than that which is the case if trust of this is greater than trust of that

filterBySourceNamespace

public void filterBySourceNamespace(java.lang.String sourceNamespace)
Filters out every correspondence in this mapping that has not the specified source namespace.

Parameters:
sourceNamespace - The namespace to be used as filter.

filterByTargetNamespace

public void filterByTargetNamespace(java.lang.String targetNamespace)
Filters out every correspondence in this mapping that has not the specified target namespace.

Parameters:
targetNamespace - The namespace to be used as filter.

setConflictPairs

public void setConflictPairs(java.util.Set<ConflictPair> cps)

getConflictPairs

public java.util.Set<ConflictPair> getConflictPairs()

replaceSubstring

public void replaceSubstring(java.lang.String regExp,
                             java.lang.String newString)
                      throws CorrespondenceException
Helper method for easy working with different version of alignments that encoded version numbers in uris (like for each year of the benchmark track).

Parameters:
regExp -
newString -
Throws:
CorrespondenceException

replaceSourceNamespace

public void replaceSourceNamespace(java.lang.String namespace)

replaceTargetNamespace

public void replaceTargetNamespace(java.lang.String namespace)

applyThresholdRelative

public void applyThresholdRelative(double rt)
Applies a threshold such that the fraction of the rt worst correspondences are removed.

Parameters:
rt - The relative threshold (between 0 and 1.0).

convertToEquivalenceCorrespondences

public int convertToEquivalenceCorrespondences()
Converts all correspondences from the mapping that express a different semantic relation than equivalence to equivalence.

Returns:
The number of correspondences removed.

splitToSubsumptionCorrespondences

public void splitToSubsumptionCorrespondences()
                                       throws CorrespondenceException
Splits all equivalence correspondences in this mapping into subsumption correspondences in both directions. If all correspondences in the mapping are equivalence correspondences, a call to this method duplicates the number of correspondences. All non-equivalenve correspondences are not touched at all.

Throws:
CorrespondenceException - Cannot occur within this method.

contains

public boolean contains(Correspondence c1)
Checks if a given correspondence is contained in this mapping. Requires at the moemnt to iterate over all correpondences, baldy implemented. Can be done by constant time if hashmaps are used.

Parameters:
c1 - The correspondence for which it is checked containment
Returns:
True, if the correspondence is contained, false otherwise.

joinToEquivalence

public void joinToEquivalence()
Joins all pairs like a < b and a > b into equivalence correspondences a = b in place.