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
引数
| 名前 | 型 | 説明 |
|---|---|---|
word | string | The word as it is written, such as 食べる or 形が合う. |
reading | string | 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出力(このページを作ったときに実行した結果)
この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。