mirror of
https://github.com/IliesAllali/parenthese.git
synced 2026-11-06 23:32:08 +00:00
kinship: compute cousin type by degree and removal
Signed-off-by: Arc676/Alessandro Vinciguerra <alesvinciguerra@gmail.com>
This commit is contained in:
1 parent
e2468f6d39
commit
e0f7eb4913
2 files changed
+33
-4
No files matched your search
@@ -3,6 +3,32 @@ import { kinshipFacts } from './facts.js'
|
||||
// Mot genré quand le sexe de la personne nommée est connu, forme neutre ou double sinon
|
||||
const g = (sex, male, female, neutral) => (sex === 'male' ? male : sex === 'female' ? female : neutral)
|
||||
|
||||
function ordinal(n) {
|
||||
switch (n) {
|
||||
case 1:
|
||||
return "First"
|
||||
case 2:
|
||||
return "Second"
|
||||
case 3:
|
||||
return "Third"
|
||||
default:
|
||||
return `{n}th`
|
||||
}
|
||||
}
|
||||
|
||||
function times(n) {
|
||||
switch (n) {
|
||||
case 1:
|
||||
return "once"
|
||||
case 2:
|
||||
return "twice"
|
||||
case 3:
|
||||
return "thrice"
|
||||
default:
|
||||
return `${n} times`
|
||||
}
|
||||
}
|
||||
|
||||
export default function nameEn(path) {
|
||||
const { ups, downs, hasSpouse, sex } = kinshipFacts(path)
|
||||
|
||||
@@ -36,10 +62,8 @@ export default function nameEn(path) {
|
||||
else if (ups >= 2 && downs >= 2) {
|
||||
const degree = Math.min(ups, downs) - 1
|
||||
const removed = Math.abs(ups - downs)
|
||||
if (degree === 1 && removed === 0) label = 'First cousin'
|
||||
else if (degree === 1) label = 'First cousin once removed'
|
||||
else if (removed === 0) label = `Cousin, degree ${degree}`
|
||||
else label = 'Distant cousin'
|
||||
if (removed === 0) label = `${ordinal(degree)} cousin`
|
||||
else label = `${ordinal(degree)} cousin, ${times(removed)} removed`
|
||||
} else label = `${ups + downs} steps apart`
|
||||
|
||||
return hasSpouse ? `${label} by marriage` : label
|
||||
|
||||
@@ -67,6 +67,11 @@ describe('nommage anglais', () => {
|
||||
expect(bothEn(['spouse', 'sibling'])).toEqual(['Brother-in-law', 'Sister-in-law', 'Brother/sister-in-law'])
|
||||
expect(bothEn(['spouse'])).toEqual(['Partner', 'Partner', 'Partner'])
|
||||
expect(bothEn(['up', 'sibling', 'down'])).toEqual(['First cousin', 'First cousin', 'First cousin'])
|
||||
expect(bothEn(['up', 'up', 'sibling', 'down', 'down'])).toEqual(['Second cousin', 'Second cousin', 'Second cousin'])
|
||||
expect(bothEn(['up', 'up', 'sibling', 'down'])).toEqual(['First cousin, once removed', 'First cousin, once removed', 'First cousin, once removed'])
|
||||
expect(bothEn(['up', 'up', 'up', 'up', 'up', 'up', 'sibling', 'down', 'down', 'down'])).toEqual(['Third cousin, thrice removed', 'Third cousin, thrice removed', 'Third cousin, thrice removed'])
|
||||
expect(bothEn(['up', 'up', 'up', 'sibling', 'down'])).toEqual(['First cousin, twice removed', 'First cousin, twice removed', 'First cousin, twice removed'])
|
||||
expect(bothEn(['up', 'up', 'up', 'up', 'up', 'sibling', 'down'])).toEqual(['First cousin, 4 times removed', 'First cousin, 4 times removed', 'First cousin, 4 times removed'])
|
||||
})
|
||||
|
||||
it('une langue inconnue retombe sur l’anglais', () => {
|
||||
|
||||
Reference in new issue
Block a user