有条理的常识集合
commondata的Python项目详细描述
注:我们正在讨论这个包裹是否有意义。见 http://lino-framework.org/tickets/109.html
这个包是“公共数据”的核心,是 维护和共享结构化的公共知识。Python 包本身只包含一些utilities,并定义 commondata命名空间。它是像
- commondata.be: 比利时常识
- commondata.ee: 爱沙尼亚常识
- commondata.eg: 埃及常识
功能
在python中维护
python编程语言结合了两个特性
- 使其易于(或至少可能)被 非程序员
- 一种强大的后台编程语言
在GPL
下免费提供自由软件不应依赖于非自由材料。
设计用于进口
库不提供很多查询功能。只是 基本最小值,用于编写测试用例。这是个设计 选择。这些数据被导入到现有的系统中。 提供他们自己的查询工具。
安装
最简单的方法是键入:
pip install commondata.ee commondata.be
或者,您可能更喜欢使用开发版本:
$ git clone https://github.com/lsaffre/commondata.git $ git clone https://github.com/lsaffre/commondata-ee.git $ git clone https://github.com/lsaffre/commondata-be.git $ pip install -e commondata $ pip install -e commondata.ee $ pip install -e commondata.be
此文档的联机版本位于https://github.com/lsaffre/commondata
实用程序
如何使用place和placegenerator类。
为每个“类型”的位置定义一个子类:
>>> from commondata.utils import Place, PlaceGenerator >>> class PlaceInFoo(Place): ... def __str__(self): ... return self.name >>> class Kingdom(PlaceInFoo): ... value = 1 >>> class County(PlaceInFoo): ... value = 2 >>> class Borough(PlaceInFoo): ... value = 3 >>> class Village(PlaceInFoo): ... value = 3
placegenerator用于实例化以填充
第1部分:配置:
>>> pg = PlaceGenerator() >>> pg.install(Kingdom, County, Borough, Village) >>> pg.set_args('name')
第2部分:填写数据
>>> root = pg.kingdom("Kwargia") >>> def fill(pg): ... pg.county("Kwargia") ... pg.borough("Kwargia") ... pg.village("Virts") ... pg.village("Vinks") ... pg.county("Gorgia") ... pg.village("Girts") ... pg.village("Ginks")
>>> fill(pg)
第3部分:使用数据
>>> [str(x) for x in root.children] ['Kwargia', 'Gorgia'] >>> kwargia = root.children[0] >>> [str(x) for x in kwargia.children] ['Kwargia', 'Virts', 'Vinks']
多语言地名
使用commondata.utils.placegenerator.set_args()方法 指定后续位置字段的名称。
>>> pg = PlaceGenerator() >>> pg.install(Kingdom, County, Borough, Village) >>> pg.set_args('name name_ar') >>> root = pg.kingdom("Egypt", u'\u0645\u0635\u0631') >>> print(root.name_ar) مصر