Ë
    µŒjô(  ã                   óŠ   — d dl Z d dlmZ d dlmZmZmZmZ d dlZd dl	m
Z
 dZdZddeedœZ e
dd	d
¬«       G d„ d«      «       Zy)é    N)ÚSimpleNamespace)ÚAnyÚDictÚOptionalÚSequence)Ú
deprecatedzD
SELECT DISTINCT ?elem 
WHERE { 
 ?elem a owl:DatatypeProperty . 
}
zB
SELECT DISTINCT ?elem 
WHERE { 
 ?elem a owl:ObjectProperty . 
}
)ÚclassesÚrelsÚdtpropsÚopropsz0.3.15z1.0zlangchain_aws.NeptuneRdfGraph)ÚsinceÚremovalÚalternative_importc                   óü   — e Zd ZdZ	 	 	 	 	 	 	 	 ddedededededee   d	ee   d
ededdfd„Z	e
defd„«       Ze
deeef   fd„«       Zdeeef   fd„Zdedeeef   fd„Zdeeef   ddfd„Zdedee   fd„Zdd„Zy)ÚNeptuneRdfGraphaÂ  Neptune wrapper for RDF graph operations.

    Args:
        host: endpoint for the database instance
        port: port number for the database instance, default is 8182
        use_iam_auth: boolean indicating IAM auth is enabled in Neptune cluster
        use_https: whether to use secure connection, default is True
        client: optional boto3 Neptune client
        credentials_profile_name: optional AWS profile name
        region_name: optional AWS region, e.g., us-west-2
        service: optional service name, default is neptunedata
        sign: optional, whether to sign the request payload, default is True

    Example:
        .. code-block:: python

        graph = NeptuneRdfGraph(
            host='<SPARQL host'>,
            port=<SPARQL port>
        )
        schema = graph.get_schema()

        OR
        graph = NeptuneRdfGraph(
            host='<SPARQL host'>,
            port=<SPARQL port>
        )
        schema_elem = graph.get_schema_elements()
        #... change schema_elements ...
        graph.load_schema(schema_elem)

    *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ÚhostÚportÚ	use_httpsÚuse_iam_authÚclientÚcredentials_profile_nameÚregion_nameÚserviceÚsignÚreturnc
                 ó�  — || _         || _        d|› d|› d�| _        	 |�|| _        n­dd l}
|�|
j                  |¬«      | _        n|
j                  «       | _        i }|r||d<   |rdnd}|› d	|› d|› �|d
<   |	r# | j                  j                  |fi |¤Ž| _        n9ddlm} ddl	m
}  | j                  j                  |fi |¤d ||¬«      i¤Ž| _        d| _        i | _        | j%                  «        y # t        $ r t        d«      ‚t        $ r5}t        |«      j                  dk(  rt        d«      |‚t        d«      |‚d }~ww xY w)Nzhttps://Ú:z/sparqlr   )Úprofile_namer   ÚhttpsÚhttpz://Úendpoint_url)ÚUNSIGNED)ÚConfigÚconfig)Úsignature_versionzRCould not import boto3 python package. Please install it with `pip install boto3`.ÚUnknownServiceErrorzgNeptuneGraph requires a boto3 version 1.28.38 or greater.Please install it with `pip install -U boto3`.z‚Could not load credentials to authenticate with AWS client. Please check that credentials in the specified profile name are valid.Ú )r   r   Úquery_endpointr   Úboto3ÚSessionÚsessionÚbotocorer"   Úbotocore.configr#   ÚImportErrorÚ	ExceptionÚtypeÚ__name__Ú
ValueErrorÚschemaÚschema_elementsÚ_refresh_schema)Úselfr   r   r   r   r   r   r   r   r   r)   Úclient_paramsÚprotocolr"   r#   Úes                   úv/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/langchain_community/graphs/neptune_rdf_graph.pyÚ__init__zNeptuneRdfGraph.__init__Q   s…  € ð )ˆÔØ&ˆÔØ (¨¨¨a°¨v°WÐ=ˆÔð0	ØÐ!Ø$�•ãà+Ð7Ø#(§=¡=Ð>V =Ó#W�D•Lð $)§=¡=£?�D”Là "�ÙØ3>�M -Ñ0á&/™7°V�à3;°*¸CÀ¸vÀQÀtÀfÐ0M�˜nÑ-áØ"5 $§,¡,×"5Ñ"5°gÑ"OÀÑ"O�D•Kå1Ý6à"5 $§,¡,×"5Ñ"5Øñ#à'ñ#ñ  &¸ÔAò#�D”Kð2 ˆŒØ/1ˆÔØ×ÑÕøô+ ò 	Üð>óð ô ò 	Ü�A‹w×ÑÐ#8Ò8Ü!ðEóð ðô
 !ð.óð ð	ûð	ús   žB7C4 Ã4EÄ0E Å Ec                 ó   — | j                   S )z;
        Returns the schema of the graph database.
        )r3   ©r6   s    r:   Ú
get_schemazNeptuneRdfGraph.get_schema˜   s   € ð
 �{‰{Ðó    c                 ó   — | j                   S )N)r4   r=   s    r:   Úget_schema_elementsz#NeptuneRdfGraph.get_schema_elementsŸ   s   € à×#Ñ#Ð#r?   c                 ó:   — | j                   j                  d¬«      S )z\
        Obtain Neptune statistical summary of classes and predicates in the graph.
        Údetailed)Úmode)r   Úget_rdf_graph_summaryr=   s    r:   Úget_summaryzNeptuneRdfGraph.get_summary£   s   € ð �{‰{×0Ñ0°jÐ0ÓAÐAr?   Úqueryc                 óX  — d|i}|}d}| j                   rÌ| j                  j                  «       }|j                  «       }|j                  }|j
                  }d}|j                  }	d}
t        |||	| j                  ¬«      }ddl	m
}  |d| j                  ||
¬«      }dd	lm}  |||| j                  «      j                  |«       d
|j                  d<   |j                  }ni }d
|d<   t!        j"                  d| j                  ||¬«      }t%        j&                  |j(                  «      }|S )z$
        Run Neptune query.
        rG   Nz
neptune-db)Ú
access_keyÚ
secret_keyÚtokenÚregionr   )Ú
AWSRequestÚPOST)ÚmethodÚurlÚdataÚparams)Ú	SigV4Authz!application/x-www-form-urlencodedzContent-Type)rO   rP   ÚheadersrQ   )r   r+   Úget_credentialsÚget_frozen_credentialsrI   rJ   rK   r   r   Úbotocore.awsrequestrM   r(   Úbotocore.authrS   Úadd_authrT   ÚrequestsÚrequestÚjsonÚloadsÚtext)r6   rG   Úrequest_datarQ   Úrequest_hdrÚcredentialsrI   rJ   r   Úsession_tokenrR   ÚcredsrM   r[   rS   ÚqueryresÚ	json_resps                    r:   rG   zNeptuneRdfGraph.query©   s'  € ð   Ð'ˆØˆØˆà×ÒØŸ,™,×6Ñ6Ó8ˆKØ%×<Ñ<Ó>ˆKØ$×/Ñ/ˆJØ$×/Ñ/ˆJØ"ˆGØ'×-Ñ-ˆMØˆFÜ#Ø%Ø%Ø#Ø×'Ñ'ô	ˆEõ 7á Ø 4×#6Ñ#6¸TÈ&ôˆGõ 0á�e˜W d×&6Ñ&6Ó7×@Ñ@ÀÔIØ.QˆG�O‰O˜NÑ+Ø!Ÿ/™/‰KàˆKØ*MˆK˜Ñ'ä×#Ñ#Ø˜t×2Ñ2¸KÈdô
ˆô —J‘J˜xŸ}™}Ó-ˆ	ØÐr?   r4   c           	      óä   — i }t         D ]F  }g }||   D ]&  }|d   }|d   }d|› d|› d�}|j                  |«       Œ( dj                  |«      ||<   ŒH d|d   › d	|d
   › d|d   › d|d   › �| _        y)zƒ
        Generates and sets schema from schema_elements. Helpful in
        cases where introspected schema needs pruning.
        ÚuriÚlocalÚ<z> (Ú)z, z–In the following, each IRI is followed by the local name and optionally its description in parentheses. 
The graph supports the following node types:
r	   z1
The graph supports the following relationships:
r
   z9
The graph supports the following OWL object properties:
r   z7
The graph supports the following OWL data properties:
r   N)Ú
ELEM_TYPESÚappendÚjoinr3   )	r6   r4   Úelem_strÚelemÚres_listÚelem_recrg   rh   Úres_strs	            r:   Úload_schemazNeptuneRdfGraph.load_schemaÖ   s¿   € ð ˆßˆDØˆHØ+¨DÔ1�Ø˜u‘o�Ø  Ñ)�Ø˜c˜U # e W¨AÐ.�Ø—‘ Õ(ð	 2ð
 "ŸY™Y xÓ0ˆH�TŠNð ð=ð ˜	Ñ"Ð#ð $@à˜ÑÐ ð !Hà˜	Ñ"Ð#ð $Fà˜Ñ!Ð"ð	$ð 	�r?   Úiric                 óÞ   — d|v r|j                  d«      }|d   › d�|d   gS d|v r9|j                  d«      }dj                  |dt        |«      dz
   «      › d�|d   gS t        d|› d�«      ‚)z1
        Split IRI into prefix and local
        Ú#r   éÿÿÿÿÚ/é   zUnexpected IRI 'z ', contains neither '#' nor '/'.)Úsplitrm   Úlenr2   )r6   rt   Útokenss      r:   Ú_get_local_namezNeptuneRdfGraph._get_local_nameó   sŠ   € ð �#‰:Ø—Y‘Y˜s“^ˆFØ˜a‘y�k �O V¨B¡ZÐ0Ð0Ø�C‰ZØ—Y‘Y˜s“^ˆFØ—x‘x  q¬3¨v«;¸©?Ð ;Ó<Ð=¸QÐ?ÀÈÁÐLÐLäÐ/°¨uÐ4TÐUÓVÐVr?   c                 ó¾  — i | j                   d<   | j                  «       }g }|d   d   d   D ]X  }|}| j                  |«      }||d   dœ}|j                  |«       |d   | j                   d   vsŒDd| j                   d   |d   <   ŒZ || j                   d<   g }|d   d   d	   D ]_  }|D ]X  }|}| j                  |«      }||d   dœ}|j                  |«       |d   | j                   d   vsŒDd| j                   d   |d   <   ŒZ Œa || j                   d
<   t        D ]¥  }	t        j                  |	«      }
|
sŒ| j                  |
«      }g }|d   d   D ]^  }|d   d   }| j                  |«      }||d   dœ}|j                  |«       |d   | j                   d   vsŒJd| j                   d   |d   <   Œ` || j                   |	<   Œ§ | j                  | j                   «       y)z5
        Query Neptune to introspect schema.
        Údistinct_prefixesÚpayloadÚgraphSummaryr	   ry   )rg   rh   r   ÚyÚ
predicatesr
   ÚresultsÚbindingsro   ÚvalueN)r4   rF   r}   rl   rk   ÚgetrG   rs   )r6   ÚsummaryÚreslistÚcrg   r|   Úelem_recordÚrÚpro   ÚqÚitemss               r:   r5   zNeptuneRdfGraph._refresh_schema   s*  € ð 57ˆ×ÑÐ0Ñ1ð ×"Ñ"Ó$ˆØˆØ˜Ñ# NÑ3°IÔ>ˆAØˆCØ×)Ñ)¨#Ó.ˆFØ"%°°q±	Ñ:ˆKØ�N‰N˜;Ô'Ø�a‰y × 4Ñ 4Ð5HÑ IÒIØGJ�×$Ñ$Ð%8Ñ9¸&À¹)ÒDð ?ð +2ˆ×Ñ˜YÑ'àˆØ˜Ñ# NÑ3°LÔAˆAÛ�Ø�Ø×-Ñ-¨cÓ2�Ø&)°F¸1±IÑ>�Ø—‘˜{Ô+Ø˜!‘9 D×$8Ñ$8Ð9LÑ$MÒMØKN�D×(Ñ(Ð)<Ñ=¸fÀQ¹iÒHñ ð Bð (/ˆ×Ñ˜VÑ$÷ ˆDÜ—‘˜tÓ$ˆAÙØØ—J‘J˜q“MˆEØˆGØ˜9Ñ% jÔ1�Ø˜‘i Ñ(�Ø×-Ñ-¨cÓ2�Ø&)°F¸1±IÑ>�Ø—‘˜{Ô+Ø˜!‘9 D×$8Ñ$8Ð9LÑ$MÒMØKN�D×(Ñ(Ð)<Ñ=¸fÀQ¹iÒHð 2ð *1ˆD× Ñ  Ò&ð ð  	×Ñ˜×-Ñ-Õ.r?   )iö  TFNNNÚneptunedataT)r   N)r1   Ú
__module__Ú__qualname__Ú__doc__ÚstrÚintÚboolr   r   r;   Úpropertyr>   r   rA   rF   rG   rs   r   r}   r5   © r?   r:   r   r       sK  „ ñ)ð\ ØØ"ØØ26Ø%)Ø$ØñEàðEð ðEð ð	Eð
 ðEð ðEð #+¨3¡-ðEð ˜c‘]ðEð ðEð ðEð 
óEðN ð˜Cò ó ðð ð$ T¨#¨s¨(¡^ò $ó ð$ðB˜T # s (™^ó Bð+àð+ð 
ˆc�3ˆh‰ó+ðZ
¨4°°S°©>ð 
¸dó 
ð:W 3ð W¨8°C©=ó Wô./r?   r   )r\   Útypesr   Útypingr   r   r   r   rZ   Úlangchain_core._api.deprecationr   ÚDTPROP_QUERYÚOPROP_QUERYrk   r   r˜   r?   r:   Ú<module>rž      sd   ðÛ Ý !ß 0Ó 0ã Ý 6ð€ð€ð ØØØñ	€
ñ Ø
ØØ6ô÷
I/ð I/óñ
I/r?   