{"id":18349106,"url":"https://github.com/andy-messer/formal-languages-practice-2","last_synced_at":"2025-04-09T23:45:31.806Z","repository":{"id":81131407,"uuid":"437965135","full_name":"Andy-Messer/formal-languages-practice-2","owner":"Andy-Messer","description":"Realization of Earley's algorithm","archived":false,"fork":false,"pushed_at":"2021-12-28T12:43:26.000Z","size":973,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-09T23:45:31.305Z","etag":null,"topics":["earley-parser","formal-languages","mipt-homeworks","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Andy-Messer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-12-13T17:32:16.000Z","updated_at":"2024-12-09T21:31:54.000Z","dependencies_parsed_at":"2023-02-28T23:15:29.161Z","dependency_job_id":null,"html_url":"https://github.com/Andy-Messer/formal-languages-practice-2","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Andy-Messer%2Fformal-languages-practice-2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Andy-Messer%2Fformal-languages-practice-2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Andy-Messer%2Fformal-languages-practice-2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Andy-Messer%2Fformal-languages-practice-2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Andy-Messer","download_url":"https://codeload.github.com/Andy-Messer/formal-languages-practice-2/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248131465,"owners_count":21052819,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["earley-parser","formal-languages","mipt-homeworks","python"],"created_at":"2024-11-05T21:20:36.956Z","updated_at":"2025-04-09T23:45:31.788Z","avatar_url":"https://github.com/Andy-Messer.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Realization of Earley's algorithm\n# Task\n\u003e It is necessary to implement the algorithm in the form of an Algo class, which has the following methods:\n\u003e \n\u003e fit(G: Grammar) ! Algo - preprocessing\n  \n\u003e predict(word: String) ! Boolean - checking whether a word belongs to the language.\n  \n\u003e Additionally, it is necessary to implement testing of the built preprocessing.\n  Algorithms for implementation\n\n\u003e 1. Earley's algorithm\n\u003e 2. LR(1)-algorithm\n\u003e Since there is no preprocessing in Earley's algorithm, it is necessary to implement the functions:\n  \n\u003e  • Scan(conf: Configuration, letter: char) ! Set• Predict(...)\n\n\u003e  • Complete(...) - think over the interface in such a way that the result can be read-\n  test. \n# Description of the algorithm\n\u003e You can find it in docs/Formal_Languages__Colloquium_2021.pdf\n\n# Testing, coverage\n\u003e These results are obtained on the basis of branch testing\n\n\u003e early_parser/grammar.py have 99% because there are raising exception in _Iterator \n\n\u003e If you want to see coverage code, do this commands:\n```bash\ncoverage run --branch -m unittest early_parser.test_module\ncoverage html\n```\n\u003e Wrote HTML report to htmlcov/index.html\n\n![](docs/coverage.png)\n\n# Summary\n\n Members                        | Descriptions                                \n--------------------------------|---------------------------------------------\n`namespace `[`early_parser::algo`](#namespaceearly__parser_1_1algo) | \n`namespace `[`early_parser::grammar`](#namespaceearly__parser_1_1grammar) | \n`class `[`early_parser::grammar::Grammar::_Iterator`](#classearly__parser_1_1grammar_1_1Grammar_1_1__Iterator) | Standard bidirectional Iterator for [Grammar](#classearly__parser_1_1grammar_1_1Grammar).\n`class `[`early_parser::algo::Algo::_State`](#classearly__parser_1_1algo_1_1Algo_1_1__State) | Metaclass that implements a state inside a certain rule\n\n# namespace `early_parser::algo` \n\n## Summary\n\n /Members                        | Descriptions                                \n--------------------------------|---------------------------------------------\n`class `[`early_parser::algo::Algo`](#classearly__parser_1_1algo_1_1Algo) | Realization of Earley algorithm.\n\n# class `early_parser::algo::Algo` \n\nRealization of Earley algorithm.\n\n## Summary\n\n Members                        | Descriptions                                \n--------------------------------|---------------------------------------------\n`public def `[`__init__`](#classearly__parser_1_1algo_1_1Algo_1a979bd29820a57d68ec4ed9bc0a4ec50a)`(self,`[`Grammar`](#classearly__parser_1_1grammar_1_1Grammar)` grammar)` | The constructor of Algo\n`public bool `[`complete`](#classearly__parser_1_1algo_1_1Algo_1a9da3a9c7b625f40126af81d0624a177b)`(self,int _id)` | The main complete method\n`public bool `[`has_word`](#classearly__parser_1_1algo_1_1Algo_1af419b631d35967aafd5768f82224e501)`(self,str word)` | Checks the presence of a word in the grammar\n`public bool `[`predict`](#classearly__parser_1_1algo_1_1Algo_1a30c9e0a7e5152029231b4eeff5f5007a)`(self,int _id)` | The main predict method\n`public def `[`scan`](#classearly__parser_1_1algo_1_1Algo_1af5dd681b5fb82f2c8d3770138d303670)`(self,int _id,str s)` | The main scan method\n\n## Members\n\n#### `public def `[`__init__`](#classearly__parser_1_1algo_1_1Algo_1a979bd29820a57d68ec4ed9bc0a4ec50a)`(self,`[`Grammar`](#classearly__parser_1_1grammar_1_1Grammar)` grammar)` \n\nThe constructor of Algo\n\n#### `public bool `[`complete`](#classearly__parser_1_1algo_1_1Algo_1a9da3a9c7b625f40126af81d0624a177b)`(self,int _id)` \n\nThe main complete method\n\n#### `public bool `[`has_word`](#classearly__parser_1_1algo_1_1Algo_1af419b631d35967aafd5768f82224e501)`(self,str word)` \n\nChecks the presence of a word in the grammar\n param word given word\n return True if there is\n return False if there isn't\n\n#### `public bool `[`predict`](#classearly__parser_1_1algo_1_1Algo_1a30c9e0a7e5152029231b4eeff5f5007a)`(self,int _id)` \n\nThe main predict method\n\n#### `public def `[`scan`](#classearly__parser_1_1algo_1_1Algo_1af5dd681b5fb82f2c8d3770138d303670)`(self,int _id,str s)` \n\nThe main scan method\n\n# namespace `early_parser::grammar` \n\n## Summary\n\n Members                        | Descriptions                                \n--------------------------------|---------------------------------------------\n`public bool `[`is_non_terminal`](#namespaceearly__parser_1_1grammar_1ab92177a919205a6addcbd088d132a168)`(str c)`            | Checks the symbol for non-terminal param c symbol return: True is non-terminal return: False is terminal.\n`public bool `[`is_symbol`](#namespaceearly__parser_1_1grammar_1a2f2d762c2d29c7432af3816b6f3496ca)`(str c)`            | Checks belonging of the symbol to the alphabet param c symbol return: True is in alphabet return: False not in the alphabet.\n`public bool `[`is_valid_rule`](#namespaceearly__parser_1_1grammar_1a8579fcff0794fd09f899e1c5b66267e4)`(str rule)`            | Checks validity of rules param rule given rules return True if valid return False if not valid.\n`public bool `[`is_valid_single_rule`](#namespaceearly__parser_1_1grammar_1a9a637f0e5ab71e4bba6daec76d81861e)`(str rule)`            | Checks validity of a separate rule param rule given rule return True if valid return False if not valid.\n`public list `[`parse_rules`](#namespaceearly__parser_1_1grammar_1a82e4ec13fa1bbf0edd01046384a15d45)`(str rule)`            | Section: Work with rules.\n`class `[`early_parser::grammar::Grammar`](#classearly__parser_1_1grammar_1_1Grammar) | Section: Work with [Grammar](#classearly__parser_1_1grammar_1_1Grammar).\n\n## Members\n\n#### `public bool `[`is_non_terminal`](#namespaceearly__parser_1_1grammar_1ab92177a919205a6addcbd088d132a168)`(str c)` \n\nChecks the symbol for non-terminal param c symbol return: True is non-terminal return: False is terminal.\n\n#### `public bool `[`is_symbol`](#namespaceearly__parser_1_1grammar_1a2f2d762c2d29c7432af3816b6f3496ca)`(str c)` \n\nChecks belonging of the symbol to the alphabet param c symbol return: True is in alphabet return: False not in the alphabet.\n\n#### `public bool `[`is_valid_rule`](#namespaceearly__parser_1_1grammar_1a8579fcff0794fd09f899e1c5b66267e4)`(str rule)` \n\nChecks validity of rules param rule given rules return True if valid return False if not valid.\n\n#### `public bool `[`is_valid_single_rule`](#namespaceearly__parser_1_1grammar_1a9a637f0e5ab71e4bba6daec76d81861e)`(str rule)` \n\nChecks validity of a separate rule param rule given rule return True if valid return False if not valid.\n\n#### `public list `[`parse_rules`](#namespaceearly__parser_1_1grammar_1a82e4ec13fa1bbf0edd01046384a15d45)`(str rule)` \n\nSection: Work with rules.\n\nSplits several rules written in one line into separate ones param rule given rules return rules list of split rules\n\n# class `early_parser::grammar::Grammar` \n\nSection: Work with [Grammar](#classearly__parser_1_1grammar_1_1Grammar).\n\nRealization of Context-free [Grammar](#classearly__parser_1_1grammar_1_1Grammar)\n\n## Summary\n\n Members                        | Descriptions                                \n--------------------------------|---------------------------------------------\n`public def `[`__init__`](#classearly__parser_1_1grammar_1_1Grammar_1a5fb051c8784ea6338ebcee41c4d38139)`(self,str start)` | Constructor.\n`public def `[`__iter__`](#classearly__parser_1_1grammar_1_1Grammar_1a45163c19b7c87f553c6f1d055d4668cb)`(self)` | Redefining of method 'iter' by class _Iterator\n`public int `[`__len__`](#classearly__parser_1_1grammar_1_1Grammar_1a5fa3fce343eed37d38c208516f6f875b)`(self,str c)` | Outputs size of object param c non-term return size of container.\n`public def `[`__repr__`](#classearly__parser_1_1grammar_1_1Grammar_1a9a47563093dfc5ba12274b66e368920c)`(self)` | This method allow to convert grammar to string !!! This method wasn't tested !!!\n`public def `[`__str__`](#classearly__parser_1_1grammar_1_1Grammar_1a23e8041ce1015febe4fdace3225714f9)`(self)` | This method allow to output grammar to stdout !!! This method wasn't tested !!!\n`public bool `[`add_rule`](#classearly__parser_1_1grammar_1_1Grammar_1af1ff1f04064b8e10ddaa6d14510f89ec)`(self,str rule)` | Add rule to grammar param rule given rule return True correctly added return False wasn't added.\n`public def `[`del_similar_rules`](#classearly__parser_1_1grammar_1_1Grammar_1a6346443a6a4f8fdb90cc82dc8bee5719)`(self)` | Delete similar rules from grammar For this uses container - set.\n`public def `[`erase_rule`](#classearly__parser_1_1grammar_1_1Grammar_1a761221323a75061309b1df0d0681b44b)`(self,`[`_Iterator`](#classearly__parser_1_1grammar_1_1Grammar_1_1__Iterator)` it)` | Deleting rule by iterator param it iterator return iterator to the next element.\n`public def `[`get_start`](#classearly__parser_1_1grammar_1_1Grammar_1afa8749a569f6a1c70b7c35337e2a7000)`(self)` | Get first nonTerminal in grammar.\n`public def `[`input_init`](#classearly__parser_1_1grammar_1_1Grammar_1a34eeb920ef7666d32ba2d7f71a4b5341)`(self)` | Input the grammar from stdin !!! This method wasn't tested !!!\n\n## Members\n\n#### `public def `[`__init__`](#classearly__parser_1_1grammar_1_1Grammar_1a5fb051c8784ea6338ebcee41c4d38139)`(self,str start)` \n\nConstructor.\n\n#### `public def `[`__iter__`](#classearly__parser_1_1grammar_1_1Grammar_1a45163c19b7c87f553c6f1d055d4668cb)`(self)` \n\nRedefining of method 'iter' by class _Iterator\n\n#### `public int `[`__len__`](#classearly__parser_1_1grammar_1_1Grammar_1a5fa3fce343eed37d38c208516f6f875b)`(self,str c)` \n\nOutputs size of object param c non-term return size of container.\n\n#### `public def `[`__repr__`](#classearly__parser_1_1grammar_1_1Grammar_1a9a47563093dfc5ba12274b66e368920c)`(self)` \n\nThis method allow to convert grammar to string !!! This method wasn't tested !!!\n\n#### `public def `[`__str__`](#classearly__parser_1_1grammar_1_1Grammar_1a23e8041ce1015febe4fdace3225714f9)`(self)` \n\nThis method allow to output grammar to stdout !!! This method wasn't tested !!!\n\n#### `public bool `[`add_rule`](#classearly__parser_1_1grammar_1_1Grammar_1af1ff1f04064b8e10ddaa6d14510f89ec)`(self,str rule)` \n\nAdd rule to grammar param rule given rule return True correctly added return False wasn't added.\n\n#### `public def `[`del_similar_rules`](#classearly__parser_1_1grammar_1_1Grammar_1a6346443a6a4f8fdb90cc82dc8bee5719)`(self)` \n\nDelete similar rules from grammar For this uses container - set.\n\n#### `public def `[`erase_rule`](#classearly__parser_1_1grammar_1_1Grammar_1a761221323a75061309b1df0d0681b44b)`(self,`[`_Iterator`](#classearly__parser_1_1grammar_1_1Grammar_1_1__Iterator)` it)` \n\nDeleting rule by iterator param it iterator return iterator to the next element.\n\n#### `public def `[`get_start`](#classearly__parser_1_1grammar_1_1Grammar_1afa8749a569f6a1c70b7c35337e2a7000)`(self)` \n\nGet first nonTerminal in grammar.\n\n#### `public def `[`input_init`](#classearly__parser_1_1grammar_1_1Grammar_1a34eeb920ef7666d32ba2d7f71a4b5341)`(self)` \n\nInput the grammar from stdin !!! This method wasn't tested !!!\n\n# class `early_parser::grammar::Grammar::_Iterator` \n\nStandard bidirectional Iterator for [Grammar](#classearly__parser_1_1grammar_1_1Grammar).\n\n## Summary\n\n Members                        | Descriptions                                \n--------------------------------|---------------------------------------------\n`public def `[`__init__`](#classearly__parser_1_1grammar_1_1Grammar_1_1__Iterator_1a34584ef1aeb0931db004e19c350472cd)`(self,`[`rules`](#classearly__parser_1_1grammar_1_1Grammar_1_1__Iterator_1a595e07a99f60f22a6a29e4fca291ea28)`,c)` | Constructor.\n`public def `[`__iter__`](#classearly__parser_1_1grammar_1_1Grammar_1_1__Iterator_1a45163c19b7c87f553c6f1d055d4668cb)`(self)` | Realization of iteration in grammar.\n`public def `[`__next__`](#classearly__parser_1_1grammar_1_1Grammar_1_1__Iterator_1a71d9958aa7271de5bb07b861c559d970)`(self)` | Redefining of method 'next'.\n`public def `[`get_rule`](#classearly__parser_1_1grammar_1_1Grammar_1_1__Iterator_1aa5b2b44bad2a6a1ca9e29c0d3c05e854)`(self)` | Get the rule by iterator.\n`public def `[`is_valid`](#classearly__parser_1_1grammar_1_1Grammar_1_1__Iterator_1ac75859e6cb7891dea32afc9f89a909a5)`(self)` | Checks whether the iterator is valid.\n\n## Members\n\n#### `public def `[`__init__`](#classearly__parser_1_1grammar_1_1Grammar_1_1__Iterator_1a34584ef1aeb0931db004e19c350472cd)`(self,`[`rules`](#classearly__parser_1_1grammar_1_1Grammar_1_1__Iterator_1a595e07a99f60f22a6a29e4fca291ea28)`,c)` \n\nConstructor.\n\n#### `public def `[`__iter__`](#classearly__parser_1_1grammar_1_1Grammar_1_1__Iterator_1a45163c19b7c87f553c6f1d055d4668cb)`(self)` \n\nRealization of iteration in grammar.\n\n#### `public def `[`__next__`](#classearly__parser_1_1grammar_1_1Grammar_1_1__Iterator_1a71d9958aa7271de5bb07b861c559d970)`(self)` \n\nRedefining of method 'next'.\n\n#### `public def `[`get_rule`](#classearly__parser_1_1grammar_1_1Grammar_1_1__Iterator_1aa5b2b44bad2a6a1ca9e29c0d3c05e854)`(self)` \n\nGet the rule by iterator.\n\n#### `public def `[`is_valid`](#classearly__parser_1_1grammar_1_1Grammar_1_1__Iterator_1ac75859e6cb7891dea32afc9f89a909a5)`(self)` \n\nChecks whether the iterator is valid.\n\n# class `early_parser::algo::Algo::_State` \n\nMetaclass that implements a state inside a certain rule\n\n## Summary\n\n Members                        | Descriptions                                \n--------------------------------|---------------------------------------------\n`public def `[`__eq__`](#classearly__parser_1_1algo_1_1Algo_1_1__State_1ad794ff077f2f05f228a7109f3670ac40)`(self,other)` | Redefining the method '=='\n`public def `[`__hash__`](#classearly__parser_1_1algo_1_1Algo_1_1__State_1a3195ea87162f33a34d0079931a8194ca)`(self)` | Redefining the hash method\n`public def `[`__init__`](#classearly__parser_1_1algo_1_1Algo_1_1__State_1a69e2d73e3e17ce29769363bccd5e8b61)`(self,str rule,int rule_pos,int str_pos)` | The constructor of _State\n\n## Members\n\n#### `public def `[`__eq__`](#classearly__parser_1_1algo_1_1Algo_1_1__State_1ad794ff077f2f05f228a7109f3670ac40)`(self,other)` \n\nRedefining the method '=='\n\n#### `public def `[`__hash__`](#classearly__parser_1_1algo_1_1Algo_1_1__State_1a3195ea87162f33a34d0079931a8194ca)`(self)` \n\nRedefining the hash method\n\n#### `public def `[`__init__`](#classearly__parser_1_1algo_1_1Algo_1_1__State_1a69e2d73e3e17ce29769363bccd5e8b61)`(self,str rule,int rule_pos,int str_pos)` \n\nThe constructor of _State\n\nGenerated by [Moxygen](https://sourcey.com/moxygen)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandy-messer%2Fformal-languages-practice-2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandy-messer%2Fformal-languages-practice-2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandy-messer%2Fformal-languages-practice-2/lists"}