Page 1 of 1
Need Help with Expression to Print Sentence when Witness Role is Empty
Posted: 08 Jul 2022 21:23
by APerson
I currently struggling with an expression and can’t figure out how to deal with a situation. In addition to the help files, I also try to find other existing facts in FH7 to use as examples but can't seem to find one for this situation. (It would be VERY NICE if examples were given in the help files, although I realize that would take a lot of work.)
Specifically, I’ve been working on a fact to record Y-DNA matches (actually, it’s coming along quite nicely) but I’ve run into a problem. Let’s say I have two people who are match on their Y-DNA but we don’t know who their common ancestor is.
In recording “witnesses,” I assign the role “Common_Ancestor” to the correct individual if he is known. However, we don’t know who he is so the role is not used.
When there is no person assigned the role of common ancestor, I would like to have a sentence to be output as,
Their common ancestor is unknown.
I strongly suspect that I would use the function “IsEmpty” to examine if “Common_Ancestor” is empty. That would return “true” as data doesn’t exist for that role. Thus, I’d like the above statement to appear.
FYI, I am able to get a sentence to print when they do share a common ancestor; that expression is:
<Their common ancestor is {role=Common_Ancestor}>
I hope this is clear.
Thanks again for the great help.
Re: Need Help with Expression to Print Sentence when Witness Role is Empty
Posted: 09 Jul 2022 10:10
by tatewise
Hi Jeff.
Yes, the < chevron > conditional template only allows a true condition and does not support a false condition.
So you need the
=CombineText(...) function that is a workaround for scenarios where the < chevron > conditional template is not suitable. In this case, it is quite easy to use because you only have one Role defined for the DNA fact.
e.g.
Their common ancestor is {=CombineText("",%FACT._SHAR>%,"","unknown")}
If the shared Fact Witness exists then their name is displayed else "unknown" is displayed.
See the Help for
https://www.family-historian.co.uk/help ... etext.html that also refers to
CombineText_AB(...) function where the text depends on two conditional values.
The FHUG Knowledge Base does have examples for that function but because it is quite an advanced topic they are somewhat hidden in
Understanding Expressions under
Sentence Templates and in
Narrative Report Fact Sentence Templates in the
Birth & Baptism Events near the end.
Re: Need Help with Expression to Print Sentence when Witness Role is Empty
Posted: 09 Jul 2022 16:40
by APerson
Hi Mike,
Thanks for the help. Unfortunately, as I've worked through your suggestion and also looked at all of the help files (especially those you mentioned) it appears as if I wasn't clear. Your statement that
Yes, the < chevron > conditional template only allows a true condition and does not support a false condition.
Is exactly where I'm having the problem. However, I realized that part of the problem is that I do have more than one role for the DNA fact. Specifically, I have three:
- Y-DNA_Direct_Line_Ancestor
When no one has been assigned the role of Common_Ancestor (thus, returns a false condition) I want to print the sentence:
Their common ancestor is unknown.
Otherwise, I want the name of the common ancestor to appear instead of "unknown."
I’m trying to get the sentence to appear for the Y-DNA Match and Y-DNA_Direct_Line_Ancestor roles when their common ancestor is not known; otherwise, I want print his name.
FYI, the Y-DNA_Match role is used for those who have tested as positive matches on a commercial DNA test, and the Y-DNA_Direct_Line_Ancestor role is for those in the tree who are in a documented direct line between each Y-DNA Match and (if one is known), their common ancestor. (Y-DNA matches, by definition, share a common ancestor - as will an mtDNA match - so we can be quite certain, with documented evidence, when people in these lines are related). That's why I've included the Y-DNA_Direct_Line_Ancestor role.
Again, thank you for your great help. I hope I've explained this a bit more clearly. If nothing else, I'm learning a lot as I work through this challenge.
Re: Need Help with Expression to Print Sentence when Witness Role is Empty
Posted: 09 Jul 2022 17:20
by tatewise
Ok, so we need to test for the Role of Common_Ancestor by replacing %FACT._SHAR>% with an =ItemIf(...) function such as ItemIf( %FACT._SHAR.ROLE% = "Common_Ancestor", %FACT._SHAR>%, %FACT._SHAR[0]% )
That returns the Common_Ancestor reference %FACT._SHAR>% or the non-existent reference %FACT._SHAR[0]%
i.e. Sentence Template becomes:
Their common ancestor is {=CombineText( "", ItemIf( %FACT._SHAR.ROLE% = "Common_Ancestor", %FACT._SHAR>%, %FACT._SHAR[0]% ), "", "unknown" )}
But what if the Common_Ancestor is not the first Fact Witness? The ItemIf(...) function has to be nested:
ItemIf( %FACT._SHAR.ROLE% = "Common_Ancestor", %FACT._SHAR>%, ItemIf( %FACT._SHAR[2].ROLE% = "Common_Ancestor", %FACT._SHAR[2]>%, %FACT._SHAR[0]% ) )
That can be repeated enough times to ensure all instances of the Fact Witness are covered.
Just take care to ensure all parameters are valid and that parentheses ( ) are in nested pairs.
This illustrates the power of the {role=Common_Ancestor} that works out the possibilities discussed above.
Re: Need Help with Expression to Print Sentence when Witness Role is Empty
Posted: 10 Jul 2022 16:31
by APerson
Hi Again Mike,
I've been playing with your last suggestion since yesterday (I've spent hours on it) and think I must be suffering from analysis paralysis - I simply can't seem to wrap my head around your suggestion, especially the part that "the ItemIf(...) function has to be nested." I believe I understand why (as the position of each witness role on the list determines the output - which seems very odd to me). But I continue have problems getting the output I'm looking for. So, here's what I've done (I hope you'll be able to see where I've gone wrong). As I try to understand this, I've tried to dissect your suggestions (as well as what's on the help files). When I try your first suggestion
Their common ancestor is {=CombineText( "", ItemIf( %FACT._SHAR.ROLE% = "Common_Ancestor", %FACT._SHAR>%, %FACT._SHAR[0]% ), "", "unknown" )}
The output returns the name of the top person on the witness list, regardless of the role they were assigned. This occurs even when there is no one identified with the role Common_Ancestor. Therefore, I suspect that something may be wrong with this initial example.
When I have tried the next example, I used the following expression (note, I added =CombineText (...)); but something must be wrong. Anyway, here's the expression:
{=CombineText( "Their common ancestor is ", ItemIf( %FACT._SHAR.ROLE% = "Common_Ancestor", %FACT._SHAR>%, ItemIf( %FACT._SHAR[2].ROLE% = "Common_Ancestor", %FACT._SHAR[2]>%, %FACT._SHAR[0]% ) ), "", "unknown" ) }
Again, the output returns are not correct. For my testing purposes (so far), I've limited my witnesses to just three people:
For the first test, I assigned just two people to the role "Y-DNA_Match" - let's call them John Doe and Paul Smith. I did not assign anyone (yet) to the role "Common_Ancestor." When I examine the output, the following is returned:
When John Doe is the first person on the list of witnesses, the following is returned:
Their common ancestor is John Doe.
However, it should say,
Their common ancestor is unknown.
as there are no witnesses who have (yet) been assigned to that role.
When I move Paul Smith to the first person on the list, his name then appears instead of John Doe's, which is still not correct.
This leads me to believe that I've botched up the placement of some of the parentheses ( ) or I've botched up the expression and/or the parameters. Regardless, my efforts to fix this have failed.
For my next test, just see what would happen I added a third person, "Bill Williams," and assigned him to the "Common_Ancestor" role.
When Bill Williams is listed as the third person on the witness list, the output returns as:
Bill Williams Their common ancestor is John Doe.
This now seems to suggest that the parameters are wrong as now two names appear but the wrong person is displayed as the common ancestor. I really don't know. As I move Bill's position on the list, the names also change on the output (which is why, I presume, there's a need to nest the ItemIf(...) function.
Anyway, I'm still stuck. I really appreciate your help.
Re: Need Help with Expression to Print Sentence when Witness Role is Empty
Posted: 10 Jul 2022 17:32
by tatewise
Sorry, my mistake
The initial expression should have index [9] instead of [0] on the last FACT._SHAR data ref:
Their common ancestor is {=CombineText( "", ItemIf( %FACT._SHAR.ROLE% = "Common_Ancestor", %FACT._SHAR>%, %FACT._SHAR[9]% ), "", "unknown" )}
To cope with two Fcat Witnesses use:
Their common ancestor is {=CombineText( "", ItemIf( %FACT._SHAR.ROLE% = "Common_Ancestor", %FACT._SHAR>%, ItemIf( %FACT._SHAR.ROLE[2]% = "Common_Ancestor", %FACT._SHAR[2]>%, %FACT._SHAR[9]% ) ), "", "unknown" )}
To cope with three use:
Their common ancestor is {=CombineText( "", ItemIf( %FACT._SHAR.ROLE% = "Common_Ancestor", %FACT._SHAR>%, ItemIf( %FACT._SHAR.ROLE[2]% = "Common_Ancestor", %FACT._SHAR[2]>%, ItemIf( %FACT._SHAR.ROLE[2]% = "Common_Ancestor", %FACT._SHAR[2]>%, %FACT._SHAR[9]% ) ) ), "", "unknown" )}
Re: Need Help with Expression to Print Sentence when Witness Role is Empty
Posted: 10 Jul 2022 18:14
by APerson
tatewise wrote: ↑10 Jul 2022 17:32
Sorry, my mistake
Update: Oops, I think I see what going on (described below), the person who is the common ancestor MUST be in the top position on the list of roles. Then, everything works! You can ignore most of what I wrote below (except, you are a programming wizard)!
No problem! I was wondering as I couldn't get the first example to work

However,
you are clearly the master and found the solution immediately!!!
Thank you!!! BTW, it's been 20+ years since I had a course in programming, so many of my "skills" are limited - I'm usually good at botching things up!
I've just run both your examples with my test data and they work. However, when a someone is assigned to the "Common_Ancestor" role, the output returned does not include that person's name and continues to report that "The common ancestor is unknown," I suspect that is a relatively simple thing to correct using an additional conditional statement but wanted to mention it.
Also, I'm now going to add more witnesses, based on your model, by nesting more
ItemIf(...). Keeping my fingers crossed.
Again, you're amazing! Thanks!
Re: Need Help with Expression to Print Sentence when Witness Role is Empty
Posted: 10 Jul 2022 20:21
by tatewise
It is getting late here and a few typos have crept in.
This will cope with the Role of Common_Ancestor in any of the first three Fact Witnesses:
Their common ancestor is {=CombineText( "", ItemIf( %FACT._SHAR.ROLE% = "Common_Ancestor", %FACT._SHAR>%, ItemIf( %FACT._SHAR[2].ROLE% = "Common_Ancestor", %FACT._SHAR[2]>%, ItemIf( %FACT._SHAR[3].ROLE% = "Common_Ancestor", %FACT._SHAR[3]>%, %FACT._SHAR[9]% ) ) ), "", "unknown" )}
I suggest that when you add a Common_Ancestor they are moved up into the first three positions.
Re: Need Help with Expression to Print Sentence when Witness Role is Empty
Posted: 11 Jul 2022 04:15
by APerson
tatewise wrote: ↑10 Jul 2022 20:21
It is getting late here and a few typos have crept in.
This will cope with the Role of
Common_Ancestor in any of the first three Fact Witnesses:
No problem, it seems to be working very well! I've just spent the past couple of hours testing it with more fake data (I added a lot more witnesses). It's late here now and I'm going to call it a night. Anyway, I'm going to work with it a bit more tomorrow. Perhaps I'll make a YouTube video and show how this (and the two other DNA facts I'm working on) can be used. Of course, the fact for mtDNA is essentially identical to this one. I've got another one I've created for autosomal DNA and that seemed to be working but I will really need to go back and look at that again once I'm done with this current one. Also, when I'm ready, I'll try to post it so others can use it too.
Thanks!
Re: Need Help with Expression to Print Sentence when Witness Role is Empty
Posted: 11 Jul 2022 09:08
by tatewise
I've realised overnight that the expression can be simplified a little using just TextIf(...) functions:
Their common ancestor is {=TextIf( %FACT._SHAR.ROLE% = "Common_Ancestor", %FACT._SHAR>%, TextIf( %FACT._SHAR[2].ROLE% = "Common_Ancestor", %FACT._SHAR[2]>%, TextIf( %FACT._SHAR[3].ROLE% = "Common_Ancestor", %FACT._SHAR[3]>%, "unknown" ) ) )}
Re: Need Help with Expression to Print Sentence when Witness Role is Empty
Posted: 11 Jul 2022 18:56
by APerson
tatewise wrote: ↑11 Jul 2022 09:08
I've realised overnight that the expression can be simplified a little using just
TextIf(...) functions . . .
Thank you very much! Your simplified code works like a charm!
As I was testing the output returns, I came across a situation that was ambiguous - when more than one person has exactly the same name. So, I thought I'd try to add the function
LifeDates to display the Common Ancestor's birth and death dates (if known); For example:
Their common ancestor is John Doe (1805-1872).
However, once again, I'm not having any luck. I'd really appreciate it if you got set me straight on how to do this.
Re: Need Help with Expression to Print Sentence when Witness Role is Empty
Posted: 11 Jul 2022 21:14
by tatewise
Yes, it is necessary to use the Text(...) function to create the desired text value.
Each
%FACT._SHAR>%
must be replaced by
Text( %FACT._SHAR>% . " (" . LifeDates(%FACT._SHAR>%) . ")" )
in order to produce a single text parameter.
A similar structure is needed if you chose to display Record Id instead.
Text( %FACT._SHAR>% . " [" . RecordId(%FACT._SHAR>%) . "]" )
Re: Need Help with Expression to Print Sentence when Witness Role is Empty
Posted: 11 Jul 2022 23:26
by APerson
Thanks, Mike!
Without your help, I don't think I would have figured out the correct
Text(...) function. Also, I now only feel half stupid, instead of totally stupid

as I was able to get the full expression to work - I also FINALLY figured out problems I was having with nesting. Again, thank you!