Page 1 of 1

How to get from witnessed fact to the original fact?

Posted: 21 Mar 2022 13:09
by Talln
Hi

I'm extracting Facts for each Individual using the fhIndGetFactList function, including their witness and timeline facts.

I'm struggling to see how, for a witness fact, I can get to the original Fact data that was witnessed.

For example: There is a Fact item A for Joe Bloggs witnessing the marriage of John Doe and Mary Foobar, and a Fact item B for John Doe marrying Mary Foobar. Given that I have the pointer for A, how can I get the pointer for B ?

I tried the Witness fields of the witness Fact, but these are blank (maybe because there was no witness to the witnessing and/or no way to record that?!)

Queries based on Fact (event or attribute) don't return Witness (or timeline) facts, so I can't prototype it in Query dialogue before coding it.

(I could load all Facts for everyone and then search for references to the Joe Bloggs but a bit resource heavy for thousands of individuals.)

Hoping that someone knows what function/expression would just get me to the original fact without effort!!

(BTW This also applies to Timeline facts and I'm hoping it's the same answer!)

Thanks in anticipation
Talln
(Extracting data for a custom website.)

Re: How to get from witnessed fact to the original fact?

Posted: 21 Mar 2022 15:41
by tatewise
This code snippet should provide the necessary clues:

Code: Select all

local tblFact = fhIndGetFactList(ptrIndi,true,true)
for _, ptrFact in ipairs (tblFact) do
	local ptrOwner = fhNewItemPtr()
	ptrOwner:MoveToRecordItem(ptrFact)
	local strFact = fhGetDisplayText(ptrFact)
	local ptrRole = fhGetItemPtr(ptrFact,"~.ROLE")
	local ptrRoot = fhNewItemPtr()
	ptrRoot:MoveToParentItem(ptrFact) 
end
ptrOwner identifies the Individual or Family record that holds the Fact.

If ptrOwner IsSame() as ptrIndi then it is their local Fact.

If strFact starts with "Witness: " then it is a Fact Witness and ptrOwner is the Principal.
Thus ptrRole is the Role and ptrRoot is the Principal Fact.

Otherwise, it is a Timeline Fact for ptrOwner.

Re: How to get from witnessed fact to the original fact?

Posted: 22 Mar 2022 15:09
by Talln
Super useful. Thanks!

I've spent an hour or so working an example which gets what I need.

I have noticed that for local family facts such as marriage the test ptrOwner IsSame() as ptrIndi fails in that ptrOwner is a family vs an individual ... so I've been looking at testing both spouses. I was trying fhCallBuiltInFunction('FactOwner', ptrFact, 1,'MALES_FIRST') but getting nulls for all facts so clearly getting something wrong!

Another observation is that FactLabel() (i.e. fhCallBuiltInFunction('FactLabel',ptrFact)) is null and only null for (my) witness facts. Not sure whether this would be as reliable a test as using "Witness: " in strFact...there may be other cases not in my dataset which would break it. The "Witness: " approach looks solid so I'm sticking with you!

Thanks again.

Re: How to get from witnessed fact to the original fact?

Posted: 22 Mar 2022 16:48
by tatewise
I've investigated a bit further and the script below should cater for all possibilities.
It focuses on testing the tag name of the 'fact' or the 'owner'.
If the 'fact' tag is _SHAR then it is not actually a 'fact' but a fact witness pointer from which Principal Fact & Role is obtained.
If the 'owner' tag is INDI it is an Individual fact and if same as the original person then it is their Fact else a Timeline Fact.
Otherwise, it must be a Family fact and if any spouse is the original person then it is their Fact else a Timeline Fact.
( The tests for HUSB[2] and WIFE[2] cater for same-sex partnerships. )

Code: Select all

local tblFact = fhIndGetFactList(ptrIndi,true,true)
for _, ptrFact in ipairs (tblFact) do
	local ptrOwner = fhNewItemPtr()
	ptrOwner:MoveToRecordItem(ptrFact)
	local strFact = fhGetDisplayText(ptrFact)
	if fhGetTag(ptrFact) == "_SHAR" then
		local ptrRole = fhGetItemPtr(ptrFact,"~.ROLE")
		local ptrRoot = fhNewItemPtr()
		ptrRoot:MoveToParentItem(ptrFact)
		zz=0		-- Fact Witness
	elseif fhGetTag(ptrOwner) == "INDI" then
		if ptrIndi:IsSame(ptrOwner) then
			zz=0	-- Own individual fact
		else
			zz=0	-- Timeline fact
		end
	else
		if ptrIndi:IsSame(fhGetItemPtr(ptrOwner,"~.HUSB[1]>"))
		or ptrIndi:IsSame(fhGetItemPtr(ptrOwner,"~.WIFE[1]>"))
		or ptrIndi:IsSame(fhGetItemPtr(ptrOwner,"~.HUSB[2]>"))
		or ptrIndi:IsSame(fhGetItemPtr(ptrOwner,"~.WIFE[2]>")) then
			zz=0	-- Own family fact
		else
			zz=0	-- Timeline fact
		end
	end
end

Re: How to get from witnessed fact to the original fact?

Posted: 23 Mar 2022 17:26
by Talln
Thanks Mike!