Skip to content

Commit

Permalink
[quickfix] fixed GEDCOM import for files where references to individu…
Browse files Browse the repository at this point in the history
…als are missing the leading I

Refactored slightly
  • Loading branch information
buske committed Nov 29, 2018
1 parent 89c898a commit 1156d08
Showing 1 changed file with 22 additions and 21 deletions.
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,28 +1314,20 @@ 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 {
// 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.
var fatherID = externalIDToID.hasOwnProperty(fatherLink)
? externalIDToID[fatherLink]
: externalIDToID[fatherLink.replace(/^@(\d+)/,"@I$1")];

if (fatherID == undefined) {
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 {
// FIXME: same quick fix as for the fatherID above
var motherID = externalIDToID.hasOwnProperty(motherLink)
? externalIDToID[motherLink]
: externalIDToID[motherLink.replace(/^@(\d+)/,"@I$1")];
var motherID = lookupNodeByReference(motherLink);

if (motherID == undefined) {
if (motherID === undefined) {
throw "Unable to import pedigree: mother link does not point to an existing individual: [" + motherLink + "]";
}
}
Expand All @@ -1337,19 +1342,15 @@ 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;

// FIXME: same quick fix as for motherID/fatherID
var childID = externalIDToID.hasOwnProperty(externalID)
? externalIDToID[externalID]
: externalIDToID[externalID.replace(/^@(\d+)/,"@I$1")];
var childID = lookupNodeByReference(externalID);

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

0 comments on commit 1156d08

Please sign in to comment.