Skip to content

API Reference

MeCab

__init__(dictionary_path=None, user_dictionary_path=None)

Parameters:

Name Type Description Default
dictionary_path Optional[PathLike]

Path to the system dictionary to use. If not provided, the default mecab-ko-dic dictionary will be used.

None
user_dictionary_path Optional[Union[PathLike, list[PathLike]]]

Path or list of paths to user dictionaries to use. If not provided, no user dictionaries will be used.

None

parse(sentence)

Perform morpheme analysis on a given sentence.

Parameters:

Name Type Description Default
sentence str

A sentence to analyze

required

Returns:

Type Description
list[Morpheme]

A list of Morpheme objects representing each morpheme in the given sentence.

pos(sentence)

Extract (surface, part-of-speech tag) pairs from a given sentence.

Parameters:

Name Type Description Default
sentence str

A sentence to analyze

required

Returns:

Type Description
list[tuple[str, str]]

A list of (surface, part-of-speech tag) pairs representing each morpheme in the given sentence.

morphs(sentence)

Extract morphemes from a given sentence.

Parameters:

Name Type Description Default
sentence str

A sentence to analyze

required

Returns:

Type Description
list[str]

A list of morphemes in the given sentence.

nouns(sentence)

Extract nouns from a given sentence

Parameters:

Name Type Description Default
sentence str

A sentence to analyze

required

Returns:

Type Description
list[str]

A list of nouns in the given sentence

dictionary: list[Dictionary] property

Returns the currently loaded dictionaries.

Returns:

Type Description
list[Dictionary]

A list of Dictionary objects representing the dictionaries currently loaded.

Morpheme

Represents a morpheme

Attributes:

Name Type Description
span Span

A span of the morpheme in a text

surface str

A surface of the morpheme

feature Feature

A feature of the morpheme

pos: str property

Returns the part-of-speech tag of the morpheme

Span

Represents a span of the morpheme in a text.

Attributes:

Name Type Description
start int

A start index of the morpheme

end int

An end index of the morpheme

Feature

Represents a feature of the morpheme. For more information, please refer to the link: https://docs.google.com/spreadsheets/d/1-9blXKjtjeKZqsf4NzHeYJCrr49-nXeRF6D80udfcwY

Attributes:

Name Type Description
pos str

A part-of-speech tag of the morpheme

semantic Optional[str]

A semantic category of the morpheme

has_jongseong Optional[bool]

Whether the last syllable of reading has jongseong or not

reading Optional[str]

A reading of the morpheme

type Optional[str]

A type of the morpheme (Inflect, Compound, Preanalysis, or None)

start_pos Optional[str]

The first part-of-speech tag of the morpheme

end_pos Optional[str]

The last part-of-speech tag of the morpheme

expression Optional[str]

An expression of the morpheme

Dictionary

Represents a dictionary information

Attributes:

Name Type Description
path Path

A path to the dictionary

number_of_words int

The number of words in the dictionary

type Type

A type of the dictionary

version int

A version of the dictionary

MeCabError

Raised if an error occurred from MeCab