用户输入解析-城市/州/邮政编码/国家/地区 [英] User input parsing - city / state / zipcode / country

查看:182
本文介绍了用户输入解析-城市/州/邮政编码/国家/地区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找有关分析用户输入的城市/州/邮政编码/国家/地区多种组合的建议.

I'm looking for advice on parsing input from a user in multiple combinations of City / State / Zip Code / Country.

一个常见的例子就是Google地图的功能.

A common example would be what Google maps does.

一些输入示例为:

  • 城市,州,国家/地区"
  • 城市,国家/地区"
  • 城市,邮政编码,国家/地区"
  • 城市,州/省,邮政编码"
  • 邮政编码"

解析用户输入内容的有效且正确的方法是什么?

What would be an efficient and correct way to parse this input from a user?

如果您知道任何示例实现,请分享:)

If you are aware of any example implementations please share :)

推荐答案

第一步是使用空格或逗号作为分隔字符,将文本分解为单独的标记.为了实现可伸缩性,您可以随后将每个令牌传递给线程或服务器(如果使用类似Map-Reducer的体系结构)以弄清楚每个令牌是什么.例如,

The first step would be to break up the text into individual tokens using spaces or commas as the delimiting characters. For scalability, you can then hand each token to a thread or server (if using a Map-Reducer like architecture) to figure out what each token is. For instance,

  • 如果图案中有数字,则可能是邮政编码.
  • 该项目是否在已知状态列表中?
  • 国家也很容易处理,就像州一样,数量有限.
  • 与写入地址的常用方式相比,令牌的顺序是什么?大部分输入内容可能会遵循当地邮局的地址格式习惯.

一旦获得了单独的令牌结果,就可以将各个部分粘合在一起以获得完整的地址.在有疑问的情况下,您可以提示用户他们的真实含义(例如Google地图),并将该信息添加到已获悉的列表中.

Once you have the individual token results, you can glue the parts back together to get a full address. In the cases where there are questions, you can prompt the user what they really meant (like Google maps) and add that information to a learned list.

假设您不打算构建地图系统,最简单的向应用程序添加支持的方法是查询Google或Yahoo并要求它们为您解析日期.

The easiest method to add that support to an applications, assuming you're not trying to build a map system, is to query Google or Yahoo and ask them to parse the date for you.

这篇关于用户输入解析-城市/州/邮政编码/国家/地区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆