Changeset 15679 in josm for trunk


Ignore:
Timestamp:
2020-01-10T23:35:22+01:00 (4 years ago)
Author:
simon04
Message:

see #13901 see #18542 - Obtain tag2link rules from OSM Sophox

Location:
trunk
Files:
2 added
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/data/tag2link.wikidata.sparql

    r15677 r15679  
    99  }
    1010}
    11 ORDER BY LCASE(?OSM_tag_or_key)
  • trunk/src/org/openstreetmap/josm/gui/util/Tag2Link.java

    r15677 r15679  
    2626/**
    2727 * 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>
    2835 *
    2936 * @since 15673
     
    3542
    3643    /**
    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.
    3845     */
    3946    protected static MultiMap<String, String> wikidataRules = new MultiMap<>();
     
    5360    public static void initialize() {
    5461        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");
    5665        } catch (Exception e) {
    5766            Logging.error("Failed to initialize tag2link rules");
     
    6372     * Fetches rules from Wikidata using a SPARQL query.
    6473     *
     74     * @param query the SPARQL query
     75     * @param server the query server
    6576     * @throws IOException in case of I/O error
    6677     */
    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))
    7082                .setHttpAccept("application/json");
    7183
     
    8698                .forEach(wikidataRules::remove);
    8799
     100        final int size = wikidataRules.size() - initialSize;
    88101        Logging.info(trn(
    89102                "Obtained {0} Tag2Link rule from {1}",
    90103                "Obtained {0} Tag2Link rules from {1}",
    91                 wikidataRules.size(), wikidataRules.size(), "Wikidata"));
     104                size, size, server));
    92105    }
    93106
Note: See TracChangeset for help on using the changeset viewer.