1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
pattern = "(?i)([\w\d]+)\s*@\s*INDI"
reIndi = New Regex(pattern)
pattern = "(?i)([\w\d]+)[\s]*@\s*FAM"
reFami = New Regex(pattern)
pattern = "(.*)\/(.*)\/"
reNom = New Regex(pattern)
pattern = "(?is)(?<typ>[a-z]+)[\s\n]+(?<rec>.*)[\n\r]{0,2}"
reAll = New Regex(pattern)
pattern = "(?im)2 plac\s(.*?)[\n\r]+"
reLnLd = New Regex(pattern)
pattern = "(?im)2 DATE\s(.*?)[\n\r]+"
reDnd = New Regex(pattern)
'Read the file into buf2
buf2 = File.ReadAllText(strfilename, System.Text.Encoding.GetEncoding(1252))
buf1 = Regex.Split(buf2, "0\s+@\s*")
buf2 = ""
'parse buf1 to detect indi or fami records
For i As Integer = 1 To UBound(buf1)
record = buf1(i)
'look for indi record
'0 @2I@ INDI
'1 NAME /ARNAUD/
'2 SURN ARNAUD
'1 SEX F
'1 BIRT
'2 Type Naissance
'2 DATE ABT 1836
'1 FAMS @5537U@
'1 FAMC @5536U@
'1 NCHI 1
'1 NMR 1
' indis are reordered in progressive ordinal numbering starting from y1=1
If (reIndi.IsMatch(record)) Then 'test if found indi
xf = New xindi
fields1 = Regex.Split(record, "(?ims)^1 ")
For j As Integer = 1 To UBound(fields1)
For Each match As Match In reAll.Matches(fields1(j))
typ = match.Groups("typ").Value
rec = match.Groups("rec").Value
Select Case typ
Case "NAME"
mymatch = reNom.Match(rec)
If mymatch.Success Then
xf.fa = mymatch.Groups(2).Value
xf.pr = mymatch.Groups(1).Value
Else
xf.fa = "?"
End If
Case "SEX"
xf.sx = If(rec.Trim() = "M", "H", If(rec = "", "", "F"))
Case "BIRT"
xf.dn = reDnd.Match(rec).Groups(1).Value
xf.ln = reLnLd.Match(rec).Groups(1).Value
Case "DEAT"
xf.dd = reDnd.Match(rec).Groups(1).Value
xf.ld = reLnLd.Match(rec).Groups(1).Value
Case "NOTE"
xf.note = xf.note & Regex.Replace(rec, ";\n|;|\s$", "")
Case "OCCU"
xf.note = xf.note & Regex.Replace(rec, ";\n|;|\s$", "")
Case "FAMC"
xf.mp = Regex.Replace(rec, "@|\s$", "")
End Select
Next
Next |
Partager