001 /**
002 * Copyright (C) 2007-2009, Jens Lehmann
003 *
004 * This file is part of DL-Learner.
005 *
006 * DL-Learner is free software; you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation; either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * DL-Learner is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with this program. If not, see <http://www.gnu.org/licenses/>.
018 *
019 */
020 package org.dllearner.scripts.matching;
021
022 import java.net.URI;
023
024 import org.dllearner.kb.sparql.SPARQLTasks;
025 import org.dllearner.kb.sparql.SparqlEndpoint;
026 import org.dllearner.kb.sparql.SparqlQuery;
027
028 import com.hp.hpl.jena.query.QuerySolution;
029 import com.hp.hpl.jena.query.ResultSet;
030
031 /**
032 * Computes owl:sameAs links between DBpedia and LinkedGeoData
033 * (or Wikipedia and OSM).
034 *
035 * @author Jens Lehmann
036 *
037 */
038 public class DBpediaLinkedGeoData {
039
040 public static void main(String[] args) {
041
042 // we start from the DBpedia URI and try to find the corresponding
043 // OSM URI (assuming that each location having coordinates in Wikipedia also
044 // exists in OSM)
045 URI dbpediaURI = URI.create("http://dbpedia.org/resource/Auerbachs_Keller");
046
047 // use official DBpedia endpoint (switch to db0 later)
048 SparqlEndpoint endpoint = SparqlEndpoint.getEndpointDBpedia();
049 SPARQLTasks st = new SPARQLTasks(endpoint);
050
051 // query latitude and longitude
052 String query = "SELECT ?lat ?long WHERE { ";
053 query += "<" + dbpediaURI + "> <http://www.w3.org/2003/01/geo/wgs84_pos#lat> ?lat .";
054 query += "<" + dbpediaURI + "> <http://www.w3.org/2003/01/geo/wgs84_pos#long> ?long . } LIMIT 1";
055
056 // perform query and read lat and long from results
057 ResultSet results = st.queryAsResultSet2(query);
058 QuerySolution qs = results.nextSolution();
059 String geoLat = qs.getLiteral("lat").getString();
060 String geoLong = qs.getLiteral("long").getString();
061
062 System.out.println("lat: " + geoLat + ", long: " + geoLong);
063
064 }
065
066 }