§
    šŠtjK)  ã                  ó.  — d dl mZ d dlmZmZmZmZ erd dlZdddddœZed	         d
z   Z	ed	         dz   Z
ed	         dz   Zed	         dz   Zed         ed	         z   dz   Zed	         ed         z   dz   Zed	         ed         z   dz   Z G d„ d¦  «        ZdS )é    )Úannotations)ÚTYPE_CHECKINGÚDictÚListÚOptionalNz-PREFIX owl: <http://www.w3.org/2002/07/owl#>
z:PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
z5PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
z0PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
)ÚowlÚrdfÚrdfsÚxsdr
   zeSELECT DISTINCT ?cls ?com
WHERE { 
    ?instance a ?cls . 
    OPTIONAL { ?cls rdfs:comment ?com } 
}zvSELECT DISTINCT ?cls ?com
WHERE { 
    ?instance a/rdfs:subClassOf* ?cls . 
    OPTIONAL { ?cls rdfs:comment ?com } 
}z’SELECT DISTINCT ?cls ?com
WHERE { 
    ?instance a/rdfs:subClassOf* ?cls . 
    FILTER (isIRI(?cls)) . 
    OPTIONAL { ?cls rdfs:comment ?com } 
}zdSELECT DISTINCT ?rel ?com
WHERE { 
    ?subj ?rel ?obj . 
    OPTIONAL { ?rel rdfs:comment ?com } 
}r	   z|SELECT DISTINCT ?rel ?com
WHERE { 
    ?rel a/rdfs:subPropertyOf* rdf:Property . 
    OPTIONAL { ?rel rdfs:comment ?com } 
}r   zSELECT DISTINCT ?op ?com
WHERE { 
    ?op a/rdfs:subPropertyOf* owl:ObjectProperty . 
    OPTIONAL { ?op rdfs:comment ?com } 
}z�SELECT DISTINCT ?dp ?com
WHERE { 
    ?dp a/rdfs:subPropertyOf* owl:DatatypeProperty . 
    OPTIONAL { ?dp rdfs:comment ?com } 
}c                  ó|   — e Zd ZdZ	 	 	 	 	 	 	 	 dd d„Zed!d„¦   «         Zd"d„Zd#d„Ze	d$d„¦   «         Z
d%d„Zd&d„ZdS )'ÚRdfGraphaì  RDFlib wrapper for graph operations.

    Modes:
    * local: Local file - can be queried and changed
    * online: Online file - can only be queried, changes can be stored locally
    * store: Triple store - can be queried and changed if update_endpoint available
    Together with a source file, the serialization should be specified.

    *Security note*: Make sure that the database connection uses credentials
        that are narrowly-scoped to only include necessary permissions.
        Failure to do so may result in data corruption or loss, since the calling
        code may attempt commands that would result in deletion, mutation
        of data if appropriately prompted or reading sensitive data if such
        data is present in the database.
        The best way to guard against such negative outcomes is to (as appropriate)
        limit the permissions granted to the credentials used with this tool.

        See https://python.langchain.com/docs/security for more information.
    NÚttlr	   Úsource_fileúOptional[str]ÚserializationÚquery_endpointÚupdate_endpointÚstandardÚ
local_copyÚgraph_kwargsúOptional[Dict]Ústore_kwargsÚreturnÚNonec	                ó~  — || _         || _        || _        || _        || _        || _        	 ddl}	ddlm}
 n# t          $ r t          d¦  «        ‚w xY w| j        dx}vrt          d|› d�¦  «        ‚|s|r|r|s|rt          d¦  «        ‚|rl|                     d	¦  «        rd
| _        nd| _        | j        €| j         | _         |	j        ¦   «         | _        | j                             || j        ¬¦  «         |r„|pi }d| _        |s- |
j        di |¤Ž| _        | j                             |¦  «         n. |
j        di |¤Ž| _        | j                             ||f¦  «         |pi } |	j        | j        fi |¤Ž| _        t)          | j        ¦  «        st+          d¦  «        ‚d| _        |                      ¦   «          dS )aä  
        Set up the RDFlib graph

        :param source_file: either a path for a local file or a URL
        :param serialization: serialization of the input
        :param query_endpoint: SPARQL endpoint for queries, read access
        :param update_endpoint: SPARQL endpoint for UPDATE queries, write access
        :param standard: RDF, RDFS, or OWL
        :param local_copy: new local copy for storing changes
        :param graph_kwargs: Additional rdflib.Graph specific kwargs
        that will be used to initialize it,
        if query_endpoint is provided.
        :param store_kwargs: Additional sparqlstore.SPARQLStore specific kwargs
        that will be used to initialize it,
        if query_endpoint is provided.
        r   N)ÚsparqlstorezTCould not import rdflib python package. Please install it with `pip install rdflib`.)r	   r
   r   z+Invalid standard. Supported standards are: ú.z–Could not unambiguously initialize the graph wrapper. Specify either a file (local or online) via the source_file or a triple store via the endpoints.ÚhttpÚonlineÚlocal)ÚformatÚstorezThe graph is empty.Ú © )r   r   r   r   r   r   ÚrdflibÚrdflib.plugins.storesr   ÚImportErrorÚ
ValueErrorÚ
startswithÚmodeÚGraphÚgraphÚparseÚSPARQLStoreÚ_storeÚopenÚSPARQLUpdateStoreÚlenÚAssertionErrorÚschemaÚload_schema)Úselfr   r   r   r   r   r   r   r   r%   r   Úsupported_standardss               úb/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/langchain_community/graphs/rdf_graph.pyÚ__init__zRdfGraph.__init__o   sk  € ð6 'ˆÔØ*ˆÔØ,ˆÔØ.ˆÔØ ˆŒØ$ˆŒð	ØˆMˆMˆMØ9Ð9Ð9Ð9Ð9Ð9Ð9øÝð 	ð 	ð 	Ýð?ñô ð ð	øøøð
 Œ=Ð8NÐ!NÐ!4ÐOÐOÝØTÐ>QÐTÐTÐTñô ð ð
 ð
	à"ð
	ð ð
	ð  ð	
	ð $3ð	
	õ ð7ñô ð ð ð 	EØ×%Ò% fÑ-Ô-ð 7Ø$�”	�	à#�”	Ø”?Ð*Ø&*Ô&6�D”OØ%˜œ™œˆDŒJØŒJ×Ò˜[°Ô1CÐÑDÔDÐDàð 
	CØ'Ð-¨2ˆLØˆDŒIØ"ð DØ5˜kÔ5ÐEÐE¸ÐEÐE�”Ø”× Ò  Ñ0Ô0Ð0Ð0à;˜kÔ;ÐKÐK¸lÐKÐK�”Ø”× Ò  .°/Ð!BÑCÔCÐCØ'Ð-¨2ˆLØ%˜œ d¤kÐBÐB°\ÐBÐBˆDŒJõ �4”:‰Œð 	8Ý Ð!6Ñ7Ô7Ð7ð ˆŒØ×ÒÑÔÐÐÐs	   ¬
7 ·AÚstrc                ó   — | j         S )z;
        Returns the schema of the graph database.
        )r4   )r6   s    r8   Ú
get_schemazRdfGraph.get_schemaÈ   s   € ð
 Œ{Ðó    ÚqueryúList[rdflib.query.ResultRow]c                ó®   ‡— ddl m} ddlmŠ 	 | j                             |¦  «        }n# |$ r}t          d|› �¦  «        ‚d}~ww xY wˆfd„|D ¦   «         S )z"
        Query the graph.
        r   ©ÚParserError)Ú	ResultRowú&Generated SPARQL statement is invalid
Nc                ó4   •— g | ]}t          |‰¦  «        ¯|‘ŒS r$   )Ú
isinstance)Ú.0ÚrrC   s     €r8   ú
<listcomp>z"RdfGraph.query.<locals>.<listcomp>Ý   s(   ø€ Ð;Ð;Ð;�a¥*¨Q°	Ñ":Ô":Ð;�Ð;Ð;Ð;r=   )Úrdflib.exceptionsrB   Úrdflib.queryrC   r,   r>   r(   )r6   r>   rB   ÚresÚerC   s        @r8   r>   zRdfGraph.queryÏ   sš   ø€ ð 	2Ð1Ð1Ð1Ð1Ð1Ø*Ð*Ð*Ð*Ð*Ð*ð	LØ”*×"Ò" 5Ñ)Ô)ˆCˆCøØð 	Lð 	Lð 	LÝÐJÀqÐJÐJÑKÔKÐKøøøøð	Løøøà;Ð;Ð;Ð;˜3Ð;Ñ;Ô;Ð;s   �* ªA¯AÁAc                ó2  — ddl m} 	 | j                             |¦  «         n# |$ r}t	          d|› �¦  «        ‚d}~ww xY w| j        rA| j                             | j        | j                             d¦  «        d         ¬¦  «         dS t	          d¦  «        ‚)	z#
        Update the graph.
        r   rA   rD   Nr   éÿÿÿÿ)Údestinationr!   z5No target file specified for saving the updated file.)rJ   rB   r,   Úupdater(   r   Ú	serializeÚsplit)r6   r>   rB   rM   s       r8   rQ   zRdfGraph.updateß   sÐ   € ð 	2Ð1Ð1Ð1Ð1Ð1ð	LØŒJ×Ò˜eÑ$Ô$Ð$Ð$øØð 	Lð 	Lð 	LÝÐJÀqÐJÐJÑKÔKÐKøøøøð	LøøøàŒ?ð 	VØŒJ× Ò Ø œO°D´O×4IÒ4IÈ#Ñ4NÔ4NÈrÔ4Rð !ñ ô ð ð ð õ ÐTÑUÔUÐUs   ˆ# £?¨:º?Úiric                ó¬   — d| v r|                       d¦  «        d         }n3d| v r|                       d¦  «        d         }nt          d| › d�¦  «        ‚|S )Nú#rO   ú/zUnexpected IRI 'z ', contains neither '#' nor '/'.)rS   r(   )rT   Ú
local_names     r8   Ú_get_local_namezRdfGraph._get_local_nameó   s`   € à�#ˆ:ˆ:ØŸš 3™œ¨Ô+ˆJˆJØ�CˆZˆZØŸš 3™œ¨Ô+ˆJˆJåÐU°ÐUÐUÐUÑVÔVÐVØÐr=   rL   úrdflib.query.ResultRowÚvarc                ó¨   — dt          ||         ¦  «        z   dz   |                      ||         ¦  «        z   dz   t          |d         ¦  «        z   dz   S )Nú<z> (ú, Úcomú))r:   rY   )r6   rL   r[   s      r8   Ú_res_to_strzRdfGraph._res_to_strý   sh   € àÝ�#�c”(‰mŒmñàñð ×"Ò" 3 s¤8Ñ,Ô,ñ-ð ñ	õ
 �#�e”*‰oŒoñð ñð	
r=   c           	     ó  ‡ — dˆ fd„}‰ j         dk    rG‰                      t          ¦  «        }‰                      t          ¦  «        } |||¦  «        ‰ _        dS ‰ j         dk    rG‰                      t
          ¦  «        }‰                      t          ¦  «        } |||¦  «        ‰ _        dS ‰ j         d	k    r¾‰                      t          ¦  «        }‰                      t          ¦  «        }‰                      t          ¦  «        }d
d 
                    ˆ fd„|D ¦   «         ¦  «        › dd 
                    ˆ fd„|D ¦   «         ¦  «        › dd 
                    ˆ fd„|D ¦   «         ¦  «        › d�‰ _        dS t          d‰ j         › d�¦  «        ‚)z4
        Load the graph schema information.
        Úclassesr?   Úrelationshipsr   r:   c                ó’   •— dd                      ˆfd„| D ¦   «         ¦  «        › dd                      ˆfd„|D ¦   «         ¦  «        › d�S )NzšIn the following, each IRI is followed by the local name and optionally its description in parentheses. 
The RDF graph supports the following node types:
r^   c                ó<   •— g | ]}‰                      |d ¦  «        ‘ŒS ©Úcls©ra   ©rG   rH   r6   s     €r8   rI   z?RdfGraph.load_schema.<locals>._rdf_s_schema.<locals>.<listcomp>  s)   ø€ ÐJÐJÐJ¸Q˜d×.Ò.¨q°%Ñ8Ô8ÐJÐJÐJr=   z5
The RDF graph supports the following relationships:
c                ó<   •— g | ]}‰                      |d ¦  «        ‘ŒS )Úrelri   rj   s     €r8   rI   z?RdfGraph.load_schema.<locals>._rdf_s_schema.<locals>.<listcomp>  s)   ø€ ÐPÐPÐP¸Q˜d×.Ò.¨q°%Ñ8Ô8ÐPÐPÐPr=   ú
)Újoin)rc   rd   r6   s     €r8   Ú_rdf_s_schemaz+RdfGraph.load_schema.<locals>._rdf_s_schema  sx   ø€ ð
Vð —9’9ÐJÐJÐJÐJÀ'ÐJÑJÔJÑKÔKðVð Vð
 —9’9ÐPÐPÐPÐPÀ-ÐPÑPÔPÑQÔQðVð Vð Vðr=   r	   r
   r   zšIn the following, each IRI is followed by the local name and optionally its description in parentheses. 
The OWL graph supports the following node types:
r^   c                ó<   •— g | ]}‰                      |d ¦  «        ‘ŒS rg   ri   rj   s     €r8   rI   z(RdfGraph.load_schema.<locals>.<listcomp>*  s)   ø€ ÐGÐGÐG¸Q˜d×.Ò.¨q°%Ñ8Ô8ÐGÐGÐGr=   z^
The OWL graph supports the following object properties, i.e., relationships between objects:
c                ó<   •— g | ]}‰                      |d ¦  «        ‘ŒS )Úopri   rj   s     €r8   rI   z(RdfGraph.load_schema.<locals>.<listcomp>-  ó)   ø€ ÐEÐEÐE¸A˜d×.Ò.¨q°$Ñ7Ô7ÐEÐEÐEr=   zi
The OWL graph supports the following data properties, i.e., relationships between objects and literals:
c                ó<   •— g | ]}‰                      |d ¦  «        ‘ŒS )Údpri   rj   s     €r8   rI   z(RdfGraph.load_schema.<locals>.<listcomp>0  rs   r=   rm   zMode 'z' is currently not supported.N)rc   r?   rd   r?   r   r:   )r   r>   Úcls_query_rdfÚrel_query_rdfr4   Úcls_query_rdfsÚrel_query_rdfsÚcls_query_owlÚop_query_owlÚdp_query_owlrn   r(   )r6   ro   ÚclssÚrelsÚopsÚdpss   `     r8   r5   zRdfGraph.load_schema  sº  ø€ ð
	ð 	ð 	ð 	ð 	ð 	ð Œ=˜EÒ!Ð!Ø—:’:�mÑ,Ô,ˆDØ—:’:�mÑ,Ô,ˆDØ'˜-¨¨dÑ3Ô3ˆDŒKˆKˆKØŒ]˜fÒ$Ð$Ø—:’:�nÑ-Ô-ˆDØ—:’:�nÑ-Ô-ˆDØ'˜-¨¨dÑ3Ô3ˆDŒKˆKˆKØŒ]˜eÒ#Ð#Ø—:’:�mÑ,Ô,ˆDØ—*’*�\Ñ*Ô*ˆCØ—*’*�\Ñ*Ô*ˆCð	Kð —9’9ÐGÐGÐGÐGÀ$ÐGÑGÔGÑHÔHð	Kð 	Kð —9’9ÐEÐEÐEÐEÀÐEÑEÔEÑFÔFð	Kð 	Kð —9’9ÐEÐEÐEÐEÀÐEÑEÔEÑFÔFð	Kð 	Kð 	Kð ŒKˆKˆKõ ÐR d¤mÐRÐRÐRÑSÔSÐSr=   )Nr   NNr	   NNN)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>   r:   r   r   )rT   r:   r   r:   )rL   rZ   r[   r:   r   r:   )r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r9   Úpropertyr<   r>   rQ   ÚstaticmethodrY   ra   r5   r$   r=   r8   r   r   Z   sñ   € € € € € ðð ð, &*Ø',Ø(,Ø)-Ø"'Ø$(Ø'+Ø'+ðWð Wð Wð Wð Wðr ðð ð ñ „Xðð<ð <ð <ð <ð Vð Vð Vð Vð( ðð ð ñ „\ðð	
ð 	
ð 	
ð 	
ð+Tð +Tð +Tð +Tð +Tð +Tr=   r   )Ú
__future__r   Útypingr   r   r   r   r%   Úprefixesrv   rx   rz   rw   ry   r{   r|   r   r$   r=   r8   ú<module>rŠ      sŽ  ðØ "Ð "Ð "Ð "Ð "Ð "ðð ð ð ð ð ð ð ð ð ð ð ð ð Ø€M€M€Mð @ØLØHØBð	ð €ð ˜Ô ðñ€ð ˜&Ô!ðñ€ð ˜Ô ðñ€ð ˜Ô ðñ€ð ˆU„OØˆvÔñð	ñð ð ˆVÔØˆu„oñð	ñð ð ˆVÔØˆu„oñð	ñð ðYTð YTð YTð YTð YTñ YTô YTð YTð YTð YTr=   