diff --git a/jamdict/__version__.py b/jamdict/__version__.py index 3f1993e..da3fa26 100644 --- a/jamdict/__version__.py +++ b/jamdict/__version__.py @@ -10,6 +10,6 @@ __url__ = "https://github.com/neocl/jamdict" __maintainer__ = "Le Tuan Anh" __version_major__ = "0.1" -__version__ = "{}a10.post2".format(__version_major__) -__version_long__ = "{} - Alpha - Post 002".format(__version_major__) -__status__ = "Prototype" +__version__ = "{}a10".format(__version_major__) +__version_long__ = "{} - Alpha 10".format(__version_major__) +__status__ = "3 - Alpha" diff --git a/jamdict/tools.py b/jamdict/tools.py index e6c8eb6..9ee028a 100755 --- a/jamdict/tools.py +++ b/jamdict/tools.py @@ -180,8 +180,12 @@ def show_info(cli, args): if not os.path.isdir(jamdict_home): jamdict_home += " [Missing]" output.print(f"JAMDICT_HOME : {jamdict_home}") - data_pkg = 'Installed' if jamdict.util._JAMDICT_DATA_AVAILABLE else 'Not installed' - output.print(f"jamdict_data package: {data_pkg}") + if jamdict.util._JAMDICT_DATA_AVAILABLE: + import jamdict_data + data_pkg = f"version {jamdict_data.__version__} [OK]" + else: + data_pkg = "Not installed" + output.print(f"jamdict-data : {data_pkg}") if args.config: _config_path = args.config + " [Custom]" if not os.path.isfile(args.config): diff --git a/jamdict/util.py b/jamdict/util.py index 178b74b..320e2f7 100644 --- a/jamdict/util.py +++ b/jamdict/util.py @@ -212,19 +212,19 @@ def __init__(self, db_file=None, kd2_file=None, self.jmnedict_xml_file = jmnedict_xml_file if jmnedict_xml_file else config.get_file('JMNEDICT_XML') if auto_config else None self.db_file = db_file if db_file else config.get_file('JAMDICT_DB') if auto_config else None - if not self.db_file or not os.path.isfile(self.db_file): + if not self.db_file or (self.db_file != ':memory:' and not os.path.isfile(self.db_file)): if _JAMDICT_DATA_AVAILABLE: self.db_file = jamdict_data.JAMDICT_DB_PATH elif self.jmd_xml_file and os.path.isfile(self.jmd_xml_file): getLogger().warning("JAMDICT_DB could NOT be found. Searching will be extremely slow. Please run `python3 -m jamdict import` first") self.kd2_file = kd2_file if kd2_file else self.db_file if auto_config else None - if not self.kd2_file or not os.path.isfile(self.kd2_file): + if not self.kd2_file or (self.kd2_file != ':memory:' and not os.path.isfile(self.kd2_file)): if _JAMDICT_DATA_AVAILABLE: self.kd2_file = None # jamdict_data.JAMDICT_DB_PATH elif self.kd2_xml_file and os.path.isfile(self.kd2_xml_file): getLogger().warning("Kanjidic2 database could NOT be found. Searching will be extremely slow. Please run `python3 -m jamdict import` first") self.jmnedict_file = jmnedict_file if jmnedict_file else self.db_file if auto_config else None - if not self.jmnedict_file or not os.path.isfile(self.jmnedict_file): + if not self.jmnedict_file or (self.jmnedict_file != ':memory:' and not os.path.isfile(self.jmnedict_file)): if _JAMDICT_DATA_AVAILABLE: self.jmnedict_file = None # jamdict_data.JAMDICT_DB_PATH elif self.jmnedict_xml_file and os.path.isfile(self.jmnedict_xml_file): @@ -384,7 +384,7 @@ def has_jmne(self, ctx=None): ''' Check if current database has jmne support ''' if ctx is None: ctx = self.__make_db_ctx() - m = ctx.meta.select_single('key=?', ('jmnedict.version',)) + m = ctx.meta.select_single('key=?', ('jmnedict.version',)) if ctx is not None else None return m is not None and len(m.value) > 0 def is_available(self): diff --git a/jamdict_demo.py b/jamdict_demo.py index e57ed5d..4949ee0 100755 --- a/jamdict_demo.py +++ b/jamdict_demo.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -''' +""" Jamdict demo application Latest version can be found at https://github.com/neocl/jamdict @@ -17,14 +17,7 @@ References: JMDict website: http://www.csse.monash.edu.au/~jwb/edict.html - Python documentation: - https://docs.python.org/ - PEP 257 - Python Docstring Conventions: - https://www.python.org/dev/peps/pep-0257/ - -@author: Le Tuan Anh -@license: MIT -''' +""" # Copyright (c) 2016, Le Tuan Anh # diff --git a/jamdol-flask.py b/jamdol-flask.py index 287ab67..9da94ab 100755 --- a/jamdol-flask.py +++ b/jamdol-flask.py @@ -1,18 +1,10 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -''' +""" jamdol - JAMDict OnLine (REST server) Latest version can be found at https://github.com/neocl/jamdict - -References: - Python documentation: - https://docs.python.org/ - PEP 257 - Python Docstring Conventions: - https://www.python.org/dev/peps/pep-0257/ - -@author: Le Tuan Anh -''' +""" # Copyright (c) 2017, Le Tuan Anh # @@ -34,16 +26,6 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -__author__ = "Le Tuan Anh " -__copyright__ = "Copyright 2017, jamdict" -__credits__ = [] -__license__ = "MIT" -__version__ = "0.1" -__maintainer__ = "Le Tuan Anh" -__email__ = "" -__status__ = "Prototype" - -######################################################################## import json import logging @@ -55,6 +37,7 @@ from chirptext.cli import setup_logging from jamdict import Jamdict +from jamdict import __version__ # --------------------------------------------------------------------- # CONFIGURATION diff --git a/setup.py b/setup.py index 37f935c..74a82f6 100644 --- a/setup.py +++ b/setup.py @@ -45,7 +45,7 @@ def read(*filenames, **kwargs): "Bug Tracker": "https://github.com/neocl/jamdict/issues", "Source Code": "https://github.com/neocl/jamdict/" }, - keywords="nlp", + keywords=['dictionary', 'japanese', 'kanji', 'japanese-language', 'jmdict', 'japanese-study', 'kanjidic2', 'japanese-dictionary', 'jamdict'], license=pkg_info['__license__'], author=pkg_info['__author__'], tests_require=requirements, @@ -61,8 +61,9 @@ def read(*filenames, **kwargs): test_suite='test', # Reference: https://pypi.python.org/pypi?%3Aaction=list_classifiers classifiers=['Programming Language :: Python', - 'Development Status :: 2 - Pre-Alpha', + 'Development Status :: {}'.format(pkg_info['__status__']), 'Natural Language :: Japanese', + 'Natural Language :: English', 'Environment :: Plugins', 'Intended Audience :: Developers', 'License :: OSI Approved :: {}'.format(pkg_info['__license__']), diff --git a/test/test_jamdict.py b/test/test_jamdict.py index 2e1a2a9..f7c1064 100644 --- a/test/test_jamdict.py +++ b/test/test_jamdict.py @@ -120,8 +120,8 @@ def test_jamdict_xml(self): print("Test Jamdict search in XML files") jam = Jamdict(jmd_xml_file=MINI_JMD, kd2_xml_file=MINI_KD2, auto_config=False) result = jam.lookup('おみやげ') - self.assertEqual(len(result.entries), 1) - self.assertEqual(len(result.chars), 2) + self.assertEqual(1, len(result.entries)) + self.assertEqual(2, len(result.chars)) self.assertEqual({c.literal for c in result.chars}, {'土', '産'}) @@ -179,70 +179,49 @@ def test_home_dir(self): os.environ['JAMDICT_HOME'] = _orig_home -class TestJamdictSQLite(unittest.TestCase): - - def test_jamdict_sqlite_all(self): - if os.path.isfile(TEST_DB): - os.unlink(TEST_DB) - 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) - # Lookup using XML - result = jam.jmdict_xml.lookup('おみやげ') - getLogger().debug("Results: {}".format(result)) - # Lookup using SQLite - jam.import_data() - # test lookup - result = jam.lookup('おみやげ') - self.assertIsNotNone(result.entries) - self.assertEqual(len(result.entries), 1) - self.assertEqual(len(result.chars), 2) - self.assertEqual({c.literal for c in result.chars}, {'土', '産'}) - - def test_memory_mode(self): - if not os.path.isfile(TEST_DB): - 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) - jam.import_data() - print("Test reading DB into RAM") - ram_jam = Jamdict(TEST_DB, memory_mode=True) - print("1st lookup") - result = ram_jam.lookup('おみやげ') - self.assertIsNotNone(result.entries) - self.assertEqual(len(result.entries), 1) - self.assertEqual(len(result.chars), 2) - self.assertEqual({c.literal for c in result.chars}, {'土', '産'}) - print("2nd lookup") - result = ram_jam.lookup('おみやげ') - self.assertIsNotNone(result.entries) - self.assertEqual(len(result.entries), 1) - self.assertEqual(len(result.chars), 2) - self.assertEqual({c.literal for c in result.chars}, {'土', '産'}) - - def test_real_lookup(self): - # test real lookup - from chirptext.leutile import Timer - t = Timer() - ram_jam = Jamdict(memory_mode=True) - print("1st lookup") - t.start('Load DB into RAM') - result = ram_jam.lookup('おみやげ') - t.stop('Load DB into RAM') - print(t) - self.assertIsNotNone(result.entries) - self.assertEqual(len(result.entries), 1) - self.assertEqual(3, len(result.chars)) - print(result.chars) - self.assertEqual({c.literal for c in result.chars}, {'土', '産', '御'}) - print("2nd lookup") - result = ram_jam.lookup('おみやげ') - self.assertIsNotNone(result.entries) - self.assertEqual(len(result.entries), 1) - self.assertEqual(3, len(result.chars)) - self.assertEqual({c.literal for c in result.chars}, {'土', '産', '御'}) - print("3rd lookup") - result = ram_jam.lookup('おみやげ') - self.assertIsNotNone(result.entries) - self.assertEqual(len(result.entries), 1) - self.assertEqual(3, len(result.chars)) - self.assertEqual({c.literal for c in result.chars}, {'土', '産', '御'}) +class TestJamdictSQLite(unittest.TestCase): + + def test_jamdict_sqlite_all(self): + if os.path.isfile(TEST_DB): + os.unlink(TEST_DB) + 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) + # Lookup using XML + result = jam.jmdict_xml.lookup('おみやげ') + getLogger().debug("Results: {}".format(result)) + # Lookup using SQLite + jam.import_data() + # test lookup + result = jam.lookup('おみやげ') + self.assertIsNotNone(result.entries) + self.assertEqual(len(result.entries), 1) + self.assertEqual(len(result.chars), 2) + self.assertEqual({c.literal for c in result.chars}, {'土', '産'}) + + def test_memory_mode(self): + if not os.path.isfile(TEST_DB): + 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) + jam.import_data() + print("Test reading DB into RAM") + ram_jam = Jamdict(TEST_DB, memory_mode=True) + print("1st lookup") + result = ram_jam.lookup('おみやげ') + self.assertIsNotNone(result.entries) + self.assertEqual(len(result.entries), 1) + self.assertEqual(len(result.chars), 2) + self.assertEqual({c.literal for c in result.chars}, {'土', '産'}) + print("2nd lookup") + result = ram_jam.lookup('おみやげ') + self.assertIsNotNone(result.entries) + self.assertEqual(len(result.entries), 1) + self.assertEqual(len(result.chars), 2) + self.assertEqual({c.literal for c in result.chars}, {'土', '産'}) + print("3rd lookup") + result = ram_jam.lookup('おみやげ') + self.assertIsNotNone(result.entries) + self.assertEqual(len(result.entries), 1) + self.assertEqual(2, len(result.chars)) + self.assertEqual({c.literal for c in result.chars}, {'土', '産'}) ########################################################################