From: <jen...@us...> - 2009-04-20 15:12:17
|
Revision: 1719 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1719&view=rev Author: jenslehmann Date: 2009-04-20 15:12:11 +0000 (Mon, 20 Apr 2009) Log Message: ----------- method to find all geo-locations in DBpedia and write them to an N-Triple file Modified Paths: -------------- trunk/README trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlEndpoint.java trunk/src/dl-learner/org/dllearner/scripts/matching/DBpediaLinkedGeoData.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/scripts/matching/DBpediaPoint.java Modified: trunk/README =================================================================== --- trunk/README 2009-04-20 12:14:59 UTC (rev 1718) +++ trunk/README 2009-04-20 15:12:11 UTC (rev 1719) @@ -14,4 +14,5 @@ DL-Learner is Open Source and licenced unter the GNU General Public License. Documentation for DL-Learner (e.g. various configuration options) can be found -in the "doc" directory and at http://dl-learner.org. +in the "doc" directory and at http://dl-learner.org. We recommend to read +doc/manual.pdf to get started. Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlEndpoint.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlEndpoint.java 2009-04-20 12:14:59 UTC (rev 1718) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlEndpoint.java 2009-04-20 15:12:11 UTC (rev 1719) @@ -172,6 +172,18 @@ return new SparqlEndpoint(u, defaultGraphURIs, new LinkedList<String>()); } + public static SparqlEndpoint getEndpointLOCALGeoData() { + URL u = null; + try { + u = new URL("http://139.18.2.37:8890/sparql"); + } catch (Exception e) { + e.printStackTrace(); + } + LinkedList<String> defaultGraphURIs=new LinkedList<String>(); + defaultGraphURIs.add("http://linkedgeodata.org"); + return new SparqlEndpoint(u, defaultGraphURIs, new LinkedList<String>()); + } + public static SparqlEndpoint getEndpointlocalJoseki() { URL u = null; try { Modified: trunk/src/dl-learner/org/dllearner/scripts/matching/DBpediaLinkedGeoData.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/matching/DBpediaLinkedGeoData.java 2009-04-20 12:14:59 UTC (rev 1718) +++ trunk/src/dl-learner/org/dllearner/scripts/matching/DBpediaLinkedGeoData.java 2009-04-20 15:12:11 UTC (rev 1719) @@ -20,6 +20,8 @@ package org.dllearner.scripts.matching; import java.io.BufferedReader; +import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.net.URI; @@ -28,6 +30,7 @@ import org.dllearner.kb.sparql.SPARQLTasks; import org.dllearner.kb.sparql.SparqlEndpoint; +import org.dllearner.kb.sparql.SparqlQuery; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; @@ -41,8 +44,24 @@ */ public class DBpediaLinkedGeoData { + private static File dbpediaFile = new File("log/DBpedia_POIs.nt"); + private static boolean regenerateFile = false; + + private static SparqlEndpoint dbpediaEndpoint = SparqlEndpoint.getEndpointLOCALDBpedia(); + private static SparqlEndpoint geoDataEndpoint = SparqlEndpoint.getEndpointLOCALGeoData(); + public static void main(String[] args) throws IOException { + // download all objects having geo-coordinates from DBpedia if necessary + if(!dbpediaFile.exists() || regenerateFile) { + createDBpediaFile(); + } + + // read file point by point + // for each point: call match method + + System.exit(0); + // we start from the DBpedia URI and try to find the corresponding // OSM URI (assuming that each location having coordinates in Wikipedia also // exists in OSM) @@ -90,4 +109,58 @@ } + // downloads information about DBpedia into a separate file + private static void createDBpediaFile() throws IOException { + + // use this to set the "chunk size" for getting DBpedia points + int limit = 1000; + int offset = 0; + + int counter = 0; + FileOutputStream fos = new FileOutputStream(dbpediaFile, true); + + do { + counter = 0; + + // query DBpedia for all objects having geo-coordinates + String queryStr = "SELECT ?object, ?lat, ?long, ?label WHERE {"; + queryStr += "?object <http://www.w3.org/2003/01/geo/wgs84_pos#lat> ?lat ."; + queryStr += "?object <http://www.w3.org/2003/01/geo/wgs84_pos#long> ?long ."; + queryStr += "?object rdfs:label ?label . }"; + queryStr += "LIMIT " + limit + " OFFSET " + offset; + + SparqlQuery query = new SparqlQuery(queryStr, dbpediaEndpoint); + ResultSet rs = query.send(); + + while(rs.hasNext()) { + QuerySolution qs = rs.nextSolution(); + + String object = qs.get("object").toString(); + String geoLat = qs.getLiteral("lat").getString(); + String geoLong = qs.getLiteral("long").getString(); + String label = qs.getLiteral("label").getString(); + + String content = "<" + object + ">" + " <http://www.w3.org/2000/01/rdf-schema#label> \"" + label + "\" .\n"; + content += "<" + object + ">" + " <http://www.w3.org/2003/01/geo/wgs84_pos#lat> \"" + geoLat + "\"^^<http://www.w3.org/2001/XMLSchema#float> .\n"; + content += "<" + object + ">" + " <http://www.w3.org/2003/01/geo/wgs84_pos#long> \"" + geoLong + "\"^^<http://www.w3.org/2001/XMLSchema#float> .\n"; + + fos.write(content.getBytes()); + + counter++; + } + + offset += limit; + System.out.println(offset + " points queried."); + + } while(counter == limit); + + + fos.close(); + + } + + private static URI findLinkedGeoDataMatch(DBpediaPoint dbpediaPoint) { + + return null; + } } Added: trunk/src/dl-learner/org/dllearner/scripts/matching/DBpediaPoint.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/matching/DBpediaPoint.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/scripts/matching/DBpediaPoint.java 2009-04-20 15:12:11 UTC (rev 1719) @@ -0,0 +1,28 @@ +/** + * Copyright (C) 2007-2009, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.scripts.matching; + +/** + * @author Jens Lehmann + * + */ +public class DBpediaPoint { + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |