Skip to content

API

api

This module defines the main kotobase API through the Kotobase class to make queries to the database and return data objects.

Kotobase

Stateless class that orchestrates the individual repositories and returns serialisable objects.

__call__(word, *, wildcard=False, include_names=False, sentence_limit=50, entry_limit=None)

Comprehensive word lookup.

Parameters:

Name Type Description Default
word str

The query string (kana, kanji) Supports SQL wildcards '*' or '%'.

required
wildcard bool

If True, passes wildcards through unchanged. If False, the search is exact (JMdict) but Tatoeba uses %word% containment.

False
include_names bool

Also query JMnedict (proper names). Can be slow on very broad wildcards.

False
sentence_limit int

Maximum number of Tatoeba sentences to fetch.

50
entry_limit int

Maximum number of entries to fetch.

None

Returns:

Name Type Description
LookupResult LookupResult

LookupResult Object.

db_info() staticmethod

Return a dictionary containing variables from Database build log file, if it exists.

Raises:

Type Description
EnvironmentError

If file doeesn't exist.

jlpt_level(word) staticmethod

Shortcut – just return JLPT vocab level for a word.

Parameters:

Name Type Description Default
word str

Word to search for.

required

Returns:

Name Type Description
int Optional[int]

The JLPT Level

kanji(literal) staticmethod

Return a single KanjiDTO (or None).

Parameters:

Name Type Description Default
literal str

Kanji Literal String.

required

Returns:

Name Type Description
KanjiDTO Optional[KanjiDTO]

Kanji data object

lookup(word, *, wildcard=False, include_names=False, sentence_limit=50, entry_limit=None)

Comprehensive word lookup.

Parameters:

Name Type Description Default
word str

The query string (kana, kanji) Supports SQL wildcards '*' or '%'.

required
wildcard bool

If True, passes wildcards through unchanged. If False, the search is exact (JMdict) but Tatoeba uses %word% containment.

False
include_names bool

Also query JMnedict (proper names). Can be slow on very broad wildcards.

False
sentence_limit int

Maximum number of Tatoeba sentences to fetch.

50
entry_limit int

Maximum number of entries to fetch.

None

Returns:

Name Type Description
LookupResult LookupResult

LookupResult Object.

sentences(text, *, limit=20) staticmethod

Fetch Japanese Tatoeba sentences containing text.

Parameters:

Name Type Description Default
text str

String text to search for

required
limit int

How many sentences to return.

20