### Install Rupo Library Source: https://github.com/ilyagusev/rupo/blob/master/README.md Commands to clone the repository, install dependency requirements, and download necessary model files via the setup script. ```bash git clone https://github.com/IlyaGusev/rupo cd rupo pip install -r requirements.txt sh download.sh ``` -------------------------------- ### Analyze Russian Poetry with Rupo API Source: https://github.com/ilyagusev/rupo/blob/master/README.md Demonstrates initializing the Engine, getting word stresses, splitting words into syllables, checking rhymes, and classifying poem meter. ```python from rupo.api import Engine engine = Engine(language="ru") engine.load(, ) # Get word stresses engine.get_stresses("корова") # Split into syllables engine.get_word_syllables("корова") # Rhyme check engine.is_rhyme("корова", "здорова") # Classify meter text = "Горит восток зарёю новой.\nУж на равнине, по холмам\nГрохочут пушки. Дым багровый\nКругами всходит к небесам." engine.classify_metre(text) ``` -------------------------------- ### Initialize and Load RuPo Engine (Python) Source: https://context7.com/ilyagusev/rupo/llms.txt Initializes the RuPo engine for Russian language and loads necessary models for stress prediction and dictionary-based analysis. Ensure download.sh is run first to obtain model files. ```python from rupo.api import Engine # Create engine instance for Russian engine = Engine(language="ru") # Load stress prediction model and dictionary # Note: Run download.sh first to get required model files engine.load( stress_model_path="./stress_models/ru_stress_rnn.h5", zalyzniak_dict="./dict/zaliznyak.txt" ) # Engine is now ready for analysis and generation print("Engine loaded successfully") ``` -------------------------------- ### Command-Line Poem Generation Source: https://context7.com/ilyagusev/rupo/llms.txt Provides instructions for generating multiple poems from the command line using the `generate_poem.py` script. Allows configuration of parameters such as metre schema, rhyme pattern, syllable count, and the number of poems to generate. ```shell # Run from terminal: # python generate_poem.py --metre-schema +- --rhyme-pattern aabb --n-syllables 8 --count 5 # With custom parameters: # python generate_poem.py \ # --model-path ./models/generator \ # --metre-schema -+ \ # --rhyme-pattern abba \ # --n-syllables 10 \ # --count 3 \ # --seed 123 ``` -------------------------------- ### Batch Markup Generation with RuPo Engine Source: https://context7.com/ilyagusev/rupo/llms.txt This Python script demonstrates how to use the RuPo Engine to process multiple text files from a directory and generate markup outputs in XML format. It initializes the engine with a Russian language model and then calls the generate_markups method to handle batch processing. The input and output paths, as well as file types, are specified. ```python from rupo.api import Engine from rupo.files.reader import FileType engine = Engine(language="ru") engine.load("./stress_models/ru_stress_rnn.h5", "./dict/zaliznyak.txt") # Process all TXT files in a directory engine.generate_markups( input_path="./poems/", input_type=FileType.RAW, output_path="./markups/output.xml", output_type=FileType.XML ) # Process single file with different output formats engine.generate_markups( input_path="./poem.txt", input_type=FileType.RAW, output_path="./markup.json", output_type=FileType.JSON ) print("Markup generation complete") ``` -------------------------------- ### Generate Poetry via CLI Source: https://github.com/ilyagusev/rupo/blob/master/README.md Executes the poem generation script using pre-defined models and configuration arguments for meter, rhyme, and sampling parameters. ```bash python generate_poem.py ``` -------------------------------- ### Generate Poem with Sampling Source: https://context7.com/ilyagusev/rupo/llms.txt Generates Russian poems using a sampling strategy based on specified metre, rhyme scheme, and syllable count. Requires a loaded engine and generator model path. Parameters like sampling_k and temperature control diversity and quality. ```python from rupo.api import Engine from rupo.settings import GENERATOR_MODEL_DIR engine = Engine() engine.load("./stress_models/ru_stress_rnn.h5", "./dict/zaliznyak.txt") poem = engine.generate_poem( model_path=GENERATOR_MODEL_DIR, metre_schema="-+", # iambic: unstressed-stressed rhyme_pattern="abab", # alternating rhyme n_syllables=8, # 8 syllables per line sampling_k=50000, # top-50000 sampling temperature=1.0, # diversity parameter seed=42 # for reproducibility ) print("Generated poem:") print(poem) poem2 = engine.generate_poem( model_path=GENERATOR_MODEL_DIR, metre_schema="+-", # trochaic: stressed-unstressed rhyme_pattern="aabb", # couplets n_syllables=8, sampling_k=30000, temperature=0.8, # less diversity seed=123 ) print("\nGenerated trochaic poem:") print(poem2) ``` -------------------------------- ### Generate Text Markup Source: https://context7.com/ilyagusev/rupo/llms.txt Generates detailed linguistic markup for Russian text, including syllables, stresses, and word boundaries. It can also provide improved markup with metre classification and error counts. Requires a loaded engine with stress models and dictionaries. ```python from rupo.api import Engine engine = Engine(language="ru") engine.load("./stress_models/ru_stress_rnn.h5", "./dict/zaliznyak.txt") text = "Я помню чудное мгновенье" markup = engine.get_markup(text, language="ru") print(f"Number of lines: {len(markup.lines)}") for line_num, line in enumerate(markup.lines): print(f"\nLine {line_num + 1}: {line.text}") print(f"Number of words: {len(line.words)}") for word in line.words: print(f" Word: '{word.text}'") print(f" Syllables: {[s.text for s in word.syllables]}") print(f" Stress position: {word.stress()}") improved_markup, classification = engine.get_improved_markup(text) print(f"\nClassified metre: {classification.metre}") print(f"Errors count: {classification.get_metre_errors_count()}") ``` -------------------------------- ### Generate Poem with Beam Search Source: https://context7.com/ilyagusev/rupo/llms.txt Generates Russian poems using beam search, which typically yields more coherent and controlled output than sampling. Allows specifying metre, rhyme, syllable count, and optionally a custom last line for the poem. Requires a loaded engine and generator model path. ```python from rupo.api import Engine from rupo.settings import GENERATOR_MODEL_DIR engine = Engine() engine.load("./stress_models/ru_stress_rnn.h5", "./dict/zaliznyak.txt") poem = engine.generate_poem( model_path=GENERATOR_MODEL_DIR, metre_schema="-+", rhyme_pattern="abab", n_syllables=8, beam_width=10, # beam width (instead of sampling_k) temperature=1.0, seed=42 ) print("Beam search poem:") print(poem) poem_with_last = engine.generate_poem( model_path=GENERATOR_MODEL_DIR, metre_schema="-+", rhyme_pattern="abab", n_syllables=8, beam_width=15, last_text="и звезда с звездою говорит", seed=99 ) print("\nPoem with custom ending:") print(poem_with_last) ``` -------------------------------- ### Find Rhymes for a Word Source: https://context7.com/ilyagusev/rupo/llms.txt Searches a vocabulary derived from marked-up texts to find words that rhyme with a given Russian word. It requires a loaded engine and paths to a vocabulary cache and optional marked-up texts for vocabulary building. Returns a list of rhyming words. ```python from rupo.api import Engine engine = Engine(language="ru") engine.load("./stress_models/ru_stress_rnn.h5", "./dict/zaliznyak.txt") vocab_dump = "./data/vocab.pickle" markup_texts = "./data/marked_texts/" word = "любовь" rhymes = engine.get_word_rhymes( word=word, vocab_dump_path=vocab_dump, markup_path=markup_texts ) print(f"Rhymes for '{word}':") for rhyme in rhymes[:20]: # Show first 20 print(f" - {rhyme}") word2 = "весна" rhymes2 = engine.get_word_rhymes(word2, vocab_dump) print(f"\nRhymes for '{word2}': {rhymes2[:10]}") ``` -------------------------------- ### Analyze Poem Metre Source: https://context7.com/ilyagusev/rupo/llms.txt Classifies the metrical structure of Russian text. It can analyze a full text or single lines, providing the detected metre. Requires a loaded engine with language models. ```python from rupo.api import Engine engine = Engine(language="ru") # Assuming engine is loaded with appropriate models and dictionaries text2 = """Выхожу один я на дорогу; Сквозь туман кремнистый путь блестит; Ночь тиха. Пустыня внемлет богу, И звезда с звездою говорит.""" metre2 = engine.classify_metre(text2) print(f"Detected metre: {metre2}") line = "Я помню чудное мгновенье" metre3 = engine.classify_metre(line) print(f"Metre of line: {metre3}") ``` -------------------------------- ### Analyze Syllables of Russian Words (Python) Source: https://context7.com/ilyagusev/rupo/llms.txt Extracts syllables from Russian words and counts the total number of syllables for prosodic analysis. Handles both simple and complex words, as well as single-syllable words. ```python from rupo.api import Engine engine = Engine() # Get syllables of a word word = "корова" syllables = engine.get_word_syllables(word) print(f"Syllables of '{word}': {syllables}") # Output: ['ко', 'ро', 'ва'] # Count syllables word2 = "здорова" count = engine.count_syllables(word2) print(f"Syllable count in '{word2}': {count}") # Output: 3 # Complex words word3 = "преподаватель" syllables3 = engine.get_word_syllables(word3) count3 = engine.count_syllables(word3) print(f"'{word3}' has {count3} syllables: {syllables3}") # Output: 'преподаватель' has 5 syllables: ['пре', 'по', 'да', 'ва', 'тель'] # Single syllable words word4 = "дом" syllables4 = engine.get_word_syllables(word4) print(f"Syllables of '{word4}': {syllables4}") # Output: ['дом'] ``` -------------------------------- ### Predict Stress Positions in Russian Words (Python) Source: https://context7.com/ilyagusev/rupo/llms.txt Predicts stress positions in Russian words, returning character indices where stress falls. Handles multiple stress patterns for homographs and correctly identifies stress for single-vowel words and words with 'ё'. ```python from rupo.api import Engine engine = Engine(language="ru") engine.load("./stress_models/ru_stress_rnn.h5", "./dict/zaliznyak.txt") # Get stress positions for a single word word = "корова" # cow stresses = engine.get_stresses(word) print(f"Stress positions in '{word}': {stresses}") # Output: [3] - stress on letter 'о' at index 3 # Handle multiple stress patterns (омографы) word2 = "замок" # lock or castle stresses2 = engine.get_stresses(word2) print(f"Stress positions in '{word2}': {stresses2}") # May return multiple positions: [1] for зАмок or [3] for замОк # Words with single vowel word3 = "я" stresses3 = engine.get_stresses(word3) print(f"Stress positions in '{word3}': {stresses3}") # Output: [0] - single vowel is always stressed # Words with ё are always stressed on ё word4 = "ёлка" stresses4 = engine.get_stresses(word4) print(f"Stress positions in '{word4}': {stresses4}") # Output: [0] ``` -------------------------------- ### Classify Metre of Russian Poetry (Python) Source: https://context7.com/ilyagusev/rupo/llms.txt Classifies the metrical pattern of Russian poems, such as iambic or trochaic. This function analyzes the provided text and returns the detected metre. Requires the engine to be initialized and loaded with necessary models. ```python from rupo.api import Engine engine = Engine(language="ru") engine.load("./stress_models/ru_stress_rnn.h5", "./dict/zaliznyak.txt") # Analyze a poem in iambic tetrameter (Pushkin) text = """ Горит восток зарёю новой. Уж на равнине, по холмам Грохочут пушки. Дым багровый Кругами всходит к небесам.""" metre = engine.classify_metre(text) print(f"Detected metre: {metre}") # Output: iambos ``` -------------------------------- ### Detect Rhyme Between Russian Words (Python) Source: https://context7.com/ilyagusev/rupo/llms.txt Checks if two Russian words rhyme based on their stressed syllables and phonetic similarity. Returns a boolean indicating whether a rhyme is detected. This function requires the engine to be loaded with stress models and dictionary. ```python from rupo.api import Engine engine = Engine(language="ru") engine.load("./stress_models/ru_stress_rnn.h5", "./dict/zaliznyak.txt") # Check if two words rhyme word1 = "корова" word2 = "здорова" is_rhyme = engine.is_rhyme(word1, word2) print(f"'{word1}' and '{word2}' rhyme: {is_rhyme}") # Output: True # Non-rhyming words word3 = "собака" word4 = "корова" is_rhyme2 = engine.is_rhyme(word3, word4) print(f"'{word3}' and '{word4}' rhyme: {is_rhyme2}") # Output: False # Classic rhyme pairs pairs = [ ("любовь", "кровь"), ("розы", "морозы"), ("день", "тень"), ("весна", "луна") ] print("\nRhyme analysis:") for w1, w2 in pairs: result = engine.is_rhyme(w1, w2) print(f"{w1} : {w2} = {result}") # All should return True ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.