Home
Softono
a

azu

Professional software vendor delivering innovative solutions on the Softono platform. Specialized in both open-source and proprietary software development.

Total Products
2

Software by azu

nlp-pattern-match
Open Source

nlp-pattern-match

# 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") Natural Language pattern matching library for JavaScript. This library based on [NLCST](https://github.com/syntax-tree/nlcst) that is Natural Language Concrete Syntax Tree format. You can write pattern match syntax using Part-of-speech(POS) tagging, Morphological Analysis(形態素解析). ## Packages This repository is monorepo. This repository includes following packages. | Package | npm | | ------ | --- | | 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) | | 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) | | 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) | | 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) | | nlcst-types | [![npm](https://img.shields.io/npm/v/nlcst-types.svg?style=flat-square)](https://www.npmjs.com/package/nlcst-types) | | unist-types | [![npm](https://img.shields.io/npm/v/unist-types.svg?style=flat-square)](https://www.npmjs.com/package/unist-types) | ## Support Language Support English and Japanese. In other words, We have the above language parser for NLCST. If you want to add language, Welcome to Pull Request. ## Match strictly [NLCST](https://github.com/syntax-tree/nlcst) Parser and Pattern match. You write Pattern of NLCST object in `patternMatcher.tag`${object}`. [nlcst-pattern-match](./packages/nlcst-pattern-match) aim to provide that match strict pattern. For more details, See [nlcst-pattern-match](./packages/nlcst-pattern-match) document. ```js import { PatternMatcher } from "nlcst-pattern-match"; import { EnglishParser } from "nlcst-parse-english"; const englishParser = new EnglishParser(); const patternMatcher = new PatternMatcher({ parser: englishParser }); const pattern = patternMatcher.tag`This is a ${{ type: "WordNode", children: [ { type: "TextNode", value: /\w+/ } ] }}.`; let text = "Hello, This is a pen."; const results = patternMatcher.match(text, pattern); const result = results[0]; assert.strictEqual( text.slice(result.position.start.offset, result.position.end.offset), "This is a pen." ); ``` ## Easy to replace [match-test-replace](./pacakges/match-test-replace) aim to provide match, test and replace easily. ```js import { replaceAll, matchTestReplace } from "match-test-replace"; const text = "webkit is matched,but node-webkit is not match"; const res = matchTestReplace(text, { pattern: /(\S*?)webkit/g, replace: () => "WebKit", test: ({ captures }) => { return captures[0] !== "node-"; } }); assert.ok(res.ok === true, "should be ok: false"); assert.strictEqual(res.results.length, 1, "no replace"); assert.strictEqual(replaceAll(text, res.results).output, "WebKit is matched,but node-webkit is not match"); ``` ## Easy + Strict Easy match and replace, but test strictly. ```js import * as assert from "assert"; import { replaceAll, matchTestReplace } from "match-test-replace"; import { PatternMatcher } from "nlcst-pattern-match"; import { EnglishParser } from "nlcst-parse-english"; const englishParser = new EnglishParser(); const matcher = new PatternMatcher({ parser: englishParser }); // https://developers.google.com/style/clause-order // NG: Click Delete if you want to delete the entire document. // OK: To delete the entire document, click Delete. const text = 'Click Delete if you want to delete the entire document.'; const res = matchTestReplace(text, { pattern: /Click (\w+) if you want to (.+)./, replace: ({ captures }) => { console.log(captures); return `To ${captures[1]}, click ${captures[0]}.` }, test: ({ all }) => { const pattern = matcher.tag`Click ${{ type: "WordNode", data: { // Verb pos: /^VB/ } }}`; return matcher.test(all, pattern); } }); assert.ok(res.ok === true, "should be ok: true"); const output = replaceAll(text, res.results).output; assert.strictEqual(output, "To delete the entire document, click Delete."); ``` ## Changelog See [Releases page](https://github.com/azu/nlp-pattern-match/releases). ## Development yarn # setup pacakges yarn bootstrap # test yarn test ## Contributing Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/azu/nlp-pattern-match/issues). 1. Fork it! 2. Create your feature branch: `git checkout -b my-new-feature` 3. Commit your changes: `git commit -am 'Add some feature'` 4. Push to the branch: `git push origin my-new-feature` 5. Submit a pull request :D ## Author - [github/azu](https://github.com/azu) - [twitter/azu_re](https://twitter.com/azu_re) ## License MIT © azu

JavaScript Libraries & Components ML Frameworks
20 Github Stars
promises-book
Open Source

promises-book

# Promises Book [![test](https://github.com/azu/promises-book/actions/workflows/test.yml/badge.svg)](https://github.com/azu/promises-book/actions/workflows/test.yml) [![Gitter chat](https://badges.gitter.im/azu/promises-book.png)](https://gitter.im/azu/promises-book) JavaScript Promiseについての薄い電子書籍です。 - ウェブ版: [https://azu.github.io/promises-book/](https://azu.github.io/promises-book/ "Promises book") - PDF版: [https://azu.github.io/promises-book/javascript-promise-book.pdf](https://azu.github.io/promises-book/javascript-promise-book.pdf) - おまけ(付録): [https://gumroad.com/l/javascript-promise](https://gumroad.com/l/javascript-promise "JavaScript Promiseの本 付録") 作者をサポートしたい場合は、次の手段が利用できます。 - GitHub Sponsorsで[作者に対してmonthly/onetimeで支援](https://github.com/sponsors/azu)できます - Gumroadで[付録を任意の値段で購入](https://gumroad.com/l/javascript-promise "JavaScript Promiseの本 付録")できます。 過去のバージョンについては次のページから参照できます。 - [JavaScript Promiseの本(v1)](https://azu.github.io/promises-book/archives/v1/) This book has been released in : - **Chinese**: [JavaScript Promise迷你书(中文版)](http://liubin.github.io/promises-book/) - **Korean**: [\[한빛미디어 eBook\] JavaScript Promise(번역서)](https://www.hanbit.co.kr/store/books/look.php?p_code=E5027975256) ## Installation この書籍はAsciidocフォーマットで書かれています。 [Asciidoctor](https://asciidoctor.org/ "Asciidoctor")でビルドすることができます。 ### HTMLのビルド ``` sh bundle install --path vendor/bundle yarn install make html open index.html ``` ### PDFのビルド フォントには[源真ゴシック (げんしんゴシック) | 自家製フォント工房](http://jikasei.me/font/genshin/ "源真ゴシック (げんしんゴシック) | 自家製フォント工房")を利用しています。 必要なもの * [源真ゴシック (げんしんゴシック) | 自家製フォント工房](http://jikasei.me/font/genshin/ "源真ゴシック (げんしんゴシック) | 自家製フォント工房") * Java ``` sh git submodule update --init make pdf open javascript-promise-book.pdf ``` ### Epubのビルド まだ完成度が高くないため品質はよくありません。 [HTML版](https://azu.github.io/promises-book/)はスマートフォン等画面が小さくても見られるようになっているためそちらの利用を推奨します。 ``` sh gem install specific_install gem specific_install -l https://github.com/asciidoctor/asciidoctor-epub3 asciidoctor-epub3 -D output index.adoc ``` ## Contributing Pull RequestやIssue等お気軽にどうぞ。 [![Gitter chat](https://badges.gitter.im/azu/promises-book.png)](https://gitter.im/azu/promises-book) に書き込むだけでも問題ないです。 Pull Requestする場合は [CONTRIBUTING.md](CONTRIBUTING.md "CONTRIBUTING.md") も参考にして下さい。 1. Fork it! 2. Create your feature branch: `git checkout -b my-new-feature` 3. Commit your changes: `git commit -am 'Add some feature'` 4. Push to the branch: `git push origin my-new-feature` 5. Submit a pull request :D ## License プログラムコードはMITライセンスで利用できます。 文章については<a rel="license" href="https://creativecommons.org/licenses/by-nc/4.0/">Creative Commons Attribution-NonCommercial</a>で利用できます。 <a rel="license" href="http://creativecommons.org/licenses/by-nc/4.0/"><img alt="クリエイティブ・コモンズ・ライセンス" style="border-width:0" src="http://i.creativecommons.org/l/by-nc/4.0/88x31.png" /></a>

E-book Management
1.4K Github Stars