{"id":16027841,"url":"https://github.com/wisn/ccgjs","last_synced_at":"2025-04-05T04:42:11.476Z","repository":{"id":56657733,"uuid":"305176016","full_name":"wisn/ccgjs","owner":"wisn","description":"A combinatory categorial grammar (CCG) library for the web.","archived":false,"fork":false,"pushed_at":"2020-10-26T20:57:58.000Z","size":514,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-10T19:08:00.973Z","etag":null,"topics":["ccg","combinatory-categorial-grammar"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/wisn.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}},"created_at":"2020-10-18T19:05:55.000Z","updated_at":"2022-12-28T21:50:00.000Z","dependencies_parsed_at":"2022-08-15T22:40:57.563Z","dependency_job_id":null,"html_url":"https://github.com/wisn/ccgjs","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/wisn%2Fccgjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wisn%2Fccgjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wisn%2Fccgjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wisn%2Fccgjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wisn","download_url":"https://codeload.github.com/wisn/ccgjs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247289394,"owners_count":20914464,"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":["ccg","combinatory-categorial-grammar"],"created_at":"2024-10-08T20:23:52.987Z","updated_at":"2025-04-05T04:42:11.452Z","avatar_url":"https://github.com/wisn.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CCGjs\n\nA combinatory categorial grammar (CCG) library for the web.\n\n**NOTE**: Work-in-progress could be found on the [development][1] branch.\n\n## Requirements\n\n- Node.js ^= 12.18.2\n- NPM ^= 6.14.7\n\n## Installation\n\n### Development\n\nRun `npm install` and we are all set.\n\n### Web Browser\n\nInclude this library on your HTML file.\n\n```html\n\u003cscript type=\"text/javascript\" src=\"/path/to/ccgjs\"\u003e\u003c/script\u003e\n```\n\nReplace `/path/to/ccgjs` with the CCGjs library URL.\nThen, use it:\n\n```html\n\u003cscript type=\"text/javascript\"\u003e\n  const { CCG } = ccgjs;\n\n  // do something\n\u003c/script\u003e\n```\n\nSee `examples/index.html` as reference.\n\n## Available APIs\n\n### CCG.Reader\n\nRead and then parse machine-readable CCG derivation into a JavaScript object.\n\nUsage:\n\n```typescript\nconst str = '(\u003cT S 0 2\u003e (\u003cL S/NP PSP PSP Hi S/NP\u003e) (\u003cL NP NNP NNP Wisnu NP\u003e))';\nconst reader = new CCG.Reader(str);\nif (reader.read()) {\n  console.log(reader.result);\n}\n```\n\nThe returned object looks like this:\n\n```\n{\n  node: {\n    type: 'T',\n    ccgCat: 'S',\n    head: 0,\n    dtrs: 2,\n  },\n  left: {\n    node: {\n      type: 'L',\n      ccgCat: 'S/NP',\n      modPOSTag: 'PSP',\n      origPOSTag: 'PSP',\n      word: 'Hi',\n      predArgCat: 'S/NP',\n    },\n  },\n  right: {\n    node: {\n      type: 'L',\n      ccgCat: 'NP',\n      modPOSTag: 'NNP',\n      origPOSTag: 'NNP',\n      word: 'Wisnu',\n      predArgCat: 'NP',\n    },\n  },\n}\n```\n\nWe uses PEG.js to build the parser.\nThe parsing expression grammar could be found on the `src/ccg.pegjs` file.\nAs for the generated parser, it could be found on the `src/generated.pegjs.ts`\nfile.\n\nRun `npm run pegjs` to generate the `.pegjs` file into `.ts` file.\n\n### CCG.Tree\n\nConstruct a JavaScript tree object based on the parsed machine-readable CCG\nderivation via `CCG.Reader`. It will also building useful metadata for later\nuse.\n\nUsage:\n\n```typescript\nconst str = '(\u003cT S 0 2\u003e (\u003cL S/NP PSP PSP Hi S/NP\u003e) (\u003cL NP NNP NNP Wisnu NP\u003e))';\nconst tree = new CCG.Tree(str);\nconsole.log(tree);\n```\n\nThe returned object looks like this:\n\n```\nTree {\n  metadata: {\n    isParsed: true,\n    sentence: 'Hi Wisnu',\n    words: [ 'Hi', 'Wisnu' ],\n    ccgCats: [ 'S/NP', 'NP' ],\n    height: 2,\n    nodes: [ [Object], [Object], [Object] ]\n  },\n  mappedIndexedWords: { '0': { value: [Object] }, '1': { value: [Object] } },\n  root: {\n    value: { type: 'T', ccgCat: 'S', head: 0, dtrs: 2 },\n    left: { value: [Object] },\n    right: { value: [Object] }\n  }\n}\n```\n\nFor more information about the omitted `[Object]`,\nsee `CCG.TreeTypes.Metadata`, `CCG.TreeTypes.IndexedWordMapper`, and\n`CCG.TreeTypes.Node`.\n\n#### toString\n\nWe can also turn the tree back into machine-readable CCG derivation by doing\n`tree.toString()`. The returned `string` will be:\n\n```\n(\u003cT S 0 2\u003e (\u003cL S/NP PSP PSP Hi S/NP\u003e) (\u003cL NP NNP NNP Wisnu NP\u003e))\n```\n\n#### buildDerivations\n\nIt is possible to get the structured CCG derivation based on the\n`CCG.TreeTypes.Node` simply by doing `tree.buildDerivations()`.\nThe returned `Array\u003cArray\u003cCCG.TreeTypes.Derivation\u003e\u003e` will be:\n\n```\n[\n  [\n    { from: 0, to: 0, ccgCat: 'S/NP' },\n    { from: 1, to: 1, ccgCat: 'NP' }\n  ],\n  [ { from: 0, to: 1, ccgCat: 'S', opr: '\u003e' } ]\n]\n```\n\nHow to read?\n\nIn the `CCG.TreeTypes.Metadata`, we may find `words` key. In this example,\nit will be `['Hi', 'Wisnu']`. Meaning that word `Hi` is at `0` index and\nword `Wisnu` is at `1` index. We may read it as:\n\n```\n  Hi     Wisnu\n------ ---------\n S/NP     NP\n---------------\u003e\n       S\n```\n\n### CCG.DOM\n\nRender and manipulate `CCG.Tree` as a DOM (document object model) directly on\nthe browser. Currently, there is only one method available.\n\nUsage:\n\n```typescript\nconst str = [\n  '(\u003cT Sf 1 2\u003e',\n  '(\u003cT NP 0 2\u003e',\n  '(\u003cL NP NNP NNP raam NP\u003e)',\n  '(\u003cL NP\\\\NP PSP PSP ne NP\\\\NP\u003e))',\n  '(\u003cT Sf\\\\NP 1 2\u003e',\n  '(\u003cT NP 0 2\u003e',\n  '(\u003cL NP NNP NNP mohan NP\u003e)',\n  '(\u003cL NP\\\\NP PSP PSP ko NP\\\\NP\u003e))',\n  '(\u003cT (Sf\\\\NP)\\\\NP 1 2\u003e',\n  '(\u003cT NP 1 2\u003e',\n  '(\u003cL NP/NP JJ JJ niilii NP/NP\u003e)',\n  '(\u003cL NP NN NN kitaab NP\u003e))',\n  '(\u003cL ((Sf\\\\NP)\\\\NP)\\\\NP VM VM dii ((Sf\\\\NP)\\\\NP)\\\\NP\u003e))))',\n].join(' ');\nconst dom = new CCG.DOM(str);\nconst table = dom.createTable();\n\n// apply it directly\ndocument.body.appendChild(table);\n\n// or take the HTML string\nconsole.log(table.outerHTML);\n```\n\nHow it looks like?\nTake a look on this [JS Bin](https://jsbin.com/woqazik/3/edit?html,output)!\n\n## TODO\n\nThere are a lot of things to do.\nThe goal of this project is to enable interactive CCG derivation manipulation\ndirectly on the web browser. By _manipulation_ we meant, as an example, the\nability to (interactively) create, edit, and delete a CCG node from its tree.\nThe direction of this project should be clear by now.\n\n## Contributing\n\nPlease refrain to contribute for the time being until this project officially\nreleased. We will add `CONTRIBUTING.md` after we are ready.\n\nBoth issues and pull requests will be ignored.\n\n## Acknowledgements\n\nThis JavaScript library is part of my undergraduate thesis.\nHence, I would like to thank my supervisors\n([@aromadhony][2] and [@saidalfaraby][3]) for their advice and guidance.\n\n## References\n\nHockenmaier, J., \u0026 Steedman, M. (2007). CCGbank: A corpus of CCG derivations\nand dependency structures extracted from the Penn Treebank.\n_Computational Linguistics_, _33_(3), 355–396.\n\nAmbati, B.R., Deoskar, T. \u0026 Steedman, M. Hindi CCGbank: A CCG treebank\nfrom the Hindi dependency treebank.\n_Lang Resources \u0026 Evaluation_ **52**, 67–100 (2018).\n\n## License\n\nLicensed under the [MIT License](LICENSE).\n\n[1]: https://github.com/wisn/ccgjs/tree/development\n[2]: https://github.com/aromadhony\n[3]: https://github.com/saidalfaraby\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwisn%2Fccgjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwisn%2Fccgjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwisn%2Fccgjs/lists"}