From 8deb83168c3e9ff0015f65d2ee62f6698405e13a Mon Sep 17 00:00:00 2001 From: Le Tuan Anh Date: Sat, 29 May 2021 16:49:57 +0800 Subject: [PATCH 1/3] add on_readings, kun_readings, and other_readings filter to kanji chars, readings are sorted to have on & kun readings in front --- jamdict/kanjidic2.py | 17 ++++++++++++++++- test/test_kanjidic2_sqlite.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/jamdict/kanjidic2.py b/jamdict/kanjidic2.py index 9841e1a..ded3669 100644 --- a/jamdict/kanjidic2.py +++ b/jamdict/kanjidic2.py @@ -445,13 +445,28 @@ def __repr__(self): def __str__(self): return repr(self) + @property + def on_readings(self): + return [r for r in self.readings if r.r_type == 'ja_on'] + + @property + def kun_readings(self): + return [r for r in self.readings if r.r_type == 'ja_kun'] + + @property + def other_readings(self): + return [r for r in self.readings if r.r_type not in('ja_kun', 'ja_on')] + def to_json(self): warnings.warn("to_json() is deprecated and will be removed in the next major release. Use to_dict() instead.", DeprecationWarning, stacklevel=2) return self.to_dict() def to_dict(self): - return {'readings': [r.to_dict() for r in self.readings], + sorted_readings = sorted(self.readings, + key=lambda x: x.r_type.startswith('ja_'), + reverse=True) + return {'readings': [r.to_dict() for r in sorted_readings], 'meanings': [m.to_dict() for m in self.meanings]} diff --git a/test/test_kanjidic2_sqlite.py b/test/test_kanjidic2_sqlite.py index 5a95d90..4d1069c 100644 --- a/test/test_kanjidic2_sqlite.py +++ b/test/test_kanjidic2_sqlite.py @@ -79,6 +79,34 @@ def test_xml2sqlite(self): self.assertTrue(c.rm_groups[0].readings) self.assertTrue(c.rm_groups[0].meanings) + def test_reading_order(self): + db = self.ramdb + with db.ctx() as ctx: + fv = self.xdb.kd2.file_version + dv = self.xdb.kd2.database_version + doc = self.xdb.kd2.date_of_creation + db.update_kd2_meta(fv, dv, doc, ctx) + metas = ctx.meta.select() + getLogger().debug("KanjiDic2 meta: {}".format(metas)) + for c in self.xdb: + db.insert_char(c, ctx) + c = db.get_char('持', ctx=ctx) + rmg = c.rm_groups[0] + self.assertEqual(["ジ"], [x.value for x in rmg.on_readings]) + self.assertEqual(['も.つ', '-も.ち', 'も.てる'], [k.value for k in rmg.kun_readings]) + self.assertEqual([('chi2', 'pinyin'), ('ji', 'korean_r'), ('지', 'korean_h'), ('Trì', 'vietnam')], + [(x.value, x.r_type) for x in rmg.other_readings]) + expected = [{'type': 'ja_on', 'value': 'ジ', 'on_type': '', 'r_status': ''}, + {'type': 'ja_kun', 'value': 'も.つ', 'on_type': '', 'r_status': ''}, + {'type': 'ja_kun', 'value': '-も.ち', 'on_type': '', 'r_status': ''}, + {'type': 'ja_kun', 'value': 'も.てる', 'on_type': '', 'r_status': ''}, + {'type': 'pinyin', 'value': 'chi2', 'on_type': '', 'r_status': ''}, + {'type': 'korean_r', 'value': 'ji', 'on_type': '', 'r_status': ''}, + {'type': 'korean_h', 'value': '지', 'on_type': '', 'r_status': ''}, + {'type': 'vietnam', 'value': 'Trì', 'on_type': '', 'r_status': ''}] + actual = c.rm_groups[0].to_dict()['readings'] + self.assertEqual(expected, actual) + # ------------------------------------------------------------------------------- # Main From eeef8f923640236e768bb40f5e0339d5e4ecf538 Mon Sep 17 00:00:00 2001 From: Le Tuan Anh Date: Sun, 30 May 2021 16:02:08 +0800 Subject: [PATCH 2/3] jamdict 0.1a11.post1 is ready --- docs/updates.rst | 5 +++++ jamdict/__version__.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/updates.rst b/docs/updates.rst index c929edc..2dbd03c 100644 --- a/docs/updates.rst +++ b/docs/updates.rst @@ -14,6 +14,11 @@ jamdict 0.1a11 - Better version checking in ``__version__.py`` - Improved documentation +- 2021-05-29 + + - (.post1) Sorted kanji readings to have on & kun readings listed first + - (.post1) Add ``on_readings``, ``kun_readings``, and ``other_readings`` filter to ``kanjidic2.RMGroup`` + jamdict 0.1a10 -------------- diff --git a/jamdict/__version__.py b/jamdict/__version__.py index 19b5e74..0f67c23 100644 --- a/jamdict/__version__.py +++ b/jamdict/__version__.py @@ -13,7 +13,7 @@ # Version configuration (enforcing PEP 440) # ------------------------------------------------------------------------------ __status__ = "3 - Alpha" -__version_tuple__ = (0, 1, 0, 11) +__version_tuple__ = (0, 1, 0, 11, 1) __version_status__ = '' # a specific value ('rc', 'dev', etc.) or leave blank to be auto-filled # ------------------------------------------------------------------------------ __status_map__ = {'3 - Alpha': 'a', '4 - Beta': 'b', '5 - Production/Stable': '', '6 - Mature': ''} From 5c38b799aa543d4367b02a888739b16d70983c85 Mon Sep 17 00:00:00 2001 From: Le Tuan Anh Date: Tue, 1 Jun 2021 21:36:10 +0800 Subject: [PATCH 3/3] Update README.md --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 81f2bc7..e3c6367 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,12 @@ # Try Jamdict out -There is a demo Jamdict virtual machine to try out online on Repl.it: +Jamdict is used in [Jamdict-web](https://jamdict.herokuapp.com/) - a web-based free and open-source Japanese reading assistant software. +Please try out the demo instance online at: + +https://jamdict.herokuapp.com/ + +There also is a demo [Jamdict virtual machine](https://replit.com/@tuananhle/jamdict-demo) online for trying out Jamdict Python code on Repl.it: https://replit.com/@tuananhle/jamdict-demo @@ -191,4 +196,4 @@ See `jamdict_demo.py` and `jamdict/tools.py` for more information. - [alt-romes](https://github.com/alt-romes) - [Matteo Fumagalli](https://github.com/matteofumagalli1275) - [Reem Alghamdi](https://github.com/reem-codes) -- [Techno-coder](https://github.com/Techno-coder) \ No newline at end of file +- [Techno-coder](https://github.com/Techno-coder)