segmentWordfunction
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 it
import { segmentWord } from "@johnmorrisdotca/hikidashi/align";
Also exported from: @johnmorrisdotca/hikidashi
Definition
function segmentWord(word: string, reading: string): WordSegment[] | null
Parameters
| Name | Type | Description |
|---|---|---|
word | string | The word as it is written, such as 食べる or 形が合う. |
reading | string | Its reading in hiragana or katakana, such as たべる. |
Returns
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.
Examples
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' } ] nullWhat it prints (run when this page was built)