Comments (5)
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.
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.
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
orvan 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.
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.
Pushed new code with unit tests. The NuGet Package has been updated to include this code as well.
from nameparsersharp.
Related Issues (16)
- Nickname parsing failed when single quotes are used and nickname is at beginning of string HOT 2
- Additional prefix (for config.cs) HOT 2
- Improvement: A few examples that aren't parsing properly HOT 2
- NuGet DLL version is incorrect HOT 2
- Parser throws ArgumentOutOfRangeExceptionexception when name has parenthesis (just nickname) HOT 1
- Incorrectly identifying name parts HOT 3
- Name with suffix and last name prefix fail to parse correctly
- Support for netstandard HOT 1
- Invalid Name Parsing HOT 1
- Invalid Parsing HOT 1
- Request functionality to add to lists. HOT 3
- Request to accept 2 names in first name
- First name is a known prefix HOT 8
- First Name is a Known Title HOT 6
- D'Juan O'Connor does not parse properly
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nameparsersharp.