Skip to content

Commit

Permalink
Merge pull request neocl#39 from letuananh/main
Browse files Browse the repository at this point in the history
version 0.1a11.post1 ready
  • Loading branch information
letuananh authored Jun 1, 2021
2 parents 21242da + 5c38b79 commit ec25056
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 4 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
- [Techno-coder](https://github.com/Techno-coder)
5 changes: 5 additions & 0 deletions docs/updates.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------------

Expand Down
2 changes: 1 addition & 1 deletion jamdict/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': ''}
Expand Down
17 changes: 16 additions & 1 deletion jamdict/kanjidic2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]}


Expand Down
28 changes: 28 additions & 0 deletions test/test_kanjidic2_sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ec25056

Please sign in to comment.