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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
<?php
/**
* webtrees: online genealogy
* Copyright (C) 2026 webtrees development team
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Fisharebest\Webtrees\Services;
use Fisharebest\Webtrees\Gedcom;
/**
* Utilities for manipulating GEDCOM data.
*/
class GedcomService
{
// Some applications, such as FTM, use GEDCOM tag names instead of the tags.
private const array TAG_NAMES = [
'ABBREVIATION' => 'ABBR',
'ADDRESS' => 'ADDR',
'ADDRESS1' => 'ADR1',
'ADDRESS2' => 'ADR2',
'ADDRESS3' => 'ADR3',
'ADOPTION' => 'ADOP',
'AGENCY' => 'AGNC',
'ALIAS' => 'ALIA',
'ANCESTORS' => 'ANCE',
'ANCES_INTEREST' => 'ANCI',
'ANULMENT' => 'ANUL',
'ASSOCIATES' => 'ASSO',
'AUTHOR' => 'AUTH',
'BAPTISM-LDS' => 'BAPL',
'BAPTISM' => 'BAPM',
'BAR_MITZVAH' => 'BARM',
'BAS_MITZVAH' => 'BASM',
'BIRTH' => 'BIRT',
'BLESSING' => 'BLES',
'BURIAL' => 'BURI',
'CALL_NUMBER' => 'CALN',
'CASTE' => 'CAST',
'CAUSE' => 'CAUS',
'CENSUS' => 'CENS',
'CHANGE' => 'CHAN',
'CHARACTER' => 'CHAR',
'CHILD' => 'CHIL',
'CHRISTENING' => 'CHR',
'ADULT_CHRISTENING' => 'CHRA',
'CONCATENATION' => 'CONC',
'CONFIRMATION' => 'CONF',
'CONFIRMATION-LDS' => 'CONL',
'CONTINUED' => 'CONT',
'COPYRIGHT' => 'COPY',
'CORPORTATE' => 'CORP',
'CREMATION' => 'CREM',
'COUNTRY' => 'CTRY',
'DEATH' => 'DEAT',
'DESCENDANTS' => 'DESC',
'DESCENDANTS_INT' => 'DESI',
'DESTINATION' => 'DEST',
'DIVORCE' => 'DIV',
'DIVORCE_FILED' => 'DIVF',
'PHY_DESCRIPTION' => 'DSCR',
'EDUCATION' => 'EDUC',
'EMIGRATION' => 'EMIG',
'ENDOWMENT' => 'ENDL',
'ENGAGEMENT' => 'ENGA',
'EVENT' => 'EVEN',
'FAMILY' => 'FAM',
'FAMILY_CHILD' => 'FAMC',
'FAMILY_FILE' => 'FAMF',
'FAMILY_SPOUSE' => 'FAMS',
'FACIMILIE' => 'FAX',
'FIRST_COMMUNION' => 'FCOM',
'FORMAT' => 'FORM',
'PHONETIC' => 'FONE',
'GEDCOM' => 'GEDC',
'GIVEN_NAME' => 'GIVN',
'GRADUATION' => 'GRAD',
'HEADER' => 'HEAD',
'HUSBAND' => 'HUSB',
'IDENT_NUMBER' => 'IDNO',
'IMMIGRATION' => 'IMMI',
'INDIVIDUAL' => 'INDI',
'LANGUAGE' => 'LANG',
'LATITUDE' => 'LATI',
'LONGITUDE' => 'LONG',
'MARRIAGE_BANN' => 'MARB',
'MARR_CONTRACT' => 'MARC',
'MARR_LICENSE' => 'MARL',
'MARRIAGE' => 'MARR',
'MEDIA' => 'MEDI',
'NATIONALITY' => 'NATI',
'NATURALIZATION' => 'NATU',
'CHILDREN_COUNT' => 'NCHI',
'NICKNAME' => 'NICK',
'MARRIAGE_COUNT' => 'NMR',
'NAME_PREFIX' => 'NPFX',
'NAME_SUFFIX' => 'NSFX',
'OBJECT' => 'OBJE',
'OCCUPATION' => 'OCCU',
'ORDINANCE' => 'ORDI',
'ORDINATION' => 'ORDN',
'PEDIGREE' => 'PEDI',
'PHONE' => 'PHON',
'PLACE' => 'PLAC',
'POSTAL_CODE' => 'POST',
'PROBATE' => 'PROB',
'PROPERTY' => 'PROP',
'PUBLICATION' => 'PUBL',
'QUALITY_OF_DATA' => 'QUAY',
'REFERENCE' => 'REFN',
'RELATIONSHIP' => 'RELA',
'RELIGION' => 'RELI',
'REPOSITORY' => 'REPO',
'RESIDENCE' => 'RESI',
'RESTRICTION' => 'RESN',
'RETIREMENT' => 'RETI',
'REC_FILE_NUMBER' => 'RFN',
'REC_ID_NUMBER' => 'RIN',
'ROMANIZED' => 'ROMN',
'SEALING_CHILD' => 'SLGC',
'SEALING_SPOUSE' => 'SLGS',
'SOURCE' => 'SOUR',
'SURN_PREFIX' => 'SPFX',
'SOC_SEC_NUMBER' => 'SSN',
'STATE' => 'STAE',
'STATUS' => 'STAT',
'SUBMITTER' => 'SUBM',
'SUBMISSION' => 'SUBN',
'SURNAME' => 'SURN',
'TEMPLE' => 'TEMP',
'TITLE' => 'TITL',
'TRAILER' => 'TRLR',
'VERSION' => 'VERS',
'WEB' => 'WWW',
'_DEATH_OF_SPOUSE' => 'DETS',
'_DEGREE' => '_DEG',
'_MEDICAL' => '_MCL',
'_MILITARY_SERVICE' => '_MILT',
];
// Custom GEDCOM tags used by other applications, with direct synonyms
private const array TAG_SYNONYMS = [
// Convert PhpGedView tag to webtrees
'_PGVU' => '_WT_USER',
'_PGV_OBJS' => '_WT_OBJE_SORT',
];
/**
* Convert a GEDCOM tag to a canonical form.
*
* @param string $tag
*
* @return string
*/
public function canonicalTag(string $tag): string
{
$tag = strtoupper($tag);
$tag = self::TAG_NAMES[$tag] ?? self::TAG_SYNONYMS[$tag] ?? $tag;
return $tag;
}
public function readLatitude(string $text): float|null
{
return $this->readDegrees($text, Gedcom::LATITUDE_NORTH, Gedcom::LATITUDE_SOUTH);
}
public function readLongitude(string $text): float|null
{
return $this->readDegrees($text, Gedcom::LONGITUDE_EAST, Gedcom::LONGITUDE_WEST);
}
private function readDegrees(string $text, string $positive, string $negative): float|null
{
$text = trim($text);
$hemisphere = substr($text, 0, 1);
$degrees = substr($text, 1);
// Match a valid GEDCOM format
if (is_numeric($degrees)) {
$hemisphere = strtoupper($hemisphere);
$degrees = (float) $degrees;
if ($hemisphere === $positive) {
return $degrees;
}
if ($hemisphere === $negative) {
return -$degrees;
}
}
// Just a number?
if (is_numeric($text)) {
return (float) $text;
}
// Can't match anything.
return null;
}
}
|