
    4Ysh?                     P   d Z ddlmZ ddlmZ ddlmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ ddlmZmZmZ ddl m!Z!m"Z"m#Z#m$Z$m%Z% e	e
eeeeeeeeeehZ& G d d	e'      Z( e(d      Z)d
Z* G d de+      Z, edd      Z-e)e)e)e)de)ddfe-j\                  _/        y)zQ
Implementation of the JSON-LD Context structure. See:

    http://json-ld.org/

    )
namedtuple)RDF   )BASE	CONTAINERCONTEXTGRAPHIDIMPORTINCLUDEDINDEXJSONLANGLISTNESTNONEPREFIX	PROPAGATE	PROTECTEDREVSETTYPEVALUEVERSIONVOCAB)INVALID_REMOTE_CONTEXTRECURSIVE_CONTEXT_INCLUSIONINVALID_CONTEXT_ENTRY)source_to_jsonurljoinurlsplit	split_irinorm_urlc                       e Zd Zy)DefinedN)__name__
__module____qualname__     /var/www/sten-cake5-migrate2.hellocrow.space/lexinfo-master/env/lib/python3.12/site-packages/rdflib/plugins/shared/jsonld/context.pyr%   r%   0   s    r*   r%   ):/?#[]@c                      e Zd Zd.dZed        Zej                  d        Zd/dZd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z ed       Z ed       Z ed       Z ed       Z ed       Z ed       Z ed       ZeedededdfdZdeddfdZ d Z!d  Z"d! Z#d/d"Z$d# Z%d$ Z&d0d%Z'd& Z(	 d1d'Z)d( Z*d0d)Z+d2d*Z,d1d+Z-d, Z.d- Z/y)3ContextNc                     |xs d| _         d | _        d | _        || _        || _        i | _        i | _        i | _        i | _        d| _	        d | _
        d| _        i | _        |r| j                  |       y y )Ng      ?FT)versionlanguagevocabbasedoc_baseterms_alias_lookup	_prefixesactiveparent	propagate_context_cacheload)selfsourcer9   r6   s       r+   __init__zContext.__init__;   sv    ~#
	
 IIf r*   c                     | j                   S N)_baserD   s    r+   r9   zContext.baseM   s    zzr*   c                     |r|j                  d      }|dkD  r|d| }t        | d      r|| j                  |      n|| _        |rdt	        |      dd z  | _        y d | _        y )Nr/   r   rI   z%s://%s   )findhasattrresolve_irirI   r!   _basedomain)rD   r9   
hash_indexs      r+   r9   zContext.baseQ   st    3JBAj) g&4+; T" 	

 ?C9x~a'::r*   c                 ^    | j                   du r| j                  n| }|j                  ||      S NF)rA   r@   _subcontext)rD   rE   rA   r@   s       r+   
subcontextzContext.subcontext^   s+     $% 7T!!&)44r*   c                 L   t        | j                        }||_        | |_        | j                  |_        | j
                  |_        | j                  |_        | j                  |_        | j                  j                         D ci c]  \  }}||d d   c}}|_        | j                  j                         |_
        | j                  j                         |_        | j                  j                         |_        | j                  |_        |j                  |       |S c c}}w )N)r6   )r4   r6   rA   r@   r7   r8   r9   r:   r<   itemsr;   copyr=   r>   rB   rC   )rD   rE   rA   ctxkls         r+   rU   zContext._subcontextc   s    dll+!
}}JJ	99}}*.++*;*;*=>$!Qa1g>
JJOO%	ll'')++-!00
 ?s   D c                 t    d | _         d | _        i | _        i | _        i | _        i | _        d| _        d| _        y )NFT)r7   r8   r;   r<   r=   r>   r?   rA   rJ   s    r+   _clearzContext._clears   s:    

r*   c                 h    |r/|j                   t        ur| j                  |j                   d      S | S )NTrA   )contextUNDEFrU   )rD   terms     r+   get_context_for_termzContext.get_context_for_term}   s/    DLL-##DLLD#AAr*   c                 z   | j                   dk\  rt        |t              r| j                  |      nd }t        |t              s|r|gng }|D ]!  }| j
                  j                  |      }|s! n d }|r-|j                  r!| j                  |j                  d      }|r|S | j                  du r| j                  S | S )N皙?Fr`   )r6   
isinstancedictget_typelistr;   getra   rV   rA   r@   )rD   nodertyperttypetermrV   s         r+   get_context_for_typezContext.get_context_for_type   s    <<3+5dD+ADMM$'tEeT*#(b  ::>>"- 
  H,,!__X-=-=_O
%%"nn5t{{?4?r*   c                 .    | j                  |t              S rH   )_getr
   rD   objs     r+   get_idzContext.get_id   s    yyb!!r*   c                 .    | j                  |t              S rH   )rr   r   rs   s     r+   ri   zContext.get_type       yyd##r*   c                 .    | j                  |t              S rH   )rr   r   rs   s     r+   get_languagezContext.get_language   rw   r*   c                 .    | j                  |t              S rH   )rr   r   rs   s     r+   	get_valuezContext.get_value       yye$$r*   c                 .    | j                  |t              S rH   )rr   r	   rs   s     r+   	get_graphzContext.get_graph   r|   r*   c                 .    | j                  |t              S rH   )rr   r   rs   s     r+   get_listzContext.get_list   rw   r*   c                 .    | j                  |t              S rH   )rr   r   rs   s     r+   get_setzContext.get_set       yyc""r*   c                 .    | j                  |t              S rH   )rr   r   rs   s     r+   get_revzContext.get_rev   r   r*   c                     | j                   j                  |g       D ]  }||v s|j                  |      c S  |j                  |      S rH   )r<   rk   )rD   rt   keyaliass       r+   rr   zContext._get   sE    [[__S"- 	&E|wwu~%	& wws|r*   c                 6    | j                  |      D ]  }|c S  y rH   )get_keysrD   r   r   s      r+   get_keyzContext.get_key   s    ]]3' 	EL	r*   c              #   `   K   || j                   v r| j                   |   D ]  }|  | y wrH   )r<   r   s      r+   r   zContext.get_keys   s4     $++S) 	s   ,.c                 ,    | j                  t              S rH   )r   r   rJ   s    r+   <lambda>zContext.<lambda>       T\\$%7 r*   c                 ,    | j                  t              S rH   )r   r
   rJ   s    r+   r   zContext.<lambda>   s    4<<#3 r*   c                 ,    | j                  t              S rH   )r   r   rJ   s    r+   r   zContext.<lambda>   r   r*   c                 ,    | j                  t              S rH   )r   r   rJ   s    r+   r   zContext.<lambda>       dll5&9 r*   c                 ,    | j                  t              S rH   )r   r   rJ   s    r+   r   zContext.<lambda>   r   r*   c                 ,    | j                  t              S rH   )r   r   rJ   s    r+   r   zContext.<lambda>   s    DLL$5 r*   c                 ,    | j                  t              S rH   )r   r	   rJ   s    r+   r   zContext.<lambda>   r   r*   Fc                 d   | j                   dk  s|	't        |t              xr |j                  t              }	| j                  |      sy | j                   dk\  r*| j                  j                  |      }|r|j                  ry t        |t        t        t        f      rt        |      }nt        |g      }t        |||||||||	|

      }|| j                  |<   t        t        t        fD ]  }||v s n t         }|| j"                  ||xs |||f<   |j$                  du r|| j&                  |<   y y )Nrf   T)r6   rg   strendswithURI_GEN_DELIMS_accept_termr;   rk   	protectedrj   settupleTermr   r   r   rb   r=   prefixr>   )rD   nameidrefcoercion	containerindexr7   reversera   r   r   existingrc   container_keys                 r+   add_termzContext.add_term   s,    <<#s+N~0NF  &<<3zz~~d+HH..i$U!34IIYK(I
  

4"D#. 	"M	)	" "MNReX1='JK;;$$(DNN5! r*   c                    | j                   }||}|t        ur|r|j                  ||||f      }|r|S |t        ur|j                  ||t        |f      }|r|S |r|j                  ||||f      }|rJ|S |r!|j                  |t        t        |f      }|r'|S |j                  ||xs t        t        |f      }|r|S |j                  |t        t        |f      S rH   )r=   rb   rk   r   r   )rD   r   r   r   r7   r   lufounds           r+   	find_termzContext.find_term   s     \\H5 YFFE8Y@AE5 FFE8UG<=EFFE8Y@AEFFE5$89EFFE8#4uc7CDEvvueUG455r*   c                 x    | j                  |d      }| j                  |      r|S d|v ry| j                  |      S )NF  )expandisblankrP   )rD   curie_or_iriiris      r+   resolvezContext.resolve  s>    kk,.<<J#:$$r*   c                 .    t        | j                  |      S rH   )r#   rI   )rD   r   s     r+   rP   zContext.resolve_iri&  s    

C((r*   c                 $    |j                  d      S )Nz_:)
startswith)rD   refs     r+   r   zContext.isblank)  s    ~~d##r*   c                    t        |t              s|S | j                  |      sy|r)| j                  j	                  |      }|r|j
                  S | j                  |      \  }}}|dk(  r|S |D| j                  j	                  |      }|rG|j                  r;|j
                  r/|j
                  |z   S |r|r| j                  r| j                  |z   S y | j                  |      S )Nr   _)
rg   r   r   r;   rk   id_prep_expandr   r8   rP   )rD   term_curie_or_iri	use_vocabrc   is_termpfxlocalnss           r+   r   zContext.expand,  s    +S1$$  !23::>>"34Dww"//0ABe#:$$?$BbiiBEEuuu}$zzzz$555 122r*   c                 D   t        t        |            \  }}| j                  j                  |      }|rdj	                  ||f      S | j
                  rLt        |      | j
                  k(  ry|j                  | j                        r|t        | j                        d  S |S )Nr,   r   )	r"   r   r>   rk   joinrI   r   rQ   len)rD   r   r   r   r   s        r+   
shrink_irizContext.shrink_iriG  s    SX&Dnn  $88S$K((ZZ3x4::% 0 013t//0233
r*   c                     t        |      }| j                  |      }|r|j                  S t        |      \  }}|| j                  k(  r|S | j
                  j                  |      }|rdj                  ||f      S |S Nr,   )r   r   r   r"   r8   r>   rk   r   )rD   r   rc   r   r   r   s         r+   	to_symbolzContext.to_symbolS  ss    #h~~c"99S>DKnn  $88S$K((
r*   c                     d| _         g }t        |t              r|n|g}|xs
 t               }| j	                  ||||       |D ]+  \  }}|| j                          | j                  |||       - y )NT)r?   rg   rj   r   _prep_sourcesr^   _read_source)rD   rE   r9   referenced_contextssources
source_urls         r+   rC   zContext.load`  sy    %fd3&1:SU42EF") 	KJ~!!&*6IJ		Kr*   c                     | j                   dk  ry|r1t        |      dkD  r#|d   dk(  r|d   j                         r|t        v S y)Nrf   Tr   r   r2   )r6   r   isalnum	NODE_KEYS)rD   r   s     r+   r   zContext._accept_terml  sC    <<#3s8a<CFcMc!fnn6F)##r*   c                    |D ]  }|}t        |t              r8|}|xs | j                  }| j                  |||      }	|	=|rt	        ||      }|	}t        |t
              r&t        |v r|t           }t        |t              r|n|g}t        |t              r| j                  |||||       |j                  ||f        y rH   )
rg   r   r:   _fetch_contextr    rh   r   rj   r   append)
rD   r9   inputsr   r   in_source_urlrE   r   source_doc_basenew_ctxs
             r+   r   zContext._prep_sourcest  s      	5F&J&#&#
"&"7$----O-@ ?&
C$F&$'f$#G_F'1&$'?VfXF&$'""&'+>
 
F343	5r*   c                     t        ||      }||v rt        |j                  |       || j                  v r| j                  |   S t	        |      }|rt
        |vrt        || j                  |<   |S rH   )r    r   addrB   r   r   r   )rD   rE   r9   r   r   s        r+   r   zContext._fetch_context  sy    T6*
,,--
+,,,&&z22
+gV+((*0J'r*   c                    |j                  t              }|rqt        |t              st        | j                  || j                  |xs
 t                     }t        |t              st        |t           }|j                  |       |}|j                  t        | j                        | _        |j                  t        | j                        | _        |j                  t        d      }|j!                         D ]{  \  }}|t        t        t        t        hv r|t"        k(  rt        |t$              r|| _        @|t(        k(  r|| _        Q|t,        k(  r|r]|r`|| _        h| j/                  ||||       } y rT   )rk   r   rg   r   r   r   r9   r   rh   r   updater   r8   r   r6   r   rX   r   boolrA   r   r7   r   
_read_term)	rD   rE   r   r   importsimportedr   r   values	            r+   r   zContext._read_source  s'   **V$gs+++**$7$@35H h-++(HOOF#FZZtzz2
zz'4<<8JJy%0	 ,,. 	?JCugvy99	!j&=!& %!' %DIUI>	?r*   c                 V   d }t        |t              r|j                  t              }|j                  t        |      }|j                  t
        t              }|r%|t        t
        t        fvr| j                  ||      }|xs |j                  t        t              }|t
        k(  r t        t        j                        }t        }nM|t        ur| j                  ||      }n2d|v r| j                  ||      }n| j                  r| j                  |z   }|j                  t        t              }| j                  ||||j                  t         t              |j                  t"        t              |j                  t$        t              t'        |      ||j                  t(              |
       nHt        |t              r$| j+                  |      sy | j                  ||      }| j                  |||       |t,        v r,| j.                  j1                  |g       j3                  |       y y )Nr,   )r   )rg   rh   rk   r   r   r   rb   r
   r   _rec_expandr   r   typer8   r   r   r   r   r   r   r   r   r   r<   
setdefaultr   )	rD   rE   r   dfnr   r   revr   ra   s	            r+   r   zContext._read_term  s   c4 ''#,C	95IwwtU+HHRu,==++FH=-3772u-E}CHH e#((7((6

T)gggu-GMM	5)u%e$S	#   #s#((-((5MM$M;IKK""5"-44T: r*   c                    ||k(  s|t         v r|S | j                  |      \  }}}|r\| j                  ||      }|=|dz   | j                  k(  r|S | j                  j                  |      }|r|j                  }||}n;||z   }n5| j                  ||      xs |}d|vr| j                  r| j                  |z   S | j                  |||      S r   )r   r   _get_source_idr8   r;   rk   r   r   )	rD   rE   exprprevr   r   nxtr   rc   s	            r+   r   zContext._rec_expand  s    4<49,K --d3c%%fc2C{9

*K::>>#.D"gg{Ci%%fc29cC#~$**zzC''T22r*   c                 t    d|vrdd |fS |j                  dd      \  }}|j                  d      sd||fS dd |fS )Nr,   Tr   z//F)splitr   )rD   r   r   r   s       r+   r   zContext._prep_expand  sR    d?t##ZZQ'
U%#u$$$$$r*   c                     |j                  |      }|+| j                  j                  |      }|r|j                  }|S t        |t              r|j                  t
              }|S rH   )rk   r;   r   rg   rh   r
   )rD   rE   r   rc   r   s        r+   r   zContext._get_source_id  sW    zz#<**..%Cvv  d#88B<Dr*   )NNN)T)NNrH   )F)0r&   r'   r(   rF   propertyr9   setterrV   rU   r^   rd   rp   ru   ri   ry   r{   r~   r   r   r   rr   r   r   lang_keyid_keytype_key	value_keylist_keyrev_key	graph_keyrb   r   r   r   rP   r   r   r   r   rC   r   r   r   r   r   r   r   r   r)   r*   r+   r4   r4   :   s[   $   
[[
M 
M5
 
@("$$%%$## 78H34F78H9:I78H56G9:I 5)p #edE6B%)$36

K IM5>"?B-;^34%	r*   r4   r   zNid, name, type, container, index, language, reverse, context,prefix, protectedFN)0__doc__collectionsr   rdflib.namespacer   keysr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   errorsr   r   r   utilr   r    r!   r"   r#   r   intr%   rb   r   objectr4   r   __new____defaults__r)   r*   r+   <module>r     s    #       0 
 I H B$dD#sD%QUV		c 	 	
 5ff fR 
W #E5%ueT r*   