Changeset 15679 in josm for trunk/src/org
- Timestamp:
- 2020-01-10T23:35:22+01:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/util/Tag2Link.java
r15677 r15679 26 26 /** 27 27 * Extracts web links from OSM tags. 28 * <p></p> 29 * The following rules are used: 30 * <ul> 31 * <li>internal rules for basic tags</li> 32 * <li>rules from Wikidata based on OSM tag or key (P1282); formatter URL (P1630); third-party formatter URL (P3303)</li> 33 * <li>rules from OSM Sophox based on permanent key ID (P16); formatter URL (P8)</li> 34 * </ul> 28 35 * 29 36 * @since 15673 … … 35 42 36 43 /** 37 * Maps OSM keys to formatter URLs from Wikidata where {@code "$1"} has to be replaced by a value.44 * Maps OSM keys to formatter URLs from Wikidata and OSM Sophox where {@code "$1"} has to be replaced by a value. 38 45 */ 39 46 protected static MultiMap<String, String> wikidataRules = new MultiMap<>(); … … 53 60 public static void initialize() { 54 61 try { 55 fetchRulesFromWikidata(); 62 wikidataRules.clear(); 63 fetchRulesViaSPARQL("resource://data/tag2link.wikidata.sparql", "https://query.wikidata.org/sparql"); 64 fetchRulesViaSPARQL("resource://data/tag2link.sophox.sparql", "https://sophox.org/sparql"); 56 65 } catch (Exception e) { 57 66 Logging.error("Failed to initialize tag2link rules"); … … 63 72 * Fetches rules from Wikidata using a SPARQL query. 64 73 * 74 * @param query the SPARQL query 75 * @param server the query server 65 76 * @throws IOException in case of I/O error 66 77 */ 67 private static void fetchRulesFromWikidata() throws IOException { 68 final String sparql = new String(new CachedFile("resource://data/tag2link.sparql").getByteContent(), Charsets.UTF_8); 69 final CachedFile sparqlFile = new CachedFile("https://query.wikidata.org/sparql?query=" + Utils.encodeUrl(sparql)) 78 private static void fetchRulesViaSPARQL(final String query, final String server) throws IOException { 79 final int initialSize = wikidataRules.size(); 80 final String sparql = new String(new CachedFile(query).getByteContent(), Charsets.UTF_8); 81 final CachedFile sparqlFile = new CachedFile(server + "?query=" + Utils.encodeUrl(sparql)) 70 82 .setHttpAccept("application/json"); 71 83 … … 86 98 .forEach(wikidataRules::remove); 87 99 100 final int size = wikidataRules.size() - initialSize; 88 101 Logging.info(trn( 89 102 "Obtained {0} Tag2Link rule from {1}", 90 103 "Obtained {0} Tag2Link rules from {1}", 91 wikidataRules.size(), wikidataRules.size(), "Wikidata"));104 size, size, server)); 92 105 } 93 106
Note:
See TracChangeset
for help on using the changeset viewer.