code: def directly_or_indirectly_related(self, ns1, id1, ns2, id2, closure_dict,
                                         relation_func):
          if id2 is None or (id2 is None and id1 is None):
              return True
          elif id1 is None:
              return False
          if closure_dict:
              term1 = self.get_uri(ns1, id1)
              term2 = self.get_uri(ns2, id2)
              ec = closure_dict.get(term1)
              if ec is not None and term2 in ec:
                  return True
              else:
                  return False
          else:
              if not self.uri_as_name:
                  e1 = self.find_entity(id1)
                  e2 = self.find_entity(id2)
                  if e1 is None or e2 is None:
                      return False
                  t1 = rdflib.term.URIRef(e1)
                  t2 = rdflib.term.URIRef(e2)
              else:
                  u1 = self.get_uri(ns1, id1)
                  u2 = self.get_uri(ns2, id2)
                  t1 = rdflib.term.URIRef(u1)
                  t2 = rdflib.term.URIRef(u2)
              to = self.graph.transitiveClosure(relation_func, t1)
              if t2 in to:
                  return True
              else:
                  return False