Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java中阿拉伯语单词的排序_Java_Sorting_Collation_Arabic - Fatal编程技术网

Java中阿拉伯语单词的排序

Java中阿拉伯语单词的排序,java,sorting,collation,arabic,Java,Sorting,Collation,Arabic,我有一个阿拉伯语单词列表,我想对其进行排序。我在不同的地区尝试过标准的Collator(比如英语或法语,但没有太多希望),我甚至创建了自己的基于规则的Collator,但没有效果。显然,默认排序依赖于unicode值顺序,这在许多情况下都有效,但在本例中显然无效 按照javadocs的说明,RuleBasedCalator需要一个字符串,指定字符的排序顺序。我使用unicode代码创建了以下字符串: 我得到的结果根本没有分类: الأَحَد, الخَميس, الاِثنَين, الثُّ

我有一个阿拉伯语单词列表,我想对其进行排序。我在不同的地区尝试过标准的Collator(比如英语或法语,但没有太多希望),我甚至创建了自己的基于规则的Collator,但没有效果。显然,默认排序依赖于unicode值顺序,这在许多情况下都有效,但在本例中显然无效

按照javadocs的说明,RuleBasedCalator需要一个字符串,指定字符的排序顺序。我使用unicode代码创建了以下字符串:

我得到的结果根本没有分类:

الأَحَد, الخَميس, الاِثنَين, الثُّلاثاء, الأَربِعاء, السَّبت, الجُمعة
此外,对于如此少量的单词,它需要相当长的时间,这使得它无法使用

有没有人知道我是否做错了什么,或者是否有一个救生图书馆已经在处理这个问题

在写这篇文章之前,我做了一些谷歌搜索,我很惊讶我没有找到一个结果

谢谢


使用代码更新:

public static class TranslatableComparator implements java.util.Comparator<Translatable> {
        @Override
        public int compare(Translatable t1, Translatable t2) {

            String sortingRules = "< \u0623=\uFE83=\uFE84 < \u0628=\uFE8F=\uFE90=\uFE92=\uFE91 < \u062A=\uFE95=\uFE96=\uFE98=\uFE97 < \u062B=\uFE99=\uFE9A=\uFE9C=\uFE9B < \u062C=\uFE9D=\uFE9E=\uFEA0=\uFE9F < \u062D=\uFEA1=\uFEA2=\uFEA4=\uFEA3 < \u062E=\uFEA5=\uFEA6=\uFEA8=\uFEA7 < \u062F=\uFEA9=\uFEAA < \u0630=\uFEAB=\uFEAC < \u0631=\uFEAD=\uFEAE < \u0632=\uFEAF=\uFEB0 < \u0633=\uFEB1=\uFEB2=\uFEB4=\uFEB3 < \u0634=\uFEB5=\uFEB6=\uFEB8=\uFEB7 < \u0635=\uFEB9=\uFEBA=\uFEBC=\uFEBB < \u0636=\uFEBD=\uFEBE=\uFEC0=\uFEBF < \u0637=\uFEC1=\uFEC2=\uFEC4=\uFEC3 < \u0638=\uFEC5=\uFEC6=\uFEC8=\uFEC7 < \u0639=\uFEC9=\uFECA=\uFECC=\uFECB < \u063A=\uFECD=\uFECE=\uFED0=\uFECF < \u0641=\uFED1=\uFED2=\uFED4=\uFED3 < \u0642=\uFED5=\uFED6=\uFED8=\uFED7 < \u0643=\uFED9=\uFEDA=\uFEDC=\uFEDB < \u0644=\uFEDD=\uFEDE=\uFED0=\uFEDF < \u0645=\uFEE1=\uFEE2=\uFEE4=\uFEE3 < \u0646=\uFEE5=\uFEE6=\uFEE8=\uFEE7 < \u0647=\uFEE9=\uFEEA=\uFEEC=\uFEEB < \u0648=\uFEED=\uFEEE < \u064A=\uFEF1=\uFEF2=\uFEF4=\uFEF3 < \u0622=\uFE81=\uFE82 < \u0629=\uFE93=\uFE94 < \u0649=\uFEEF=\uFEF0 < \u0627";
            RuleBasedCollator col = null;
            try {
                col = new RuleBasedCollator(sortingRules);
            } catch (ParseException e) {
                //col = (RuleBasedCollator)RuleBasedCollator.getInstance(Locale.FRENCH);
            }

            return col.getCollationKey(t1.getTranslation().getText()).compareTo(col.getCollationKey(t2.getTranslation().getText()));
        }
    }
公共静态类translateableComparator实现java.util.Comparator{
@凌驾
公共整数比较(可翻译t1,可翻译t2){
字符串排序规则="2009\0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 7 7 7=\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \试图试图试图试图试图试图试图试图试图试图试图试图试图试图试图试图试图试图试图试图试图试图试图试图试图试图\u0630=\uFEAB=\uFEAC<\u0631=\uFEAD=\uFEAE<\u0632=\uFEAF=\uFEB0<\u0633=\uF布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布布\ u0641=\uFED1=\uFED2=\uFED4=\uFED3<\u0642=\uFED5=\uFED6=\uFED8.0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 uFE93=\uFE94<\u0649=\uFEEF=\uFEF0<\u0627”;
RuleBasedCollector col=null;
试一试{
col=新的基于规则的触发器(排序规则);
}捕获(解析异常){
//col=(RuleBasedCollator)RuleBasedCollator.getInstance(Locale.FRENCH);
}
返回col.getCollationKey(t1.getTranslation().getText()).compareTo(col.getCollationKey(t2.getTranslation().getText());
}
}

您不需要定义自己的collator,只需使用阿拉伯语的内置collator。您的
比较器
如下所示

public int compare(Translatable t1, Translatable t2) {
        Collator.getInstance(new Locale("ar")).compare(t1.getTranslation().getText(), t2.getTranslation().getText());
}
(您可以通过浏览
collator.getAvailableCales()
中的结果来检查collator是否可用于阿拉伯语)

如注释中所述,如果您担心性能问题,则应计算排序规则键,将它们存储在
可翻译的
对象中,并对其进行排序

如果您真的想了解您定义的内容与标准collator之间的差异,只需打印出规则:

System.out.println((RuleBasedCollator) Collator.getInstance(new Locale("ar"))).getRules();

请你再发一些代码好吗?这样我们就可以看到实际发生的情况了?@shaunvxc用代码更新了。我对基于规则的计算器不太熟悉,但是当你用逗号分隔那些值相等的字符时会发生什么事呢?类似这样:“public int compare(Translatable t1, Translatable t2) { Collator.getInstance(new Locale("ar")).compare(t1.getTranslation().getText(), t2.getTranslation().getText()); }
System.out.println((RuleBasedCollator) Collator.getInstance(new Locale("ar"))).getRules();