Exemple #1
0
def test_add_dataset():
    c = Cihai()
    c.add_dataset(SimplestDataset, namespace='simple')
    assert hasattr(c, 'simple')
    assert isinstance(c.simple, extend.Dataset)
    assert hasattr(c.simple, 'a_method')
    assert callable(c.simple.a_method)
    assert c.simple.a_method() == 'hi'
Exemple #2
0
def run():
    c = Cihai(unihan=False)

    c.add_dataset(MyDataset, namespace='moo')
    c.moo.bootstrap()

    print('Definitions exactly for 好', c.moo.givemedata('好'))

    print('Definitions matching with 你好:', ', '.join(c.moo.search('好')))

    print('Reverse definition with Good:', ', '.join(c.moo.backwards('Good')))
Exemple #3
0
def run():
    c = Cihai(unihan=False)

    c.add_dataset(MyDataset, namespace='moo')
    c.moo.bootstrap()

    print('Definitions exactly for 好', c.moo.givemedata('好'))

    print('Definitions matching with 你好:', ', '.join(c.moo.search('好')))

    print('Reverse definition with Good:', ', '.join(c.moo.backwards('Good')))
Exemple #4
0
def run(unihan_options={}):
    c = Cihai(unihan=False)
    c.add_dataset('cihai.data.unihan.dataset.Unihan', namespace='unihan')

    if not c.unihan.is_bootstrapped:  # download and install Unihan to db
        c.unihan.bootstrap(unihan_options)

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

    query = c.unihan.reverse_char('good')
    print('matches for "good": %s ' % ', '.join([glph.char for glph in query]))
Exemple #5
0
def test_add_dataset_unihan(unihan_options):
    c = Cihai()
    c.add_dataset(Unihan, namespace='unihan')
    assert hasattr(c, 'unihan')
    assert isinstance(c.unihan, extend.Dataset)

    c.unihan.sql

    c.unihan.bootstrap(options=unihan_options)
    U = c.sql.base.classes.Unihan

    first_glyph = (c.unihan.sql.session.query(U).filter(
        U.kDefinition.isnot(None)).first())

    char = first_glyph.char
    assert (c.unihan.lookup_char(
        char=char).first().kDefinition == first_glyph.kDefinition)

    assert (c.unihan.reverse_char(
        hints=[first_glyph.kDefinition]).first().char == char
            ), 'works with list of column value matches'

    assert (c.unihan.reverse_char(
        hints=first_glyph.kDefinition).first().char == char
            ), 'works with strings'

    c.unihan.add_plugin(UnihanVariants, 'variants')
    assert hasattr(c.unihan, 'variants')

    def variant_list(field):
        for char in c.unihan.with_fields(field):
            variants = []
            for var in char.untagged_vars(field):
                variants.append(var)
            yield (char, variants)

    result = {char: variants for (char, variants) in variant_list('kZVariant')}

    assert len(result.values()) > 0
    assert len(result.keys()) > 0