*Name Problems

Writing and using plugins for Version 5 and above.
Ron Melby
Famous
Posts: 145
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Name Problems

Postby Ron Melby » 10 Apr 2018 17:46

local ptrINDI = fhNewItemPtr()
ptrINDI:MoveToFirstRecord("INDI")

while ptrINDI:IsNotNull() do
ptrNew = fhGetItemPtr(ptrINDI,"INDI.NAME:SURNAME")
Surname = fhGetValueAsText(ptrNew)
ptrNew = fhGetItemPtr(ptrINDI,"INDI.NAME:GIVEN_ALL")
Givenname = fhGetValueAsText(ptrNew)

ptrINDI contains: individual: Mavis Elaine Aune
Givenname contains: Mavis Elaine /Aune/
Surname contains: Mavis Elaine /Aune/
ptrINDI contains: name: Mavis Elaine Aune

I would expect Surname to be: Aune
and Givenname to be: Mavis Elaine

what am I missing here?
Win 7 64 bit. FH V.6.2.6

User avatar
tatewise
Megastar
Posts: 13613
Joined: 25 May 2010 11:00
Family Historian: V6.2
Location: Torbay, Devon, UK
Contact:

Re: Name Problems

Postby tatewise » 10 Apr 2018 18:38

Hi Ron.

fhGetItemPtr(...) gets a pointer to a Field regardless of Qualifiers.

A Field is separated from its Qualifier by a colon (:).
So INDI.NAME is the Field and SURNAME or GIVEN_ALL is the Qualifier.
See Knowledge Base > Understanding Data References.

Instead you need to use fhGetItemText(...) that supports Qualifiers.
See Tools > Plugins > How to Write Plugins > Sample Plugin Scripts > List All Individuals using all possible Surnames that uses that function with the same Qualifiers that you are using.
i.e.
while ptrINDI:IsNotNull() do
Surname = fhGetItemText(ptrINDI,"~.NAME:SURNAME")
Givenname = fhGetItemText(ptrINDI,"~.NAME:GIVEN_ALL")
Mike Tate ~ researching the Tate and Scott family history.

Ron Melby
Famous
Posts: 145
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: Name Problems

Postby Ron Melby » 10 Apr 2018 19:11

ahhhhhhhhhh. thanks, still learning and stumbling on nuance. nuancedly, of course.
Win 7 64 bit. FH V.6.2.6

Ron Melby
Famous
Posts: 145
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: Name Problems

Postby Ron Melby » 14 Apr 2018 16:51

two problems:

-- Get INDI Record
ptrRecord:MoveToRecordItem(ptr)
ptrWork:MoveToRecordItem(ptr)
Surname = fhGetItemText(ptrWork,"~.NAME:SURNAME")
Givenname = fhGetItemText(ptrWork,"~.NAME:GIVEN_ALL")
Sortname = (Surname.. ", "..Givenname)
table.insert(tblINDI, Sortname)

on debug:
Surname contains ELLS
Givenname contains Ida Josephine
Sortname contains ELLS, Ida Josephine
but when I output the results this field is blank

ah, text, not item.

-- FaG Link

table.insert(tblSource,ptr:Clone()) **
ptrWork:MoveTo(ptr,'~.PAGE')
table.insert(tblPAGE,ptrWork:Clone())
** on this one, the 1st occurance of the output points to the source record itself, all subsequent output points to the INDI record and the citation line in it. (the first record is not at all different from the rest)

now, only one left...

-- FaG CEM
ptrWork:MoveToParentItem(ptr)
table.insert(tblCEM,ptrWork:Clone()) <<<<<<<<<here I want to get the BURI or CREM ADDR (or make it blank) instead of the Buried Mar 11865 in (PLAC...) record
Win 7 64 bit. FH V.6.2.6

User avatar
tatewise
Megastar
Posts: 13613
Joined: 25 May 2010 11:00
Family Historian: V6.2
Location: Torbay, Devon, UK
Contact:

Re: Name Problems

Postby tatewise » 14 Apr 2018 17:40

Presumably the first script ending "ah, text, not item." is NOT a problem (so why post it?).

The two problems are "-- FaG Link" and "-- FaG CEM" but there is not enough script to understand where ptr comes from and how it changes in each loop (I presume it is in a loop?).
Mike Tate ~ researching the Tate and Scott family history.

Ron Melby
Famous
Posts: 145
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: Name Problems

Postby Ron Melby » 14 Apr 2018 20:04

Code: Select all

@title: Cemetery Table FaG
@author: Ron Melby
@lastupdated: Apr 2018
@version: 1.0
@description:
FaG
* INDI
* EVENT
* CEMETERY
* SOURCE
* Page
* Plot

]]

-- SearchINDI
function SearchINDI(SrcTag, ptrSOUR)
-- SrcTag:    Tag of Item being searched for
-- action:    function to perform
-- Loop through Record Types
  local ptr          = fhNewItemPtr()
  local recordPtr    = fhNewItemPtr()
 
 ptr:MoveToFirstRecord('INDI')
  while ptr:IsNotNull() do
    if fhGetTag(ptr) == SrcTag then
      BuildTables(ptr, ptrSOUR)
    end
    recordPtr:MoveToRecordItem(ptr)
    ptr:MoveNextSpecial()
 end
end

-- BuildTables
function BuildTables(ptr, ptrSOUR)
  local ptrINDI   = fhNewItemPtr()
  local ptrLink   = fhNewItemPtr()
  local ptrWork   = fhNewItemPtr()
  local ptrCEM    = fhNewItemPtr()
  ptrLink         = fhGetValueAsLink(ptr)
  local Surname   = ' '
  local Givenname = ' '
  Sortname        = ' '
  if ptrLink:IsSame(ptrSOUR) then
  -- Matching Record Found Add to Tables.
 
  -- Get INDI Record
    ptrINDI:MoveToRecordItem(ptr)
    ptrWork:MoveToRecordItem(ptr)
    Surname = fhGetItemText(ptrWork,"~.NAME:SURNAME")
    Givenname = fhGetItemText(ptrWork,"~.NAME:GIVEN_ALL")
    Sortname = (Surname.. ", "..Givenname)
    table.insert(tblINDI, Sortname)

  -- FaG CEM
    ptrWork:MoveToParentItem(ptr)
    table.insert(tblEvent,fhGetTag(ptrWork))
    CemAddr = ('~.' ..(fhGetTag(ptrWork)).. '.ADDR')
    ptrWork:MoveTo(ptrINDI,CemAddr)
    table.insert(tblCEM,ptrWork:Clone())   --this line fix

  -- FaG Link
    table.insert(tblSOUR,ptr:Clone())
    ptrWork:MoveTo(ptr,'~.PAGE')
  -- <a href="https://www.w3schools.com/html/">Visit our HTML tutorial</a>
    table.insert(tblPAGE,ptrWork:Clone())
 
  -- Plot
    ptrWork:MoveTo(ptr,'~.NOTE2')
    table.insert(tblPlot,ptrWork:Clone())
  end
end

-- Main Code
-- Create Tables for Result Set
tblINDI   = {}
tblEvent  = {}
tblCEM    = {}
tblSOUR   = {}
tblPAGE   = {}
tblPlot   = {}

-- Prompt for Source
tblSOUR = fhPromptUserForRecordSel('SOUR',1)
if #tblSOUR == 0 then
  fhMessageBox('Plugin Cancelled')
  return
end
--if citation not used
local iCitations = fhCallBuiltInFunction('LinksTo',tblSOUR[1])
if iCitations == 0 then
  fhMessageBox('No Citations Found')
  return
end

SearchINDI('SOUR', tblSOUR[1])
if #tblINDI > 0 then
-- Output Tables built to Results Window
  fhOutputResultSetColumn("Person",   "text", tblINDI,  #tblINDI, 128, "align_left")
  fhOutputResultSetColumn("Event",    "text", tblEvent, #tblCEM,   40, "align_left")
  fhOutputResultSetColumn("Cemetery", "item", tblCEM,   #tblCEM,  256, "align_left")
  fhOutputResultSetColumn("Cite",     "item", tblSOUR,  #tblINDI,  56, "align_left")
  fhOutputResultSetColumn("Page",     "item", tblPAGE,  #tblPAGE, 156, "align_left")
  fhOutputResultSetColumn("Plot",     "item", tblPlot,  #tblPlot, 248, "align_left")
else
  fhMessageBox('No Citations Found')
end


1) first problem, is now partially known, but unsolved....I am saving the selected source in tblSource as a parameter, first cycle, but am confused where I should put it, only since I am learning a new language.
2) how do I set my formatted name as a link so it acts just like the individual Records window?
Win 7 64 bit. FH V.6.2.6

User avatar
tatewise
Megastar
Posts: 13613
Joined: 25 May 2010 11:00
Family Historian: V6.2
Location: Torbay, Devon, UK
Contact:

Re: Name Problems

Postby tatewise » 14 Apr 2018 21:13

-- FaG Link problem.
You are using tblSOUR for two purposes that conflict.
tblSOUR = fhPromptUserForRecordSel('SOUR',1) creates tblSOUR[1]
table.insert(tblSOUR,ptr:Clone()) is inserting tblSOUR[2], tblSOUR[3], et seq.
So 1st entry in Result Set comes from tblSOUR = fhPromptUserForRecordSel('SOUR',1)
You must use two different variables for the Source selection and the Result Set.
So use tblSel instead of tblSOUR for the Source selection script.

-- FaG CEM problem
ptrWork:MoveToParentItem(ptr) the parent of a Source Citation can be many, many items not just Events
table.insert(tblEvent,fhGetTag(ptrWork))
CemAddr = ('~.' ..(fhGetTag(ptrWork)).. '.ADDR') so if it is not an Event it won't have an ADDR field

how do I set my formatted name as a link
You need a buddy item entry in the Result Set for the Individual record pointer.
e.g.
tblNAME = {} for your formatted name
tblINDI = {} for the record pointer
Then in -- Get INDI Record
table.insert(tblNAME, Sortname)
table.insert(tblINDI, ptrINDI:Clone())

The Result Set then needs to use a buddy item:
fhOutputResultSetColumn("Person", "text", tblNAME, #tblINDI, 128, "align_left")
fhOutputResultSetColumn("Person", "item", tblINDI, #tblINDI, 128, "align_left", 0, true, "default", "buddy")

This is the Plugin equivalent of the Query feature in Knowledge Base > Sort Fact Query on Owner Surname and is an advanced technique.
Mike Tate ~ researching the Tate and Scott family history.

Ron Melby
Famous
Posts: 145
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: Name Problems

Postby Ron Melby » 15 Apr 2018 00:33

I guess I see that. thanks. I sort of thought I might be able to fhGetValueAsLink, fhSetValueAslink, because under the covers, they have to be a pair of pointers (a dictionary, or table entry LOL) like any other symbolic link is under the covers. Just seems more straightforward and efficient to me, buddy fields (do they have them in iup (hidden key fields?) are useful on a screen.

next issue, so I am cutting the name stuff down to surname_first but there is n cute way to get suffix (I store jr. sr. and such in suffix:SUFX) and it would be handy to show that as:
Sibley Fredrick Jr. in my name field. you got a slick routine to pick that out??
Win 7 64 bit. FH V.6.2.6

User avatar
tatewise
Megastar
Posts: 13613
Joined: 25 May 2010 11:00
Family Historian: V6.2
Location: Torbay, Devon, UK
Contact:

Re: Name Problems

Postby tatewise » 15 Apr 2018 10:29

I have started a new thread PDF Reports (15851) regarding the PDF stuff.

The Name Suffix field has the tag NSFX not SUFX so the script needed is:

Surname = fhGetItemText(ptrWork,"~.NAME:SURNAME")
Givenname = fhGetItemText(ptrWork,"~.NAME:GIVEN_ALL")
NameSuffix = fhGetItemText(ptrWork,"~.NAME.NSFX")
if NameSuffix ~= "" then NameSuffix = ", "..NameSuffix end
Sortname = Surname.. ", "..Givenname..NameSuffix

The If NameSuffix ~= "" then is needed to ensure trailing ", " is avoided when no Name Suffix.
Mike Tate ~ researching the Tate and Scott family history.

Ron Melby
Famous
Posts: 145
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: Name Problems

Postby Ron Melby » 16 Apr 2018 15:29

I did it so its:

Surname, Given All Sr.
and avoided the problem altogether.

also did the buddy field, not a big thing, like 4 lines or so inserted.

I have spent countless months on my PLAC and ADDR fields, standardizing, and on every new thing I come up with, I still find mistakes (albiet very small) so I have the situation where in certain CREM and BURI there is no ADDR so in that case I need to go to the parent CREM or BURI and get its note as a clone and stick in the table. seems like that will be easy.
Win 7 64 bit. FH V.6.2.6

Ron Melby
Famous
Posts: 145
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: Name Problems

Postby Ron Melby » 18 Apr 2018 01:58

CemAddr = ('~.' ..(fhGetTag(ptrWork)).. '.ADDR')
ptrWork:MoveTo(ptrINDI, CemAddr)
if ptrWork == nil then
CemAddr = ('~.' ..(fhGetTag(ptrWork)).. '.NOTE')
ptrWork:MoveTo(ptrINDI, CemAddr)
end
table.insert(tblCEM, ptrWork:Clone()) --this line fix

in the debugger ptrWork is (null)
how do I compare a pointer to (null) ? it is not executing the statement between if and end
Win 7 64 bit. FH V.6.2.6

User avatar
David2416
Diamond
Posts: 52
Joined: 12 Nov 2017 16:37
Family Historian: V6.2

Re: Name Problems

Postby David2416 » 18 Apr 2018 06:08

Use IsNull()
Eg
while ptrWork:IsNull() do
code
End

Null is a special value comparison to which always produces Null. It's not 0, nil, or an empty string.

Ron Melby
Famous
Posts: 145
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: Name Problems

Postby Ron Melby » 24 Apr 2018 00:20

no Idea how I duplicated it, but I have a very cramped keyboard.
Last edited by Ron Melby on 24 Apr 2018 00:23, edited 1 time in total.
Win 7 64 bit. FH V.6.2.6

Ron Melby
Famous
Posts: 145
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: Name Problems

Postby Ron Melby » 24 Apr 2018 00:22

I try to be meticulous and accurate when entering information into my gedcom, nevertheless I am riddled with small errors.

as a sideline to my FaG Cemetery Table (all other situations have been worked out by your help) I am doing a cut down report to search for one type of error:

In the ~.SOUR.PAGE field I have:
http://www.findagrave.com/memorial/86624711
http://www.findagrave.com/memorial/104727644
...

So, I am a long way from understanding the match or sub psuedo-regex patterns..

I want to endup with the digits only, ie
86624711

is it ([^%d]} for the match?

and given that I am asking that question, what I would really like in the table is the pairs or trips or whatever, in the form, name and number that are duplicates only, but that is beyond me, of the 1200 or so records I have that have a findagrave there are perhaps (oh, I hope) maybe 12 that I have messed up on. but even to sort them (I can do that) I think I can stare and compare most of the errors.
Win 7 64 bit. FH V.6.2.6

User avatar
tatewise
Megastar
Posts: 13613
Joined: 25 May 2010 11:00
Family Historian: V6.2
Location: Torbay, Devon, UK
Contact:

Re: Name Problems

Postby tatewise » 24 Apr 2018 09:59

Yes, it does take a while to understand Lua Patterns, especially if not familiar with Regular Expressions.
The pattern "([^%d])" will match a single non-digit character.
Whereas "([^%d]+)" will match a series of non-digit characters.
But it is actually the digits that you want to capture and discard the rest of the URL, but keep anything else.
e.g.
local strOldPage = fhGetItemText(ptrWork,"~.SOUR.PAGE")
local strNewPage = strOldPage:gsub("http.-(%d+)","%1")

So that matches any text starting with http and ending with some digits %d+ that are captured.
Thus the whole URL is replaced by the 1st capture %1 of just the digits.
Any other text in the PAGE field is retained.
If there are multiple http then each one is reduced to just the digits.
If nothing matches the pattern then everything is retained.
So testing if strOldPage == strNewPage then determines whether anything changed.

In your last question, I guess you are just looking for duplicated grave numbers?
So the following script will detect the duplications assuming only one per PAGE field.
The strategy is to populate a table with an index entry for each new grave number.
So if the index entry already exists you have found a duplicate.
local tblGrave = {}

then inside loop
local strGrave = strNewPage:match("%d+")
if tblGrave[strGrave] then

~ duplicate found so create Result Set entry for strGrave No, with ptrINDI from tblGrave[strGrave], and current loop ptrINDI ~
else
tblGrave[strGrave] = ptrINDI:Clone()
end
Mike Tate ~ researching the Tate and Scott family history.

Ron Melby
Famous
Posts: 145
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: Name Problems

Postby Ron Melby » 24 Apr 2018 11:12

well I've worked on this for quite some time....and dont know anymore than I did at the outset.

-- FaG Web Page
1. ptrWork:MoveTo(ptr,'~.PAGE')
2. table.insert(tblPAGE,ptrWork:Clone())
3. local strOldPage = fhGetDisplayText(ptrWork,'min')
4. local strNewPage = strOldPage:gsub("www.-(%d+)","%1")
5. table.insert(tblNUM,strOldPage)

I have tried line 3 both ways (fhGetItemText and fhGetDisplayText) (exactly as you have given it to me tatewise): with the following exception
local strOldPage = fhGetItemText(ptrWork,"~.SOUR.PAGE")
local strNewPage = strOldPage:gsub("www.-(%d+)","%1")

@ 5, ptrWork contains: where within source: http://www.findagrave.com/memorial/123456789 (I have stripped all http, https and trailing strings after the numbers on all FaG pages. WYSIWYG). both local str(s) contain "". and the output is on the order of:
ELLS, Josephine (c1) and bbbbbbbbb (c2) Ihave tblPAGE as buddy, so clicking on the blank field gets me to the BURI or CREM record but not the page (the record parent is in blue when I go there) (because of this strange behavior, I know something is wrong with the table and of course I can see it)

I know ptrWork is correct, and it is the situation either way fhGetDisplay or fhGetItem... no errors, and I cant see for the life of me how this code is incorrect, but obviously it is '
Win 7 64 bit. FH V.6.2.6

User avatar
tatewise
Megastar
Posts: 13613
Joined: 25 May 2010 11:00
Family Historian: V6.2
Location: Torbay, Devon, UK
Contact:

Re: Name Problems

Postby tatewise » 24 Apr 2018 11:40

It is important to keep a clear understanding of what ptrWork is pointing at.

The main problem with line 3 is that it is missing a parameter and should be:
local strOldPage = fhGetDisplayText(ptrWork, "~.", 'min')

but since ptrWork is pointing at the PAGE field, you can more simply use:
local strOldPage = fhGetValueAsText(ptrWork)
or
local strOldPage = fhGetItemText(ptrWork,"~.")

but NOT:
local strOldPage = fhGetItemText(ptrWork,"~.SOUR.PAGE")
Can you tell me why that won't work?
Mike Tate ~ researching the Tate and Scott family history.

Ron Melby
Famous
Posts: 145
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: Name Problems

Postby Ron Melby » 24 Apr 2018 11:46

it would end up looking for something like
'~.SOUR.PAGE' (base)
'~.SOUR.PAGE' (offset) so...

'~.SOUR.PAGE~.SOUR.PAGE'
Win 7 64 bit. FH V.6.2.6

Ron Melby
Famous
Posts: 145
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: Name Problems

Postby Ron Melby » 24 Apr 2018 11:59

local strOldPage = fhGetValueAsText(ptrWork)
this worked, looking at it I see why, but still a little shaky on why the old code didnt.
I also needed to write strNewPage on line 5.
Win 7 64 bit. FH V.6.2.6


Return to “Plugin Discussions”

Who is online

Users browsing this forum: No registered users and 5 guests