Extracting census address from source title
Posted: 08 Feb 2020 10:01
I have a lot of old census records in my database that pre-date my use of FH so do not include the detailed address. All my censuses have single individual citations to a corresponding source record with a title along the lines of "Census, 1881: Bermondsey, SRY (156 Jamaica Road)". Extracting this address data where it is present seems like an obvious job for a small custom plug-in. Unfortunately, it's two years since I last dabbled with writing plug-ins, and I'm very rusty! The following code seems to work ok, judging by source queries run before and after, but does it look reasonable please? I'm very wary of unintended consequences to other data!
I know it would need more refinement to generalise application (error testing, etc), but it needs to run only once on each database so can be relatively quick and dirty as long as it is correct!
Thanks in anticipation!
I know it would need more refinement to generalise application (error testing, etc), but it needs to run only once on each database so can be relatively quick and dirty as long as it is correct!
Code: Select all
ptIndi = fhNewItemPtr() -- record pointer
ptIndi:MoveToFirstRecord('INDI') -- set pointer to first INDI record
while ptIndi:IsNotNull() do -- loop through individuals
ptCensus = fhGetItemPtr(ptIndi, '~.CENS')
while ptCensus:IsNotNull() do -- loop through their census events
strAddress = '' -- reset strings
strTitle = ''
strSourceAddress = ''
strAddress = fhGetItemText(ptCensus, '~.ADDR') -- census address
if strAddress == '' then
strTitle = fhGetItemText(ptCensus, '~.SOUR>TITL') -- get source title
strSourceAddress = string.match(strTitle, "%((.-)%)")
if strSourceAddress ~= nil then -- create new address field
ptAddress = fhCreateItem('ADDR', ptCensus)
fhSetValueAsText(ptAddress, strSourceAddress)
end
end
ptCensus:MoveNext('SAME_TAG')
end
ptIndi:MoveNext('SAME_TAG') -- move to next individual
end