本文介绍了将一个人的名字解析为其组成部分的简单方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

许多联系人管理程序都这样做 - 您输入一个名字(例如,John W. Smith"),它会在内部自动将其分解为:

A lot of contact management programs do this - you type in a name (e.g., "John W. Smith") and it automatically breaks it up internally into:

名字:约翰
中间名: W.
姓氏:史密斯

同样,它会计算出诸如Jane W. Smith 夫人"和John Doe, Jr. 博士"之类的内容.也正确(假设您允许名称中的前缀"和后缀"等字段).

Likewise, it figures out things like "Mrs. Jane W. Smith" and "Dr. John Doe, Jr." correctly as well (assuming you allow for fields like "prefix" and "suffix" in names).

我认为这是人们想要做的相当普遍的事情......所以问题是......你会怎么做?是否有一个简单算法?也许是正则表达式?

I assume this is a fairly common things that people would want to do... so the question is... how would you do it? Is there a simple algorithm for this? Maybe a regular expression?

我追求 .NET 解决方案,但我并不挑剔.

I'm after a .NET solution, but I'm not picky.

更新:我很欣赏没有简单的解决方案可以涵盖所有边缘情况和文化......表格 - 例如,税收或其他政府表格 - 是一种情况,您必须在固定字段中输入名称,无论您喜欢与否),但您不一定要强迫用户输入他们的将名称命名为离散字段(更少的输入 = 新手用户更容易).

Update: I appreciate that there is no simple solution for this that covers ALL edge cases and cultures... but let's say for the sake of argument that you need the name in pieces (filling out forms - as in, say, tax or other government forms - is one case where you are bound to enter the name into fixed fields, whether you like it or not), but you don't necessarily want to force the user to enter their name into discrete fields (less typing = easier for novice users).

您希望程序猜测"(尽其所能)首先、中间、最后等内容.如果可以,请查看 Microsoft Outlook 如何为联系人执行此操作 - 它允许您输入名称,但如果您需要澄清,您可以打开一个额外的小窗口.我会做同样的事情 - 为用户提供窗口,以防他们想以离散的形式输入名称 - 但允许在一个框中输入名称并进行覆盖大多数 常用名称.

You'd want to have the program "guess" (as best it can) on what's first, middle, last, etc. If you can, look at how Microsoft Outlook does this for contacts - it lets you type in the name, but if you need to clarify, there's an extra little window you can open. I'd do the same thing - give the user the window in case they want to enter the name in discrete pieces - but allow for entering the name in one box and doing a "best guess" that covers most common names.

推荐答案

对此没有简单的解决方案.名称构建因文化而异,即使在英语世界,也有前缀和后缀不一定是名称的一部分.

There is no simple solution for this. Name construction varies from culture to culture, and even in the English-speaking world there's prefixes and suffixes that aren't necessarily part of the name.

一种基本方法是在字符串的开头查找敬语(例如,Hon. John Doe"),在结尾查找数字或其他一些字符串(例如,John Doe IV"、John Doe Jr.")."),但实际上您所能做的就是应用一组启发式方法并希望获得最好的结果.

A basic approach is to look for honorifics at the beginning of the string (e.g., "Hon. John Doe") and numbers or some other strings at the end (e.g., "John Doe IV", "John Doe Jr."), but really all you can do is apply a set of heuristics and hope for the best.

查找未处理名称的列表并针对它测试您的算法可能很有用.不过,我不知道有没有预先包装好的东西.

It might be useful to find a list of unprocessed names and test your algorithm against it. I don't know that there's anything prepackaged out there, though.

这篇关于将一个人的名字解析为其组成部分的简单方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 22:44
查看更多