问题描述
我提出了一个棘手的问题,我不确定如何解决.因此,我制定了一个包含字典的 plist,其中包含两个对象:
I present a tricky question that I am not sure how to approach. So, I have formulated a plist containing dictionaries which contain two objects:
- 国家名称
- 国家插头大小
不过,只有 210 个国家/地区/事实.
There are only 210 countries/facts though.
而且,我已经启用了搜索许多国家的列表,其中可能存在或不存在事实.但这是我的问题,我正在使用一个名为 Geonames 的网络服务,用户可以使用搜索栏显示控制器来搜索国家/地区,而这些与插头尺寸配对的 plist 国家/地区名称实际上来自 Wikipedia 文章.
And, I have enabled to search through a list of many many countries, in which there might be a fact or not. But here is my problem, I am using a web service called Geonames and the user can use a search bar display controller to search for countries, and these plist country names paired with plug sizes are actually from a Wikipedia article.
现在,Geonames 中的国家名称和我在 Wikipedia 中的 plist 中的名称可能略有不同,可能有一个额外的空格、一个额外的破折号、一个额外的字母.这就是为什么我想查看 geoname country 字符串是否与 plist 中的字符串非常相似.
Now, the country naming in Geonames and in my plist from Wikipedia might be named slightly different, maybe with an extra space, an extra dash, an extra letter. This is why I want to see if the geoname country string is very similar to the one in the plist.
所以,这不会是 isEqualToString:
因为它会发现它是否准确,compare:
方法可以工作吗?
So, this would not be isEqualToString:
because that finds if it is exact, can the compare:
method work?
我该如何处理?这是一个例子:
How can I approach this? Here is an example:
Geoname 返回(不是一个真实的国家只是一个例子):
Geoname returns (not a real country just an example):
- 怡亭
但 plist 可能会返回:
But plist may return:
- 依婷
所以有 1 个额外的 't',但还有其他情况.我希望将它们进行比较,或者至少相似,因此我可以将它们视为匹配项.
So with 1 extra 't', but there are other circumstances. I would like these to be compared as exact, or at least similar, so I could consider them as a match.
有什么教程、资源、项目等你可以指点我吗?
Are there any tutorials, resources, projects etc. you could point me towards?
谢谢!再见!
推荐答案
Soundex 算法在这种情况下很有用.
The Soundex algorithm is useful in cases like this.
我在 github 上找到了一个示例实现.
I found a sample implementation on github.
这篇关于检查两个 NSString 是否相似的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!