Skip to content

Commit 886b2c2

Browse files
authored
Merge pull request #37 from letuananh/main
jamdict 0.1a10 is ready on PyPI
2 parents 5754700 + f39c5a7 commit 886b2c2

File tree

7 files changed

+66
-106
lines changed

7 files changed

+66
-106
lines changed

jamdict/__version__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
__url__ = "https://github.com/neocl/jamdict"
1111
__maintainer__ = "Le Tuan Anh"
1212
__version_major__ = "0.1"
13-
__version__ = "{}a10.post2".format(__version_major__)
14-
__version_long__ = "{} - Alpha - Post 002".format(__version_major__)
15-
__status__ = "Prototype"
13+
__version__ = "{}a10".format(__version_major__)
14+
__version_long__ = "{} - Alpha 10".format(__version_major__)
15+
__status__ = "3 - Alpha"

jamdict/tools.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,12 @@ def show_info(cli, args):
180180
if not os.path.isdir(jamdict_home):
181181
jamdict_home += " [Missing]"
182182
output.print(f"JAMDICT_HOME : {jamdict_home}")
183-
data_pkg = 'Installed' if jamdict.util._JAMDICT_DATA_AVAILABLE else 'Not installed'
184-
output.print(f"jamdict_data package: {data_pkg}")
183+
if jamdict.util._JAMDICT_DATA_AVAILABLE:
184+
import jamdict_data
185+
data_pkg = f"version {jamdict_data.__version__} [OK]"
186+
else:
187+
data_pkg = "Not installed"
188+
output.print(f"jamdict-data : {data_pkg}")
185189
if args.config:
186190
_config_path = args.config + " [Custom]"
187191
if not os.path.isfile(args.config):

jamdict/util.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -212,19 +212,19 @@ def __init__(self, db_file=None, kd2_file=None,
212212
self.jmnedict_xml_file = jmnedict_xml_file if jmnedict_xml_file else config.get_file('JMNEDICT_XML') if auto_config else None
213213

214214
self.db_file = db_file if db_file else config.get_file('JAMDICT_DB') if auto_config else None
215-
if not self.db_file or not os.path.isfile(self.db_file):
215+
if not self.db_file or (self.db_file != ':memory:' and not os.path.isfile(self.db_file)):
216216
if _JAMDICT_DATA_AVAILABLE:
217217
self.db_file = jamdict_data.JAMDICT_DB_PATH
218218
elif self.jmd_xml_file and os.path.isfile(self.jmd_xml_file):
219219
getLogger().warning("JAMDICT_DB could NOT be found. Searching will be extremely slow. Please run `python3 -m jamdict import` first")
220220
self.kd2_file = kd2_file if kd2_file else self.db_file if auto_config else None
221-
if not self.kd2_file or not os.path.isfile(self.kd2_file):
221+
if not self.kd2_file or (self.kd2_file != ':memory:' and not os.path.isfile(self.kd2_file)):
222222
if _JAMDICT_DATA_AVAILABLE:
223223
self.kd2_file = None # jamdict_data.JAMDICT_DB_PATH
224224
elif self.kd2_xml_file and os.path.isfile(self.kd2_xml_file):
225225
getLogger().warning("Kanjidic2 database could NOT be found. Searching will be extremely slow. Please run `python3 -m jamdict import` first")
226226
self.jmnedict_file = jmnedict_file if jmnedict_file else self.db_file if auto_config else None
227-
if not self.jmnedict_file or not os.path.isfile(self.jmnedict_file):
227+
if not self.jmnedict_file or (self.jmnedict_file != ':memory:' and not os.path.isfile(self.jmnedict_file)):
228228
if _JAMDICT_DATA_AVAILABLE:
229229
self.jmnedict_file = None # jamdict_data.JAMDICT_DB_PATH
230230
elif self.jmnedict_xml_file and os.path.isfile(self.jmnedict_xml_file):
@@ -384,7 +384,7 @@ def has_jmne(self, ctx=None):
384384
''' Check if current database has jmne support '''
385385
if ctx is None:
386386
ctx = self.__make_db_ctx()
387-
m = ctx.meta.select_single('key=?', ('jmnedict.version',))
387+
m = ctx.meta.select_single('key=?', ('jmnedict.version',)) if ctx is not None else None
388388
return m is not None and len(m.value) > 0
389389

390390
def is_available(self):

jamdict_demo.py

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
33

4-
'''
4+
"""
55
Jamdict demo application
66
77
Latest version can be found at https://github.com/neocl/jamdict
@@ -17,14 +17,7 @@
1717
References:
1818
JMDict website:
1919
http://www.csse.monash.edu.au/~jwb/edict.html
20-
Python documentation:
21-
https://docs.python.org/
22-
PEP 257 - Python Docstring Conventions:
23-
https://www.python.org/dev/peps/pep-0257/
24-
25-
@author: Le Tuan Anh <tuananh.ke@gmail.com>
26-
@license: MIT
27-
'''
20+
"""
2821

2922
# Copyright (c) 2016, Le Tuan Anh <tuananh.ke@gmail.com>
3023
#

jamdol-flask.py

+3-20
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
33

4-
'''
4+
"""
55
jamdol - JAMDict OnLine (REST server)
66
Latest version can be found at https://github.com/neocl/jamdict
7-
8-
References:
9-
Python documentation:
10-
https://docs.python.org/
11-
PEP 257 - Python Docstring Conventions:
12-
https://www.python.org/dev/peps/pep-0257/
13-
14-
@author: Le Tuan Anh <tuananh.ke@gmail.com>
15-
'''
7+
"""
168

179
# Copyright (c) 2017, Le Tuan Anh <tuananh.ke@gmail.com>
1810
#
@@ -34,16 +26,6 @@
3426
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
3527
# THE SOFTWARE.
3628

37-
__author__ = "Le Tuan Anh <tuananh.ke@gmail.com>"
38-
__copyright__ = "Copyright 2017, jamdict"
39-
__credits__ = []
40-
__license__ = "MIT"
41-
__version__ = "0.1"
42-
__maintainer__ = "Le Tuan Anh"
43-
__email__ = "<tuananh.ke@gmail.com>"
44-
__status__ = "Prototype"
45-
46-
########################################################################
4729

4830
import json
4931
import logging
@@ -55,6 +37,7 @@
5537
from chirptext.cli import setup_logging
5638

5739
from jamdict import Jamdict
40+
from jamdict import __version__
5841

5942
# ---------------------------------------------------------------------
6043
# CONFIGURATION

setup.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def read(*filenames, **kwargs):
4545
"Bug Tracker": "https://github.com/neocl/jamdict/issues",
4646
"Source Code": "https://github.com/neocl/jamdict/"
4747
},
48-
keywords="nlp",
48+
keywords=['dictionary', 'japanese', 'kanji', 'japanese-language', 'jmdict', 'japanese-study', 'kanjidic2', 'japanese-dictionary', 'jamdict'],
4949
license=pkg_info['__license__'],
5050
author=pkg_info['__author__'],
5151
tests_require=requirements,
@@ -61,8 +61,9 @@ def read(*filenames, **kwargs):
6161
test_suite='test',
6262
# Reference: https://pypi.python.org/pypi?%3Aaction=list_classifiers
6363
classifiers=['Programming Language :: Python',
64-
'Development Status :: 2 - Pre-Alpha',
64+
'Development Status :: {}'.format(pkg_info['__status__']),
6565
'Natural Language :: Japanese',
66+
'Natural Language :: English',
6667
'Environment :: Plugins',
6768
'Intended Audience :: Developers',
6869
'License :: OSI Approved :: {}'.format(pkg_info['__license__']),

test/test_jamdict.py

+45-66
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ def test_jamdict_xml(self):
120120
print("Test Jamdict search in XML files")
121121
jam = Jamdict(jmd_xml_file=MINI_JMD, kd2_xml_file=MINI_KD2, auto_config=False)
122122
result = jam.lookup('おみやげ')
123-
self.assertEqual(len(result.entries), 1)
124-
self.assertEqual(len(result.chars), 2)
123+
self.assertEqual(1, len(result.entries))
124+
self.assertEqual(2, len(result.chars))
125125
self.assertEqual({c.literal for c in result.chars}, {'土', '産'})
126126

127127

@@ -179,70 +179,49 @@ def test_home_dir(self):
179179
os.environ['JAMDICT_HOME'] = _orig_home
180180

181181

182-
class TestJamdictSQLite(unittest.TestCase):
183-
184-
def test_jamdict_sqlite_all(self):
185-
if os.path.isfile(TEST_DB):
186-
os.unlink(TEST_DB)
187-
jam = Jamdict(db_file=TEST_DB, kd2_file=TEST_DB, jmnedict_file=TEST_DB, jmd_xml_file=MINI_JMD, kd2_xml_file=MINI_KD2, jmnedict_xml_file=MINI_JMNE)
188-
# Lookup using XML
189-
result = jam.jmdict_xml.lookup('おみやげ')
190-
getLogger().debug("Results: {}".format(result))
191-
# Lookup using SQLite
192-
jam.import_data()
193-
# test lookup
194-
result = jam.lookup('おみやげ')
195-
self.assertIsNotNone(result.entries)
196-
self.assertEqual(len(result.entries), 1)
197-
self.assertEqual(len(result.chars), 2)
198-
self.assertEqual({c.literal for c in result.chars}, {'土', '産'})
199-
200-
def test_memory_mode(self):
201-
if not os.path.isfile(TEST_DB):
202-
jam = Jamdict(db_file=TEST_DB, kd2_file=TEST_DB, jmnedict_file=TEST_DB, jmd_xml_file=MINI_JMD, kd2_xml_file=MINI_KD2, jmnedict_xml_file=MINI_JMNE)
203-
jam.import_data()
204-
print("Test reading DB into RAM")
205-
ram_jam = Jamdict(TEST_DB, memory_mode=True)
206-
print("1st lookup")
207-
result = ram_jam.lookup('おみやげ')
208-
self.assertIsNotNone(result.entries)
209-
self.assertEqual(len(result.entries), 1)
210-
self.assertEqual(len(result.chars), 2)
211-
self.assertEqual({c.literal for c in result.chars}, {'土', '産'})
212-
print("2nd lookup")
213-
result = ram_jam.lookup('おみやげ')
214-
self.assertIsNotNone(result.entries)
215-
self.assertEqual(len(result.entries), 1)
216-
self.assertEqual(len(result.chars), 2)
217-
self.assertEqual({c.literal for c in result.chars}, {'土', '産'})
218-
219-
def test_real_lookup(self):
220-
# test real lookup
221-
from chirptext.leutile import Timer
222-
t = Timer()
223-
ram_jam = Jamdict(memory_mode=True)
224-
print("1st lookup")
225-
t.start('Load DB into RAM')
226-
result = ram_jam.lookup('おみやげ')
227-
t.stop('Load DB into RAM')
228-
print(t)
229-
self.assertIsNotNone(result.entries)
230-
self.assertEqual(len(result.entries), 1)
231-
self.assertEqual(3, len(result.chars))
232-
print(result.chars)
233-
self.assertEqual({c.literal for c in result.chars}, {'土', '産', '御'})
234-
print("2nd lookup")
235-
result = ram_jam.lookup('おみやげ')
236-
self.assertIsNotNone(result.entries)
237-
self.assertEqual(len(result.entries), 1)
238-
self.assertEqual(3, len(result.chars))
239-
self.assertEqual({c.literal for c in result.chars}, {'土', '産', '御'})
240-
print("3rd lookup")
241-
result = ram_jam.lookup('おみやげ')
242-
self.assertIsNotNone(result.entries)
243-
self.assertEqual(len(result.entries), 1)
244-
self.assertEqual(3, len(result.chars))
245-
self.assertEqual({c.literal for c in result.chars}, {'土', '産', '御'})
182+
class TestJamdictSQLite(unittest.TestCase):
183+
184+
def test_jamdict_sqlite_all(self):
185+
if os.path.isfile(TEST_DB):
186+
os.unlink(TEST_DB)
187+
jam = Jamdict(db_file=TEST_DB, kd2_file=TEST_DB, jmnedict_file=TEST_DB,
188+
jmd_xml_file=MINI_JMD, kd2_xml_file=MINI_KD2, jmnedict_xml_file=MINI_JMNE)
189+
# Lookup using XML
190+
result = jam.jmdict_xml.lookup('おみやげ')
191+
getLogger().debug("Results: {}".format(result))
192+
# Lookup using SQLite
193+
jam.import_data()
194+
# test lookup
195+
result = jam.lookup('おみやげ')
196+
self.assertIsNotNone(result.entries)
197+
self.assertEqual(len(result.entries), 1)
198+
self.assertEqual(len(result.chars), 2)
199+
self.assertEqual({c.literal for c in result.chars}, {'土', '産'})
200+
201+
def test_memory_mode(self):
202+
if not os.path.isfile(TEST_DB):
203+
jam = Jamdict(db_file=TEST_DB, kd2_file=TEST_DB, jmnedict_file=TEST_DB, jmd_xml_file=MINI_JMD, kd2_xml_file=MINI_KD2, jmnedict_xml_file=MINI_JMNE)
204+
jam.import_data()
205+
print("Test reading DB into RAM")
206+
ram_jam = Jamdict(TEST_DB, memory_mode=True)
207+
print("1st lookup")
208+
result = ram_jam.lookup('おみやげ')
209+
self.assertIsNotNone(result.entries)
210+
self.assertEqual(len(result.entries), 1)
211+
self.assertEqual(len(result.chars), 2)
212+
self.assertEqual({c.literal for c in result.chars}, {'土', '産'})
213+
print("2nd lookup")
214+
result = ram_jam.lookup('おみやげ')
215+
self.assertIsNotNone(result.entries)
216+
self.assertEqual(len(result.entries), 1)
217+
self.assertEqual(len(result.chars), 2)
218+
self.assertEqual({c.literal for c in result.chars}, {'土', '産'})
219+
print("3rd lookup")
220+
result = ram_jam.lookup('おみやげ')
221+
self.assertIsNotNone(result.entries)
222+
self.assertEqual(len(result.entries), 1)
223+
self.assertEqual(2, len(result.chars))
224+
self.assertEqual({c.literal for c in result.chars}, {'土', '産'})
246225

247226

248227
########################################################################

0 commit comments

Comments
 (0)