def canonicalTerm(self, term):

        if isinstance(term, URIRef):

            if self.prolog is not None:
                namespace_manager = NamespaceManager(Graph())

                for prefix,uri in self.prolog.prefixBindings.items():
                    namespace_manager.bind(prefix, uri, override=False)

                try:
                    prefix,uri,localName = namespace_manager.compute_qname(term)
                except:
                    return term

                if prefix not in self.prolog.prefixBindings:
                    return term
                else:
                    return u':'.join([prefix, localName])

            else:
                return term

        elif isinstance(term, Literal):
            return term.n3()

        elif isinstance(term, BNode):
            return term.n3()

        else:
            assert isinstance(term, Variable)
            return term.n3()
dataset/ETHPy150Open RDFLib/rdfextras/rdfextras/sparql/graph.py/BasicGraphPattern.canonicalTerm/original