o
    Zhn                     @   s`   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dZG dd de	Zd	S )
    )TupleUnion)
Comparator
Comparison	OperationOperatorStructuredQueryVisitorvaluereturnc                 C   s   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
    r   e/var/www/html/lang_env/lib/python3.10/site-packages/langchain_community/query_constructors/vectara.pyprocess_value   s   
r   c                   @   s   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dZdedefddZd	edefd
dZdedeeef fddZdS )VectaraTranslatorzFTranslate `Vectara` internal query language elements to valid filters.funcr   c                 C   sF   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LTEZ_validate_func)selfr   Zmap_dictr   r   r   _format_func$   s   

zVectaraTranslator._format_func	operationc                    s2    fdd|j D } |j}d|| d S )Nc                    s   g | ]}|  qS r   )accept).0argr   r   r   
<listcomp>3   s    z5VectaraTranslator.visit_operation.<locals>.<listcomp>z(  ))	argumentsr    operatorjoin)r   r!   argsr)   r   r%   r   visit_operation2   s   z!VectaraTranslator.visit_operation
comparisonc                 C   s8   |  |j}t|j}|j}d| d | d | d S )Nz( doc. r'   )r    
comparatorr   r
   	attribute)r   r-   r/   Zprocessed_valuer0   r   r   r   visit_comparison7   s
   
z"VectaraTranslator.visit_comparisonstructured_queryc                 C   s*   |j d u ri }nd|j | i}|j|fS )Nfilter)r3   r"   query)r   r2   kwargsr   r   r   visit_structured_query?   s   

z(VectaraTranslator.visit_structured_queryN)__name__
__module____qualname____doc__r   r   r   Zallowed_operatorsr   r   r   r   r   r   r   Zallowed_comparatorsr   r   r    r   r,   r   r1   r   r   dictr6   r   r   r   r   r      s(    
r   N)typingr   r   Zlangchain_core.structured_queryr   r   r   r   r   r	   intfloatr   r   r   r   r   r   r   <module>   s     
