{"id":15009430,"url":"https://github.com/robmch/cyk-parser","last_synced_at":"2025-04-09T17:23:57.586Z","repository":{"id":182807441,"uuid":"76282426","full_name":"RobMcH/CYK-Parser","owner":"RobMcH","description":"A CYK parser written in Python 3.","archived":false,"fork":false,"pushed_at":"2021-01-20T16:15:39.000Z","size":13,"stargazers_count":37,"open_issues_count":1,"forks_count":25,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-23T19:23:14.679Z","etag":null,"topics":["cyk-parser","natural-language-processing","nlp","nlp-parsing","parser","parsing","python-3-6"],"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/RobMcH.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2016-12-12T18:09:41.000Z","updated_at":"2024-06-21T10:21:28.000Z","dependencies_parsed_at":"2023-07-21T14:21:21.458Z","dependency_job_id":null,"html_url":"https://github.com/RobMcH/CYK-Parser","commit_stats":null,"previous_names":["robmch/cyk-parser"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobMcH%2FCYK-Parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobMcH%2FCYK-Parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobMcH%2FCYK-Parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobMcH%2FCYK-Parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RobMcH","download_url":"https://codeload.github.com/RobMcH/CYK-Parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248075497,"owners_count":21043598,"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":["cyk-parser","natural-language-processing","nlp","nlp-parsing","parser","parsing","python-3-6"],"created_at":"2024-09-24T19:25:13.679Z","updated_at":"2025-04-09T17:23:57.569Z","avatar_url":"https://github.com/RobMcH.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CYK-Parser\n\nThis is a simple context-free grammar parser written in Python 3.\nIt includes a converter to transform a context-free grammar to chomsky normal form. The converter can't handle epsilon productions, though. For the actual parsing the Cocke-Younger-Kasamai algorithm is used.\n\n#\n\nThe code isn't by any means perfect and isn't supposed to.\n**Feel free to use any piece of the code in your own projects.**\n\n# Usage\n### As a standalone program\nTo run the parser **Python 3.6** needs to be installed. The file \"GrammarConverter.py\" needs to be either in the same directory or within a directory, in which Python looks for modules to include. The program can be run as a module (`python3 -m Parser`), when\nin the same directory, or as a normal python script. If the parser is run as a standalone program it expects two arguments. The first one is a file containing the grammar (see below for an example) and the second one a file containing the input sentence.\n\n`python3 cyk_parser.py /home/Users/god/grammar.txt /home/Users/god/sentences/pajamas.txt`\n\n\u003e Using /home/Users/god/grammar.txt as path for the grammar and /home/Users/god/sentences/pajamas.txt\nas path for the sentence.\n\nWhen the sentence is contained in the language produced by the grammar, the parser will output the parsed tree in a non-graphical string format.\n\n`python3 cyk_parser.py grammar.txt \"I shot an elephant in my pajamas\"`  \n\u003e Using grammar.txt as path for the grammar and sentence.txt as path for the sentence.  \nThe given sentence is contained in the language produced by the given grammar!\n\n\u003e Possible parse(s):  \n[S [NP 'I'][VP [V 'shot'][NP [NP0 [Det 'an'][N 'elephant']][PP [P 'in'][NP [Det 'my'][N 'pajamas']]]]]]  \n[S [NP 'I'][VP [VP [V 'shot'][NP [Det 'an'][N 'elephant']]][PP [P 'in'][NP [Det 'my'][N 'pajamas']]]]]\n\nWhen the sentence is not contained in the grammar, the parser won't print out a tree.\n\n`python3 cyk_parser.py some_grammar.txt sentence.txt`\n\n\u003e Using some_grammar.txt as path for the grammar and sentence.txt as path for the sentence.  \nThe given sentence is not contained in the language produced by the given grammar!\n\n### As imported module\nAlternatively the parser can be imported into other python scripts. The constructor expects a grammar which will be converted to CNF, so any CFG is fine, and some input to parse. Both of the arguments can either be file paths or just a string. Parser objects are callable and expect new input which by default just will be stored in the object and not directly parsed.\n\n# Example input\nAn example for a simple grammar is given below. Just paste it in a text file and run the parser with it and an input sentence file (it is assumed, that the whole input sentence is in the first line of that file) or pass it as a string to the parser.  \n\nS -\u003e NP VP  \nPP -\u003e P NP  \nNP -\u003e Det N  \nNP -\u003e Det N PP  \nNP -\u003e 'I'  \nVP -\u003e V NP  \nVP -\u003e VP PP  \nDet -\u003e 'an'  \nDet -\u003e 'my'  \nN -\u003e 'elephant'  \nN -\u003e 'pajamas'  \nV -\u003e 'shot'  \nP -\u003e 'in'  \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobmch%2Fcyk-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobmch%2Fcyk-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobmch%2Fcyk-parser/lists"}