我有一个从 Ancestral Quest 导出的带有我的家谱的 GEDCOM 文件,它非常广泛,我想对其进行一些分析。我想构建一个树结构,并递归地探索它。
是否有任何库可以读取 GEDCOM 文件并创建树结构或某种类型的有向图?
您可以使用 python-gendom 解析文件并将其转换为 LightGraphs 的图形。随后 GraphPlot 可用于实际绘制绘图。
这是一个工作代码框架:
using PyCall
using Conda
using LightGraphs
run(`$(PyCall.python) -m pip install python-gedcom`)
gedcom = pyimport("gedcom")
gparser = pyimport("gedcom.parser")
gedcom_parser = gparser.Parser()
# download from "https://www.gedcom.org/samples/555SAMPLE.GED"
gedcom_parser.parse_file("c:/temp/555SAMPLE.GED")
g = SimpleDiGraph()
for el in gedcom_parser.get_root_child_elements()
display(el)
# todo populate graph g
# recursively iterate over tree
# see https://pypi.org/project/python-gedcom/ for more details how to read the data
end
# todo use GraphPlot to plot the graph