i am new to wikidata and i have tried to query query the start/ end dates of the commander of the kz dachau using sparql. I have following code but i don't get any data.
SELECT ?KZ_Dachau ?start ?end ?name
WHERE
{?KZ_Dachau p:P1037 ?leiter.
?leiter ps:P1037 wd:Q151198;
pq:P580 ?start;
pq:P582 ?end.
?KZ_Dachau wdt:P1559 ?name. }
a similar query, on which my query based, works fine:
SELECT ?papst ?start ?end ?name ?pic
WHERE
{?papst p:P39 ?position.
?position ps:P39 wd:Q19546;
pq:P580 ?start;
pq:P582 ?end.
?papst wdt:P1559 ?name.}
what i doing wrong?
I think my approach is wrong, but i don't know how to resolve it :/ And i dont understand, why i can't select any properties of the entity kz dachau (Q151198).
The issue is that you got the order wrong, i.e. in WikiData, the property director/manager has a person as object, not subject as in your query.
This query will work:
SELECT ?KZ_Dachau ?start ?end ?name
WHERE
{wd:Q151198 p:P1037 ?leiter. #Notice the change in order
?leiter ps:P1037 ?KZ_Dachau;
pq:P580 ?start;
pq:P582 ?end.
?KZ_Dachau wdt:P1559 ?name. }
Also, you may use property paths, in this case ^ inverts the property, so that ?a :hasChild ?b will be exactly the same as ?b ^:hasChild ?a:
SELECT ?KZ_Dachau ?start ?end ?name
WHERE
{?KZ_Dachau ^ps:P1037 ?leiter.
?leiter ^p:P1037 wd:Q151198;
pq:P580 ?start;
pq:P582 ?end.
?KZ_Dachau wdt:P1559 ?name. }
P39 in WikiData on the other hand has a person as a subject, hence why that query works. However, if you look at Eicke, WikiData just says that he held the position of member of the Reichstag, and says nothing about him being manager/director at Dachau.
Related
Why can get results with this query:
SELECT *
WHERE {
?person rdfs:label "Kirk Douglas"#en;
dbo:birthPlace ?place. # With dbp: too
}
but not with another one:
SELECT *
WHERE {
?person rdfs:label "Kirk Douglas"#en;
dbo:starring ?film.
}
I'm following tags in https://dbpedia.org/page/Kirk_Douglas
Some tip to understand it.
Thx!
In dbr:Kirk_Douglas you can read:
dbo:birthPlace dbr:Amsterdam_(city),_New_York
...
is dbo:starring of dbr:The_Light_at_the_Edge_of_the_World
dbr:Cast_a_Giant_Shadow
dbr:Two-Fisted_Tales_(film)
...
where is dbo:starring of is a way of simulating an inverse property for dbo:starring.
Indeed, in dbo:starring you can read:
rdfs:domain dbo:Work
...
rdfs:range dbo:Actor
This means that you shouldn't build triples like ?actor dbo:starring ?work, while ?work dbo:starring ?actor is a valid triple.
So your query should be something like:
SELECT *
WHERE {
?person rdfs:label "Kirk Douglas"#en .
?film dbo:starring ?person .
}
I need a sparql query that given a free text (user input),
it finds me from dbpedia all the classes related to it.
How do it?
Also asked here. Accepted answer said --
When you say classes, are you mean about types? If yes, try something like
SELECT ?uri ?label ?type
WHERE {
?uri rdfs:label ?label .
?uri <http://dbpedia.org/ontology/type> ?type .
FILTER regex(str(?label), "Leipzig") .
}
limit 10
I couldn't let this go...
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX virtdrf: <http://www.openlinksw.com/schemas/virtrdf#>
SELECT ?s1c AS ?c1
COUNT (*) AS ?c2
?c3
WHERE
{
QUAD MAP virtrdf:DefaultQuadMap
{
GRAPH ?g
{
?s1 ?s1textp ?o1 .
?o1 bif:contains '"dbpedia"' .
}
}
?s1 a ?s1c .
OPTIONAL { ?s1c rdfs:label ?c3
FILTER(langMatches(LANG(?c3),"EN"))}
}
GROUP BY ?s1c ?c3
ORDER BY DESC (2) ASC (3)
The earlier answer gets you partial results.
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}
}
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")
}
I am trying to get the hierarchy of super and subclass of dbpedia ontolgy.
Sparql query:
SELECT DISTINCT ?superclass ?subclass
WHERE
{
?subclass a owl:Class .
?subclass rdfs:subClassOf ?superclass
}
ORDER BY ?superclass ?subclass
It gives me all classes. But when I am trying to get the counts of entity inside classes. Some classes have entity while some don't have.
Sparql query to get the count of entity inside classes.
Getting Entities:
SELECT DISTINCT ?label AS ?label
?name AS ?name
?link AS ?link
WHERE
{
?link rdf:type <http://www.wikidata.org/entity/Q12136> .
OPTIONAL { ?link foaf:name ?name }
OPTIONAL { ?link rdfs:label ?label }
FILTER( lang(?label) = "en" )
}
Not getting Entities:
SELECT DISTINCT ?label AS ?label
?name AS ?name
?link AS ?link
WHERE
{
?link rdf:type <http://www.wikidata.org/entity/Q18553493> .
OPTIONAL { ?link foaf:name ?name }
OPTIONAL { ?link rdfs:label ?label }
FILTER(lang(?label) = "en" )
}
Why some classes don't have entities? Or Am I doing something wrong? Any help please?
First of all, you are talking about classes and not ontologies. I don't know why you think that entities are instances of ontologies, especially when you're talking about individuals/instances/resources.
Second, why shouldn't there be classes that do not have instances yet?