项目作者: textlint-ja

项目描述 :
形態素解析結果のTokenベースの辞書でマッチするtextlintルール
高级语言: JavaScript
项目地址: git://github.com/textlint-ja/textlint-rule-morpheme-match.git
创建时间: 2018-12-22T02:14:49Z
项目社区:https://github.com/textlint-ja/textlint-rule-morpheme-match

开源协议:MIT License

下载


@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:

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

Usage

Via .textlintrc(Recommended)

  1. {
  2. "rules": {
  3. "@textlint-ja/morpheme-match": {
  4. "dictionaryPathList": ["./path/to/dictionary.js"]
  5. }
  6. }
  7. }

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に置換され、自動修正ができるようになります
  1. module.exports = [
  2. // ルール1
  3. {
  4. // https://azu.github.io/morpheme-match/?text=省略(することが可能)。
  5. message: `"することが可能$1"は冗長な表現です。"することが可能"を省き簡潔な表現にすると文章が明瞭になります。
  6. 参考: http://qiita.com/takahi-i/items/a93dc2ff42af6b93f6e0`,
  7. tokens: [
  8. {
  9. "surface_form": "する",
  10. "pos": "動詞",
  11. "pos_detail_1": "自立",
  12. "pos_detail_2": "*",
  13. "pos_detail_3": "*",
  14. "conjugated_type": "サ変・スル",
  15. "conjugated_form": "基本形",
  16. "basic_form": "する",
  17. "reading": "スル",
  18. "pronunciation": "スル"
  19. }, {
  20. "surface_form": "こと",
  21. "pos": "名詞",
  22. "pos_detail_1": "非自立",
  23. "pos_detail_2": "一般",
  24. "pos_detail_3": "*",
  25. "conjugated_type": "*",
  26. "conjugated_form": "*",
  27. "basic_form": "こと",
  28. "reading": "コト",
  29. "pronunciation": "コト"
  30. }, {
  31. "surface_form": "が",
  32. "pos": "助詞",
  33. "pos_detail_1": "格助詞",
  34. "pos_detail_2": "一般",
  35. "pos_detail_3": "*",
  36. "conjugated_type": "*",
  37. "conjugated_form": "*",
  38. "basic_form": "が",
  39. "reading": "ガ",
  40. "pronunciation": "ガ"
  41. }, {
  42. "surface_form": "可能",
  43. "pos": "名詞",
  44. "pos_detail_1": "形容動詞語幹",
  45. "pos_detail_2": "*",
  46. "pos_detail_3": "*",
  47. "conjugated_type": "*",
  48. "conjugated_form": "*",
  49. "basic_form": "可能",
  50. "reading": "カノウ",
  51. "pronunciation": "カノー"
  52. }, {
  53. "pos": "助動詞",
  54. "_capture": "$1"
  55. }
  56. ]
  57. },
  58. // ルール2
  59. {
  60. "message": "\"適用\"の誤用である可能性があります。適応 => 適用",
  61. "expected": "を適用",
  62. "tokens": [
  63. {
  64. "surface_form": "を",
  65. "pos": "助詞",
  66. "pos_detail_1": "格助詞",
  67. "pos_detail_2": "一般",
  68. "pos_detail_3": "*",
  69. "conjugated_type": "*",
  70. "conjugated_form": "*",
  71. "basic_form": "を",
  72. "reading": "ヲ",
  73. "pronunciation": "ヲ"
  74. },
  75. {
  76. "surface_form": "適応",
  77. "pos": "名詞",
  78. "pos_detail_1": "サ変接続",
  79. "pos_detail_2": "*",
  80. "pos_detail_3": "*",
  81. "conjugated_type": "*",
  82. "conjugated_form": "*",
  83. "basic_form": "適応",
  84. "reading": "テキオウ",
  85. "pronunciation": "テキオー"
  86. }
  87. ]
  88. }
  89. ];

参考

Changelog

See Releases page.

Running tests

Install devDependencies and Run npm test:

  1. 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