rupo

repository·master·Indexed 41 days ago

https://github.com/ilyagusev/rupo

A Python library for the analysis and generation of Russian poetry. It provides tools for stress prediction, syllable splitting, rhyme detection, and metre classification via the rupo.api.Engine class and rupo.metre package. Supports poem generation through a CLI with sampling and beam search modes. Requires Python 3.8.

Tokens
1.7K
Snippets
4
Records
8
Agent score
50%

What's inside rupo

  1. Overview of the rupo.main package

    master
    The rupo.main package is the primary entry point for the rupo library, which is designed for the analysis and generation of Russian poems. It provides access to core submodules for text processing, including markup, tokenization, and vocabulary management.
  2. Use the rupo.metre package for poetic meter analysis

    master

    The rupo.metre package provides tools for analyzing and working with poetic meters in Russian. It is organized into several submodules:

    • rupo.metre.metre_classifier: Used for classifying the meter of a given text.
    • rupo.metre.patterns: Provides tools for working with poetic patterns.
    • rupo.metre: The main entry point for the package functionality.
  3. Use rupo.main submodules for poem analysis

    master

    The rupo.main package is organized into several functional submodules that you can use to build poem analysis or generation pipelines:

    • rupo.main.tokenizer: Handles the tokenization of Russian text.
    • rupo.main.vocabulary: Manages the vocabulary used in linguistic analysis.
    • rupo.main.markup: Provides tools for text markup and structural analysis.
    • rupo.main.test_*: Contains testing modules for markup, tokenizer, and vocabulary (primarily for verifying correctness of the core components).
  4. Install rupo

    master

    To install rupo, clone the repository, install the requirements, and run the download script to fetch necessary models and dictionaries.

    Warning: Python 3.9+ is not supported! Use Python 3.8.

    git clone https://github.com/IlyaGusev/rupo
    cd rupo
    pip install -r requirements.txt
    sh download.sh
  5. Analyze Russian poetry with the Engine API

    master

    Use the rupo.api.Engine class to perform linguistic analysis on Russian text, including stress prediction, syllable splitting, rhyme checking, and metre classification.

    1. Initialize the engine with language="ru".
    2. Load the required models using .load(<stress model path>, <zalyzniak dict path>).
    3. Use the following methods:
      • get_stresses(word): Returns the stress position (e.g., [3]).
      • get_word_syllables(word): Returns a list of syllables (e.g., ["ко", "ро", "ва"]).
      • is_rhyme(word1, word2): Returns True if words rhyme.
      • classify_metre(text): Returns the metre type (e.g., iambos).
    from rupo.api import Engine
    engine = Engine(language="ru")
    engine.load(<stress model path>, <zalyzniak dict path>)
    
    # Examples
    print(engine.get_stresses("корова"))        # [3]
    print(engine.get_word_syllables("корова"))  # ['ко', 'ро', 'ва']
    print(engine.is_rhyme("корова", "здорова")) # True
    
    text = "Горит восток зарёю новой.\nУж на равнине, по холмам\nГрохочут пушки. Дым багровый\nКругами всходит к небесам."
    print(engine.classify_metre(text))           # iambos
  6. Reference: generate_poem.py CLI arguments

    master

    The following arguments are available for the generate_poem.py script:

    | Argument            | Default | Description                                                                  |
    |:--------------------|:--------|:-----------------------------------------------------------------------------|
    | --metre-schema      | +-      | feet type: -+ (iambos), +- (trochee), ...                                    |
    | --rhyme-pattern     | abab    | rhyme pattern                                                                |
    | --n-syllables       | 8       | number of syllables in line                                                 |
    | --sampling-k        | 50000   | top-k words to sample from (sampling mode)                                  |
    | --beam-width        | None    | width of beam search (beam search mode)                                     |
    | --temperature       | 1.0     | sampling softmax temperature                                                |
    | --last-text         | None    | custom last line                                                            |
    | --count             | 100     | count of poems to generate                                                  |
    | --model-path        | None    | optional path to generator model directory                                  |
    | --token-vocab-path  | None    | optional path to vocabulary                                                 |
    | --stress-vocab-path | None    | optional path to stress vocabulary                                          |