{'fraction_non_alphanumeric': 0.02967128866479201, 'fraction_numerical': 0.011829729467662174, 'mean_word_length': 4.863558840250142, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 3, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
The Algorithmic Inflection of Russian and Generation of Grammatically Correct Text

We present a deterministic algorithm for Russian inflection. This algorithm is implemented in a publicly available web-service www.passare.ru which provides functions for inflection of single words, word matching and synthesis of grammatically correct Russian text. The inflectional functions have been tested against the annotated corpus of Russian language OpenCorpora.


Introduction
Automatic inflection of words in a natural language is necessary for a variety of theoretical and applied purposes like parsing, topic-to-question generation [3], speech recognition and synthesis, machine translation [13], tagset design [17], information retrieval [12], content analysis etc [1,2]. Various approaches towards automated inflection have been used to deal with particular aspects of inflection [5,23] in predefined languages [6,8,9,15,16,19] or in an unspecified inflected language [7].
Despite substantial recent progress in the field [16,21,22], automatic inflection still represents a problem of formidable computational complexity for many natural languages in the world. Most state-of-the-art approaches make use of extensive manually annotated corpora that currently exist for all major languages [20]. Real-time handling of a dictionary that contains millions of inflected word forms and tens of millions of relations between them is not an easy task [10]. Besides, no dictionary can ever be complete. For these reasons, algorithmic coverage of the grammar of a natural language is important provided that inflection in this language is complex enough.
Russian is a highly inflected language whose grammar is known for its complexity [21,23]. In Russian, inflection of a word may require changing its prefix, root and ending simultaneously while the rules of inflection are highly complex [11,23]. The form of a word can depend on as many as five grammatical categories such as number, gender, person, tense, case, voice, animacy etc. By an estimate based on [18], the average number of different grammatical forms of a Russian adjective is 11.716. A Russian verb has, on average, 44.069 different inflected forms, counting participles of all kinds and the gerunds.
In the present paper we describe a fully algorithmic dictionary-free approach towards automatic inflection of Russian. The algorithms described in the present paper are implemented in C # programming language. The described functionality is freely available online at www.passare.ru through both manual entry of a word to be inflected and by API access of main functions for dealing with big amounts of data.

Algorithms and implementation
The web-service passare.ru offers a variety of functions for inflection of single Russian words, word matching, and synthesis of grammatically correct text. In particular, the inflection of a Russian noun by number and case, the inflection of a Russian adjective by number, gender, and case, the inflection of a Russian adverb by the degrees of comparison are implemented. Russian verb is the part of speech whose inflection is by far the most complicated in the language. The presented algorithm provides inflection of a Russian verb by tense, person, number, and gender. It also allows one to form the gerunds and the imperative forms of a verb. Besides, functions for forming and inflecting active present and past participles as well as passive past participles are realized. Passive present participle is the only verb form not currently supported by the website due to the extreme level of its irregularity and absence for numerous verbs in the language.
The algorithmic coverage of the Russian language provided by the web-service passare.ru aims to balance grammatical accuracy and easiness of use. For that reason, a few simplifying assumptions have been made: the Russian letters "ё" and "е" are identified; no information on the stress in a word is required to produce its inflected forms; for inflectional functions, the existence of an input word in the language is determined by the user. Furthermore, the animacy of a noun is not treated as a variable category in the noun-inflecting function despite the existence of 1037 nouns (about 1.4% of the nouns in the OpenCorpora database [18]) with unspecified animacy. This list of nouns has been manually reviewed on a case-by-case basis and the decision has been made in favor of the form that is more frequent in the language. The other form can be obtained by calling the same function with a different case parameter (Nominative or Genitive instead of Accusative).
Similarly, the perfectiveness is not implemented as a parameter in a verb-inflecting function although by [18] there exist 1038 verbs (about 3.2% of the verbs in the database) in the language whose perfectiveness is not specified. For such verbs, the function produces forms that correspond to both perfective and imperfective inflections.
The inflectional form of a Russian word defined by a choice of grammatical categories (such as number, gender, person, tense, case, voice, animacy etc.) is in general not uniquely defined. This applies in particular to many feminine nouns, feminine forms of adjectives and to numerous verbs. For such words, the algorithms implemented in the web-service passare.ru only aim at finding one of the inflectional forms, typically, the one which is the most common in the language.
Due to the rich morphology of the Russian language and to the high complexity of its grammar, a detailed description of the algorithms of Russian inflection cannot be provided in a journal paper. The algorithm for the generation of the perfective gerund form of a verb is presented in Fig. 1. Most of the notation in Figure 1 is the same as that of the C # programming language. Furthermore, NF denotes the input normal form (the infinitive) of a verb to be processed. GetPerfectness() is a boolean function which detects whether a verb is perfective or not. Verb() is the function which inflects a given verb with respect to person, number, gender and tense (see the notation in Section 5). BF denotes the basic form of a Russian verb which is most suitable for constructing the perfective gerund of that verb. We found it convenient to use one of the three different basic forms depending on the type of the input verb to be inflected. The list vowels comprises all vowels in the Russian alphabet. The algorithms have been implemented in C # programming language. The implementation comprises about 35,000 lines of code and has been compiled into a 571 kB executable file.

Software speed tests and verification of results
The software being presented has been tested against the one of the widest publicly available corpora of Russian, OpenCorpora [18]. We have been using Intel Core i5-2320 processor clocked at 3.00GHz with 16GB RAM under Windows 7. The results are summarized in the below table. All of the words whose inflected forms did not show full agreement with the OpenCorpora database have been manually reviewed on a case-by-case basis. In the case of nouns, 26.76% of all error-producing input words belong to the class of Russian nouns whose animacy cannot be determined outside the context (e.g. "ёж", "жучок" and the like). For verbs, 11.26% of the discrepancies result from the verbs whose perfectiveness cannot be determined outside the context without additional information on the stress in the word (e.g. "насыпать", "пахнуть" etc.).
Besides, a substantial number of errors in OpenCorpora have been discovered. The classification of flaws in OpenCorpora is beyond the scope of the present work and we only mention that the inflection of the verb "застелить" as well as the gerund forms of the verbs "выместить" and "напечь" appear to be incorrect in this database at the time of writing.

Synthesis of grammatically correct text
Using the basic functions described above, one can implement automated synthesis of grammatically correct Russian text on the basis of any logical, numerical, financial, factual or any other precise data. The website passare.ru provides examples of such metafunctions that generate grammatically correct weather forecast and currency exchange rates report on the basis of real-time data available online. Besides, it offers a function that converts a correct arithmetic formula into Russian text.
The following piece of C # code is the core of one of the central functions which generate a grammatically correct report on exchange rates of currencies.
[ SynthFunction ( " ( C h a n g e i n e x c h a n g e r a t e ) " ) ]

Automated API access of main functions
Although all functions of the website www.passare.ru can be accessed manually by choosing options and typing words to be inflected or entering the parameters of a text to be automatically created, API-based automatic access is enabled to speed up work with big amounts of data. The details of the API access of main functions are as follows.
interface: socket ip: 46.173.208.127 port: 9999 character encoding: UTF8 To access a function, one needs to connect to the server, send a query string ending with the zero byte, receive the response string ending with the zero byte and close the connection.

Discussion
There exist several other approaches towards automated Russian inflection and synthesis of grammatically correct Russian text, e.g. [14,16]. Besides, numerous programs attempt automated inflection of a particular part of speech or synthesis of a document with a rigid predefined structure [4]. Judging by publicly available information, most of such program make extensive use of manually annotated corpora which might cause failure when the word to be inflected is different enough from the elements in the database.
The solution presented in this paper has been designed to be as independent of any dictionary data as possible. However, due to numerous irregularities in the Russian language, several lists of exceptional linguistic objects (like the list of indeclinable nouns or the list of verbs with strongly irregular gerund forms, see Fig. 1) have been composed and used throughout the code. Whenever possible, rational descriptions of exceptional cases have been adopted to keep the numbers of elements in such lists to the minimum.