使用SPARQL查询DBpedia以获取POI

时间:2012-06-16 12:15:36

标签: sparql dbpedia

我尝试从特殊的经度和纬度获得所有POI。

你能给我一个提示,以获得更好的结果吗?我现在在结果集中获得:Germany:M-Bahn等主题。

这是我的java代码:

public class DBPedia_SparqSql {

  /**
   * @param args
   */
  public static void main(String[] args) {
    // TODO Auto-generated method stub
    float YOUR_LONG = 13.380834f;
    float YOUR_LAT = 52.516388f;
    float radius = 0.01f;
    String sparqlQueryString1= "PREFIX owl: <http://www.w3.org/2002/07/owl#> "+
    "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> "+
    "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> "+
    "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "+
    "PREFIX foaf: <http://xmlns.com/foaf/0.1/> "+
    "PREFIX dc: <http://purl.org/dc/elements/1.1/> "+
    "PREFIX : <http://dbpedia.org/resource/> "+
    "PREFIX dbpedia2: <http://dbpedia.org/property/> "+
    "PREFIX dbpedia: <http://dbpedia.org/> "+
    "PREFIX skos: <http://www.w3.org/2004/02/skos/core#> "+
    "PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> "+
    "PREFIX onto: <http://dbpedia.org/ontology/> " +
    "PREFIX dcterms: <http://purl.org/dc/terms/> "+
    "SELECT DISTINCT ?s ?sub ?long ?lat WHERE {"+
    "?s a onto:Place . "+
    "?s geo:lat ?lat . "+
    "?s geo:long ?long . " +
    "?s dcterms:subject ?sub "+
    " FILTER ( ?long > "+(YOUR_LONG-radius)+"&& ?long < "+(YOUR_LONG+radius)+" && ?lat > "+(YOUR_LAT-radius)+" && ?lat < "+(YOUR_LAT+radius)+")}"+
    "LIMIT 200";
    System.out.println(sparqlQueryString1);

    Query query = QueryFactory.create(sparqlQueryString1);
    QueryExecution qexec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", query);

    ResultSet results = qexec.execSelect();
    ResultSetFormatter.out(System.out, results, query);       

    qexec.close() ;
  }

}

1 个答案:

答案 0 :(得分:1)

这取决于你对“更好”的意思。你正在寻找的是一个有区别的特征,一些“好”结果确实具有的属性,而“坏”结果则没有(或者相反)。

找出要查询的属性的一个好方法是只去特定主题的DBPedia资源页面,看看有什么。 page for Germany显示了DBPedia对该主题的了解:它是一个国家,它的人口规模是多少等。

要查看的好属性是rdf:type属性。查看您确实要返回的结果是否共享某些值,然后将其添加到查询中。但您也可以使用其他(组合)属性。我无法告诉你这些属性或值应该是什么,只有你知道自己的用例。

相关问题