o
    –h¥  ã                   @   sl   d dl mZ d dlmZ d dlZd dlmZ d dlmZ d dl	m
Z
 ddlT dd	d
„Zddd„Zdd„ ZdS )é    )Úabsolute_import)ÚBytesION)Ú_EncodeVarint)Ú_DecodeVarint)ÚDecodeErroré   )Ú*c              
   C   sn   t ||ƒ\}}z|  ||| || | … ¡ W || S  ty6 } zt dt¡ W Y d}~|| S d}~ww )á  
    Stanford CoreNLP uses the Java "writeDelimitedTo" function, which
    writes the size (and offset) of the buffer before writing the object.
    This function handles parsing this message starting from offset 0.

    @returns how many bytes of @buf were consumed.
    ziFailed to decode a serialized output from CoreNLP server. An incomplete or empty object will be returned.N)r   ÚParseFromStringr   ÚwarningsÚwarnÚRuntimeWarning)ÚobjÚbufÚoffsetÚsizeÚposÚe© r   úS/var/www/html/env_mimamsha/lib/python3.10/site-packages/stanza/protobuf/__init__.pyÚparseFromDelimitedString   s    ýÿ€ýr   c                 C   s2   |du rt ƒ }t|j|  ¡ dƒ | |  ¡ ¡ |S )r	   NT)r   r   ÚwriteÚByteSizeÚSerializeToString)r   Ústreamr   r   r   ÚwriteToDelimitedString   s
   r   c                 C   s8   d}t | jƒD ]\}}|dkr||j7 }||j7 }q|S )z[
    Helper routine that converts a Sentence protobuf to a string from
    its tokens.
    Ú r   )Ú	enumerateÚtokenÚbeforeÚword)ÚsentenceÚtextÚiÚtokr   r   r   Úto_text*   s   
r%   )r   )N)Ú
__future__r   Úior   r   Ú google.protobuf.internal.encoderr   Ú google.protobuf.internal.decoderr   Úgoogle.protobuf.messager   ÚCoreNLP_pb2r   r   r%   r   r   r   r   Ú<module>   s    

