Package: mikan
MikanMikan is a Japanese language manipulation library.importmikaneat=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))# nekogasanbikitabetakunakattadesuMotivationI 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 readingsIn Mikan, most class classes inherits from theWordclass. A word is a list of writings. Each writing can also be a reading.For example:importmikan# create a word with three writings: 日本, にほん and にっぽん# にほん and にっぽん are readings toojapan=mikan.Word('日本','にほん','にっぽん')print(japan.writings)# ['日本', 'にほん', 'にっぽん']print(japan.readings)# ['にほん', 'にっぽん']Words can be combined to create compounds:importmikanjapan=mikan.Word('日本','にほん')cooking=mikan.Word('料理','りょうり')japanese_cooking=japan+cookingprint(japanese_cooking.writings)# ['日本料理', 'にほん料理', '日本りょうり', 'にほんりょうり']print(japanese_cooking.readings)# ['にほんりょうり']VerbsMikan 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 aconjugatemethod 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.TAIAdjectivesMikan only has support for i-adjectives yet, available using theIAdjectiveclass.They have the same interface than verbs, with the following forms:PRESENTPASTTE_FORMADVERBNumbersNumbers are created with theNumberand can be created from python integers or from kanjis:importmikana1=mikan.Number(42)a2=mikan.Number('四十二')asserta1==a2CountersMikan includes a generic classCounterand 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:importmikannumber=mikan.Number(1)hon=mikan.Counter('本','ほん')assert'いっぽん'in(number+hon).readingsDatetimeMikan has a wrapper for Pythondatetime.dateclass:importdatetimeimportmikanmikan_date=mikan.Date(datetime.date(year=2020,month=3,day=16))print(mikan_date)# 2020年3月16日RomajiSome 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 katakanaimportmikanfriday=mikan.to_romaji('きんようび')kinyoubi=mikan.to_hiragana(friday)print(friday)# kin'youbiprint(kinyoubi)# きんようび