{"id":15662164,"url":"https://github.com/azu/nlp-pattern-match","last_synced_at":"2025-07-08T06:34:08.412Z","repository":{"id":25702710,"uuid":"106092145","full_name":"azu/nlp-pattern-match","owner":"azu","description":"Natural Language pattern matching library for JavaScript.","archived":false,"fork":false,"pushed_at":"2022-02-23T12:30:54.000Z","size":435,"stargazers_count":20,"open_issues_count":3,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-16T06:53:45.589Z","etag":null,"topics":["english","japanese","javascript","morphological-analysis","nlcst","nlp","pos"],"latest_commit_sha":null,"homepage":null,"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/azu.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"azu"}},"created_at":"2017-10-07T11:20:30.000Z","updated_at":"2025-03-15T01:37:03.000Z","dependencies_parsed_at":"2022-07-27T05:16:37.493Z","dependency_job_id":null,"html_url":"https://github.com/azu/nlp-pattern-match","commit_stats":null,"previous_names":[],"tags_count":66,"template":false,"template_full_name":null,"purl":"pkg:github/azu/nlp-pattern-match","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azu%2Fnlp-pattern-match","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azu%2Fnlp-pattern-match/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azu%2Fnlp-pattern-match/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azu%2Fnlp-pattern-match/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/azu","download_url":"https://codeload.github.com/azu/nlp-pattern-match/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azu%2Fnlp-pattern-match/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262396900,"owners_count":23304517,"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":["english","japanese","javascript","morphological-analysis","nlcst","nlp","pos"],"created_at":"2024-10-03T13:30:27.594Z","updated_at":"2025-07-08T06:34:08.378Z","avatar_url":"https://github.com/azu.png","language":"TypeScript","funding_links":["https://github.com/sponsors/azu"],"categories":[],"sub_categories":[],"readme":"# nlp-pattern-match [![Actions Status: test](https://github.com/azu/nlp-pattern-match/workflows/test/badge.svg)](https://github.com/azu/nlp-pattern-match/actions?query=workflow%3A\"test\")\n\nNatural Language pattern matching library for JavaScript.\n\nThis library based on [NLCST](https://github.com/syntax-tree/nlcst) that is Natural Language Concrete Syntax Tree format.\n\nYou can write pattern match syntax using Part-of-speech(POS) tagging, Morphological Analysis(形態素解析).\n\n## Packages\n\nThis repository is monorepo.\nThis repository includes following packages.\n\n| Package | npm |\n| ------  | --- |\n| nlcst-parse-english | [![npm](https://img.shields.io/npm/v/nlcst-parse-english.svg?style=flat-square)](https://www.npmjs.com/package/nlcst-parse-english) |\n| nlcst-parse-japanese | [![npm](https://img.shields.io/npm/v/nlcst-parse-japanese.svg?style=flat-square)](https://www.npmjs.com/package/nlcst-parse-japanese) |\n| nlcst-pattern-match | [![npm](https://img.shields.io/npm/v/nlcst-pattern-match.svg?style=flat-square)](https://www.npmjs.com/package/nlcst-pattern-match) |\n| match-test-replace | [![npm](https://img.shields.io/npm/v/match-test-replace.svg?style=flat-square)](https://www.npmjs.com/package/match-test-replace) |\n| nlcst-types | [![npm](https://img.shields.io/npm/v/nlcst-types.svg?style=flat-square)](https://www.npmjs.com/package/nlcst-types) |\n| unist-types | [![npm](https://img.shields.io/npm/v/unist-types.svg?style=flat-square)](https://www.npmjs.com/package/unist-types) |\n\n## Support Language\n\nSupport English and Japanese.\nIn other words, We have the above language parser for NLCST.\n\nIf you want to add language, Welcome to Pull Request.\n\n## Match strictly\n\n[NLCST](https://github.com/syntax-tree/nlcst) Parser and Pattern match.\n\nYou write Pattern of NLCST object in `patternMatcher.tag`${object}`. \n\n[nlcst-pattern-match](./packages/nlcst-pattern-match) aim to provide that match strict pattern.\n\nFor more details, See [nlcst-pattern-match](./packages/nlcst-pattern-match) document.\n\n```js\nimport { PatternMatcher } from \"nlcst-pattern-match\";\nimport { EnglishParser } from \"nlcst-parse-english\";\nconst englishParser = new EnglishParser();\nconst patternMatcher = new PatternMatcher({\n    parser: englishParser\n});\nconst pattern = patternMatcher.tag`This is a ${{\n    type: \"WordNode\",\n    children: [\n        {\n            type: \"TextNode\",\n            value: /\\w+/\n        }\n    ]\n}}.`;\nlet text = \"Hello, This is a pen.\";\nconst results = patternMatcher.match(text, pattern);\nconst result = results[0];\n\nassert.strictEqual(\n    text.slice(result.position.start.offset, result.position.end.offset),\n    \"This is a pen.\"\n);\n```\n\n## Easy to replace \n\n[match-test-replace](./pacakges/match-test-replace) aim to provide match, test and replace easily.\n\n```js\nimport { replaceAll, matchTestReplace } from \"match-test-replace\";\nconst text = \"webkit is matched,but node-webkit is not match\";\nconst res = matchTestReplace(text, {\n    pattern: /(\\S*?)webkit/g,\n    replace: () =\u003e \"WebKit\",\n    test: ({ captures }) =\u003e {\n        return captures[0] !== \"node-\";\n    }\n});\nassert.ok(res.ok === true, \"should be ok: false\");\nassert.strictEqual(res.results.length, 1, \"no replace\");\nassert.strictEqual(replaceAll(text, res.results).output, \"WebKit is matched,but node-webkit is not match\");\n```\n\n\n## Easy + Strict\n\nEasy match and replace, but test strictly.\n\n```js\nimport * as assert from \"assert\";\nimport { replaceAll, matchTestReplace } from \"match-test-replace\";\nimport { PatternMatcher } from \"nlcst-pattern-match\";\nimport { EnglishParser } from \"nlcst-parse-english\";\nconst englishParser = new EnglishParser();\nconst matcher = new PatternMatcher({ parser: englishParser });\n// https://developers.google.com/style/clause-order\n// NG: Click Delete if you want to delete the entire document.\n// OK: To delete the entire document, click Delete.\nconst text = 'Click Delete if you want to delete the entire document.';\nconst res = matchTestReplace(text, {\n    pattern: /Click (\\w+) if you want to (.+)./,\n    replace: ({ captures }) =\u003e {\n        console.log(captures);\n        return `To ${captures[1]}, click ${captures[0]}.`\n    },\n    test: ({ all }) =\u003e {\n        const pattern = matcher.tag`Click ${{\n            type: \"WordNode\",\n            data: {\n                // Verb\n                pos: /^VB/\n            }\n        }}`;\n        return matcher.test(all, pattern);\n    }\n});\nassert.ok(res.ok === true, \"should be ok: true\");\nconst output = replaceAll(text, res.results).output;\nassert.strictEqual(output, \"To delete the entire document, click Delete.\");\n```\n\n## Changelog\n\nSee [Releases page](https://github.com/azu/nlp-pattern-match/releases).\n\n## Development\n\n    yarn\n    # setup pacakges\n    yarn bootstrap\n    # test\n    yarn test\n\n## Contributing\n\nPull requests and stars are always welcome.\n\nFor bugs and feature requests, [please create an issue](https://github.com/azu/nlp-pattern-match/issues).\n\n1. Fork it!\n2. Create your feature branch: `git checkout -b my-new-feature`\n3. Commit your changes: `git commit -am 'Add some feature'`\n4. Push to the branch: `git push origin my-new-feature`\n5. Submit a pull request :D\n\n## Author\n\n- [github/azu](https://github.com/azu)\n- [twitter/azu_re](https://twitter.com/azu_re)\n\n## License\n\nMIT © azu\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazu%2Fnlp-pattern-match","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fazu%2Fnlp-pattern-match","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazu%2Fnlp-pattern-match/lists"}