added synonyms support

This commit is contained in:
Chumva 2018-03-17 19:12:29 +02:00
parent bf7f0424df
commit 22ccbc9ff6
4 changed files with 70 additions and 14 deletions

View file

@ -17,7 +17,10 @@ public abstract class AbstractPoiType {
private AbstractPoiType baseLangType;
private boolean notEditableOsm;
private String poiAdditionalCategory;
private List<String> excludedPoiAdditionalCategoies;
private List<String> excludedPoiAdditionalCategories;
private String synonyms;
private String enTranslation;
private String translation;
public AbstractPoiType(String keyName, MapPoiTypes registry) {
this.keyName = keyName;
@ -66,12 +69,26 @@ public abstract class AbstractPoiType {
public String getTranslation() {
return registry.getTranslation(this);
if(translation == null) {
translation = registry.getTranslation(this);
}
return translation;
}
public String getSynonyms() {
if(synonyms == null) {
synonyms = registry.getSynonyms(this);
}
return synonyms;
}
public String getEnTranslation() {
return registry.getEnTranslation(this);
if(enTranslation == null) {
enTranslation = registry.getEnTranslation(this);
}
return enTranslation;
}
public String getPoiAdditionalCategoryTranslation() {
@ -137,14 +154,14 @@ public abstract class AbstractPoiType {
}
public List<String> getExcludedPoiAdditionalCategories() {
return excludedPoiAdditionalCategoies;
return excludedPoiAdditionalCategories;
}
public void addExcludedPoiAdditionalCategories(String[] excludedPoiAdditionalCategories) {
if (excludedPoiAdditionalCategoies == null) {
excludedPoiAdditionalCategoies = new ArrayList<>();
if (this.excludedPoiAdditionalCategories == null) {
this.excludedPoiAdditionalCategories = new ArrayList<>();
}
Collections.addAll(excludedPoiAdditionalCategoies, excludedPoiAdditionalCategories);
Collections.addAll(this.excludedPoiAdditionalCategories, excludedPoiAdditionalCategories);
}
public abstract Map<PoiCategory, LinkedHashSet<String>> putTypes(Map<PoiCategory, LinkedHashSet<String>> acceptedTypes);

View file

@ -55,8 +55,10 @@ public class MapPoiTypes {
String getTranslation(String keyName);
String getEnTranslation(AbstractPoiType type);
String getEnTranslation(String keyName);
String getSynonyms(AbstractPoiType type);
String getSynonyms(String keyName);
}
public static MapPoiTypes getDefaultNoInit() {
@ -699,6 +701,15 @@ public class MapPoiTypes {
}
public String getSynonyms(AbstractPoiType abstractPoiType) {
if (poiTranslator != null) {
String translation = poiTranslator.getSynonyms(abstractPoiType);
if (!Algorithms.isEmpty(translation)) {
return translation;
}
}
return "";
}
public String getEnTranslation(AbstractPoiType abstractPoiType) {
if (poiTranslator != null) {
String translation = poiTranslator.getEnTranslation(abstractPoiType);

View file

@ -1,6 +1,5 @@
package net.osmand.search.core;
import com.google.openlocationcode.OpenLocationCode;
import com.jwetherell.openmap.common.LatLonPoint;
import com.jwetherell.openmap.common.UTMPoint;
@ -50,7 +49,6 @@ import java.util.Set;
import java.util.TreeSet;
import gnu.trove.list.array.TIntArrayList;
import gnu.trove.set.hash.TLongHashSet;
public class SearchCoreFactory {
@ -616,13 +614,17 @@ public class SearchCoreFactory {
List<AbstractPoiType> results = new ArrayList<AbstractPoiType>() ;
NameStringMatcher nm = phrase.getNameStringMatcher();
for (PoiFilter pf : topVisibleFilters) {
if (!phrase.isUnknownSearchWordPresent() || nm.matches(pf.getTranslation()) || nm.matches(pf.getEnTranslation())) {
if (!phrase.isUnknownSearchWordPresent() ||
nm.matches(pf.getTranslation()) || nm.matches(pf.getEnTranslation()) ||
nm.matches(pf.getSynonyms())) {
results.add(pf);
}
}
if (phrase.isUnknownSearchWordPresent()) {
for (PoiCategory c : categories) {
if (!results.contains(c) && (nm.matches(c.getTranslation()) || nm.matches(c.getEnTranslation()) ) ) {
if (!results.contains(c) &&
(nm.matches(c.getTranslation()) || nm.matches(c.getEnTranslation())
|| nm.matches(c.getSynonyms())) ) {
results.add(c);
}
}
@ -631,14 +633,17 @@ public class SearchCoreFactory {
Entry<String, PoiType> e = it.next();
PoiType pt = e.getValue();
if (pt.getCategory() != types.getOtherMapCategory()) {
if (!results.contains(pt) && ( nm.matches(pt.getEnTranslation()) || nm.matches(pt.getTranslation()) )) {
if (!results.contains(pt) && (
nm.matches(pt.getEnTranslation()) || nm.matches(pt.getTranslation())
|| nm.matches(pt.getSynonyms()) )) {
results.add(pt);
}
List<PoiType> additionals = pt.getPoiAdditionals();
if (additionals != null) {
for (PoiType a : additionals) {
if (!a.isReference() && !results.contains(a) &&
( nm.matches(a.getEnTranslation()) || nm.matches(a.getTranslation()) )) {
( nm.matches(a.getEnTranslation()) || nm.matches(a.getTranslation())
|| nm.matches(a.getSynonyms()) )) {
results.add(a);
}
}

View file

@ -357,6 +357,29 @@ public class AppInitializer implements IProgress {
return null;
}
@Override
public String getSynonyms(AbstractPoiType type) {
if(type.getBaseLangType() != null) {
return getSynonyms(type.getBaseLangType());
}
return getSynonyms(type.getIconKeyName());
}
@Override
public String getSynonyms(String keyName) {
try {
Field f = R.string.class.getField("synonyms_poi_" + keyName);
if (f != null) {
Integer in = (Integer) f.get(null);
return app.getString(in);
}
} catch (Exception e) {
// LOG.debug("No translation for "+ keyName + " " + e.getMessage());
}
return "";
}
@Override
public String getEnTranslation(AbstractPoiType type) {
if(type.getBaseLangType() != null) {