在比较字符串时忽略希伯来元音

时间:2012-10-06 20:17:31

标签: java encoding hebrew

晚上好,我希望你能帮我解决这个问题,因为我很难找到解决方案。

我有一个单词提供者,他们给我发了一些希伯来语的单词,例如 -

  

Vowelled - בַּיִתnot vowelled - בית

     

Vowelled - הַבַּיְתָהnot vowelled - הביתה

与我的提供者不同,我的用户通常不能输入希伯来语元音(我也不希望他这样做)。用户故事是用户在提供的单词中搜索单词。问题是在元音和非元音词之间的比较。由于每个都由内存中的不同字节数组表示,因此equals方法返回false。

我试着研究UTF-8如何处理希伯来元音,看起来它只是普通字符。

我确实想向用户呈现元音,所以我想将字符串保持在内存中,但是在比较时我想忽略它们。有没有简单的方法来解决这个问题?

2 个答案:

答案 0 :(得分:5)

您可以使用Collator。我无法告诉你它是如何工作的,因为它对我来说是新的,但这似乎可以解决问题:

public static void main( String[] args ) {
    String withVowels = "בַּיִת";
    String withoutVowels = "בית";

    String withVowelsTwo = "הַבַּיְתָה";
    String withoutVowelsTwo = "הביתה";

    System.out.println( "These two strings are " + (withVowels.equals( withoutVowels ) ? "" : "not ") + "equal" );
    System.out.println( "The second two strings are " + (withVowelsTwo.equals( withoutVowelsTwo ) ? "" : "not ") + "equal" );

    Collator collator = Collator.getInstance( new Locale( "he" ) );
    collator.setStrength( Collator.PRIMARY );

    System.out.println( collator.equals( withVowels, withoutVowels ) );
    System.out.println( collator.equals( withVowelsTwo, withoutVowelsTwo ) );
}

由此,我得到以下输出:

These two strings are not equal
The second two strings are not equal
true
true

答案 1 :(得分:0)

AFAIK没有。 元音是人物。甚至一些字母和点的组合也是字符。查看维基百科页面。

http://en.wikipedia.org/wiki/Unicode_and_HTML_for_the_Hebrew_alphabet

您只能将字词的搜索键存储为05dx-05ex范围内的字符。您可以使用元音为单词添加另一个字段。

当然你应该期待以下内容:

  • 根据nikkud,您应该考虑具有不同含义的单词。
  • 你应该考虑י和ו的“误导”,这是常见的。
相关问题