Get all settlements coordinates in Israel from DBpedia - sparql

For my application I want to get the names and the geographic coordinates of most of settlements in Israel (Tel Aviv, Haife etc.).
My idea is to get it from DBpedia (querying the English pages is enough for me).
I tried this query:
SELECT distinct ?subject AS ?mainSubject ?o1 AS ?name ?o2 AS ?point ?o3 AS ?country
WHERE {?subject ?property <http://dbpedia.org/ontology/PopulatedPlace>.
?subject <http://xmlns.com/foaf/0.1/name> ?o1.
?subject <http://www.georss.org/georss/point> ?o2.
?subject <http://dbpedia.org/ontology/country> ?o3.
filter (contains(str(?o3),"Israel")) }
but I get only a few results.
For example I don't get :
https://en.wikipedia.org/wiki/Afula
https://en.wikipedia.org/wiki/Nahariya
Any ideas for better query?
Thanks.

You cannot get the results you want because they do not have georss information that you request. You can do it by OPTIONAL clause.
SELECT distinct ?subject AS ?mainSubject ?o1 AS ?name ?o2 AS ?point ?o3 AS ?country WHERE {
?subject ?property <http://dbpedia.org/ontology/PopulatedPlace>.
?subject <http://xmlns.com/foaf/0.1/name> ?o1.
OPTIONAL{?subject <http://www.georss.org/georss/point> ?o2.}
?subject <http://dbpedia.org/ontology/country> ?o3.
filter (contains(str(?o3),"Israel")) }
On the other hand, instead of FILTER you can directly put the resource of Israel:
SELECT distinct ?subject AS ?mainSubject ?o1 AS ?name ?o2 AS ?point WHERE {
?subject ?property <http://dbpedia.org/ontology/PopulatedPlace>.
?subject <http://xmlns.com/foaf/0.1/name ?o1.
OPTIONAL{?subject <http://www.georss.org/georss/point> ?o2.}
?subject <http://dbpedia.org/ontology/country> <http://dbpedia.org/resource/Israel>. }

Related

Get range class of Datatype property

I have the following SPARQL query
SELECT DISTINCT ?p ?class ?type
WHERE {
?resource ?p ?target .
?p rdfs:range ?class .
?class rdf:type ?type .
}
I get results only for the object properties.
If ?class = xsd:float, then rdf:type = rdfs:Datatype, right?
Why I do not receive also results for the type of data properties?

How to query all properties of owl:Thing of dbpedia using SPARQL?

When I use the following SPARQL query I get all properties of the DBpedia class Country:
select ?range ?domain ?prop ?label
Where{
?class rdfs:subClassOf{0,1} ?domain.
?prop rdfs:domain ?domain.
?prop rdfs:range ?range.
?prop rdfs:label ?label.
FILTER(lang(?label) = 'en')
FILTER(?class = <http://dbpedia.org/ontology/Country>)
}
When I try to do this with 'Thing' or 'OWL:Thing' or 'A Thing' or anything equivalent instead of Country, I get an empty result.
I want to adopt the ontology of DBpedia's owl:Thing, so I want to retrieve all properties of http://mappings.dbpedia.org/server/ontology/classes/owl%3AThing (including labela and range).
Does anyone know how I can achieve this?
There is not property in DBpedia with the domain owl:Thing:
select * {
?prop rdfs:domain owl:Thing
}
The reason for this is probably that if no explicit domain is given, owl:Thing is the trivial domain. You can check this also if you look at particular properties from your referred list, e.g. dbo:abbreviation
Workaround query:
SELECT ?range (owl:Thing as ?domain) ?prop ?label {
VALUES ?type {owl:DatatypeProperty owl:ObjectProperty}
?prop a ?type
OPTIONAL {?prop rdfs:range ?range }
?prop rdfs:label ?label.
FILTER(langmatches(lang(?label), 'en'))
FILTER NOT EXISTS {?prop rdfs:domain ?domain}
}

Aggregate properties

I'm developing my own Fuseki endpoint from some DBpedia data.
I'm in doubt on how to aggregate properties related to a single resource.
SELECT ?name ?website ?abstract ?genre ?image
WHERE{
VALUES ?s {<http://dbpedia.org/resource/Attack_Attack!>}
?s foaf:name ?name ;
dbo:abstract ?abstract .
OPTIONAL { ?s dbo:genre ?genre } .
OPTIONAL { ?s dbp:website ?website } .
OPTIONAL { ?s dbo:image ?image } .
FILTER LANGMATCHES(LANG(?abstract ), "en")
}
SPARQL endpoint: http://dbpedia.org/sparql/
This query returns 2 matching results. They are different just for the dbo:genre value. There is a way I can query the knowledge base and retrieving a single result with a list of genres?
#chrisis's query works well on the DBpedia SPARQL Endpoint, which is based on Virtuoso.
However, if you are using Jena Fuseki, you should use more conformant syntax:
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/property/>
SELECT
?name
(SAMPLE(?website) AS ?sample_website)
(SAMPLE(?abstract) AS ?sample_abstract)
(SAMPLE(?image) AS ?sample_image)
(GROUP_CONCAT(?genre; separator=', ') AS ?genres)
WHERE {
VALUES (?s) {(<http://dbpedia.org/resource/Attack_Attack!>)}
?s foaf:name ?name ;
dbo:abstract ?abstract .
OPTIONAL { ?s dbo:genre ?genre } .
OPTIONAL { ?s dbp:website ?website } .
OPTIONAL { ?s dbo:image ?image} .
FILTER LANGMATCHES(LANG(?abstract ), "en")
} GROUP BY ?name
The differences from the #chrisis's query are:
Since GROUP_CONCAT is an aggregation function, it might be used with GROUP BY only;
Since GROUP BY is used, all non-grouping variables should be aggregated (e.g. via SAMPLE);
GROUP_CONCAT syntax is slightly different.
In Fuseki, these AS in the projection are in fact superfluous: see this question and comments.
Yes, the GROUP_CONCAT() function is what you want.
SELECT ?name ?website ?abstract (GROUP_CONCAT(?genre,',') AS ?genres) ?image
WHERE{
<http://dbpedia.org/resource/Attack_Attack!> a dbo:Band ;
foaf:name ?name;
dbo:abstract ?abstract .
OPTIONAL{ <http://dbpedia.org/resource/Attack_Attack!> dbo:genre ?genre } .
OPTIONAL{ <http://dbpedia.org/resource/Attack_Attack!> dbp:website ?website} .
OPTIONAL{ <http://dbpedia.org/resource/Attack_Attack!> dbo:image ?image} .
FILTER LANGMATCHES(LANG(?abstract ), "en")
}

SPARQL Query to get Movie detail

To get movie detail from linkedmdb, I used sparql query :
PREFIX mdb: <http://data.linkedmdb.org/resource/movie/film>
SELECT DISTINCT ?Title ?Genre ?Actor ?Country ?Director ?Year WHERE {
?film mdb:id ?uri .
?film dc:title ?Title .
?film movie:genre ?filmgenre.
?filmgenre movie:film_genre_name ?Genre .
?film movie:actor ?cast .
?cast movie:actor_name ?Actor .
?film movie:country ?Ctr .
?Ctr movie:country_name ?Country .
?film dc:date ?Year .
?film movie:director ?Drc .
?Drc movie:director_name ?Director
FILTER regex(?Title, "Kingdom of Heaven")
}
But SPARQL results shown Title same as counted Actor . How to combine the query so that Title is not repeated?
I've try using GROUP_CONCAT but not working in LinkedMDB Endpoint?
Could someone guide me?

SPARQL in Protege 4.3

I need to return individuals for my query:
SELECT ?subject ?class
WHERE { ?subject rdfs:subClassOf ?class.
?class rdfs:comment "linear"#en}
But it works only with subclasses. Should I replace rdfs:subClassOf on different operator?
Your query specifically asks for ?subjects that are subclasses of ?class (where ?class has the rdfs:comment "linear"#en). To retrieve instances of type ?class, you'd use
?subject rdf:type ?class
or, since SPARQL allows abbreviating rdf:type by a,
?subject a ?class
If you can't share details about the body of data, you are querying, you might want to get an idea yourself by checking
SELECT ?s ?p ?subject ?class
WHERE
{ ?s ?p ?class .
?subject rdfs:subClassOf ?class .
?class rdfs:comment "linear"#en .
} ORDER BY ?s ?p ?subject ?class
and/or
SELECT ?subject ?class ?p ?o
WHERE
{ ?subject ?p ?o .
?subject rdfs:subClassOf ?class .
?class rdfs:comment "linear"#en .
} ORDER BY ?subject ?class ?p ?o
from where you can expand in the same manner until you get a handle.