简体   繁体   English

是否可以将全名转换为名字和姓氏?

[英]Is it possible to convert full name to firstname and lastname?

I need to convert full name to first and last name. 我需要将全名转换为名字和姓氏。 Is this possible within ~90% success rate if names are mostly western? 如果名字大多是西方的,这是否有可能在90%的成功率内?

You assume that "western names" all have the same simple format. 您假定“西方名称”都具有相同的简单格式。 That is not so. 事实并非如此。 For example, Spanish names generally have two "last names", but can get quite a bit more complicated. 例如, 西班牙语名称通常具有两个 “姓氏”,但可能会变得更加复杂。

Many European countries have nobility particles that can complicate names. 许多欧洲国家的贵族分子可以使名字复杂化。

Names are cultural, and cultures are much more diverse and complex than most people imagine. 名字是文化的,文化比大多数人想象的要多样化和复杂得多。 Even in "the West". 即使在“西方”。

I don't think so. 我不这么认为。 It mostly depends on the data that you have available. 它主要取决于您可用的数据。 If the user always enters "Firstname Lastname" then you can check for the last whitespace, perform a separation and that's it. 如果用户总是输入“ Firstname Lastname”,那么您可以检查最后一个空格,执行分隔,仅此而已。

But for the typical German customer there are a wide range of possible missing matches. 但是对于典型的德国客户来说,可能会丢失很多匹配项。 Names like "Hans Ulrich-Schmidt" where the user forgets the dash (or even worse, explicitely doesn't enter it) will not be parsed correctly. 诸如“ Hans Ulrich-Schmidt”之类的名称将使用户忘记破折号(或更糟的是,明确地不输入破折号),将无法正确解析。 But there is no clear way to determine whether the "Ulrich" in "Hans Ulrich Schmidt" ist part of the first or the last name. 但是没有明确的方法来确定“汉斯·乌尔里希·施密特”中的“乌尔里希”是姓还是名。

That's just one example, there are many more so I think: No, it's not possible. 那只是一个例子,还有更多例子,我想:不,这不可能。

Assuming that your input is FirstName Name Name LastName, split the string and use first and last indexes: 假设您输入的是FirstName Name Name LastName,请分割字符串并使用first和last索引:

String bigName = "John McDonalds Harris"
String[] names = bigName.split(" ");
System.out.println(String.format("FirstName: %s : LastName: %s", names[0], names[names.length-1])); 

It will print : FistName: John : LastName: Harris 它将打印:FistName:John:LastName:Harris

It depends on the initial format. 这取决于初始格式。 For example in VCards the standard format is 例如,在VCards中,标准格式为

LastName;FirstName

The delimiter is semicolon. 分隔符是分号。

In general case it is extremely hard. 通常情况下,这非常困难。 I agree with guys that already said this. 我同意那些已经说过的话。 If you seriously want to solve the problem you have to implement Locale dependent parser. 如果您真的想解决该问题,则必须实现依赖于语言环境的解析器。 For example English are usually composed as first name and then last name. 例如,英语通常由名字和姓组成。 Hungarians write last name and then first names. 匈牙利人写下姓氏,然后写下名字。 In Russian it is more complicated: sometimes it is first name and last name, sometimes they use reverse order. 俄语更复杂:有时是名字和姓氏,有时它们使用相反的顺序。 It depends on the text style. 这取决于文本样式。 The reverse order is used in more formal texts. 在更正式的文本中使用相反的顺序。

You can try to use dictionaries of first and last names. 您可以尝试使用名字和姓氏的字典。 This can help in some cases. 在某些情况下这可能会有所帮助。 But what to do with name like "Elton John"? 但是,使用“ Elton John”之类的名字怎么办? And what about "Warren Christopher"? 那“沃伦·克里斯托弗”呢? and "Christopher Robin"? 和“克里斯托弗·罗宾”?

Probably if you have a large list of names and all names are written using the same format you can first detect the style using names dictionary and then use it. 如果您的名称列表很大,并且所有名称都使用相同的格式书写,则可以先使用名称字典检测样式,然后再使用它。 You will probably get 90% of success. 您可能会获得90%的成功。

Good luck 祝好运

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM