pymystem3

repository·master·Indexed 43 days ago

https://github.com/nlpub/pymystem3

A Python wrapper for the Yandex Mystem 3.1 morphological analyzer used for Russian language processing. It provides functionality for lemmatization and deriving morphological attributes such as part-of-speech, gender, and number via the Mystem class's lemmatize and analyze methods.

Tokens
592
Snippets
3
Records
6
Agent score
5%

What's inside pymystem3

  1. Explore pymystem3 submodules

    master

    The pymystem3 package is organized into several submodules:

    • pymystem3.constants: Contains constant definitions used throughout the package.
    • pymystem3.metadata: Contains package metadata.
    • pymystem3.mystem: The core module containing the primary logic for interacting with the Mystem analyzer.
    • pymystem3: The top-level package module.
  2. Install pymystem3

    master

    You can install the stable version of pymystem3 via PyPI or the latest version directly from GitHub using pip.

    Stable version:

    pip install pymystem3

    Latest version (recommended):

    pip install git+https://github.com/nlpub/pymystem3
    pip install pymystem3
  3. Configure the path to the mystem binary via MYSTEM_BIN

    master
    By default, pymystem3 uses the path defined in pymystem3.constants.MYSTEM_BIN to locate the Mystem binary. If your Mystem binary is installed in a non-standard location, you can specify its path by setting the MYSTEM_BIN environment variable.
  4. Perform lemmatization with Mystem

    master

    Use the lemmatize method of the Mystem class to perform lemmatization on a string of text. This returns a list of lemmas (the dictionary form of words) corresponding to the input tokens.

    from pymystem3 import Mystem
    text = "Красивая мама красиво мыла раму"
    m = Mystem()
    lemmas = m.lemmatize(text)
    print(''.join(lemmas))
    # Output: красивый мама красиво мыть рама
  5. Get detailed morphological analysis with analyze()

    master

    To get full grammatical information alongside lemmas, use the analyze method. This returns a list of dictionaries, where each dictionary contains the original text and an analysis list containing morphological attributes like the lemma (lex) and grammatical features (gr).

    import json
    from pymystem3 import Mystem
    
    text = "Красивая мама красиво мыла раму"
    m = Mystem()
    analysis = m.analyze(text)
    
    print(json.dumps(analysis, ensure_ascii=False))
  6. System Requirements for pymystem3

    master

    Python Runtimes

    • CPython 2.6+ / 3.3+
    • PyPy 1.9+

    Supported Platforms

    • Ubuntu Linux 12.04+
    • Mac OSX 10.9+
    • Windows 7+

    Note for 32-bit or FreeBSD: If you are using a 32-bit architecture or the FreeBSD platform, use version 0.1.10 of the package.