o
    wÖij  ã                   @  s¨   d dl mZ d dlmZ d dlmZmZ d dlZd dlZd dl	m
Z
mZ d dlmZmZmZ eeef Zeeƒ ¡ jd ZdeeƒgZG d	d
„ d
eƒZG dd„ dƒZdS )é    )Úannotations)ÚPath)ÚOptionalÚUnionN)Ú
DictionaryÚMorpheme)Úcreate_latticeÚensure_listÚto_csvÚmecabrcz--rcfilec                   @  s   e Zd ZdZdS )Ú
MeCabErrorz&Raised if an error occurred from MeCabN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r   r   úH/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/mecab/mecab.pyr      s    r   c                   @  sR   e Zd Z		dddd„Zddd„Zddd„Zddd„Zddd„Zeddd„ƒZ	dS )ÚMeCabNÚdictionary_pathúOptional[PathLike]Úuser_dictionary_pathú)Optional[Union[PathLike, list[PathLike]]]c                 C  sV   |du rt j}t|ƒ}dt|ƒg}|rdt|ƒgng }g t¢|¢|¢}t |¡| _dS )a,  
        Parameters:
            dictionary_path: Path to the system dictionary to use. If not provided, the default mecab-ko-dic dictionary will be used.
            user_dictionary_path: Path or list of paths to user dictionaries to use. If not provided, no user dictionaries will be used.
        Nz--dicdirz	--userdic)	Úmecab_ko_dicr   r	   Ústrr
   Ú_rcfile_optionÚ_mecabÚTaggerÚ_tagger)Úselfr   r   Údictionary_optionÚuser_dictionay_optionÚoptionsr   r   r   Ú__init__   s   
ÿþýzMeCab.__init__Úsentencer   Úreturnúlist[Morpheme]c                 C  s0   t |ƒ}| j |¡st| j ¡ ƒ‚dd„ |D ƒS )zåPerform morpheme analysis on a given sentence.

        Parameters:
            sentence: A sentence to analyze

        Returns:
            A list of `Morpheme` objects representing each morpheme in the given sentence.
        c                 S  s   g | ]
\}}t  ||¡‘qS r   )r   Ú
_from_node)Ú.0ÚspanÚnoder   r   r   Ú
<listcomp>?   s    zMeCab.parse.<locals>.<listcomp>)r   r   Úparser   Úwhat)r   r#   Úlatticer   r   r   r+   2   s   	zMeCab.parseúlist[tuple[str, str]]c                 C  ó   dd„ |   |¡D ƒS )a  Extract `(surface, part-of-speech tag)` pairs from a given sentence.

        Parameters:
            sentence: A sentence to analyze

        Returns:
            A list of `(surface, part-of-speech tag)` pairs representing each morpheme in the given sentence.
        c                 S  s   g | ]}|j |jf‘qS r   )ÚsurfaceÚpos©r'   Úmorphemer   r   r   r*   J   s    zMeCab.pos.<locals>.<listcomp>©r+   ©r   r#   r   r   r   r1   A   ó   	z	MeCab.posú	list[str]c                 C  r/   )z»Extract morphemes from a given sentence.

        Parameters:
            sentence: A sentence to analyze

        Returns:
            A list of morphemes in the given sentence.
        c                 S  s   g | ]}|j ‘qS r   )r0   r2   r   r   r   r*   U   s    z MeCab.morphs.<locals>.<listcomp>r4   r5   r   r   r   ÚmorphsL   r6   zMeCab.morphsc                 C  r/   )z±Extract nouns from a given sentence

        Parameters:
            sentence: A sentence to analyze

        Returns:
            A list of nouns in the given sentence
        c                 S  s   g | ]}|j  d ¡r|j‘qS )ÚN)r1   Ú
startswithr0   r2   r   r   r   r*   `   s    zMeCab.nouns.<locals>.<listcomp>r4   r5   r   r   r   ÚnounsW   r6   zMeCab.nounsúlist[Dictionary]c                 C  s   t  | j ¡ ¡S )z Returns the currently loaded dictionaries.

        Returns:
            A list of `Dictionary` objects representing the dictionaries currently loaded.
        )r   Ú_from_dictionary_infor   Údictionary_info)r   r   r   r   Ú
dictionaryb   s   zMeCab.dictionary)NN)r   r   r   r   )r#   r   r$   r%   )r#   r   r$   r.   )r#   r   r$   r7   )r$   r<   )
r   r   r   r"   r+   r1   r8   r;   Úpropertyr?   r   r   r   r   r      s    ý



r   )Ú
__future__r   Úpathlibr   Útypingr   r   r   r   Úmecab.typesr   r   Úmecab.utilsr   r	   r
   r   ÚPathLikeÚ__file__ÚabsoluteÚparentÚmecabrc_pathr   Ú	Exceptionr   r   r   r   r   r   Ú<module>   s    