GithubHelp home page GithubHelp logo

Comments (5)

aeshirey avatar aeshirey commented on June 4, 2024

I wonder if this might be more elegantly solved by post-parsing the last name according to the prefixes? Or, if the goal is to be able to better sort, maybe a simple public property that filters out last name prefixes that can be used for LINQ sorting. For example:

public string RawSurname
  {
    get
    {
        return string.Join(" ", _LastList
            .SelectMany(part => part.Split(' '))
            .SkipWhile(part => Prefixes.Contains(part)));
    }
}

This would give you the ability to do the following:

[TestMethod]
public void RawSurname()
{
    var parsed = new HumanName("John Smith");
    Assert.AreEqual(parsed.RawSurname, "Smith");

    parsed = new HumanName("Johannes van der Waals");
    Assert.AreEqual(parsed.RawSurname, "Waals");
}

And therefore, do something as follows:

var people = new [] { "John X", "Johannes van der Waals", "Juan de Zapata" };
var parsed = people
    .Select(person => new HumanName(person))
    .OrderBy(person => person.RawSurname)
    .Select(person => string.Format("{0}, {1}", person.Last, person.First);

// parsed:
// van der Waals, Johannes
// X, John
// de Zapata, Juan

from nameparsersharp.

Toxaris-NL avatar Toxaris-NL commented on June 4, 2024

While that would seem to sort the sorting issue partially, it would not be a complete solution. The display would also be different (Waals, Johannes van der). Also, if the 'RawSurname' is the same, the sorting will use the prefixes to determine the sequence. So, 'Linden, van der' comes after 'Linden, van den'.
The routine you mentioned can be used as a base for that of course, but if the prefixes would be a seperate attribute, it would be a lot easier. In databases they are also stored in a different field or as 'Linden, van der'. It would make processing names easier.

I do understand the reluctance though of implementing this.

from nameparsersharp.

aeshirey avatar aeshirey commented on June 4, 2024

According to Wikipedia:

In the Netherlands, and Suriname, names starting with "van" are filed under the initial letter of the following name proper, so Johannes van der Waals is filed under "W", as: Waals, Johannes van der or van der Waals, Johannes

You've got better cultural context than I do, but this is basically what I have to inform myself. So I think the biggest question with regard to this change is whether this library should presume anything about displaying the name or whether it should just separate out last name prefixes from the base last name. I'm inclined to think the latter and leave formatting to the caller. For example:

var person = new HumanName("Johannes van der Waals");
Assert.AreEqual("Johannes", person.First);
Assert.AreEqual("van der", person.LastPrefixes); // specifically, the prefixes to the last name
Assert.AreEqual("Waals", person.LastBase); // only the base component of the last name
Assert.AreEqual("van der Waals", person.Last); // the full last name, combined

This means you can still easily sort by the base name but further discriminate based on the prefixes:

IEnumerable<HumanName> people = getPeople();
var sorted = people
   .OrderBy(person => person.LastBase)
   .ThenBy(person => person.LastPrefixes);

Yet you can also format according to your own needs:

Console.WriteLine("{0}, {1} {2}", person.LastBase, person.First, person.LastPrefixes); // "Waals, Johannes van der"
Console.WriteLine("{0}, {1}", person.Last, person.First); // "van der Waals, Johannes"

from nameparsersharp.

Toxaris-NL avatar Toxaris-NL commented on June 4, 2024

Hmm, perhaps in Suriname, but Wikipedia is wrong about the Netherlands for sure. What you propose will work I guess. In that way, the prefixes can be separated from the lastname if you want, but not be obliged to.

from nameparsersharp.

aeshirey avatar aeshirey commented on June 4, 2024

Pushed new code with unit tests. The NuGet Package has been updated to include this code as well.

from nameparsersharp.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.