From b8b3c87ba77c423f9a84fe475b544deb52b742c4 Mon Sep 17 00:00:00 2001 From: Michael Peter Christen Date: Thu, 14 Jun 2012 09:44:14 +0200 Subject: [PATCH] - renamed localization to location (that was confusing) - renamed 'Locale' navigator to 'Location' - produce Location navigation only if geolocation libraries are loaded --- htroot/DictionaryLoader_p.java | 8 +++--- htroot/yacysearchtrailer.java | 2 +- .../net/yacy/cora/lod/vocabulary/Tagging.java | 4 +-- source/net/yacy/document/Autotagging.java | 9 ++++--- source/net/yacy/document/LibraryProvider.java | 2 +- .../geolocalization/GeonamesLocalization.java | 8 +++--- .../{Localization.java => Locations.java} | 6 ++--- .../OpenGeoDBLocalization.java | 8 +++--- .../OverarchingLocalization.java | 26 +++++++++---------- 9 files changed, 37 insertions(+), 36 deletions(-) rename source/net/yacy/document/geolocalization/{Localization.java => Locations.java} (97%) diff --git a/htroot/DictionaryLoader_p.java b/htroot/DictionaryLoader_p.java index 9568816e2..3f0cebfcf 100644 --- a/htroot/DictionaryLoader_p.java +++ b/htroot/DictionaryLoader_p.java @@ -69,7 +69,7 @@ public class DictionaryLoader_p { final byte[] b = response.getContent(); FileUtils.copy(b, LibraryProvider.Dictionary.GEON0.file()); LibraryProvider.geoLoc.addLocalization(LibraryProvider.Dictionary.GEON0.nickname, new GeonamesLocalization(LibraryProvider.Dictionary.GEON0.file())); - LibraryProvider.autotagging.addLocalization(LibraryProvider.geoLoc); + LibraryProvider.autotagging.addPlaces(LibraryProvider.geoLoc); prop.put("geon0Status", LibraryProvider.Dictionary.GEON0.file().exists() ? 1 : 0); prop.put("geon0ActionLoaded", 1); } catch (final MalformedURLException e) { @@ -99,7 +99,7 @@ public class DictionaryLoader_p { if (post.containsKey("geon0Activate")) { LibraryProvider.Dictionary.GEON0.fileDisabled().renameTo(LibraryProvider.Dictionary.GEON0.file()); LibraryProvider.geoLoc.addLocalization(LibraryProvider.Dictionary.GEON0.nickname, new GeonamesLocalization(LibraryProvider.Dictionary.GEON0.file())); - LibraryProvider.autotagging.addLocalization(LibraryProvider.geoLoc); + LibraryProvider.autotagging.addPlaces(LibraryProvider.geoLoc); prop.put("geon0ActionActivated", 1); } @@ -112,7 +112,7 @@ public class DictionaryLoader_p { FileUtils.copy(b, LibraryProvider.Dictionary.GEODB1.file()); LibraryProvider.geoLoc.removeLocalization(LibraryProvider.Dictionary.GEODB0.nickname); LibraryProvider.geoLoc.addLocalization(LibraryProvider.Dictionary.GEODB1.nickname, new OpenGeoDBLocalization(LibraryProvider.Dictionary.GEODB1.file(), false)); - LibraryProvider.autotagging.addLocalization(LibraryProvider.geoLoc); + LibraryProvider.autotagging.addPlaces(LibraryProvider.geoLoc); prop.put("geo1Status", LibraryProvider.Dictionary.GEODB1.file().exists() ? 1 : 0); prop.put("geo1ActionLoaded", 1); } catch (final MalformedURLException e) { @@ -142,7 +142,7 @@ public class DictionaryLoader_p { if (post.containsKey("geo1Activate")) { LibraryProvider.Dictionary.GEODB1.fileDisabled().renameTo(LibraryProvider.Dictionary.GEODB1.file()); LibraryProvider.geoLoc.addLocalization(LibraryProvider.Dictionary.GEODB1.nickname, new OpenGeoDBLocalization(LibraryProvider.Dictionary.GEODB1.file(), false)); - LibraryProvider.autotagging.addLocalization(LibraryProvider.geoLoc); + LibraryProvider.autotagging.addPlaces(LibraryProvider.geoLoc); prop.put("geo1ActionActivated", 1); } diff --git a/htroot/yacysearchtrailer.java b/htroot/yacysearchtrailer.java index 67bbbfc5e..35cacd8a9 100644 --- a/htroot/yacysearchtrailer.java +++ b/htroot/yacysearchtrailer.java @@ -349,7 +349,7 @@ public class yacysearchtrailer { // category: location search // show only if there is a location database present and if there had been any search results - if (LibraryProvider.geoLoc.locations() == 0 || + if (LibraryProvider.geoLoc.size() == 0 || theSearch.getRankingResult().getLocalIndexCount() == 0) { prop.put("cat-location", 0); } else { diff --git a/source/net/yacy/cora/lod/vocabulary/Tagging.java b/source/net/yacy/cora/lod/vocabulary/Tagging.java index efd469eee..b23b0f53a 100644 --- a/source/net/yacy/cora/lod/vocabulary/Tagging.java +++ b/source/net/yacy/cora/lod/vocabulary/Tagging.java @@ -36,7 +36,7 @@ import java.util.regex.Pattern; import net.yacy.cora.storage.Files; import net.yacy.document.WordCache.Dictionary; -import net.yacy.document.geolocalization.Localization; +import net.yacy.document.geolocalization.Locations; public class Tagging { @@ -345,7 +345,7 @@ public class Tagging { } } - public Tagging(String name, Localization localization) { + public Tagging(String name, Locations localization) { this(name); Set locNames = localization.locationNames(); for (String loc: locNames) { diff --git a/source/net/yacy/document/Autotagging.java b/source/net/yacy/document/Autotagging.java index 16594ccdd..e3559f12a 100644 --- a/source/net/yacy/document/Autotagging.java +++ b/source/net/yacy/document/Autotagging.java @@ -32,7 +32,7 @@ import java.util.concurrent.ConcurrentHashMap; import net.yacy.cora.document.UTF8; import net.yacy.cora.lod.vocabulary.Tagging; import net.yacy.document.WordCache.Dictionary; -import net.yacy.document.geolocalization.Localization; +import net.yacy.document.geolocalization.Locations; import net.yacy.kelondro.logging.Log; /** @@ -130,13 +130,14 @@ public class Autotagging { } } - public void addLocalization(Localization localization) { - Tagging voc = new Tagging("Locale", localization); + public void addPlaces(Locations locations) { + if (locations.size() == 0) return; // otherwise we get a navigation that does nothing + Tagging voc = new Tagging("Locations", locations); try { voc.setObjectspace("http://dbpedia.org/resource/"); } catch (IOException e) { } - this.vocabularies.put("Locale", voc); + this.vocabularies.put("Locations", voc); for (String t: voc.tags()) { this.allTags.put(t, PRESENT); } diff --git a/source/net/yacy/document/LibraryProvider.java b/source/net/yacy/document/LibraryProvider.java index d9311434c..1d1c53b0f 100644 --- a/source/net/yacy/document/LibraryProvider.java +++ b/source/net/yacy/document/LibraryProvider.java @@ -113,7 +113,7 @@ public class LibraryProvider { initAutotagging(tagPrefix); Set allTags = new HashSet() ; allTags.addAll(autotagging.allTags()); // we must copy this into a clone to prevent circularity - autotagging.addLocalization(geoLoc); + autotagging.addPlaces(geoLoc); //autotagging.addDictionaries(dymLib.getDictionaries()); // strange results with this: normal word lists are 'too full' WordCache.learn(allTags); } diff --git a/source/net/yacy/document/geolocalization/GeonamesLocalization.java b/source/net/yacy/document/geolocalization/GeonamesLocalization.java index 2f6225069..e3325978d 100644 --- a/source/net/yacy/document/geolocalization/GeonamesLocalization.java +++ b/source/net/yacy/document/geolocalization/GeonamesLocalization.java @@ -42,7 +42,7 @@ import java.util.zip.ZipFile; import net.yacy.document.StringBuilderComparator; import net.yacy.kelondro.logging.Log; -public class GeonamesLocalization implements Localization +public class GeonamesLocalization implements Locations { /* @@ -131,7 +131,7 @@ public class GeonamesLocalization implements Localization } @Override - public int locations() { + public int size() { return this.id2loc.size(); } @@ -226,9 +226,9 @@ public class GeonamesLocalization implements Localization @Override public boolean equals(final Object other) { - if ( !(other instanceof Localization) ) { + if ( !(other instanceof Locations) ) { return false; } - return nickname().equals(((Localization) other).nickname()); + return nickname().equals(((Locations) other).nickname()); } } diff --git a/source/net/yacy/document/geolocalization/Localization.java b/source/net/yacy/document/geolocalization/Locations.java similarity index 97% rename from source/net/yacy/document/geolocalization/Localization.java rename to source/net/yacy/document/geolocalization/Locations.java index 4b7b87add..5652ab02b 100644 --- a/source/net/yacy/document/geolocalization/Localization.java +++ b/source/net/yacy/document/geolocalization/Locations.java @@ -27,17 +27,17 @@ import java.util.Set; import java.util.TreeSet; /** - * localization interface + * location interface * @author Michael Peter Christen * */ -public interface Localization { +public interface Locations { /** * the number of locations that this localization stores * @return the number of locations */ - public int locations(); + public int size(); /** * find a location by name diff --git a/source/net/yacy/document/geolocalization/OpenGeoDBLocalization.java b/source/net/yacy/document/geolocalization/OpenGeoDBLocalization.java index f3173684a..c6eb082b6 100644 --- a/source/net/yacy/document/geolocalization/OpenGeoDBLocalization.java +++ b/source/net/yacy/document/geolocalization/OpenGeoDBLocalization.java @@ -49,7 +49,7 @@ import net.yacy.kelondro.logging.Log; * of more than 100MB! This class will provide a super-fast access to the OpenGeoDB, since all request are * evaluated using data in the RAM. */ -public class OpenGeoDBLocalization implements Localization +public class OpenGeoDBLocalization implements Locations { private final Map id2loc; @@ -184,7 +184,7 @@ public class OpenGeoDBLocalization implements Localization } @Override - public int locations() { + public int size() { return this.id2loc.size(); } @@ -304,9 +304,9 @@ public class OpenGeoDBLocalization implements Localization @Override public boolean equals(final Object other) { - if ( !(other instanceof Localization) ) { + if ( !(other instanceof Locations) ) { return false; } - return nickname().equals(((Localization) other).nickname()); + return nickname().equals(((Locations) other).nickname()); } } diff --git a/source/net/yacy/document/geolocalization/OverarchingLocalization.java b/source/net/yacy/document/geolocalization/OverarchingLocalization.java index 26fded0ba..681f66af3 100644 --- a/source/net/yacy/document/geolocalization/OverarchingLocalization.java +++ b/source/net/yacy/document/geolocalization/OverarchingLocalization.java @@ -28,15 +28,15 @@ import java.util.Map; import java.util.Set; import java.util.TreeSet; -public class OverarchingLocalization implements Localization { +public class OverarchingLocalization implements Locations { - private final Map services; + private final Map services; /** * create a new overarching localization object */ public OverarchingLocalization() { - this.services = new HashMap(); + this.services = new HashMap(); } /** @@ -44,7 +44,7 @@ public class OverarchingLocalization implements Localization { * @param nickname the nickname of the service * @param service the service */ - public void addLocalization(final String nickname, final Localization service) { + public void addLocalization(final String nickname, final Locations service) { this.services.put(nickname, service); } @@ -61,10 +61,10 @@ public class OverarchingLocalization implements Localization { * @return the number of locations */ @Override - public int locations() { + public int size() { int locations = 0; - for (final Localization service: this.services.values()) { - locations += service.locations(); + for (final Locations service: this.services.values()) { + locations += service.size(); } return locations; } @@ -78,7 +78,7 @@ public class OverarchingLocalization implements Localization { @Override public TreeSet find(final String anyname, final boolean locationexact) { final TreeSet locations = new TreeSet(); - for (final Localization service: this.services.values()) { + for (final Locations service: this.services.values()) { locations.addAll(service.find(anyname, locationexact)); } return locations; @@ -91,7 +91,7 @@ public class OverarchingLocalization implements Localization { @Override public Set locationNames() { final Set locations = new HashSet(); - for (final Localization service: this.services.values()) { + for (final Locations service: this.services.values()) { locations.addAll(service.locationNames()); } return locations; @@ -108,7 +108,7 @@ public class OverarchingLocalization implements Localization { if (s.length() == 0) { return recommendations; } - for (final Localization service: this.services.values()) { + for (final Locations service: this.services.values()) { recommendations.addAll(service.recommend(s)); } return recommendations; @@ -125,7 +125,7 @@ public class OverarchingLocalization implements Localization { if (s.length() == 0) { return recommendations; } - for (final Localization service: this.services.values()) { + for (final Locations service: this.services.values()) { recommendations.addAll(service.recommend(s)); } return recommendations; @@ -156,10 +156,10 @@ public class OverarchingLocalization implements Localization { */ @Override public boolean equals(final Object other) { - if (!(other instanceof Localization)) { + if (!(other instanceof Locations)) { return false; } - return nickname().equals(((Localization) other).nickname()); + return nickname().equals(((Locations) other).nickname()); } }