Attempt at creating SQLAlchemy models and a normalized SQLite db for UNIHAN
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
doc
examples
requirements
tests Run through black Aug 25, 2018
unihan_db
.coveragerc
.gitignore
.tmuxp.yaml
.travis.yml
CHANGES
LICENSE
MANIFEST.in
Makefile
Pipfile
README.rst
setup.cfg
setup.py
tox.ini

README.rst

unihan-db - database SQLAlchemy models for UNIHAN. Part of the cihai project. Powered by unihan-etl. See also: libUnihan.

Python Package Documentation Status Build Status Code Coverage License

By default, unihan-db creates a SQLite database in an XDG data directory. You can specify a custom database destination by passing a database url into get_session.

Example usage:

#!/usr/bin/env python
# -*- coding: utf8 - *-
from __future__ import unicode_literals

import pprint

from sqlalchemy.sql.expression import func

from unihan_db import bootstrap
from unihan_db.tables import Unhn

session = bootstrap.get_session()

bootstrap.bootstrap_unihan(session)

random_row = session.query(Unhn).order_by(
    func.random()
).limit(1).first()

pp = pprint.PrettyPrinter(indent=0)

pp.pprint(random_row.to_dict())

Run:

$ ./examples/01_bootstrap.py

Output:

{'char': '',
'kCantonese': [{'char_id': '', 'definition': 'maa5', 'id': 24035}],
'kDefinition': [],
'kHanYu': [{'char_id': '',
          'id': 24014,
          'locations': [{'character': 5,
                       'generic_indice_id': 24014,
                       'generic_reading_id': None,
                       'id': 42170,
                       'page': 4237,
                       'virtual': 0,
                       'volume': 6}],
          'type': 'kHanYu'}],
'kHanyuPinyin': [{'char_id': '',
                'id': 18090,
                'locations': [{'character': 5,
                             'generic_indice_id': None,
                             'generic_reading_id': 18090,
                             'id': 42169,
                             'page': 4237,
                             'virtual': 0,
                             'volume': 6}],
                'readings': [{'generic_reading_id': 18090,
                            'id': 26695,
                            'reading': ''}],
                'type': 'kHanyuPinyin'}],
'kMandarin': [{'char_id': '', 'hans': '', 'hant': '', 'id': 23486}],
'ucn': 'U+93B7'}