§
    kÃ¿a:  ã                   ót   — d Z ddlmZ ddlmZ ddlmZ  G d„ de¦  «        Zd„ Zedk    r e¦   «          d	S d	S )
ze
A commandline tool for testing if RDF graphs are isomorpic, i.e. equal
if BNode labels are ignored.
é    )ÚGraph)ÚBNode)Úcombinationsc                   óN   ‡ — e Zd ZdZˆ fd„Zd„ Zd„ Zdd„Zd„ Zd„ Z	d	„ Z
d
„ Zˆ xZS )ÚIsomorphicTestableGraphz�
    Ported from:
    http://www.w3.org/2001/sw/DataAccess/proto-tests/tools/rdfdiff.py
    (Sean B Palmer's RDF Graph Isomorphism Tester)
    c                 óV   •—  t          t          | ¦  «        j        di |¤Ž d | _        d S )N© )Úsuperr   Ú__init__Úhash)ÚselfÚkargsÚ	__class__s     €ú?/usr/lib/python3/dist-packages/rdflib/tools/graphisomorphism.pyr   z IsomorphicTestableGraph.__init__   s2   ø€ Ø5�Õ% tÑ,Ô,Ô5Ð>Ð>¸Ð>Ð>Ð>ØˆŒ	ˆ	ˆ	ó    c                 óx   — t          t          t          |                      ¦   «         ¦  «        ¦  «        ¦  «        S )zÔ
        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
        )r   ÚtupleÚsortedÚhashtriples)r   s    r   Úinternal_hashz%IsomorphicTestableGraph.internal_hash   s.   € õ •E�& ×!1Ò!1Ñ!3Ô!3Ñ4Ô4Ñ5Ô5Ñ6Ô6Ð6r   c              #   ón   ‡ K  — ‰ D ].}ˆ fd„|D ¦   «         }t          t          |¦  «        ¦  «        V — Œ/d S )Nc              3   óp   •K  — | ]0}t          |t          ¦  «        r‰                     |¦  «        p|V — Œ1d S ©N)Ú
isinstancer   Úvhash)Ú.0Útr   s     €r   ú	<genexpr>z6IsomorphicTestableGraph.hashtriples.<locals>.<genexpr>    sA   øè è € ÐOÐOÀ1•*˜Q¥Ñ&Ô&Ð8¨4¯:ª:°a©=¬=Ð>¸QÐOÐOÐOÐOÐOÐOr   )r   r   )r   ÚtripleÚgs   `  r   r   z#IsomorphicTestableGraph.hashtriples   sT   øè è € Øð 	!ð 	!ˆFØOÐOÐOÐOÈÐOÑOÔOˆAÝ•u˜Q‘x”x‘.”.Ð Ð Ð Ð ð	!ð 	!r   Fc                 ób   — t          t          |                      ||¦  «        ¦  «        ¦  «        S r   )r   r   Úvhashtriples)r   ÚtermÚdones      r   r   zIsomorphicTestableGraph.vhash#   s(   € Ý•V˜D×-Ò-¨d°DÑ9Ô9Ñ:Ô:Ñ;Ô;Ð;r   c              #   óh   K  — | D ],}||v r&t          |                      |||¦  «        ¦  «        V — Œ-d S r   )r   Úvhashtriple)r   r#   r$   r   s       r   r"   z$IsomorphicTestableGraph.vhashtriples&   sO   è è € Øð 	=ð 	=ˆAØ�qˆyˆyÝ˜D×,Ò,¨Q°°dÑ;Ô;Ñ<Ô<Ð<Ð<Ð<øð	=ð 	=r   c              #   óÞ   K  — t          d¦  «        D ]Z}t          ||         t          ¦  «        s||         V — Œ(|s||         |k    r|V — Œ;|                      ||         d¬¦  «        V — Œ[d S )Né   T)r$   )Úranger   r   r   )r   r   r#   r$   Úps        r   r&   z#IsomorphicTestableGraph.vhashtriple+   sŽ   è è € Ý�q‘”ð 	7ð 	7ˆAÝ˜f Qœi­Ñ/Ô/ð 7Ø˜Q”i����Øð 7˜& œ) tÒ+Ð+Ø����à—j’j ¨¤°�jÑ6Ô6Ð6Ð6Ð6Ð6ð	7ð 	7r   c                 ó6  — t          |t          ¦  «        sdS t          | ¦  «        t          |¦  «        k    rdS t                               t          | ¦  «        t          |¦  «        ¦  «        rdS |                      ¦   «         |                     ¦   «         k    S )zGraph isomorphism testing.FT)r   r   ÚlenÚlistÚ__eq__r   ©r   ÚGs     r   r.   zIsomorphicTestableGraph.__eq__4   s~   € å˜!Õ4Ñ5Ô5ð 	Ø�5Ý�‰YŒY�#˜a™&œ&Ò Ð Ø�5Ý�[Š[�˜d™œ¥T¨!¡W¤WÑ-Ô-ð 	Ø�4Ø×!Ò!Ñ#Ô# q§¢Ñ'8Ô'8Ò8Ð8r   c                 ó.   — |                       |¦  «         S )z#Negative graph isomorphism testing.)r.   r/   s     r   Ú__ne__zIsomorphicTestableGraph.__ne__>   s   € à—;’;˜q‘>”>Ð!Ð!r   )F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r"   r&   r.   r2   Ú__classcell__)r   s   @r   r   r      s°   ø€ € € € € ðð ðð ð ð ð ð7ð 7ð 7ð!ð !ð !ð
<ð <ð <ð <ð=ð =ð =ð
7ð 7ð 7ð9ð 9ð 9ð"ð "ð "ð "ð "ð "ð "r   r   c                  ó¦  — dd l } ddlm} d} ||¬¦  «        }|                     ddddd	¬
¦  «         |                     ddddg d¢d¬¦  «         |                     ¦   «         \  }}g }i }|j        rGt          ¦   «                              | j        |j        ¬¦  «        }| 	                    |¦  «         d||<   |D ]D}	t          ¦   «                              |	|j        ¬¦  «        }| 	                    |¦  «         |	||<   ŒEt          ¦   «         }
t          |d¦  «        D ]2\  }}||f|
vr'||f|
vr!||k    sJ ||         ›d||         ›�¦   «         ‚Œ3d S )Nr   )ÚOptionParserz,usage: %prog [options] file1 file2 ... fileN)Úusagez-sz--stdinÚ
store_trueFzLoad from STDIN as well)ÚactionÚdefaultÚhelpz--formatÚxmlÚinputFormatÚ
RDF_FORMAT)r?   ÚtrixÚn3ÚntÚrdfazoThe format of the RDF document(s) to compareOne of 'xml','n3','trix', 'nt', or 'rdfa'.  The default is %default)r=   ÚdestÚmetavarÚchoicesr>   )Úformatz(STDIN)é   z != )ÚsysÚoptparser9   Ú
add_optionÚ
parse_argsÚstdinr   Úparser@   ÚappendÚsetr   )rK   r9   r:   ÚopÚoptionsÚargsÚgraphsÚgraph2FNameÚgraphÚfnÚcheckedÚgraph1Úgraph2s                r   Úmainr]   C   sÏ  € Ø€J€J€JØ%Ð%Ð%Ð%Ð%Ð%à>€EØ	ˆ˜EÐ	"Ñ	"Ô	"€BØ‡M‚MØØØØØ&ð ñ ô ð ð ‡M‚MØØØØØ3Ð3Ð3ð0ð ñ 	ô 	ð 	ð —m’m‘o”o�O€Wˆdà€FØ€KØ„}ð 'Ý'Ñ)Ô)×/Ò/°´	À'ÔBUÐ/ÑVÔVˆØ�Š�eÑÔÐØ&ˆ�EÑØð  ð  ˆÝ'Ñ)Ô)×/Ò/°¸7Ô;NÐ/ÑOÔOˆØ�Š�eÑÔÐØˆ�EÑÐÝ‰eŒe€GÝ& v¨qÑ1Ô1ð ð ‰ˆ�Ø�FÐ 7Ð*Ð*°¸Ð/?ÀwÐ/NÐ/NØ˜VÒ#Ð#Ð#Ø˜FÔ#Ð#Ð#Ø˜FÔ#Ð#ð&Ñ#Ô#Ð#øðð r   Ú__main__N)	r6   Úrdflibr   r   Ú	itertoolsr   r   r]   r3   r	   r   r   ú<module>ra      s¦   ððð ð
 Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø "Ð "Ð "Ð "Ð "Ð "ð5"ð 5"ð 5"ð 5"ð 5"˜eñ 5"ô 5"ð 5"ðp*ð *ð *ðZ ˆzÒÐØ€D�F„F€F€F€Fð Ðr   