
    Pi=                      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j        e          Z	 g d
Z G d d          Z deee ed          ddZ!d Z"d Z#d Z$d Z%	 dFdZ&d Z' 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%                    1                    ej2        ej3        ej4        ej5        ej6        ej7        ej8        ej9        ej:        ej;        ej<        ej=        g          Z>d& Z?d' Z@ G d( d)eA          ZB G d* d+eB          ZCdGd,ZD G d- d.e+          ZE G d/ d0          ZF G d1 d2eFeE          ZGej<        ej;        gZH G d3 d4          ZI G d5 d6          ZJ G d7 d8eFeE          ZKd9 ZL G d: d;eE          ZM e d<           ZN e d=           ZO e d>           ZP e d?           ZQ e d@           ZR e dA           ZSdBZT G dC dDe+          ZUdGdEZVdS )Hu  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__`

```python
>>> 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

```python
>>> 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.

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

```

We can then access the rdfs:subClassOf relationships

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

```

This can also be used against already populated graphs:

```python
>>> 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

```python
>>> 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

```python
>>> 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:

```python
>>> 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)

```python
>>> del c[c.index(Class(exNs.Work, graph=g))]
>>> c
( ex:Opera OR ex:CreativeWork )

```

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

```python
>>> 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

```python
>>> 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:

```python
>>> 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

```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                  2    e Zd Zd Zd Zd Zd Zd Zd ZdS )r&   c                    || _         d S Nfunction)selfr>   s     j/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/rdflib/extras/infixowl.py__init__zInfix.__init__            c                (    t          | |fd          S )Nc                .    |                     ||           S r<   r=   xr?   others      r@   <lambda>z#Infix.__rlshift__.<locals>.<lambda>       t}}UA7N7N rC   r&   r?   rH   s     r@   __rlshift__zInfix.__rlshift__       DNNNOOOrC   c                ,    |                      |          S r<   r=   rL   s     r@   
__rshift__zInfix.__rshift__       }}U###rC   c                (    t          | |fd          S )Nc                .    |                     ||           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                ,    |                      |          S r<   r=   rL   s     r@   
__matmul__zInfix.__matmul__   rQ   rC   c                .    |                      ||          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&      st        ! ! !P P P$ $ $P 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                |    |                      t          |                    \  }}}d                    ||g          S N:)compute_qnamer.   join)graphuriprefix	localnames       r@   r1   r1      s<    "001B31G1GHHFC88VY'(((rC   c                    t          | t                    r| j        S t          | t          t          t
          f          sJ | S r<   )
isinstancer   
identifierr   r   r   things    r@   r/   r/      s?    % %&%!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.     sY    %(E*++ %&%11 	
 	
FN	
 	
1 rC   c                l    t          | t                    r| j        S t          | t                    sJ | S r<   )ro   r+   rp   r   rq   s    r@   r7   r7     s8    %"" %(((((rC   Fc                
   | J |r|rt          |           }fd| D             }n9t          t          |                     }fdt          |           D             }|t          j        k    r g }g }|D ]B}t	          |t
                    r|                    |           -|                    |           C|rfd}	t          |          dk    r*dd                    t          |	|                    z   dz   }
nt          |d	                   }
|r4t          |
          d
z   d                    fd|D                       z   S |
S dd                    d |D                       z   dz   S |t          j        k    r%dd                    d |D                       z   dz   S |t          j        k    r%dd                    d |D                       z   dz   S |t          j        k    sJ nt          j                            | t"          j                  v rt'                              | t          j                            d	         }                    |          \  }
}}d                    |
|g          }t-                              |t.          j                            }|rd|z  }                    | t          j                  D ]}d|dt          |          dc S                     | t          j                  D ]}d|dt          |          dc S                     | t          j                  D ]}d|dt          |          dc S t          j        dt          j        dt          j        di}                    | t'          |                                           df          D ]\  }}}d|d||         d|dc S t'                              | t          j                            }|rdt          |d	                   z  S d                    d tB          D                       }|dz   d z   }tE          d!          | i}#                    |d"|#          D ].\  }}t	          | t
                    st          ||$          c S /	                     |           \  }
}}d                    |
|g          }nY# tH          $ rL t	          | tJ                    r| &                                cY S t	          | t                    s| j'        n| cY S w xY wt-          tQ          | %          j                  }|r|S |S )&z
    Core serialization
    thing is a Class and is processed as a subject
    store is an RDFLib Graph to be queried about thing
    Nc                0    g | ]}t          |          S r^   r2   .0childstores     r@   
<listcomp>z$manchesterSyntax.<locals>.<listcomp>&  s$    JJJ5(66JJJrC   c                0    g | ]}t          |          S r^   rw   rx   s     r@   r|   z$manchesterSyntax.<locals>.<listcomp>)  s1       38 ..  rC   c                d                         |           \  }}}d                    ||g          S rf   )rh   ri   )rG   rl   rk   rm   r{   s       r@   castToQNamez%manchesterSyntax.<locals>.castToQName6  s4    -2-@-@-C-C*FC88VY$7888rC      z( z AND  )r   z THAT c                J    g | ]}t          t          |                     S r^   )strr2   )ry   rG   r{   s     r@   r|   z$manchesterSyntax.<locals>.<listcomp>C  s,    PPPS!1!U!;!;<<PPPrC   c                ,    g | ]}t          |          S r^   r   ry   cs     r@   r|   z$manchesterSyntax.<locals>.<listcomp>I  s    +E+E+EqCFF+E+E+ErC   z OR c                ,    g | ]}t          |          S r^   r   r   s     r@   r|   z$manchesterSyntax.<locals>.<listcomp>K  s    &@&@&@!s1vv&@&@&@rC   z{  c                ,    g | ]}t          |          S r^   r   r   s     r@   r|   z$manchesterSyntax.<locals>.<listcomp>M  s    #=#=#=qCFF#=#=#=rC   z }subject	predicaterg   z'%s'z ONLY z VALUE z SOME MAXMINEQUALSz
( NOT %s )
c                6    g | ]}d |dt           |         dS )zPREFIX z: <>)r5   )ry   ks     r@   r|   z$manchesterSyntax.<locals>.<listcomp>i  s+    QQQAAGAJJJ?QQQrC   z6
SELECT ?p ?bool WHERE {?class a owl:Class; ?p ?bool .z?bool rdf:first ?foo }z?classsparql)	processorinitBindingsbooleanrj   ))iterr   r	   intersectionOfro   r   appendlenri   mapr2   r   unionOfoneOfcomplementOfr-   objectsr
   typerc   
onPropertyrh   r   r   labelallValuesFromhasValuesomeValuesFrommaxCardinalityminCardinalitycardinalitytriples_choiceskeysr5   r   query	Exceptionr   n3rp   r   )rr   r{   r   transientListlivechildrenchildren	childlistnamedrz   r   rl   proprk   rm   
propstringr   	onlyclassval	someclass
cardlookup_spocomplprologqstrinitbboolpropcolqnames    `                            r@   r2   r2     s/     @C 	;;LJJJJEJJJHH
5% 8 899L   <Fue<T<T  H c(((IE% , ,eV,, ,LL''''$$U++++ N9 9 9 9 9 u::>>!GLL[%1H1H$I$IIDPFF-eAh>>F 	"F"#!,,PPPPiPPP  "Mgll+E+EH+E+E+EFFFMM##&++&@&@x&@&@&@AAADHH	!!#((#=#=H#=#=#=>>>EEc......	EMM%38MLL	L	LEMM%3>MJJKKAN!&!4!4T!:!:YXXvy122
emmDDJmGGHH 	(%Ju@QRR 	W 	WII'1zz3CIu3U3U3U3UVVVV==#,=GG 	R 	RCC(2

4DS%4P4P4P4PQQQQu@RSS 	W 	WII'1zz3CIu3U3U3U3UVVVVOX


 --ud:??;L;L6M6Mt.TUU 	C 	CHB11%/ZZABBBBu8HIIJJE /a%@@AAQQQQQRRGH&' 	
 (##U+"[[PU[VV 	F 	FMHceV,, F'UHEEEEEEF	M%*%8%8%?%?"FCHHfi011EE 	M 	M 	M%'' "xxzz!!!+5eS+A+AL5##uLLL		M
 eE///566 	LLs   10S" "3T8T87T8c              #     K   |                      t          j        t          j                  D ](}t          |t                    rt	          |          V  )d S N)r   object)subjectsr
   r   r	   r   ro   r   rj   r   s     r@   r$   r$     sU      ^^chsy^AA  a   	((NNN rC   c                      e Zd Zd Zd ZdS )TermDeletionHelperc                    || _         d S r<   )r   )r?   r   s     r@   rA   zTermDeletionHelper.__init__  s    			rC   c                      fd}|S )Nc                V    | j                             | j        j        d f           d S r<   )rj   removerp   r   )instr?   s    r@   _removerz-TermDeletionHelper.__call__.<locals>._remover  s*    Jt	4@AAAAArC   r^   )r?   fr   s   `  r@   rZ   zTermDeletionHelper.__call__  s(    	B 	B 	B 	B 	B rC   Nr[   r\   r]   rA   rZ   r^   rC   r@   r   r     s2              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j                  d             Z eeee          ZdS )r%   zE
    A typed individual, the base class of the InfixOWL classes.
    c                z    | j                             | j        d d f          D ]}|                    |           d S r<   )factoryGraphtriplesrp   addr?   rj   facts      r@   	serializezIndividual.serialize  sF    %--td.KLL 	 	DIIdOOOO	 	rC   Nc                L   |d ur|pt                      | _        || j        | _        n|| _        d | _        t          | j        t                     sS	 | j                            | j                  \  }}}d                    ||g          | _        d S # t          $ r Y d S w xY wd S 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LUWW=*DJJDJ
$/511 	)-)A)A$/)R)R&Y XXvy&9::


   		 	s   ?B 
B! B!c                J    | j                             dd| j        f           dS )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88888rC   c                J    | j                             | j        ddf           dS )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88888rC   c                V    |                                   |                                  dS )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                             dd| j        f          D ]0\  }}}| j                             ||t	          |          f           1|                                  dS )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.

        ```python
        >>> 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  sj    $ 
**D$+HII 	= 	=HAq"JNNAq"3E":":;<<<<rC   returnIterable[_ObjectType]c              #  n   K   | j                             | j        t          j                  D ]}|V  d S Nr   )rj   r   rp   r
   r   r?   _ts     r@   	_get_typezIndividual._get_type  sC      *$$T_$QQ 	 	BHHHH	 	rC   kind4Union[Individual, Identifier, Iterable[_ObjectType]]c                t   |sd S t          |t          t          f          r;| j                            | j        t          j        t          |          f           d S |D ]Y}t          |t          t          f          sJ | j                            | j        t          j        t          |          f           Zd S r<   )	ro   r%   r   rj   r   rp   r
   r   r.   )r?   r   r   s      r@   	_set_typezIndividual._set_type  s     	FdZ455 	RJNNDOSX7H7N7NOPPPPP R R!!j*%=>>>>>
;LQ;O;OPQQQQR RrC   c                    dS )z
        ```python
        >>> 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   r   c                    | j         S r<   )r   r   s    r@   _get_identifierzIndividual._get_identifier  s      rC   ic                    sJ  j         k    rd  j                             j         d d f          D             }d  j                            d d  j         f          D             }|D ]'\  }} j                             j         ||f           (|D ]'\  }} j                            || j         f           ( _          j                             fd|D                         j                             fd|D                        t          t                    sN	  j                                      \  }}}	d                    ||	g           _	        d S # t          $ r Y d S w xY wd S )Nc                    g | ]
\  }}}||fS r^   r^   ry   r   r   r   s       r@   r|   z.Individual._set_identifier.<locals>.<listcomp>  s2     ! ! !Aq! A! ! !rC   c                    g | ]
\  }}}||fS r^   r^   r   s       r@   r|   z.Individual._set_identifier.<locals>.<listcomp>  s2          Aq! A     rC   c                ,    g | ]\  }}||j         fS r^   r   )ry   p1o1r   r?   s      r@   r|   z.Individual._set_identifier.<locals>.<listcomp>  s(    UUURaR4UUUrC   c                ,    g | ]\  }}||j         fS r^   r   )ry   s1r  r   r?   s      r@   r|   z.Individual._set_identifier.<locals>.<listcomp>  s(    TTTRb"a4TTTrC   rg   )r   rj   r   r   addNro   r   rh   ri   r   r   )
r?   r   oldstatements_outoldstatements_inr  r  r  rl   rk   rm   s
   ``        r@   _set_identifierzIndividual._set_identifier  s   q!!!! !#z1143DdD2QRR! ! !   #z114t?P2QRR      , ? ?B
!!4#4b""=>>>>* ? ?B
!!2r4+<"=>>>> !DJOOUUUUUCTUUUVVVJOOTTTTTCSTTTUUU!U## 	)-)A)A!)D)D&Y XXvy&9::


   		 	s   *:E& &
E43E4c              #  n   K   | j                             | j        t          j                  D ]}|V  d S r   )rj   r   rp   r	   sameAsr   s     r@   _get_sameAszIndividual._get_sameAs  sC      *$$T_
$SS 	 	BHHHH	 	rC   termc                l   t          |t          t          f          r;| j                            | j        t          j        t          |          f           d S |D ]Y}t          |t          t          f          sJ | j                            | j        t          j        t          |          f           Zd S r<   )	ro   r%   r   rj   r   rp   r	   r  r.   )r?   r  r   s      r@   _set_sameAszIndividual._set_sameAs  s    
 dZ455 	TJNNDOSZ9J49P9PQRRRRR T T!!j*%=>>>>>
=Nq=Q=QRSSSST TrC   c                    d S r<   r^   r   s    r@   _delete_sameAszIndividual._delete_sameAs*      rC   NN)r   r   )r   r   )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%     s         577L     9 9 99 9 9    ,   R R R R !!  "!  8Iy,77D! ! ! !   2 /?;;J   
T 
T 
T 
T 
##  $# Xk;??FFFrC   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:

    ```
    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.

    ```xml
    <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>
    ```
    NFc                    t          t          |                               ||           |rG|                                  | j        |                     |          fg| j        _        |r|g| _        d S d S d S r<   )	superr   rA   setupACEAnnotationsrp   handleAnnotation	PN_sgpropextentr   )r?   rp   rj   nameAnnotationnameIsLabel	__class__s        r@   rA   zAnnotatableTerms.__init__{  s     	%%..z5AAA 	.$$&&&$"7"7"G"GH%DN!  .,-


	. 	.
. .rC   c                N    t          |t                    r|nt          |          S r<   )ro   r   )r?   r   s     r@   r  z!AnnotatableTerms.handleAnnotation  s!     g..@ssGCLL@rC   c                   | 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                   | _        d S )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.setupACEAnnotations  s   
v666 "L3#9
 
 

 "L3#9
 
 

 "L3#9
 
 

 "L3#9
 
 

 "L3#9
 
 

 #MC$:$*
 
 
rC   c              #  n   K   | j                             | j        t          j                  D ]}|V  d S r   )rj   r   rp   r   comment)r?   r4  s     r@   _get_commentzAnnotatableTerms._get_comment  L      z))Ot| * 
 
 	 	G MMMM	 	rC   c                    |sd S t          |t                    r.| j                            | j        t
          j        |f           d S |D ].}| j                            | j        t
          j        |f           /d S r<   )ro   r   rj   r   rp   r   r4  )r?   r4  r   s      r@   _set_commentzAnnotatableTerms._set_comment  s     	Fgz** 	CJNNDOT\7CDDDDD C C
qABBBBC CrC   c                    d S r<   r^   r   s    r@   _del_commentzAnnotatableTerms._del_comment  r  rC   c              #  n   K   | j                             | j        t          j                  D ]}|V  d S r   )rj   r   rp   r   seeAlso)r?   seealsos     r@   _get_seealsozAnnotatableTerms._get_seealso  r6  rC   c                p    |sd S |D ].}| j                             | j        t          j        |f           /d S r<   )rj   r   rp   r   r<  )r?   seealsosr   s      r@   _set_seealsozAnnotatableTerms._set_seealso  sJ     	F 	? 	?AJNNDOT\1=>>>>	? 	?rC   c                    d S r<   r^   r   s    r@   _del_seealsozAnnotatableTerms._del_seealso  r  rC   c              #  n   K   | j                             | j        t          j                  D ]}|V  d S r   )rj   r   rp   r   r   )r?   r   s     r@   
_get_labelzAnnotatableTerms._get_label  sC      Z''4:'VV 	 	EKKKK	 	rC   c                    |sd S t          |t                    r.| j                            | j        t
          j        |f           d S |D ].}| j                            | j        t
          j        |f           /d S r<   )ro   r   rj   r   rp   r   r   )r?   r   l_s      r@   
_set_labelzAnnotatableTerms._set_label  s     	FeZ(( 	BJNNDOTZ?@@@@@ B B
R@AAAAB BrC   c                    dS )z
        ```python
        >>> 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  r5  r8  r   r   r4  r:  r  r>  rA  r<  rC  rE  rH  r   rJ  __classcell__r  s   @r@   r   r   4  s       D DR . . . . . . A A A
 
 
B  C C C %%  &% h|\<@@G  ? ? ? %%  &% h|\<@@G  B B B 
##  $#  HZ];;EEEEErC   r   c                       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 metadataNc                @   t          t          |                               ||           |g n|| _        |g n|| _        | j        t          j        t          j        f| j	        vr8| j	        
                    | j        t          j        t          j        f           d S d S r<   )r  r*   rA   importsr4  rp   r
   r   r	   rj   r   )r?   rp   rO  r4  rj   r  s        r@   rA   zOntology.__init__  s    h&&z5999$_rr'$_rr'OSXs|4DJFFJNNDOSXs|DEEEEE GFrC   c                ^    | j                             | j        t          j        |f           d S r<   )rj   setrp   r	   versionInfo)r?   versions     r@   
setVersionzOntology.setVersion  s'    
'BCCCCCrC   c              #  p   K   | j                             | j        t          d                   D ]}|V  d S )NrO  r   )rj   r   rp   r	   )r?   rb   s     r@   _get_importszOntology._get_imports  sN      :%%Os9~ & 
 
 	 	C IIII	 	rC   c                r    |sd S |D ]/}| j                             | j        t          d         |f           0d S )NrO  )rj   r   rp   r	   )r?   rH   r   s      r@   _set_importszOntology._set_imports
  sP     	F 	A 	AAJNNDOS^Q?@@@@	A 	ArC   rO  c                    d S r<   r^   r   s    r@   _del_importszOntology._del_imports  r  rC   )NNNN)r[   r\   r]   r  rA   rT  rV  rX  r   r	   rZ  r  rO  rK  rL  s   @r@   r*   r*     s        ##F F F F F FD D D  A A A I''  (' h|\<@@GGGGGrC   r*   c              #     K   t          |                     t          j        t          j                            D ]}t          |          V  d S r   )rQ  r   r
   r   r	   r   r   s     r@   r   r     sL      #(39EEFF  Ahh rC   c              #    K   t                      }|                     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r)|                    |           t          || |          V  }d S )Nrj   r%  )rQ  r   r
   r   r	   SymmetricPropertyFunctionalPropertyInverseFunctionalPropertyTransitivePropertyDatatypePropertyObjectPropertyr(  r   r+   )rj   	prevpropsr   _pr   bTypes         r@   r   r     s      I))H%&-&$"&	
  ; ;2q !)"	
 
 
 &EE(EIMM!1EE::::::5; ;rC   c                  "    e Zd Zd ZddZd ZdS )r   c                @    t          t          | |z                       S r<   )r   r   r?   names     r@   r  zClassNamespaceFactory.term<  s    VD4K(()))rC   Nc                ,    |                      |          S r<   )r  )r?   keydefaults      r@   __getitem__z!ClassNamespaceFactory.__getitem__?  s    yy~~rC   c                d    |                     d          rt          |                     |          S )N__)
startswithAttributeErrorr  ri  s     r@   __getattr__z!ClassNamespaceFactory.__getattr__B  s,    ??4   	#  99T??"rC   r<   )r[   r\   r]   r  rn  rs  r^   rC   r@   r   r   ;  sF        * * *   # # # # #rC   r   z0http://www.w3.org/2002/07/owl#resourcePropertiesc              #    K   t           j        | j        v r	 t          | t          j                  } | j                            | j        t           j        t           j	        gdf          D ]G\  }}}t          |d          }t          |t                    rt          |          D ]}|V  C|V  HdS # t          $ r Y dS w xY wt          | t          j                  } t          | t                    rM| D ]H}t          |d          }t          |j        t                    rt          |          D ]}|V  D|V  IdS | j        D ]7}t          |j        t                    rt          |          D ]}|V  3|V  8| j                            t#          |           t$          df          D ]N\  }}}t          |t                    r/t          t          |t          j                            D ]}|V  J|V  OdS )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   re  inner_class_idinner_class_c_clsr   s           r@   r!   r!   ]  s     
 #(""	C!899C*-*:*J*J#"3S5G!H$O+ + & &&B $N4PPPne44 &,[99 ! ! ! &%%%%& &  	 	 	DD	 Z455c<(( 	&  T$???dou55 ,T22 ! ! ! JJJJ   #~ & &k4e<< &,[99 ! ! ! &%%%% -=="3''$?  & &	B a'' &,Yq*:Q-R-RSS ! ! ! &%%%%& &s   BB3 3
C Cc                   d }t          | t          j                  } | j        D ]} ||           | j                            | j        t          j        df           | j        D ]} ||           | j                            | j        t          j        df           | j
        }|r7| j                            | j        t          j
        df            ||           t          | t                    rM| D ]} ||           |                                  | j                            | j        | j        df           dS dS )a  
    Recursively clear the given class, continuing
    where any related class is an anonymous class

    ```python
    >>> 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                l    t          t          |           t                    rt          |            d S d S r<   )ro   r.   r   r"   )_classs    r@   deepClearIfBNodez(DeepClassClear.<locals>.deepClearIfBNode  s;    '//77 	#6"""""	# 	#rC   N)r   r%   r   rw  rj   r   rp   r   equivalentClassr	   r   ro   r   clear	_operator)class_to_pruner  r   inverse_classs       r@   r"   r"     s   \# # # ~z/FGGN&  !:DOT RSSS+  !:C<OQU VWWW"/M (##^%>@PRV$WXXX'''.,// 
 	  	 AQ##&(@$G	
 	
 	
 	
 	
	
 
rC   c                      e Zd ZdZdS )r'   zY
    !!! warning "Deprecated"
        This class will be removed in version `7.0.0`.
    N)r[   r\   r]   r  r^   rC   r@   r'   r'     s         
 	DrC   r'   c                      e Zd Zd Zd ZdS )r(   c                    || _         d S r<   msg)r?   r  s     r@   rA   zMalformedClassError.__init__  s    rC   c                    | j         S r<   r  r   s    r@   __repr__zMalformedClassError.__repr__  s	    xrC   N)r[   r\   r]   rA   r  r^   rC   r@   r(   r(     s2              rC   r(   c                .   |d u r| j         p|}|                    t          |           t          j                  D ]}|t
          j        k    rt          |           |d}|                    t          |           d d f          D ]x\  }}}|t          j        k    rb|t
          j        k    r||d<   ,|t          j	        vr;||t          |                    t          t
                              d                   <   yt          d t          j	        D                                           |          st          d          t          di |c S |                    t          |           t
          j        t
          j        t
          j        gd f          D ]Z\  }}}|t
          j        k    r"t'          t          |           |          c c S t)          t          |           ||          c c S t+          t          |           |d	
          c S d S )Nr   )rp   rj   r   c           	         g | ]<}t          |                    t          t                              d                    =S )r  )r   splitr	   )ry   r   s     r@   r|   zCastClass.<locals>.<listcomp>  s7    RRRQWWSXX&&r*++RRRrC   zMalformed owl:Restrictionr   )operatorrj   Trj   rv  r^   )r   r   r.   r
   r   r	   r-   r   r   restrictionKindsr   r  rQ  intersectionr(   r   r   r   r   r#   r   r   )r   rj   r   kwargsr   r   r   r   s           r@   r   r     s1   TM,an5E&7&:&:chOO Y Y3?""$5a$8$85IIF!MM+<Q+?+?t*LMM ? ?Aq==CN**/0|,,K$@@@$=>s1773s88#4#4R#899:RR[5QRRR l6""G **EFFF((((((("22%a(('ci@  
W 
W	Ar 	>>*+<Q+?+?uMMMMMMMM'(9!(<(<qPUVVVVVVVV*1--USWXXXXXX;Y YrC   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$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/ ee/          Z0d# Z1d$ Z2d% Z3d*d'Z4 xZ5S )+r   uv  '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        D ]*}t          || j                                      |           +| j        D ]*}t          || j                                      |           +| j        r/t          | j        | j                                      |           d S d S r<   )rw  r   rj   r   r  disjointWithr   )r?   rj   cls      r@   
_serializezClass._serialize"  s    / 	7 	7Bb$*%%//6666& 	7 	7Bb$*%%//6666# 	7 	7Bb$*%%//6666 	Fd'44>>uEEEEE	F 	FrC   c                    | j                             | j        d d f          D ]}|                    |           |                     |           d S r<   )rj   r   rp   r   r  r   s      r@   r   zClass.serialize,  sS    J&&t'DEE 	 	DIIdOOOOrC   c                    t          |t                    r|\  }}n|}|}|r'| j        |                     |          fg| j        _        |r)| j        |                     |          fg| j        _        d S d S r<   )ro   tuplerp   r  r*  r  r,  )r?   noun_annotations	cn_sgprop	cn_plprops       r@   setupNounAnnotationszClass.setupNounAnnotations1  s    &.. 	)#3 Iyy(I(I 	$"7"7	"B"BC%DN!  	$"7"7	"B"BC%DN!!!	 	rC   NFc                   t          t          |                               |||
|           |	r|                     |	           |s| j        t
          j        t          j        f| j        vr[| j        t
          j        t          j	        f| j        vr6| j        
                    | j        t
          j        t          j        f           |g n|| _        |g n|| _        |g n|| _        |r|| _        |g n|| _        d S r<   )r  r   rA   r  rp   r
   r   r	   rj   r-   r   rw  r  r  r   r4  )r?   rp   rw  r  r  r   rj   rv  r4  nounAnnotationsr  r  r  s               r@   rA   zClass.__init__A  s     	eT##J~{SSS 	7%%o666&	C#(CI6djHH#(CO<DJNNJNNDOSXsyABBB * 2""
%4%<rr/"."6BBL 	- ,D$_rr'rC   c              #  z   K   |d u r| j         p|                    t          j        | j                  D ]}|V  d S r   )rj   r   r
   r   rp   )r?   rj   members      r@   _get_extentzClass._get_extenta  s[      }3<uFFht G 
 
 	 	F LLLL	 	rC   c                    |sd S |D ];}| j                             t          |          t          j        | j        f           <d S r<   )rj   r   r.   r
   r   rp   )r?   rH   ms      r@   _set_extentzClass._set_extentg  sW     	F 	N 	NAJNN-a00#(DOLMMMM	N 	NrC   c                    d S r<   r^   r   s    r@   	_del_typezClass._del_typem  r  rC   c              #  Z   K   | j                             | j        |          D ]}|V  d S r   )rj   r   rp   )r?   r  
annotations      r@   _get_annotationzClass._get_annotations  sF      *,,T_PT,UU 	 	J	 	rC   c                    | S r<   r^   )rG   s    r@   rI   zClass.<lambda>w  s    Q rC   c                D    t          d          t          j        | j        fS )NCLASS)r   r
   r   rp   r   s    r@   _get_extentqueryzClass._get_extentqueryy  s    !!38T_==rC   c                    d S r<   r^   rL   s     r@   _set_extentqueryzClass._set_extentquery|  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__  s     DO$$$rC   c                z    t          |t                    sJ t          |                      | j        |j        k    S r<   )ro   r   reprrp   rL   s     r@   __eq__zClass.__eq__  s6    %''44e44'%"222rC   c                D    t          |t                    sJ | g|_        | S r<   )ro   r   rw  rL   s     r@   __iadd__zClass.__iadd__  s'    %''''' 6rC   c                    t          |t                    sJ | j                            t	          |          t
          j        | j        f           | S r<   )ro   r   rj   r   r.   r   rw  rp   rL   s     r@   __isub__zClass.__isub__  sG    %'''''
,U33T_doVWWWrC   c                "    t          |           S )z@
        Shorthand for Manchester syntax's not operator
        )r   )r   r   s    r@   
__invert__zClass.__invert__  s     $''''rC   c                H    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*    
 [4-tz
 
 
 	
rC   c                H    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

        ```python
        >>> 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+    0 '$dj
 
 
 	
rC   c              #     K   | j                             | j        t          j                  D ]}t          || j         d          V  d S )Nr   Tr  )rj   r   rp   r   rw  r   r?   ancs     r@   _get_subclassofzClass._get_subclassof  se      :%%Ot & 
 
 	L 	LC 4:dKKKKKKK	L 	LrC   c                    |sd S |D ];}| j                             | j        t          j        t          |          f           <d S r<   )rj   r   rp   r   rw  r.   r?   rH   scs      r@   _set_subclassofzClass._set_subclassof  sX     	F 	V 	VBJNNDOT_>OPR>S>STUUUU	V 	VrC   c                    d S r<   r^   r   s    r@   _del_subclassofzClass._del_subclassof  r  rC   c              #     K   | j                             | j        t          j                  D ]}t          || j                   V  d S Nr   r   )rj   r   rp   r	   r  r   )r?   ecs     r@   _get_equivalentclasszClass._get_equivalentclass  s`      *$$Os/B % 
 
 	. 	.B $*-------	. 	.rC   c                    |sd S |D ];}| j                             | j        t          j        t          |          f           <d S r<   )rj   r   rp   r	   r  r.   r  s      r@   _set_equivalentclasszClass._set_equivalentclass  s]     	F 	 	BJNN#"57H7L7LM   	 	rC   c                    d S r<   r^   r   s    r@   _del_equivalentclasszClass._del_equivalentclass  r  rC   c              #     K   | j                             | j        t          j                  D ]}t          || j                   V  d S r  )rj   r   rp   r	   r  r   )r?   rd   s     r@   _get_disjointwithzClass._get_disjointwith  s`      *$$Os/? % 
 
 	. 	.B $*-------	. 	.rC   c                    |sd S |D ];}| j                             | j        t          j        t          |          f           <d S r<   )rj   r   rp   r	   r  r.   )r?   rH   r   s      r@   _set_disjointwithzClass._set_disjointwith  sY     	F 	V 	VAJNNDOS-=?PQR?S?STUUUU	V 	VrC   c                    d S r<   r^   r   s    r@   _del_disjointwithzClass._del_disjointwith  r  rC   c                   t          | j                            | j        t          j                            }|sd S t          |          dk    rt          |d         | j                  S t          t          |                    )Nr   r   r   r   )	rc   rj   r   rp   r	   r   r   r   r   )r?   comps     r@   _get_complementofzClass._get_complementof  sy    Jt#BRSS
 
  	'4YY!^^a
3333CII&&&rC   c                    |sd S | j                             | j        t          j        t          |          f           d S r<   )rj   r   rp   r	   r   r.   rL   s     r@   _set_complementofzClass._set_complementof  s>     	F
)9;LU;S;STUUUUUrC   c                    d S r<   r^   r   s    r@   _del_complementofzClass._del_complementof  r  rC   c              #    K   t          j        | j        | j                  D ]}|V  t	          | j                            t          j        | j                            }|rt          | j        
                    t          j        |                    }|r	|d         }n|}| j                            t          j        |          D ]*}t          |t                    rt!          |d          V  +| j                            | j        t          j                  D ]D}t'          |g| j                  D ]*}t          |t                    rt!          |d          V  +EdS )a  
        computed attributes that returns a generator over taxonomic 'parents'
        by disjunction, conjunction, and subsumption

        ```python
        >>> 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  Tru  r   N)	itertoolschainrw  r  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     8  odot7KLL 	 	FLLLLT&//	4?KKLL 
	L 1 E EchPT U UVVL &!-b!1!%!%!2!;!;^" " L L mV44 LdKKKKKK)11$/3CUVV 	E 	EH)8*D<MNNN E Eff-- EtDDDDDDE	E 	ErC   c                n   | j         t          j        t          j        f| j        v rdS t          | j                  }| j                            | j         t          j	        t          j
        gd f          D ]0\  }}}|                    t          || j        |                     1|D ]} dS | j        rdS dS )NFr   T)rp   r
   r   r	   r-   rj   rc   r  r   r   r   r   r2   r   )r?   r  
_boolclassr   r  _es         r@   isPrimitivezClass.isPrimitiveK  s    OSXs74:EE5$&'''+z'A'A_s13;?F(
 (
 	I 	I#J8 II&xQGGGHHHH 	 	B55 	5trC   c              #  n   K   | j                             t          j        | j                  D ]}|V  d S r   )rj   r   r   rw  rp   )r?   r   s     r@   subSumpteeIdszClass.subSumpteeIds[  sC      $$tt$WW 	 	AGGGG	 	rC   c                0    |                      dd          S )NFT)fullnormalization)manchesterClassr   s    r@   r  zClass.__repr__d  s    ##d#CCCrC   Tc                    g }t           j                  }t           j                  } j                             j        t          j        t          j        gdf          D ]0\  }}}|	                    t          | j        |                     1t           j                  }	 j        }
|
r|		                    |
           d}t           j                             j        t          j                            }|rd|d         z   dz   pd}|ra|rd}nd} fd	|D             }|rd
|z  }|	                    d|                    d |D                       z             |rd|d         z   |d<   |rP fd|D             }|rd|z  }|	                    dd                    |          z             |rd|d         z   |d<   |	rG|	                    dd                     fd|	D                       z             |rd|d         z   |d<   t           j                             j        t          j                            }|rE|rC|r+d|z  |rd|d         z  pdz   d                    |          z   pd                    |          }n)|r|rd|d         z  pdpdd                    |          z   }t%           j        t&                    rdp	d j        z  |z   S )I
        Returns the Manchester Syntax equivalent for this class
        Nr    (r   )z
                z, c                    g | ]u}t          |t                    r<t          j        t                    r"t	          t          |j                            p!t          t          |          j                  vS r^   )	ro   r   rp   r   r  r   rj   r2   r.   ry   r   r?   s     r@   r|   z)Class.manchesterClass.<locals>.<listcomp>  s     
 
 
  1e$$ 3t6631dj1122C !!21!5!5tzBB
 
 
rC   zPrimitive Type %szSubClassOf: %sc                ,    g | ]}t          |          S r^   r   )ry   ns     r@   r|   z)Class.manchesterClass.<locals>.<listcomp>  s    /O/O/O1A/O/O/OrC   z
    r  c                    g | ];}t          |t                    r|p!t          t          |          j                  <S r^   )ro   r   r2   r.   rj   r  s     r@   r|   z)Class.manchesterClass.<locals>.<listcomp>  s[     # # #  1c"" F#$5a$8$8$*EE# # #rC   zA Defined Class %szEquivalentTo: %szDisjointWith %s
z
                 c                T    g | ]$}t          t          |          j                  %S r^   )r2   r.   rj   r  s     r@   r|   z)Class.manchesterClass.<locals>.<listcomp>  s/    TTTA%&7&:&:DJGGTTTrC   z
    ## %s ##z
    %sz . zSome Class z
Class: %s )rc   rw  r  rj   r   rp   r	   r   r   r   r2   r  r   r   r   r   ri   r4  ro   r   r   )r?   r  r  exprsr  r  r  r   r  rd   r   	klasskindr   scjoinnec_statementsnec_suff_statementsdescr
klassdescrs   `                 r@   r  zClass.manchesterClassg  s    $/""$&'''+z'A'A_s13;?F(
 (
 	I 	I#J8 II&xQGGGHHHH$#$$ 	IIaLLL	TZ''DDEE .#a.3.4" 	1 -
 
 
 
 
 
 
N  8/%7	LL 6;;/O/O/O/O/O#P#PP    1$uRy0b	 	1# # # # 	# # # # 9058	LL+dii8K.L.LLMMM 1$uRy0b	 	1LL#',,TTTTQSTTT     1$uRy0b	TZ''FFGG 	M 	 $$y02Z%(28b:**U##$% ::e$$ J  <4zE!H4:*

5)))  t.. )dj(	 	rC   )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  rw  r  r  r  r	   r  r  r  r  r  r  r  r  r   r  r  parentsr  r  r  r  rK  rL  s   @r@   r   r     s        :F F F  
  $ $: : : : : :@   N N N !!  "! Xk;	::F#':     /;;77J> > >   (+-=>>K% % %3 3 3  
  
( ( (
 
 

 
 
8L L LV V V ((  )( / J. . .   +,,  -, h24H O. . .V V V ())  *) 8,.? L	' 	' 	'V V V
 ())  *) 8,.? L.E .E .E` h|$$G     D D DT T T T T T T TrC   r   c                  X    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dS )r)   Nc                   |r|| _         |g n|}|rWt          | j         |d                   | _        |D ]2}|| j        vr'| j                            t	          |                     3d S t          | j         t                      d |D                       | _        | j                             | j        | j        | j        j	        f           d S )Nr   c                ,    g | ]}t          |          S r^   )r.   )ry   r  s     r@   r|   z,OWLRDFListProxy.__init__.<locals>.<listcomp>  s!    %L%L%Lq&7&:&:%L%L%LrC   )
rj   r   _rdfListr   r.   r   r   rp   r  rk   )r?   r  r  rj   r  s        r@   rA   zOWLRDFListProxy.__init__  s     	DJ""W 	Q&tz8A;??DM! D D..M(():6)B)BCCCD D '
EGG%L%LG%L%L%L DM
 JNNDOT^T]=NOPPPPPrC   c                |   t          |t                    s4J t          |          t          t          |                    z               t          |t                    rOt          |           }|t          |          k    rdS t          |          D ]}| |         ||         k    r dS  dS dS | 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HetDKK7H7H)HHH'e\** 	7YYFU##u ==    CCyE#J..$uu44    ?e&666rC   c                *    t          | j                  S r<   )r   r  r   s    r@   __len__zOWLRDFListProxy.__len__  s    4=!!!rC   c                P    | j                             t          |                    S r<   )r  indexr.   r?   items     r@   r  zOWLRDFListProxy.index  s!    }""#4T#:#:;;;rC   c                    | j         |         S r<   r  r?   rl  s     r@   rn  zOWLRDFListProxy.__getitem__  s    }S!!rC   c                4    t          |          | j        |<   d S r<   )r.   r  )r?   rl  r9   s      r@   __setitem__zOWLRDFListProxy.__setitem__  s    .u55crC   c                    | j         |= d S r<   r  r   s     r@   __delitem__zOWLRDFListProxy.__delitem__  s    M#rC   c                8    | j                                          d S r<   )r  r  r   s    r@   r  zOWLRDFListProxy.clear  s    rC   c              #  &   K   | j         D ]}|V  d S r<   r  r  s     r@   __iter__zOWLRDFListProxy.__iter__  s,      M 	 	DJJJJ	 	rC   c                F    | j         D ]}|t          |          k    r dS dS )Nr   r   )r  r.   )r?   r  r   s      r@   __contains__zOWLRDFListProxy.__contains__  s8     	 	A%d++++qq ,qrC   c                :    | j                             |           d S r<   )r  r   r  s     r@   r   zOWLRDFListProxy.append   s    T"""""rC   c                T    | j                             t          |                     | S r<   )r  r   r.   rL   s     r@   r  zOWLRDFListProxy.__iadd__  s&    .u55666rC   r  )r[   r\   r]   rA   r  r  r  rn  r"  r$  r  r'  r)  r   r  r^   rC   r@   r)   r)     s        Q Q Q Q"7 7 7(" " "< < <" " "6 6 6        # # #    rC   r)   c                  :    e Zd ZdZej        Zd ZddZd Z	d Z
dS )r#   a  Class for owl:oneOf forms:

    OWL Abstract Syntax is used

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

    ```python
    >>> 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                    dS NFr^   r   s    r@   r  zEnumeratedClass.isPrimitive.      urC   Nc                    t                               | ||           |g n|}t          | j                            t
          j        | j                            }t                              | ||           d S )Nr   r   r   )	r   rA   rc   rj   r   r	   r   rp   r)   )r?   rp   r  rj   rdfLists        r@   rA   zEnumeratedClass.__init__1  sr    tZu555""WJDOLL
 
 	  w88888rC   c                N    t          | j        j        | j        | j                  S r  r   )r2   r  rk   rj   r  r   s    r@   r  zEnumeratedClass.__repr__9  s"       14:t~VVVVrC   c                   t          |t                                }| j        D ]?}|                    |           t	          || j                                      |           @|                    | j        | j	        |j
        f           | j                            | j        d d f          D ])\  }}}|| j	        k    r|                    |||f           *|                     |           d S r<   r   r   r  r   r   rj   r   r   rp   r  rk   r   r  r?   rj   
clonedlistr  r   r   r   s          r@   r   zEnumeratedClass.serialize?  s    uww//
- 	7 	7Bb!!!b$*%%//6666		4?DNJNCDDDz))4?D$*GHH 	% 	%GAq!DN""		1a)$$$rC   )NNN)r[   r\   r]   r  r	   r   r  r  rA   r  r   r^   rC   r@   r#   r#     sl        ! !F 	I  9 9 9 9W W W
 
 
 
 
rC   r#   c                      e Zd ZdZd Zd ZdS )BooleanClassExtentHelperaw  
    ```python
    >>> 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                    || _         d S r<   r  )r?   r  s     r@   rA   z!BooleanClassExtentHelper.__init__e  rB   rC   c                      fd}|S )Nc               3     K   t           j                            j                  D ]} t	          | j                  V  d S )Nr<  )r%   r   r   r  r   )r   r?   s    r@   
_getExtentz5BooleanClassExtentHelper.__call__.<locals>._getExtenti  sQ      ,55dmDD > >"1t}=======> >rC   r^   )r?   r   r?  s   `  r@   rZ   z!BooleanClassExtentHelper.__call__h  s$    	> 	> 	> 	> 	> rC   N)r[   r\   r]   r  rA   rZ   r^   rC   r@   r:  r:  O  s<         *! ! !    rC   r:  c                      e Zd Zd Zd ZdS )r   c                    || _         d S r<   _callfn)r?   anycallables     r@   rA   zCallable.__init__q  s    "rC   c                     | j         |i |S r<   rB  )r?   argsr  s      r@   rZ   zCallable.__call__t  s    t|T,V,,,rC   Nr   r^   rC   r@   r   r   p  s2        # # #- - - - -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dS )r   zl
    See: http://www.w3.org/TR/owl-ref/#Boolean

    owl:complementOf is an attribute of Class, however
    c                     d S r<   r^   r^   rC   r@   getIntersectionszBooleanClass.getIntersections  	     	rC   c                     d S r<   r^   r^   rC   r@   	getUnionszBooleanClass.getUnions  rJ  rC   Nc                T   |xg }|                     |t          j        t          j        gd f          D ]\  }}}|                    |           |}t          |          dk    sJ t          |                      t                              | ||           |t          j        t          j        fv sJ t          |                      || _
        t          | j                            || j                            }	|r|	r
J d            t                              | |	|           d S )Nr   r   r1  z-This is a previous boolean class description.)r   r	   r   r   r   r   r  r   rA   r   r  rc   rj   r   rp   r)   )
r?   rp   r  r  rj   propsr   r   r   r  s
             r@   rA   zBooleanClass.__init__  s.    E"22c0#+>E   	Ar Qu::???DKK???tZu555C.<<<<c(mm<<<!
**Xt*WWXX	;'	; 	;:	; 	;'  x99999rC   c                X    t          | j        t          |           | j                  }|S )z-
        Create a copy of this class
        r  )r   r  rc   rj   )r?   copy_of_classs     r@   copyzBooleanClass.copy  s1     %^T$ZZtz
 
 
 rC   c                   t          |t                                }| j        D ]?}|                    |           t	          || j                                      |           @|                    | j        | j	        |j
        f           | j                            | j        d d f          D ])\  }}}|| j	        k    r|                    |||f           *|                     |           d S r<   r6  r7  s          r@   r   zBooleanClass.serialize  s    uww//
- 	7 	7Bb!!!b$*%%//6666		4?DNJNCDDDz))4?D$*GHH 	% 	%GAq!DN""		1a)$$$rC   c                    dS r.  r^   r   s    r@   r  zBooleanClass.isPrimitive  r/  rC   c                    || j         k    s
J d            | j                            | j        | j         | j        j        f           | j                            | j        || j        j        f           || _         dS )a8  
        Converts a unionOf / intersectionOf class expression into one
        that instead uses the given operator

        ```python
        >>> 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)r  rj   r   rp   r  rk   r   )r?   newOperators     r@   changeOperatorzBooleanClass.changeOperator  ss    4 dn,,,.W,,,
4?DNDM<MNOOO
dm6GHIII$rC   c                    t          t          | j        t                    r| j        j        nt                      | j        | j                  S r4  )r2   ro   r  r   rk   r   rj   r  r   s    r@   r  zBooleanClass.__repr__  sG      !+DM:!F!FSDMEGGJN
 
 
 	
rC   c                    | j         t          j        k    sJ | j                            t          |                     | S )z9
        Adds other to the list and returns self
        )r  r	   r   r  r   r.   rL   s     r@   r  zBooleanClass.__or__  s=     ~,,,,.u55666rC   )r[   r\   r]   r  r:  r	   r   r   rI  r   rL  rA   rQ  r   r  rV  r  r  r^   rC   r@   r   r   x  s$         c011  X 21  x 011ck**  X +* ##I (:DPT: : : :(      % % %>
 
 
    rC   r   c                    dS )zj
    TODO: implement this function

    DisjointClasses(' description description { description } ')'
    Nr^   )r  s    r@   r   r     s	     	DrC   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-   a  
    ```
    restriction ::= 'restriction('
    datavaluedPropertyID dataRestrictionComponent
    { dataRestrictionComponent } ')'
    | 'restriction(' individualvaluedPropertyID
    individualRestrictionComponent
    { individualRestrictionComponent } ')'
    ```
    Nc
                F   |t                      n|}t          t          |                               |	|d           | j        t
          j        t          |          f|vr4|                    | 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 |
D             }t          |          st!          d          |                                \  }}|| _        t'          |t(                    r|| _        n\t'          |t,                    rt/          |          | _        n2t1          | j                            | j        |                    | _        | j        || j        f| j        vr'| j                            | j        || j        f           | j        J t-          | j                              | j        t6          j        t
          j        f| j        vrn| j                            | j        t6          j        t
          j        f           | j                            | j        t6          j        t
          j        f           d S d S )NTr  c                     g | ]\  }}|||fS r<   r^   )ry   r   oterms      r@   r|   z(Restriction.__init__.<locals>.<listcomp>+  s!    WWWJQaZrC   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_typesvalid_restr_propsrestriction_rangerestriction_typer  s                 r@   rA   zRestriction.__init__
  s    !=ek4  ))eD 	* 	
 	
 	
 ON ,,
 	 
 II#.2Fz2R2RS   %C-.S/0CL!#/*S/0S/0
 XW+WWW$%% 	%  
 /@.C.C.E.E++/'44 		$5D!!)511 	$56G$H$HD!! %*
""4?4DEE% %D!
 O!
 	 
 JNNDO-=t?TUVVV$00%2H2H000OSXs7tzIIJNNDOSXsGHHHJt#)DEEEEE JIrC   c                j   t          | j        | j        d                              |           | j                            | j        ddf          D ]`\  }}}|                    |||f           |t          j        t          j	        fv r(t          || j                                      |           adS )aK  
        ```python
        >>> 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')]

        ```
        Nr]  )r+   r   rj   r   r   rp   r   r	   r   r   r   )r?   rj   r   r   r   s        r@   r   zRestriction.serializeI  s    2 	
TBBBLLUSSSz))4?D$*GHH 	: 	:GAq!IIq!Qi   S&(:;;;!TZ((225999	: 	:rC   c                    dS r.  r^   r   s    r@   r  zRestriction.isPrimitiveh  r/  rC   c                8    t          | j        | j        f          S r<   )r  r   ra  r   s    r@   r  zRestriction.__hash__k  s    T_d&;<===rC   c                   t          |t                    s4J t          |          t          t          |                    z               t          |t                    r |j        | j        k    o|j        | j        k    S dS )z
        Equivalence of restrictions is determined by equivalence of the
        property in question and the restriction 'range'
        F)ro   r   r  r   r-   r   rd  ra  rL   s     r@   r  zRestriction.__eq__n  sz    
 %''HHetDKK7H7H)HHH'e[)) 	 DO3 E+t/DD 5rC   c                ~    t          | j                            | j        t          j                            d         S )Nr   r   )rc   rj   r   rp   r	   r   r   s    r@   _get_onpropertyzRestriction._get_onproperty}  s8    Jt#.QQ
 

 	rC   c                    |sd S | j         t          j        t          |          f}|| j        v rd S | j                            |           d S r<   )rp   r	   r   r7   rj   rQ  )r?   r   triples      r@   _set_onpropertyzRestriction._set_onproperty  sT     	F/3>3G3M3MNTZFJNN6"""""rC   c                    d S r<   r^   r   s    r@   _del_onpropertyzRestriction._del_onproperty  r  rC   c                    | j                             | j        t          j                  D ]}t          || j                   c S d S r  )rj   r   rp   r	   r   r   r?   r   s     r@   _get_allvaluesfromzRestriction._get_allvaluesfrom  sT    ##Os/@ $ 
 
 	. 	.A $*------trC   c                    |sd S | j         t          j        t          |          f}|| j        v rd S | j                            |           d S r<   )rp   r	   r   r.   rj   rQ  r?   rH   rm  s      r@   _set_allvaluesfromzRestriction._set_allvaluesfrom  sU     	F/3#46G6N6NOTZFJNN6"""""rC   c                    d S r<   r^   r   s    r@   _del_allvaluesfromzRestriction._del_allvaluesfrom  r  rC   c                    | j                             | j        t          j                  D ]}t          || j                   c S d S r  )rj   r   rp   r	   r   r   rr  s     r@   _get_somevaluesfromzRestriction._get_somevaluesfrom  T    ##Os/A $ 
 
 	. 	.A $*------trC   c                    |sd S | j         t          j        t          |          f}|| j        v rd S | j                            |           d S r<   )rp   r	   r   r.   rj   rQ  ru  s      r@   _set_somevaluesfromzRestriction._set_somevaluesfrom  U     	F/3#57H7O7OPTZFJNN6"""""rC   c                    d S r<   r^   r   s    r@   _del_somevaluesfromzRestriction._del_somevaluesfrom  r  rC   c                    | j                             | j        t          j                  D ]}t          || j                   c S d S r  )rj   r   rp   r	   r   r   rr  s     r@   _get_hasvaluezRestriction._get_hasvalue  sJ    ##DOs|#TT 	. 	.A$*------trC   c                    |sd S | j         t          j        t          |          f}|| j        v rd S | j                            |           d S r<   )rp   r	   r   r.   rj   rQ  ru  s      r@   _set_hasvaluezRestriction._set_hasvalue  sT     	F/3<1B51I1IJTZFJNN6"""""rC   c                    d S r<   r^   r   s    r@   _del_hasvaluezRestriction._del_hasvalue  r  rC   c                    | j                             | j        t          j                  D ]}t          || j                   c S d S r  )rj   r   rp   r	   r   r   rr  s     r@   _get_cardinalityzRestriction._get_cardinality  sJ    ##DOs#WW 	. 	.A$*------trC   c                    |sd S | j         t          j        t          |          f}|| j        v rd S | j                            |           d S r<   )rp   r	   r   r/   rj   rQ  ru  s      r@   _set_cardinalityzRestriction._set_cardinality  sS     	F/3?K4F4FGTZFJNN6"""""rC   c                    d S r<   r^   r   s    r@   _del_cardinalityzRestriction._del_cardinality  r  rC   c                    | j                             | j        t          j                  D ]}t          || j                   c S d S r  )rj   r   rp   r	   r   r   rr  s     r@   _get_maxcardinalityzRestriction._get_maxcardinality  r{  rC   c                    |sd S | j         t          j        t          |          f}|| j        v rd S | j                            |           d S r<   )rp   r	   r   r/   rj   rQ  ru  s      r@   _set_maxcardinalityzRestriction._set_maxcardinality  sT     	F/3#5{57I7IJTZFJNN6"""""rC   c                    d S r<   r^   r   s    r@   _del_maxcardinalityzRestriction._del_maxcardinality  r  rC   c                    | j                             | j        t          j                  D ]}t          || j                   c S d S r  )rj   r   rp   r	   r   r   rr  s     r@   _get_mincardinalityzRestriction._get_mincardinality  r{  rC   c                    |sd S | j         t          j        t          |          f}|| j        v rd S | j                            |           d S r<   )rp   r	   r   r.   rj   rQ  ru  s      r@   _set_mincardinalityzRestriction._set_mincardinality
  r~  rC   c                    d S r<   r^   r   s    r@   _del_mincardinalityzRestriction._del_mincardinality  r  rC   c                    | j                             | j        | j        d f          D ]4\  }}}|                    t          t                              d         c S d S )Nr  )rj   r   rp   r  r  r   r	   )r?   r   r   r   s       r@   restrictionKindzRestriction.restrictionKind  sb    z11_d3T:
 
 	) 	)GAq!
 773s88$$R((((trC   c                6    t          | j        | j                  S )zO
        Returns the Manchester Syntax equivalent for this restriction
        )r2   rp   rj   r   s    r@   r  zRestriction.__repr__$  s      <<<rC   )NNNNNNNN),r[   r\   r]   r  r	   r   r   r   r   r   r   r  rA   r   r  r  r  rk  rn  r   r   rp  r  rs  rv  rx  rz  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rK  rL  s   @r@   r-   r-     s       	 	 	 =F =F =F =F =F =F~: : :>  > > >    
# # # ''  (' / J  # # # )**  +* H.0B M  # # # *++  ,+ X02E N  
# # # %%  &% x}mDDH  
# # # ((  )( (+-=?OPPK  # # # *++  ,+ X02E N  # # # *++  ,+ X02E N  = = = = = = =rC   r-   c                0    t          | |j        |          S )N)rj   r   r-   rj   r   r  s     r@   rI   rI   /  s    TfUUU rC   c                0    t          | |j        |          S )N)rj   r   r  r  s     r@   rI   rI   2  s    TVTTT rC   c                0    t          | | j        |          S )N)rj   r   r  r  s     r@   rI   rI   5      TFSSS rC   c                0    t          | | j        |          S )N)rj   r   r  r  s     r@   rI   rI   8  r  rC   c                0    t          | | j        |          S )N)rj   r   r  r  s     r@   rI   rI   ;  s    TPPP rC   c                0    t          | | j        |          S )N)rj   r9   r  r  s     r@   rI   rI   =  s    ;t4:V#T#T#T rC   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j                  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                D   t          |t                    r|\  }}}n|}|}|}|r'| j        |                     |          fg| j        _        |r'| j        |                     |          fg| j        _        |r)| j        |                     |          fg| j        _        dS dS )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  r0  r2  )r?   verb_annotationsr.  r0  tv_vbgs        r@   setupVerbAnnotationszProperty.setupVerbAnnotationsY  s     &.. 	&+;(Iy&&(I(I%F 	$"7"7	"B"BC%DN!  	$"7"7	"B"BC%DN!  	X'+8M8Mf8U8U&V%WDO"""	X 	XrC   NFc                   t          t          |                               ||||           |r|                     |           t	          | j        t                    rJ |3t          t          | j        | j	                  j
                  | _        nN| j        t          j
        |f| j	        vr,| j	                            | j        t          j
        |f           || _        || _        || _        || _        || _        |
g n|
| _        d S )Nr   )r  r+   rA   r  ro   rp   r   r   r%   rj   r   	_baseTyper
   r   subPropertyOf	inverseOfdomainr  r4  )r?   rp   rj   r%  r  r  r  r  	otherTypeequivalentPropertyr4  verbAnnotationsr  r  r  s                 r@   rA   zProperty.__init__x  s      	h&&z5.+VVV 	7%%o666dou55555":doTZ#P#P#P#UVVDNN84DJFF
8DEEE%DN*"
$_rr'rC   c                |   | j                             | j        d d f          D ]}|                    |           t	          j        | j        | j                  D ]}|                    |           t	          j        | j	        | j
                  D ]*}t          || j                                       |           +d S r<   )rj   r   rp   r   r  r  r  r  r   r  r  r   )r?   rj   r   r   r   s        r@   r   zProperty.serialize  s    J&&t'DEE 	 	DIIdOOOO!3T^DD 	 	AKKdj99 	6 	6Aa$$..u5555	6 	6rC   c              #  h   K   |d u r| j         p|                    d | j        d f          D ]}|V  d S r<   )rj   r   rp   )r?   rj   rm  s      r@   r  zProperty._get_extent  sX      }3<uEE4?D)
 
 	 	F LLLL	 	rC   c                b    |sd S |D ]'\  }}| j                             || j        |f           (d S r<   )rj   r   rp   )r?   rH   subjobjs       r@   r  zProperty._set_extent  sL     	F 	9 	9ID#JNND$/378888	9 	9rC   c           
     X    g }t           j         j        v r|                    d j        dt           j                  rt           j                  pdd           t           j                  rt          t           j                  j                  }|r*|j         j        k    rt           j                  j        }n!t          t           j                            }|                    d|dt           j
         j        v rdpd            j                             j        t          j        t           j        t           j        t           j        gf          D ]S\  }}}|                    t#          |                    t#          t                               d                              Tn|                    d	 j        d
t           j                  rt           j                  pd            j                             j        t          j        t           j        f          D ]\  }}}|                    d           d |                    d
                     fd j        D                                  |                    d
                     fd j        D                                  |                    d
                     fd j        D                                  d                    d |D                       }|dz  }|S )NzObjectProperty( z annotation(r  r   z  inverseOf( r   z
 Symmetricr  zDatatypeProperty( r   z   Functionalc                \   t          |           }t          |t                    r| S |                    t                    rt          |           S t          |                    |t          j	        t          j
        gd f                    rt          |           S t          | j                  S r<   )r.   ro   r   rq  r   r   r   r   r	   r   r   r  r   )r  gnormalized_names      r@   canonicalNamez(Property.__repr__.<locals>.canonicalName  s    /55O/511 ' ++C00 	'4yy !!$s{C4F&GN   '
 Dzz!4:&rC   c                8    g | ]}d  |j                   z  S )z   super( %s )r   )ry   super_propertyr  r?   s     r@   r|   z%Property.__repr__.<locals>.<listcomp>  s<       & %}}^TZ'P'PP  rC   c                8    g | ]}d  |j                   z  S )z   domain( %s )r   )ry   r  r  r?   s     r@   r|   z%Property.__repr__.<locals>.<listcomp>  s<        &fdj(I(II  rC   c                8    g | ]}d  |j                   z  S )z   range( %s )r   )ry   r  r  r?   s     r@   r|   z%Property.__repr__.<locals>.<listcomp>  s<        %}}UDJ'G'GG  rC   r   c                    g | ]}||S r^   r^   )ry   exprs     r@   r|   z%Property.__repr__.<locals>.<listcomp>	  s    444t4444rC   z
))r	   rc  r   r   r   r   r4  r  rp   r  r^  rj   r   r
   r_  r`  ra  r   r  r   ri   r  r  r  )r?   rttwo_link_inverseinversereprr   re  roletyper  s   `      @r@   r  zProperty.__repr__  s   **III:::uT\22JuT\7J7JPbPPR   T^$$ #(t~)>)>)H#I#I # >(8(Ct(V(V"'"7"7"=KK"&uT^'<'<"="=K			 $-:K|QrQ   %)J$>$> OH.5.% % = = B 		#hnnSXX66r:;;<<<<= III:::uT\22JuT\7J7JPbPR   %)J$6$6#(C,BC% % + + B 		/****	' 	' 	' 			HH    *.*<   	
 	
 	
 			HH    "&+   	
 	
 	
 			HH    !%   	
 	
 	
 YY4444455
e	rC   c              #     K   | j                             | j        t          j                  D ]}t          || j         d           V  d S Nr   r]  )rj   r   rp   r   r  r+   r  s     r@   _get_subpropertyofzProperty._get_subpropertyof
	  sf      :%%Ot/A & 
 
 	A 	AC 3dj4@@@@@@@	A 	ArC   c                    |sd S |D ];}| j                             | j        t          j        t          |          f           <d S r<   )rj   r   rp   r   r  r.   )r?   rH   subpropertys      r@   _set_subpropertyofzProperty._set_subpropertyof	  s]     	F  	 	KJNN$"46G6T6TU   	 	rC   c                    d S r<   r^   r   s    r@   _del_subpropertyofzProperty._del_subpropertyof	  r  rC   c              #     K   | j                             | j        t          j                  D ]}t          || j         d           V  d S r  )rj   r   rp   r	   r  r+   r  s     r@   _get_inverseofzProperty._get_inverseof 	  s\      :%%do%WW 	A 	AC3dj4@@@@@@@	A 	ArC   c                    |sd S | j                             | j        t          j        t          |          f           d S r<   )rj   r   rp   r	   r  r.   rL   s     r@   _set_inverseofzProperty._set_inverseof$	  s=     	F
8I%8P8PQRRRRRrC   c                    d S r<   r^   r   s    r@   _del_inverseofzProperty._del_inverseof)	  r  rC   c              #     K   | j                             | j        t          j                  D ]}t          || j                   V  d S r  )rj   r   rp   r   r  r   )r?   doms     r@   _get_domainzProperty._get_domain/	  sV      :%%do%UU 	/ 	/C4:.......	/ 	/rC   c                8   |sd S t          |t          t          f          r;| j                            | j        t          j        t          |          f           d S |D ];}| j                            | j        t          j        t          |          f           <d S r<   )	ro   r%   r   rj   r   rp   r   r  r.   )r?   rH   r  s      r@   _set_domainzProperty._set_domain3	  s     	Fej*566 	WJNNDOT[:KE:R:RSTTTTT W W
>OPS>T>TUVVVVW WrC   c                    d S r<   r^   r   s    r@   _del_domainzProperty._del_domain<	  r  rC   c              #     K   | j                             | j        t          j                  D ]}t          || j                   V  d S r  )rj   r   rp   r   r  r   )r?   rans     r@   
_get_rangezProperty._get_rangeB	  sV      :%%do%TT 	/ 	/C4:.......	/ 	/rC   c                8   |sd S t          |t          t          f          r;| j                            | j        t          j        t          |          f           d S |D ];}| j                            | j        t          j        t          |          f           <d S r<   )	ro   r%   r   rj   r   rp   r   r  r.   )r?   rangesr  s      r@   
_set_rangezProperty._set_rangeF	  s     	Ffz:677 	XJNNDOTZ9J69R9RSTTTTT X X
=Nu=U=UVWWWWX XrC   c                    d S r<   r^   r   s    r@   
_del_rangezProperty._del_rangeO	  r  rC   c                    | j         D ]0\  }}}| j                            |t          |          |f           1| j                            d | j        d f           d S r<   )r  rj   r   r7   r   rp   )r?   rH   r   re  r   s        r@   r   zProperty.replaceU	  sg     	@ 	@HAr1JNNA3E::A>????
4$788888rC   r<   )"r[   r\   r]   r  r  r	   rc  rA   r   r  r  r  r  r  r  r  r   r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   rK  rL  s   @r@   r+   r+   G  su        "X X XB # :  :  :  :  :  :D6 6 6   9 9 9 Xk;//FX X XtA A A   *++  ,+ H.0B MA A AS S S
 &&  '& HHI/ / /W W W $$  %$ Xk;<<F/ / /X X X 
##  $# HZZ88E9 9 9 9 9 9 9rC   r+   c                ^   |i n|}t          |           }|                    dt                     |                    dt                     |                    dt                     t          |                                          D ]\  }}|                    ||d           || _        dS )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     '.BBLM(//64(((5#&&&5#&&&M//1122 < <vsU;;;;/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   rQ  
differencer   r   r   r   r  rO  rR  backwardCompatibleWithincompatibleWithr   r   r   r   r!   r"   r^  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     sY  U Un # " " " " "      " " " " " " " " ( ( ( ( ( ( + + + + + + + + M M M M M M M M M M M M M M M M D D D D D D D D D D D D D D      		8	$	$& & &\- - - - - - - -* 3F9::
, ) ) )
       /4e e e eP         [@ [@ [@ [@ [@ [@ [@ [@| 
<	=	=@< @< @< @< @<z @< @< @<FA A A A A A A A@  
; ; ;># # # # #I # # # #I@AA *"	  (+& +& +&\C
 C
 C
L	 	 	 	 	Z 	 	 	    .   Y Y Y YDw w w w w w w wtG G G G G G G GTA A A A Aou A A AH '5        B- - - - - - - -q q q q q?E q q qh	 	 	s= s= s= s= s=% s= s= s=r	 uUU  uTT  eSS  eSS  %PP  	TTUU& R9 R9 R9 R9 R9 R9 R9 R9j0 0 0 0 0 0rC   