Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix surname extraction #66

Open
apple-phi opened this issue Aug 12, 2024 · 1 comment · May be fixed by #67
Open

Fix surname extraction #66

apple-phi opened this issue Aug 12, 2024 · 1 comment · May be fixed by #67

Comments

@apple-phi
Copy link

In the JSON generator, it assumes the Western convention of forename surname. This is a format not specified by GEDCOM, which instead says (in GEDCOM 5.5.5) that:

The surname of an individual, if known, is enclosed between two slash (/) characters. The order of the name parts should be the order that the person would, by custom of their culture,have used when giving it to a recorder.

Examples

William Lee /Parry/ - given name William Lee, surname Parry
William Lee - given name only or surname not known
/Parry/ - surname only
William Lee /Mac Parry/ - both Mac and Parry are part of the surname Mac Parry
William /Parry/ Boatsman - surname Parry embedded in the name string
William Lee /Pa.../ - surname partly unknown (unreadable)

In the current behaviour, any text after the surname is discarded. This is a bug.

The current implementation is the following:

topola/src/gedcom.ts

Lines 34 to 40 in f493984

function extractName(name: string): { firstName?: string; lastName?: string } {
const arr = name.split('/');
if (arr.length === 1) {
return { firstName: arr[0].trim() };
}
return { firstName: arr[0].trim(), lastName: arr[1].trim() };
}


I propose changing it to something like this:

function extractName(name: string): { firstName?: string; lastName?: string } {
  const matches = name.match(/\/([^\/]+)\//);
  if (matches) {
    const lastName = matches[1].trim();
    // Replace the last name part (including slashes) and trim the result
    let firstName = name.replace(matches[0], '').trim();
    // Replace any occurrence of double spaces with a single space
    firstName = firstName.replace(/\s\s+/g, ' ');
    return { 
      firstName: firstName || undefined, 
      lastName: lastName 
    };
  } else {
    // If no last name is found, just return the trimmed and cleaned firstName
    return { firstName: name.trim().replace(/\s\s+/g, ' ') };
  }
}

Which results in:

extractName("William Lee /Mac Pa.../ Boatsman")
// {"firstName": "William Lee Boatsman", "lastName": "Mac Pa..."}

This way at least, no information is lost (even if it may not be presented in the desired order on topola).

@apple-phi apple-phi changed the title Handle non-Western naming conventions Fix surname extraction Aug 12, 2024
@apple-phi apple-phi linked a pull request Aug 12, 2024 that will close this issue
@apple-phi
Copy link
Author

A further improvement would be to let the user specify the order / format of the names visualised to be either forename surname or surname forename

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant