java.lang.Object
de.uni_mannheim.informatik.dws.melt.matching_jena_matchers.util.TransitiveClosure<T>

public class TransitiveClosure<T> extends Object
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 Details

    • objectToId

      private Map<T,Integer> objectToId
      Map from object to synset ID
    • idToClosure

      private Map<Integer,Set<T>> idToClosure
      Map from synset ID to actual closure (set of objects)
    • idCounter

      private int idCounter
      id counter to be used when generating new synset ids.
  • Constructor Details

    • TransitiveClosure

      public TransitiveClosure()
      Initialize an empty transitive closure.
  • Method Details

    • add

      public void add(T... elements)
      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

      public void add(TransitiveClosure<T> transitiveClosure)
      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

      public void add(Iterable<T> elements)
      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

      public Collection<Set<T>> 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

      public boolean belongToTheSameCluster(T... elements)
      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

      public boolean belongToTheSameCluster(Iterable<T> elements)
      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

      public Set<T> getIdentitySetForElement(T element)
      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

      public Integer getIdentityID(T element)
      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 than Integer.MAX_VALUE elements, returns Integer.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 than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.
      Returns:
      the number of identity sets.