Skip to content

Commit

Permalink
Merge pull request #475 from se-sss/master
Browse files Browse the repository at this point in the history
More convenient output of Relationship calculator.
  • Loading branch information
Serg-Norseman authored Jul 3, 2023
2 parents 5cff68c + b316920 commit df9625d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ private void Solve()
} else if (kinsGraph.FindVertex(fRec2.XRef) == null) {
fResult = "These individuals have no common relatives.";
} else {
kinsGraph.SetTreeRoot(fRec1);
fResult = kinsGraph.GetRelationship(fRec2, true, GlobalOptions.Instance.ShortKinshipForm);
kinsGraph.SetTreeRoot(fRec2);
fResult = kinsGraph.GetRelationship(fRec1, true, GlobalOptions.Instance.ShortKinshipForm);
}
}
}
Expand Down
22 changes: 15 additions & 7 deletions projects/GKCore/GKCore/Kinships/KinshipsGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,12 @@ public string GetRelationship(GDMIndividualRecord targetRec, bool fullFormat = f
int great = 0;
int degree = 0;
GDMIndividualRecord src = null, tgt = null, prev_tgt = null;
string part, fullRel = "";
string relPart = "";

GDMIndividualRecord starting = null;

System.Collections.Generic.Stack<string> relPartsStack = new System.Collections.Generic.Stack<string>();

var edgesPath = fGraph.GetPath(target);
foreach (Edge edge in edgesPath) {
prev_tgt = tgt;
Expand Down Expand Up @@ -138,7 +140,7 @@ public string GetRelationship(GDMIndividualRecord targetRec, bool fullFormat = f
degree += deg;

if (finRel == RelationKind.rkUndefined && fullFormat) {
part = GetRelationPart(starting, src, prevRel, great, degree, shortForm);
relPart = GetRelationPart(starting, src, prevRel, great, degree, shortForm);
src = prev_tgt;

starting = prev_tgt;
Expand All @@ -148,8 +150,7 @@ public string GetRelationship(GDMIndividualRecord targetRec, bool fullFormat = f
prevprevRel = prevRel;
prevRel = RelationKind.rkNone;

if (fullRel.Length > 0) fullRel += ", ";
fullRel += part;
relPartsStack.Push(relPart);

finRel = KinshipsMan.FindKinship(prevprevRel, prevRel, curRel, out g, out deg);
great += g;
Expand All @@ -165,10 +166,17 @@ public string GetRelationship(GDMIndividualRecord targetRec, bool fullFormat = f
string relRes = GetRelationName(targetRec, finRel, great, degree, shortForm);
return relRes;
} else {
part = GetRelationPart(starting, tgt, finRel, great, degree, shortForm);
relPart = GetRelationPart(starting, tgt, finRel, great, degree, shortForm);

relPartsStack.Push(relPart);

if (fullRel.Length > 0) fullRel += ", ";
fullRel += part;
string fullRel = "";
while (relPartsStack.Count > 0){
fullRel += relPartsStack.Pop();
if (relPartsStack.Count != 0) {
fullRel += ", ";
}
}

return fullRel;
}
Expand Down

0 comments on commit df9625d

Please sign in to comment.