xref: /webtrees/app/SurnameTradition/LithuanianSurnameTradition.php (revision 59597b37d69e8147c3f4a27643e9c8edaa2a0592)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2019 webtrees development team
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18declare(strict_types=1);
19
20namespace Fisharebest\Webtrees\SurnameTradition;
21
22/**
23 * Lithuanian — Children take their father’s surname. Wives take their husband’s surname. Surnames are inflected to indicate an individual’s sex and marital status.
24 */
25class LithuanianSurnameTradition extends PaternalSurnameTradition
26{
27    // Inflect a surname for wives
28    private const INFLECT_WIFE = [
29        'as\b' => 'ienė',
30        'is\b' => 'ienė',
31        'ys\b' => 'ienė',
32        'us\b' => 'ienė',
33    ];
34
35    // Inflect a surname for daughters
36    private const INFLECT_DAUGHTER = [
37        'a\b'   => 'aitė',
38        'as\b'  => 'aitė',
39        'is\b'  => 'ytė',
40        'ys\b'  => 'ytė',
41        'ius\b' => 'iūtė',
42        'us\b'  => 'utė',
43    ];
44
45    // Inflect a surname for males
46    private const INFLECT_MALE = [
47        'aitė\b' => 'as',
48        'ytė\b'  => 'is',
49        'iūtė\b' => 'ius',
50        'utė\b'  => 'us',
51    ];
52
53    /**
54     * What names are given to a new child
55     *
56     * @param string $father_name A GEDCOM NAME
57     * @param string $mother_name A GEDCOM NAME
58     * @param string $child_sex   M, F or U
59     *
60     * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
61     */
62    public function newChildNames(string $father_name, string $mother_name, string $child_sex): array
63    {
64        if (preg_match(self::REGEX_SURN, $father_name, $match)) {
65            if ($child_sex === 'F') {
66                return array_filter([
67                    'NAME' => $this->inflect($match['NAME'], self::INFLECT_DAUGHTER),
68                    'SURN' => $this->inflect($match['SURN'], self::INFLECT_MALE),
69                ]);
70            }
71
72            return array_filter([
73                'NAME' => $match['NAME'],
74                'SURN' => $match['SURN'],
75            ]);
76        }
77
78        return [
79            'NAME' => '//',
80        ];
81    }
82
83    /**
84     * What names are given to a new parent
85     *
86     * @param string $child_name A GEDCOM NAME
87     * @param string $parent_sex M, F or U
88     *
89     * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
90     */
91    public function newParentNames(string $child_name, string $parent_sex): array
92    {
93        if ($parent_sex === 'M' && preg_match(self::REGEX_SURN, $child_name, $match)) {
94            return array_filter([
95                'NAME' => $this->inflect($match['NAME'], self::INFLECT_MALE),
96                'SURN' => $this->inflect($match['SURN'], self::INFLECT_MALE),
97            ]);
98        }
99
100        return [
101            'NAME' => '//',
102        ];
103    }
104
105    /**
106     * What names are given to a new spouse
107     *
108     * @param string $spouse_name A GEDCOM NAME
109     * @param string $spouse_sex  M, F or U
110     *
111     * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
112     */
113    public function newSpouseNames(string $spouse_name, string $spouse_sex): array
114    {
115        if ($spouse_sex === 'F' && preg_match(self::REGEX_SURN, $spouse_name, $match)) {
116            return [
117                'NAME'   => '//',
118                '_MARNM' => $this->inflect($match['NAME'], self::INFLECT_WIFE),
119            ];
120        }
121
122        return [
123            'NAME' => '//',
124        ];
125    }
126}
127