
    4YshU                       d Z ddlZddlmZmZmZmZmZmZm	Z	 ddl
mZ ddlmZ ddlmZmZ ddlmZ ddlmZ dd	lmZ ddlZ ej.                  e      Z	 g d
Z G d d      Zdeee ed      ddZd Zd Zd Zd Z dFdZ!d Z"d Z# G d d      Z$ G d de%      Z& ed      Z' G d de&      Z( G d d e(      Z)d! Z*d" Z+ G d# d$e      Z, e- ed%            j]                  ej^                  ej`                  ejb                  ejd                  ejf                  ejh                  ejj                  ejl                  ejn                  ejp                  ejr                  ejt                  g      Z;d& Z<d' Z= G d( d)e>      Z?dGd*Z@ G d+ d,e(      ZA G d- d.e%      ZB G d/ d0eBeA      ZCejr                  ejp                  gZD G d1 d2      ZE G d3 d4      ZF G d5 d6eBeA      ZGd7 ZH G d8 d9eA      ZI ed:       ZJ ed;       ZK ed<       ZL ed=       ZM ed>       ZN ed?       ZOd@ZP G dA dBe(      ZQi fdCZRdD ZSedEk(  r eS        yy)Ha  RDFLib Python binding for OWL Abstract Syntax

see: http://www.w3.org/TR/owl-semantics/syntax.html
     http://owl-workshop.man.ac.uk/acceptedLong/submission_9.pdf

3.2.3 Axioms for complete classes without using owl:equivalentClass

Named class description of type 2 (with owl:oneOf) or type 4-6
(with owl:intersectionOf, owl:unionOf or owl:complementOf

Uses Manchester Syntax for __repr__

>>> exNs = Namespace('http://example.com/')
>>> namespace_manager = NamespaceManager(Graph())
>>> namespace_manager.bind('ex', exNs, override=False)
>>> namespace_manager.bind('owl', OWL, override=False)
>>> g = Graph()
>>> g.namespace_manager = namespace_manager

Now we have an empty graph, we can construct OWL classes in it
using the Python classes defined in this module

>>> a = Class(exNs.Opera, graph=g)

Now we can assert rdfs:subClassOf and owl:equivalentClass relationships
(in the underlying graph) with other classes using the 'subClassOf'
and 'equivalentClass' descriptors which can be set to a list
of objects for the corresponding predicates.

>>> a.subClassOf = [exNs.MusicalWork]

We can then access the rdfs:subClassOf relationships

>>> print(list(a.subClassOf))
[Class: ex:MusicalWork ]

This can also be used against already populated graphs:

>>> owlGraph = Graph().parse(str(OWL)) #doctest: +SKIP
>>> namespace_manager.bind('owl', OWL, override=False) #doctest: +SKIP
>>> owlGraph.namespace_manager = namespace_manager #doctest: +SKIP
>>> list(Class(OWL.Class, graph=owlGraph).subClassOf) #doctest: +SKIP
[Class: rdfs:Class ]

Operators are also available. For instance we can add ex:Opera to the extension
of the ex:CreativeWork class via the '+=' operator

>>> a #doctest: +SKIP
Class: ex:Opera SubClassOf: ex:MusicalWork
>>> b = Class(exNs.CreativeWork, graph=g)
>>> b += a
>>> print(sorted(a.subClassOf, key=lambda c:c.identifier)) #doctest: +SKIP
[Class: ex:CreativeWork , Class: ex:MusicalWork ]

And we can then remove it from the extension as well

>>> b -= a
>>> a #doctest: +SKIP
Class: ex:Opera SubClassOf: ex:MusicalWork

Boolean class constructions can also  be created with Python operators.
For example, The | operator can be used to construct a class consisting of a
owl:unionOf the operands:

>>> c =  a | b | Class(exNs.Work, graph=g)
>>> c #doctest: +SKIP
( ex:Opera OR ex:CreativeWork OR ex:Work )

Boolean class expressions can also be operated as lists (using python list
operators)

>>> del c[c.index(Class(exNs.Work, graph=g))]
>>> c #doctest: +SKIP
( ex:Opera OR ex:CreativeWork )

The '&' operator can be used to construct class intersection:

>>> woman = Class(exNs.Female, graph=g) & Class(exNs.Human, graph=g)
>>> woman.identifier = exNs.Woman
>>> woman #doctest: +SKIP
( ex:Female AND ex:Human )
>>> len(woman)
2

Enumerated classes can also be manipulated

>>> contList = [Class(exNs.Africa, graph=g), Class(exNs.NorthAmerica, graph=g)]
>>> EnumeratedClass(members=contList, graph=g) #doctest: +SKIP
{ ex:Africa ex:NorthAmerica }

owl:Restrictions can also be instantiated:

>>> Restriction(exNs.hasParent, graph=g, allValuesFrom=exNs.Human) #doctest: +SKIP
( ex:hasParent ONLY ex:Human )

Restrictions can also be created using Manchester OWL syntax in 'colloquial'
Python
>>> exNs.hasParent | some | Class(exNs.Physician, graph=g) #doctest: +SKIP
( ex:hasParent SOME ex:Physician )

>>> Property(exNs.hasParent,graph=g) | max | Literal(1) #doctest: +SKIP
( ex:hasParent MAX 1 )

>>> print(g.serialize(format='pretty-xml')) #doctest: +SKIP

    N)BNodeLiteral	NamespaceRDFRDFSURIRefVariable)Graph)
Collection)OWLXSD)NamespaceManager)
Identifier)first)$nsBindsACE_NSCLASS_RELATIONSsomeonlymaxminexactlyvaluePropertyAbstractSyntax
AllClassesAllDifferentAllPropertiesAnnotatableTermsBooleanClassCallable	CastClassClassClassNamespaceFactoryclassOrIdentifierclassOrTermCommonNSBindingsComponentTermsDeepClassClearEnumeratedClassgenerateQNameGetIdentifiedClasses
IndividualMalformedClassmanchesterSyntaxOntologyOWLRDFListProxyPropertypropertyOrIdentifierRestrictiontermDeletionDecoratorc                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)Infixc                     || _         y Nfunction)selfr:   s     v/var/www/sten-cake5-migrate2.hellocrow.space/lexinfo-master/env/lib/python3.12/site-packages/rdflib/extras/infixowl.py__init__zInfix.__init__   	         c                      t        | |fd      S )Nc                 &    |j                  ||       S r8   r9   xr;   others      r<   <lambda>zInfix.__ror__.<locals>.<lambda>       t}}UA7N r?   r6   r;   rD   s     r<   __ror__zInfix.__ror__       DNOOr?   c                 $    | j                  |      S r8   r9   rH   s     r<   __or__zInfix.__or__       }}U##r?   c                      t        | |fd      S )Nc                 &    |j                  ||       S r8   r9   rB   s      r<   rE   z#Infix.__rlshift__.<locals>.<lambda>   rF   r?   rG   rH   s     r<   __rlshift__zInfix.__rlshift__   rJ   r?   c                 $    | j                  |      S r8   r9   rH   s     r<   
__rshift__zInfix.__rshift__   rM   r?   c                 &    | j                  ||      S r8   r9   )r;   value1value2s      r<   __call__zInfix.__call__   s    }}VV,,r?   N)	__name__
__module____qualname__r=   rI   rL   rP   rR   rV    r?   r<   r6   r6      s"    !P$P$-r?   r6   z$http://www.w3.org/2004/02/skos/core#z$http://www.w3.org/2000/10/swap/list#z http://purl.org/dc/elements/1.1/)skosrdfrdfsowllistdcc                 d    | j                  t        |            \  }}}dj                  ||g      S N:)compute_qnamer$   join)graphuriprefix	localNames       r<   r*   r*      s3    "001B31GHFC88VY'((r?   c                 x    t        | t              r| j                  S t        | t        t        t
        f      sJ | S r8   )
isinstancer"   
identifierr   r   r   things    r<   r%   r%      s4    %%&%!9:::r?   c                     t        | t        t        f      r| j                  S t        | t        t
        f      s
J d| z         | S )Nz8Expecting a Class, Property, URIRef, or BNode.. not a %s)rk   r1   r"   rl   r   r   rm   s    r<   r$   r$      sG    %(E*+%&%1 	
FN	
1 r?   c                 b    t        | t              r| j                  S t        | t              sJ | S r8   )rk   r1   rl   r   rm   s    r<   r2   r2      s-    %"%(((r?   c                 
   | J |r|r%t        |       }| D cg c]  }t        |       }}n8t        t        |             }t        |       D cg c]  }t        |       }}|t        j                  k(  rg }g }|D ]5  }t        |t              r|j                  |       %|j                  |       7 |rfd}	t        |      dkD  r"ddj                  t        |	|            z   dz   }
nt        |d         }
|rAt        |
      dz   dj                  |D cg c]  }t        t        |             c}      z   S |
S ddj                  |D cg c]  }t        |       c}      z   dz   S |t        j                  k(  r.dd	j                  |D cg c]  }t        |       c}      z   dz   S |t        j                  k(  r.d
dj                  |D cg c]  }t        |       c}      z   dz   S |t        j                  k(  sJ t        j                  j!                  | t"        j$                        v rt'        j!                  | t        j(                              d   }j+                  |      \  }
}}dj                  |
|g      }t-        j!                  |t.        j0                              }|rd|z  }j!                  | t        j2                        D ]  }d|dt        |      dc S  j!                  | t        j4                        D ]  }d|dt        |      dc S  j!                  | t        j6                        D ]  }d|dt        |      dc S  t        j8                  dt        j:                  dt        j<                  di}j?                  | t'        |jA                               df      D ]  \  }}}d|d||   d|dc S  t'        j!                  | t        j                              }|rdt        |d         z  S dj                  tB        D cg c]  }d|dtB        |   d c}      }|dz   dz   }tE        d      | i}jG                  |d|      D ]%  \  }}t        | t              rt        ||       c S  	 j+                  |       \  }
}}dj                  |
|g      } t-        tO        | "      j0                        }|r|S | S c c}w c c}w c c}w c c}w c c}w c c}w c c}w # tH        $ r- t        | tJ              r| jM                         cY S d!| z   dz   cY S w xY w)#z
    Core serialization
    Nc                 T    j                  |       \  }}}dj                  ||g      S rb   )rd   re   )rC   rh   rg   ri   stores       r<   castToQNamez%manchesterSyntax.<locals>.castToQName  s.    -2-@-@-C*FC88VY$788r?      z( z AND  )r   z THAT z OR z{  z }subject	predicaterc   z'%s'z ONLY z VALUE z SOME MAXMINEQUALSz
( NOT %s )
zPREFIX z: <>z6
SELECT ?p ?bool WHERE {?class a owl:Class; ?p ?bool .z?bool rdf:first ?foo }z?classsparql)	processorinitBindingsboolean<rf   )(iterr.   r   r   intersectionOfrk   r   appendlenre   mapstrunionOfoneOfcomplementOfr3   objectsr   typer_   
onPropertyrd   r   r   labelallValuesFromhasValuesomeValuesFrommaxCardinalityminCardinalitycardinalitytriples_choiceskeysr   r	   query	Exceptionr   n3r"   )!rn   rs   r   transientListliveChildrenchildchildren	childListnamedrt   rh   rC   cproprg   ri   
propStringr   	onlyClassval	someClass
cardLookupspocomplkprologqstrinitbboolPropcolqnames!    `                               r<   r.   r.      s    ;LDIJ5(6JHJ
5% 89L<Fue<T38 .H  c(((IE% ,eV,LL'$$U+	,
 9 u:>!GLL[%1H$IIDPF-eAh>FF"#!,,FOPS!1!U!;<P "MgllH+EqCF+EFFMM#&++x&@!s1v&@AADHH		!#((H#=qCF#=>>EEc.....	EMM%388ML	LEMM%3>>MJKAN!&!4!4T!:YXXvy12
emmDDJJmGH%Ju@Q@QR 	WI'13CIu3UVV	W==#,,=G 	RC(24DS%4PQQ	Ru@R@RS 	WI'13CIu3UVV	W OOX


 ,,eT*//:K5Ld-ST 	CGAq!%/ABB	Cu8H8HIJE/a%@AAQAGAJ?QRGH&' 	
 (#U+"[[PU[V 	FMHceV,'UHEE	F	%%*%8%8%?"FCHHfi01E
 eE/556LLo K4 Q ,F&@#=6 R  	%%'xxz!;$$	%sA   S5S:S?
T
T	
T
7T'(T )UUUc              #      K   | j                  t        j                  t        j                        D ]   }t        |t              st	        |       " y wN)rz   object)subjectsr   r   r   r"   rk   r   )rf   r   s     r<   r+   r+   U  s=     ^^chhsyy^A a (Ns   AAAc                       fd}|S )Nc                     | _         | S r8   )property)funcr   s    r<   someFuncz'termDeletionDecorator.<locals>.someFunc\  s    r?   rZ   )r   r   s   ` r<   r4   r4   [  s     Or?   c                       e Zd Zd Zd Zy)TermDeletionHelperc                     || _         y r8   )r   )r;   r   s     r<   r=   zTermDeletionHelper.__init__d  s	    	r?   c                       fd}|S )Nc                 j    | j                   j                  | j                  j                  d f       y r8   )rf   removerl   r   )instr;   s    r<   _removerz-TermDeletionHelper.__call__.<locals>._removerh  s$    JJt		4@Ar?   rZ   )r;   fr   s   `  r<   rV   zTermDeletionHelper.__call__g  s    	B r?   N)rW   rX   rY   r=   rV   rZ   r?   r<   r   r   c  s    r?   r   c                      e Zd ZdZ e       Zd ZddZd Zd Z	d Z
d Zd	 Zd
 Z eej                         d        Z eeee      Zd Zd Z eee      Zd Zd Z eej2                        d        Z eeee      Zy)r,   z
    A typed individual
    c                     | j                   j                  | j                  d d f      D ]  }|j                  |        y r8   )factoryGraphtriplesrl   addr;   rf   facts      r<   	serializezIndividual.serializeu  s8    %%--td.KL 	DIIdO	r?   Nc                 B   |d uxr |xs
 t               | _        || j                  | _        n|| _        d | _        t        | j                  t               sC	 | j                  j                  | j                        \  }}}dj                  ||g      | _        y y #  Y y xY wrb   )	r   _Individual__identifierr   rf   r   rk   rl   rd   re   )r;   rl   rf   rh   rg   ri   s         r<   r=   zIndividual.__init__y  s    &d2AzLUW=**DJDJ
$//51)-)A)A$//)R&Y XXvy&9:
 2s   AB Bc                 T    | j                   j                  d d | j                  f       y r8   rf   r   rl   r;   s    r<   clearInDegreezIndividual.clearInDegree  s    

4t78r?   c                 T    | j                   j                  | j                  d d f       y r8   r   r   s    r<   clearOutDegreezIndividual.clearOutDegree  s    

4??D$78r?   c                 D    | j                          | j                          y r8   )r   r   r   s    r<   deletezIndividual.delete  s    r?   c                     | j                   j                  d d | j                  f      D ]-  \  }}}| j                   j                  ||t	        |      f       / | j                          y r8   )rf   r   rl   r   r$   r   r;   rD   r   r   r   s        r<   replacezIndividual.replace  sW    zz))4t*GH 	=GAq!JJNNAq"3E":;<	=r?   c              #      K   | j                   j                  | j                  t        j                        D ]  }|  y wNrx   )rf   r   rl   r   r   r;   _ts     r<   	_get_typezIndividual._get_type  s6     **$$T__$Q 	BH	   A Ac                 r   |sy t        |t        t        f      r@| j                  j	                  | j
                  t        j                  t        |      f       y |D ]Y  }t        |t        t        f      sJ | j                  j	                  | j
                  t        j                  t        |      f       [ y r8   )	rk   r,   r   rf   r   rl   r   r   r$   )r;   kindr   s      r<   	_set_typezIndividual._set_type  s    dZ45JJNNDOOSXX7H7NOP R!!j*%=>>>

;LQ;OPQRr?   c                      y)z
        >>> g = Graph()
        >>> b=Individual(OWL.Restriction,g)
        >>> b.type = RDF.Resource
        >>> len(list(b.type))
        1
        >>> del b.type
        >>> len(list(b.type))
        0
        NrZ   r   s    r<   _delete_typezIndividual._delete_type       	r?   c                     | j                   S r8   )r   r   s    r<   _get_identifierzIndividual._get_identifier  s       r?   c           
         |sJ || j                   k7  ra| j                  j                  | j                   d d f      D cg c]
  \  }}}||f }}}}| j                  j                  d d | j                   f      D cg c]
  \  }}}||f }}}}|D ]-  \  }}| j                  j                  | j                   ||f       / |D ]-  \  }	}| j                  j                  |	|| j                   f       / || _         | j                  j	                  |D cg c]  \  }}|||| j                  f c}}       | j                  j	                  |D 	cg c]  \  }	}|	||| j                  f c}}	       t        |t              s9	 | j                  j                  |      \  }
}}dj                  |
|g      | _	        y y c c}}}w c c}}}w c c}}w c c}}	w #  Y y xY wrb   )
r   rf   r   r   addNrk   r   rd   re   r   )r;   ir   r   r   oldStmtsOut
oldStmtsInp1o1s1rh   rg   ri   s                r<   _set_identifierzIndividual._set_identifier  s   q!!!  $zz1143D3DdD2QR Aq! AK   $zz114t?P?P2QR Aq! AJ  & ?B

!!4#4#4b""=>?$ ?B

!!2r4+<+<"=>? !DJJOO;ORaR4OPJJOO:NRb"a4NO!U#)-)A)A!)D&Y XXvy&9:
 $ PN
s$   G  GG
G
7G Gc              #      K   | j                   j                  | j                  t        j                        D ]  }|  y wr   )rf   r   rl   r   sameAsr   s     r<   _get_sameAszIndividual._get_sameAs  s6     **$$T__

$S 	BH	r   c                 l   t        |t        t        f      r@| j                  j	                  | j
                  t        j                  t        |      f       y |D ]Y  }t        |t        t        f      sJ | j                  j	                  | j
                  t        j                  t        |      f       [ y r8   )	rk   r,   r   rf   r   rl   r   r   r$   )r;   termr   s      r<   _set_sameAszIndividual._set_sameAs  s     dZ45JJNNDOOSZZ9J49PQR T!!j*%=>>>

=Nq=QRSTr?   c                      y r8   rZ   r   s    r<   _delete_sameAszIndividual._delete_sameAs      r?   NN)rW   rX   rY   __doc__r
   r   r   r=   r   r   r   r   r   r   r   r   r   r   r   r   r   rl   r   r   r   r   r   rZ   r?   r<   r,   r,   n  s     7L99
R ! " Iy,7D!2 /?;JT 

# $ k;?Fr?   r,   z'http://attempto.ifi.uzh.ch/ace_lexicon#c                        e Zd ZdZd fd	Zd Zd Zd Zd Z e	e
j                        d        Z eeee      Zd Zd	 Z e	e
j                         d
        Z eeee      Zd Zd Z e	e
j(                        d        Z eeee      Z xZS )r   zC
    Terms in an OWL ontology with rdfs:label and rdfs:comment
    c                     t         t        |   ||       |rI| j                          | j                  | j                  |      fg| j                  _        |r	|g| _        y y y r8   )	superr   r=   setupACEAnnotationsrl   handleAnnotation	PN_sgPropextentr   )r;   rl   rf   nameAnnotationnameIsLabel	__class__s        r<   r=   zAnnotatableTerms.__init__  sb    .z5A$$&$"7"7"GH%DNN! ,-
  r?   c                 <    t        |t              r|S t        |      S r8   )rk   r   )r;   r   s     r<   r  z!AnnotatableTerms.handleAnnotation  s     g.s@GCL@r?   c                    | j                   j                  dt        d       t        t        j                  t
        j                  | j                         | _        t        t        j                  t
        j                  | j                         | _	        t        t        j                  t
        j                  | j                         | _        t        t        j                  t
        j                  | j                         | _        t        t        j                  t
        j                  | j                         | _        t        t        j                   t
        j                  | j                         | _        y )NaceFoverride)baseTyperf   )rf   bindr   r1   PN_sgr   AnnotationPropertyr  CN_sg	CN_sgPropCN_pl	CN_plPropTV_sg	TV_sgPropTV_pl	TV_plPropTV_vbg
TV_vbgPropr   s    r<   r  z$AnnotatableTerms.setupACEAnnotations  s    

v6 "LL3#9#9

 "LL3#9#9

 "LL3#9#9

 "LL3#9#9

 "LL3#9#9

 #MMC$:$:$**
r?   c              #      K   | j                   j                  | j                  t        j                        D ]  }|  y wr   )rf   r   rl   r   comment)r;   r  s     r<   _get_commentzAnnotatableTerms._get_comment  s=     zz))OOt|| * 
 	G M	r   c                    |sy t        |t              r7| j                  j                  | j                  t
        j                  |f       y |D ]8  }| j                  j                  | j                  t
        j                  |f       : y r8   )rk   r   rf   r   rl   r   r  )r;   r  r   s      r<   _set_commentzAnnotatableTerms._set_comment#  sa    gz*JJNNDOOT\\7CD C

qABCr?   c                      y r8   rZ   r   s    r<   _del_commentzAnnotatableTerms._del_comment,  r   r?   c              #      K   | j                   j                  | j                  t        j                        D ]  }|  y wr   )rf   r   rl   r   seeAlso)r;   sAs     r<   _get_seeAlsozAnnotatableTerms._get_seeAlso2  s6     **$$T__$U 	BH	r   c                     |sy |D ]8  }| j                   j                  | j                  t        j                  |f       : y r8   )rf   r   rl   r   r%  )r;   seeAlsosr   s      r<   _set_seeAlsozAnnotatableTerms._set_seeAlso6  s6     	?AJJNNDOOT\\1=>	?r?   c                      y r8   rZ   r   s    r<   _del_seeAlsozAnnotatableTerms._del_seeAlso<  r   r?   c              #      K   | j                   j                  | j                  t        j                        D ]  }|  y wr   )rf   r   rl   r   r   )r;   r   s     r<   
_get_labelzAnnotatableTerms._get_labelB  s6     ZZ''4::'V 	EK	r   c                    |sy t        |t              r7| j                  j                  | j                  t
        j                  |f       y |D ]8  }| j                  j                  | j                  t
        j                  |f       : y r8   )rk   r   rf   r   rl   r   r   )r;   r   l_s      r<   
_set_labelzAnnotatableTerms._set_labelF  sa    eZ(JJNNDOOTZZ?@ B

R@ABr?   c                      y)z
        >>> g=Graph()
        >>> b=Individual(OWL.Restriction,g)
        >>> b.label = Literal('boo')
        >>> len(list(b.label))
        1
        >>> del b.label
        >>> len(list(b.label))
        0
        NrZ   r   s    r<   _delete_labelzAnnotatableTerms._delete_labelO  r   r?   )NNF)rW   rX   rY   r   r=   r  r  r  r!  r   r   r  r#  r   r'  r*  r%  r,  r.  r1  r   r3  __classcell__r	  s   @r<   r   r     s    .A
BC % & |\<@G? % & |\<@GB 

# $ Z];Er?   r   c                   l     e Zd ZdZd fd	Zd Zd Zd Z ee	d         d        Z
 eeee
      Z xZS )	r/   zThe owl ontology metadatac                 b   t         t        |   ||       |xr |xs g | _        |xr |xs g | _        | j
                  t        j                  t        j                  f| j                  vrE| j                  j                  | j
                  t        j                  t        j                  f       y y r8   )r  r/   r=   importsr  rl   r   r   r   rf   r   )r;   rl   r8  r  rf   r	  s        r<   r=   zOntology.__init__c  s~    h&z59*70b*70bOOSXXs||4DJJFJJNNDOOSXXs||DE Gr?   c                 p    | j                   j                  | j                  t        j                  |f       y r8   )rf   setrl   r   versionInfo)r;   versions     r<   
setVersionzOntology.setVersionj  s!    

'BCr?   c              #   z   K   | j                   j                  | j                  t        d         D ]  }|  y w)Nr8  rx   )rf   r   rl   r   )r;   r^   s     r<   _get_importszOntology._get_importsm  s=     ::%%OOs9~ & 
 	C I	s   9;c                 v    |sy |D ]1  }| j                   j                  | j                  t        d   |f       3 y )Nr8  )rf   r   rl   r   )r;   rD   r   s      r<   _set_importszOntology._set_importss  s8     	AAJJNNDOOS^Q?@	Ar?   r8  c                      y r8   rZ   r   s    r<   _del_importszOntology._del_importsy  r   r?   )NNNN)rW   rX   rY   r   r=   r=  r?  rA  r   r   rC  r   r8  r4  r5  s   @r<   r/   r/   `  sJ    #FDA I' ( |\<@Gr?   r/   c              #      K   t               }| j                  t        j                  t        j
                        D ]%  }||vs|j                  |       t        |       ' y wr   )r:  r   r   r   r   r"   r   )rf   prevClassesr   s      r<   r   r     sN     %K^^chhsyy^A KOOA(Ns   AA%!A%c              #   V  K   t               }| j                  d t        j                  t        j
                  t        j                  t        j                  t        j                  t        j                  t        j                  t        j                  gf      D ]  \  }}}|t        j
                  t        j                  t        j                  t        j                  fv rt        j                  }nt        j                  }||vsm|j                  |       t        || |        y w)Nrf   r  )r:  r   r   r   r   SymmetricPropertyFunctionalPropertyInverseFunctionalPropertyTransitivePropertyDatatypePropertyObjectPropertyr  r   r1   )rf   	prevPropsr   r   r   bTypes         r<   r   r     s     I((HH%%&&--&&$$""&&	
 ;1a !!))""	
 
 &&E((EIMM!1EE::5;s   DD)$D)c                        e Zd Zd ZddZd Zy)r#   c                 0    t        t        | |z               S r8   )r"   r   r;   names     r<   r   zClassNamespaceFactory.term  s    VD4K())r?   Nc                 $    | j                  |      S r8   )r   )r;   keydefaults      r<   __getitem__z!ClassNamespaceFactory.__getitem__  s    yy~r?   c                 R    |j                  d      rt        | j                  |      S )N__)
startswithAttributeErrorr   rR  s     r<   __getattr__z!ClassNamespaceFactory.__getattr__  s"    ??4   99T?"r?   r8   )rW   rX   rY   r   rW  r\  rZ   r?   r<   r#   r#     s    *#r?   r#   z0http://www.w3.org/2002/07/owl#resourcePropertiesc              #     K   t         j                  | j                  v r	 t        | t        j
                        } | j
                  j                  | j                  t         j                  t         j                  gdf      D ]<  \  }}}t        |d      }t        |t              rt        |      D ]  }|  9| > yt        | t        j
                        } t        | t              rH| D ]B  }t        |d      }t        |j                  t              rt        |      D ]  }|  ?| D y| j                  D ]5  }t        |j                  t              rt        |      D ]  }|  2| 7 | j
                  j                  t!        |       t"        df      D ]G  \  }}}t        |t              r-t        t        |t        j
                              D ]  }|  D I y#  Y yxY ww)z
    Takes a Class instance and returns a generator over the classes that
    are involved in its definition, ignoring unnamed classes
    NTskipOWLClassMembership)r   r3   r   r!   r,   r   r   rl   r   r   r"   rk   r   r'   r   
subClassOfr$   r   )clsr   r   
innerClsIdinnerCls_c_clsr   s           r<   r'   r'     s    
 #(("	C!8!89C$'$4$4$D$D#"3"3S5G5G!H$O% # 1j !DIj%0,X6 ! ! #N# Z445c<( T$?doou5,T2 ! ! J  NN #h1159,X6 ! ! #N# ++;;"3'$? #1a a',Yq*:Q:Q-RS ! ! #N#'	s   G3BG, ?D-G3,G0.G3c                    d }t        | t        j                        } | j                  D ]
  } ||        | j                  j                  | j                  t        j                  df       | j                  D ]
  } ||        | j                  j                  | j                  t        j                  df       | j                  }|r>| j                  j                  | j                  t        j                  df        ||       t        | t              rR| D ]
  } ||        | j                          | j                  j                  | j                  | j                  df       yy)at  
    Recursively clear the given class, continuing
    where any related class is an anonymous class

    >>> EX = Namespace('http://example.com/')
    >>> namespace_manager = NamespaceManager(Graph())
    >>> namespace_manager.bind('ex', EX, override=False)
    >>> namespace_manager.bind('owl', OWL, override=False)
    >>> g = Graph()
    >>> g.namespace_manager = namespace_manager
    >>> Individual.factoryGraph = g
    >>> classB = Class(EX.B)
    >>> classC = Class(EX.C)
    >>> classD = Class(EX.D)
    >>> classE = Class(EX.E)
    >>> classF = Class(EX.F)
    >>> anonClass = EX.someProp | some | classD #doctest: +SKIP
    >>> classF += anonClass #doctest: +SKIP
    >>> list(anonClass.subClassOf) #doctest: +SKIP
    [Class: ex:F ]
    >>> classA = classE | classF | anonClass #doctest: +SKIP
    >>> classB += classA #doctest: +SKIP
    >>> classA.equivalentClass = [Class()] #doctest: +SKIP
    >>> classB.subClassOf = [EX.someProp | some | classC] #doctest: +SKIP
    >>> classA #doctest: +SKIP
    ( ex:E OR ex:F OR ( ex:someProp SOME ex:D ) )
    >>> DeepClassClear(classA) #doctest: +SKIP
    >>> classA #doctest: +SKIP
    (  )
    >>> list(anonClass.subClassOf) #doctest: +SKIP
    []
    >>> classB #doctest: +SKIP
    Class: ex:B SubClassOf: ( ex:someProp SOME ex:C )

    >>> otherClass = classD | anonClass #doctest: +SKIP
    >>> otherClass #doctest: +SKIP
    ( ex:D OR ( ex:someProp SOME ex:D ) )
    >>> DeepClassClear(otherClass) #doctest: +SKIP
    >>> otherClass #doctest: +SKIP
    (  )
    >>> otherClass.delete() #doctest: +SKIP
    >>> list(g.triples((otherClass.identifier, None, None))) #doctest: +SKIP
    []
    c                 N    t        t        |       t              rt        |        y y r8   )rk   r$   r   r(   )_classs    r<   deepClearIfBNodez(DeepClassClear.<locals>.deepClearIfBNode%  s    '/76" 8r?   N)r!   r,   r   r`  rf   r   rl   r   equivalentClassr   r   rk   r   clear	_operator)classToPruneri  r   inverseClasss       r<   r(   r(     s;   \# \:+B+BCL$$ |66NO)) |668K8KTRS,,L!!<#:#:C<L<Ld"ST&,- 	 AQ	 !!$$l&<&<dC	
	 .r?   c                       e Zd Zd Zd Zy)r-   c                     || _         y r8   msg)r;   rr  s     r<   r=   zMalformedClass.__init__>  s	    r?   c                     | j                   S r8   rq  r   s    r<   __repr__zMalformedClass.__repr__A  s    xxr?   N)rW   rX   rY   r=   rt  rZ   r?   r<   r-   r-   =  s    r?   r-   c                 T   |d u xr | j                   xs |}|j                  t        |       t        j                        D ]  }|t
        j                  k(  rt        |       |d}|j                  t        |       d d f      D ]s  \  }}}|t        j                  k7  s|t
        j                  k(  r||d<   4|t        j                  vrG||t        |j                  t        t
                    d         <   u t        t        j                  D cg c],  }t        |j                  t        t
                    d         . c}      j                  |      st        d      t        d
i |c S |j                  t        |       t
        j                   t
        j"                  t
        j$                  gd f      D ]M  \  }}}|t
        j$                  k(  rt'        t        |       |      c c S t)        t        |       ||      c c S  t+        t        |       |d	      c S  y c c}w )Nrx   )rl   rf   r   zMalformed owl:Restrictionr   )operatorrf   Trf   r_  rZ   )r   r   r$   r   r   r   r3   r   r   restrictionKindsr   splitr:  intersectionr-   r   r   r   r   r)   r   r"   )r   rf   r   kwArgsr   r   r   r   s           r<   r!   r!   E  s   TM,ann5E&7&:chhO Y3??"$5a$85IF ==*;A*>d)KL ?1a=CNN*/0|,K$@$@@$=>s1773s8#4R#89:? 5@5Q5QRQWWSX&r*+Rl6"# %%@AA((( 00%a(''cii@ 
W1a 		>*+<Q+?uMM'(9!(<qPUVV
W *1-USWXX;Y Ss   1H%
c                       e Zd ZdZd Zd Zd Z	 	 	 	 	 	 	 	 	 	 	 d$ fd	Zd%dZd Z	 e
ej                        d        Z eee	e      Zej"                  fd	Z eed
       Zd Zd Z eee      Zd Zd Zd Zd Zd Zd Zd Zd Zd Z e
ej@                        d        Z! eeee!      Z d Z"d Z# e
e$jJ                        d        Z& ee"e#e&      Z%d Z'd Z( e
e$jR                        d        Z* ee'e(e*      Z)d Z+d Z, e
e$jZ                        d        Z. ee+e,e.      Z-d  Z/ ee/      Z0d! Z1d" Z2d&d#Z3 xZ4S )'r"   ul  
    'General form' for classes:

    The Manchester Syntax (supported in Protege) is used as the basis for the
    form of this class

    See: http://owl-workshop.man.ac.uk/acceptedLong/submission_9.pdf:

    [Annotation]
    ‘Class:’ classID {Annotation
    ( (‘SubClassOf:’ ClassExpression)
    | (‘EquivalentTo’ ClassExpression)
    | (’DisjointWith’ ClassExpression)) }

    Appropriate excerpts from OWL Reference:

    ".. Subclass axioms provide us with partial definitions: they represent
     necessary but not sufficient conditions for establishing class
     membership of an individual."

    ".. A class axiom may contain (multiple) owl:equivalentClass statements"

    "..A class axiom may also contain (multiple) owl:disjointWith statements.."

    "..An owl:complementOf property links a class to precisely one class
      description."

    c                    | j                   D ]'  }t        || j                        j                  |       ) | j                  D ]'  }t        || j                        j                  |       ) | j
                  D ]'  }t        || j                        j                  |       ) | j                  r0t        | j                  | j                        j                  |       y y r8   )r`  r!   rf   r   rj  disjointWithr   )r;   rf   cls      r<   
_serializezClass._serialize  s    // 	7Bb$**%//6	7&& 	7Bb$**%//6	7## 	7Bb$**%//6	7d''4>>uE r?   c                     | j                   j                  | j                  d d f      D ]  }|j                  |        | j	                  |       y r8   )rf   r   rl   r   r  r   s      r<   r   zClass.serialize  sB    JJ&&t'DE 	DIIdO	r?   c                     t        |t              r|\  }}n|}|}|r-| j                  | j                  |      fg| j                  _        |r.| j                  | j                  |      fg| j                  _        y y r8   )rk   tuplerl   r  r  r  r  )r;   nounAnnotationsr  r  s       r<   setupNounAnnotationszClass.setupNounAnnotations  sw    ou-#2 Iy'I'I$"7"7	"BC%DNN! $"7"7	"BC%DNN! r?   c                 J   t         t        |   |||
|       |	r| j                  |	       |s| j                  t
        j                  t        j                  f| j                  vr{| j                  t
        j                  t        j                  f| j                  vrD| j                  j                  | j                  t
        j                  t        j                  f       |xr |xs g | _        |xr |xs g | _        |xr |xs g | _        |r|| _        |xr |xs g | _        y r8   )r  r"   r=   r  rl   r   r   r   rf   r3   r   r`  rj  r  r   r  )r;   rl   r`  rj  r  r   rf   r_  r  r  r  r  r	  s               r<   r=   zClass.__init__  s     	eT#J~{S%%o6&#((CII6djjH#((COO<DJJNJJNNDOOSXXsyyAB$39r.B?Hb(9\?R ,D*70br?   c              #      K   |d u xr | j                   xs |j                  t        j                  | j                        D ]  }|  y wr   )rf   r   r   r   rl   )r;   rf   members      r<   _get_extentzClass._get_extent  sL     }3<uFFhht G 
 	F L	s   A
Ac                     |sy |D ]A  }| j                   j                  t        |      t        j                  | j
                  f       C y r8   )rf   r   r$   r   r   rl   )r;   rD   ms      r<   _set_extentzClass._set_extent  s>     	NAJJNN-a0#((DOOLM	Nr?   c                      y r8   rZ   r   s    r<   	_del_typezClass._del_type  r   r?   c              #   X   K   | j                   j                  | |      D ]  }|  y wr   )rf   r   )r;   r   
annotations      r<   _get_annotationzClass._get_annotation  s/     **,,TT,J 	J	s   (*c                     | S r8   rZ   )rC   s    r<   rE   zClass.<lambda>  s    Q r?   c                 N    t        d      t        j                  | j                  fS )NCLASS)r	   r   r   rl   r   s    r<   _get_extentQueryzClass._get_extentQuery  s    !388T__==r?   c                      y r8   rZ   rH   s     r<   _set_extentQueryzClass._set_extentQuery  s    r?   c                 ,    t        | j                        S )zy
        >>> b=Class(OWL.Restriction)
        >>> c=Class(OWL.Restriction)
        >>> len(set([b,c]))
        1
        )hashrl   r   s    r<   __hash__zClass.__hash__  s     DOO$$r?   c                 t    t        |t              sJ t        |             | j                  |j                  k(  S r8   )rk   r"   reprrl   rH   s     r<   __eq__zClass.__eq__  s0    %'4e4'%"2"222r?   c                 :    t        |t              sJ | g|_        | S r8   )rk   r"   r`  rH   s     r<   __iadd__zClass.__iadd__  s!    %''' 6r?   c                     t        |t              sJ | j                  j                  t	        |      t
        j                  | j                  f       | S r8   )rk   r"   rf   r   r$   r   r`  rl   rH   s     r<   __isub__zClass.__isub__  s>    %'''

,U3T__dooVWr?   c                     t        |       S )z@
        Shorthand for Manchester syntax's not operator
        )r   )r"   r   s    r<   
__invert__zClass.__invert__  s     $''r?   c                 R    t        t        j                  | |g| j                        S )z
        Construct an anonymous class description consisting of the union of
        this class and 'other' and return it
        rw  membersrf   )r   r   r   rf   rH   s     r<   rL   zClass.__or__  s$    
 [[4-tzz
 	
r?   c                 R    t        t        j                  | |g| j                        S )a  
        Construct an anonymous class description consisting of the
        intersection of this class and 'other' and return it

        >>> exNs = Namespace('http://example.com/')
        >>> namespace_manager = NamespaceManager(Graph())
        >>> namespace_manager.bind('ex', exNs, override=False)
        >>> namespace_manager.bind('owl', OWL, override=False)
        >>> g = Graph()
        >>> g.namespace_manager = namespace_manager

        Chaining 3 intersections

        >>> female = Class(exNs.Female, graph=g)
        >>> human = Class(exNs.Human, graph=g)
        >>> youngPerson = Class(exNs.YoungPerson, graph=g)
        >>> youngWoman = female & human & youngPerson
        >>> youngWoman #doctest: +SKIP
        ex:YoungPerson THAT ( ex:Female AND ex:Human )
        >>> isinstance(youngWoman, BooleanClass)
        True
        >>> isinstance(youngWoman.identifier, BNode)
        True
        r  )r   r   r   rf   rH   s     r<   __and__zClass.__and__
  s&    2 ''$djj
 	
r?   c              #      K   | j                   j                  | j                  t        j                        D ]  }t        || j                   d        y w)Nrx   Trx  )rf   r   rl   r   r`  r"   r;   ancs     r<   _get_subClassOfzClass._get_subClassOf'  sM     ::%%OOt & 
 	LC 4::dKK	L   AAc                     |sy |D ]A  }| j                   j                  | j                  t        j                  t        |      f       C y r8   )rf   r   rl   r   r`  r$   r;   rD   scs      r<   _set_subClassOfzClass._set_subClassOf-  s?     	VBJJNNDOOT__>OPR>STU	Vr?   c                      y r8   rZ   r   s    r<   _del_subClassOfzClass._del_subClassOf3  r   r?   c              #      K   | j                   j                  | j                  t        j                        D ]  }t        || j                           y wNrx   r   )rf   r   rl   r   rj  r"   )r;   ecs     r<   _get_equivalentClasszClass._get_equivalentClass9  sK     **$$OOs/B/B % 
 	.B $**--	.   AAc                     |sy |D ]A  }| j                   j                  | j                  t        j                  t        |      f       C y r8   )rf   r   rl   r   rj  r$   r  s      r<   _set_equivalentClasszClass._set_equivalentClass?  sA     	BJJNN#"5"57H7LM	r?   c                      y r8   rZ   r   s    r<   _del_equivalentClasszClass._del_equivalentClassG  r   r?   c              #      K   | j                   j                  | j                  t        j                        D ]  }t        || j                           y wr  )rf   r   rl   r   r  r"   )r;   r`   s     r<   _get_disjointWithzClass._get_disjointWithO  sK     **$$OOs/?/? % 
 	.B $**--	.r  c                     |sy |D ]A  }| j                   j                  | j                  t        j                  t        |      f       C y r8   )rf   r   rl   r   r  r$   )r;   rD   r   s      r<   _set_disjointWithzClass._set_disjointWithU  sA     	VAJJNNDOOS-=-=?PQR?STU	Vr?   c                      y r8   rZ   r   s    r<   _del_disjointWithzClass._del_disjointWith[  r   r?   c                     t        | j                  j                  | j                  t        j
                              }|sy t        |      dk(  rt        |d   | j                        S t        t        |            )Nrx   ru   r   r   )	r_   rf   r   rl   r   r   r   r"   r   )r;   comps     r<   _get_complementOfzClass._get_complementOfa  sd    JJt#BRBRS
 Y!^a

33CI&&r?   c                     |sy | j                   j                  | j                  t        j                  t        |      f       y r8   )rf   r   rl   r   r   r$   rH   s     r<   _set_complementOfzClass._set_complementOfl  s/    

)9)9;LU;STUr?   c                      y r8   rZ   r   s    r<   _del_complementOfzClass._del_complementOfq  r   r?   c              #     K   t        j                  | j                  | j                        D ]  }|  t	        | j
                  j                  t        j                  | j                              }|rt        | j
                  j                  t        j                  |            }|r|d   }n|}| j
                  j                  t        j                  |      D ]"  }t        |t              st!        |d       $ | j
                  j#                  | j                  t        j$                        D ]?  }t'        |g| j
                        D ]"  }t        |t              st!        |d       $ A yw)aw  
        computed attributes that returns a generator over taxonomic 'parents'
        by disjunction, conjunction, and subsumption

        >>> from rdflib.util import first
        >>> exNs = Namespace('http://example.com/')
        >>> namespace_manager = NamespaceManager(Graph())
        >>> namespace_manager.bind('ex', exNs, override=False)
        >>> namespace_manager.bind('owl', OWL, override=False)
        >>> g = Graph()
        >>> g.namespace_manager = namespace_manager
        >>> Individual.factoryGraph = g
        >>> brother = Class(exNs.Brother)
        >>> sister = Class(exNs.Sister)
        >>> sibling = brother | sister
        >>> sibling.identifier = exNs.Sibling
        >>> sibling #doctest: +SKIP
        ( ex:Brother OR ex:Sister )
        >>> first(brother.parents) #doctest: +SKIP
        Class: ex:Sibling EquivalentTo: ( ex:Brother OR ex:Sister )
        >>> parent = Class(exNs.Parent)
        >>> male = Class(exNs.Male)
        >>> father = parent & male
        >>> father.identifier = exNs.Father
        >>> list(father.parents) #doctest: +SKIP
        [Class: ex:Parent , Class: ex:Male ]

        rv  Tr^  r   N)	itertoolschainr`  rj  r   r   r   r   rl   r_   transitive_subjectsrestr   r   rk   r   r"   r   r   r0   )r;   parentlinklistSiblingscollectionHeaddisjClsrdfListr  s           r<   _get_parentszClass._get_parentsw  s5    :  oodoot7K7KL 	FL	 T&&//		4??KL 1 1 E EchhPT UVL!-b!1!%,,55ckk>R Fgv.EEF ((00#BTBTU 	EG)7)4;L;LM Eff-tDDE	Es   C-E80A3E8$E8c                    | j                   t        j                  t        j                  f| j
                  v ryt        | j                        }| j
                  j                  | j                   t        j                  t        j                  gd f      D ]-  \  }}}|j                  t        || j
                  |             / |D ]  } y | j                  ryy)NFr   T)rl   r   r   r   r3   rf   r_   rj  r   r   r   r   r.   r   )r;   r  	boolClassr   r  es         r<   isPrimitivezClass.isPrimitive  s    OOSXXs74::E$&&'%)ZZ%?%?__s113;;?F&
 	H!Iq' II&w

AFG	H  	A	r?   c              #      K   | j                   j                  t        j                  | j                        D ]  }|  y wr   )rf   r   r   r`  rl   )r;   r   s     r<   subSumpteeIdszClass.subSumpteeIds  s6     $$tt$W 	AG	r   c                    g }t        | j                        }t        | j                        }| j                  j	                  | j
                  t        j                  t        j                  gdf      D ]-  \  }}}|j                  t        || j                  |             / t        | j                        }	| j                  }
|
r|	j                  |
       d}t        | j                  j                  | j
                  t        j                              }|xr d|d   z   dz   xs d}|r|rd}nd}|D cg c]p  }t!        |t"              xr; t!        | j
                  t$              xr t'        t)        || j                              xs t        t+        |      | j                        r }}|rd	|z  }|j                  d
|j-                  |D cg c]  }t/        |       c}      z         |rd|d   z   |d<   |ry|D cg c]7  }t!        |t.              xr |xs t        t+        |      | j                        9 }}|rd|z  }|j                  ddj-                  |      z         |rd|d   z   |d<   |	r[|j                  ddj-                  |	D cg c]!  }t        t+        |      | j                        # c}      z         |rd|d   z   |d<   t        | j                  j                  | j
                  t        j0                              }|rB|r@|xr( d|z  |xr d|d   z  xs dz   dj-                  |      z   xs dj-                  |      }n*|xr |xr d|d   z  xs dxs ddj-                  |      z   }t!        | j
                  t$              xr dxs d| j2                  z  |z   S c c}w c c}w c c}w c c}w )I
        Returns the Manchester Syntax equivalent for this class
        Nr    (r   )z
                z, zPrimitive Type %szSubClassOf: %sz
    rv  zA Defined Class %szEquivalentTo: %szDisjointWith %s
z
                 z
    ## %s ##z
    %sz . zSome Class z
Class: %s )r_   r`  rj  rf   r   rl   r   r   r   r   r.   r  r   r   r   r   rk   r"   r   r  r!   r$   re   r   r  r   )r;   fullnormalizationexprsr  r  r  r   r  r`   r   	klassKindr   scJoinr   necStatementsnnec_SuffStatementsdescr
klassDescrs                       r<   rt  zClass.__repr__  s    $//"$&&'%)ZZ%?%?__s113;;?F&
 	H!Iq' II&w

AFG	H $##$IIaL	TZZ''DE.#a.3.4"- 
  1e$ 3t631djj12C !!21!5tzzBC
M 
 /%7	LL 6;;/N1A/N#OO $uRy0b	
 	"  1c" F#$5a$8$**EF" " "058	LL+dii8J.KKL$uRy0b	LL#',,QSTA%&7&:DJJGT $uRy0b	TZZ''FGM $$y02Z%(28b:**U#$% ::e$   <4zE!H4:*

5))  t. )djj(	 	m
 0O
" Us   6A5N0N5<N:&N?)NNNNNNFNNNFr8   )FT)5rW   rX   rY   r   r  r   r  r=   r  r  r   r   r   r  r   r  r   r   r  r  r  r  extentQueryr  r  r  r  r  rL   r  r  r  r`  r  r  r  r   rj  r  r  r  r  r  r  r  r   r  r  parentsr  r  rt  r4  r5  s   @r<   r"   r"   g  s   :F
$ $1@N ! " k;	:F#'::  /;7J> +-=>K%3

(

:LV ( ) /?OLJ. ++, - 24HO.V (() * -/@BSTL	'V
 (() * -/@BSTL-E^ |$GQr?   r"   c                   V    e Z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y)r0   Nc           
         |r|| _         |xr |xs g }|rYt        | j                   |d         | _        |D ]5  }|| j                  vs| j                  j                  t	        |             7 y t        | j                   t               |D cg c]  }t	        |       c}      | _        | j                   j                  | j                  | j                  | j                  j                  f       y c c}w Nr   )
rf   r   _rdfListr   r$   r   r   rl   rl  rg   )r;   r  r  rf   r  r  s         r<   r=   zOWLRDFListProxy.__init__  s    DJ%g+&tzz71:>DM! D.MM(():6)BCD '

EGG%Lq&7&:%LDM JJNNDOOT^^T]]=N=NOP &Ms   C1c                 0   t        |t              s%J t        |      t        t        |            z          t        |t              r9t        |       }|t        |      k7  ryt        |      D ]  }| |   ||   k7  r y y y| j                  |j                  k(  S )zo
        Equivalence of boolean class constructors is determined by
        equivalence of its members
        FTN)rk   r"   r  r   r   r   rangerl   )r;   rD   lengthidxs       r<   r  zOWLRDFListProxy.__eq__$  s    
 %'HetDK7H)HH'e\*YFU# =  CCyE#J.$ 
 ??e&6&666r?   c                 ,    t        | j                        S r8   )r   r  r   s    r<   __len__zOWLRDFListProxy.__len__7  s    4==!!r?   c                 J    | j                   j                  t        |            S r8   )r  indexr$   r;   items     r<   r  zOWLRDFListProxy.index:  s    }}""#4T#:;;r?   c                      | j                   |   S r8   r  r;   rU  s     r<   rW  zOWLRDFListProxy.__getitem__=  s    }}S!!r?   c                 4    t        |      | j                  |<   y r8   )r$   r  )r;   rU  r   s      r<   __setitem__zOWLRDFListProxy.__setitem__@  s    .u5cr?   c                     | j                   |= y r8   r  r  s     r<   __delitem__zOWLRDFListProxy.__delitem__C  s    MM#r?   c                 8    | j                   j                          y r8   )r  rk  r   s    r<   rk  zOWLRDFListProxy.clearF  s    r?   c              #   6   K   | j                   D ]  }|  y wr8   r  r  s     r<   __iter__zOWLRDFListProxy.__iter__I  s     MM 	DJ	s   c                 F    | j                   D ]  }|t        |      k(  s y y)Nru   r   )r  r$   )r;   r  r   s      r<   __contains__zOWLRDFListProxy.__contains__M  s+     	A%d++	 r?   c                 :    | j                   j                  |       y r8   )r  r   r  s     r<   r   zOWLRDFListProxy.appendS  s    T"r?   c                 N    | j                   j                  t        |             | S r8   )r  r   r$   rH   s     r<   r  zOWLRDFListProxy.__iadd__V  s    .u56r?   r   )rW   rX   rY   r=   r  r  r  rW  r   r  rk  r  r  r   r  rZ   r?   r<   r0   r0     s?    Q7&"<"6#r?   r0   c                   B    e Zd ZdZej
                  Zd ZddZd Z	d Z
y)r)   a2  
    Class for owl:oneOf forms:

    OWL Abstract Syntax is used

    axiom ::= 'EnumeratedClass('
        classID ['Deprecated'] { annotation } { individualID } ')'


    >>> exNs = Namespace('http://example.com/')
    >>> namespace_manager = NamespaceManager(Graph())
    >>> namespace_manager.bind('ex', exNs, override=False)
    >>> namespace_manager.bind('owl', OWL, override=False)
    >>> g = Graph()
    >>> g.namespace_manager = namespace_manager
    >>> Individual.factoryGraph = g
    >>> ogbujiBros = EnumeratedClass(exNs.ogbujicBros,
    ...                              members=[exNs.chime,
    ...                                       exNs.uche,
    ...                                       exNs.ejike])
    >>> ogbujiBros #doctest: +SKIP
    { ex:chime ex:uche ex:ejike }
    >>> col = Collection(g, first(
    ...    g.objects(predicate=OWL.oneOf, subject=ogbujiBros.identifier)))
    >>> [g.qname(item) for item in col]
    [u'ex:chime', u'ex:uche', u'ex:ejike']
    >>> print(g.serialize(format='n3')) #doctest: +SKIP
    @prefix ex: <http://example.com/> .
    @prefix owl: <http://www.w3.org/2002/07/owl#> .
    @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    <BLANKLINE>
    ex:ogbujicBros a owl:Class;
        owl:oneOf ( ex:chime ex:uche ex:ejike ) .
    <BLANKLINE>
    <BLANKLINE>
    c                      yNFrZ   r   s    r<   r  zEnumeratedClass.isPrimitive      r?   Nc                     t         j                  | ||       |xr |xs g }t        | j                  j	                  t
        j                  | j                              }t        j                  | ||       y )Nr   rz   ry   )	r"   r=   r_   rf   r   r   r   rl   r0   )r;   rl   r  rf   r  s        r<   r=   zEnumeratedClass.__init__  s[    tZu5%g+tzz))CIIt)WX  w8r?   c                 n    t        | j                  j                  | j                  | j                        S r  r   r.   r  rg   rf   rl  r   s    r<   rt  zEnumeratedClass.__repr__  %       1 14::t~~VVr?   c                    t        |t                     }| j                  D ]8  }|j                  |       t	        || j
                        j                  |       : |j                  | j                  | j                  |j                  f       | j
                  j                  | j                  d d f      D ]*  \  }}}|| j                  k7  s|j                  |||f       , | j                  |       y r8   r   r   r  r   r!   rf   r   r   rl   rl  rg   r   r  r;   rf   
clonedListr  r   r   r   s          r<   r   zEnumeratedClass.serialize  s    uw/
-- 	7Bb!b$**%//6	7 			4??DNNJNNCDzz))4??D$*GH 	%GAq!DNN"		1a)$	% 	r?   )NNN)rW   rX   rY   r   r   r   rl  r  r=   rt  r   rZ   r?   r<   r)   r)   [  s(    #J 		I9W
r?   r)   c                       e Zd ZdZd Zd Zy)BooleanClassExtentHelpera  
    >>> testGraph = Graph()
    >>> Individual.factoryGraph = testGraph
    >>> EX = Namespace("http://example.com/")
    >>> namespace_manager = NamespaceManager(Graph())
    >>> namespace_manager.bind('ex', EX, override=False)
    >>> testGraph.namespace_manager = namespace_manager
    >>> fire = Class(EX.Fire)
    >>> water = Class(EX.Water)
    >>> testClass = BooleanClass(members=[fire, water])
    >>> testClass2 = BooleanClass(
    ...     operator=OWL.unionOf, members=[fire, water])
    >>> for c in BooleanClass.getIntersections():
    ...     print(c) #doctest: +SKIP
    ( ex:Fire AND ex:Water )
    >>> for c in BooleanClass.getUnions():
    ...     print(c) #doctest: +SKIP
    ( ex:Fire OR ex:Water )
    c                     || _         y r8   rw  )r;   rw  s     r<   r=   z!BooleanClassExtentHelper.__init__  r>   r?   c                       fd}|S )Nc               3      K   t         j                  j                  j                        D ]  } t	        | j                          y w)Nr  )r,   r   r   rw  r   )r   r;   s    r<   
_getExtentz5BooleanClassExtentHelper.__call__.<locals>._getExtent  s<     ,,55dmmD >"1t}}==>s   A	ArZ   )r;   r   r  s   `  r<   rV   z!BooleanClassExtentHelper.__call__  s    	> r?   N)rW   rX   rY   r   r=   rV   rZ   r?   r<   r  r    s    (!r?   r  c                       e Zd Zd Zy)r    c                     || _         y r8   )rV   )r;   anycallables     r<   r=   zCallable.__init__  s	    #r?   N)rW   rX   rY   r=   rZ   r?   r<   r    r      s    $r?   r    c                       e Zd ZdZ eej                        ed               Z ee      Z eej                        ed               Z
 ee
      Z
dej                  ddfdZd Zd Zd Zd	 Zd
 Zd Zy)r   zm
    See: http://www.w3.org/TR/owl-ref/#Boolean

    owl:complementOf is an attribute of Class, however

    c                       y r8   rZ   rZ   r?   r<   getIntersectionszBooleanClass.getIntersections       	r?   c                       y r8   rZ   rZ   r?   r<   	getUnionszBooleanClass.getUnions  r%  r?   Nc           	         |ng }|j                  |t        j                  t        j                  gd f      D ]  \  }}}|j	                  |       |} t        |      dk(  sJ t        |             t        j                  | ||       |t        j                  t        j                  fv sJ t        |             || _
        t        | j                  j                  || j                              }	|r:|	r8J dt        t        | j                  |	d         j!                               z          t"        j                  | |	|       y )Nru   r   r  z-This is a previous boolean class description!r   )r   r   r   r   r   r   r  r"   r=   r   rl  r_   rf   r   rl   r   r   r0   )
r;   rl   rw  r  rf   propsr   r   r   r  s
             r<   r=   zBooleanClass.__init__  s&    E 00c00#++>E 1a Q	
 u:?/DK/?tZu5C..<<Kc(mK<!tzz))Hdoo)VWw	
:Ttzz71:.113>
 
	
& 	  w8r?   c                 \    t        | j                  t        |       | j                        }|S )z-
        Create a copy of this class
        r  )r   rl  r_   rf   )r;   copyOfClasss     r<   copyzBooleanClass.copy  s)     #^^T$Ztzz
 r?   c                    t        |t                     }| j                  D ]8  }|j                  |       t	        || j
                        j                  |       : |j                  | j                  | j                  |j                  f       | j
                  j                  | j                  d d f      D ]*  \  }}}|| j                  k7  s|j                  |||f       , | j                  |       y r8   r  r  s          r<   r   zBooleanClass.serialize  s    uw/
-- 	7Bb!b$**%//6	7 			4??DNNJNNCDzz))4??D$*GH 	%GAq!DNN"		1a)$	% 	r?   c                      yr  rZ   r   s    r<   r  zBooleanClass.isPrimitive	  r  r?   c                 B   || j                   k7  sJ d       | j                  j                  | j                  | j                   | j                  j
                  f       | j                  j                  | j                  || j                  j
                  f       || _         y)a  
        Converts a unionOf / intersectionOf class expression into one
        that instead uses the given operator


        >>> testGraph = Graph()
        >>> Individual.factoryGraph = testGraph
        >>> EX = Namespace("http://example.com/")
        >>> namespace_manager = NamespaceManager(Graph())
        >>> namespace_manager.bind('ex', EX, override=False)
        >>> testGraph.namespace_manager = namespace_manager
        >>> fire = Class(EX.Fire)
        >>> water = Class(EX.Water)
        >>> testClass = BooleanClass(members=[fire,water])
        >>> testClass #doctest: +SKIP
        ( ex:Fire AND ex:Water )
        >>> testClass.changeOperator(OWL.unionOf)
        >>> testClass #doctest: +SKIP
        ( ex:Fire OR ex:Water )
        >>> try: testClass.changeOperator(OWL.unionOf)
        ... except Exception as e: print(e)
        The new operator is already being used!

        z'The new operator is already being used!N)rl  rf   r   rl   r  rg   r   )r;   newOperators     r<   changeOperatorzBooleanClass.changeOperator  ss    2 dnn,W.WW,

4??DNNDMM<M<MNO

dmm6G6GHI$r?   c                 n    t        | j                  j                  | j                  | j                        S r  r  r   s    r<   rt  zBooleanClass.__repr__*  r  r?   c                     | j                   t        j                  k(  sJ | j                  j	                  t        |             | S )z9
        Adds other to the list and returns self
        )rl  r   r   r  r   r$   rH   s     r<   rL   zBooleanClass.__or__0  s7     ~~,,,.u56r?   )rW   rX   rY   r   r  r   r   r    r$  r   r'  r=   r,  r   r  r1  rt  rL   rZ   r?   r<   r   r     s     c001  2   01ckk*  + #I (:(:DPT9,%<Wr?   r   c                      y)zH
    DisjointClasses(' description description { description } ')'

    NrZ   )r  s    r<   r   r   9  s    
 	r?   c                       e Zd ZdZej
                  ej                  ej                  ej                  ej                  gZ
 e       dddddddf fd	Zd Zd Zd Zd Zd Zd	 Z eej(                        d
        Z eeee      Zd Zd Z eej
                        d        Z eeee      Zd Zd Z eej                        d        Z eeee      Zd Zd Z eej                        d        Z eeee      Zd Z d Z! eejD                        d        Z# ee e!e#      Z"d Z$d Z% eej                        d        Z& ee$e%e&      Zd Z'd Z( eej                        d        Z) ee'e(e)      Z	d Z*d Z+ xZ,S )r3   z
    restriction ::= 'restriction('
    datavaluedPropertyID dataRestrictionComponent
    { dataRestrictionComponent } ')'
    | 'restriction(' individualvaluedPropertyID
    individualRestrictionComponent
    { individualRestrictionComponent } ')'

    Nc
                    t         t        |   |	|d       | j                  t        j
                  t        |      f|vr5|j                  | j                  t        j
                  t        |      f       || _        |t        j                  f|t        j                  f|t        j                  f|t        j                  f|t        j                  f|t        j                  fg}
|
D cg c]  \  }}|s	||f }}}t        |      sJ |j                         \  }}|| _        t#        |t$              r|| _        nUt#        |t(              rt+        |      | _        n4t-        | j.                  j1                  | j                  |            | _        | j                  || j&                  f| j.                  vr2| j.                  j                  | j                  || j&                  f       | j&                  J t)        | j                               | j                  t2        j4                  t        j                  f| j.                  vr| j.                  j                  | j                  t2        j4                  t        j                  f       | j.                  j7                  | j                  t2        j4                  t        j(                  f       y y c c}}w )NTrx  )r  r3   r=   rl   r   r   r2   r   r   r   r   r   r   r   r   poprestrictionTyperk   r   restrictionRanger"   r$   r   rf   r   r   r   r   )r;   r   rf   r   r   r   r   r   r   rl   
restrTypesr   oTermvalidRestrPropsr9  r8  r	  s                   r<   r=   zRestriction.__init__T  s;    	k4)eD 	* 	
 OONN ,
 	
 II#..2Fz2RS %C--.S//0CLL!#//*S//0S//0

 9CH*1eaAu:HH?###,;,?,?,A)/.&
3$4D!(%0$56F$GD!$)

""4??OD%D! OO_d.C.CDDJJVJJNNDOO_d>S>STU$$0H%2HH0OOSXXs7tzzIJJNNDOOSXXsGHJJt#))DE J Is   )
K4Kc                    t        | j                  | j                  d      j                  |       | j                  j	                  | j
                  ddf      D ]b  \  }}}|j                  |||f       |t        j                  t        j                  fv s>t        || j                        j                  |       d y)a  
        >>> g1 = Graph()
        >>> g2 = Graph()
        >>> EX = Namespace("http://example.com/")
        >>> namespace_manager = NamespaceManager(g1)
        >>> namespace_manager.bind('ex', EX, override=False)
        >>> namespace_manager = NamespaceManager(g2)
        >>> namespace_manager.bind('ex', EX, override=False)
        >>> Individual.factoryGraph = g1
        >>> prop = Property(EX.someProp, baseType=OWL.DatatypeProperty)
        >>> restr1 = (Property(
        ...    EX.someProp,
        ...    baseType=OWL.DatatypeProperty)) | some | (Class(EX.Foo))
        >>> restr1 #doctest: +SKIP
        ( ex:someProp SOME ex:Foo )
        >>> restr1.serialize(g2)
        >>> Individual.factoryGraph = g2
        >>> list(Property(
        ...     EX.someProp,baseType=None).type
        ... ) #doctest: +NORMALIZE_WHITESPACE +SKIP
        [rdflib.term.URIRef(
            u'http://www.w3.org/2002/07/owl#DatatypeProperty')]
        NrG  )r1   r   rf   r   r   rl   r   r   r   r   r!   )r;   rf   r   r   r   s        r<   r   zRestriction.serialize  s    0 	

TBLLUSzz))4??D$*GH 	:GAq!IIq!Qi S&&(:(:;;!TZZ(2259	:r?   c                      yr  rZ   r   s    r<   r  zRestriction.isPrimitive  r  r?   c                 D    t        | j                  | j                  f      S r8   )r  r   r9  r   s    r<   r  zRestriction.__hash__  s    T__d&;&;<==r?   c                     t        |t              s%J t        |      t        t        |            z          t        |t              r4|j
                  | j
                  k(  xr |j                  | j                  k(  S y)z
        Equivalence of restrictions is determined by equivalence of the
        property in question and the restriction 'range'
        F)rk   r"   r  r   r3   r   r9  rH   s     r<   r  zRestriction.__eq__  sk    
 %'HetDK7H)HH'e[)  DOO3 D**d.C.CC
 r?   c                     t        | j                  j                  | j                  t        j
                              d   S )Nrx   r   )r_   rf   r   rl   r   r   r   s    r<   _get_onPropertyzRestriction._get_onProperty  s6    JJt#..Q

 	r?   c                     | j                   t        j                  t        |      f}|sy || j                  v ry | j                  j                  |       y r8   )rl   r   r   r2   rf   r:  )r;   r   triples      r<   _set_onPropertyzRestriction._set_onProperty  sA    //3>>3G3MNtzz!JJNN6"r?   c                      y r8   rZ   r   s    r<   _del_onPropertyzRestriction._del_onProperty  r   r?   c                     | j                   j                  | j                  t        j                        D ]  }t        || j                         c S  y r  )rf   r   rl   r   r   r"   r;   r   s     r<   _get_allValuesFromzRestriction._get_allValuesFrom  sL    ##OOs/@/@ $ 
 	.A $**--	. r?   c                     | j                   t        j                  t        |      f}|sy || j                  v ry | j                  j                  |       y r8   )rl   r   r   r$   rf   r:  r;   rD   rD  s      r<   _set_allValuesFromzRestriction._set_allValuesFrom  sC    //3#4#46G6NOtzz!JJNN6"r?   c                      y r8   rZ   r   s    r<   _del_allValuesFromzRestriction._del_allValuesFrom  r   r?   c                     | j                   j                  | j                  t        j                        D ]  }t        || j                         c S  y r  )rf   r   rl   r   r   r"   rI  s     r<   _get_someValuesFromzRestriction._get_someValuesFrom  L    ##OOs/A/A $ 
 	.A $**--	. r?   c                     | j                   t        j                  t        |      f}|sy || j                  v ry | j                  j                  |       y r8   )rl   r   r   r$   rf   r:  rL  s      r<   _set_someValuesFromzRestriction._set_someValuesFrom  C    //3#5#57H7OPtzz!JJNN6"r?   c                      y r8   rZ   r   s    r<   _del_someValuesFromzRestriction._del_someValuesFrom  r   r?   c                     | j                   j                  | j                  t        j                        D ]  }t        || j                         c S  y r  )rf   r   rl   r   r   r"   rI  s     r<   _get_hasValuezRestriction._get_hasValue  sA    ##DOOs||#T 	.A$**--	.r?   c                     | j                   t        j                  t        |      f}|sy || j                  v ry | j                  j                  |       y r8   )rl   r   r   r$   rf   r:  rL  s      r<   _set_hasValuezRestriction._set_hasValue   sA    //3<<1B51IJtzz!JJNN6"r?   c                      y r8   rZ   r   s    r<   _del_hasValuezRestriction._del_hasValue	  r   r?   c                     | j                   j                  | j                  t        j                        D ]  }t        || j                         c S  y r  )rf   r   rl   r   r   r"   rI  s     r<   _get_cardinalityzRestriction._get_cardinality  sA    ##DOOs#W 	.A$**--	.r?   c                     | j                   t        j                  t        |      f}|sy || j                  v ry | j                  j                  |       y r8   )rl   r   r   r$   rf   r:  rL  s      r<   _set_cardinalityzRestriction._set_cardinality  sA    //3??4Ee4LMtzz!JJNN6"r?   c                      y r8   rZ   r   s    r<   _del_cardinalityzRestriction._del_cardinality  r   r?   c                     | j                   j                  | j                  t        j                        D ]  }t        || j                         c S  y r  )rf   r   rl   r   r   r"   rI  s     r<   _get_maxCardinalityzRestriction._get_maxCardinality#  rR  r?   c                     | j                   t        j                  t        |      f}|sy || j                  v ry | j                  j                  |       y r8   )rl   r   r   r$   rf   r:  rL  s      r<   _set_maxCardinalityzRestriction._set_maxCardinality*  rU  r?   c                      y r8   rZ   r   s    r<   _del_maxCardinalityzRestriction._del_maxCardinality3  r   r?   c                     | j                   j                  | j                  t        j                        D ]  }t        || j                         c S  y r  )rf   r   rl   r   r   r"   rI  s     r<   _get_minCardinalityzRestriction._get_minCardinality;  rR  r?   c                     | j                   t        j                  t        |      f}|sy || j                  v ry | j                  j                  |       y r8   )rl   r   r   r$   rf   r:  rL  s      r<   _set_minCardinalityzRestriction._set_minCardinalityB  rU  r?   c                      y r8   rZ   r   s    r<   _del_minCardinalityzRestriction._del_minCardinalityK  r   r?   c                     | j                   j                  | j                  | j                  d f      D ]  }|j	                  t
              d   c S   )Nrv  )rf   triple_choicesrl   ry  rz  r   )r;   r   s     r<   restrictionKindzRestriction.restrictionKindS  sN    **__d33T:
 	$A 773<##	$ 	r?   c                 B    t        | j                  | j                        S )zO
        Returns the Manchester Syntax equivalent for this restriction
        )r.   rl   rf   r   s    r<   rt  zRestriction.__repr__Z  s      <<r?   )-rW   rX   rY   r   r   r   r   r   r   r   ry  r
   r=   r   r  r  r  rB  rE  r   r   rG  r   rJ  rM  rO  rQ  rT  rW  rY  r[  r]  r_  ra  r   rc  re  rg  ri  rk  rm  ro  rr  rt  r4  r5  s   @r<   r3   r3   A  s    	 g1Ff:<>
# ' ( /?OLJ# ))* + /1CEWXM# **+ , 02EN
# % & }mDH
# ( ) +-=?OPK# **+ , 02EN# **+ , 02EN=r?   r3   c                 2    t        | |j                  |      S )N)rf   r   r3   rf   r   rh  s     r<   rE   rE   e  s    TfU r?   c                 2    t        | |j                  |      S )N)rf   r   ru  rv  s     r<   rE   rE   h  s    TVT r?   c                 2    t        | | j                  |      S )N)rf   r   ru  rv  s     r<   rE   rE   k      TFS r?   c                 2    t        | | j                  |      S )N)rf   r   ru  rv  s     r<   rE   rE   n  ry  r?   c                 2    t        | | j                  |      S )N)rf   r   ru  rv  s     r<   rE   rE   q  s    TP r?   c                 2    t        | | j                  |      S )N)rf   r   ru  rv  s     r<   rE   rE   s  s    ;t4::V#T r?   zh
%s( %s { %s }
%s
{ 'super(' datavaluedPropertyID ')'} ['Functional']
{ domain( %s ) } { range( %s ) } )c                       e Zd ZdZd Zddej                  ddddddddddf fd	Zd ZddZ	d Z
 ee	e
      Zd	 Zd
 Zd Z eej$                        d        Z eeee      Zd Zd Z eej,                        d        Z eeee      Zd Zd Z eej4                        d        Z eeee      Zd Zd Z eej<                        d        Z eeee      Zd Z  xZ!S )r1   a  
    axiom ::= 'DatatypeProperty(' datavaluedPropertyID ['Deprecated']
                { annotation }
                { 'super(' datavaluedPropertyID ')'} ['Functional']
                { 'domain(' description ')' } { 'range(' dataRange ')' } ')'
                | 'ObjectProperty(' individualvaluedPropertyID ['Deprecated']
                { annotation }
                { 'super(' individualvaluedPropertyID ')' }
                [ 'inverseOf(' individualvaluedPropertyID ')' ] [ 'Symmetric' ]
                [ 'Functional' | 'InverseFunctional' |
                'Functional' 'InverseFunctional' |
                'Transitive' ]
                { 'domain(' description ')' } { 'range(' description ')' } ')

    c                 Z   t        |t              r|\  }}}n|}|}|}|r-| j                  | j                  |      fg| j                  _        |r-| j                  | j                  |      fg| j                  _        |r.| j                  | j                  |      fg| j                  _        y y r8   )rk   r  rl   r  r  r  r  r  )r;   verbAnnotationsr  r  r  s        r<   setupVerbAnnotationszProperty.setupVerbAnnotations  s    ou-+:(Iy&'I'I$F$"7"7	"BC%DNN! $"7"7	"BC%DNN! '+8M8Mf8U&V%WDOO" r?   NFc                 *   t         t        |   ||||       |r| j                  |       t	        | j
                  t              rJ |:t        t        | j
                  | j                        j                        | _        nf| j
                  t        j                  |f| j                  vr6| j                  j                  | j
                  t        j                  |f       || _        || _        || _        || _        || _        |
xr |
xs g | _        y )Nr   )r  r1   r=   r  rk   rl   r   r   r,   rf   r   	_baseTyper   r   subPropertyOf	inverseOfdomainr  r  )r;   rl   rf   r  r  r  r  r  	otherTypeequivalentPropertyr  r  r  r  r	  s                 r<   r=   zProperty.__init__  s      	h&z5.+V%%o6doou555":dooTZZ#P#U#UVDN84DJJF

8DE%DN*"
*70br?   c                    | j                   j                  | j                  d d f      D ]  }|j                  |        t	        j
                  | j                  | j                        D ]  }|j                  |        t	        j
                  | j                  | j                        D ]'  }t        || j                         j                  |       ) y r8   )rf   r   rl   r   r  r  r  r  r   r  r  r!   )r;   rf   r   r   r   s        r<   r   zProperty.serialize  s    JJ&&t'DE 	DIIdO	!3!3T^^D 	AKK	djj9 	6Aa$..u5	6r?   c              #      K   |d u xr | j                   xs |j                  d | j                  d f      D ]  }|  y wr8   )rf   r   rl   )r;   rf   rD  s      r<   r  zProperty._get_extent  sG     }3<uEE4??D)
 	F L	s   =?c                 n    |sy |D ]-  \  }}| j                   j                  || j                  |f       / y r8   )rf   r   rl   )r;   rD   subjobjs       r<   r  zProperty._set_extent  s6     	9ID#JJNND$//378	9r?   c                    g }t         j                  | j                  v r|j                  d| j                  dt        | j                        xr t        | j                        xs dd       t        | j                        rt        t        | j                        j                        }|r9|j                  | j                  k(  r t        | j                        j                  }nt        t        | j                              }|j                  d|dt         j                  | j                  v xr dxs d       | j                  j                  | j                  t        j                  t         j                  t         j                  t         j                   gf      D ]6  \  }}}|j                  t#        |j%                  t               d                8 n|j                  d	| j                  d
t        | j                        xr t        | j                        xs d       | j                  j'                  | j                  t        j                  t         j                  f      D ]  \  }}}|j                  d        d }|j                  d
j)                  | j*                  D cg c]  }d ||| j                        z   c}             |j                  d
j)                  | j,                  D 	cg c]  }	d ||	| j                        z   c}	             |j                  d
j)                  | j.                  D 
cg c]  }
d ||
| j                        z   c}
             dj)                  |D cg c]  }|s|	 c}      }|dz  }t#        |      j1                  d      S c c}w c c}	w c c}
w c c}w )NzObjectProperty( z annotation(r  r  z  inverseOf( rv   z
 Symmetricrv  zDatatypeProperty( rw   z   Functionalc                 2   t        |       }t        |t              r| S |j                  t              rt        |       S t        |j                  |t        j                  t        j                  gd f            rt        |       S t        | j                        S r8   )r$   rk   r   rZ  r   r   r   r   r   r   r   r  r   )r   gnormalizedNames      r<   canonicalNamez(Property.__repr__.<locals>.canonicalName  s|    .t4N.%0**3/4y !!#ckk33E3E%FM
 Dz!4::&r?   z   super( %s )z   domain( %s )z   range( %s )r~   z
)zutf-8)r   rM  r   r   r   r   r  r  rl   r  rH  rf   r   r   rI  rJ  rK  r   rz  r   re   r  r  r  encode)r;   rttwoLinkInverseinverseReprr   r   roleTyper  superPr  r  exprs               r<   rt  zProperty.__repr__  s   *II::uT\\2JuT\\7JPbPR T^^$!&uT^^'<'F'F!G!n&?&?4??&R"'"7"="=K"&uT^^'<"=K		 $--:K|QrQ #'**"<"<OOHH..55..
# 81h 		#hnnS1"5678 II::uT\\2JuT\\7JPbPR #'**"4"4#((C,B,BC# +1h 		/*+
	' 			HH #'"4"4 %}VTZZ'HH	
 			HH #'++ &fdjj(II	
 			HH "& %}UDJJ'GG	
 YY4t45
e2w~~g&&1 5s   0N1<N6N;?O O c              #      K   | j                   j                  | j                  t        j                        D ]  }t        || j                   d         y wNrx   rG  )rf   r   rl   r   r  r1   r  s     r<   _get_subPropertyOfzProperty._get_subPropertyOf,  sO     ::%%OOt/A/A & 
 	AC 3djj4@@	Ar  c                     |sy |D ]A  }| j                   j                  | j                  t        j                  t        |      f       C y r8   )rf   r   rl   r   r  r$   )r;   rD   sPs      r<   _set_subPropertyOfzProperty._set_subPropertyOf2  sA     	YBJJNNDOOT-?-?ARSUAVWX	Yr?   c                      y r8   rZ   r   s    r<   _del_subPropertyOfzProperty._del_subPropertyOf8  r   r?   c              #      K   | j                   j                  | j                  t        j                        D ]  }t        || j                   d         y wr  )rf   r   rl   r   r  r1   r  s     r<   _get_inverseOfzProperty._get_inverseOf>  sF     ::%%doo%W 	AC3djj4@@	Ar  c                     |sy | j                   j                  | j                  t        j                  t        |      f       y r8   )rf   r   rl   r   r  r$   rH   s     r<   _set_inverseOfzProperty._set_inverseOfB  s-    

8I%8PQRr?   c                      y r8   rZ   r   s    r<   _del_inverseOfzProperty._del_inverseOfG  r   r?   c              #      K   | j                   j                  | j                  t        j                        D ]  }t        || j                           y wr  )rf   r   rl   r   r  r"   )r;   doms     r<   _get_domainzProperty._get_domainM  sB     ::%%doo%U 	/C4::..	/r  c                 B   |sy t        |t        t        f      r@| j                  j	                  | j
                  t        j                  t        |      f       y |D ]A  }| j                  j	                  | j
                  t        j                  t        |      f       C y r8   )	rk   r,   r   rf   r   rl   r   r  r$   )r;   rD   r  s      r<   _set_domainzProperty._set_domainQ  ss    ej*56JJNNDOOT[[:KE:RST W

>OPS>TUVWr?   c                      y r8   rZ   r   s    r<   _del_domainzProperty._del_domainZ  r   r?   c              #      K   | j                   j                  | j                  t        j                        D ]  }t        || j                           y wr  )rf   r   rl   r   r  r"   )r;   rans     r<   
_get_rangezProperty._get_range`  sB     ::%%doo%T 	/C4::..	/r  c                 B   |sy t        |t        t        f      r@| j                  j	                  | j
                  t        j                  t        |      f       y |D ]A  }| j                  j	                  | j
                  t        j                  t        |      f       C y r8   )	rk   r,   r   rf   r   rl   r   r  r$   )r;   rangesr  s      r<   
_set_rangezProperty._set_ranged  sr    fz:67JJNNDOOTZZ9J69RST X

=Nu=UVWXr?   c                      y r8   rZ   r   s    r<   
_del_rangezProperty._del_rangem  r   r?   c                     | j                   D ]-  \  }}}| j                  j                  |t        |      |f       / | j                  j	                  d | j
                  d f       y r8   )r  rf   r   r2   r   rl   r   s        r<   r   zProperty.replaces  sW    {{ 	@GAq!JJNNA3E:A>?	@

4$78r?   r8   )"rW   rX   rY   r   r  r   rM  r=   r   r  r  r   r  rt  r  r  r   r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r4  r5  s   @r<   r1   r1   |  sS    X( ## 1D69 k;/FS'jAY **+ , /1CEWXMAS
 & ' HI/W $ % k;<F/X 

# $ ZZ8E9r?   r1   c                    t        |       }|j                  dt               |j                  dt               |j                  dt               t        |j                               D ]  \  }}|j                  ||d        || _        y)zI
    Takes a graph and binds the common namespaces (rdf,rdfs, & owl)
    r]   r\   r^   Fr  N)r   r  r   r   r   r_   itemsnamespace_manager)rf   additionalNSr  rh   rg   s        r<   r&   r&   z  s}     )/64(5#&5#&L..01 <vsU;</Er?   c                  ,    dd l } | j                          y r  )doctesttestmod)r  s    r<   testr    s    OOr?   __main__r  r8   )Tr   r  rdflibr   r   r   r   r   r   r	   rdflib.graphr
   rdflib.collectionr   rdflib.namespacer   r   r   rdflib.termr   rdflib.utilr   logging	getLoggerrW   logger__all__r6   r   r*   r%   r$   r2   r.   r+   r4   r   r   r,   r   r   r/   r   r   r#   r:  
differencer   r   r   r   r  r8  r;  backwardCompatibleWithincompatibleWithr   r   r   r   r'   r(   r   r-   r!   r"   r0   r)   BooleanPredicatesr  r    r   r   r3   r   r   r   r   r   r   r   r1   r&   r  rZ   r?   r<   <module>r     s  iV  I I I  ( % - "  			8	$%^- -* 39:
,)
_D v@ v@r 
<	=s<z s<lA A@;>#I # @A*""		 (+#\C
LY YDj jZDf DNAou AH ''5  @$ $
o?E od	]=% ]=F	 U T S S P 	TU& {9 {9| *, 
0 zF r?   