Class TransitiveClosure<T>
java.lang.Object
de.uni_mannheim.informatik.dws.melt.matching_jena_matchers.util.TransitiveClosure<T>
Computes a transitive closure in RAM.
This class is generic and can hold arbitrary classes as elements for the transitive closure.
One can add elements which should belong to the same identity set via the add methods.
Afterward, the computed identity sets can be retrived by the
getClosure()
call.
Remove methods are not implemented (just create new instances of TransitiveClosure).
Example:
TransitiveClosure<String> tc = new TransitiveClosure<>();
tc.add("A", "B");
tc.add("B", "C", "D");
tc.add("E", "F");
tc.getClosure();
//returns [ {"A", "B", "C", "D"}, {"E", "F"} ]
-
Field Summary
Modifier and TypeFieldDescriptionprivate int
id counter to be used when generating new synset ids.Map from synset ID to actual closure (set of objects)Map from object to synset ID -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(TransitiveClosure<T> transitiveClosure) Adds another transitive closure to this object.void
Adds elements to this transitive closure.void
Adds elements to this transitive closure.boolean
belongToTheSameCluster
(Iterable<T> elements) Checks if all given elements belong to the same identity set.boolean
belongToTheSameCluster
(T... elements) Checks if all given elements belong to the same identity set.int
Returns the number of all elements in this transitive closure (regardless of their identity set).int
Returns the number of identity sets in this transitive closure.Collection<Set<T>>
Returns the transitive closure.getIdentityID
(T element) Returns the internal id which represents the identity set.getIdentitySetForElement
(T element) Returns the identity set in which the given object is stored.
-
Field Details
-
objectToId
Map from object to synset ID -
idToClosure
Map from synset ID to actual closure (set of objects) -
idCounter
private int idCounterid counter to be used when generating new synset ids.
-
-
Constructor Details
-
TransitiveClosure
public TransitiveClosure()Initialize an empty transitive closure.
-
-
Method Details
-
add
Adds elements to this transitive closure. All items in the elements parameter are assumed to be equal. Usually these are two elements (like A - B)- Parameters:
elements
- iterable of items which are equal.
-
add
Adds another transitive closure to this object. Only this object is modified. The parameter transitiveClosure is not modified.- Parameters:
transitiveClosure
- other transitive closure which is added to this object
-
add
Adds elements to this transitive closure. All items in the elements parameter are assumed to be equal. Usually these are two elements (like A - B)- Parameters:
elements
- iterable of items which are equal.
-
getClosure
Returns the transitive closure. This means a collections of identity sets auch that all elements in one set belong to one identity.- Returns:
- transitive closure
-
belongToTheSameCluster
Checks if all given elements belong to the same identity set. Returns true if this is the case , false otherwise.- Parameters:
elements
- all elements to check.- Returns:
- true if all given elements belong to the same identity set
-
belongToTheSameCluster
Checks if all given elements belong to the same identity set. Returns true if this is the case , false otherwise.- Parameters:
elements
- all elements to check.- Returns:
- true if all given elements belong to the same identity set
-
getIdentitySetForElement
Returns the identity set in which the given object is stored.- Parameters:
element
- the element to search the identiry set for- Returns:
- the identity set
-
getIdentityID
Returns the internal id which represents the identity set. Only use if an arbitrary id is fine for the caller.- Parameters:
element
- the element to look for the internal id.- Returns:
- the internal id which represents the identity set.
-
countOfAllElements
public int countOfAllElements()Returns the number of all elements in this transitive closure (regardless of their identity set). If it contains more thanInteger.MAX_VALUE
elements, returnsInteger.MAX_VALUE
.- Returns:
- the number of all elements in this transitive closure.
-
countOfIdentitySets
public int countOfIdentitySets()Returns the number of identity sets in this transitive closure. If it contains more thanInteger.MAX_VALUE
elements, returnsInteger.MAX_VALUE
.- Returns:
- the number of identity sets.
-