
    4Ysh:                     b    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        y	y	)
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                 :    t        t        | 
  di | d | _        y )N )superr   __init__hash)selfkargs	__class__s     }/var/www/sten-cake5-migrate2.hellocrow.space/lexinfo-master/env/lib/python3.12/site-packages/rdflib/tools/graphisomorphism.pyr   z IsomorphicTestableGraph.__init__   s    %t5>>	    c                 X    t        t        t        | j                                           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4566r   c              #   ^    K    D ]#  } fd|D        }t        t        |             % y w)Nc              3   l   K   | ]+  }t        |t              xr j                  |      xs | - y wN)
isinstancer   vhash).0tr   s     r   	<genexpr>z6IsomorphicTestableGraph.hashtriples.<locals>.<genexpr>    s-     O1*Q&84::a=>Q>Os   14)r   r   )r   triplegs   `  r   r   z#IsomorphicTestableGraph.hashtriples   s.      	!FOOAuQx. 	!s   *-c                 J    t        t        | j                  ||                  S r   )r   r   vhashtriples)r   termdones      r   r   zIsomorphicTestableGraph.vhash#   s    VD--dD9:;;r   c              #   `   K   | D ]%  }||v st        | j                  |||             ' y wr   )r   vhashtriple)r   r#   r$   r   s       r   r"   z$IsomorphicTestableGraph.vhashtriples&   s6      	=AqyD,,Qd;<<	=s   
.!.c              #      K   t        d      D ]D  }t        ||   t              s||    |s||   |k(  r| -| j                  ||   d       F y w)N   T)r$   )ranger   r   r   )r   r   r#   r$   ps        r   r&   z#IsomorphicTestableGraph.vhashtriple+   sZ     q 	7AfQi/Qi&)t+jjj66	7s   AAc                     t        |t              syt        |       t        |      k7  ryt        j	                  t        |       t        |            ry| j                         |j                         k(  S )zGraph isomorphism testing.FT)r   r   lenlist__eq__r   r   Gs     r   r.   zIsomorphicTestableGraph.__eq__4   sW    !45Y#a& [[dT!W-!!#q'888r   c                 &    | j                  |       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      s0    7!
<=
79"r   r   c                  f   dd l } ddlm} d} ||      }|j                  ddddd	
       |j                  ddddg dd       |j	                         \  }}g }i }|j
                  rEt               j                  | j
                  |j                        }|j                  |       d||<   |D ]=  }	t               j                  |	|j                        }|j                  |       |	||<   ? t               }
t        |d      D ]*  \  }}||f|
vs||f|
vs||k(  rJ ||   d||           y )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   sa   %>E	E	"BMM&   MM30  	 mmoOWdFK}}')//		'BUBU/Ve&E  ')//7;N;N/OeE  eG&vq1 F7*/?w/NV# F#F#& #r   __main__N)	r6   rdflibr   r   	itertoolsr   r   r]   r3   r	   r   r   <module>ra      s<   
   "5"e 5"p*Z zF r   