o
    h3	                     @   sn   d Z ddlmZmZ ddlmZmZ dZdd Zdd Z	d	d
 Z
G dd deZdd Zedkr5e  dS dS )z
Direct pipe connection to the Java CoreNLP Morphology class

Only effective for English.  Must be supplied with PTB scheme xpos, not upos
    )MorphologyRequestMorphologyResponse)send_requestJavaProtobufContextz1edu.stanford.nlp.process.ProcessMorphologyRequestc                 C   s   t | ttS N)r   r   MORPHOLOGY_JAVA)request r	   S/var/www/html/env_mimamsha/lib/python3.10/site-packages/stanza/server/morphology.pysend_morphology_request   s   r   c                 C   s4   t  }t| |D ]\}}|j }||_||_q|S )za
    Turn a list of words and a list of tags into a request

    tags must be xpos, not upos
    )r   zipwordsaddwordxpos)r   	xpos_tagsr   r   tagtagged_wordr	   r	   r
   build_request   s   
r   c                 C   s   t | |}t|S )z
    Get the lemmata for each word/tag pair

    Currently the return is a MorphologyResponse from CoreNLP.proto

    tags must be xpos, not upos
    )r   r   )r   r   r   r	   r	   r
   process_text   s   
r   c                       s*   e Zd ZdZd fdd	Zdd Z  ZS )
Morphologyz
    Morphology context window

    This is a context window which keeps a process open.  Should allow
    for multiple requests without launching new java processes each time.

    (much faster than calling process_text over and over)
    Nc                    s   t t| |tt d S r   )superr   __init__r   r   )self	classpath	__class__r	   r
   r   6   s   zMorphology.__init__c                 C   s   t ||}| |S )z8
        Get the lemmata for each word/tag pair
        )r   process_request)r   r   r   r   r	   r	   r
   process9   s   

zMorphology.processr   )__name__
__module____qualname____doc__r   r   __classcell__r	   r	   r   r
   r   -   s    r   c                  C   s   g d} g d}g d}t | |}dd |jD }t| ||ks#J t }|| |}dd |jD }||ks;J W d    d S 1 sFw   Y  d S )N)Jenniferhasthe	prettiestantennae)NNPVBZDTJJSNNS)r$   haver&   prettyantennac                 S      g | ]}|j qS r	   lemma.0xr	   r	   r
   
<listcomp>G       zmain.<locals>.<listcomp>c                 S   r1   r	   r2   r4   r	   r	   r
   r7   M   r8   )r   r   printr   r   )r   tagsexpectedresultr3   morphr	   r	   r
   mainA   s   
"r>   __main__N)r"   stanza.protobufr   r   $stanza.server.java_protobuf_requestsr   r   r   r   r   r   r   r>   r   r	   r	   r	   r
   <module>   s    
