跳转到主要内容

UNIHAN CJK数据库的SQLAlchemy模型

项目描述

unihan-db · Python Package License Code Coverage

UNIHAN数据库的SQLAlchemy模型。cihai项目的组成部分。由unihan-etl提供支持。另请参阅:libUnihan

默认情况下,unihan-db会在XDG数据目录中创建一个SQLite数据库。您可以通过传递数据库URL到get_session来指定自定义数据库目标。

示例用法

#!/usr/bin/env python
"""Example for bootstrapping UNIHAN DB and print out a row."""
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_query = session.query(Unhn).order_by(func.random()).limit(1)

assert random_row_query is not None

random_row = random_row_query.first()

pprint.pprint(bootstrap.to_dict(random_row))

pprint.pprint(random_row.to_dict())  # type:ignore

运行

$ ./examples/01_bootstrap.py

输出

{'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': 'mǎ'}],
                'type': 'kHanyuPinyin'}],
'kMandarin': [{'char_id': '鎷', 'hans': 'mǎ', 'hant': 'mǎ', 'id': 23486}],
'ucn': 'U+93B7'}

开发

$ git clone https://github.com/cihai/unihan-etl.git
$ cd unihan-etl

启动您的环境并了解更多关于贡献的信息。我们在所有cihai项目中使用相同的约定/工具:pytestsphinxmypyrufftmuxp以及文件监视器辅助工具(例如entr(1))。

Python版本

  • 0.8.0:
    • 最后一个Python 3.7版本
    • 最后一个SQLAlchemy 1.3版本

更多信息

Docs Build Status

项目详情


下载文件

下载适合您平台的应用程序。如果您不确定要选择哪个,请了解更多关于安装包的信息。

源分发

unihan_db-0.15.0.tar.gz (40.8 kB 查看散列值)

上传时间

构建分发

unihan_db-0.15.0-py3-none-any.whl (11.8 kB 查看散列值)

上传时间 Python 3

支持者: