o
    i)                     @   sN   d Z ddlmZ ddlmZmZ G dd deZd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                       sZ   e Zd ZdZ fddZdd Zdd Zdd	d
Zdd Zdd Z	dd Z
dd Z  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                    s    t t| jdi | d | _d S )N )superr   __init__hash)selfkargs	__class__r   X/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/rdflib/tools/graphisomorphism.pyr      s   
z IsomorphicTestableGraph.__init__c                 C   s   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
   r   r   r   internal_hash   s   z%IsomorphicTestableGraph.internal_hashc                 #   s0     D ]} fdd|D }t t|V  qd S )Nc                 3   s(    | ]}t |tr |p|V  qd S N)
isinstancer   vhash).0tr   r   r   	<genexpr>    s   & z6IsomorphicTestableGraph.hashtriples.<locals>.<genexpr>)r	   r   )r
   triplegr   r   r   r      s
   z#IsomorphicTestableGraph.hashtriplesFc                 C   s   t t| ||S r   )r   r   vhashtriples)r
   termdoner   r   r   r   #   s   zIsomorphicTestableGraph.vhashc                 c   s,    | D ]}||v rt | |||V  qd S r   )r   vhashtriple)r
   r   r   r   r   r   r   r   &   s   z$IsomorphicTestableGraph.vhashtriplesc                 c   sZ    t dD ]%}t|| ts|| V  q|s|| |kr |V  q| j|| ddV  qd S )N   T)r   )ranger   r   r   )r
   r   r   r   pr   r   r   r   +   s   z#IsomorphicTestableGraph.vhashtriplec                 C   sJ   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
   Gr   r   r   r%   4   s   
zIsomorphicTestableGraph.__eq__c                 C   s   |  | S )z#Negative graph isomorphism testing.)r%   r&   r   r   r   __ne__>   s   zIsomorphicTestableGraph.__ne__)F)__name__
__module____qualname____doc__r   r   r   r   r   r   r%   r(   __classcell__r   r   r   r   r      s    
	
r   c                  C   s  dd l } ddlm} d}||d}|jddddd	d
 |jddddg ddd | \}}g }i }|jrHt j| j|jd}|	| d||< |D ]}	t j|	|jd}|	| |	||< qJt
 }
t|dD ] \}}||f|
vr||f|
vr||ksJ d|| || f qgd 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)r4   trixn3ntrdfazoThe format of the RDF document(s) to compareOne of 'xml','n3','trix', 'nt', or 'rdfa'.  The default is %default)r2   destmetavarchoicesr3   )formatz(STDIN)   z%s != %s)sysoptparser.   
add_option
parse_argsstdinr   parser5   appendsetr   )r@   r.   r/   opoptionsargsgraphsgraph2FNamegraphfncheckedgraph1graph2r   r   r   mainC   sN   



rR   __main__N)	r,   	itertoolsr   rdflibr   r   r   rR   r)   r   r   r   r   <module>   s    8-
