Page 1 of 1

pattern matching

Posted: 17 Oct 2020 17:08
by Ron Melby
wife's grandson's wife

lets say I have a relation like that in my file.
there are two instances of wife.
I want to capture the second one..

it seems like I might need to use string.gmatch but cannot figure it out.
currently I use:
local _fwife = string.match(_0fr.RLT, '(wife)')
and it captures and returns the first.

Re: pattern matching

Posted: 18 Oct 2020 10:35
by tatewise
Pattern matching is not the solution. It is just like all the earlier discussions about 'instances'.
i.e. An Individual's 1st Occupation is INDI.OCCU[1] and their 2nd Occupation is INDI.OCCU[2]

So an Individual's 1st Spouse is INDI.FAMS[1]>WIFE> and 2nd Spouse is INDI.FAMS[2]>WIFE>
or there is the shortcut for 1st Spouse INDI.~SPOU[1]> and 2nd Spouse INDI.~SPOU[2]>
(That shortcut works for both men and women to find their wife or husband.)
i.e.
local ptrWife = fhGetItemPtr( ptrHusb, "~.FAMS[2]>WIFE>" )
or
local ptrWife = fhGetItemPtr( ptrHusb, "~.~SPOU[2]>" )

Re: pattern matching

Posted: 18 Oct 2020 14:39
by Ron Melby
Mike,
you misunderstand me, as I said before its a relation; i.e it is returned from fhBIF 'Relationship' 'TEXT' it is a string, and not family pointers.

My mother married twice.
first husband they had a daughter.
that daughter had a son, and he married. (grandson and wife)

my father and mother got married and here I am! not germaine to the issue, just placing things in spacetime.

when I look at the wife of that grandson of my mother -- (and to my mother: grandson's wife) with relationship he is; to my father: wife's grandson and his wife is relation to my father: wife's grandson's wife.

so where the relation is: wife something wife or husband something husband I need to ferret out the second instance.

Re: pattern matching

Posted: 18 Oct 2020 16:44
by tatewise
You are correct ~ I don't understand.
You did not say you were using the Relationship() function. How was I supposed to guess that?

I don't see where there is the 2nd instance of a wife. Your mother has two instances of a husband.

You will need to explain in more detail what you are trying to achieve with a snippet of code showing where you are stuck.

Are you saying you want to find the wife of your mother's grandson?
You must already have that pointer as a parameter to the Relationship() function.
The other pointer is to your father.
So it provides the relationship "wife's grandson's wife".

Re: pattern matching

Posted: 18 Oct 2020 16:56
by Ron Melby
rlt = 'wife's grandson's wife'
rlt = 'wife's brothers wife'
and so on...

lets say I have a relation like that in my file.

when I scan the string rlt, I want to capture only the second instance of wife. I already can get the first one.

in general where there are 2 instances of a word (or partial word... and it can be any word in a string.. ) repeated in a string I want to know the 2nd one is there. the second is important to me, the first is not.

local rr = rtvRLT(ptr)
local husb = string.match(rr.RLT, '(husband)')
local wife = string.match(rr.RLT, '(wife)')

husb does not exist, that is good.
wife does exist, but it picked the first one, which I dont care about, I want it to exist on the second one.

Re: pattern matching

Posted: 18 Oct 2020 19:46
by tatewise
Ah! Now I understand.

local rr = rtvRLT(ptr)
local husb = string.match(rr.RLT, 'husband.+(husband)')
local wife = string.match(rr.RLT, 'wife.+(wife)')

i.e. the pattern requires the word then any characters .+ and finally captures 2nd (word) if it exists.