Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A quick fix for importing pedigrees from GEDCOM files with improper links #3

Open
wants to merge 3 commits into
base: 1.3.8-gene42
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions components/pedigree/resources/src/main/resources/pedigree/model/import.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,19 @@ define([

var relationshipTracker = new RelationshipTracker(newG, defaultEdgeWeight);

var createPersonNode = function(graph, attributes) {
return graph._addVertex( null, BaseGraph.TYPE.PERSON, attributes, graph.defaultPersonNodeWidth );
};

var lookupNodeByReference = function(reference) {
// FIXME: some applications produce a GEDCOM file where links have incorrect IDs,
// where a correct reference "@Ixxx@" is replaced by "@xxx@". So as a quick fix an attemptis made to either look up
// the proper ID, or the ID with an "I" pefix attached before the numeric part of the ID.
return externalIDToID.hasOwnProperty(reference)
? externalIDToID[reference]
: externalIDToID[reference.replace(/^@(\d+)/,"@I$1")];
};

// second pass (once all vertex IDs are known): process families & add edges
for (var i = 0; i < gedcom.families.length; i++) {
var nextFamily = gedcom.families[i];
Expand All @@ -1301,14 +1314,22 @@ define([

// create a virtual parent in case one of the parents is missing
if (fatherLink == null) {
var fatherID = newG._addVertex( null, BaseGraph.TYPE.PERSON, {"gender": "M", "comments": "unknown"}, newG.defaultPersonNodeWidth );
var fatherID = createPersonNode(newG, {"gender": "M", "comments": "unknown"});
} else {
var fatherID = externalIDToID[fatherLink];
var fatherID = lookupNodeByReference(fatherLink);

if (fatherID === undefined) {
throw "Unable to import pedigree: father link does not point to an existing individual: [" + fatherLink + "]";
}
}
if (motherLink == null) {
var motherID = newG._addVertex( null, BaseGraph.TYPE.PERSON, {"gender": "F", "comments": "unknown"}, newG.defaultPersonNodeWidth );
var motherID = createPersonNode(newG, {"gender": "F", "comments": "unknown"});
} else {
var motherID = externalIDToID[motherLink];
var motherID = lookupNodeByReference(motherLink);

if (motherID === undefined) {
throw "Unable to import pedigree: mother link does not point to an existing individual: [" + motherLink + "]";
}
}

// both motherID and fatherID are now given and represent valid existing nodes in the pedigree
Expand All @@ -1321,18 +1342,17 @@ define([

if (children == null) {
// create a virtual child
var childID = newG._addVertex( null, BaseGraph.TYPE.PERSON, {"gender": "U", "placeholder": true}, newG.defaultPersonNodeWidth );
var childID = createPersonNode(newG, {"gender": "U", "placeholder": true});
externalIDToID[childID] = childID;
children = [{"value": childID}];
// TODO: add "infertile by choice" property to the relationship
}

for (var j = 0; j < children.length; j++) {
var externalID = children[j].value;
var childID = lookupNodeByReference(externalID);

var childID = externalIDToID.hasOwnProperty(externalID) ? externalIDToID[externalID] : null;

if (childID == null) {
if (childID === undefined) {
throw "Unable to import pedigree: child link does not point to an existing individual: [" + externalID + "]";
}

Expand Down