kujin

[![Build Status](https://travis-ci.com/shooontan/kujin

Kujin

Install

# npm
$ npm install kujin kuromoji

# or yarn
$ yarn add kujin kuromoji

Usage

const Kujin = require('kujin')

const kujin = Kujin();

(async () => {
  /**
   * [ [ '古池', 'や' ], [ '蛙', '飛び込む' ], [ '水', 'の', '音' ] ]
   **/
  const ku = await kujin.find('閑さや古池や蛙飛び込む水の音');
})();

Documents

Kujin Node

Kujin uses Node which extended kuromoji.js ipadic feature.

const node = {
  word_id: 189220,
  word_type: 'KNOWN',
  word_position: 8,
  surface_form: '句',
  pos: '名詞',
  pos_detail_1: '一般',
  pos_detail_2: '*',
  pos_detail_3: '*',
  conjugated_type: '*',
  conjugated_form: '*',
  basic_form: '句',
  reading: 'ク',
  pronunciation: 'ク',
  head: true,
  tail: true,
}

Kujin(options)

const kujin = Kujin({
  dicPath: 'path/to/dictionary/dir',
  noHeads: [node, node],
  noTails: [node],
  trims: [node],
  rule: [5, 7, 5],
});

dicPath : string

path to dictionary.

default: node_modules/kuromoji/dict

noHeads : Node[]

default:

noHeads: [
  {
    pos: '助詞',
  },
  {
    pos: '助動詞',
  },
  {
    pos: 'フィラー',
  },
]

noTails : Node[]

default:

noTails: [
  {
    pos: '動詞',
    conjugated_form: '未然形',
  },
  {
    pos: '接頭詞',
  },
]

trims : Node[]

Node filter. trims remove Nodes.

default:

trims: [
  {
    pos: '記号',
  },
  {
    pos: '名詞',
    surface_form: '!',
  },
  {
    pos: '名詞',
    surface_form: '?',
  },
  {
    pos: '名詞',
    surface_form: ')',
  },
]

rule : number[]

default: [5, 7, 5]

parse rule.

kujin.find(text, [options])

  • text : string
  • options : object
    • flat : boolean
      • default is false

find out Ku from text.

/**
 *  [ [ '古池', 'や' ], [ '蛙', '飛び込む' ], [ '水', 'の', '音' ] ]
 **/
const ku = await kujin.find('閑さや古池や蛙飛び込む水の音');


/**
 *  '古池や 蛙飛び込む 水の音'
 **/
const ku = await kujin.find('閑さや古池や蛙飛び込む水の音', {
  flat: true
});

kujin.findAll(text, [options])

  • text : string
  • optioins : object
    • flat : boolean
      • default is false

find out all Ku from text.

/**
 *  [
 *    [
 *      [ '古池', 'や' ], [ '蛙', '飛び込む' ], [ '水', 'の', '音' ]
 *    ],
 *    [
 *      [ '柿', 'く', 'へ', 'ば' ], [ '鐘', 'が', '鳴る', 'なり' ], [ '法隆寺' ]
 *    ]
 *  ]
 **/
const ku = await kujin.findAll('閑さや古池や蛙飛び込む水の音柿くへば鐘が鳴るなり法隆寺');

/**
 * [
 *  '古池や 蛙飛び込む 水の音',
 *  '柿くへば 鐘が鳴るなり 法隆寺'
 * ]
 **/
const ku = await kujin.findAll('さや古池や蛙飛び込む水の音柿くへば鐘が鳴るなり法隆寺', {
  flat: true,
});

HomePage

https://github.com/shooontan/kujin#readme

Repository

git+https://github.com/shooontan/kujin.git


上一篇:custom-guider
下一篇:@webpack-server-kit/express

相关推荐

暂无相关文章

公众号

欢迎 JavaScript 爱好者