I would like to get some places from DBPedia in certain area, and that would be easy if those points would had geometry property. However, all they have is georss:point. I have converted this to two doubles, but I cannot convert them to geo:geometry object that can be supplied to location filter.
The code I have thus far:
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?name
?abstract
?ns
?ew
WHERE
{ ?m foaf:name ?name
. ?m georss:point ?coord
. ?m <http://dbpedia.org/ontology/abstract> ?abstract
. BIND( xsd:double(strbefore( ?coord, " " )) AS ?ns )
BIND( xsd:double(strafter( ?coord, " " )) AS ?ew )
BIND( geo:Point(?ew, ?ns) AS ?geo ) # <-- I have problem with this
FILTER (bif:st_intersects (?geo, bif:st_point(?geo), 10))
FILTER (LANG(?abstract) = "en")
}
If you know any way to convert those or other filtering method, please enlighten me. :)
There is not enough information here to give you a simple and clear answer.
However, I think you may be able to figure it out from the examples in the GEOSPARQL documentation for Virtuoso, the DBMS engine which hosts DBpedia. There's more here.
Related
I need to find the names of similar types from DBpedia so I'm trying to figure out a query which can return me the names of entities which have same subject type in its dct:subject (example I want to find similar types of white house so i want to write a query for same . I'm considering the dct:subject to find them ). If there is any other approach please mention it
Previously I tried it for rdf:type but the result are not so good and some time it shows time out
I have done my problem by the query mentioned below and now i want to consider dct:subject instead of rdf:type
select distinct ?label ?resource count(distinct ?type) as ?score where {
values ?type { dbo:Thing dbo:Organization yago:WikicatIslam-relatedControversies yago:WikicatIslamistGroups yago:WikicatRussianFederalSecurityServiceDesignatedTerroristOrganizations yago:Abstraction100002137 yago:Act100030358 yago:Cabal108241798 yago:Group100031264 yago:Movement108464601 yago:PoliticalMovement108472335
}
?resource rdfs:label ?label ;
foaf:name ?name ;
a ?type .
FILTER (lang(?label) = 'en').
}
ORDER BY DESC(?score)
I’m new to query languages and linked data so thanks a lot for the help. I also have a similar question about sparql on wikidata
Wikidata sparql query returns 0 result
I would like to look up all the art movements in dbpedia with the associated artists (associated with the movement -peopleNam, famous for the movement-famousName, influence the movement-influenceName) here is my query with lots of redundant prefix (that I could not enter because of the amount of links)
SELECT ?movementName ?famousName ?peopleName ?influenceName
WHERE {
?m dc:subject <http://dbpedia.org/resource/Category:Art_movements> .
?m rdfs:label ?movementName .
FILTER(LANG(?movementName) = "en")
?m dbp:knownFor ?a .
?a rdfs:label ?famousName .
FILTER(LANG(?famousName) = "en")
?m dbp:movement ?b .
?b rdfs:label ?peopleName .
FILTER(LANG(?peopleName) = "en")
?m dbp:influencedBy ?d .
?d rdfs:label ?influenceName .
FILTER(LANG(?influenceName) = "en")
}'
When I run the query with only the movement name I get 235 results but whenever I add any other artist name, I get 0 result. Could you show me what went wrong?
A similar query is done in wikidata with some encouraging results but I haven’t tried to match the two sources yet.
Thanks
I'm entering the following query at http://dbpedia.org/sparql:
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
SELECT ?s ?name ?value ?lat ?lng
WHERE {
?s a <http://dbpedia.org/ontology/PopulatedPlace> .
?s <http://dbpedia.org/property/name> ?name .
?s <http://dbpedia.org/property/populationTotal> ?value .
FILTER (?lng > -8.64 AND ?lng < 2.1 AND ?lat < 61.1 AND ?lat > 49.35 )
?s geo:lat ?lat .
?s geo:long ?lng .
}
(The bounding box is intended to be for the UK, the other option is to add <http://dbpedia.org/ontology/country> <http://dbpedia.org/resource/United_Kingdom> ., but there's a possibility that some places might not have been tagged with UK as the country).
The problem is that it doesn't seem to be pulling back many places (around 290).
Swapping population for populationTotal gives 1588 places, and I can't figure out (semantically) which one should be used.
Is this a limitation with the underlying data, or is there something that could be improved in the way I'm formulating the query?
Note: this question is mainly academic now as I got the info from http://download.geonames.org/export/dump/GB.zip, but I'd much prefer to use open data and the semantic web, so posting up this question to see if there was something I was missing, or to find out if there is a shortcoming in how the data is being scraped from Wikipedia and whether I can muck in.
Your query is only returning locations that have a value for populationTotal. For example, if Town A has "10,000" for populationTotal in the database, and Town B has NULL, only Town A will be returned.
If you want to return all locations in the UK, then you need to specify population as an optional parameter. This query will show you all the locations, as well as the populations for the ones that have that data.
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
SELECT ?s ?name ?value ?lat ?lng
WHERE {
?s a <http://dbpedia.org/ontology/PopulatedPlace> .
?s <http://dbpedia.org/property/name> ?name .
OPTIONAL { ?s <http://dbpedia.org/property/populationTotal> ?value . }
FILTER (?lng > -8.64 AND ?lng < 2.1 AND ?lat < 61.1 AND ?lat > 49.35 )
?s geo:lat ?lat .
?s geo:long ?lng .
}
is there a way to query dbpedia's other language version? I would like to use data that is often non-existent in English version of dbpedia. For example, en and de, the second one has georss property and first one does not.
My problem is, query below won't fetch Aachen's Cathedral as in English version in does not have any georss data. How can I ask de.dbpedia.org for data?
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?name ?abstract ?ns ?ew
WHERE{
?m <http://dbpedia.org/ontology/abstract> ?abstract.
?m foaf:name ?name.
?m georss:point ?coord.
bind( xsd:double(strbefore( ?coord, " " )) as ?ns )
bind( xsd:double(strafter( ?coord, " " )) as ?ew )
FILTER ( ?ns > 50.5 && ?ns < 50.9 && ?ew > 6.02 && ?ew < 6.14 )
FILTER (LANG(?abstract) = "de")
}
You can run your query against the localized SPARQL endpoint. In this case, try running your query against http://de.dbpedia.org/sparql. When I do that, I get results that include Aachen (though I'm not a German speaker, so I don't know whether the description is what you're looking for).
I'm using Jena TDB for store a dataset of triples from a file. I have a problem when I try to send a SPARQL query to TDB using filter. For example the following query works:
select ?ob where {
?ob rdfs:label "NameOfLabel"#language .
}
but this doesn't:
select ?ob where {
?ob rdfs:label ?pr .
filter( ?pr = "NameOfLabel" ) .
}
The purpose of this query is to find an ?ob from a "NameOfLabel" (ignoring the language). I've tried regex and str(?pr), and some other things, but these haven't worked. How can I do this?
Update (based on answer)
When I try using filter( str(?pr) = "NameOfLabel" ), I get an exception. Here's the stack trace:
Exception in thread "main" java.lang.IllegalArgumentException: getLow: Empty RecordBuffer
at com.hp.hpl.jena.tdb.base.buffer.RecordBuffer.getLow(RecordBuffer.java:59)
at com.hp.hpl.jena.tdb.base.recordbuffer.RecordRangeIterator.hasNext(RecordRangeIterator.java:112)
at org.apache.jena.atlas.iterator.Iter$4.hasNext(Iter.java:317)
at com.hp.hpl.jena.tdb.sys.DatasetControlMRSW$IteratorCheckNotConcurrent.hasNext(DatasetControlMRSW.java:119)
at org.apache.jena.atlas.iterator.Iter$4.hasNext(Iter.java:317)
at org.apache.jena.atlas.iterator.Iter$3.hasNext(Iter.java:200)
at org.apache.jena.atlas.iterator.Iter.hasNext(Iter.java:915)
at org.apache.jena.atlas.iterator.RepeatApplyIterator.hasNext(RepeatApplyIterator.java:59)
at com.hp.hpl.jena.tdb.solver.SolverLib$IterAbortable.hasNext(SolverLib.java:191)
at org.apache.jena.atlas.iterator.Iter$4.hasNext(Iter.java:317)
at com.hp.hpl.jena.sparql.engine.iterator.QueryIterPlainWrapper.hasNextBinding(QueryIterPlainWrapper.java:54)
at com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:112)
at com.hp.hpl.jena.sparql.engine.iterator.QueryIterConvert.hasNextBinding(QueryIterConvert.java:59)
at com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:112)
at com.hp.hpl.jena.sparql.engine.iterator.QueryIterDistinctReduced.hasNextBinding(QueryIterDistinctReduced.java:54)
at com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:112)
at com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorWrapper.hasNextBinding(QueryIteratorWrapper.java:40)
at com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:112)
at com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorWrapper.hasNextBinding(QueryIteratorWrapper.java:40)
at com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:112)
at com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorWrapper.hasNextBinding(QueryIteratorWrapper.java:40)
at com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:112)
at com.hp.hpl.jena.sparql.engine.ResultSetStream.hasNext(ResultSetStream.java:75)
EDIT II:
Dataset dataset = TDBFactory.createDataset(DIRECTORY);
dataset.begin(ReadWrite.READ);
QueryExecution qExec = QueryExecutionFactory.create(query, dataset) ;
ResultSet risultati = qExec.execSelect();
while(risultati.hasNext()){
system.out.println(risultati.next());
}
The plain literal "NameOfLabel" is not the same as the literal with a language tag "NameOfLabel"#en. If
?ob rdfs:label "NameOfLabel"#en # (1)
works, then so should
?ob rdfs:label ?label .
filter ( ?label = "NameOfLabel"#en ) # (2)
If you want to compare the string content in a filter without comparing the language, just do:
?ob rdfs:label ?label .
filter ( str(?label) = "NameOfLabel" ) # (3)
Note that (2) is really not very good practice. It doesn't make much sense to filter on exact values, because you can just use (1) instead. (3) is OK, because you do actually need to use the str function. If you want to specify some exact values at run time, and have variables in the query, you also have the option of
values ?label { "NameOfObject"#en }
?ob rdfs:label ?label .
which has the advantage of being able to specify multiple values for ?label. If you're using Jena, you can also use a ParameterizedSparqlString and just have the pattern
?ob rdfs:label ?label .
but replace ?label when you have the value that you want. See my answer to get latitude and longitude of a place dbpedia for an example of ParameterizedSparqlStrings.