nltk.transitive_closure()

nltk.transitive_closure(graph, reflexive=False)[source]

Calculate the transitive closure of a directed graph, optionally the reflexive transitive closure.

The algorithm is a slight modification of the “Marking Algorithm” of Ioannidis & Ramakrishnan (1998) “Efficient Transitive Closure Algorithms”.

Parameters:
  • graph (dict(set)) – the initial graph, represented as a dictionary of sets
  • reflexive (bool) – if set, also make the closure reflexive
Return type:

dict(set)