如何在JAVA中比较不同语言的字符串值? [英] How to compare different language String values in JAVA?

查看:126
本文介绍了如何在JAVA中比较不同语言的字符串值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Web应用程序中,我使用的是两种不同的语言,即英语阿拉伯语.

In my web application I am using two different Languages namely English and Arabic.

我的Web应用程序中有一个搜索框,如果我们按名称或名称的一部分进行搜索,它将通过比较故乡"从数据库中检索值用户的strong>

I have a search box in my web application in which if we search by name or part of the name then it will retrieve the values from DB by comparing the "Hometown" of the user

说明:

例如,如果某个用户属于"strongtown"加利福尼亚州,并且他搜索了"名称"并说""Victor" ,那么我的查询将首先看到家乡加利福尼亚" 的人,并且在加利福尼亚" 作为家乡的人中,维克多" * 名称 *将被搜索,并检索具有加利福尼亚" 作为其家乡和"胜利者"的用户"作为其名称或名称的一部分.

Like if a user belongs to hometown "California" and he searches a name say "Victor" then my query will first see the people who are having the same hometown "California" and in the list of people who have "California" as hometown the "Victor" *name* will be searched and it retrieve the users having "California" as their hometown and "victor" in their name or part of the name.

问题 是如果加利福尼亚州" 英语保存了加利福尼亚" ,它将比较并检索价值观.但是加利福尼亚" 以阿拉伯语保存为كاليفورنيا" .在这种情况下,家乡比较失败,并且它无法检索值.

The problem is if the hometown "California" is saved in English it will compare and retrieve the values. But "California" will be saved as "كاليفورنيا" in Arabic. In this case the hometown comparison fails and it cant retrieve the values.

我希望我的查询应该找到两个相同的家乡并检索值.有可能吗?

I wish that my query should find both are same hometown and retrieve the values. Is it possible?

对于这种比较逻辑,我应该想到什么替代.我很迷惑.有什么建议吗?

What alternate I should think of for this logic for comparison. I am confused. Any suggestion please?

* 我有一个主意,如果得到了家乡,那么可以使用Google翻译器或音译器并将家乡更改为另一种语言.如果是英语,则为阿拉伯语;如果是英语,则为阿拉伯语,并给出将两者结合在一起的搜索结果.有什么建议吗? *

*I have an Idea such that if the hometown is got then is it possible to use Google translator or transliterator and change the hometown to another language. if it is in english then to arabic or if it is in english then to arabic and give the search results joining both. Any suggestion?*

推荐答案

将所有名称音译为相同的语言(例如英语)以进行搜索,并使用Levenstein编辑距离来计算名称的语音表示之间的相似度.如果仅将查询与每个名称进行比较,但是将数据库中的所有地名预索引到

Transliterate all names into the same language (e.g. English) for searching, and use Levenstein edit distance to compute the similarity between the phonetic representations of the names. This will be slow if you simply compare your query with every name, but if you pre-index all of the place names in your database into a Burkhard-Keller tree, then they can be efficiently searched by edit distance from the query term.

此技术使您可以按名称实际匹配的程度对其进行排序.比起使用变音器或双变音器,您更可能以这种方式找到匹配项,尽管这更难以实现.

This technique allows you to sort names by how close they actually match. You're probably more likely to find a match this way than using metaphone or double-metaphone, though this is more difficult to implement.

这篇关于如何在JAVA中比较不同语言的字符串值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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