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

morpheme-match

v2.0.4

Published

match function that match token(形態素解析) with sentence.

Downloads

235,128

Readme

morpheme-match

morpheme-match provide match function that match token with sentence.

形態素解析したトークンを元に、文章にマッチするトークンが含まれているかをチェックするライブラリ。

Install

Install with npm:

npm install morpheme-match

Usage

createTokenMatcher(expectedTokens): function

createTokenMatcher() return function(token): { match: boolean, tokens?: Array, skipped? Array }.

We want to check "名詞かもしれない" contain "かも" token. Write following:

See example code with azu.github.io/morpheme-match/#名詞(かも)しれない.

import {createTokenMatcher} from "morpheme-match";
const matchToken = createTokenMatcher([
    {
        "surface_form": "かも",
        "pos": "助詞",
        "pos_detail_1": "副助詞",
        "pos_detail_2": "*",
        "pos_detail_3": "*",
        "conjugated_type": "*",
        "conjugated_form": "*",
        "basic_form": "かも",
        "reading": "カモ",
        "pronunciation": "カモ"
    }
]);
const tokens = [
    {
        "surface_form": "名詞",
        "pos": "名詞",
        "pos_detail_1": "一般",
        "pos_detail_2": "*",
        "pos_detail_3": "*",
        "conjugated_type": "*",
        "conjugated_form": "*",
        "basic_form": "名詞",
        "reading": "メイシ",
        "pronunciation": "メイシ"
    },
    // Hit!
    {
        "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": "ナイ"
    }
];
const result = tokens.some(token => {
    const {match} = matchToken(token);
    return match;
});
console.log(result);// true

If want to get matched token, write following:

let resultTokens = [];
const result = tokens.some(token => {
    const {match, tokens, skipped} = matchToken(token);
    resultTokens = tokens;
    return match;
});
console.log(resultTokens);
/*
[ { surface_form: 'かも',
    pos: '助詞',
    pos_detail_1: '副助詞',
    pos_detail_2: '*',
    pos_detail_3: '*',
    conjugated_type: '*',
    conjugated_form: '*',
    basic_form: 'かも',
    reading: 'カモ',
    pronunciation: 'カモ' } ]
*/

Tips

morpheme-matchは_から始まるキーを無視するため、メタ情報は_で書き込む事ができます。

const matchToken = createTokenMatcher([
    {
        "surface_form": "かも",
        "pos": "助詞",
        "pos_detail_1": "副助詞",
        "pos_detail_2": "*",
        "pos_detail_3": "*",
        "conjugated_type": "*",
        "conjugated_form": "*",
        "basic_form": "かも",
        "reading": "カモ",
        "pronunciation": "カモ",
        "_cature": "$1"
    }
]);

キー_skippabletrueの場合はマッチしない場合は無視されます。

const matchToken = createTokenMatcher([
    {
        "surface_form": "かも",
    },
    {
        "surface_form": "、",
        "_skippable": true,
    },
    {
        "surface_form": "しれ",
    },
]);

関連

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