Module Import alias If CompareGt SubscriptLoad AttributeLoad NameLoad attr Slice Num TupleLoad Num Num body Assign NameStore Str orelse Assign NameStore Str Assign NameStore ListLoad Str Str Str Str Str Str ImportFrom alias alias alias ImportFrom alias TryExcept body Import alias Assign NameStore Call AttributeLoad NameLoad attr handlers ExceptHandler type NameLoad body Import alias Assign NameStore Call AttributeLoad NameLoad attr ClassDef bases NameLoad body Expr Str FunctionDef arguments args NameParam defaults kwarg body Expr Call AttributeLoad Call NameLoad NameLoad NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str If UnaryOpNot Call NameLoad NameLoad NameLoad body Return NameLoad orelse If CompareNotEq Call NameLoad NameLoad Call NameLoad NameLoad body Return NameLoad orelse If CompareEq Call NameLoad NameLoad Call NameLoad NameLoad body Return NameLoad Return CompareEq Call AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str Return UnaryOpNot Call AttributeLoad NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Str Return Call AttributeLoad Call NameLoad NameLoad attr decorator_list decorator_list ClassDef bases NameLoad body FunctionDef arguments args NameParam NameParam NameParam defaults NameLoad body Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam defaults body Return Call AttributeLoad NameLoad attr Call NameLoad Call NameLoad Call NameLoad AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam defaults body For NameStore AttributeLoad NameLoad attr body Expr Yield Call NameLoad Call AttributeLoad NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body For NameStore NameLoad body If Call NameLoad NameLoad NameLoad body Expr Yield Call NameLoad keyword BinOpMod Str Call AttributeLoad NameLoad attr NameLoad orelse Expr Yield NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults NameLoad body Return Call AttributeLoad NameLoad attr Call NameLoad Call NameLoad Call AttributeLoad NameLoad attr NameLoad NameLoad keyword NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults body For NameStore AttributeLoad NameLoad attr body If CompareIn NameLoad NameLoad body Expr Yield Call NameLoad Call AttributeLoad NameLoad attr NameLoad NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam defaults body For TupleStore NameStore NameStore Call NameLoad NameLoad body If UnaryOpNot Call NameLoad NameLoad NameLoad body Expr Yield NameLoad orelse If BoolOpOr NameLoad CompareEq NameLoad NameLoad body Expr Yield NameLoad orelse Expr Yield Call AttributeLoad NameLoad attr NameLoad keyword NameLoad decorator_list decorator_list FunctionDef arguments args NameParam defaults body Expr Str Return Call NameLoad GeneratorExp TupleLoad AttributeLoad Call NameLoad NameLoad attr NameLoad comprehension NameStore NameLoad decorator_list FunctionDef arguments args NameParam defaults body If Call NameLoad NameLoad NameLoad body Return NameLoad Return Call NameLoad keyword AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str Return CompareEq Call AttributeLoad Call NameLoad NameLoad attr Call AttributeLoad Call NameLoad NameLoad attr decorator_list FunctionDef arguments args NameParam defaults body Expr Str Assign NameStore Call NameLoad AugAssignAdd NameStore Call AttributeLoad Call NameLoad NameLoad NameLoad attr Return Call NameLoad ListLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str Assign NameStore Call NameLoad NameLoad Assign NameStore Call NameLoad NameLoad Assign NameStore BinOpMult NameLoad NameLoad Assign NameStore BinOpSub NameLoad NameLoad Assign NameStore BinOpSub NameLoad NameLoad Return TupleLoad NameLoad NameLoad NameLoad decorator_list FunctionDef arguments args NameParam defaults body Assign NameStore NameLoad For NameStore NameLoad body If Call NameLoad NameLoad NameLoad body Expr Call AttributeLoad NameLoad attr Call AttributeLoad Call NameLoad NameLoad attr Str orelse Expr Call AttributeLoad NameLoad attr Call AttributeLoad Call NameLoad NameLoad attr Str Return Call AttributeLoad NameLoad attr decorator_list Assign NameStore Call NameLoad FunctionDef arguments args NameParam NameParam defaults body Expr Str Return Call NameLoad GeneratorExp CompareEq NameLoad NameLoad comprehension TupleStore NameStore NameStore Call NameLoad NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body For TupleStore NameStore NameStore Call NameLoad Call NameLoad Call NameLoad NameLoad Call NameLoad Call NameLoad NameLoad body Expr Yield TupleLoad NameLoad NameLoad decorator_list FunctionDef arguments args NameParam defaults body Return GeneratorExp Call NameLoad NameLoad comprehension NameStore NameLoad decorator_list FunctionDef arguments args NameParam defaults body Return Call NameLoad GeneratorExp BoolOpOr BoolOpAnd Call NameLoad NameLoad NameLoad NameLoad NameLoad comprehension NameStore NameLoad decorator_list
N/A N/A sys N/A N/A N/A N/A sys version_info N/A 2 N/A 2 4 N/A N/A __doc__ 
A collection of utilities for canonicalizing and inspecting graphs.

Among other things, they solve of the problem of deterministic bnode
comparisons.

Warning: the time to canonicalize bnodes may increase exponentially on larger
graphs. Use with care!

Example of comparing two graphs::

    >>> g1 = Graph().parse(format='n3', data='''
    ...     @prefix : <http://example.org/ns#> .
    ...     <http://example.org> :rel
    ...         <http://example.org/same>,
    ...         [ :label "Same" ],
    ...         <http://example.org/a>,
    ...         [ :label "A" ] .
    ... ''')
    >>> g2 = Graph().parse(format='n3', data='''
    ...     @prefix : <http://example.org/ns#> .
    ...     <http://example.org> :rel
    ...         <http://example.org/same>,
    ...         [ :label "Same" ],
    ...         <http://example.org/b>,
    ...         [ :label "B" ] .
    ... ''')
    >>>
    >>> iso1 = to_isomorphic(g1)
    >>> iso2 = to_isomorphic(g2)

These are not isomorphic::

    >>> iso1 == iso2
    False

Diff the two graphs::

    >>> in_both, in_first, in_second = graph_diff(iso1, iso2)

Present in both::

    >>> def dump_nt_sorted(g):
    ...     for l in sorted(g.serialize(format='nt').splitlines()):
    ...         if l: print(l.decode('ascii'))

    >>> dump_nt_sorted(in_both) #doctest: +SKIP
    <http://example.org> <http://example.org/ns#rel> <http://example.org/same> .
    <http://example.org> <http://example.org/ns#rel> _:cbcaabaaba17fecbc304a64f8edee4335e .
    _:cbcaabaaba17fecbc304a64f8edee4335e <http://example.org/ns#label> "Same" .

Only in first::

    >>> dump_nt_sorted(in_first) #doctest: +SKIP
    <http://example.org> <http://example.org/ns#rel> <http://example.org/a> .
    <http://example.org> <http://example.org/ns#rel> _:cb124e4c6da0579f810c0ffe4eff485bd9 .
    _:cb124e4c6da0579f810c0ffe4eff485bd9 <http://example.org/ns#label> "A" .

Only in second::

    >>> dump_nt_sorted(in_second) #doctest: +SKIP
    <http://example.org> <http://example.org/ns#rel> <http://example.org/b> .
    <http://example.org> <http://example.org/ns#rel> _:cb558f30e21ddfc05ca53108348338ade8 .
    _:cb558f30e21ddfc05ca53108348338ade8 <http://example.org/ns#label> "B" .
 N/A N/A __doc__ N/A __all__ N/A IsomorphicGraph to_isomorphic isomorphic to_canonical_graph graph_diff similar rdflib.graph Graph ConjunctiveGraph ReadOnlyGraphAggregate rdflib.term BNode N/A N/A N/A hashlib N/A md N/A N/A hashlib md5 N/A N/A N/A ImportError N/A N/A md5 N/A md N/A N/A md5 new IsomorphicGraph N/A ConjunctiveGraph N/A N/A 
    Ported from <http://www.w3.org/2001/sw/DataAccess/proto-tests/tools/rdfdiff.py>
    (Sean B Palmer's RDF Graph Isomorphism Tester).
     __init__ N/A N/A self N/A kwargs N/A N/A N/A N/A N/A super IsomorphicGraph self __init__ kwargs N/A __eq__ N/A N/A self other N/A N/A N/A Graph isomorphism testing. N/A N/A N/A isinstance other IsomorphicGraph N/A N/A False N/A N/A N/A N/A len self N/A len other N/A N/A False N/A N/A N/A N/A list self N/A list other N/A N/A True N/A N/A N/A N/A self internal_hash N/A N/A other internal_hash N/A __ne__ N/A N/A self other N/A N/A N/A Negative graph isomorphism testing. N/A N/A N/A N/A self __eq__ other N/A internal_hash N/A N/A self N/A N/A N/A 
        This is defined instead of __hash__ to avoid a circular recursion
        scenario with the Memory store for rdflib which requires a hash lookup
        in order to return a generator of triples.
         N/A N/A N/A N/A _TripleCanonicalizer self to_hash N/A N/A _TripleCanonicalizer N/A object N/A __init__ N/A N/A self graph hashfunc N/A hash N/A N/A N/A self graph graph N/A N/A self hashfunc hashfunc N/A to_hash N/A N/A self N/A N/A N/A N/A N/A self hashfunc N/A tuple N/A sorted N/A map N/A self hashfunc N/A N/A self canonical_triples N/A canonical_triples N/A N/A self N/A N/A N/A triple N/A self graph N/A N/A N/A N/A tuple N/A N/A self _canonicalize_bnodes triple N/A _canonicalize_bnodes N/A N/A self triple N/A N/A N/A term triple N/A N/A N/A isinstance term BNode N/A N/A N/A N/A BNode value N/A cb%s N/A N/A self _canonicalize term N/A N/A N/A term N/A _canonicalize N/A N/A self term done N/A False N/A N/A N/A N/A self hashfunc N/A tuple N/A sorted N/A N/A self _vhashtriples term done key _hetero_tuple_key N/A _vhashtriples N/A N/A self term done N/A N/A N/A triple N/A self graph N/A N/A N/A term triple N/A N/A N/A N/A tuple N/A N/A self _vhashtriple triple term done N/A _vhashtriple N/A N/A self triple target_term done N/A N/A N/A N/A i term N/A enumerate triple N/A N/A N/A N/A isinstance term BNode N/A N/A N/A term N/A N/A N/A done N/A term target_term N/A N/A N/A i N/A N/A N/A N/A N/A self _canonicalize term done True N/A N/A _hetero_tuple_key N/A N/A x N/A N/A N/A Sort like Python 2 - by name of type, then by value. Expects tuples. N/A N/A tuple N/A N/A N/A N/A type a __name__ a N/A a x N/A to_isomorphic N/A N/A graph N/A N/A N/A N/A isinstance graph IsomorphicGraph N/A N/A graph N/A N/A IsomorphicGraph store N/A graph store N/A isomorphic N/A N/A graph1 graph2 N/A N/A N/A 
    Compare graph for equality. Uses an algorithm to compute unique hashes
    which takes bnodes into account.

    Examples::

        >>> g1 = Graph().parse(format='n3', data='''
        ...     @prefix : <http://example.org/ns#> .
        ...     <http://example.org> :rel <http://example.org/a> .
        ...     <http://example.org> :rel <http://example.org/b> .
        ...     <http://example.org> :rel [ :label "A bnode." ] .
        ... ''')
        >>> g2 = Graph().parse(format='n3', data='''
        ...     @prefix ns: <http://example.org/ns#> .
        ...     <http://example.org> ns:rel [ ns:label "A bnode." ] .
        ...     <http://example.org> ns:rel <http://example.org/b>,
        ...             <http://example.org/a> .
        ... ''')
        >>> isomorphic(g1, g2)
        True

        >>> g3 = Graph().parse(format='n3', data='''
        ...     @prefix : <http://example.org/ns#> .
        ...     <http://example.org> :rel <http://example.org/a> .
        ...     <http://example.org> :rel <http://example.org/b> .
        ...     <http://example.org> :rel <http://example.org/c> .
        ... ''')
        >>> isomorphic(g1, g3)
        False
     N/A N/A N/A N/A N/A _TripleCanonicalizer graph1 to_hash N/A N/A N/A _TripleCanonicalizer graph2 to_hash N/A to_canonical_graph N/A N/A g1 N/A N/A N/A 
    Creates a canonical, read-only graph where all bnode id:s are based on
    deterministical MD5 checksums, correlated with the graph contents.
     N/A graph N/A Graph N/A graph N/A N/A N/A _TripleCanonicalizer g1 _md5_hash canonical_triples N/A N/A ReadOnlyGraphAggregate N/A graph N/A graph_diff N/A N/A g1 g2 N/A N/A N/A 
    Returns three sets of triples: "in both", "in first" and "in second".
     N/A cg1 N/A to_canonical_graph g1 N/A cg2 N/A to_canonical_graph g2 N/A in_both N/A cg1 cg2 N/A in_first N/A cg1 cg2 N/A in_second N/A cg2 cg1 N/A N/A in_both in_first in_second N/A _md5_hash N/A N/A t N/A N/A N/A h md N/A i t N/A N/A N/A isinstance i tuple N/A N/A N/A N/A h update N/A N/A N/A _md5_hash i encode ascii N/A N/A N/A N/A h update N/A N/A N/A unicode i encode utf8 N/A N/A N/A h hexdigest N/A N/A _MOCK_BNODE N/A BNode similar N/A N/A g1 g2 N/A N/A N/A 
    Checks if the two graphs are "similar", by comparing sorted triples where
    all bnodes have been replaced by a singular mock bnode (the
    ``_MOCK_BNODE``).

    This is a much cheaper, but less reliable, alternative to the comparison
    algorithm in ``isomorphic``.
     N/A N/A all N/A N/A t1 t2 N/A N/A t1 t2 N/A _squashed_graphs_triples g1 g2 N/A _squashed_graphs_triples N/A N/A g1 g2 N/A N/A N/A N/A t1 t2 N/A zip N/A sorted N/A _squash_graph g1 N/A sorted N/A _squash_graph g2 N/A N/A N/A N/A t1 t2 N/A _squash_graph N/A N/A graph N/A N/A N/A N/A N/A _squash_bnodes triple N/A triple graph N/A _squash_bnodes N/A N/A triple N/A N/A N/A N/A tuple N/A N/A N/A N/A isinstance t BNode _MOCK_BNODE t N/A t triple N/A