{"id":20425391,"url":"https://github.com/catseye/relwrite","last_synced_at":"2025-03-05T04:45:18.091Z","repository":{"id":142239954,"uuid":"568464119","full_name":"catseye/relwrite","owner":"catseye","description":"MIRROR of https://codeberg.org/catseye/relwrite : Relate strings to strings via a grammar in the Chomsky hierarchy","archived":false,"fork":false,"pushed_at":"2022-12-31T20:31:06.000Z","size":23,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-15T15:12:34.252Z","etag":null,"topics":["beam-search","breadth-first-search","chomsky-hierarchy","context-sensitive-grammars","generic-parser","grammar-based-systems","text-generation","text-generator","unrestricted-grammars"],"latest_commit_sha":null,"homepage":"https://catseye.tc/node/relwrite","language":"Python","has_issues":false,"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/catseye.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":"2022-11-20T16:05:20.000Z","updated_at":"2023-10-31T11:50:54.000Z","dependencies_parsed_at":"2023-03-21T19:17:29.168Z","dependency_job_id":null,"html_url":"https://github.com/catseye/relwrite","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/catseye%2Frelwrite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/catseye%2Frelwrite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/catseye%2Frelwrite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/catseye%2Frelwrite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/catseye","download_url":"https://codeload.github.com/catseye/relwrite/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241966977,"owners_count":20050324,"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":["beam-search","breadth-first-search","chomsky-hierarchy","context-sensitive-grammars","generic-parser","grammar-based-systems","text-generation","text-generator","unrestricted-grammars"],"created_at":"2024-11-15T07:13:09.344Z","updated_at":"2025-03-05T04:45:18.085Z","avatar_url":"https://github.com/catseye.png","language":"Python","readme":"`relwrite`\n==========\n\n`relwrite` relates strings to strings via a grammar in the Chomsky hierarchy.\n\nWhat does \"relate\" mean in this context?\n\n*   Given a grammar and a string of terminals, it can _parse_ that string, and\n    report if is in the language of the grammar or not.\n*   Given a grammar and a nonterminal, it can _generate_ a string of terminals\n    from them.\n\nThe relational engine in `relwrite` is a very general one, based on string rewriting.\nThere are therefore no restrictions on the input grammar -- it may be **regular**,\n**context-free**, **context-sensitive**, or **unrestricted**.  If the grammar is\nambiguous, then all possible parses (or generations) can be returned.\n\nIt should be understood that `relwrite` trades off performance and small\nmemory footprint in favour of generality, so in general usage, it works\nbest on small inputs.\n\nThere are, however, features intended to improve performance in the case of very\nlong derivations.  Search strategies can be used to enable a **beam search** algorithm\nwhich aggressively focuses on derivations with a desired propery, e.g. a particular\nminimum length.  This does sacrifice completeness however -- only a handful of all\nthe possible results will be returned.\n\nThe grammar must be provided in the form of a JSON file.  There are example\ngrammar files in the `eg/` directory of this repo.\n\n### Example usage\n\nGenerate a string from a starting non-terminal in a grammar:\n\n```\n./bin/relwrite complete eg/recursive-grammar.json \\\n               --start \"\u003cSentence\u003e\" --max-derivations=1\n```\n\nParse a string w.r.t. a grammar:\n\n```\n./bin/relwrite complete eg/recursive-grammar.json \\\n               --parse --start \"a penguin sees a penguin then sees a dog\" \\\n               --goal \"\u003cSentence\u003e\"\n```\n\nUse the `complete` strategy to generate all possible strings from a\nstarting non-terminal in a grammar.  NOTE that this can use unreasonable\namounts of resources, with possibly adverse effects on your system.\n\n```\n./bin/relwrite complete eg/sample-grammar.json --start \"\u003cSentence\u003e\"\n```\n\nUse the `expand` strategy to generate a really long string from a non-terminal\nin a grammar, without running out of memory and only taking a few hours of\nprocessor time:\n\n```\n./bin/relwrite expand eg/recursive-grammar.json \\\n               --start \"\u003cSentence\u003e\" --max-derivations=1 --expand-until=3000 \\\n               --output-file=out.json\n```\n\nUse the `contract` strategy to parse a really long string from a non-terminal\nin a grammar, without running out of memory and only taking a few hours of\nprocessor time.  This assumes the string to be parsed is in JSON format in\nthe file `out.json` -- the generation example above would produce this.\n\n```\n./bin/relwrite contract eg/recursive-grammar.json \\\n               --parse --start-set-file=out.json\n```\n\n### Detailed usage\n\nRun `relwrite --help` for a description of all the possible command-line options.  Note that\nthese are somewhat provisional and subject to change.\n\n### Notes\n\n`relwrite` uses the term \"derivation\" as a generic term meaning \"a parse or a generated utterance\".\nIt also uses the term \"utterance\" to mean \"any string of terminals and non-terminals\".\n\n### TODO\n\nAnalyze the input grammar and classify it in the Chomsky hierarchy.\n\nIf the input grammar is context-free, use a chart parsing algorithm to\nefficiently parse it, or an incremental algorithm to generate from it.\n\nAllow strategies to be defined richly, perhaps in JSON files, and let\nthem configure parameters like beam width, max rewrites per utterance, etc.\n\nFor max rewrites per utterance, allow them to be taken from random\npoints (or at least from a randomly-chosen start point) in the utterace.\n\nSupport random search.  For `contract` strategy, it should be sufficient to\nidentify the subset of the next states that is sufficiently contracting\n(this is not a \"beam width\" so much as a \"pre-filter\"),\nthen select a single instance from it at random (beam width of 1).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcatseye%2Frelwrite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcatseye%2Frelwrite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcatseye%2Frelwrite/lists"}