本文へ移動

Hikidashi引き出し

和暦と漢数字の相互変換、活用した語の辞書形、漢字への読みの割り当て、貼り付けた文からの単語の抽出、文の難しさ。日本語のテキストを扱う小さな道具を集めた引き出しです。

「引き出し」という名前は、道具が一つずつしまってあり、必要なときに取り出して使える、という意味です。 名前について(英語)

目次

リファレンス · 読みの割り当て

segmentWord関数

リファレンスの説明と例は英語です。見出しと目次は日本語です。

A word cut into its kanji and its kana, each kanji run with its share of the reading.

The kana a word is written with are anchors in its reading: 形が合う read かたちがあう is 形 かたち, が, 合 あ, う. Kana that end a word after its kanji are its okurigana, which the writing half asks for in brackets. A katakana reading, or katakana in the word, reads the same as hiragana. A compound of several kanji (絵日記, えにっき) is one segment, since a reading cannot be split between kanji without a dictionary.

インポート

import { segmentWord } from "@johnmorrisdotca/hikidashi/align";

ほかのエクスポート元: @johnmorrisdotca/hikidashi

定義

function segmentWord(word: string, reading: string): WordSegment[] | null

引数

名前型説明
wordstring

The word as it is written, such as 食べる or 形が合う.

readingstring

Its reading in hiragana or katakana, such as たべる.

戻り値

WordSegment[] | null

The word's runs left to right, each with its share of the reading; null when the reading does not fit the word (so that a test can leave the word out rather than mark a wrong answer right), and for a word with no kanji, a reading with a space or control character in it, or a word or reading longer than ALIGN_LIMITS.

例

import { segmentWord } from "@johnmorrisdotca/hikidashi/align";

console.log(segmentWord("形が合う", "かたちがあう")?.map((part) => `${part.text}:${part.reading}:${part.kind}`));
console.log(segmentWord("絵日記", "エニッキ"), segmentWord("食べる", "のむ"));
[ '形:かたち:kanji', 'が:が:kana', '合:あ:kanji', 'う:う:okurigana' ]
[ { text: '絵日記', reading: 'えにっき', kind: 'kanji' } ] null

出力(このページを作ったときに実行した結果)

ソースを見るGitHub で編集@johnmorrisdotca/hikidashi 1.1.0 のソースから作成しました。

この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。