How to query dbpedia.org with sparql - sparql

I'm very new in OpenData and try to write a query in SPARQL.
My goal is to get data for following set of criteria:
- Category: Home_automation
- select all items from type "Thing"
- with at least one entry in "is Product of"
- that have a picture-url with a German description
I tried the following:
PREFIX cat: <http://dbpedia.org/resource/Category:>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT *
WHERE {
cat:Home_automation skos:broader ?x
}
But now I don't know how to add the other filters to the where clause.
I tried to user broader:... to get the items, but I think that was the wrong direction.
I tested the queries with: https://dbpedia.org/sparql
The result should be:
| (label) | (url)
|--------------------------|-----------------------------------
|"Kurzzeitwecker"#de | urls to the picture of the device
|"Staubsauger"#de | -||-
|"Waschmaschine"#de | -||-
|"Geschirrspülmaschine"#de | -||-
Does anyone have some tips please?
UPDATE: new query:
PREFIX cat: <http://dbpedia.org/resource/Category:>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?s ?label WHERE {
?s ?p cat:Home_automation .
?s rdf:type owl:Thing .
?s rdfs:label ?label
FILTER (LANG(?label)='de')
}
order by ?p

It is not clear what you want. You must first know what exact related information dbpedia contains and how they are structured.
However, you can try discovering what types of relationships cat:Home_automation is involved in, thus, you may know better what you want.
I suggest starting by generic queries, to specify how cat:Home_automation occurs in dbpedia, then, you might be able to go more specific, and pose further queries.
A query to list triples where cat:Home_automation is an subject:
PREFIX cat: <http://dbpedia.org/resource/Category:>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT ?p ?o WHERE {
cat:Home_automation ?p ?o
}
order by ?p
A query to list triples where cat:Home_automation is an object:
PREFIX cat: <http://dbpedia.org/resource/Category:>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT ?s ?p WHERE {
?s ?p cat:Home_automation
}
order by ?p
check the results, see what is interesting for you, and then continue with further queries.

Related

How to query specific entities from Wikidata by ID using a SPARQL query?

I need a SPARQL query returning a specific Wikidata ID or a list of IDs. In real life such query is useless but I need it for testing purposes.
The easiest variant I could come up with was:
SELECT DISTINCT ?s
WHERE
{
?s ?p ?o
FILTER (?s = wd:Q151345).
}
I have to use DISTINCT because ?s ?p ?o matches every triple within Q151345, if I omit it it output the item as many times as many property-value pairs it has.
Is there any easier way?
With the keyword VALUES, it's possible to use multiple instances.
PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
SELECT ?s
WHERE
{
VALUES ?s { wd:Q151345 wd:Q2996394 }
?s ?p ?o
}
LIMIT 10
Demo : http://linkedwiki.com/query/Query_multiple_instance_of_in_same_query
Doc: https://www.w3.org/TR/sparql11-query/#inline-data
#greatvovan You can try
PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
SELECT DISTINCT ?s WHERE {
SELECT ?s WHERE
{
VALUES ?s { wd:Q151345 wd:Q2996394 }
?s ?p ?o
}
}

How do get data from example owl data using sparql query

This is my example owl :
<rdf:type rdf:resource="http://www.w3.org/2000/10/swap/pim/contact#Person"/>
<foaf:age rdf:datatype="http://www.w3.org/2001/XMLSchema#string">10</foaf:age>
<foaf:birthday rdf:datatype="http://www.w3.org/2001/XMLSchema#string">10.10</foaf:birthday>
<foaf:firstName rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Liis</foaf:firstName>
</owl:NamedIndividual>
And because im rookie with sparql, i want to know how do make a query to get all instances with this rdf a
<rdf:type rdf:resource="http://www.w3.org/2000/10/swap/pim/contact#Person"/>
nd then get the data from it example like get age and the get age=10 or get name and name="someName"
<foaf:age rdf:datatype="http://www.w3.org/2001/XMLSchema#string">10</foaf:age> i mean get data from this row.
My answares to this question are:
This query help you to find all instances, s is the object name, p is the type how do accsess to this data and o is the value of the row.
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX resource: <http://purl.org/vocab/resourcelist/schema#>
select distinct ?s ?p ?o ?k where {
?s ?p ?o ;
a <http://www.w3.org/2000/10/swap/pim/contact#Person> .
?k foaf:age ?x .}
and the second part ?k foaf:age ?x . is how do accsess to instance data by the type name.
and the result is <http://example.register.nl/nationaalhandelsregister#person1>,10

SPARQL query to find "notable" people

I am using live Dbpedia (http://dbpedia-live.openlinksw.com/sparql/) to get basic details of notable people. My query is:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
SELECT DISTINCT ?x0 ?name ?dob WHERE {
?x0 rdf:type foaf:Person.
?x0 rdfs:label ?name.
?x0 dbpedia-owl:birthDate ?dob.
FILTER REGEX(?name,"^[A-Z]","i").
} LIMIT 200
This works and I use LIMIT 200 to limit the output to a small number of people. My problem is the 200 people are random, and I want some way of measuring 'notability' such that I return 200 notable people, rather than 200 random people. There are over 500,000 people in Dbpedia.
My question is, how can I measure 'notability' and limit the query to return notable people only? I realize there is no 'notability' property and it is very subjective. I am happy to use any indirect or approximate measure such as number of links or number of references. But I don't know how to do this.
Edit : As a result of the helpful comments I improved the query to include page ranks:
PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo:<http://dbpedia.org/ontology/>
PREFIX vrank:<http://purl.org/voc/vrank#>
SELECT DISTINCT ?s ?name2 ?dob ?v
FROM <http://dbpedia.org>
FROM <http://people.aifb.kit.edu/ath/#DBpedia_PageRank>
WHERE {
?s rdf:type foaf:Person.
?s rdfs:label ?name.
?s dbo:birthDate ?dob.
?s vrank:hasRank/vrank:rankValue ?v.
FILTER REGEX(?name,"^[A-Z].*").
BIND (str(?name) AS ?name2)
} ORDER BY DESC(?v) LIMIT 100
The problem now is there are lots of duplicates, even though I am using DISTINCT.

SPARQL - get list of places in one country

I'm new to SPARQL and would like some help in my learning.
I want to get latitude and longitude of several places (neighborhoods, cities, states, regions, rivers, monuments, ..) of my country: Brazil.
I tried:
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT *
WHERE {
?s a dbo:Place .
?s geo:lat ?lat .
?s geo:long ?long .
?s a ?type .
?s a ?city .
?s rdfs:label "Rio de Janeiro"#en.
}
limit 10
I don't want to restrict my query to just "cities". I want to search for places by various attributes: "city", "river", "village", "mountain", "monuments", "hill", "island", "valley", "point", "peak" ...
Furthermore, I am not restricting the country ...
Anybody can help me?
Your query looks like the one in Get Place categories from DBpedia using SPARQL.
As it stands, your query is not limited to cities - it is just limited to dbo:Places that have the English name (label) "Rio de Janeiro". ?city is a variable; its name doesn't do anything special.
If you want any place, just remove the above mentioned triple patterns.
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT *
WHERE {
?s a dbo:Place .
?s geo:lat ?lat .
?s geo:long ?long .
?s a ?type .
}
limit 10
This gets you 10 places with latitude and longitude and another class. You could browse DBpedia to see what kinds of places there are, decide whether you need dbo:Location_(feature) too and try subclasses of Place, Location too (as per DBpedia, getting the direct or indirect types of Place). To filter for country, you could add to your query
?s dbo:country <http://dbpedia.org/resource/Brazil> .
But not every place will have an explicit link to the country like this. You'll have to see what properties can help out with linking a place to its country.

Getting a list of American physicists from DBpedia using SPARQL

I want to query the American Physicsts and get the list of physicists. How can I do this?
The SPARQL you need would look like this ....
PREFIX category: <http://dbpedia.org/resource/Category:>
PREFIX dcterms: <http://purl.org/dc/terms/>
SELECT *
WHERE {
?s dcterms:subject category:American_physicists .
}
see results here
If you want the list with some extra predicates you need to join more triple patterns using the variable ?s. For instance, to retrieve the birthdate for each physicist ...
PREFIX category: <http://dbpedia.org/resource/Category:>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX dbpedia: <http://dbpedia.org/ontology/>
SELECT *
WHERE {
?s dcterms:subject category:American_physicists .
?s dbpedia:birthDate ?bithdate .
}
results here