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;
public final static Log LOG = PlatformUtil.getLog(TransliterationHelper.class);
public final static int DEFAULT = 1000;
public final static int JAPANESE = 1001;
public final static String DEFAULT = "default";
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(){}
@ -35,19 +37,22 @@ public class TransliterationHelper {
return instance;
}
public static void setActiveMapLanguage(int activeMapLanguage) {
TransliterationHelper.activeMapLanguage = activeMapLanguage;
public static void setCountry(String countryName) {
TransliterationHelper.country = countryName;
}
public static int getActiveMapLanguage() {
return activeMapLanguage;
public static String getCountry() {
return country;
}
public String transliterateText(String text) {
switch (activeMapLanguage) {
if(tokenizer==null){
tokenizer = new Tokenizer();
}
switch (country) {
case DEFAULT:
return Junidecode.unidecode(text);
case JAPANESE:
case JAPAN:
return japanese2Romaji(text);
}
return text;
@ -57,14 +62,13 @@ public class TransliterationHelper {
boolean capitalizeWords = true;
Tokenizer tokenizer = new Tokenizer();
List<Token> tokens = tokenizer.tokenize(input);
StringBuilder builder = new StringBuilder();
if (kanaMap.isEmpty()) {
if (katakanaMap.isEmpty()) {
initKanaMap();
}
String lastTokenToMerge = "";
for (Token token : tokens) {
String type = token.getAllFeaturesArray()[1];
@ -84,20 +88,13 @@ public class TransliterationHelper {
builder.append(token.getSurface());
} else {
String romaji = convertKanaToRomaji(token.getAllFeaturesArray()[8]);
if (lastFeature.endsWith("")) {
lastTokenToMerge = lastFeature;
continue;
} else {
lastTokenToMerge = "";
}
if (capitalizeWords) {
builder.append(romaji.substring(0, 1).toUpperCase());
builder.append(romaji.substring(1));
} else {
// Convert foreign katakana words to uppercase
if (token.getSurface()
.equals(token.getPronunciation())) // detect katakana
.equals(token.getPronunciation()))
{
romaji = romaji.toUpperCase();
}
@ -114,19 +111,19 @@ public class TransliterationHelper {
StringBuilder t = new StringBuilder();
for (int i = 0; i < s.length(); i++) {
if (i <= s.length() - 2) {
if (kanaMap.containsKey(s.substring(i, i + 2))) {
t.append(kanaMap.get(s.substring(i, i + 2)));
if (katakanaMap.containsKey(s.substring(i, i + 2))) {
t.append(katakanaMap.get(s.substring(i, i + 2)));
i++;
} else if (kanaMap.containsKey(s.substring(i, i + 1))) {
t.append(kanaMap.get(s.substring(i, i + 1)));
} else if (katakanaMap.containsKey(s.substring(i, i + 1))) {
t.append(katakanaMap.get(s.substring(i, i + 1)));
} 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 {
t.append(s.charAt(i));
}
} else {
if (kanaMap.containsKey(s.substring(i, i + 1))) {
t.append(kanaMap.get(s.substring(i, i + 1)));
if (katakanaMap.containsKey(s.substring(i, i + 1))) {
t.append(katakanaMap.get(s.substring(i, i + 1)));
} else {
t.append(s.charAt(i));
}
@ -136,113 +133,113 @@ public class TransliterationHelper {
}
private void initKanaMap(){
kanaMap.put("", "a");
kanaMap.put("", "i");
kanaMap.put("", "u");
kanaMap.put("", "e");
kanaMap.put("", "o");
kanaMap.put("", "ka");
kanaMap.put("", "ki");
kanaMap.put("", "ku");
kanaMap.put("", "ke");
kanaMap.put("", "ko");
kanaMap.put("", "sa");
kanaMap.put("", "shi");
kanaMap.put("", "su");
kanaMap.put("", "se");
kanaMap.put("", "so");
kanaMap.put("", "ta");
kanaMap.put("", "chi");
kanaMap.put("", "tsu");
kanaMap.put("", "te");
kanaMap.put("", "to");
kanaMap.put("", "na");
kanaMap.put("", "ni");
kanaMap.put("", "nu");
kanaMap.put("", "ne");
kanaMap.put("", "no");
kanaMap.put("", "ha");
kanaMap.put("", "hi");
kanaMap.put("", "fu");
kanaMap.put("", "he");
kanaMap.put("", "ho");
kanaMap.put("", "ma");
kanaMap.put("", "mi");
kanaMap.put("", "mu");
kanaMap.put("", "me");
kanaMap.put("", "mo");
kanaMap.put("", "ya");
kanaMap.put("", "yu");
kanaMap.put("", "yo");
kanaMap.put("", "ra");
kanaMap.put("", "ri");
kanaMap.put("", "ru");
kanaMap.put("", "re");
kanaMap.put("", "ro");
kanaMap.put("", "wa");
kanaMap.put("", "wo");
kanaMap.put("", "n");
kanaMap.put("", "ga");
kanaMap.put("", "gi");
kanaMap.put("", "gu");
kanaMap.put("", "ge");
kanaMap.put("", "go");
kanaMap.put("", "za");
kanaMap.put("", "ji");
kanaMap.put("", "zu");
kanaMap.put("", "ze");
kanaMap.put("", "zo");
kanaMap.put("", "da");
kanaMap.put("", "ji");
kanaMap.put("", "zu");
kanaMap.put("", "de");
kanaMap.put("", "do");
kanaMap.put("", "ba");
kanaMap.put("", "bi");
kanaMap.put("", "bu");
kanaMap.put("", "be");
kanaMap.put("", "bo");
kanaMap.put("", "pa");
kanaMap.put("", "pi");
kanaMap.put("", "pu");
kanaMap.put("", "pe");
kanaMap.put("", "po");
kanaMap.put("キャ", "kya");
kanaMap.put("キュ", "kyu");
kanaMap.put("キョ", "kyo");
kanaMap.put("シャ", "sha");
kanaMap.put("シュ", "shu");
kanaMap.put("ショ", "sho");
kanaMap.put("チャ", "cha");
kanaMap.put("チュ", "chu");
kanaMap.put("チョ", "cho");
kanaMap.put("ニャ", "nya");
kanaMap.put("ニュ", "nyu");
kanaMap.put("ニョ", "nyo");
kanaMap.put("ヒャ", "hya");
kanaMap.put("ヒュ", "hyu");
kanaMap.put("ヒョ", "hyo");
kanaMap.put("リャ", "rya");
kanaMap.put("リュ", "ryu");
kanaMap.put("リョ", "ryo");
kanaMap.put("ギャ", "gya");
kanaMap.put("ギュ", "gyu");
kanaMap.put("ギョ", "gyo");
kanaMap.put("ジャ", "ja");
kanaMap.put("ジュ", "ju");
kanaMap.put("ジョ", "jo");
kanaMap.put("ティ", "ti");
kanaMap.put("ディ", "di");
kanaMap.put("ツィ", "tsi");
kanaMap.put("ヂャ", "dya");
kanaMap.put("ヂュ", "dyu");
kanaMap.put("ヂョ", "dyo");
kanaMap.put("ビャ", "bya");
kanaMap.put("ビュ", "byu");
kanaMap.put("ビョ", "byo");
kanaMap.put("ピャ", "pya");
kanaMap.put("ピュ", "pyu");
kanaMap.put("ピョ", "pyo");
kanaMap.put("", "-");
katakanaMap.put("", "a");
katakanaMap.put("", "i");
katakanaMap.put("", "u");
katakanaMap.put("", "e");
katakanaMap.put("", "o");
katakanaMap.put("", "ka");
katakanaMap.put("", "ki");
katakanaMap.put("", "ku");
katakanaMap.put("", "ke");
katakanaMap.put("", "ko");
katakanaMap.put("", "sa");
katakanaMap.put("", "shi");
katakanaMap.put("", "su");
katakanaMap.put("", "se");
katakanaMap.put("", "so");
katakanaMap.put("", "ta");
katakanaMap.put("", "chi");
katakanaMap.put("", "tsu");
katakanaMap.put("", "te");
katakanaMap.put("", "to");
katakanaMap.put("", "na");
katakanaMap.put("", "ni");
katakanaMap.put("", "nu");
katakanaMap.put("", "ne");
katakanaMap.put("", "no");
katakanaMap.put("", "ha");
katakanaMap.put("", "hi");
katakanaMap.put("", "fu");
katakanaMap.put("", "he");
katakanaMap.put("", "ho");
katakanaMap.put("", "ma");
katakanaMap.put("", "mi");
katakanaMap.put("", "mu");
katakanaMap.put("", "me");
katakanaMap.put("", "mo");
katakanaMap.put("", "ya");
katakanaMap.put("", "yu");
katakanaMap.put("", "yo");
katakanaMap.put("", "ra");
katakanaMap.put("", "ri");
katakanaMap.put("", "ru");
katakanaMap.put("", "re");
katakanaMap.put("", "ro");
katakanaMap.put("", "wa");
katakanaMap.put("", "wo");
katakanaMap.put("", "n");
katakanaMap.put("", "ga");
katakanaMap.put("", "gi");
katakanaMap.put("", "gu");
katakanaMap.put("", "ge");
katakanaMap.put("", "go");
katakanaMap.put("", "za");
katakanaMap.put("", "ji");
katakanaMap.put("", "zu");
katakanaMap.put("", "ze");
katakanaMap.put("", "zo");
katakanaMap.put("", "da");
katakanaMap.put("", "ji");
katakanaMap.put("", "zu");
katakanaMap.put("", "de");
katakanaMap.put("", "do");
katakanaMap.put("", "ba");
katakanaMap.put("", "bi");
katakanaMap.put("", "bu");
katakanaMap.put("", "be");
katakanaMap.put("", "bo");
katakanaMap.put("", "pa");
katakanaMap.put("", "pi");
katakanaMap.put("", "pu");
katakanaMap.put("", "pe");
katakanaMap.put("", "po");
katakanaMap.put("キャ", "kya");
katakanaMap.put("キュ", "kyu");
katakanaMap.put("キョ", "kyo");
katakanaMap.put("シャ", "sha");
katakanaMap.put("シュ", "shu");
katakanaMap.put("ショ", "sho");
katakanaMap.put("チャ", "cha");
katakanaMap.put("チュ", "chu");
katakanaMap.put("チョ", "cho");
katakanaMap.put("ニャ", "nya");
katakanaMap.put("ニュ", "nyu");
katakanaMap.put("ニョ", "nyo");
katakanaMap.put("ヒャ", "hya");
katakanaMap.put("ヒュ", "hyu");
katakanaMap.put("ヒョ", "hyo");
katakanaMap.put("リャ", "rya");
katakanaMap.put("リュ", "ryu");
katakanaMap.put("リョ", "ryo");
katakanaMap.put("ギャ", "gya");
katakanaMap.put("ギュ", "gyu");
katakanaMap.put("ギョ", "gyo");
katakanaMap.put("ジャ", "ja");
katakanaMap.put("ジュ", "ju");
katakanaMap.put("ジョ", "jo");
katakanaMap.put("ティ", "ti");
katakanaMap.put("ディ", "di");
katakanaMap.put("ツィ", "tsi");
katakanaMap.put("ヂャ", "dya");
katakanaMap.put("ヂュ", "dyu");
katakanaMap.put("ヂョ", "dyo");
katakanaMap.put("ビャ", "bya");
katakanaMap.put("ビュ", "byu");
katakanaMap.put("ビョ", "byo");
katakanaMap.put("ピャ", "pya");
katakanaMap.put("ピュ", "pyu");
katakanaMap.put("ピョ", "pyo");
katakanaMap.put("", "-");
}
}

View file

@ -1,7 +1,7 @@
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.list.TLongList;
@ -308,12 +308,9 @@ public class MapRenderRepositories {
BinaryMapIndexReader fr = files.get(mapName);
if (fr != null && (fr.containsMapData(leftX, topY, rightX, bottomY, zoom) ||
fr.containsRouteData(leftX, topY, rightX, bottomY, zoom))) {
if(!Algorithms.isEmpty(fr.getCountryName())) {
log.debug("country: " +fr.getCountryName());
setTransliterationMethod(fr.getCountryName());
setCountryForTransliterationMethod(fr.getCountryName());
}
if (!nativeFiles.contains(mapName)) {
long time = System.currentTimeMillis();
nativeFiles.add(mapName);
@ -551,7 +548,7 @@ public class MapRenderRepositories {
}
if(res.size() > 0) {
log.debug("Country name:" + c.getCountryName());
setTransliterationMethod(c.getCountryName());
setCountryForTransliterationMethod(c.getCountryName());
if(basemap) {
renderedState |= 1;
} else {
@ -599,15 +596,15 @@ public class MapRenderRepositories {
return mi;
}
private void setTransliterationMethod(String countryName) {
if(TransliterationHelper.getActiveMapLanguage()!=1001) {
private void setCountryForTransliterationMethod(String countryName) {
if(!countryName.equals(TransliterationHelper.getCountry())) {
switch (countryName) {
case "Japan": {
setActiveMapLanguage(TransliterationHelper.JAPANESE);
setCountry(countryName);
break;
}
default:
setActiveMapLanguage(TransliterationHelper.DEFAULT);
setCountry(TransliterationHelper.DEFAULT);
break;
}
}