
    i;                      d Z ddlmZ ddlZddlZddlmZmZ ddlm	Z	 ddl
mZmZ ddlmZmZmZmZmZmZ ddlmZmZmZmZmZ dd	lmZ  ej8                  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%	 dEdZ&d Z' G d d      Z( G d d      Z) ed      Z* G d de)      Z+ G d de+      Z,d  Z-d! Z. G d" d#e      Z/ e0 ed$            jc                  ejd                  ejf                  ejh                  ejj                  ejl                  ejn                  ejp                  ejr                  ejt                  ejv                  ejx                  ejz                  g      Z>d% Z?d& Z@ G d' d(eA      ZB G d) d*eB      ZCdFd+ZD G d, d-e+      ZE G d. d/      ZF G d0 d1eFeE      ZGejx                  ejv                  gZH G d2 d3      ZI G d4 d5      ZJ G d6 d7eFeE      ZKd8 ZL G d9 d:eE      ZM e d;       ZN e d<       ZO e d=       ZP e d>       ZQ e d?       ZR e d@       ZSdAZT G dB dCe+      ZUdFdDZVy)Guz  RDFLib Python binding for OWL Abstract Syntax

OWL Constructor     DL Syntax       Manchester OWL Syntax   Example
====================================================================================
intersectionOf      C ∩ D              C AND D             Human AND Male
unionOf             C ∪ D              C OR D              Man OR Woman
complementOf         ¬ C               NOT C               NOT Male
oneOf             {a} ∪ {b}...        {a b ...}            {England Italy Spain}
someValuesFrom      ∃ R C              R SOME C            hasColleague SOME Professor
allValuesFrom       ∀ R C              R ONLY C            hasColleague ONLY Professor
minCardinality      ≥ N R              R MIN 3             hasColleague MIN 3
maxCardinality      ≤ N R              R MAX 3             hasColleague MAX 3
cardinality         = N R              R EXACTLY 3         hasColleague EXACTLY 3
hasValue             ∃ R               {a} R VALUE a       hasColleague VALUE Matthew

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/")
>>> g = Graph()
>>> g.bind("ex", exNs, override=False)

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))
>>> list(Class(OWL.Class, graph=owlGraph).subClassOf)
[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
Class: ex:Opera SubClassOf: ex:MusicalWork
>>> b = Class(exNs.CreativeWork, graph=g)
>>> b += a
>>> print(sorted(a.subClassOf, key=lambda c:c.identifier))
[Class: ex:CreativeWork , Class: ex:MusicalWork ]

And we can then remove it from the extension as well

>>> b -= a
>>> a
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
( 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
( 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
( 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)
{ ex:Africa ex:NorthAmerica }

owl:Restrictions can also be instantiated:

>>> Restriction(exNs.hasParent, graph=g, allValuesFrom=exNs.Human)
( 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)
( ex:hasParent SOME ex:Physician )

>>> Property(exNs.hasParent, graph=g) @ max @ Literal(1)
( ex:hasParent MAX 1 )

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

    )annotationsN)IterableUnion)
Collection)Graph_ObjectType)OWLRDFRDFSXSD	NamespaceNamespaceManager)BNode
IdentifierLiteralURIRefVariable)first)%ACE_NS
AllClassesAllDifferentAllPropertiesAnnotatableTermsBooleanClassCLASS_RELATIONSCallable	CastClassClassClassNamespaceFactoryCommonNSBindingsComponentTermsDeepClassClearEnumeratedClassGetIdentifiedClasses
IndividualInfixMalformedClassMalformedClassErrorOWLRDFListProxyOntologyPropertyPropertyAbstractSyntaxRestrictionclassOrIdentifierclassOrTermexactlygenerateQNamemanchesterSyntaxmaxminnsBindsonlypropertyOrIdentifiersomevaluec                  0    e Zd Zd Zd Zd Zd Zd Zd Zy)r&   c                    || _         y Nfunction)selfr>   s     EC:\Projects\mas-dev\.venv\Lib\site-packages\rdflib/extras/infixowl.py__init__zInfix.__init__   	         c                     t        | |fd      S )Nc                &    |j                  ||       S r<   r=   xr?   others      r@   <lambda>z#Infix.__rlshift__.<locals>.<lambda>       t}}UA7NrC   r&   r?   rH   s     r@   __rlshift__zInfix.__rlshift__       DNOOrC   c                $    | j                  |      S r<   r=   rL   s     r@   
__rshift__zInfix.__rshift__       }}U##rC   c                     t        | |fd      S )Nc                &    |j                  ||       S r<   r=   rF   s      r@   rI   z#Infix.__rmatmul__.<locals>.<lambda>   rJ   rC   rK   rL   s     r@   __rmatmul__zInfix.__rmatmul__   rN   rC   c                $    | j                  |      S r<   r=   rL   s     r@   
__matmul__zInfix.__matmul__   rQ   rC   c                &    | j                  ||      S r<   r=   )r?   value1value2s      r@   __call__zInfix.__call__   s    }}VV,,rC   N)	__name__
__module____qualname__rA   rM   rP   rT   rV   rZ    rC   r@   r&   r&      s"    !P$P$-rC   r&   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@   r1   r1      s3    "001B31GHFC88VY'((rC   c                x    t        | t              r| j                  S t        | t        t        t
        f      sJ | S r<   )
isinstancer   
identifierr   r   r   things    r@   r/   r/      s4    %%&%!9:::rC   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)ro   r+   r   rp   r   r   rq   s    r@   r.   r.      sG    %(E*+%&%1 	
FN	
1 rC   c                b    t        | t              r| j                  S t        | t              sJ | S r<   )ro   r+   rp   r   rq   s    r@   r7   r7      s-    %"%(((rC   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-        tQ        | !      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        $ rE t        | tJ              r| jM                         cY S t        | t              s| jN                  cY S | cY S w xY w)"z
    Core serialization
    thing is a Class and is processed as a subject
    store is an RDFLib Graph to be queried about thing
    Nc                T    j                  |       \  }}}dj                  ||g      S rf   )rh   ri   )rG   rl   rk   rm   stores       r@   castToQNamez%manchesterSyntax.<locals>.castToQName  s.    -2-@-@-C*FC88VY$788rC      z( z AND  )r   z THAT z OR z{  z }subject	predicaterg   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rj   ))iterr2   r   r	   intersectionOfro   r   appendlenri   mapstrunionOfoneOfcomplementOfr-   objectsr
   typerc   
onPropertyrh   r   r   labelallValuesFromhasValuesomeValuesFrommaxCardinalityminCardinalitycardinalitytriples_choiceskeysr5   r   query	Exceptionr   n3rp   r   )!rr   rw   r   transientListlivechildrenchildchildren	childlistnamedrx   rl   rG   cproprk   rm   
propstringr   	onlyclassval	someclass
cardlookup_spocomplkprologqstrinitbboolpropcolqnames!    `                               r@   r2   r2      s    ;LDIJE5(6EHJ
5% 89L<Fue<T<T5 .<T   c(((IE%eV,LL'$$U+	 &
 9 u:>!GLL[%1H$IIDPF-eAh>FF"#!,,FOPiS!1!U!;<iP "MgllH+EHqCFH+EFFMM#&++x&@x!s1vx&@AADHH		!#((H#=HqCFH#=>>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RI'13CIu3UVV S==#,,=GC(24DS%4PQQ Hu@R@RSI'13CIu3UVV T OOX


 --ud:??;L6Mt.TUHB1%/ABB V u8H8HIJE/a%@AAQAGAJ?QRGH&' 	
 (#U+"[[PU[VMHceV,'UHEE W	M%*%8%8%?"FCHHfi01E eE/556LLs K4 Q ,F&@#=8 R  	M%'xxz!+5eS+A5##LuL		MsG   S5S:S?
T
T	
T
7T'(T )U&U&!U&%U&c              #     K   | j                  t        j                  t        j                        D ]   }t        |t              st	        |       " y wN)r~   object)subjectsr
   r   r	   r   ro   r   rj   r   s     r@   r$   r$   _  s9     ^^chhsyy^Aa (N Bs   AAAc                      e Zd Zd Zd Zy)TermDeletionHelperc                    || _         y r<   )r   )r?   r   s     r@   rA   zTermDeletionHelper.__init__f  s	    	rC   c                      fd}|S )Nc                j    | j                   j                  | j                  j                  d f       y r<   )rj   removerp   r   )instr?   s    r@   _removerz-TermDeletionHelper.__call__.<locals>._removerj  s$    JJt		4@ArC   r^   )r?   fr   s   `  r@   rZ   zTermDeletionHelper.__call__i  s    	B rC   Nr[   r\   r]   rA   rZ   r^   rC   r@   r   r   e  s    rC   r   c                     e Zd ZdZ e       Zd ZddZd Zd Z	d Z
d Zdd	Zdd
Z eej                         d        Z eeee      ZddZddZ eee      ZddZ	 	 ddZ eej2                        d        Z eeee      Zy)r%   zF
    A typed individual, the base class of the InfixOWL classes.

    c                    | j                   j                  | j                  d d f      D ]  }|j                  |        y r<   )factoryGraphtriplesrp   addr?   rj   facts      r@   	serializezIndividual.serializex  s4    %%--td.KLDIIdO MrC   Nc                R   |d uxr |xs
 t               | _        || j                  | _        n|| _        d | _        t        | j                  t               sC	 | j                  j                  | j                        \  }}}dj                  ||g      | _        y y # t        $ r Y y w xY wrf   )
r   _Individual__identifierr   rj   r   ro   rp   rh   ri   r   )r?   rp   rj   rl   rk   rm   s         r@   rA   zIndividual.__init__|  s    &d2AzLUW=**DJDJ
$//51)-)A)A$//)R&Y XXvy&9:
 2  s   AB 	B&%B&c                T    | j                   j                  dd| j                  f       y)za
        Remove references to this individual as an object in the
        backing store.
        Nrj   r   rp   r?   s    r@   clearInDegreezIndividual.clearInDegree  s!    
 	

4t78rC   c                T    | j                   j                  | j                  ddf       y)a&  
        Remove all statements to this individual as a subject in the
        backing store. Note that this only removes the statements
        themselves, not the blank node closure so there is a chance
        that this will cause orphaned blank nodes to remain in the
        graph.
        Nr   r   s    r@   clearOutDegreezIndividual.clearOutDegree  s!     	

4??D$78rC   c                D    | j                          | j                          y)z`
        Delete the individual from the graph, clearing the in and
        out degrees.
        N)r   r   r   s    r@   deletezIndividual.delete  s    
 	rC   c                    | j                   j                  dd| j                  f      D ]-  \  }}}| j                   j                  ||t	        |      f       / | j                          y)a  
        Replace the individual in the graph with the given other,
        causing all triples that refer to it to be changed and then
        delete the individual.

        >>> g = Graph()
        >>> b = Individual(OWL.Restriction, g)
        >>> b.type = RDFS.Resource
        >>> len(list(b.type))
        1
        >>> del b.type
        >>> len(list(b.type))
        0
        N)rj   r   rp   r   r.   r   )r?   rH   sr   _os        r@   replacezIndividual.replace  sU     

**D$+HIHAq"JJNNAq"3E":;< JrC   c              #     K   | j                   j                  | j                  t        j                        D ]  }|  y wNr|   )rj   r   rp   r
   r   r?   _ts     r@   	_get_typezIndividual._get_type  s2     **$$T__$QBH R   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 r<   )	ro   r%   r   rj   r   rp   r
   r   r.   )r?   kindr   s      r@   	_set_typezIndividual._set_type  s    dZ45JJNNDOOSXX7H7NOP!!j*%=>>>

;LQ;OPQ rC   c                     y)z
        >>> g = Graph()
        >>> b = Individual(OWL.Restriction, g)
        >>> b.type = RDFS.Resource
        >>> len(list(b.type))
        1
        >>> del b.type
        >>> len(list(b.type))
        0
        Nr^   r   s    r@   _delete_typezIndividual._delete_type       	rC   c                    | j                   S r<   )r   r   s    r@   _get_identifierzIndividual._get_identifier  s       rC   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 # t        $ r Y y w xY wrf   )r   rj   r   r   addNro   r   rh   ri   r   r   )r?   ir   r   r   oldstatements_outoldstatements_inp1o1s1rl   rk   rm   s                r@   _set_identifierzIndividual._set_identifier  s   q!!!  $zz1143D3DdD2QR!RGAq! AR  !  $zz114t?P?P2QR RGAq! AR    ,B

!!4#4#4b""=> ,*B

!!2r4+<+<"=> + !DJJOOCTUCTRaR4CTUVJJOOCSTCSRb"a4CSTU!U#)-)A)A!)D&Y XXvy&9:
 $!  VT
  s*   G  GG
G
7G 	G&%G&c              #     K   | j                   j                  | j                  t        j                        D ]  }|  y wr   )rj   r   rp   r	   sameAsr   s     r@   _get_sameAszIndividual._get_sameAs  s2     **$$T__

$SBH T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 r<   )	ro   r%   r   rj   r   rp   r	   r   r.   )r?   termr   s      r@   _set_sameAszIndividual._set_sameAs  s|    
 dZ45JJNNDOOSZZ9J49PQR!!j*%=>>>

=Nq=QRS rC   c                     y r<   r^   r   s    r@   _delete_sameAszIndividual._delete_sameAs      rC   NN)returnzIterable[_ObjectType])r   4Union[Individual, Identifier, Iterable[_ObjectType]])r   r   )r   r   )r   r  )r[   r\   r]   __doc__r   r   r   rA   r   r   r   r   r   r   r   r
   r   r   propertyr   r   rp   r   r   r	   r   r   r^   rC   r@   r%   r%   p  s    
 7L99&R ! " Iy,7D!2 /?;J
TH
T 

# $ k;?FrC   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   a
  
    Terms in an OWL ontology with rdfs:label and rdfs:comment


    ## Interface with ATTEMPTO (http://attempto.ifi.uzh.ch/site)

    ### Verbalisation of OWL entity IRIS

    #### How are OWL entity IRIs verbalized?

    The OWL verbalizer maps OWL entity IRIs to ACE content words such
    that

    - OWL individuals map to ACE proper names (PN)
    - OWL classes map to ACE common nouns (CN)
    - OWL properties map to ACE transitive verbs (TV)

    There are 6 morphological categories that determine the surface form
    of an IRI:

    - singular form of a proper name (e.g. John)
    - singular form of a common noun (e.g. man)
    - plural form of a common noun (e.g. men)
    - singular form of a transitive verb (e.g. mans)
    - plural form of a transitive verb (e.g. man)
    - past participle form a transitive verb (e.g. manned)

    The user has full control over the eventual surface forms of the IRIs
    but has to choose them in terms of the above categories.
    Furthermore,

    - the surface forms must be legal ACE content words (e.g. they
      should not contain punctuation symbols);
    - the mapping of IRIs to surface forms must be bidirectional
      within the same word class, in order to be able to (if needed)
      parse the verbalization back into OWL in a semantics preserving
      way.

    ### Using the lexicon

    It is possible to specify the mapping of IRIs to surface forms using
    the following annotation properties:

    .. code-block:: none

        http://attempto.ifi.uzh.ch/ace_lexicon#PN_sg
        http://attempto.ifi.uzh.ch/ace_lexicon#CN_sg
        http://attempto.ifi.uzh.ch/ace_lexicon#CN_pl
        http://attempto.ifi.uzh.ch/ace_lexicon#TV_sg
        http://attempto.ifi.uzh.ch/ace_lexicon#TV_pl
        http://attempto.ifi.uzh.ch/ace_lexicon#TV_vbg

    For example, the following axioms state that if the IRI "#man" is used
    as a plural common noun, then the wordform men must be used by the
    verbalizer. If, however, it is used as a singular transitive verb,
    then mans must be used.

    .. code-block:: none

        <AnnotationAssertion>
            <AnnotationProperty IRI="http://attempto.ifi.uzh.ch/ace_lexicon#CN_pl"/>
            <IRI>#man</IRI>
            <Literal datatypeIRI="&xsd;string">men</Literal>
        </AnnotationAssertion>

        <AnnotationAssertion>
            <AnnotationProperty IRI="http://attempto.ifi.uzh.ch/ace_lexicon#TV_sg"/>
            <IRI>#man</IRI>
            <Literal datatypeIRI="&xsd;string">mans</Literal>
        </AnnotationAssertion>

    c                    t         t        |   ||       |rI| j                          | j                  | j                  |      fg| j                  _        |r	|g| _        y y y r<   )	superr   rA   setupACEAnnotationsrp   handleAnnotation	PN_sgpropextentr   )r?   rp   rj   nameAnnotationnameIsLabel	__class__s        r@   rA   zAnnotatableTerms.__init__V  sd     	.z5A$$&$"7"7"GH%DNN! ,-
  rC   c                <    t        |t              r|S t        |      S r<   )ro   r   )r?   r   s     r@   r  z!AnnotatableTerms.handleAnnotationf  s     g.s@GCL@rC   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)baseTyperj   )rj   bindr   r+   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.setupACEAnnotationsi  s    

v6 "LL3#9#9

 "LL3#9#9

 "LL3#9#9

 "LL3#9#9

 "LL3#9#9

 #MMC$:$:$**
rC   c              #     K   | j                   j                  | j                  t        j                        D ]  }|  y wr   )rj   r   rp   r   comment)r?   r"  s     r@   _get_commentzAnnotatableTerms._get_comment  8     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 r<   )ro   r   rj   r   rp   r   r"  )r?   r"  r   s      r@   _set_commentzAnnotatableTerms._set_comment  sZ    gz*JJNNDOOT\\7CD

qAB rC   c                     y r<   r^   r   s    r@   _del_commentzAnnotatableTerms._del_comment  r   rC   c              #     K   | j                   j                  | j                  t        j                        D ]  }|  y wr   )rj   r   rp   r   seeAlso)r?   seealsos     r@   _get_seealsozAnnotatableTerms._get_seealso  r$  r   c                    |sy |D ]8  }| j                   j                  | j                  t        j                  |f       : y r<   )rj   r   rp   r   r*  )r?   seealsosr   s      r@   _set_seealsozAnnotatableTerms._set_seealso  s1    AJJNNDOOT\\1=> rC   c                     y r<   r^   r   s    r@   _del_seealsozAnnotatableTerms._del_seealso  r   rC   c              #     K   | j                   j                  | j                  t        j                        D ]  }|  y wr   )rj   r   rp   r   r   )r?   r   s     r@   
_get_labelzAnnotatableTerms._get_label  s2     ZZ''4::'VEK Wr   c                   |sy t        |t              r7| j                  j                  | j                  t
        j                  |f       y |D ]8  }| j                  j                  | j                  t
        j                  |f       : y r<   )ro   r   rj   r   rp   r   r   )r?   r   l_s      r@   
_set_labelzAnnotatableTerms._set_label  sZ    eZ(JJNNDOOTZZ?@

R@A rC   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
        Nr^   r   s    r@   _delete_labelzAnnotatableTerms._delete_label  r   rC   )NNF)r[   r\   r]   r  rA   r  r  r#  r&  r   r   r"  r(  r  r,  r/  r*  r1  r3  r6  r   r8  __classcell__r  s   @r@   r   r     s    GX . A
BC % & |\<@G? % & |\<@GB 

# $ Z];ErC   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                R   t         t        |   ||       |g n|| _        |g n|| _        | j
                  t        j                  t        j                  f| j                  vrE| j                  j                  | j
                  t        j                  t        j                  f       y y r<   )r  r*   rA   importsr"  rp   r
   r   r	   rj   r   )r?   rp   r=  r"  rj   r  s        r@   rA   zOntology.__init__  sv    h&z59$_r'$_r'OOSXXs||4DJJFJJNNDOOSXXs||DE GrC   c                p    | j                   j                  | j                  t        j                  |f       y r<   )rj   setrp   r	   versionInfo)r?   versions     r@   
setVersionzOntology.setVersion  s!    

'BCrC   c              #  z   K   | j                   j                  | j                  t        d         D ]  }|  y w)Nr=  r|   )rj   r   rp   r	   )r?   rb   s     r@   _get_importszOntology._get_imports  s8     ::%%OOs9~ & 
C I
s   9;c                v    |sy |D ]1  }| j                   j                  | j                  t        d   |f       3 y )Nr=  )rj   r   rp   r	   )r?   rH   r   s      r@   _set_importszOntology._set_imports  s1    AJJNNDOOS^Q?@ rC   r=  c                     y r<   r^   r   s    r@   _del_importszOntology._del_imports  r   rC   )NNNN)r[   r\   r]   r  rA   rB  rD  rF  r   r	   rH  r  r=  r9  r:  s   @r@   r*   r*     sJ    #FDA I' ( |\<@GrC   r*   c              #     K   t        | j                  t        j                  t        j
                              D ]  }t        |        y wr   )r?  r   r
   r   r	   r   r   s     r@   r   r     s4     #((399EFAh Gs   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rj   r  )r?  r   r
   r   r	   SymmetricPropertyFunctionalPropertyInverseFunctionalPropertyTransitivePropertyDatatypePropertyObjectPropertyr  r   r+   )rj   	prevpropsr   _pr   bTypes         r@   r   r     s     I))HH%%&&--&&$$""&&	
2q !!))""	
 
 &&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 r<   )r   r   r?   names     r@   r   zClassNamespaceFactory.term  s    VD4K())rC   Nc                $    | j                  |      S r<   )r   )r?   keydefaults      r@   __getitem__z!ClassNamespaceFactory.__getitem__  s    yy~rC   c                R    |j                  d      rt        | j                  |      S )N__)
startswithAttributeErrorr   rW  s     r@   __getattr__z!ClassNamespaceFactory.__getattr__  s"    ??4   99T?"rC   r<   )r[   r\   r]   r   r\  ra  r^   rC   r@   r   r     s    *#rC   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# t        $ r Y yw 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	   r-   r   r   r%   r   r   rp   r   r   r   ro   r   r!   r   r   
subClassOfr.   r   )clsr   rS  inner_class_idinner_class_c_clsr   s           r@   r!   r!   5  s    
 #(("	C!8!89C*-*:*:*J*J#"3"3S5G5G!H$O+&B $N4Pne4,[9  : &%+ Z445c<(T$?doou5,T2  3 J   #~~k44e<,[9  : &%  . !--=="3'$?	B a',Yq*:Q:Q-RS  T &%'  		s*   G;BG, ?D-G;,	G85G;7G88G;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)a  
    Recursively clear the given class, continuing
    where any related class is an anonymous class

    >>> EX = Namespace("http://example.com/")
    >>> g = Graph()
    >>> g.bind("ex", EX, override=False)
    >>> 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
    >>> classF += anonClass
    >>> list(anonClass.subClassOf)
    [Class: ex:F ]
    >>> classA = classE | classF | anonClass
    >>> classB += classA
    >>> classA.equivalentClass = [Class()]
    >>> classB.subClassOf = [EX.someProp @ some @ classC]
    >>> classA
    ( ex:E OR ex:F OR ( ex:someProp SOME ex:D ) )
    >>> DeepClassClear(classA)
    >>> classA
    (  )
    >>> list(anonClass.subClassOf)
    []
    >>> classB
    Class: ex:B SubClassOf: ( ex:someProp SOME ex:C )

    >>> otherClass = classD | anonClass
    >>> otherClass
    ( ex:D OR ( ex:someProp SOME ex:D ) )
    >>> DeepClassClear(otherClass)
    >>> otherClass
    (  )
    >>> otherClass.delete()
    >>> list(g.triples((otherClass.identifier, None, None)))
    []
    c                N    t        t        |       t              rt        |        y y r<   )ro   r.   r   r"   )_classs    r@   deepClearIfBNodez(DeepClassClear.<locals>.deepClearIfBNode  s    '/76" 8rC   N)r   r%   r   re  rj   r   rp   r   equivalentClassr	   r   ro   r   clear	_operator)class_to_prunern  r   inverse_classs       r@   r"   r"   c  s.   V# ~z/F/FGN&& '!:!:DOOT RS++ ,!:!:C<O<OQU VW"//M##^%>%>@P@PRV$WX'.,/AQ  ##&&(@(@$G	
	 0rC   c                      e Zd ZdZy)r'   zc
    .. deprecated:: TODO-NEXT-VERSION
       This class will be removed in version ``7.0.0``.
    N)r[   r\   r]   r  r^   rC   r@   r'   r'     s    
 	rC   r'   c                      e Zd Zd Zd Zy)r(   c                    || _         y r<   msg)r?   rx  s     r@   rA   zMalformedClassError.__init__  s	    rC   c                    | j                   S r<   rw  r   s    r@   __repr__zMalformedClassError.__repr__  s    xxrC   N)r[   r\   r]   rA   rz  r^   rC   r@   r(   r(     s    rC   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 )Nr|   )rp   rj   r   zMalformed owl:Restrictionr   )operatorrj   Trj   rd  r^   )r   r   r.   r
   r   r	   r-   r   r   restrictionKindsr   splitr?  intersectionr(   r   r   r   r   r#   r   r   )	r   rj   r   kwargsr   r   r   r   r   s	            r@   r   r     s   TM,ann5E&7&:chhO3??"$5a$85IF!MM+<Q+?t*LMAq=CNN*/0|,K$@$@@$=>s1773s8#4R#89: N 5@5Q5QR5QQWWSX&r*+5QRl6"# **EFF((("22%a(''cii@	Ar 		>*+<Q+?uMM'(9!(<qPUVV *1-USWXX; P 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# Z3d'd$Z4 xZ5S )(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 r<   )re  r   rj   r   ro  disjointWithr   )r?   rj   cls      r@   
_serializezClass._serialize  s    //Bb$**%//6 "&&Bb$**%//6 '##Bb$**%//6 $d''4>>uE rC   c                    | j                   j                  | j                  d d f      D ]  }|j                  |        | j	                  |       y r<   )rj   r   rp   r   r  r   s      r@   r   zClass.serialize  s>    JJ&&t'DEDIIdO FrC   c                    t        |t              r|\  }}n|}|}|r-| j                  | j                  |      fg| j                  _        |r.| j                  | j                  |      fg| j                  _        y y r<   )ro   tuplerp   r  r  r
  r  )r?   noun_annotations	cn_sgprop	cn_plprops       r@   setupNounAnnotationszClass.setupNounAnnotations  sx    &.#3 Iy(I(I$"7"7	"BC%DNN! $"7"7	"BC%DNN! rC   c                6   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       |g n|| _        |g n|| _        |g n|| _        |r|| _        |g | _        y || _        y r<   )r  r   rA   r  rp   r
   r   r	   rj   r-   r   re  ro  r  r   r"  )r?   rp   re  ro  r  r   rj   rd  r"  nounAnnotationsr  r  r  s               r@   rA   zClass.__init__  s     	eT#J~{S%%o6&#((CII6djjH#((COO<DJJNJJNNDOOSXXsyyAB * 2"
%4%<r/"."6BL ,D$_r'rC   c              #     K   |d u xr | j                   xs |j                  t        j                  | j                        D ]  }|  y wr   )rj   r   r
   r   rp   )r?   rj   members      r@   _get_extentzClass._get_extent6  sG     }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 r<   )rj   r   r.   r
   r   rp   )r?   rH   ms      r@   _set_extentzClass._set_extent<  s7    AJJNN-a0#((DOOLM rC   c                     y r<   r^   r   s    r@   	_del_typezClass._del_typeB  r   rC   c              #  l   K   | j                   j                  | j                  |      D ]  }|  y wr   )rj   r   rp   )r?   r   
annotations      r@   _get_annotationzClass._get_annotationH  s0     **,,T__PT,UJ Vs   24c                    | S r<   r^   )rG   s    r@   rI   zClass.<lambda>L  s    QrC   c                N    t        d      t        j                  | j                  fS )NCLASS)r   r
   r   rp   r   s    r@   _get_extentqueryzClass._get_extentqueryN  s    !388T__==rC   c                     y r<   r^   rL   s     r@   _set_extentqueryzClass._set_extentqueryQ  s    rC   c                ,    t        | j                        S )z}
        >>> b = Class(OWL.Restriction)
        >>> c = Class(OWL.Restriction)
        >>> len(set([b,c]))
        1
        )hashrp   r   s    r@   __hash__zClass.__hash__V  s     DOO$$rC   c                t    t        |t              sJ t        |             | j                  |j                  k(  S r<   )ro   r   reprrp   rL   s     r@   __eq__zClass.__eq___  s0    %'4e4'%"2"222rC   c                :    t        |t              sJ | g|_        | S r<   )ro   r   re  rL   s     r@   __iadd__zClass.__iadd__c  s!    %''' 6rC   c                    t        |t              sJ | j                  j                  t	        |      t
        j                  | j                  f       | S r<   )ro   r   rj   r   r.   r   re  rp   rL   s     r@   __isub__zClass.__isub__h  s>    %'''

,U3T__dooVWrC   c                    t        |       S )z@
        Shorthand for Manchester syntax's not operator
        )r   )r   r   s    r@   
__invert__zClass.__invert__m  s     $''rC   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
        r}  membersrj   )r   r	   r   rj   rL   s     r@   __or__zClass.__or__s  s$    
 [[4-tzz
 	
rC   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

        Chaining 3 intersections

        >>> exNs = Namespace("http://example.com/")
        >>> g = Graph()
        >>> g.bind("ex", exNs, override=False)
        >>> 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   rj   rL   s     r@   __and__zClass.__and__|  s&    * ''$djj
 	
rC   c              #     K   | j                   j                  | j                  t        j                        D ]  }t        || j                   d        y w)Nr|   Tr~  )rj   r   rp   r   re  r   r?   ancs     r@   _get_subclassofzClass._get_subclassof  sF     ::%%OOt & 
C 4::dKK
   AAc                    |sy |D ]A  }| j                   j                  | j                  t        j                  t        |      f       C y r<   )rj   r   rp   r   re  r.   r?   rH   scs      r@   _set_subclassofzClass._set_subclassof  s8    BJJNNDOOT__>OPR>STU rC   c                     y r<   r^   r   s    r@   _del_subclassofzClass._del_subclassof  r   rC   c              #     K   | j                   j                  | j                  t        j                        D ]  }t        || j                           y wNr|   r   )rj   r   rp   r	   ro  r   )r?   ecs     r@   _get_equivalentclasszClass._get_equivalentclass  sF     **$$OOs/B/B % 
B $**--
   AAc                    |sy |D ]A  }| j                   j                  | j                  t        j                  t        |      f       C y r<   )rj   r   rp   r	   ro  r.   r  s      r@   _set_equivalentclasszClass._set_equivalentclass  s<    BJJNN#"5"57H7LM rC   c                     y r<   r^   r   s    r@   _del_equivalentclasszClass._del_equivalentclass  r   rC   c              #     K   | j                   j                  | j                  t        j                        D ]  }t        || j                           y wr  )rj   r   rp   r	   r  r   )r?   rd   s     r@   _get_disjointwithzClass._get_disjointwith  sF     **$$OOs/?/? % 
B $**--
r  c                    |sy |D ]A  }| j                   j                  | j                  t        j                  t        |      f       C y r<   )rj   r   rp   r	   r  r.   )r?   rH   r   s      r@   _set_disjointwithzClass._set_disjointwith  s:    AJJNNDOOS-=-=?PQR?STU rC   c                     y r<   r^   r   s    r@   _del_disjointwithzClass._del_disjointwith  r   rC   c                    t        | j                  j                  | j                  t        j
                              }|sy t        |      dk(  rt        |d   | j                        S t        t        |            )Nr|   ry   r   r   )	rc   rj   r   rp   r	   r   r   r   r   )r?   comps     r@   _get_complementofzClass._get_complementof  sd    JJt#BRBRS
 Y!^a

33CI&&rC   c                    |sy | j                   j                  | j                  t        j                  t        |      f       y r<   )rj   r   rp   r	   r   r.   rL   s     r@   _set_complementofzClass._set_complementof  s/    

)9)9;LU;STUrC   c                     y r<   r^   r   s    r@   _del_complementofzClass._del_complementof  r   rC   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)a  
        computed attributes that returns a generator over taxonomic 'parents'
        by disjunction, conjunction, and subsumption

        >>> from rdflib.util import first
        >>> exNs = Namespace('http://example.com/')
        >>> g = Graph()
        >>> g.bind("ex", exNs, override=False)
        >>> Individual.factoryGraph = g
        >>> brother = Class(exNs.Brother)
        >>> sister = Class(exNs.Sister)
        >>> sibling = brother | sister
        >>> sibling.identifier = exNs.Sibling
        >>> sibling
        ( ex:Brother OR ex:Sister )
        >>> first(brother.parents)
        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)
        [Class: ex:Parent , Class: ex:Male ]

        r|  Trc  r   N)	itertoolschainre  ro  r   r   r   r
   rp   rc   transitive_subjectsrestr	   r   ro   r   r   r   r   r)   )r?   parentlinksiblingslistcollectionheaddisjointclassrdf_listr  s           r@   _get_parentszClass._get_parents  s#    4  oodoot7K7KLFL M T&&//		4??KL 1 1 E EchhPT UVL!-b!1!%!%!2!2!;!;^" mV4dKK	"
 ))11$//3CUCUVH)8*D<M<MNff-tDD O W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)rp   r
   r   r	   r-   rj   rc   ro  r   r   r   r   r2   r   )r?   r  
_boolclassr   r  _es         r@   isPrimitivezClass.isPrimitive  s    OOSXXs74::E$&&''+zz'A'A__s113;;?F(
#J8 II&xQGH	(

 B rC   c              #     K   | j                   j                  t        j                  | j                        D ]  }|  y wr   )rj   r   r   re  rp   )r?   r   s     r@   subSumpteeIdszClass.subSumpteeIds+  s2     $$tt$WAG Xr   c                (    | j                  dd      S )NFT)fullnormalization)manchesterClassr   s    r@   rz  zClass.__repr__4  s    ##d#CCrC   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
    r|  zA Defined Class %szEquivalentTo: %szDisjointWith %s
z
                 z
    ## %s ##z
    %sz . zSome Class z
Class: %s )rc   re  ro  rj   r   rp   r	   r   r   r   r2   r  r   r   r   r   ro   r   r   r  r   r.   ri   r   r"  r   )r?   r  r  exprsr  r  r  r   r  rd   r   	klasskindr   scjoinr   nec_statementsnnec_suff_statementsdescr
klassdescrs                       r@   r  zClass.manchesterClass7  s    $//"$&&''+zz'A'A__s113;;?F(
#J8 II&xQGH	(

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

5))  t. )djj(	 	m
 0P
# Us   6A5N0N5<N:&N?)NNNNNNFNNNFr<   )FT)6r[   r\   r]   r  r  r   r  rA   r  r  r   r
   r   r  r  r
  r   r   r  r  r  r  extentQueryr  r  r  r  r  r  r  r  r  re  r  r  r  r	   ro  r  r  r  r  r  r  r  r   r  r  parentsr  r  rz  r  r9  r:  s   @r@   r   r     s   :F
$ $:@N ! " k;	:F#'::  /;7J> +-=>K%3

(

2LV ( ) /J. ++, - 24HO.V (() * ,.?L	'V
 (() * ,.?L,E\ |$G DTrC   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)r)   Nc           
        |r|| _         |g n|}|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   )
rj   r   _rdfListr   r.   r   r   rp   rq  rk   )r?   r  r  rj   r  r  s         r@   rA   zOWLRDFListProxy.__init__  s    DJ"W&tzz8A;?DM!.MM(():6)BC " '

EGG%LGq&7&:G%LDM
 JJNNDOOT^^T]]=N=NOP	 &Ms   C-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)ro   r   r  r   r   r   rangerp   )r?   rH   lengthidxs       r@   r  zOWLRDFListProxy.__eq__  s    
 %'HetDK7H)HH'e\*YFU# =CCyE#J.$ ) ??e&6&666rC   c                ,    t        | j                        S r<   )r   r  r   s    r@   __len__zOWLRDFListProxy.__len__  s    4==!!rC   c                J    | j                   j                  t        |            S r<   )r  indexr.   r?   items     r@   r  zOWLRDFListProxy.index  s    }}""#4T#:;;rC   c                     | j                   |   S r<   r  r?   rZ  s     r@   r\  zOWLRDFListProxy.__getitem__  s    }}S!!rC   c                4    t        |      | j                  |<   y r<   )r.   r  )r?   rZ  r9   s      r@   __setitem__zOWLRDFListProxy.__setitem__  s    .u5crC   c                    | j                   |= y r<   r  r	  s     r@   __delitem__zOWLRDFListProxy.__delitem__  s    MM#rC   c                8    | j                   j                          y r<   )r  rp  r   s    r@   rp  zOWLRDFListProxy.clear  s    rC   c              #  6   K   | j                   D ]  }|  y wr<   r  r  s     r@   __iter__zOWLRDFListProxy.__iter__  s     MMDJ "s   c                F    | j                   D ]  }|t        |      k(  s y y)Nry   r   )r  r.   )r?   r  r   s      r@   __contains__zOWLRDFListProxy.__contains__  s&    A%d++  rC   c                :    | j                   j                  |       y r<   )r  r   r  s     r@   r   zOWLRDFListProxy.append  s    T"rC   c                N    | j                   j                  t        |             | S r<   )r  r   r.   rL   s     r@   r  zOWLRDFListProxy.__iadd__  s    .u56rC   r   )r[   r\   r]   rA   r  r  r  r\  r  r  rp  r  r  r   r  r^   rC   r@   r)   r)     s?    Q"7("<"6#rC   r)   c                  B    e Zd ZdZej
                  Zd ZddZd Z	d Z
y)r#   a  
    Class for owl:oneOf forms:

    OWL Abstract Syntax is used

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

    >>> exNs = Namespace("http://example.com/")
    >>> g = Graph()
    >>> g.bind("ex", exNs, override=False)
    >>> 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)))
    >>> sorted([g.qname(item) for item in col])
    ['ex:chime', 'ex:ejike', 'ex:uche']
    >>> 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NFr^   r   s    r@   r  zEnumeratedClass.isPrimitive      rC   Nc                    t         j                  | ||       |g n|}t        | j                  j	                  t
        j                  | j                              }t        j                  | ||       y )Nr   r~   r}   )	r   rA   rc   rj   r   r	   r   rp   r)   )r?   rp   r  rj   rdfLists        r@   rA   zEnumeratedClass.__init__  s\    tZu5"WJJDOOL
 	  w8rC   c                n    t        | j                  j                  | j                  | j                        S r  r   )r2   r  rk   rj   rq  r   s    r@   rz  zEnumeratedClass.__repr__  s%       1 14::t~~VVrC   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 r<   r   r   r  r   r   rj   r   r   rp   rq  rk   r   r  r?   rj   
clonedlistr  r   r   r   s          r@   r   zEnumeratedClass.serialize  s    uw/
--Bb!b$**%//6   			4??DNNJNNCDzz))4??D$*GHGAq!DNN"		1a)$ I 	rC   )NNN)r[   r\   r]   r  r	   r   rq  r  rA   rz  r   r^   rC   r@   r#   r#     s(    B 		I9W
rC   r#   c                      e Zd ZdZd Zd Zy)BooleanClassExtentHelpera`  
    >>> testGraph = Graph()
    >>> Individual.factoryGraph = testGraph
    >>> EX = Namespace("http://example.com/")
    >>> testGraph.bind("ex", EX, override=False)
    >>> 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 r<   r}  )r?   r}  s     r@   rA   z!BooleanClassExtentHelper.__init__0  rB   rC   c                      fd}|S )Nc               3     K   t         j                  j                  j                        D ]  } t	        | j                          y w)Nr%  )r%   r   r   r}  r   )r   r?   s    r@   
_getExtentz5BooleanClassExtentHelper.__call__.<locals>._getExtent4  s8     ,,55dmmD"1t}}== Es   A	Ar^   )r?   r   r(  s   `  r@   rZ   z!BooleanClassExtentHelper.__call__3  s    	> rC   N)r[   r\   r]   r  rA   rZ   r^   rC   r@   r#  r#    s    $!rC   r#  c                      e Zd Zd Zd Zy)r   c                    || _         y r<   _callfn)r?   anycallables     r@   rA   zCallable.__init__<  s	    "rC   c                &     | j                   |i |S r<   r+  )r?   argsr  s      r@   rZ   zCallable.__call__?  s    t||T,V,,rC   Nr   r^   rC   r@   r   r   ;  s    #-rC   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 r<   r^   r^   rC   r@   getIntersectionszBooleanClass.getIntersectionsK       	rC   c                      y r<   r^   r^   rC   r@   	getUnionszBooleanClass.getUnionsR  r3  rC   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	|	rJ d       t        j                  | |	|       y )Nry   r   r  z-This is a previous boolean class description.)r   r	   r   r   r   r   r  r   rA   r   rq  rc   rj   r   rp   r)   )
r?   rp   r}  r  rj   propsr   r   r   r  s
             r@   rA   zBooleanClass.__init__Y  s     E"22c00#++>E	Ar Q	
 u:?/DK/?tZu5C..<<Kc(mK<!

**Xt*WXx	;:	;'  x9rC   c                \    t        | j                  t        |       | j                        }|S )z-
        Create a copy of this class
        r  )r   rq  rc   rj   )r?   copy_of_classs     r@   copyzBooleanClass.copym  s)     %^^T$Ztzz
 rC   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 r<   r  r   s          r@   r   zBooleanClass.serializev  s    uw/
--Bb!b$**%//6   			4??DNNJNNCDzz))4??D$*GHGAq!DNN"		1a)$ I 	rC   c                     yr  r^   r   s    r@   r  zBooleanClass.isPrimitive  r  rC   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/")
        >>> testGraph.bind("ex", EX, override=False)
        >>> fire = Class(EX.Fire)
        >>> water = Class(EX.Water)
        >>> testClass = BooleanClass(members=[fire,water])
        >>> testClass
        ( ex:Fire AND ex:Water )
        >>> testClass.changeOperator(OWL.unionOf)
        >>> testClass
        ( ex:Fire OR ex:Water )
        >>> try:
        ...     testClass.changeOperator(OWL.unionOf)
        ... except Exception as e:
        ...     print(e)  # doctest: +SKIP
        The new operator is already being used!

        z'The new operator is already being used!N)rq  rj   r   rp   r  rk   r   )r?   newOperators     r@   changeOperatorzBooleanClass.changeOperator  ss    0 dnn,W.WW,

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

dmm6G6GHI$rC   c                    t        t        | j                  t              r| j                  j                  n	t               | j                  | j                        S r  )r2   ro   r  r   rk   r   rj   rq  r   s    r@   rz  zBooleanClass.__repr__  s=      !+DMM:!FDMMEGJJNN
 	
rC   c                    | j                   t        j                  k(  sJ | j                  j	                  t        |             | S )z9
        Adds other to the list and returns self
        )rq  r	   r   r  r   r.   rL   s     r@   r  zBooleanClass.__or__  s7     ~~,,,.u56rC   )r[   r\   r]   r  r#  r	   r   r   r2  r   r5  rA   r:  r   r  r?  rz  r  r^   rC   r@   r   r   C  s     c001  2   01ckk*  + #I (:(:DPT:(%:
rC   r   c                     y)zk
    TODO: implement this function

    DisjointClasses(' description description { description } ')'

    Nr^   )r  s    r@   r   r     s     	rC   c                      e Zd ZdZej
                  ej                  ej                  ej                  ej                  ej                  gZ	 	 	 	 	 	 	 	 d 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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* xZ+S )r-   z
    restriction ::= 'restriction('
    datavaluedPropertyID dataRestrictionComponent
    { dataRestrictionComponent } ')'
    | 'restriction(' individualvaluedPropertyID
    individualRestrictionComponent
    { individualRestrictionComponent } ')'

    c
                   |
t               n|}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]  \  }}|	||f }}}t        |      st!        d      |j#                         \  }}|| _        t'        |t(              r|| _        nUt'        |t,              rt/        |      | _        n4t1        | j2                  j5                  | j                  |            | _        | j                  || j*                  f| j2                  vr2| j2                  j                  | j                  || j*                  f       | j*                  J t-        | j                               | j                  t6        j8                  t
        j                  f| j2                  vr| j2                  j                  | j                  t6        j8                  t
        j                  f       | j2                  j;                  | j                  t6        j8                  t
        j,                  f       y y c c}}w )NTr~  z{Missing value. One of: allValuesFrom, someValuesFrom,value, cardinality, maxCardinality or minCardinalitymust have a value.)r   r  r-   rA   rp   r	   r   r7   r   r   r   r   r   r   r   r   
ValueErrorpoprestrictionTypero   r   restrictionRanger   r.   r   rj   r   r
   r   r   )r?   r   rj   r   r   r9   r   r   r   rp   restr_typesr   otermvalid_restr_propsrestriction_rangerestriction_typer  s                   r@   rA   zRestriction.__init__  sl    !=ek4)eD 	* 	
 OONN ,
 	
 II#..2Fz2RS %C--.S//0CLL!#//*S//0S//0
 ;FW+JQaZ+W$%% 
 /@.C.C.E++/'4$5D!)51$56G$HD! %*

""4??4DE%D!
 OO!!
 	
 JJNNDOO-=t?T?TUV$$0H%2HH0OOSXXs7tzzIJJNNDOOSXXsGHJJt#))DE J5 Xs   7
K&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/")
        >>> g1.bind("ex", EX, override=False)
        >>> g2.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(
            'http://www.w3.org/2002/07/owl#DatatypeProperty')]
        NrK  )r+   r   rj   r   r   rp   r   r	   r   r   r   )r?   rj   r   r   r   s        r@   r   zRestriction.serialize  s    , 	

TBLLUSzz))4??D$*GHGAq!IIq!Qi S&&(:(:;;!TZZ(2259 IrC   c                     yr  r^   r   s    r@   r  zRestriction.isPrimitive/  r  rC   c                D    t        | j                  | j                  f      S r<   )r  r   rH  r   s    r@   r  zRestriction.__hash__2  s    T__d&;&;<==rC   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)ro   r   r  r   r-   r   rL  rH  rL   s     r@   r  zRestriction.__eq__5  sk    
 %'HetDK7H)HH'e[)  DOO3 E++t/D/DD rC   c                    t        | j                  j                  | j                  t        j
                              d   S )Nr|   r   )rc   rj   r   rp   r	   r   r   s    r@   _get_onpropertyzRestriction._get_onpropertyD  s6    JJt#..Q

 	rC   c                    |sy | j                   t        j                  t        |      f}|| j                  v ry | j                  j                  |       y r<   )rp   r	   r   r7   rj   r?  )r?   r   triples      r@   _set_onpropertyzRestriction._set_onpropertyI  sA    //3>>3G3MNTZZJJNN6"rC   c                     y r<   r^   r   s    r@   _del_onpropertyzRestriction._del_onpropertyR  r   rC   c                    | j                   j                  | j                  t        j                        D ]  }t        || j                         c S  y r  )rj   r   rp   r	   r   r   r?   r   s     r@   _get_allvaluesfromzRestriction._get_allvaluesfromZ  sG    ##OOs/@/@ $ 
A $**--
 rC   c                    |sy | j                   t        j                  t        |      f}|| j                  v ry | j                  j                  |       y r<   )rp   r	   r   r.   rj   r?  r?   rH   rU  s      r@   _set_allvaluesfromzRestriction._set_allvaluesfroma  sC    //3#4#46G6NOTZZJJNN6"rC   c                     y r<   r^   r   s    r@   _del_allvaluesfromzRestriction._del_allvaluesfromj  r   rC   c                    | j                   j                  | j                  t        j                        D ]  }t        || j                         c S  y r  )rj   r   rp   r	   r   r   rZ  s     r@   _get_somevaluesfromzRestriction._get_somevaluesfromr  G    ##OOs/A/A $ 
A $**--
 rC   c                    |sy | j                   t        j                  t        |      f}|| j                  v ry | j                  j                  |       y r<   )rp   r	   r   r.   rj   r?  r]  s      r@   _set_somevaluesfromzRestriction._set_somevaluesfromy  C    //3#5#57H7OPTZZJJNN6"rC   c                     y r<   r^   r   s    r@   _del_somevaluesfromzRestriction._del_somevaluesfrom  r   rC   c                    | j                   j                  | j                  t        j                        D ]  }t        || j                         c S  y r  )rj   r   rp   r	   r   r   rZ  s     r@   _get_hasvaluezRestriction._get_hasvalue  s=    ##DOOs||#TA$**-- UrC   c                    |sy | j                   t        j                  t        |      f}|| j                  v ry | j                  j                  |       y r<   )rp   r	   r   r.   rj   r?  r]  s      r@   _set_hasvaluezRestriction._set_hasvalue  sA    //3<<1B51IJTZZJJNN6"rC   c                     y r<   r^   r   s    r@   _del_hasvaluezRestriction._del_hasvalue  r   rC   c                    | j                   j                  | j                  t        j                        D ]  }t        || j                         c S  y r  )rj   r   rp   r	   r   r   rZ  s     r@   _get_cardinalityzRestriction._get_cardinality  s=    ##DOOs#WA$**-- XrC   c                    |sy | j                   t        j                  t        |      f}|| j                  v ry | j                  j                  |       y r<   )rp   r	   r   r/   rj   r?  r]  s      r@   _set_cardinalityzRestriction._set_cardinality  s@    //3??K4FGTZZJJNN6"rC   c                     y r<   r^   r   s    r@   _del_cardinalityzRestriction._del_cardinality  r   rC   c                    | j                   j                  | j                  t        j                        D ]  }t        || j                         c S  y r  )rj   r   rp   r	   r   r   rZ  s     r@   _get_maxcardinalityzRestriction._get_maxcardinality  rc  rC   c                    |sy | j                   t        j                  t        |      f}|| j                  v ry | j                  j                  |       y r<   )rp   r	   r   r/   rj   r?  r]  s      r@   _set_maxcardinalityzRestriction._set_maxcardinality  sB    //3#5#5{57IJTZZJJNN6"rC   c                     y r<   r^   r   s    r@   _del_maxcardinalityzRestriction._del_maxcardinality  r   rC   c                    | j                   j                  | j                  t        j                        D ]  }t        || j                         c S  y r  )rj   r   rp   r	   r   r   rZ  s     r@   _get_mincardinalityzRestriction._get_mincardinality  rc  rC   c                    |sy | j                   t        j                  t        |      f}|| j                  v ry | j                  j                  |       y r<   )rp   r	   r   r.   rj   r?  r]  s      r@   _set_mincardinalityzRestriction._set_mincardinality  rf  rC   c                     y r<   r^   r   s    r@   _del_mincardinalityzRestriction._del_mincardinality  r   rC   c                    | j                   j                  | j                  | j                  d f      D ](  \  }}}|j	                  t        t                    d   c S  y )Nr|  )rj   r   rp   r  r  r   r	   )r?   r   r   r   s       r@   restrictionKindzRestriction.restrictionKind  sT    zz11__d33T:
GAq!
 773s8$R((
 rC   c                B    t        | j                  | j                        S )zO
        Returns the Manchester Syntax equivalent for this restriction
        )r2   rp   rj   r   s    r@   rz  zRestriction.__repr__  s      <<rC   )NNNNNNNN),r[   r\   r]   r  r	   r   r   r   r   r   r   r  rA   r   r  r  r  rS  rV  r   r   rX  r  r[  r^  r`  rb  re  rh  rj  rl  rn  rp  rr  rt  rv  rx  rz  r|  r~  r  r  rz  r9  r:  s   @r@   r-   r-     s&    	 =F~:8>
# ' ( /J# ))* + .0BM# **+ , 02EN
# % & }mDH
# ( ) +-=?OPK# **+ , 02EN# **+ , 02EN=rC   r-   c                2    t        | |j                  |      S )N)rj   r   r-   rj   r   rm  s     r@   rI   rI     s    TfUrC   c                2    t        | |j                  |      S )N)rj   r   r  r  s     r@   rI   rI     s    TVTrC   c                2    t        | | j                  |      S )N)rj   r   r  r  s     r@   rI   rI         TFSrC   c                2    t        | | j                  |      S )N)rj   r   r  r  s     r@   rI   rI     r  rC   c                2    t        | | j                  |      S )N)rj   r   r  r  s     r@   rI   rI     s    TPrC   c                2    t        | | j                  |      S )N)rj   r9   r  r  s     r@   rI   rI     s    ;t4::V#TrC   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 )r+   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)a  

        OWL properties map to ACE transitive verbs (TV)

        There are 6 morphological categories that determine the surface form
        of an IRI:

            singular form of a transitive verb (e.g. mans)
            plural form of a transitive verb (e.g. man)
            past participle form a transitive verb (e.g. manned)

            http://attempto.ifi.uzh.ch/ace_lexicon#TV_sg
            http://attempto.ifi.uzh.ch/ace_lexicon#TV_pl
            http://attempto.ifi.uzh.ch/ace_lexicon#TV_vbg

        N)ro   r  rp   r  r  r
  r  r   )r?   verb_annotationsr  r  tv_vbgs        r@   setupVerbAnnotationszProperty.setupVerbAnnotations  s    $ &.+;(Iy&(I(I%F$"7"7	"BC%DNN! $"7"7	"BC%DNN! '+8M8Mf8U&V%WDOO" rC   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       || _        || _        || _        || _        || _        |
g | _        y |
| _        y )Nr   )r  r+   rA   r  ro   rp   r   r   r%   rj   r   	_baseTyper
   r   subPropertyOf	inverseOfdomainr  r"  )r?   rp   rj   r  r  r  r  r  	otherTypeequivalentPropertyr"  verbAnnotationsr  r  r  s                 r@   rA   zProperty.__init__B  s      	h&z5.+V%%o6doou555":dooTZZ#P#U#UVDN84DJJF

8DE%DN*"
$_r'rC   c                   | j                   j                  | j                  d d f      D ]  }|j                  |        t	        j
                  | j                  | j                        D ]  }|j                  |        t	        j
                  | j                  | j                        D ]'  }t        || j                         j                  |       ) y r<   )rj   r   rp   r   r  r  r  r  r   r  r  r   )r?   rj   r   r   r   s        r@   r   zProperty.serialized  s    JJ&&t'DEDIIdO F!3!3T^^DAKK Edjj9Aa$..u5 :rC   c              #     K   |d u xr | j                   xs |j                  d | j                  d f      D ]  }|  y wr<   )rj   r   rp   )r?   rj   rU  s      r@   r  zProperty._get_extentl  sB     }3<uEE4??D)
F L
s   =?c                n    |sy |D ]-  \  }}| j                   j                  || j                  |f       / y r<   )rj   r   rp   )r?   rH   subjobjs       r@   r  zProperty._set_extentr  s1    ID#JJNND$//378 rC   c                l   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 ]?  \  }}}|j                  t#        |j%                  t#        t                     d                A 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  }|S c c}w c c}	w c c}
w c c}w )NzObjectProperty( z annotation(r  r  z  inverseOf( rz   z
 Symmetricr|  zDatatypeProperty( r{   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 r<   )r.   ro   r   r_  r   r   r   r   r	   r   r   r  r   )r   gnormalized_names      r@   canonicalNamez(Property.__repr__.<locals>.canonicalName  s|    /5O/51 ++C04y !!$s{{C4F4F&GN
 Dz!4::&rC   z   super( %s )z   domain( %s )z   range( %s )r   z
))r	   rQ  r   r   r   r   r"  r  rp   r  rL  rj   r   r
   rM  rN  rO  r   r  r   ri   r  r  r  )r?   rttwo_link_inverseinversereprr   rS  roletyper  super_propertyr  r  exprs               r@   rz  zProperty.__repr__z  s   *II::uT\\2JuT\\7JPbPR T^^$#(t~~)>)H)H#I #(8(C(Ct(V"'"7"="=K"&uT^^'<"=K		 $--:K|QrQ %)JJ$>$> OOHH..55..% B 		#hnnSX6r:;<% II::uT\\2JuT\\7JPbPR %)JJ$6$6#((C,B,BC% B 		/*%
	' 			HH +/*<*<*< %}^TZZ'PP*<	
 			HH #'++"- &fdjj(II"-	
 			HH "&!+ %}UDJJ'GG!+	
 YY4t45
e	3 5s   9N"N'N,N1N1c              #     K   | j                   j                  | j                  t        j                        D ]  }t        || j                   d         y wNr|   rK  )rj   r   rp   r   r  r+   r  s     r@   _get_subpropertyofzProperty._get_subpropertyof  sH     ::%%OOt/A/A & 
C 3djj4@@
r  c                    |sy |D ]A  }| j                   j                  | j                  t        j                  t        |      f       C y r<   )rj   r   rp   r   r  r.   )r?   rH   subpropertys      r@   _set_subpropertyofzProperty._set_subpropertyof  s<     KJJNN$"4"46G6TU !rC   c                     y r<   r^   r   s    r@   _del_subpropertyofzProperty._del_subpropertyof  r   rC   c              #     K   | j                   j                  | j                  t        j                        D ]  }t        || j                   d         y wr  )rj   r   rp   r	   r  r+   r  s     r@   _get_inverseofzProperty._get_inverseof  s@     ::%%doo%WC3djj4@@ Xr  c                    |sy | j                   j                  | j                  t        j                  t        |      f       y r<   )rj   r   rp   r	   r  r.   rL   s     r@   _set_inverseofzProperty._set_inverseof  s-    

8I%8PQRrC   c                     y r<   r^   r   s    r@   _del_inverseofzProperty._del_inverseof  r   rC   c              #     K   | j                   j                  | j                  t        j                        D ]  }t        || j                           y wr  )rj   r   rp   r   r  r   )r?   doms     r@   _get_domainzProperty._get_domain  s>     ::%%doo%UC4::.. V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 r<   )	ro   r%   r   rj   r   rp   r   r  r.   )r?   rH   r  s      r@   _set_domainzProperty._set_domain  sl    ej*56JJNNDOOT[[:KE:RST

>OPS>TUV rC   c                     y r<   r^   r   s    r@   _del_domainzProperty._del_domain	  r   rC   c              #     K   | j                   j                  | j                  t        j                        D ]  }t        || j                           y wr  )rj   r   rp   r   r  r   )r?   rans     r@   
_get_rangezProperty._get_range	  s>     ::%%doo%TC4::.. U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 r<   )	ro   r%   r   rj   r   rp   r   r  r.   )r?   rangesr  s      r@   
_set_rangezProperty._set_range	  sk    fz:67JJNNDOOTZZ9J69RST

=Nu=UVW  rC   c                     y r<   r^   r   s    r@   
_del_rangezProperty._del_range	  r   rC   c                    | j                   D ]-  \  }}}| j                  j                  |t        |      |f       / | j                  j	                  d | j
                  d f       y r<   )r
  rj   r   r7   r   rp   )r?   rH   r   rS  r   s        r@   r   zProperty.replace	  sP    HAr1JJNNA3E:A>? $

4$78rC   r<   )"r[   r\   r]   r  r  r	   rQ  rA   r   r  r  r  r
  rz  r  r  r   r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r9  r:  s   @r@   r+   r+     sU    !XJ ## :D69 k;/FXtA **+ , .0BMAS
 & ' HI/W $ % k;<F/X 

# $ ZZ8E9rC   r+   c                "   |i n|}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)
    Nra   r`   rb   Fr  )r   r  r   r
   r	   rc   itemsnamespace_manager)rj   additionalNSadditional_nsr  rl   rk   s         r@   r    r    &	  s     '.BLM(/64(5#&5#&M//12vsU; 3/ErC   r  r<   )Wr  
__future__r   r  loggingtypingr   r   rdflib.collectionr   rdflib.graphr   r   rdflib.namespacer	   r
   r   r   r   r   rdflib.termr   r   r   r   r   rdflib.utilr   	getLoggerr[   logger__all__r&   r5   r1   r/   r.   r7   r2   r$   r   r%   r   r   r*   r   r   r   r?  
differencer   r   r   r   r  r=  r@  backwardCompatibleWithincompatibleWithr   r   r   r   r!   r"   rE  r'   r(   r   r   r)   r#   BooleanPredicatesr#  r   r   r   r-   r8   r6   r3   r4   r0   r9   r,   r+   r    r^   rC   r@   <module>r     s  qf #   " ( + M M D D 			8	$&\- -* 39:
,)
 /4eP V@ V@r 
<	=@<z @<FA A@
;>#I # @A*""		 (+&\@
F	Z 	. YDr rjG GT?ou ?D ''5  <- -p?E pf	o=% o=j	 U T S S P 	TU& U9 U9p0rC   