
    Ngn                     t    d dl mZmZ d dlmZmZmZmZmZm	Z	 dee
eef         defdZ G d de	          ZdS )	    )TupleUnion)
Comparator
Comparison	OperationOperatorStructuredQueryVisitorvaluereturnc                 V    t          | t                    rd|  dS t          |           S )zDConvert a value to a string and add single quotes if it is a string.')
isinstancestr)r   s    j/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/query_constructors/vectara.pyprocess_valuer      s.    % 5|||5zz    c                       e Zd ZdZej        ej        gZ	 ej	        ej
        ej        ej        ej        ej        gZ	 deeef         defdZdedefdZdedefdZd	edeeef         fd
ZdS )VectaraTranslatorzFTranslate `Vectara` internal query language elements to valid filters.funcr   c                     t           j        dt           j        dt          j        dt          j        dt          j        dt          j        dt          j        dt          j	        di}| 
                    |           ||         S )	Nz and z or =z!=>z>=<z<=)r   ANDORr   EQNEGTGTELTLTE_validate_func)selfr   map_dicts      r   _format_funczVectaraTranslator._format_func$   sa    L'KM3M4M3NDM3ND	
 	D!!!~r   	operationc                       fd|j         D             }                     |j                  }d|                    |          z   dz   S )Nc                 :    g | ]}|                               S  )accept).0argr$   s     r   
<listcomp>z5VectaraTranslator.visit_operation.<locals>.<listcomp>3   s%    @@@S

4  @@@r   z(  ))	argumentsr&   operatorjoin)r$   r'   argsr1   s   `   r   visit_operationz!VectaraTranslator.visit_operation2   sQ    @@@@I,?@@@$$Y%788hmmD)))D00r   
comparisonc                     |                      |j                  }t          |j                  }|j        }d|z   dz   |z   dz   |z   dz   S )Nz( doc. r/   )r&   
comparatorr   r   	attribute)r$   r5   r8   processed_valuer9   s        r   visit_comparisonz"VectaraTranslator.visit_comparison7   sW    &&z'<==
'
(899(	I%+j83>PSWW	
r   structured_queryc                 `    |j         i }nd|j                             |           i}|j        |fS )Nfilter)r>   r+   query)r$   r<   kwargss      r   visit_structured_queryz(VectaraTranslator.visit_structured_query?   s>     "*FF 0 7 > >t D DEF%v--r   N)__name__
__module____qualname____doc__r   r   r   allowed_operatorsr   r   r   r   r    r!   r"   allowed_comparatorsr   r   r&   r   r4   r   r;   r	   r   dictrA   r*   r   r   r   r      s        PP!x{3. 1x';!<     1 1s 1 1 1 1

: 
# 
 
 
 
. /.	sDy	. . . . . .r   r   N)typingr   r   langchain_core.structured_queryr   r   r   r   r	   r
   intfloatr   r   r   r*   r   r   <module>rM      s                          sE3/ C    1. 1. 1. 1. 1. 1. 1. 1. 1. 1.r   