berkmancenter / namae

Namae (名前) parses personal names and splits them into their component parts.
159 stars 32 forks source link

Fantastic gem, can I give it formatting hints? or parse last first middle etc #1

Closed dnajd closed 10 years ago

dnajd commented 10 years ago

I notice it recognizes last, first middle etc

but believe it needs the comma. if I feed it a name like last first middle etc

without a comma it can't figure it out. but would be nice to be able to give it hints of the format. Is this already available?

inukshuk commented 10 years ago

Single names are supported whether you use a comma or not; see the examples here https://github.com/berkmancenter/namae#format-and-examples — we distinguish between sort-order and display-order, i.e.:

Alan Turing #-> display-order
Turing, Alan #-> sort-order

When you have multiple names it's a little more tricky, because the comma is often used to separate individual names as well as name parts. You can set the prefer_comma_as_separator option to tell Namae that the comma should be used as a separator. Look here to see all options and their default values: https://github.com/berkmancenter/namae/blob/master/lib/namae/parser.y#L96

Middle names are not parsed because the concept of 'middle name' is mostly a matter of personal taste. However, it's easy to split the given names if you're interested in that information.

inukshuk commented 10 years ago

I noticed in your example: last first middle would not work without a comma, but if you write it as first middle last it will work. So basically, when using a comma the last name comes first; when not using a comma it comes last. Notice that this means that if you have multiple last names (which is very common in Spanish for instance) you need to use the comma.