
    PiS                     l    d Z ddlmZ ddlmZ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.
    )combinations)BNodeGraphc                   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     q/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-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O1*Q&&84::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OAuQxx..    	! 	!r   Fc                 b    t          t          |                     ||                              S r   )r   r   vhashtriples)r   termdones      r   r   zIsomorphicTestableGraph.vhash#   s(    VD--dD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qyy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 	7AfQi// 7Qi 7&)t++jj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YY#a&&  5[[dT!WW-- 	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   JJJ%%%%%%>E	E	"	"	"BMM&     MM3330  	 	 	 mmooOWdFK} ''))//	'BU/VVe&E    '))//7;N/OOeEeeG&vq11  F7**/?w/N/NV###F###F##&### r   __main__N)	r6   	itertoolsr   rdflibr   r   r   r]   r3   r	   r   r   <module>ra      s    
 # " " " " "        5" 5" 5" 5" 5"e 5" 5" 5"p* * *Z zDFFFFF r   