# Revision history:
#	Jun08 created
#	Sep08 adapted to be included

# Grammar to include this file

# \DESCRIPTION
# Parses individuals' and organisations' names, with a relationship between them
# Can preface input with "ETHint:<C or P>;" or "ETType:<C or P>;"  C=company/organisation, P=person
# Can preface input with "SaluteHint:<...>;"
# Can preface input with "GenderHint:<...>;"

# INCLUDing file must define sOrgOrIndividualParam

\DEFINE SPLIT_ON_AND_AFTER_ORGTYPE

# Grammar to include this file, and use variables below
\VARIABLES
20	inputType_		# Whether an individual or an organisation
# Individual
20	prefix1_
5	title1_
20	firstName1_
20	middleName1_
25	lastName1_
10	suffix1_
1	typicalGender1_
12	flag1_
20	prefix2_
5	title2_
20	firstName2_
20	middleName2_
25	lastName2_
10	suffix2_
1	typicalGender2_
12	flag2_
20	prefix3_
5	title3_
20	firstName3_
20	middleName3_
25	lastName3_
10	suffix3_
1	typicalGender3_
12	flag3_
20	prefix4_
5	title4_
20	firstName4_
20	middleName4_
25	lastName4_
10	suffix4_
1	typicalGender4_
12	flag4_
20	prefix5_
5	title5_
20	firstName5_
20	middleName5_
25	lastName5_
10	suffix5_
1	typicalGender5_
12	flag5_
20	prefix6_
5	title6_
20	firstName6_
20	middleName6_
25	lastName6_
10	suffix6_
1	typicalGender6_
12	flag6_
20	prefix7_
5	title7_
20	firstName7_
20	middleName7_
25	lastName7_
10	suffix7_
1	typicalGender7_
12	flag7_
20	prefix8_
5	title8_
20	firstName8_
20	middleName8_
25	lastName8_
10	suffix8_
1	typicalGender8_
12	flag8_
# Organisation
60	primName_			#Organisation key name
30	primQual_			#Organisation qualifiers
15	primType_			#Organisation type
8	primNysiisName_		#NYSIIS of organisation key name
4	primRsndxName_		#Reverse Soundex of organisation name
8	primNysiisFull_		#NYSIIS of organisation key name & qualifiers
120	primCleanOrg_		#Locality & punctuation removed from end
50	primPreOrg_			#what's before the name
50	primPostOrg_		#what's after the qual or type
60	secName_
30	secQual_
15	secType_
8	secNysiisName_
4	secRsndxName_
8	secNysiisFull_
120	secCleanOrg_
10	secPreOrg_
50	secPostOrg_
60	thirdName_
30	thirdQual_
15	thirdType_
8	thirdNysiisName_
4	thirdRsndxName_
8	thirdNysiisFull_
120	thirdCleanOrg_
10	thirdPreOrg_
50	thirdPostOrg_
20	checkFlag_
# relationships
20	RelationshipType1_
20	RelationshipFrom1_
20	RelationshipTo1_
20	RelationshipType2_
20	RelationshipFrom2_
20	RelationshipTo2_

\VARIABLES
200	sItem1
200	sItem2
200	sItem3
50	sTemp
50	sRelationship1
50	sRelationship2
10	sRel1
10	sRel
1	s1
1	sEntityHint
9	sEntityHintFull
50	sSaluteHint
10	sGenderHint
4	sInitials1
4	sInitials2
600	sBuffer
20	sCheckFlag
1	sDummy
50	sEndItem
50	sEndItem1
50	sEndItem2
50	sBeginItem
50	sBeginItem1
50	sBeginItem2
5	sAnd
5	sAnd1
5	sAnd2
30	sPreviousWord
50	sPreviousWords


# array - second entity parsed by OrgOrIndividual
20	b_inputType
20	b_prefix1
5	b_title1
20	b_firstName1
20	b_middleName1
25	b_lastName1
10	b_suffix1
1	b_typicalGender1
12	b_flag1
20	b_prefix2
5	b_title2
20	b_firstName2
20	b_middleName2
25	b_lastName2
10	b_suffix2
1	b_typicalGender2
12	b_flag2
20	b_prefix3
5	b_title3
20	b_firstName3
20	b_middleName3
25	b_lastName3
10	b_suffix3
1	b_typicalGender3
12	b_flag3
20	b_prefix4
5	b_title4
20	b_firstName4
20	b_middleName4
25	b_lastName4
10	b_suffix4
1	b_typicalGender4
12	b_flag4
20	b_prefix5
5	b_title5
20	b_firstName5
20	b_middleName5
25	b_lastName5
10	b_suffix5
1	b_typicalGender5
12	b_flag5
20	b_prefix6
5	b_title6
20	b_firstName6
20	b_middleName6
25	b_lastName6
10	b_suffix6
1	b_typicalGender6
12	b_flag6
20	b_prefix7
5	b_title7
20	b_firstName7
20	b_middleName7
25	b_lastName7
10	b_suffix7
1	b_typicalGender7
12	b_flag7
20	b_prefix8
5	b_title8
20	b_firstName8
20	b_middleName8
25	b_lastName8
10	b_suffix8
1	b_typicalGender8
12	b_flag8
60	b_primName
30	b_primQual
15	b_primType
8	b_primNysiisName
4	b_primRsndxName
8	b_primNysiisFull
120	b_primCleanOrg
50	b_primPreOrg
50	b_primPostOrg
60	b_secName
30	b_secQual
15	b_secType
8	b_secNysiisName
4	b_secRsndxName
8	b_secNysiisFull
120	b_secCleanOrg
10	b_secPreOrg
50	b_secPostOrg
60	b_thirdName
30	b_thirdQual
15	b_thirdType
8	b_thirdNysiisName
4	b_thirdRsndxName
8	b_thirdNysiisFull
120	b_thirdCleanOrg
10	b_thirdPreOrg
50	b_thirdPostOrg
1	b_checkFlag

# array - third entity parsed by OrgOrIndividual
20	c_inputType
20	c_prefix1
5	c_title1
20	c_firstName1
20	c_middleName1
25	c_lastName1
10	c_suffix1
1	c_typicalGender1
12	c_flag1
20	c_prefix2
5	c_title2
20	c_firstName2
20	c_middleName2
25	c_lastName2
10	c_suffix2
1	c_typicalGender2
12	c_flag2
20	c_prefix3
5	c_title3
20	c_firstName3
20	c_middleName3
25	c_lastName3
10	c_suffix3
1	c_typicalGender3
12	c_flag3
20	c_prefix4
5	c_title4
20	c_firstName4
20	c_middleName4
25	c_lastName4
10	c_suffix4
1	c_typicalGender4
12	c_flag4
20	c_prefix5
5	c_title5
20	c_firstName5
20	c_middleName5
25	c_lastName5
10	c_suffix5
1	c_typicalGender5
12	c_flag5
20	c_prefix6
5	c_title6
20	c_firstName6
20	c_middleName6
25	c_lastName6
10	c_suffix6
1	c_typicalGender6
12	c_flag6
20	c_prefix7
5	c_title7
20	c_firstName7
20	c_middleName7
25	c_lastName7
10	c_suffix7
1	c_typicalGender7
12	c_flag7
20	c_prefix8
5	c_title8
20	c_firstName8
20	c_middleName8
25	c_lastName8
10	c_suffix8
1	c_typicalGender8
12	c_flag8
60	c_primName
30	c_primQual
15	c_primType
8	c_primNysiisName
4	c_primRsndxName
8	c_primNysiisFull
120	c_primCleanOrg
50	c_primPreOrg
50	c_primPostOrg
60	c_secName
30	c_secQual
15	c_secType
8	c_secNysiisName
4	c_secRsndxName
8	c_secNysiisFull
120	c_secCleanOrg
10	c_secPreOrg
50	c_secPostOrg
60	c_thirdName
30	c_thirdQual
15	c_thirdType
8	c_thirdNysiisName
4	c_thirdRsndxName
8	c_thirdNysiisFull
120	c_thirdCleanOrg
10	c_thirdPreOrg
50	c_thirdPostOrg
1	c_checkFlag

# array - SaluteHint parsed by IndNames3a
20	sh_prefix1
5	sh_title1
20	sh_firstName1
20	sh_middleName1
25	sh_lastName1
10	sh_suffix1
1	sh_typicalGender1
12	sh_flag1
20	sh_prefix2
5	sh_title2
20	sh_firstName2
20	sh_middleName2
25	sh_lastName2
10	sh_suffix2
1	sh_typicalGender2
12	sh_flag2

\NUMERIC_VARIABLES
iLen
iPos
iPos2
bMatch
iInd1
iInd2
iOrg1
iOrg2
i
j
bTACheck

\CONSTANTS
sAllPunctuation = " \t!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
sDelimiters =  "()-[]{};:?,. \t"
sInnerDelimiters = "-. "
sTrimChars = "-;:?,. \t"
sTypeDelimiters = sDelimiters - "&/"

\SUB_GRAMMARS
OrgOrIndividual	OrgOrIndividual.grm
IndNames3a		IndNames3a.grm
Org3			Organisation3.grm

\TABLE RelationshipTable CASE_INSENSITIVE
#trading as
TRADING AS
T/AS=TRADING AS
T//AS=TRADING AS
T/A=TRADING AS
TA=TRADING AS
T A=TRADING AS
T/ A=TRADING AS
T/ AS=TRADING AS
DOING BUSINESS AS=TRADING AS
OPERATING AS=TRADING AS

# as trustee for
AS TRUSTEE FOR
AS TRUSTEE THE=AS TRUSTEE FOR
AS TRUSTEES FOR=AS TRUSTEE FOR
AS THE TRUSTEE FOR=AS TRUSTEE FOR
AS THE TRUSTEES FOR=AS TRUSTEE FOR
AS TRUSTEE ACCOUNT FOR=AS TRUSTEE FOR
A TF=AS TRUSTEE FOR
A/T/F=AS TRUSTEE FOR
ATF=AS TRUSTEE FOR
A T F=AS TRUSTEE FOR
IN ITS CAPACITY ATF=AS TRUSTEE FOR
IN TRUST FOR=AS TRUSTEE FOR
ITF=AS TRUSTEE FOR
I T F=AS TRUSTEE FOR
T/F=AS TRUSTEE FOR
T/FOR=AS TRUSTEE FOR
TRUSTEES FOR=AS TRUSTEE FOR
A/TRUS OF=AS TRUSTEE FOR
ATFT=AS TRUSTEE FOR
TF=AS TRUSTEE FOR
AS TRUSTEE TO=AS TRUSTEE FOR
A/T FOR=AS TRUSTEE FOR
AS T/F=AS TRUSTEE FOR
A/ TRUS OF=AS TRUSTEE FOR
T/F=AS TRUSTEE FOR
T/TEE FOR=AS TRUSTEE FOR
TRUSTS FOR=AS TRUSTEE FOR
TRUSTEE FOR=AS TRUSTEE FOR
IN TRUST=AS TRUSTEE FOR

# others
ON BEHALF OF
OBO=ON BEHALF OF
OBF=ON BEHALF OF
ABF=ON BEHALF OF

AS EXECUTORS FOR
EXECUTORS OF ESTATE=AS EXECUTORS FOR
EXECUTOR FOR THE ESTATE OF=AS EXECUTORS FOR

AS NOMINEE FOR
AS NOM FOR=AS NOMINEE FOR
IN ITS CAP AS NOM FOR=AS NOMINEE FOR

AS ADMIN FOR
AS THE ADMIN OF THE FINANCIAL MATTERS FOR=AS ADMIN FOR
AS THE ADMIN OF THE FIN MATTERS FOR=AS ADMIN FOR
AS THE ADMINISTRATOR OF THE FINANCIAL MATTERS FOR=AS ADMIN FOR
AS THE ADMIN OF=AS ADMIN FOR
AS THE ADMINISTRATOR OF=AS ADMIN FOR
AS ADMINISTRATOR FOR THE FINANCIAL AFFAIRS OF=AS ADMIN FOR
AS ADMINISTRATOR FOR THE FINANCIAL AFFAIRS=AS ADMIN FOR

AS RESPONSIBLE FOR
AS RESPONSIBLE ENTITY FOR=AS RESPONSIBLE FOR
ARE FOR=AS RESPONSIBLE FOR
AS RE FOR=AS RESPONSIBLE FOR
AS RESP ENTITY FOR=AS RESPONSIBLE FOR

AS CUSTODIAN FOR
IN IT'S CAPACITY AS THE CUSTODIAN OF=AS CUSTODIAN FOR
ACF=AS CUSTODIAN FOR
AS CUSTODIAN OF=AS CUSTODIAN FOR

SALE TO
S/T=SALE TO

\TABLE FTRRITable CASE_INSENSITIVE
For their respective rights and interests
For their respective rights & interests
FTRR&I
F T R R & I
For Their R R & I
For Their RR&I
For Their RR & I

\TABLE titleToGenderTable CASE_INSENSITIVE
MR=M
MRS=F
MISS=F
MS=F
#DR
#PROF
SIR=M
LADY=F
FTHR=M
MSTR=M
HON=M

\TABLE titleTable CASE_INSENSITIVE
MR
MRS
MISS
MS
DR
PROF
SIR
LADY
PROFESSOR
DOCTOR
HON
MASTER
MSTR

\TABLE orgTypeTable CASE_INSENSITIVE # copied from Organisation3.grm
& SONS
A/C
ACADEMY
ADMIN
ADMINISTRATION
ADMINS
AGENCIES
AGENCY
AGENT
AGENTS
ASS
ASSC
ASSN
ASSO
ASSOC
ASSOCIA
ASSOCIATE
ASSOCIATES
ASSOCIATION
ASSOCS
AUTH
AUTHOR
AUTHORITY
BOARD
BODY CORP
BODY CORPORATE
CHURCH
CHURCHES
CLUB
CO
CO OP
CO OPERATIVE
CO-OP
CO-OPERATIVE
COLLEGE
COMM
COMMISSION
COMPANIES
COMPANY
COOP
COOPERATIVE
COOPERATIVES
CORP
CORPORATE
CORPORATIO
CORPORATION
DEPARTMENT
DEPT
ENDOWMENT
F/T
F/TRUST
FAMILY TR
FAMILY TRUST
FAMILY TST
FOUND
FOUNDATION
GMBH
GOVERNMENT
GOVT
GROUP
INC
INCORP
INCORPORATED
INCORPORATION
INST
INSTITUTE
INSTITUTE OF TAFE
INSTITUTION
LIMITED
LTD
ORG
ORGANISATION
ORGANIZATION
P/L
PROPRIETARY
PTY
PTY LIMITED
PTY LTD
PTYL
S/F
SOCIETY
SUPER FUND
SUPERANNUATION FUND
SUPERFUND
SYNDICATE
TRUST
TRUSTS
U/T
U/TR
U/TRUST
UNIT TRUST
UNIT TST
UNIVERSITY

# normally a sub-set of orgTypeTable; copied from Organisation3.grm
\TABLE orgTypeTable2 CASE_INSENSITIVE
& ASSOCIATES=ASSOCIATES
& ASSOCS=ASSOCIATES
& COMPANY=CO
& SONS=SONS
AGENCY
AGENT
AGENTS=AGENT
AND CO=CO
ASSO=ASSOCIATES
ASSOC=ASSOCIATES
ASSOCIATES
ASSOCIATION
ASSOCS=ASSOCIATES
AUTHORITY
BOARD
BODY CORP=BODY CORPORATE
BODY CORPORATE
CHURCH
CHURCHES
CLUB
CO OP=COOP
CO OPERATIVE=COOP
CO-OP=COOP
CO-OPERATIVE=COOP
COLLEGE
COMMISSION
COMPANIES=CO
COMPANY=CO
COOP
COOPERATIVE=COOP
COOPERATIVES=COOP
CORP
CORPORATE=CORP
CORPORATION==CORP
DEPARTMENT
DEPT=DEPARTMENT
ENDOWMENT
F/T=FAMILY TRUST
F/TRUST=FAMILY TRUST
FAMILY TR=FAMILY TRUST
FAMILY TRUST
FAMILY TST=FAMILY TRUST
FOUNDATION
GMBH
GOVERNMENT
GROUP
INC
INCORPORATED=INC
INCORPORATION=INC
INSTITUTE
INSTITUTE OF TAFE
INSTITUTION
LIMITED=LTD
LTD
ORG=ORGANISATION
ORGANISATION
ORGANIZATION==ORGANISATION
P/L=PTY LTD
PROPRIETARY=PTY
PTY
PTY LTD
S/F=SUPER FUND
SOCIETY
SUPER FUND
SUPERANNUATION FUND=SUPER FUND
SUPERFUND=SUPER FUND
SYNDICATE
TRUST
TRUSTS
U/T=UNIT TRUST
U/TR=UNIT TRUST
U/TRUST=UNIT TRUST
UNIT TRUST
UNIT TST=UNIT TRUST
UNIVERSITY

\TABLE AfterAndTable CASE_INSENSITIVE #company words that code after "and"
ASSOCIATES
CO
COMPANY
NOMINEES
SON
SONS


\IF FILE_EXISTS Site_Custom_Company_Details.txt
	\INCLUDE Site_Custom_Company_Details.txt
\ENDIF

\IF FILE_EXISTS Site_Custom_Person_Details.txt
	\INCLUDE Site_Custom_Person_Details.txt
\ENDIF

\PRE_PARSE
{
	# extract Entiry Hint from input ("ETHint:P" or "ETHint:C")
	sTemp = LEFT(INPUT, 7)
	sTemp = UCASE(sTemp)
	IF sTemp = "ETHINT:"
		sEntityHintFull = LEFT(INPUT, 9)	# "ETHint:P;" or "ETHint:C;"
		sEntityHint = MID(INPUT, 8, 1)		# P or C
		IF sEntityHint <> "P"
			IF sEntityHint <> "C"
				sEntityHintFull  = ""
			END IF
		END IF
		INPUT = MID(INPUT, 9)
	ELSEIF sTemp = "ETTYPE:"
		sEntityHintFull = LEFT(INPUT, 9)	# "ETType:P;" or "ETType:C;"
		sEntityHint = MID(INPUT, 8, 1)		# P or C
		IF sEntityHint <> "P"
			IF sEntityHint <> "C"
				sEntityHintFull  = ""
			END IF
		END IF
		INPUT = MID(INPUT, 9)
	END IF
	INPUT = LTRIM(INPUT, ";\t ") # skip tab or semi-colon
	# extract Salutation Hint ("SaluteHint:...")
	sTemp = LEFT(INPUT, 11)
	sTemp = UCASE(sTemp)
	IF sTemp = "SALUTEHINT:"
		# till tab or semi-colon
		iPos = INSTR(INPUT, "\t")
		iPos2 = INSTR(INPUT, ";")
		IF iPos2 > 0
			IF iPos = 0
				iPos = iPos2
			ELSEIF iPos2 < iPos
				iPos = iPos2
			END IF
		END IF
		iPos = iPos - 12
		sSaluteHint = MID(INPUT, 12, iPos)
		sh_prefix1 = IndNames3a(sSaluteHint, 16) # returns 40, but array only 16 long
		iPos = iPos + 13
		INPUT = MID(INPUT, iPos)
	END IF
	# extract Gender Hint ("GenderHint:...")
	sTemp = LEFT(INPUT, 11)
	sTemp = UCASE(sTemp)
	IF sTemp = "GENDERHINT:"
		# till tab or semi-colon
		iPos = INSTR(INPUT, "\t")
		iPos2 = INSTR(INPUT, ";")
		IF iPos2 > 0
			IF iPos = 0
				iPos = iPos2
			ELSEIF iPos2 < iPos
				iPos = iPos2
			END IF
		END IF
		iPos = iPos - 12
		sGenderHint = MID(INPUT, 12, iPos)
		iPos = iPos + 13
		INPUT = MID(INPUT, iPos)
		# extract Salutation Hint ("SaluteHint:...")
		sTemp = LEFT(INPUT, 11)
		sTemp = UCASE(sTemp)
		IF sTemp = "SALUTEHINT:"
			# till tab or semi-colon
			iPos = INSTR(INPUT, "\t")
			iPos2 = INSTR(INPUT, ";")
			IF iPos2 > 0
				IF iPos = 0
					iPos = iPos2
				ELSEIF iPos2 < iPos
					iPos = iPos2
				END IF
			END IF
			iPos = iPos - 12
			sSaluteHint = MID(INPUT, 12, iPos)
			sh_prefix1 = IndNames3a(sSaluteHint, 16) # returns 40, but array only 16 long
			iPos = iPos + 13
			INPUT = MID(INPUT, iPos)
		END IF
	END IF
	# remove " REF " followed by numbers or punctuation
	iPos = INSTR(INPUT, " REF ")
	IF iPos > 0
		i = iPos + 4
		sBuffer = MID(INPUT, i)
		# to test if any alpha after "REF", remove alphas and compare with original
		sTemp = REPLACE(sBuffer, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", "")
		IF sTemp = sBuffer
			INPUT = LEFT(INPUT, iPos)
		END IF
	END IF
	# trim
	INPUT = TRIM(INPUT, " \t")
	# ends in DO NOT USE
	sTemp = RIGHT(INPUT, 10)
	IF sTemp = "DO NOT USE"
		sCheckFlag = sTemp
		iLen = LEN(INPUT)
		iLen = iLen - 10
		INPUT = LEFT(INPUT, iLen)
		INPUT = TRIM(INPUT, " \t")
	END IF

	# remove "in its own capacity and"
	sBuffer = UCASE(INPUT)
	iPos = INSTR(sBuffer, "IN ITS OWN CAPACITY AND")
	IF iPos > 0
		iPos = iPos + 23
		sBuffer = MID(INPUT, iPos)
		sBuffer = LTRIM(sBuffer)
		iPos = iPos - 24
		INPUT = LEFT(INPUT, iPos)
		INPUT = RTRIM(INPUT)
		INPUT = INPUT & sBuffer
	END IF

	# puts a space before "P/L" at the end if there isn't one already
	sTemp = RIGHT(INPUT, 3)
	IF sTemp = "P/L"
		iLen = LEN(INPUT)
		iLen = iLen - 3
		sTemp = MID(INPUT, iLen, 1)
		iPos = INSTR(sAllPunctuation, sTemp)
		IF iPos = 0
			INPUT = LEFT(INPUT, iLen)
			INPUT = INPUT + " P/L"
		END IF
	END IF
}

\GRAMMAR
OrgType		: TABLE orgTypeTable DELIMITERS sTypeDelimiters
OrgType2	: TABLE orgTypeTable2 DELIMITERS sTypeDelimiters
Title		: TABLE titleTable
Ampersand	: "&" <>
AndInWords	: "AND" <>
			: "and" <>
			: "And" <>
And			: Ampersand
			: AndInWords
AndOrComma	: And
			: ","
			: "-"
			: "/"
			: ";"
Relationship: TABLE RelationshipTable DELIMITERS sDelimiters \
				INNER_DELIMITERS sInnerDelimiters TOLERANCE2 10
			: OrgType(sDummy sEndItem) And(sAnd) Title(sDummy sBeginItem)
			{
				IF sAnd1 = ""
					sEndItem1 = sEndItem
					sAnd1 = sAnd
					sBeginItem1 = sBeginItem
				ELSE
					sEndItem2 = sEndItem
					sAnd2 = sAnd
					sBeginItem2 = sBeginItem
				END IF
			}
\IFDEF SPLIT_ON_AND_AFTER_ORGTYPE
			: OrgType2(sDummy sEndItem) AndOrComma(sAnd)
			{
				IF sAnd1 = ""
					sEndItem1 = sEndItem
					sAnd1 = sAnd
					sBeginItem1 = ""
				ELSE
					sEndItem2 = sEndItem
					sAnd2 = sAnd
					sBeginItem2 = ""
				END IF
			}
\ENDIF
Word		: WORD
CloseAngle	: ">"
OpenAngle	: "-<"
			: "- <"
Ftrri		: TABLE FTRRITable DELIMITERS sTypeDelimiters TOLERANCE2 7
End			: Word Relationship(sRelationship1 sRel1) Word \
				Relationship(sRelationship2 sRel) Word @
			{	sItem1 = SUB_INPUT(0, -2)
				sItem2 = SUB_INPUT(2, -4)
				sItem3 = SUB_INPUT(4)
				sItem1 = TRIM(sItem1, sTrimChars)
				sItem2 = TRIM(sItem2, sTrimChars)
				sItem3 = TRIM(sItem3, sTrimChars)
				# first relationship is an "AND" relationship
				IF sRel1 = "" # not TABLE, so 2nd definition of Relationship
					IF sAnd1 <> "" # should be true
						sItem1 = sItem1 & sEndItem1
						sItem2 = sBeginItem1 & sItem2
						sRelationship1 = "AND"
						# and second relationship is an "AND" relationship
						IF sAnd2 <> ""
							sItem2 = sItem2 & sEndItem2
							sItem3 = sBeginItem2 & sItem3
							sRelationship2 = "AND"
						END IF
					END IF
				# only second relationship is an "AND" relationship
				ELSEIF sAnd1 <> ""
					sItem2 = sItem2 & sEndItem1
					sItem3 = sBeginItem1 & sItem3
					sRelationship2 = "AND"
				END IF
				# "T A" or "TA" may be initials and not "Trading As"
				IF sRel = "TA"
					bTACheck = 1
				ELSEIF sRel = "T A"
					bTACheck = 1
				END IF
				IF bTACheck = 1
					# get two words before the "TA"
					sPreviousWord = ""
					iPos = INSTRREV(sItem2, " ")
					IF iPos > 0
						iPos = iPos + 1
						sPreviousWord = MID(sItem2, iPos)
						iPos = iPos - 2
						iPos = INSTRREV(sItem2, " ", iPos)
						IF iPos > 0
							iPos = iPos + 1
							sPreviousWords = MID(sItem2, iPos)
						END IF
					END IF
					# if previous entity ends in org name, then TA=Trading As
					sTemp = LOOKUP(sPreviousWord, orgTypeTable)
					IF sTemp = ""
						sTemp = LOOKUP(sPreviousWords, orgTypeTable)
					END IF
					IF sTemp = ""
						# only one word after it -> initials
						iPos = INSTR(sItem3, " ")
						IF iPos = 0
							sItem2 = sItem2 & sRel
							sItem2 = sItem2 & sItem3
							sItem3 = ""
							sRelationship2 = ""
						END IF
					END IF
				ELSE
					# "TF &" may be initials, not "Trust For"
					iLen = LEN(sRel)
					IF iLen = 2
						sTemp = LEFT(sItem3, 1)
						IF sTemp = "&"
							sItem2 = sItem2 & sRel
							sItem2 = sItem2 & sItem3
							sItem3 = ""
							sRelationship2 = ""
						END IF
					END IF
				END IF
				# "T A" or "TA" may be initials and not "Trading As"
				IF sRelationship2 <> ""
					IF sRel1 = "TA"
						bTACheck = 1
					ELSEIF sRel1 = "T A"
						bTACheck = 1
					ELSE
						bTACheck = 0
					END IF
					IF bTACheck = 1
						# get two words before the "TA"
						sPreviousWord = ""
						sPreviousWords = ""
						iPos = INSTRREV(sItem1, " ")
						IF iPos > 0
							iPos = iPos + 1
							sPreviousWord = MID(sItem1, iPos)
							iPos = iPos - 2
							iPos = INSTRREV(sItem1, " ", iPos)
							IF iPos > 0
								iPos = iPos + 1
								sPreviousWords = MID(sItem1, iPos)
							END IF
						END IF
						# if previous entity ends in org name, then TA=Trading As
						sTemp = LOOKUP(sPreviousWord, orgTypeTable)
						IF sTemp = ""
							sTemp = LOOKUP(sPreviousWords, orgTypeTable)
						END IF
						IF sTemp = ""
							# only one word after it -> initials
							iPos = INSTR(sItem2, " ")
							IF iPos = 0
								sItem1 = sItem1 & sRel1
								sItem1 = sItem1 & sItem2
								sItem2 = sItem3
								sRelationship1 = sRelationship2
								sRelationship2 = ""
							END IF
						END IF
					END IF
				END IF
			}
			: Relationship(sRelationship1 sRel)
			{	sItem1 = SUB_INPUT(0, -1)
				sItem2 = SUB_INPUT(1)
				sItem1 = TRIM(sItem1, sTrimChars)
				sItem2 = TRIM(sItem2, sTrimChars)
				IF sItem1 = ""
					sRelationship1 = ""
				ELSEIF sItem2 = ""
					sRelationship1 = ""
				# "and" relationship
				ELSEIF sAnd1 <> ""
					sItem1 = sItem1 & sEndItem1
					sItem2 = sBeginItem1 & sItem2
					sRelationship1 = "AND"
					sRel1 = ""
				# "T A" may be initials and not "Trading As"
				ELSE
					IF sRel = "TA"
						sRel = "T A"
					END IF
					IF sRel = "T A"
						# get two words before the "TA"
						sPreviousWord = ""
						iPos = INSTRREV(sItem1, " ")
						IF iPos > 0
							iPos = iPos + 1
							sPreviousWord = MID(sItem1, iPos)
							iPos = iPos - 2
							iPos = INSTRREV(sItem1, " ", iPos)
							IF iPos > 0
								iPos = iPos + 1
								sPreviousWords = MID(sItem1, iPos)
							END IF
						END IF
						# word before is not an org word
						sTemp = LOOKUP(sPreviousWord, orgTypeTable)
						IF sTemp = ""
							sTemp = LOOKUP(sPreviousWords, orgTypeTable)
						END IF
						IF sTemp = ""
							# only one word after it -> initials
							iPos = INSTR(sItem2, " ")
							IF iPos = 0
								sRelationship1 = ""
							# word before it is a title -> initials
							ELSE
								sTemp = LOOKUP(sPreviousWord, titleTable)
								IF sTemp <> ""
									sRelationship1 = ""
								END IF
							END IF
						END IF
					ELSE
						# "TF &" may be initials, not "Trust For"
						iLen = LEN(sRel)
						IF iLen = 2
							sTemp = LEFT(sItem2, 1)
							IF sTemp = "&"
								sRelationship1 = ""
							END IF
						END IF
					END IF
				END IF
			}
			# pick up "-<...>" or "- <...>" at field end [Sep08] SunCorp STD
			: OpenAngle CloseAngle $ @
			{
				sItem1 = SUB_INPUT(0, -1)
				sItem2 = SUB_INPUT(1, -2)
				sRelationship1 = "ACCOUNT"
			}
			# remove "For their respective rights and interests" from end
			: Ftrri $
			{
				sBuffer = SUB_INPUT(0, -1)
				INPUT = sBuffer
			}
			# 'AND' divides (if there is also an ampersand)
\IFDEF SPLIT_ON_AND_IF_THERES_AN_AMPERSAND
			: Word AndInWords Word Ampersand Word(sTemp) @
			{
				sItem1 = SUB_INPUT(0, -2)
				sItem2 = SUB_INPUT(2)
				sItem1 = TRIM(sItem1, sTrimChars)
				sItem2 = TRIM(sItem2, sTrimChars)
				sTemp = LOOKUP(sTemp, AfterAndTable)
				IF sTemp = ""
					sRelationship1 = "AND"
				END IF
			}
			: Ampersand Word AndInWords Word(sTemp) @
			{
				sItem1 = SUB_INPUT(0, -3)
				sItem2 = SUB_INPUT(3)
				sItem1 = TRIM(sItem1, sTrimChars)
				sItem2 = TRIM(sItem2, sTrimChars)
				sTemp = LOOKUP(sTemp, AfterAndTable)
				IF sTemp = ""
					sRelationship1 = "AND"
				END IF
			}
\ENDIF

\POST_PARSE {

	# no relationship -> only one item of information
	IF sRelationship1 = ""
		INPUT = sEntityHintFull + INPUT
		INPUT = sOrgOrIndividualParam + INPUT
		inputType_ = OrgOrIndividual(INPUT, 93)
	# have relationship -> two (or three) items of information
	ELSE
		# remove "For their respective rights and interests" from end
		sBuffer = sItem2
		# each loop iteration removes leading word from input (sBuffer)
		WHILE sBuffer <> ""
			sTemp = LOOKUP(sBuffer, FTRRITable)
			IF sTemp <> ""
				# remove words from input
				iLen = LEN(sBuffer) # words found at end
				i = LEN(sItem2)		# full input
				i = i - iLen
				i = i - 1
				sItem2 = LEFT(sItem2, i)	# input with words removed
				sBuffer = ""		# exit while
			ELSE
				# remove leading word
				iPos = INSTR(sBuffer, " ")
				IF iPos > 0
					iPos = iPos + 1
					sBuffer = MID(sBuffer, iPos)
				ELSE
					sBuffer = "" # exit while
				END IF
			END IF
		WEND
		# remove "For their respective rights and interests" from end
		IF sRelationship2 <> ""
			sBuffer = sItem3
			# each loop iteration removes leading word from input (sBuffer)
			WHILE sBuffer <> ""
				sTemp = LOOKUP(sBuffer, FTRRITable)
				IF sTemp <> ""
					# remove words from input
					iLen = LEN(sBuffer) # words found at end
					i = LEN(sItem3)		# full input
					i = i - iLen
					i = i - 1
					sItem3 = LEFT(sItem3, i)	# input with words removed
					sBuffer = ""		# exit while
				ELSE
					# remove leading word
					iPos = INSTR(sBuffer, " ")
					IF iPos > 0
						iPos = iPos + 1
						sBuffer = MID(sBuffer, iPos)
					ELSE
						sBuffer = "" # exit while
					END IF
				END IF
			WEND
		END IF
		#
		sItem1 = sEntityHintFull + sItem1
		sItem1 = sOrgOrIndividualParam + sItem1
		inputType_ = OrgOrIndividual(sItem1, 93)
		# trading as -> must be an organisation
		IF sRelationship1 = "TRADING AS"
			b_primName = Org3(sItem2, 28)
		ELSE
			sItem2 = sOrgOrIndividualParam + sItem2
			b_inputType = OrgOrIndividual(sItem2, 93)
		END IF

		# depending on two items, create output and relationships
		RelationshipType1_ = sRelationship1
		# number of individuals in first item (set iInd1)
		IF lastName5_ <> ""
			RelationshipFrom1_ = "i1,i2,i3,i4,i5"
			iInd1 = 5
		ELSEIF lastName4_ <> ""
			RelationshipFrom1_ = "i1,i2,i3,i4"
			iInd1 = 4
		ELSEIF lastName3_ <> ""
			RelationshipFrom1_ = "i1,i2,i3"
			iInd1 = 3
		ELSEIF lastName2_ <> ""
			RelationshipFrom1_ = "i1,i2"
			iInd1 = 2
		ELSEIF lastName1_ <> ""
			RelationshipFrom1_ = "i1"
			iInd1 = 1
		ELSE
			iInd1 = 0
		END IF
		# number of organisations in first item (set iOrg1)
		IF secName_ <> ""
			RelationshipFrom1_ = RelationshipFrom1_ & "o1,o2"
			iOrg1 = 2
		ELSEIF primName_ <> ""
			RelationshipFrom1_ = RelationshipFrom1_ & "o1"
			iOrg1 = 1
		ELSE
			iOrg1 = 0
		END IF
		# number of individuals in second item (set iInd2)
		IF b_lastName5 <> ""
			iInd2 = 5
		ELSEIF b_lastName4 <> ""
			iInd2 = 4
		ELSEIF b_lastName3 <> ""
			iInd2 = 3
		ELSEIF b_lastName2 <> ""
			iInd2 = 2
		ELSEIF b_lastName1 <> ""
			iInd2 = 1
		ELSE
			iInd2 = 0
		END IF
		# number of organisations in second item (set iOrd2)
		IF b_secName <> ""
			iOrg2 = 2
		ELSEIF b_primName <> ""
			iOrg2 = 1
		ELSE
			iOrg2 = 0
		END IF
		# move individual(s) from second item into output fields
		sBuffer = JOIN(b_prefix1, 40, "\t")
		IF iInd1 = 0
			prefix1_ = SPLIT(sBuffer, 40, "\t")
		ELSEIF iInd1 = 1
			prefix2_ = SPLIT(sBuffer, 40, "\t")
		ELSEIF iInd1 = 2
			prefix3_ = SPLIT(sBuffer, 40, "\t")
		ELSEIF iInd1 = 3
			prefix4_ = SPLIT(sBuffer, 40, "\t")
		ELSEIF iInd1 = 4
			prefix5_ = SPLIT(sBuffer, 32, "\t")
		ELSEIF iInd1 = 5
			prefix6_ = SPLIT(sBuffer, 24, "\t")
		END IF
		# move organisation(s) from second item into output fields
		sBuffer = JOIN(b_primName, 18, "\t")
		IF iOrg1 = 0
			primName_ = SPLIT(sBuffer, 18, "\t")
		ELSEIF iOrg1 = 1
			secName_ = SPLIT(sBuffer, 18, "\t")
		ELSEIF iOrg1 = 2
			thirdName_ = SPLIT(sBuffer, 9, "\t")
		END IF
		# set RelationshipTo
		IF iInd2 > 0
			i = iInd1 + 1
			s1 = STR(i)
			RelationshipTo1_ = "i" + s1
			IF iInd2 > 1
				j = iInd1 + iInd2
				WHILE i < j
					i = i + 1
					s1 = STR(i)
					RelationshipTo1_ = RelationshipTo1_ + ",i"
					RelationshipTo1_ = RelationshipTo1_ + s1
				WEND
			END IF
		END IF
		IF iOrg2 = 1
			IF iOrg1 = 0
				RelationshipTo1_ = RelationshipTo1_ & "o1"
			ELSEIF iOrg1 = 1
				RelationshipTo1_ = RelationshipTo1_ & "o2"
			ELSEIF iOrg1 = 2
				RelationshipTo1_ = RelationshipTo1_ & "o3"
			END IF
		ELSEIF iOrg2 = 2
			IF iOrg1 = 0
				RelationshipTo1_ = RelationshipTo1_ & "o1,o2"
			ELSEIF iOrg1 = 1
				RelationshipTo1_ = RelationshipTo1_ & "o2,o3"
			ELSEIF iOrg1 = 2
				RelationshipTo1_ = RelationshipTo1_ & "o3,o4"
			END IF
		END IF

		# have 2nd relationship -> three items of information
		IF sRelationship2 <> ""
			# trading as -> must be an organisation
			IF sRelationship2 = "TRADING AS"
				c_primName = Org3(sItem3, 28)
			ELSE
				c_inputType = OrgOrIndividual(sItem3, 93)
			END IF

			# depending on two items, create output and relationships
			RelationshipType2_ = sRelationship2
			# 'To' of 1st relation is 'From' of 2nd
			RelationshipFrom2_ = RelationshipTo1_
			iInd1 = iInd1 + iInd2
			iOrg1 = iOrg1 + iOrg2
			# number of individuals in third item (set iInd2)
			IF c_lastName5 <> ""
				iInd2 = 5
			ELSEIF c_lastName4 <> ""
				iInd2 = 4
			ELSEIF c_lastName3 <> ""
				iInd2 = 3
			ELSEIF c_lastName2 <> ""
				iInd2 = 2
			ELSEIF c_lastName1 <> ""
				iInd2 = 1
			ELSE
				iInd2 = 0
			END IF
			# number of organisations in third item (set iOrd2)
			IF c_secName <> ""
				iOrg2 = 2
			ELSEIF c_primName <> ""
				iOrg2 = 1
			ELSE
				iOrg2 = 0
			END IF
			# move individual(s) from third item into output fields
			sBuffer = JOIN(c_prefix1, 40, "\t")
			IF iInd1 = 0
				prefix1_ = SPLIT(sBuffer, 40, "\t")
			ELSEIF iInd1 = 1
				prefix2_ = SPLIT(sBuffer, 40, "\t")
			ELSEIF iInd1 = 2
				prefix3_ = SPLIT(sBuffer, 40, "\t")
			ELSEIF iInd1 = 3
				prefix4_ = SPLIT(sBuffer, 40, "\t")
			ELSEIF iInd1 = 4
				prefix5_ = SPLIT(sBuffer, 32, "\t")
			ELSEIF iInd1 = 5
				prefix6_ = SPLIT(sBuffer, 24, "\t")
			END IF
			# move organisation(s) from second item into output fields
			sBuffer = JOIN(c_primName, 18, "\t")
			IF iOrg1 = 0
				primName_ = SPLIT(sBuffer, 18, "\t")
			ELSEIF iOrg1 = 1
				secName_ = SPLIT(sBuffer, 18, "\t")
			ELSEIF iOrg1 = 2
				thirdName_ = SPLIT(sBuffer, 9, "\t")
			END IF
			# set RelationshipTo
			IF iInd2 > 0
				i = iInd1 + 1
				s1 = STR(i)
				RelationshipTo2_ = "i" + s1
				IF iInd2 > 1
					j = iInd1 + iInd2
					WHILE i < j
						i = i + 1
						s1 = STR(i)
						RelationshipTo2_ = RelationshipTo2_ + ",i"
						RelationshipTo2_ = RelationshipTo2_ + s1
					WEND
				END IF
			END IF
			IF iOrg2 = 1
				IF iOrg1 = 0
					RelationshipTo2_ = RelationshipTo2_ & "o1"
				ELSEIF iOrg1 = 1
					RelationshipTo2_ = RelationshipTo2_ & "o2"
				ELSEIF iOrg1 = 2
					RelationshipTo2_ = RelationshipTo2_ & "o3"
				END IF
			ELSEIF iOrg2 = 2
				IF iOrg1 = 0
					RelationshipTo2_ = RelationshipTo2_ & "o1,o2"
				ELSEIF iOrg1 = 1
					RelationshipTo2_ = RelationshipTo2_ & "o2,o3"
				ELSEIF iOrg1 = 2
					RelationshipTo2_ = RelationshipTo2_ & "o3,o4"
				END IF
			END IF
		END IF
	END IF

	# fix "AND" relationship, as it isn't really a relationship
	# - merge the second two items
	IF RelationshipType2_ = "AND"
		RelationshipTo1_ = RelationshipTo1_ + ","
		RelationshipTo1_ = RelationshipTo1_ + RelationshipTo2_
		RelationshipType2_ = ""
		RelationshipFrom2_ = ""
		RelationshipTo2_ = ""
	END IF
	IF RelationshipType1_ = "AND"
		# - no relationship
		IF RelationshipType2_ = ""
			RelationshipType1_ = ""
			RelationshipFrom1_ = ""
			RelationshipTo1_ = ""
		# - merge the first two items
		ELSE
			RelationshipFrom1_ = RelationshipFrom1_ + ","
			RelationshipFrom1_ = RelationshipFrom1_ + RelationshipTo1_
			RelationshipTo1_ = RelationshipTo2_
			RelationshipType1_ = RelationshipType2_
			RelationshipType2_ = ""
			RelationshipFrom2_ = ""
			RelationshipTo2_ = ""
		END IF
	END IF
	
	# Enhance person1 data with Title (and maybe gender) from Salutation Hint
	IF sh_lastName1 <> ""
		IF title1_ = ""
			IF sh_title1 <> ""
				# last names match
				IF sh_lastName1 = lastName1_
					# compare first name
					bMatch = 0 # false
					# hint has initial
					iLen = LEN(sh_firstName1)
					IF iLen = 1
						s1 = LEFT(firstName1_, 1)
						IF s1 = sh_firstName1
							bMatch = 1 # True
						END IF
					# hint has full name
					ELSEIF iLen > 1
						# name is initial
						iLen = LEN(firstName1_)
						IF iLen = 1
							s1 = LEFT(sh_firstName1, 1)
							IF s1 = firstName1_
								bMatch = 1
							END IF
						# compare directly (either name is full or none)
						ELSEIF firstName1_ = sh_firstName1
							bMatch = 1
						END IF
					# no initial or name in hint -> gender must match
					ELSE
						sTemp = LOOKUP(sh_title1, titleToGenderTable)
						IF sTemp <> ""
							IF sTemp = typicalGender1_
								title1_ = sh_title1
							END IF
						END IF
					END IF
					# compare middle name
					IF bMatch = 1
						bMatch = 0
						# ok if name doesn't have middle name
						IF middleName1_ = ""
							bMatch = 1
						ELSE
							iPos = INSTR(sh_middleName1, " ")
							# two middle names
							IF iPos > 0
								sInitials1 = LEFT(sh_middleName1, 1)
								iPos = iPos + 1
								sTemp = MID(sh_middleName1, iPos, 1)
								sInitials1 = sInitials1 + sTemp
								# name also has two middle names
								iPos = INSTR(middleName1_, " ")
								IF iPos > 0
									sInitials2 = LEFT(middleName1_, 1)
									iPos = iPos + 1
									sTemp = MID(middleName1_, iPos, 1)
									sInitials2 = sInitials2 + sTemp
									IF sInitials1 = sInitials2
										bMatch = 1 # True
									END IF
								END IF
							ELSE
								# hint is initial
								iLen = LEN(sh_middleName1)
								IF iLen = 1
									s1 = LEFT(middleName1_, 1)
									IF s1 = sh_middleName1
										bMatch = 1 # True
									END IF
								# hint has full name
								ELSEIF iLen > 1
									# name is initial
									iLen = LEN(middleName1_)
									IF iLen = 1
										s1 = LEFT(sh_middleName1, 1)
										IF s1 = middleName1_
											bMatch = 1
										END IF
									# name is also full
									ELSEIF middleName1_ = sh_middleName1
										bMatch = 1
									END IF
								# ok if hint doesn't have a middle name
								ELSE
									bMatch = 1
								END IF
							END IF
						END IF
					END IF
					IF bMatch = 1
						title1_ = sh_title1
						# use salutation hint to update gender
						IF sh_typicalGender1 <> ""
							IF typicalGender1_ = "_"
								typicalGender1_ = UCASE(sh_typicalGender1)
							ELSEIF typicalGender1_ = ""
								typicalGender1_ = UCASE(sh_typicalGender1)
							END IF
						END IF
					END IF
				END IF
			END IF
		END IF
	END IF
	# Enhance person2 data with Title from Salutation Hint
	IF sh_lastName2 <> ""
		IF title2_ = ""
			IF sh_title2 <> ""
				# last names match
				IF sh_lastName2 = lastName2_
					# compare first name
					bMatch = 0 # false
					# hint has initial
					iLen = LEN(sh_firstName2)
					IF iLen = 1
						s1 = LEFT(firstName2_, 1)
						IF s1 = sh_firstName2
							bMatch = 1 # True
						END IF
					# hint has full name
					ELSEIF iLen > 1
						# name is initial
						iLen = LEN(firstName2_)
						IF iLen = 1
							s1 = LEFT(sh_firstName2, 1)
							IF s1 = firstName2_
								bMatch = 1
							END IF
						# compare directly (either name is full or none)
						ELSEIF firstName2_ = sh_firstName2
							bMatch = 1
						END IF
					# no initial or name in hint -> gender must match
					ELSE
						sTemp = LOOKUP(sh_title2, titleToGenderTable)
						IF sTemp <> ""
							IF sTemp = typicalGender2_
								title2_ = sh_title2
							END IF
						END IF
					END IF
					# compare middle name
					IF bMatch = 1
						bMatch = 0
						# ok if name doesn't have middle name
						IF middleName2_ = ""
							bMatch = 1
						ELSE
							# hint is initial
							iLen = LEN(sh_middleName2)
							IF iLen = 1
								s1 = LEFT(middleName2_, 1)
								IF s1 = sh_middleName2
									bMatch = 1 # True
								END IF
							# hint has full name
							ELSEIF iLen > 1
								# name is initial
								iLen = LEN(middleName2_)
								IF iLen = 1
									s1 = LEFT(sh_middleName2, 1)
									IF s1 = middleName2_
										bMatch = 1
									END IF
								# name is also full
								ELSEIF middleName2_ = sh_middleName2
									bMatch = 1
								END IF
							# ok if hint doesn't have a middle name
							ELSE
								bMatch = 1
							END IF
						END IF
					END IF
					IF bMatch = 1
						title2_ = sh_title2
						# use salutation hint to update gender
						IF sh_typicalGender2 <> ""
							IF typicalGender2_ = "_"
								typicalGender2_ = UCASE(sh_typicalGender2)
							ELSEIF typicalGender2_ = ""
								typicalGender2_ = UCASE(sh_typicalGender2)
							END IF
						END IF
					END IF
				END IF
			END IF
		END IF
	END IF

	# use GenderHint to resolve ambiguity
	IF sGenderHint <> ""
		IF lastName1_ <> ""
			IF typicalGender1_ = "_"
				typicalGender1_ = sGenderHint
			ELSEIF typicalGender1_ = ""
				typicalGender1_ = sGenderHint
			END IF
		END IF
	END IF
	# set checkFlag flag from b_* & c_*
	checkFlag_ = checkFlag_ + b_checkFlag
	checkFlag_ = checkFlag_ + c_checkFlag
	checkFlag_ = checkFlag_ & sCheckFlag

	# check for parsing problem: 1-letter surname
	iLen = LEN(lastName1_)
	IF iLen = 1
		checkFlag_ = checkFlag & "1"
	ELSE
		iLen = LEN(lastName2_)
		IF iLen = 1
			checkFlag_ = checkFlag & "1"
		ELSE
			iLen = LEN(lastName3_)
			IF iLen = 1
				checkFlag_ = checkFlag & "1"
			ELSE
				iLen = LEN(lastName4_)
				IF iLen = 1
					checkFlag_ = checkFlag & "1"
				ELSE
					iLen = LEN(lastName5_)
					IF iLen = 1
						checkFlag_ = checkFlag & "1"
					ELSE
						iLen = LEN(lastName6_)
						IF iLen = 1
							checkFlag_ = checkFlag & "1"
						ELSE
							iLen = LEN(lastName7_)
							IF iLen = 1
								checkFlag_ = checkFlag & "1"
							ELSE
								iLen = LEN(lastName8_)
								IF iLen = 1
									checkFlag_ = checkFlag & "1"
								END IF
							END IF
						END IF
					END IF
				END IF
			END IF
		END IF
	END IF

	# check for parsing problem: pre or post company info
	IF primPreOrg_ <> ""
		checkFlag_ = checkFlag & "P"
	ELSEIF primPostOrg_ <> ""
		checkFlag_ = checkFlag & "P"
	ELSEIF secPreOrg_ <> ""
		checkFlag_ = checkFlag & "P"
	ELSEIF secPostOrg_ <> ""
		checkFlag_ = checkFlag & "P"
	ELSEIF thirdPreOrg_ <> ""
		checkFlag_ = checkFlag & "P"
	ELSEIF thirdPostOrg_ <> ""
		checkFlag_ = checkFlag & "P"
	END IF

	# Including grammar to finish POST_PARSE section
