Reference
Sentence difficulty
import { … } from "@johnmorrisdotca/hikidashi/difficulty";
0.3 kB minified and gzipped, with everything it imports (measured with esbuild)
難しさ: how hard an example sentence is to read, so the easiest one can lead.
A character like 水 appears in thousands of example sentences, and showing whichever one a database returned first hands a first-grader a sentence built from rare name kanji. Score each sentence once (when it is added, say) and the query is a plain sort.
Two things make a sentence hard: how long it is, and the hardest character in it. Length is the honest baseline, since a short sentence is readable even when every word is new, and the hardest kanji dominates, because one unknown character stops a learner as surely as ten do.
What a kanji costs comes from the school grade or the frequency rank you hold for it (KANJIDIC2 has both). The package carries no table of its own.
Exports
| Name | Kind | What it is |
|---|---|---|
kanjiCost | function | The cost of one kanji. |
KanjiDifficultySource | type | What your dictionary knows about a kanji, which kanjiCost turns into a cost. |
kanjiIn | function | Every kanji in the text, once each, in the order they appear. |
sentenceDifficulty | function | The sentence's score, lowest first: its length in characters plus three times its hardest kanji. |
UNKNOWN_KANJI_COST | constant | What a kanji costs when nothing is known about it: 20, the most any kanji costs. |