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

analyze-desumasu-dearu

v5.0.1

Published

文の敬体(ですます調)、常体(である調)を解析

Downloads

160,686

Readme

analyze-desumasu-dearu Actions Status: test

文の敬体(ですます調)、常体(である調)を解析するライブラリ

形態素解析器としてkuromoji.jsを利用しています。

Installation

npm install analyze-desumasu-dearu

Usage

"use strict";
const isDearu = require("analyze-desumasu-dearu").isDearu;
const isDesumasu = require("analyze-desumasu-dearu").isDesumasu;
const analyze = require("analyze-desumasu-dearu").analyze;
const analyzeDearu = require("analyze-desumasu-dearu").analyzeDearu;
const analyzeDesumasu = require("analyze-desumasu-dearu").analyzeDesumasu;
const text = "昨日はいい天気であったのだが、今日は悪天候です。";
analyze(text).then(results => {
    console.log("==である==");
    console.log(results.filter(isDearu));
    console.log("==ですます==");
    console.log(results.filter(isDesumasu));
});

Result to

==である==
[ { type: '特殊・ダ',
    value: 'であった',
    surface: 'で',
    index: 7,
    token: 
     { word_id: 305030,
       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: 'デ' } },
  { type: '特殊・ダ',
    value: 'だが、',
    surface: 'だ',
    index: 12,
    token: 
     { word_id: 305000,
       word_type: 'KNOWN',
       word_position: 13,
       surface_form: 'だ',
       pos: '助動詞',
       pos_detail_1: '*',
       pos_detail_2: '*',
       pos_detail_3: '*',
       conjugated_type: '特殊・ダ',
       conjugated_form: '基本形',
       basic_form: 'だ',
       reading: 'ダ',
       pronunciation: 'ダ' } } ]
==ですます==
[ { type: '特殊・デス',
    value: 'です。',
    surface: 'です',
    index: 21,
    token: 
     { word_id: 305080,
       word_type: 'KNOWN',
       word_position: 22,
       surface_form: 'です',
       pos: '助動詞',
       pos_detail_1: '*',
       pos_detail_2: '*',
       pos_detail_3: '*',
       conjugated_type: '特殊・デス',
       conjugated_form: '基本形',
       basic_form: 'です',
       reading: 'デス',
       pronunciation: 'デス' } } ]

analyze(text, options): Promise.<AnalyzedResultObject[]>

textから敬体(ですます調)と常体(である調)を取り出した結果を返します

  • options
  • ignoreConjunction: 無視オプションを指定できます
/**
 * デフォルトのオプション値
 * @type {{ignoreConjunction: boolean}}
 */
const defaultOptions = {
    // 接続的な使い方を無視する
    // e.g.) 今日はいい天気であるが明日はどうなるかは分からない。
    ignoreConjunction: false
};
// AnalyzedResultObjectの配列
[{
    // 文体を含んだ内容 - なんとなくいい感じの部分までを繋げた文字列
    // e.g.) "です。"
    value: string,
    // 該当するtoken文字
    // e.g.) "です"
    surface: string,
    // textの先頭からの位置(start with 0)
    index: number,
    // kuromoji.jsのtokenオブジェクトそのもの https://github.com/takuyaa/kuromoji.js#api
    // surfaceやindexはこのtokenから算出
    token: AnalyzedToken
}]

analyzeDesumasu(text, options): Promise.<AnalyzedResultObject[]>

textに含まれる文の敬体(ですます調)を解析して、AnalyzedResultObjectの配列を返します。

内部的にはanalyze()を使っています。

/**
 * `text` の敬体(ですます調)について解析し、敬体(ですます調)のトークン情報を返します。
 * @param {string} text
 * @param {Object} options
 * @return {Promise.<AnalyzedResultObject[]>}
 */
export function analyzeDesumasu(text, options = defaultOptions) {
    return analyze(text, options).then(results => results.filter(isDesumasu));
}

analyzeDearu(text, options): Promise.<AnalyzedResultObject[]>

常体(である調)を解析してAnalyzedResultObjectの配列を返します

  • options
  • ignoreConjunction: 無視オプションを指定できます。
/**
 * デフォルトのオプション値
 * @type {{ignoreConjunction: boolean}}
 */
const defaultOptions = {
    // 接続的なであるの使い方を無視する
    // e.g.) 今日はいい天気であるが明日はどうなるかは分からない。
    ignoreConjunction: false
};

内部的にはanalyze()を使っています。

/**
 * `text` の常体(である調)について解析し、常体(である調)のトークン情報を返します。
 * @param {string} text
 * @param {Object} options
 * @return {Promise.<AnalyzedResultObject[]>}
 */
export function analyzeDearu(text, options = defaultOptions) {
    return analyze(text, options).then(results => results.filter(isDearu))
}

UseCase

以下のツールなどで利用しています。

Tests

npm test

Contributing

  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

Acknowledge

Thank for RedPen.