merge with master

This commit is contained in:
madwasp79 2019-02-18 15:15:08 +02:00
parent 7b03a40ffc
commit 79351d932c
2 changed files with 140 additions and 146 deletions

View file

@ -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("", "-");
} }
} }

View file

@ -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;
} }
} }