Skip to content

Dict

dict

This module defines the dict_router of the Mirumoji API

Attributes:

Name Type Description
LOGGER Logger

Module's logging object

dict_router APIRouter

The FastAPI router object

AUDIO_MEDIA_TYPES = {'mp3': 'audio/mpeg', 'ogg': 'audio/ogg'} module-attribute

Maps a pronunciation clip's container format to its HTTP media type

analyze(sentence, mode=BundleMode.grammar) async

Tokenizes a sentence and enriches every stitched word with dictionary data

Slower than /dict/tokenize (one dictionary lookup per word). Intended for on-demand analysis rather than bulk rendering

Parameters:

Name Type Description Default
sentence str

The Japanese sentence to analyze

required
mode BundleMode

How aggressively to group tokens into words

grammar

Returns:

Type Description
list[EnrichedJapaneseWord]

A list of EnrichedJapaneseWord models, one per stitched word

Raises:

Type Description
FugashiError

If tokenization fails

KotobaseError

If a dictionary lookup fails

by_radicals(radicals, mode='all') async

Finds Kanji that contain one, or every one of the given radicals

Parameters:

Name Type Description Default
radicals str

The radical glyphs, concatenated or comma-separated (e.g. 言口 or 言,口)

required
mode Literal

When all, every one of radicals must be present in the kanji. When any, kanjis that contain at least one of radicals are matched

'all'

Returns:

Type Description
list[KanjiInfo]

The matching KanjiInfo models

Raises:

Type Description
HTTPException

400 when no radical glyphs are provided

KotobaseError

If the search fails

kanji(literal) async

Fetches the full profile of a single Kanji

Parameters:

Name Type Description Default
literal str

The Kanji literal

required

Returns:

Type Description
KanjiInfo

The KanjiInfo profile

Raises:

Type Description
HTTPException

404 when the Kanji is unknown

KotobaseError

If the lookup fails

kanji_audio(literal) async

Lists the pronunciation clips available for a Kanji (Kanji Alive)

The clips list is empty when the audio pack is not installed or the Kanji has no recorded clips

Parameters:

Name Type Description Default
literal str

The Kanji literal

required

Returns:

Type Description
KanjiAudio

The KanjiAudio clip listing

Raises:

Type Description
KotobaseError

If the lookup fails

kanji_audio_clip(literal, clip) async

Streams the raw bytes of one pronunciation clip

Parameters:

Name Type Description Default
literal str

The Kanji literal the clip belongs to

required
clip str

The clip id from the audio listing endpoint

required

Returns:

Type Description
Response

The audio bytes with the clip's media type

Raises:

Type Description
HTTPException

404 when no clip matches

KotobaseError

If the lookup fails

kanji_sentences(literal, limit=10) async

Lists example sentences that contain a Kanji

Parameters:

Name Type Description Default
literal str

The Kanji literal

required
limit int

Maximum number of sentences to return

10

Returns:

Type Description
list[Example]

The matching Example sentences with translations

Raises:

Type Description
KotobaseError

If the lookup fails

kanji_strokes(literal) async

Fetches a Kanji's stroke-order diagram as an SVG document (KanjiVG)

The SVG is self-contained, so the frontend can inline it and animate the stroke paths

Parameters:

Name Type Description Default
literal str

The Kanji literal

required

Returns:

Type Description
Response

The SVG document as image/svg+xml

Raises:

Type Description
HTTPException

404 when no stroke-order data exists for the Kanji

KotobaseError

If the lookup fails

kanji_words(literal, limit=50) async

Lists dictionary entries whose written form uses a Kanji

Parameters:

Name Type Description Default
literal str

The Kanji literal

required
limit int

Maximum number of entries to return

50

Returns:

Type Description
list[JMEntry]

The matching JMEntry models

Raises:

Type Description
KotobaseError

If the lookup fails

query(word, wildcard=False, reading=None, pos=None) async

Looks up dictionary data for a single word or a wildcard pattern

Token Hints
  • reading and pos are optional hints from tokenization

  • When provided, entries whose kana form matches the reading and whose part of speech matches the token rank first

  • Unknown written forms fall back to a lookup by reading

Parameters:

Name Type Description Default
word str

Word or wildcard pattern to look up

required
wildcard bool

When True, treat word as a wildcard pattern matching multiple words

False
reading str | None

The token's reading (any kana), when known

None
pos str | None

The token's UniDic top-level part of speech, when known

None

Returns:

Type Description
KotobaseData

The KotobaseData for the query

Raises:

Type Description
KotobaseError

If the lookup fails

radicals() async

Lists every search radical with its stroke count (RADKFILE)

Returns:

Type Description
list[RadicalInfo]

All search radicals

Raises:

Type Description
KotobaseError

If the lookup fails

resolve(ref) async

Resolves a sense cross-reference or antonym code into its entries

Parameters:

Name Type Description Default
ref str

The reference code from a sense's xrefs or antonyms

required

Returns:

Type Description
list[JMEntry]

The referenced JMEntry models

Raises:

Type Description
KotobaseError

If the resolution fails

search(q, limit=50) async

Searches dictionary entries by English meaning (reverse lookup)

Japanese word and wildcard searches go through /dict/query instead

Parameters:

Name Type Description Default
q str

The English search text

required
limit int

Maximum number of entries to return

50

Returns:

Type Description
list[JMEntry]

The matching JMEntry models

Raises:

Type Description
KotobaseError

If the search fails

tokenize(sentence, mode=BundleMode.grammar) async

Tokenizes a sentence into useful, stitched words (no dictionary lookups)

This is the fast path for rendering clickable text. Call /dict/analyze or /dict/query to fetch dictionary data for a word

Parameters:

Name Type Description Default
sentence str

The Japanese sentence to tokenize

required
mode BundleMode

How aggressively to group tokens into words

grammar

Returns:

Type Description
list[JapaneseWord]

A list of JapaneseWord models, one per stitched word

Raises:

Type Description
FugashiError

If tokenization fails

tokenize_batch(req) async

Tokenizes many sentences in one request (stitched words, no dict data)

Lets a client tokenize a whole subtitle file up front in a single call, so playback never tokenizes per-cue

Parameters:

Name Type Description Default
req TokenizeBatchRequest

The sentences to tokenize

required

Returns:

Type Description
list[list[JapaneseWord]]

One JapaneseWord list per input sentence, in the same order

Raises:

Type Description
FugashiError

If tokenization fails