用于分析、分析和操作gedcom文件的python模块。
python-gedcom的Python项目详细描述
python gedcom解析器
用于分析、分析和操作gedcom文件的python模块。
GEDCOM文件包含祖先数据。解析器当前支持 GEDCOM 5.5格式,详细说明为here。
For the latest changes please have a look at the
CHANGELOG.md
file.The current development process can be tracked in the develop branch.
安装
模块可以通过pip安装。
运行pip<version> install python-gedcom
安装或pip<version> install python-gedcom --upgrade
升级到上载到PyPI repository的最新版本。
如果要使用python-gedcom
包的最新预发行版,
只需将--pre
选项附加到pip
:pip<version> install python-gedcom --pre
示例用法
For more examples: Please have a look at the test files found in the
tests/
directory.
成功安装后,您可以导入gedcom
包,并像这样使用:
fromgedcom.element.individualimportIndividualElementfromgedcom.parserimportParser# Path to your `.ged` filefile_path=''# Initialize the parsergedcom_parser=Parser()# Parse your filegedcom_parser.parse_file(file_path)root_child_elements=gedcom_parser.get_root_child_elements()# Iterate through all root child elementsforelementinroot_child_elements:# Is the `element` an actual `IndividualElement`? (Allows usage of extra functions such as `surname_match` and `get_name`.)ifisinstance(element,IndividualElement):# Get all individuals whose surname matches "Doe"ifelement.surname_match('Doe'):# Unpack the name tuple(first,last)=element.get_name()# Print the first and last name of the found individualprint(first+" "+last)
严格解析
像祖先和myheritage这样的大型站点(以及其他站点)并不总是生成格式完美的gedcom文件。 如果在解析过程中遇到错误,可以考虑禁用严格解析,这在默认情况下是启用的:
fromgedcom.parserimportParserfile_path=''# Path to your `.ged` filegedcom_parser=Parser()gedcom_parser.parse_file(file_path,False)# Disable strict parsing
禁用严格解析将允许解析器优雅地处理以下怪癖:
- 不使用
CONC
或CONT
的多行字段
- 处理不以crlf结尾的最后一行(
\r\n
)
参考
Note: At a later state the documentation may be outsourced into individual, automatically generated wiki pages. (Makes things a little bit easier.)
Parser
类
Parser
类表示实际的解析器。使用此类分析GEDCOM文件。
Note: May be imported via
from gedcom.parser import Parser
.
Method | Parameters | Returns | Description |
---|---|---|---|
^{ | Empties the element list and dictionary to cause ^{ | ||
^{ | ^{ | Returns a list containing all elements from within the GEDCOM file | |
^{ | ^{ | Returns a dictionary containing all elements, identified by a pointer, from within the GEDCOM file | |
^{ | ^{ | Returns a virtual root element containing all logical records as children | |
^{ | ^{ | Returns a list of logical records in the GEDCOM file | |
^{ | ^{ | Opens and parses a file, from the given file path, as GEDCOM 5.5 formatted data | |
^{ | ^{ | ^{ | Returns a list of marriages of an individual formatted as a tuple (^{ |
^{ | ^{ | ^{ | Returns a list of marriage years (as integers) for an individual |
^{ | ^{ | ^{ | Checks if one of the marriage years of an individual matches the supplied year. Year is an integer. |
^{ | ^{ | ^{ | Check if one of the marriage years of an individual is in a given range. Years are integers. |
^{ | ^{ | ^{ | Return family elements listed for an individual |
^{ | ^{ | ^{ | Return elements corresponding to ancestors of an individual |
^{ | ^{ | ^{ | Return elements corresponding to parents of an individual |
^{ | ^{ | ^{ | Return path from descendant to ancestor |
^{ | ^{ | ^{ | Return array of family members: individual, spouse, and children |
^{ | Write GEDCOM data to stdout | ||
^{ | ^{ | Save GEDCOM data to a file |
Element
类
元素表示已分析的GEDCOM文件中的一行。
可以通过from gedcom.element.element import Element
导入。
Method | Parameters | Returns | Description |
---|---|---|---|
^{ | ^{ | Returns the level of this element from within the GEDCOM file | |
^{ | ^{ | Returns the pointer of this element from within the GEDCOM file | |
^{ | ^{ | Returns the tag of this element from within the GEDCOM file | |
^{ | ^{ | Returns the tag of this element from within the GEDCOM file | |
^{ | ^{ | ^{ | Sets the value of this element |
^{ | ^{ | Returns the value of this element including concatenations or continuations | |
^{ | ^{ | ^{ | Sets the value of this element, adding concatenation and continuation lines when necessary |
^{ | ^{ | Returns the direct child elements of this element | |
^{ | ^{ | ^{ | Creates and returns a new child element of this element |
^{ | ^{ | ^{ | Adds a child element to this element |
^{ | ^{ | Returns the parent element of this element | |
^{ | ^{ | Adds a parent element to this element. There's usually no need to call this method manually, ^{ | |
^{ | ^{ | DEPRECATED: As of version ^{ | |
^{ | ^{ | ^{ | Formats this element and optionally all of its sub-elements into a GEDCOM conform string |
Casting an
Element
to a string will internally call theto_gedcom_string()
method.
FamilyElement
类(派生自Element
)
可以通过from gedcom.element.family import FamilyElement
导入。
Method | Parameters | Returns | Description |
---|---|---|---|
^{ | ^{ | Checks if this element is an actual family |
FileElement
类(派生自Element
)
可以通过from gedcom.element.file import FileElement
导入。
Method | Parameters | Returns | Description |
---|---|---|---|
^{ | ^{ | Checks if this element is an actual file |
IndividualElement
类(派生自Element
)
表示分析的GEDCOM文件中的人员。
可以通过from gedcom.element.individual import IndividualElement
导入。
Method | Parameters | Returns | Description |
---|---|---|---|
^{ | ^{ | Checks if this element is an actual individual | |
^{ | ^{ | Checks if this individual is deceased | |
^{ | ^{ | Checks if this element is a child of a family | |
^{ | ^{ | Checks if this individual is marked private | |
^{ | ^{ | Returns an individual's names as a tuple: (^{ | |
^{ | ^{ | ^{ | Matches a string with the surname of an individual |
^{ | ^{ | ^{ | Matches a string with the given names of an individual |
^{ | ^{ | Returns the gender of a person in string format | |
^{ | ^{ | Returns the birth data of a person formatted as a tuple: (^{ | |
^{ | ^{ | Returns the birth year of a person in integer format | |
^{ | ^{ | Returns the death data of a person formatted as a tuple: (^{ | |
^{ | ^{ | Returns the death year of a person in integer format | |
^{ | ^{ | Returns the burial data of a person formatted as a tuple: (^{ | |
^{ | ^{ | Returns a list of censuses of an individual formatted as tuples: (^{ | |
^{ | ^{ | Returns the date of when the person data was last changed formatted as a string | |
^{ | ^{ | Returns the occupation of a person | |
^{ | ^{ | ^{ | Returns ^{ |
^{ | ^{ | ^{ | Checks if the birth year of an individual lies within the given range |
^{ | ^{ | ^{ | Returns ^{ |
^{ | ^{ | ^{ | Returns ^{ |
^{ | ^{ | ^{ | Checks if this individual matches all of the given criteria. Full format for ^{ |
ObjectElement
类(派生自Element
)
可以通过from gedcom.element.object import ObjectElement
导入。
Method | Parameters | Returns | Description |
---|---|---|---|
^{ | ^{ | Checks if this element is an actual object |
RootElement
类(派生自Element
)
虚拟gedcom根元素,包含作为子级的所有逻辑记录。
地方发展
我建议使用pyenv进行本地开发。
运行测试
- 运行
pip<version> install --no-cache-dir -r requirements.txt
以安装依赖项 - 使用控制台中的tox(
tox
)运行测试- 对于Python2.7,运行
tox -e py27
(您需要安装Python2.7) - 对于python 3.4,运行
tox -e py34
(您需要安装python3.4) - 对于python 3.5,运行
tox -e py35
(您需要安装python3.5) - 对于Python3.6,运行
tox -e py36
(您需要安装Python3.6)
- 对于Python2.7,运行
将新包上载到pypi
- 运行
pip<version> install --no-cache-dir -r requirements.txt
以安装依赖项 - 运行
python<version> setup.py sdist bdist_wheel
生成分发存档文件 - 运行
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
将存档文件上载到测试python包索引存储库
When the package is ready to be published to the real Python Package Index the
repository-url
ishttps://upload.pypi.org/legacy/
.
更改日志
请看一下^{
历史记录
此模块最初基于由 杨百翰大学的丹尼尔·扎帕拉(版权所有(c)2005),其中 在GPL v2下获得许可,然后由 Mad Price Ball2012年。
该项目于2018年由Nicklas Reincke接管。 与Damon Brodie一起进行了许多更改,并对解析器进行了优化。
许可证
根据GNU General Public License v2
授权python gedcom解析器
版权所有(c)2018 Damon Brodie(damon.brodie,gmail.com)
版权所有(c)2018-2019 Nicklas Reincke(请访问reynke.com)
版权所有(c)2016 Andreas Oberritter
版权所有(c)2012 Madeleine Price Ball
版权所有(c)2005 Daniel Zappala(Zappala at cs.byu.edu)
版权所有(c)2005杨百翰大学
此程序是免费软件;您可以重新分发和/或修改 根据由 自由软战争e foundation;许可证的版本2,或 (由您选择)任何更高版本。
这个程序的发布是希望它能有用, 但没有任何保证;甚至没有 适销性或适合某一特定目的的适销性。见 GNU通用公共许可证了解更多详细信息。
你应该收到一份GNU通用公共许可证的副本 如果没有,请写信给自由软件基金会。 美国马萨诸塞州波士顿市富兰克林街51号,5楼,邮编:02110-1301。