merge with master
This commit is contained in:
parent
7b03a40ffc
commit
79351d932c
2 changed files with 140 additions and 146 deletions
|
@ -14,12 +14,14 @@ public class TransliterationHelper {
|
||||||
private static TransliterationHelper instance;
|
private static TransliterationHelper instance;
|
||||||
|
|
||||||
public final static Log LOG = PlatformUtil.getLog(TransliterationHelper.class);
|
public final static Log LOG = PlatformUtil.getLog(TransliterationHelper.class);
|
||||||
public final static int DEFAULT = 1000;
|
public final static String DEFAULT = "default";
|
||||||
public final static int JAPANESE = 1001;
|
public final static String JAPAN = "Japan";
|
||||||
|
|
||||||
private static int activeMapLanguage = DEFAULT;
|
private static String country = DEFAULT;
|
||||||
|
|
||||||
private Map<String, String> kanaMap = new HashMap<>();
|
private Tokenizer tokenizer;
|
||||||
|
|
||||||
|
private Map<String, String> katakanaMap = new HashMap<>();
|
||||||
|
|
||||||
private TransliterationHelper(){}
|
private TransliterationHelper(){}
|
||||||
|
|
||||||
|
@ -35,19 +37,22 @@ public class TransliterationHelper {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setActiveMapLanguage(int activeMapLanguage) {
|
public static void setCountry(String countryName) {
|
||||||
TransliterationHelper.activeMapLanguage = activeMapLanguage;
|
TransliterationHelper.country = countryName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getActiveMapLanguage() {
|
public static String getCountry() {
|
||||||
return activeMapLanguage;
|
return country;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String transliterateText(String text) {
|
public String transliterateText(String text) {
|
||||||
switch (activeMapLanguage) {
|
if(tokenizer==null){
|
||||||
|
tokenizer = new Tokenizer();
|
||||||
|
}
|
||||||
|
switch (country) {
|
||||||
case DEFAULT:
|
case DEFAULT:
|
||||||
return Junidecode.unidecode(text);
|
return Junidecode.unidecode(text);
|
||||||
case JAPANESE:
|
case JAPAN:
|
||||||
return japanese2Romaji(text);
|
return japanese2Romaji(text);
|
||||||
}
|
}
|
||||||
return text;
|
return text;
|
||||||
|
@ -57,14 +62,13 @@ public class TransliterationHelper {
|
||||||
|
|
||||||
boolean capitalizeWords = true;
|
boolean capitalizeWords = true;
|
||||||
|
|
||||||
Tokenizer tokenizer = new Tokenizer();
|
|
||||||
List<Token> tokens = tokenizer.tokenize(input);
|
List<Token> tokens = tokenizer.tokenize(input);
|
||||||
|
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
if (kanaMap.isEmpty()) {
|
if (katakanaMap.isEmpty()) {
|
||||||
initKanaMap();
|
initKanaMap();
|
||||||
}
|
}
|
||||||
String lastTokenToMerge = "";
|
|
||||||
for (Token token : tokens) {
|
for (Token token : tokens) {
|
||||||
String type = token.getAllFeaturesArray()[1];
|
String type = token.getAllFeaturesArray()[1];
|
||||||
|
|
||||||
|
@ -84,20 +88,13 @@ public class TransliterationHelper {
|
||||||
builder.append(token.getSurface());
|
builder.append(token.getSurface());
|
||||||
} else {
|
} else {
|
||||||
String romaji = convertKanaToRomaji(token.getAllFeaturesArray()[8]);
|
String romaji = convertKanaToRomaji(token.getAllFeaturesArray()[8]);
|
||||||
if (lastFeature.endsWith("ッ")) {
|
|
||||||
lastTokenToMerge = lastFeature;
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
lastTokenToMerge = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (capitalizeWords) {
|
if (capitalizeWords) {
|
||||||
builder.append(romaji.substring(0, 1).toUpperCase());
|
builder.append(romaji.substring(0, 1).toUpperCase());
|
||||||
builder.append(romaji.substring(1));
|
builder.append(romaji.substring(1));
|
||||||
} else {
|
} else {
|
||||||
// Convert foreign katakana words to uppercase
|
|
||||||
if (token.getSurface()
|
if (token.getSurface()
|
||||||
.equals(token.getPronunciation())) // detect katakana
|
.equals(token.getPronunciation()))
|
||||||
{
|
{
|
||||||
romaji = romaji.toUpperCase();
|
romaji = romaji.toUpperCase();
|
||||||
}
|
}
|
||||||
|
@ -114,19 +111,19 @@ public class TransliterationHelper {
|
||||||
StringBuilder t = new StringBuilder();
|
StringBuilder t = new StringBuilder();
|
||||||
for (int i = 0; i < s.length(); i++) {
|
for (int i = 0; i < s.length(); i++) {
|
||||||
if (i <= s.length() - 2) {
|
if (i <= s.length() - 2) {
|
||||||
if (kanaMap.containsKey(s.substring(i, i + 2))) {
|
if (katakanaMap.containsKey(s.substring(i, i + 2))) {
|
||||||
t.append(kanaMap.get(s.substring(i, i + 2)));
|
t.append(katakanaMap.get(s.substring(i, i + 2)));
|
||||||
i++;
|
i++;
|
||||||
} else if (kanaMap.containsKey(s.substring(i, i + 1))) {
|
} else if (katakanaMap.containsKey(s.substring(i, i + 1))) {
|
||||||
t.append(kanaMap.get(s.substring(i, i + 1)));
|
t.append(katakanaMap.get(s.substring(i, i + 1)));
|
||||||
} else if (s.charAt(i) == 'ッ') {
|
} else if (s.charAt(i) == 'ッ') {
|
||||||
t.append(kanaMap.get(s.substring(i + 1, i + 2)).charAt(0));
|
t.append(katakanaMap.get(s.substring(i + 1, i + 2)).charAt(0));
|
||||||
} else {
|
} else {
|
||||||
t.append(s.charAt(i));
|
t.append(s.charAt(i));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (kanaMap.containsKey(s.substring(i, i + 1))) {
|
if (katakanaMap.containsKey(s.substring(i, i + 1))) {
|
||||||
t.append(kanaMap.get(s.substring(i, i + 1)));
|
t.append(katakanaMap.get(s.substring(i, i + 1)));
|
||||||
} else {
|
} else {
|
||||||
t.append(s.charAt(i));
|
t.append(s.charAt(i));
|
||||||
}
|
}
|
||||||
|
@ -136,113 +133,113 @@ public class TransliterationHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initKanaMap(){
|
private void initKanaMap(){
|
||||||
kanaMap.put("ア", "a");
|
katakanaMap.put("ア", "a");
|
||||||
kanaMap.put("イ", "i");
|
katakanaMap.put("イ", "i");
|
||||||
kanaMap.put("ウ", "u");
|
katakanaMap.put("ウ", "u");
|
||||||
kanaMap.put("エ", "e");
|
katakanaMap.put("エ", "e");
|
||||||
kanaMap.put("オ", "o");
|
katakanaMap.put("オ", "o");
|
||||||
kanaMap.put("カ", "ka");
|
katakanaMap.put("カ", "ka");
|
||||||
kanaMap.put("キ", "ki");
|
katakanaMap.put("キ", "ki");
|
||||||
kanaMap.put("ク", "ku");
|
katakanaMap.put("ク", "ku");
|
||||||
kanaMap.put("ケ", "ke");
|
katakanaMap.put("ケ", "ke");
|
||||||
kanaMap.put("コ", "ko");
|
katakanaMap.put("コ", "ko");
|
||||||
kanaMap.put("サ", "sa");
|
katakanaMap.put("サ", "sa");
|
||||||
kanaMap.put("シ", "shi");
|
katakanaMap.put("シ", "shi");
|
||||||
kanaMap.put("ス", "su");
|
katakanaMap.put("ス", "su");
|
||||||
kanaMap.put("セ", "se");
|
katakanaMap.put("セ", "se");
|
||||||
kanaMap.put("ソ", "so");
|
katakanaMap.put("ソ", "so");
|
||||||
kanaMap.put("タ", "ta");
|
katakanaMap.put("タ", "ta");
|
||||||
kanaMap.put("チ", "chi");
|
katakanaMap.put("チ", "chi");
|
||||||
kanaMap.put("ツ", "tsu");
|
katakanaMap.put("ツ", "tsu");
|
||||||
kanaMap.put("テ", "te");
|
katakanaMap.put("テ", "te");
|
||||||
kanaMap.put("ト", "to");
|
katakanaMap.put("ト", "to");
|
||||||
kanaMap.put("ナ", "na");
|
katakanaMap.put("ナ", "na");
|
||||||
kanaMap.put("ニ", "ni");
|
katakanaMap.put("ニ", "ni");
|
||||||
kanaMap.put("ヌ", "nu");
|
katakanaMap.put("ヌ", "nu");
|
||||||
kanaMap.put("ネ", "ne");
|
katakanaMap.put("ネ", "ne");
|
||||||
kanaMap.put("ノ", "no");
|
katakanaMap.put("ノ", "no");
|
||||||
kanaMap.put("ハ", "ha");
|
katakanaMap.put("ハ", "ha");
|
||||||
kanaMap.put("ヒ", "hi");
|
katakanaMap.put("ヒ", "hi");
|
||||||
kanaMap.put("フ", "fu");
|
katakanaMap.put("フ", "fu");
|
||||||
kanaMap.put("ヘ", "he");
|
katakanaMap.put("ヘ", "he");
|
||||||
kanaMap.put("ホ", "ho");
|
katakanaMap.put("ホ", "ho");
|
||||||
kanaMap.put("マ", "ma");
|
katakanaMap.put("マ", "ma");
|
||||||
kanaMap.put("ミ", "mi");
|
katakanaMap.put("ミ", "mi");
|
||||||
kanaMap.put("ム", "mu");
|
katakanaMap.put("ム", "mu");
|
||||||
kanaMap.put("メ", "me");
|
katakanaMap.put("メ", "me");
|
||||||
kanaMap.put("モ", "mo");
|
katakanaMap.put("モ", "mo");
|
||||||
kanaMap.put("ヤ", "ya");
|
katakanaMap.put("ヤ", "ya");
|
||||||
kanaMap.put("ユ", "yu");
|
katakanaMap.put("ユ", "yu");
|
||||||
kanaMap.put("ヨ", "yo");
|
katakanaMap.put("ヨ", "yo");
|
||||||
kanaMap.put("ラ", "ra");
|
katakanaMap.put("ラ", "ra");
|
||||||
kanaMap.put("リ", "ri");
|
katakanaMap.put("リ", "ri");
|
||||||
kanaMap.put("ル", "ru");
|
katakanaMap.put("ル", "ru");
|
||||||
kanaMap.put("レ", "re");
|
katakanaMap.put("レ", "re");
|
||||||
kanaMap.put("ロ", "ro");
|
katakanaMap.put("ロ", "ro");
|
||||||
kanaMap.put("ワ", "wa");
|
katakanaMap.put("ワ", "wa");
|
||||||
kanaMap.put("ヲ", "wo");
|
katakanaMap.put("ヲ", "wo");
|
||||||
kanaMap.put("ン", "n");
|
katakanaMap.put("ン", "n");
|
||||||
kanaMap.put("ガ", "ga");
|
katakanaMap.put("ガ", "ga");
|
||||||
kanaMap.put("ギ", "gi");
|
katakanaMap.put("ギ", "gi");
|
||||||
kanaMap.put("グ", "gu");
|
katakanaMap.put("グ", "gu");
|
||||||
kanaMap.put("ゲ", "ge");
|
katakanaMap.put("ゲ", "ge");
|
||||||
kanaMap.put("ゴ", "go");
|
katakanaMap.put("ゴ", "go");
|
||||||
kanaMap.put("ザ", "za");
|
katakanaMap.put("ザ", "za");
|
||||||
kanaMap.put("ジ", "ji");
|
katakanaMap.put("ジ", "ji");
|
||||||
kanaMap.put("ズ", "zu");
|
katakanaMap.put("ズ", "zu");
|
||||||
kanaMap.put("ゼ", "ze");
|
katakanaMap.put("ゼ", "ze");
|
||||||
kanaMap.put("ゾ", "zo");
|
katakanaMap.put("ゾ", "zo");
|
||||||
kanaMap.put("ダ", "da");
|
katakanaMap.put("ダ", "da");
|
||||||
kanaMap.put("ヂ", "ji");
|
katakanaMap.put("ヂ", "ji");
|
||||||
kanaMap.put("ヅ", "zu");
|
katakanaMap.put("ヅ", "zu");
|
||||||
kanaMap.put("デ", "de");
|
katakanaMap.put("デ", "de");
|
||||||
kanaMap.put("ド", "do");
|
katakanaMap.put("ド", "do");
|
||||||
kanaMap.put("バ", "ba");
|
katakanaMap.put("バ", "ba");
|
||||||
kanaMap.put("ビ", "bi");
|
katakanaMap.put("ビ", "bi");
|
||||||
kanaMap.put("ブ", "bu");
|
katakanaMap.put("ブ", "bu");
|
||||||
kanaMap.put("ベ", "be");
|
katakanaMap.put("ベ", "be");
|
||||||
kanaMap.put("ボ", "bo");
|
katakanaMap.put("ボ", "bo");
|
||||||
kanaMap.put("パ", "pa");
|
katakanaMap.put("パ", "pa");
|
||||||
kanaMap.put("ピ", "pi");
|
katakanaMap.put("ピ", "pi");
|
||||||
kanaMap.put("プ", "pu");
|
katakanaMap.put("プ", "pu");
|
||||||
kanaMap.put("ペ", "pe");
|
katakanaMap.put("ペ", "pe");
|
||||||
kanaMap.put("ポ", "po");
|
katakanaMap.put("ポ", "po");
|
||||||
kanaMap.put("キャ", "kya");
|
katakanaMap.put("キャ", "kya");
|
||||||
kanaMap.put("キュ", "kyu");
|
katakanaMap.put("キュ", "kyu");
|
||||||
kanaMap.put("キョ", "kyo");
|
katakanaMap.put("キョ", "kyo");
|
||||||
kanaMap.put("シャ", "sha");
|
katakanaMap.put("シャ", "sha");
|
||||||
kanaMap.put("シュ", "shu");
|
katakanaMap.put("シュ", "shu");
|
||||||
kanaMap.put("ショ", "sho");
|
katakanaMap.put("ショ", "sho");
|
||||||
kanaMap.put("チャ", "cha");
|
katakanaMap.put("チャ", "cha");
|
||||||
kanaMap.put("チュ", "chu");
|
katakanaMap.put("チュ", "chu");
|
||||||
kanaMap.put("チョ", "cho");
|
katakanaMap.put("チョ", "cho");
|
||||||
kanaMap.put("ニャ", "nya");
|
katakanaMap.put("ニャ", "nya");
|
||||||
kanaMap.put("ニュ", "nyu");
|
katakanaMap.put("ニュ", "nyu");
|
||||||
kanaMap.put("ニョ", "nyo");
|
katakanaMap.put("ニョ", "nyo");
|
||||||
kanaMap.put("ヒャ", "hya");
|
katakanaMap.put("ヒャ", "hya");
|
||||||
kanaMap.put("ヒュ", "hyu");
|
katakanaMap.put("ヒュ", "hyu");
|
||||||
kanaMap.put("ヒョ", "hyo");
|
katakanaMap.put("ヒョ", "hyo");
|
||||||
kanaMap.put("リャ", "rya");
|
katakanaMap.put("リャ", "rya");
|
||||||
kanaMap.put("リュ", "ryu");
|
katakanaMap.put("リュ", "ryu");
|
||||||
kanaMap.put("リョ", "ryo");
|
katakanaMap.put("リョ", "ryo");
|
||||||
kanaMap.put("ギャ", "gya");
|
katakanaMap.put("ギャ", "gya");
|
||||||
kanaMap.put("ギュ", "gyu");
|
katakanaMap.put("ギュ", "gyu");
|
||||||
kanaMap.put("ギョ", "gyo");
|
katakanaMap.put("ギョ", "gyo");
|
||||||
kanaMap.put("ジャ", "ja");
|
katakanaMap.put("ジャ", "ja");
|
||||||
kanaMap.put("ジュ", "ju");
|
katakanaMap.put("ジュ", "ju");
|
||||||
kanaMap.put("ジョ", "jo");
|
katakanaMap.put("ジョ", "jo");
|
||||||
kanaMap.put("ティ", "ti");
|
katakanaMap.put("ティ", "ti");
|
||||||
kanaMap.put("ディ", "di");
|
katakanaMap.put("ディ", "di");
|
||||||
kanaMap.put("ツィ", "tsi");
|
katakanaMap.put("ツィ", "tsi");
|
||||||
kanaMap.put("ヂャ", "dya");
|
katakanaMap.put("ヂャ", "dya");
|
||||||
kanaMap.put("ヂュ", "dyu");
|
katakanaMap.put("ヂュ", "dyu");
|
||||||
kanaMap.put("ヂョ", "dyo");
|
katakanaMap.put("ヂョ", "dyo");
|
||||||
kanaMap.put("ビャ", "bya");
|
katakanaMap.put("ビャ", "bya");
|
||||||
kanaMap.put("ビュ", "byu");
|
katakanaMap.put("ビュ", "byu");
|
||||||
kanaMap.put("ビョ", "byo");
|
katakanaMap.put("ビョ", "byo");
|
||||||
kanaMap.put("ピャ", "pya");
|
katakanaMap.put("ピャ", "pya");
|
||||||
kanaMap.put("ピュ", "pyu");
|
katakanaMap.put("ピュ", "pyu");
|
||||||
kanaMap.put("ピョ", "pyo");
|
katakanaMap.put("ピョ", "pyo");
|
||||||
kanaMap.put("ー", "-");
|
katakanaMap.put("ー", "-");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package net.osmand.plus.render;
|
package net.osmand.plus.render;
|
||||||
|
|
||||||
|
|
||||||
import static net.osmand.util.TransliterationHelper.setActiveMapLanguage;
|
import static net.osmand.util.TransliterationHelper.setCountry;
|
||||||
|
|
||||||
import gnu.trove.iterator.TIntObjectIterator;
|
import gnu.trove.iterator.TIntObjectIterator;
|
||||||
import gnu.trove.list.TLongList;
|
import gnu.trove.list.TLongList;
|
||||||
|
@ -308,12 +308,9 @@ public class MapRenderRepositories {
|
||||||
BinaryMapIndexReader fr = files.get(mapName);
|
BinaryMapIndexReader fr = files.get(mapName);
|
||||||
if (fr != null && (fr.containsMapData(leftX, topY, rightX, bottomY, zoom) ||
|
if (fr != null && (fr.containsMapData(leftX, topY, rightX, bottomY, zoom) ||
|
||||||
fr.containsRouteData(leftX, topY, rightX, bottomY, zoom))) {
|
fr.containsRouteData(leftX, topY, rightX, bottomY, zoom))) {
|
||||||
|
|
||||||
if(!Algorithms.isEmpty(fr.getCountryName())) {
|
if(!Algorithms.isEmpty(fr.getCountryName())) {
|
||||||
log.debug("country: " +fr.getCountryName());
|
setCountryForTransliterationMethod(fr.getCountryName());
|
||||||
setTransliterationMethod(fr.getCountryName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!nativeFiles.contains(mapName)) {
|
if (!nativeFiles.contains(mapName)) {
|
||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
nativeFiles.add(mapName);
|
nativeFiles.add(mapName);
|
||||||
|
@ -551,7 +548,7 @@ public class MapRenderRepositories {
|
||||||
}
|
}
|
||||||
if(res.size() > 0) {
|
if(res.size() > 0) {
|
||||||
log.debug("Country name:" + c.getCountryName());
|
log.debug("Country name:" + c.getCountryName());
|
||||||
setTransliterationMethod(c.getCountryName());
|
setCountryForTransliterationMethod(c.getCountryName());
|
||||||
if(basemap) {
|
if(basemap) {
|
||||||
renderedState |= 1;
|
renderedState |= 1;
|
||||||
} else {
|
} else {
|
||||||
|
@ -599,15 +596,15 @@ public class MapRenderRepositories {
|
||||||
return mi;
|
return mi;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setTransliterationMethod(String countryName) {
|
private void setCountryForTransliterationMethod(String countryName) {
|
||||||
if(TransliterationHelper.getActiveMapLanguage()!=1001) {
|
if(!countryName.equals(TransliterationHelper.getCountry())) {
|
||||||
switch (countryName) {
|
switch (countryName) {
|
||||||
case "Japan": {
|
case "Japan": {
|
||||||
setActiveMapLanguage(TransliterationHelper.JAPANESE);
|
setCountry(countryName);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
setActiveMapLanguage(TransliterationHelper.DEFAULT);
|
setCountry(TransliterationHelper.DEFAULT);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue