用于分析、分析和操作gedcom文件的python模块。

python-gedcom的Python项目详细描述


python gedcom解析器

PyPIGitHub releaseBuild Status

用于分析、分析和操作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选项附加到pippip<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

禁用严格解析将允许解析器优雅地处理以下怪癖:

  • 不使用CONCCONT
  • 的多行字段
  • 处理不以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.

MethodParametersReturnsDescription
^{}Empties the element list and dictionary to cause ^{} and ^{} to return updated data
^{}^{} of ^{}Returns a list containing all elements from within the GEDCOM file
^{}^{} of ^{}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
^{}^{} of ^{}Returns a list of logical records in the GEDCOM file
^{}^{} file_path, ^{} strictOpens and parses a file, from the given file path, as GEDCOM 5.5 formatted data
^{}^{} individual^{}: (^{} date, ^{} place)Returns a list of marriages of an individual formatted as a tuple (^{} date, ^{} place)
^{}^{} individual^{} of ^{}Returns a list of marriage years (as integers) for an individual
^{}^{} individual, ^{} year^{}Checks if one of the marriage years of an individual matches the supplied year. Year is an integer.
^{}^{} individual, ^{} from_year, ^{} to_year^{}Check if one of the marriage years of an individual is in a given range. Years are integers.
^{}^{} individual, ^{} family_type = ^{}^{} of ^{}Return family elements listed for an individual
^{}^{} individual, ^{} ancestor_type = ^{}^{} of ^{}Return elements corresponding to ancestors of an individual
^{}^{} individual, ^{} parent_type = ^{}^{} of ^{}Return elements corresponding to parents of an individual
^{}^{} descendant, ^{} ancestor, ^{} = ^{}^{}Return path from descendant to ancestor
^{}^{} family, ^{} members_type = ^{}^{} of ^{}Return array of family members: individual, spouse, and children
^{}Write GEDCOM data to stdout
^{}^{} open_fileSave GEDCOM data to a file

Element

元素表示已分析的GEDCOM文件中的一行。

可以通过from gedcom.element.element import Element导入。

MethodParametersReturnsDescription
^{}^{}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
^{}^{} value^{}Sets the value of this element
^{}^{}Returns the value of this element including concatenations or continuations
^{}^{} value^{}Sets the value of this element, adding concatenation and continuation lines when necessary
^{}^{} of ^{}Returns the direct child elements of this element
^{}^{} tag, ^{} pointer = ^{}, ^{} value = ^{}^{}Creates and returns a new child element of this element
^{}^{} child^{}Adds a child element to this element
^{}^{}Returns the parent element of this element
^{}^{} parentAdds a parent element to this element. There's usually no need to call this method manually, ^{} calls it automatically.
^{}^{}DEPRECATED: As of version ^{} use ^{} method instead.
^{}^{} recursive = ^{}^{}Formats this element and optionally all of its sub-elements into a GEDCOM conform string

Casting an Element to a string will internally call the to_gedcom_string() method.

FamilyElement类(派生自Element

可以通过from gedcom.element.family import FamilyElement导入。

MethodParametersReturnsDescription
^{}^{}Checks if this element is an actual family

FileElement类(派生自Element

可以通过from gedcom.element.file import FileElement导入。

MethodParametersReturnsDescription
^{}^{}Checks if this element is an actual file

IndividualElement类(派生自Element

表示分析的GEDCOM文件中的人员。

可以通过from gedcom.element.individual import IndividualElement导入。

MethodParametersReturnsDescription
^{}^{}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
^{}^{}: (^{} given_name, ^{} surname)Returns an individual's names as a tuple: (^{} given_name, ^{} surname)
^{}^{} surname_to_match^{}Matches a string with the surname of an individual
^{}^{} given_name_to_match^{}Matches a string with the given names of an individual
^{}^{}Returns the gender of a person in string format
^{}^{}: (^{} date, ^{} place, ^{} sources)Returns the birth data of a person formatted as a tuple: (^{} date, ^{} place, ^{} sources)
^{}^{}Returns the birth year of a person in integer format
^{}^{}: (^{} date, ^{} place, ^{} sources)Returns the death data of a person formatted as a tuple: (^{} date, ^{} place, ^{} sources)
^{}^{}Returns the death year of a person in integer format
^{}^{}: (^{} date, ^{} place, ^{} sources)Returns the burial data of a person formatted as a tuple: (^{} date, ^{}list` sources)
^{}^{} of ^{}: (^{} date, ^{} place, ^{} sources)Returns a list of censuses of an individual formatted as tuples: (^{} date, ^{}list` sources)
^{}^{}Returns the date of when the person data was last changed formatted as a string
^{}^{}Returns the occupation of a person
^{}^{} year^{}Returns ^{} if the given year matches the birth year of this person
^{}^{} from_year, ^{} to_year^{}Checks if the birth year of an individual lies within the given range
^{}^{} year^{}Returns ^{} if the given year matches the death year of this person
^{}^{} from_year, ^{} to_year^{}Returns ^{} if the given year matches the death year of this person
^{}^{} criteria^{}Checks if this individual matches all of the given criteria. Full format for ^{}: ^{}

ObjectElement类(派生自Element

可以通过from gedcom.element.object import ObjectElement导入。

MethodParametersReturnsDescription
^{}^{}Checks if this element is an actual object

RootElement类(派生自Element

虚拟gedcom根元素,包含作为子级的所有逻辑记录。

地方发展

我建议使用pyenv进行本地开发。

运行测试

  1. 运行pip<version> install --no-cache-dir -r requirements.txt以安装依赖项
  2. 使用控制台中的toxtox)运行测试
    • 对于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)

将新包上载到pypi

  1. 运行pip<version> install --no-cache-dir -r requirements.txt以安装依赖项
  2. 运行python<version> setup.py sdist bdist_wheel生成分发存档文件
  3. 运行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 is https://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。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何将jaxb插件扩展与gradlejaxbplugin一起使用   java Hibernate列表<Object[]>到特定对象   java使用多态性显示arraylist的输出   java水平堆叠卡,带有一定偏移量   java错误:找不到符号方法liesInt()   java客户机/服务器文件收发中的多线程流管理   在java中可以基于访问重载方法吗?   包含空元素的java排序数组   swing Java按钮/网格布局   java BottomNavigationView getmaxitemcount   java空指针异常字符串生成器   java Xamarin升级导致“类文件版本错误52.0,应为50.0”错误   java我正在尝试打印它,而不只是对每一行进行println   Tomcat7中的java是否需要复制上下文。将xml转换为conf/Catalina/locahost以使其生效   带有注入服务的java REST端点在何处引发自定义WebServiceException?   在Java中使用GPS数据   java如何将JFreeChart ChartPanel导出到包含添加的CrosshairOverlay的图像对象?   内置Eclipse期间的Java 8堆栈溢出   java在GWT编译的JavaScript中如何表示BigDecimal