npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@textlint-ja/textlint-rule-morpheme-match

v2.0.0

Published

形態素解析結果のTokenベースの辞書でマッチするtextlintルール

Downloads

171

Readme

@textlint-ja/textlint-rule-morpheme-match Actions Status: test

形態素解析結果のTokenベースの辞書でマッチするtextlintルール。

kuromoji.js形態素解析のTokenを取得し、morpheme-match-textlintを使い辞書とTokenが一致しているかを判定しています。

textlint-rule-prhでは正規表現のマッチができますが、品詞の一致などは見れません。 textlint-rule-morpheme-matchは日本語を単語レベルでの一致でチェックするルールです。

Install

Install with npm:

npm install @textlint-ja/textlint-rule-morpheme-match

Usage

Via .textlintrc(Recommended)

{
    "rules": {
        "@textlint-ja/morpheme-match": {
            "dictionaryPathList": ["./path/to/dictionary.js"] 
        }
    }
}

Options

  • dictionaryPathList: string[]
    • 辞書ファイルへのファイルパスの配列
    • 例) /user/file/to/dict.js, ~/download/dict.js, ./path/to/dict.json などのファイルパス形式に対応しています

辞書ファイル

辞書ファイルは.jsまたは.json形式で記述できます。 1つの辞書ファイルには、複数のルールを含めることが可能です。

  • tokens: マッチするTokenのパターンを配列で記述します
    • それぞれのTokenに記述しているプロパティの一致を見ます
    • どのTokenでもいいワイルドカード的なものは{}(空のオブジェクト)を置くことで実現できます
    • Tokenについてはmorpheme-matchを参考にしてください
    • _captureというプロパティには、surface_formをキャプチャをする正規表現の変数を指定できます。
    • 記憶した変数はmessage$1のように指定すると、メッセージを出すときに置換されます
    • String.prototype.replace() | MDN
  • message: tokensにマッチした場合のエラーメッセージを記述します
  • expected: textlint --fixで自動的に修正する結果を記述します
    • tokensにマッチした箇所がexpectedに置換され、自動修正ができるようになります
module.exports = [
    // ルール1
    {
        // https://azu.github.io/morpheme-match/?text=省略(することが可能)。
        message: `"することが可能$1"は冗長な表現です。"することが可能"を省き簡潔な表現にすると文章が明瞭になります。
参考: http://qiita.com/takahi-i/items/a93dc2ff42af6b93f6e0`,
        tokens: [
            {
                "surface_form": "する",
                "pos": "動詞",
                "pos_detail_1": "自立",
                "pos_detail_2": "*",
                "pos_detail_3": "*",
                "conjugated_type": "サ変・スル",
                "conjugated_form": "基本形",
                "basic_form": "する",
                "reading": "スル",
                "pronunciation": "スル"
            }, {
                "surface_form": "こと",
                "pos": "名詞",
                "pos_detail_1": "非自立",
                "pos_detail_2": "一般",
                "pos_detail_3": "*",
                "conjugated_type": "*",
                "conjugated_form": "*",
                "basic_form": "こと",
                "reading": "コト",
                "pronunciation": "コト"
            }, {
                "surface_form": "が",
                "pos": "助詞",
                "pos_detail_1": "格助詞",
                "pos_detail_2": "一般",
                "pos_detail_3": "*",
                "conjugated_type": "*",
                "conjugated_form": "*",
                "basic_form": "が",
                "reading": "ガ",
                "pronunciation": "ガ"
            }, {
                "surface_form": "可能",
                "pos": "名詞",
                "pos_detail_1": "形容動詞語幹",
                "pos_detail_2": "*",
                "pos_detail_3": "*",
                "conjugated_type": "*",
                "conjugated_form": "*",
                "basic_form": "可能",
                "reading": "カノウ",
                "pronunciation": "カノー"
            }, {
                "pos": "助動詞",
                "_capture": "$1"
            }
        ]
    },
    // ルール2
    {
        "message": "\"適用\"の誤用である可能性があります。適応 => 適用",
        "expected": "を適用",
        "tokens": [
          {
            "surface_form": "を",
            "pos": "助詞",
            "pos_detail_1": "格助詞",
            "pos_detail_2": "一般",
            "pos_detail_3": "*",
            "conjugated_type": "*",
            "conjugated_form": "*",
            "basic_form": "を",
            "reading": "ヲ",
            "pronunciation": "ヲ"
          },
          {
            "surface_form": "適応",
            "pos": "名詞",
            "pos_detail_1": "サ変接続",
            "pos_detail_2": "*",
            "pos_detail_3": "*",
            "conjugated_type": "*",
            "conjugated_form": "*",
            "basic_form": "適応",
            "reading": "テキオウ",
            "pronunciation": "テキオー"
          }
        ]
    }
];

参考

Changelog

See Releases page.

Running tests

Install devDependencies and Run npm test:

npm i -d && npm test

Contributing

Pull requests and stars are always welcome.

For bugs and feature requests, please create an issue.

  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

License

MIT © azu