A Japanese language manipulation library
Project description
Mikan
Mikan is a Japanese language manipulation library.
import mikan
eat = mikan.IchidanVerb('食べる', 'たべる')
want_to_eat = eat.conjugate(mikan.VerbForm.TAI)
did_not_want_to_eat = want_to_eat.conjugate(mikan.AdjectiveForm.PAST, negative=True)
three_small_animals = mikan.Number(3) + mikan.Counter('匹', 'ひき')
cat = mikan.Word('猫', 'ねこ')
sentence = cat + 'が' + three_small_animals + did_not_want_to_eat + 'です'
reading = sentence.readings.pop()
print(sentence) # 猫が3匹食べたくなかったです
print(reading) # ねこがさんびきたべたくなかったです
print(mikan.to_romaji(reading)) # nekogasanbikitabetakunakattadesu
Motivation
I wanted to learn japanese, but it proved to be hard. So I wrote some Python app mixing a dictionary and a SRS system, with generated items (like inflected verbs), to help me. But the code became messy and hard to manage, so I moved the generation code into a Python library. I named it Mikan, because I like how the みかん hiragana looks like (though fruit names tends to be written with katakana...). Now I'm working on this library and my app is kind of stale. And I'm still not speaking japanese.
Words, writings and readings
In Mikan, most class classes inherits from the Word class. A word is a list of writings. Each writing can also be a reading.
For example:
import mikan
# create a word with three writings: 日本, にほん and にっぽん
# にほん and にっぽん are readings too
japan = mikan.Word('日本', 'にほん', 'にっぽん')
print(japan.writings) # ['日本', 'にほん', 'にっぽん']
print(japan.readings) # ['にほん', 'にっぽん']
Words can be combined to create compounds:
import mikan
japan = mikan.Word('日本', 'にほん')
cooking = mikan.Word('料理', 'りょうり')
japanese_cooking = japan + cooking
print(japanese_cooking.writings) # ['日本料理', 'にほん料理', '日本りょうり', 'にほんりょうり']
print(japanese_cooking.readings) # ['にほんりょうり']
Verbs
Mikan provides 5 verb classes:
GodanVerbfor class 1 verbsIchidanVerbfor class 2 verbsKuruVerbfor 来る (to come) and 来る-based compounds (ie: 持ってくる)SuruVerbfor する and する-verbs (ie: 勉強する)IkuVerbfor 行く and 行く-based compounds (ie: 持っていく)
Verbs have a conjugate method that returns the inflected form of a verb.
conjugate(forms, negative=False, polite=False)
The available verb forms are:
VerbForm.PRESENTVerbForm.PASTVerbForm.IMPERATIVEVerbForm.TE_FORMVerbForm.CONDITIONAL_EBAVerbForm.CONDITIONAL_RAVerbForm.PRESUMPTIVEVerbForm.VOLITIONALVerbForm.POTENTIALVerbForm.PASSIVEVerbForm.CAUSATIVEVerbForm.TAI
Adjectives
Mikan only has support for i-adjectives yet, available using the IAdjective class.
They have the same interface than verbs, with the following forms:
PRESENTPASTTE_FORMADVERB
Numbers
Numbers are created with the Number and can be created from python integers or from kanjis:
import mikan
a1 = mikan.Number(42)
a2 = mikan.Number('四十二')
assert a1 == a2
Counters
Mikan includes a generic class Counter and some specific classes for reading exceptions:
DayHourCounterfor hours of day counter (よじ, くじ)MonthDayCounterfor days of month counter (ついたち, ふつか, ...)MonthCounterfor months counter (しがつ, しちがつ, ...)TsuCounterfor the generic つ counter (ひとつ, ふたつ, ...)
Combining numbers and counters produce the required reading changes:
import mikan
number = mikan.Number(1)
hon = mikan.Counter('本', 'ほん')
assert 'いっぽん' in (number + hon).readings
Datetime
Mikan has a wrapper for Python datetime.date class:
import datetime
import mikan
mikan_date = mikan.Date(datetime.date(year=2020, month=3, day=16))
print(mikan_date) # 2020年3月16日
Romaji
Some functions are provided to convert between romaji and kana:
to_romajiconverts string in kana to romaji/hepburnto_hiraganaconverts string in romaji/hepburn to hiraganato_katakanaconverts string in romaji/hepburn to katakana
import mikan
friday = mikan.to_romaji('きんようび')
kinyoubi = mikan.to_hiragana(friday)
print(friday) # kin'youbi
print(kinyoubi) # きんようび
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mikan-0.2.0.tar.gz.
File metadata
- Download URL: mikan-0.2.0.tar.gz
- Upload date:
- Size: 16.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2a7f9ee58fbb830eff6763a389a13f399942b663d1b9547db66599fc36484d66
|
|
| MD5 |
5dab523470ee3438ab8aa5c9df795109
|
|
| BLAKE2b-256 |
594f2b904c0a657995d6410e5ff74f0472d5925837591a3ffd3324934ae026df
|
File details
Details for the file mikan-0.2.0-py3-none-any.whl.
File metadata
- Download URL: mikan-0.2.0-py3-none-any.whl
- Upload date:
- Size: 17.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
debb10c037014938a79bdac53ae390fac556b87df0f78b37e9958f7299abcebb
|
|
| MD5 |
6edae5311038becb6a30444fae8917f8
|
|
| BLAKE2b-256 |
06de0ee4961a835d3f71be286725d592ad49bb0aeca9c63828d02247d777b9ed
|