跳转到主要内容

用于glottolog数据整理的Python包

项目描述

pyglottolog

通过编程访问Glottolog数据

Build Status Documentation Status PyPI

[!注意]
通过Glottolog CLDF数据集,以编程方式访问Glottolog数据变得容易得多。因此,pyglottolog现在主要作为内部数据整理工具。

安装

要安装pyglottolog,您需要在系统上安装Python,版本大于3.8。运行

pip install pyglottolog

这将安装命令行界面glottolog

注意:要使用pyglottolog,您还需要本地副本的Glottolog数据。这可以是

请确保您记住此本地数据副本的位置 - 您可能在使用pyglottolog时需要将此位置作为选项传递。

cldfbench提供了一个方便的方法来克隆数据存储库,保持其更新,并从pyglottolog访问它。有关详细信息,请参阅README

Python API

使用pyglottolog,可以从Python程序中通过编程方式访问Glottolog数据。所有功能都通过一个pyglottolog.Glottolog实例进行中介,例如。

>>> from pyglottolog import Glottolog
>>> glottolog = Glottolog('.')
>>> print(glottolog)
<Glottolog repos v0.2-259-g27ac0ef at /.../glottolog>

有关详细信息,请参阅readthedocs上的API文档

命令行界面

命令行功能是通过glottolog子命令实现的。可以通过运行来检查可用子命令的列表

$ glottolog -h
usage: glottolog [-h] [--log-level LOG_LEVEL] [--repos REPOS]
                 [--repos-version REPOS_VERSION]
                 COMMAND ...

optional arguments:
  -h, --help            show this help message and exit
  --log-level LOG_LEVEL
                        log level [ERROR|WARN|INFO|DEBUG] (default: 20)
  --repos REPOS         clone of glottolog/glottolog
  --repos-version REPOS_VERSION
                        version of repository data. Requires a git clone!
                        (default: None)

available commands:
  Run "COMAMND -h" to get help for a specific command.

  COMMAND
    create              Create a new languoid directory for a languoid
                        specified by name and level.
    edit                Open a languoid's INI file in a text editor.
    htmlmap             Create an HTML/Javascript map (using leaflet) of
                        Glottolog languoids.
    iso2codes           Map ISO codes to the list of all Glottolog languages
                        and dialects subsumed "under" it.
    langdatastats       List all metadata fields used in languoid INI files
                        and their frequency.
    langsearch          Search Glottolog languoids.
    languoids           Write languoids data to csv files
    refsearch           Search Glottolog references
    searchindex         Index
    show                Display details of a Glottolog object.
    tree                Print the classification tree starting at a specific
                        languoid.

提取语言数据

Glottolog数据通常与其他数据集成或作为工具中的参考数据,例如在CLDF数据集中的LanguageTable中。

为此,可以从glottolog/glottolog-cldf复制LanguageTable,或者可以使用glottologlanguoids子命令,该命令将基本语言数据输出到一个带有伴随元数据的CSVW文件中

glottolog languoids [--output=OUTDIR] [--version=VERSION]

这将创建一个CSVW包,即

  • CSV表glottolog-languoids-VERSION.csv
  • 和JSON描述glottolog-languoids-VERSION.csv-metadata.json

其中VERSION是在数据存储库上运行git describe的结果,或者在从存储库的导出或从ZENODO的下载上运行命令时作为--version=VERSION传递的版本字符串。

语言搜索

为了方便搜索所有语言信息文件,pyglottolog附带创建和搜索Whoosh索引的功能。要这样做,请运行

glottolog searchindex

这将花费几分钟(大约在配备SSD的较强大的笔记本电脑上为15分钟)并构建一个大小约为800 MB的索引,在build/

现在您可以搜索索引,例如使用替代名称作为查询

$ glottolog langsearch "Abipónok"
1 matches
Abipon [abip1241] language
languoids/tree/guai1249/guai1250/abip1241/md.ini
Abipónok [hu]

1 matches

但您也可以利用在pyglottolog.fts.get_langs_index中定义的模式;即使用查询中的字段

$ glottolog langsearch "country:PG"
...

Alamblak [alam1246] language
languoids/tree/sepi1257/sepi1258/east2496/alam1246/md.ini
Papua New Guinea (PG)

906 matches

$ glottolog --repos=. langsearch "iso:mal"
...

Malayalam [mala1464] language
languoids/tree/drav1251/sout3133/sout3138/tami1291/tami1292/tami1293/tami1294/tami1297/tami1298/mala1541/mala1464/md.ini

1 matches

参考文献搜索

对于参考数据也可以这样做:要创建包含所有参考数据的Whoosh索引,请运行

glottolog searchindex

现在您可以查询索引(使用模式中描述的字段)

$ glottolog refsearch "author:Haspelmath AND title:Atlas"
...
(13 matches)

项目详细信息


下载文件

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

源代码分发

pyglottolog-3.13.0.tar.gz (6.7 MB 查看哈希值)

上传时间 源代码

构建分发

pyglottolog-3.13.0-py2.py3-none-any.whl (6.7 MB 查看哈希值)

上传时间 Python 2 Python 3

支持