0.0.3 • Published 6 years ago

kujin v0.0.3

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

Kujin

npm version install size Build Status

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,
});
0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago