{"id":22847667,"url":"https://github.com/belrbez/cyk-chomsky-nf-grammar-algorithm-java","last_synced_at":"2025-10-10T21:40:08.648Z","repository":{"id":94445331,"uuid":"110036612","full_name":"belrbez/cyk-chomsky-nf-grammar-algorithm-java","owner":"belrbez","description":"Implementation of algorithm to Converting CFGs to CNF (Chomsky Normal Form) and  Cocke–Younger–Kasami (CYK) algorithm for CFGs","archived":false,"fork":false,"pushed_at":"2020-11-08T16:17:32.000Z","size":28,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-03T01:38:58.345Z","etag":null,"topics":["algorithm","cfgs","chomsky","cyk","cyk-chomskynf","grammar","java","normalforms","parser"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/belrbez.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null}},"created_at":"2017-11-08T22:14:22.000Z","updated_at":"2023-10-10T12:43:04.000Z","dependencies_parsed_at":"2023-03-13T16:59:41.898Z","dependency_job_id":null,"html_url":"https://github.com/belrbez/cyk-chomsky-nf-grammar-algorithm-java","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/belrbez/cyk-chomsky-nf-grammar-algorithm-java","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/belrbez%2Fcyk-chomsky-nf-grammar-algorithm-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/belrbez%2Fcyk-chomsky-nf-grammar-algorithm-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/belrbez%2Fcyk-chomsky-nf-grammar-algorithm-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/belrbez%2Fcyk-chomsky-nf-grammar-algorithm-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/belrbez","download_url":"https://codeload.github.com/belrbez/cyk-chomsky-nf-grammar-algorithm-java/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/belrbez%2Fcyk-chomsky-nf-grammar-algorithm-java/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279005419,"owners_count":26083883,"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","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["algorithm","cfgs","chomsky","cyk","cyk-chomskynf","grammar","java","normalforms","parser"],"created_at":"2024-12-13T04:09:04.468Z","updated_at":"2025-10-10T21:40:08.643Z","avatar_url":"https://github.com/belrbez.png","language":"Java","readme":"# CYK-ChomskyNF\nImplementation of algorithm to Converting CFGs to CNF (Chomsky Normal Form) and  Cocke–Younger–Kasami (CYK) algorithm for CFGs\n\nThere are two modules: root and CoreMin.\nUse CoreMin module for simple start of algorithms.\n\n## Cocke-Younger-Algorithm\nThis is the famous CYK algorithm implemented in Java.\nIt can be used to test a given string with a grammar file that is in ![Chomsky\nNormal Form](https://en.wikipedia.org/wiki/Chomsky_normal_form).\n\n### CYK formal algorithm [1]\n\n\tlet the input be a string S consisting of n characters: a1 ... an.\n\tlet the grammar contain r nonterminal symbols R1 ... Rr.\n\tThis grammar contains the subset Rs which is the set of start symbols.\n\tlet P[n,n,r] be an array of booleans. Initialize all elements of P to false.\n\tfor each i = 1 to n\n\t  for each unit production Rj -\u003e ai\n\t    set P[i,1,j] = true\n\tfor each i = 2 to n -- Length of span\n\t  for each j = 1 to n-i+1 -- Start of span\n\t    for each k = 1 to i-1 -- Partition of span\n\t      for each production RA -\u003e RB RC\n\t        if P[j,k,B] and P[j+k,i-k,C] then set P[j,i,A] = true\n\tif any of P[1,n,x] is true (x is iterated over the set s, where s are all the indices for Rs) then\n\t  S is member of language\n\telse\n\t  S is not member of language\n\n\n### Chomsky Normal Form to Context Free Grammar algorithm [2]\n\n\t1. Remove all nonterminal from the right hand side of all productions except the unit\n\tproductions.\n\t2. Replace any rule that has three or more nonterminals with the equivalent rules of size\n\ttwo.\n\t3. Replace every rule S with S0. Add a new rule S0-\u003eS\n\t4. Remove all epsilon transitions by iterating their equivalent form. For each production\n\tthat includes a terminal that is equal to epsilon, add another rule equal to the initial\n\trule excluding the terminal that is equal to epsilon.\n\t5. Remove all the unit rules of the form A ? B\n\n\n## Running the algorithm\n\n1. Clone the project, cd into the folder and then the src folder then run javac\n   to compile:\n   \n    `git clone git://github.com/belrbeZ/CYK-ChomskyNF`\n   \n    or Use Git or checkout with SVN using the web URL \n    \n    `https://github.com/belrbeZ/CYK-ChomskyNF.git`\n    \n2. Compile and start console applications with demonstration of algorithms.\n\n    2.1. If you want to see whole cyk algorithm with converting grammar in CNF form\n        \n            `cd CYK-ChomskyNF/CoreMin/src/` \n            \n            `javac cyk.java`\n            \n    2.2. If you want to see only CNF grammar converting\n        \n            `cd CYK-ChomskyNF/CoreMin/src/`\n            \n            `javac Grammar.java`\n        \n3. Run the program by giving it a grammar|input file of your choosing and supplying\n   a string:\n   \n   3.1. CYK:\n\n       `java Cyk grammar_hw6.txt word1_hw6.txt`\n\n    Or simple start application to use the default input files (\"grammar_hw6.txt\" and \"word1_hw6.txt\").\n\n       `java Cyk`\n    \n    3.2. CNF:\n\n       `java Grammar grammar_hw6.txt`\n\n    Or simple start application to use the default input files (\"grammar_hw6.txt\").\n\n       `java Grammar`\n    \n\n### Requirements\n  - Java 7\n\n##Refferences\n[1] CKY Algorithm, Chomsky Normal Form. Scott Farrar. CLMA, University of Washington. January 13, 2010.\n\n[2] Chomsky Normal Form. \n\u003chttps://www.tutorialspoint.com/automata_theory/chomsky_normal_form.htm\u003e.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbelrbez%2Fcyk-chomsky-nf-grammar-algorithm-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbelrbez%2Fcyk-chomsky-nf-grammar-algorithm-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbelrbez%2Fcyk-chomsky-nf-grammar-algorithm-java/lists"}