Compare Strings in a Language
The new function AlphabeticOrder allows strings to be compared in terms of the alphabetic order associated to a language.
AlphabeticOrder returns 1 when the first string should appear before the second one, 0 if they are equivalent, and −1 when they are reversed.
In[1]:=
AlphabeticOrder["z", "å", Entity["Language", "Swedish"]]
Out[1]=
The results from AlphabeticOrder and Order may be different for non-English languages.
In[2]:=
{Order["італьянская", "японская"],
AlphabeticOrder["італьянская", "японская", "Belarusian"]}
Out[2]=
The IgnoreDiacritics option allows flexible string comparisons.
In[3]:=
AlphabeticOrder["como", "cómo", Entity["Language", "Spanish"],
IgnoreDiacritics -> True]
Out[3]=
This option does not override basic language rules. For example, one letter may be considered as a diacritic in one language but a basic letter in another language.
In[4]:=
{AlphabeticOrder["ñandú", "nandu", Entity["Language", "Spanish"],
IgnoreDiacritics -> True],
AlphabeticOrder["ñandú", "nandu", Entity["Language", "English"],
IgnoreDiacritics -> True]}
Out[4]=
The function AlphabeticSort sorts using AlphabeticOrder as ordering function.
In[5]:=
AlphabeticSort[{"アメリカ合衆国", "日本", "イギリス", "ペルー", "スウェーデン", "インド"},
Entity["Language", "Japanese"]]
Out[5]=