Skip to content

Russian Texts Statistics (ruTS)

ruTS

ruTS computes for Russian texts what usually takes several different tools: from basic statistics, readability and lexical diversity to morphology, syntax, cohesion, stylometry and corpus measures - by published formulas adapted to the Russian language.

The source is a string or a spaCy Doc; every statistic is available both as a class and as a spaCy pipeline component.

Try it without installing in the demo on Hugging Face Spaces: the readability grade, metrics, plots and highlighted fragments of a pasted text.

Features

Installation

Requires Python 3.11 or newer.

pip install ruts

More on dependencies and installing from the repository - on the Installation page.

Quick start

from ruts import BasicStats, DiversityStats, ReadabilityStats

text = "Существуют три вида лжи: ложь, наглая ложь и статистика"

BasicStats(text).get_stats()
ReadabilityStats(text).flesch_reading_easy
DiversityStats(text).ttr
{'c_letters': {1: 1, 3: 2, 4: 3, 6: 1, 10: 2},
 'c_syllables': {1: 5, 2: 1, 3: 1, 4: 2},
 'n_sents': 1,
 'n_words': 9,
 'n_unique_words': 8,
 'n_long_words': 3,
 'n_complex_words': 2,
 'n_simple_words': 7,
 'n_monosyllable_words': 5,
 'n_polysyllable_words': 4,
 'n_chars': 55,
 'n_letters': 45,
 'n_spaces': 8,
 'n_syllables': 18,
 'n_punctuations': 2,
 'letters_entropy': 2.197159723424149,
 'syllables_entropy': 1.6577427265048887,
 'c_punctuations': {'comma': 1,
                    'period': 0,
                    'question': 0,
                    'exclamation': 0,
                    'ellipsis': 0,
                    'colon': 1,
                    'semicolon': 0,
                    'dash': 0,
                    'hyphen': 0,
                    'angle_quotes': 0,
                    'straight_quotes': 0,
                    'parentheses': 0,
                    'other': 0}}
74.93500000000003
0.8888888888888888

Any statistic can be printed in a readable form:

BasicStats(text).print_stats()
            Статистика            | Значение
---------------------------------------------
Предложения                       |    1
Слова                             |    9
Уникальные слова                  |    8
Длинные слова                     |    3
Сложные слова                     |    2
Простые слова                     |    7
Односложные слова                 |    5
Многосложные слова                |    4
Символы                           |    55
Буквы                             |    45
Пробелы                           |    8
Слоги                             |    18
Знаки препинания                  |    2
Энтропия длин слов в буквах (бит) |   2.20
Энтропия длин слов в слогах (бит) |   1.66

A walkthrough of one short story with every tool of the library is in the notebook examples/01_text_walkthrough.ipynb (opens in Colab), the other notebooks are on the examples page.