Ejemplo n.º 1
0
    def __init__(self):
        super().__init__()

        self.c = Cihai()

        if not self.c.is_bootstrapped:  # download and install Unihan to db
            bootstrap_unihan(self.c.metadata)
            self.c.reflect_db()
Ejemplo n.º 2
0
def test_unihan_options(unihan_options, test_config_file):
    app = Cihai.from_file(test_config_file)
    bootstrap.bootstrap_unihan(app.metadata, unihan_options)
    assert 'Unihan' in app.metadata.tables
    assert app.metadata.tables['Unihan'].columns
    assert set(app.metadata.tables['Unihan'].columns.keys()) == \
        set(bootstrap.UNIHAN_FIELDS + ['ucn', 'char'])
    assert bootstrap.is_bootstrapped(app.metadata)
Ejemplo n.º 3
0
def test_reflect_db(tmpdb_file, unihan_options):
    c = Cihai({
        'database': {
            'url': 'sqlite:///{tmpdb_file}'.format(tmpdb_file=tmpdb_file)
        }
    })
    assert not c.is_bootstrapped
    bootstrap.bootstrap_unihan(c.metadata, unihan_options)
    assert not hasattr(c.base.classes, 'Unihan')
    c.reflect_db()
    assert hasattr(c.base.classes, 'Unihan')
Ejemplo n.º 4
0
#!/usr/bin/env python
# -*- coding: utf8 - *-

from __future__ import unicode_literals, print_function

from cihai.core import Cihai
from cihai.bootstrap import bootstrap_unihan

c = Cihai()
if not c.is_bootstrapped:  # download and install Unihan to db
    bootstrap_unihan(c.metadata)
    c.reflect_db()  # automap new table created during bootstrap

query = c.lookup_char('好')
glyph = query.first()
print("lookup for 好: %s" % glyph.kDefinition)

query = c.reverse_char('good')
print('matches for "good": %s ' % ', '.join([glph.char for glph in query]))