Skip to the content

Kotoba言葉

Load only the word lists you need, mark repeated letters correctly and play a daily or seeded word game.

Kotoba is the Japanese word for words. About the name

Contents

How-to

Shiritori, idioms, proverbs and compounds

Judge a word chain with house rules, and read and search the idiom, proverb and four-character compound lists.

Judge a word chain

Shiritori is the Japanese word chain: each word starts on the kana the last one ended on, and a word ending in ん loses, because no word starts on it.

import {playShiritori,shiritoriChoices,readShiritoriWords} from "@johnmorrisdotca/kotoba";
import {JA_SHIRITORI} from "@johnmorrisdotca/kotoba/shiritori-ja";
console.log(playShiritori(["さくら"],"らくだ"));
console.log(playShiritori(["さくら"],"いぬ"));
console.log(playShiritori(["さくら"],"らいおん"));
console.log(shiritoriChoices(readShiritoriWords(JA_SHIRITORI),["さくら"])[0]);
{ ok: true, loses: false, next: 'た' }
{ ok: false, why: 'wrong-start' }
{ ok: true, loses: true, next: null }
{ reading: 'らいげつ', word: '来月', meaning: 'next month' }

playShiritori takes the readings so far and the word now said. It returns where the word leaves the chain, that it loses, or why it was refused: wrong-start, repeated or not-kana. shiritoriChoices works over any words with a reading, so a game can chain the words one learner has met as easily as the whole list. No choices left is how a chain ends without a ん.

House rules

No two tables play alike, so two rules are options. The defaults are the forgiving ones, which keep a chain going from a small pool of words.

import {shiritoriHeadKey,shiritoriTailKey} from "@johnmorrisdotca/kotoba";
console.log(shiritoriHeadKey("がっこう"),shiritoriHeadKey("がっこう",{voicing:"kept"}));
console.log(shiritoriTailKey("コーヒー"),shiritoriTailKey("コーヒー",{longVowel:"before"}));
か が
い ひ

voicing says whether が chains from か ("ignored") or only from が ("kept"). longVowel says whether コーヒー chains on the vowel it lengthens, い ("vowel"), or on the kana before the mark, ひ ("before"). A small kana always reads as its large one.

Read and search the idioms

import {readIdioms,searchIdioms} from "@johnmorrisdotca/kotoba";
import {JA_IDIOMS} from "@johnmorrisdotca/kotoba/idioms-ja";
const idioms=readIdioms(JA_IDIOMS);
console.log(searchIdioms(idioms,"laurels")[0]);
console.log(idioms.filter((one)=>one.kind==="idiom"&&one.elementary).length);
{
  idiom: '胡坐をかく',
  reading: 'あぐらをかく',
  meaning: "to rest on one's laurels",
  meanings: [ "to rest on one's laurels", 'to be self-complacent' ],
  kind: 'idiom',
  kanji: [ '胡', '坐' ],
  elementary: false,
  common: false
}
622

Every row says whose judgement put it there. "idiom" is an entry JMdict itself marks idiomatic. "expression" is this package's own rule, for set phrases JMdict files as plain expressions: a body part, 気 or an animal, then a particle, then something said about it, with a meaning that says nothing about the thing itself. So 鼻が高い ("proud") is on the list and 手を洗う ("to wash one's hands") is not.

meaning is the first plain gloss of the sense that is the idiom, not of a literal sense before it, and meanings holds them all, because one alone can mislead. elementary says every kanji in the phrase is taught in Japanese elementary school, which is a fact about its kanji: nothing here is a school's list of idioms. Each list is its own entry point: to fetch one only when it is needed, await import("@johnmorrisdotca/kotoba/idioms-ja").

Read and search the proverbs and the four-character compounds

import {readSayings,searchSayings} from "@johnmorrisdotca/kotoba";
import {JA_PROVERBS} from "@johnmorrisdotca/kotoba/proverbs-ja";
import {JA_YOJIJUKUGO} from "@johnmorrisdotca/kotoba/yojijukugo-ja";
const proverbs=readSayings(JA_PROVERBS);
const compounds=readSayings(JA_YOJIJUKUGO);
console.log(searchSayings(proverbs,"monkey")[0]?.saying);
console.log(searchSayings(compounds,"two birds")[0]);
console.log(compounds.filter((one)=>one.elementary).length);
猿も木から落ちる
{
  saying: '一挙両得',
  reading: 'いっきょりょうとく',
  meaning: 'killing two birds with one stone',
  meanings: [ 'killing two birds with one stone', 'serving two ends' ],
  kanji: [ '一', '挙', '両', '得' ],
  elementary: true,
  common: false
}
656

Each is an entry point of its own, proverbs-ja and yojijukugo-ja, so a page fetches only the list it uses. They hold the entries JMdict marks as proverbs (929) and as four-character compounds, yojijukugo (1,832), each with its reading, its plain English glosses and the same elementary and common flags as an idiom. JMdict decides what is one: this package adds nothing and has no kind. An entry is left out when JMdict marks any of its senses vulgar, X-rated, sensitive or derogatory, and also when any gloss of it names sex or the sex trade, which JMdict does not always mark (朝雲暮雨, "sexual liaison"), because these lists turn up in children's games. The idioms follow the same rule (股を開く, 闇の女 and 籠の鳥 are not there), and so do the shiritori words, by their first sense (セックス, 売春 and 浮気 are not there). One function, scripts/children-bar.mjs, makes the call for every list, and the monthly JMdict refresh runs it. No list of words is perfect for children: a site for them should read the rows it shows.

Add your own words for your own site

The lists are plain data once they are read, so one way to fit them to a site is to keep using the package and lay your own rows over its list, in your site's code. The package stays as it is, and a new version still brings its new words.

import {readIdioms,searchIdioms,readShiritoriWords,shiritoriChoices} from "@johnmorrisdotca/kotoba";
import {JA_IDIOMS} from "@johnmorrisdotca/kotoba/idioms-ja";
import {JA_SHIRITORI} from "@johnmorrisdotca/kotoba/shiritori-ja";
const byPhrase=new Map(readIdioms(JA_IDIOMS).map((one)=>[one.idiom,one]));
const proud=byPhrase.get("鼻が高い");
if(proud)byPhrase.set(proud.idiom,{...proud,meaning:"proud of someone",meanings:["proud of someone"]});
byPhrase.set("胸を張る",{idiom:"胸を張る",reading:"むねをはる",meaning:"to hold one's head high",meanings:["to hold one's head high"],kind:"expression",kanji:["胸","張"],elementary:true,common:false});
const idioms=[...byPhrase.values()];
console.log(searchIdioms(idioms,"head high")[0]?.idiom);
const words=[...readShiritoriWords(JA_SHIRITORI),{reading:"らむね",word:"ラムネ",meaning:"a fizzy lemon drink"}];
console.log(shiritoriChoices(words,["さくら"]).some((one)=>one.word==="ラムネ"));
胸を張る
true

The idioms are held by their written form, so a row of your own replaces the list's row for the same phrase, and adds a phrase the list does not have. If a later version of the list gains that phrase, yours still stands and nothing is doubled. To take a phrase out, byPhrase.delete("…"). The shiritori words are one list joined to another. searchIdioms and shiritoriChoices take any rows, so nothing else in your code changes.

On a row you write, kind, kanji, elementary and common are your own statement, not this package's or JMdict's. The lists leave out what the last section names because they turn up in children's games; a site that is not for children may add such a phrase this way, and that choice is the site's. A row you write yourself is yours. A row you take from the list and reword is still made from JMdict, so it stays under the licence below and keeps its credit on the screen.

Where the words come from

Every list is made from JMdict, and elementary from KANJIDIC2, the property of the Electronic Dictionary Research and Development Group, under CC BY-SA 4.0 and the Group's conditions. A page that shows these words must say so on that screen; NOTICE.md has wording to use. Anything JMdict marks vulgar, X-rated, sensitive or derogatory, and anything whose gloss names sex or the sex trade, is left out, because these lists turn up in children's games.

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/kotoba 1.11.0.