How to resolve disambiguation in Yago/DBpedia? - sparql

Assuming I am searching for an entity such as "Wizard of Oz" and know I am specifically interested in the book rather then movie or musical.
Which query/method will return correct results on most cases?

You can do that with a query like:
SELECT * WHERE {
?s <http://dbpedia.org/property/name> ?name .
?s a <http://dbpedia.org/ontology/Book> .
FILTER(regex(STR(?name), "wizard of oz", "i"))
}

You can also do that with DBpedia Lookup:
http://lookup.dbpedia.org/api/search.asmx/KeywordSearch?QueryClass=book&QueryString=wizard+of+oz
Or with DBpedia Spotlight:
http://spotlight.dbpedia.org/rest/candidates?text=wizard+of+oz+book

As every book, and only books, have an ISBN, I guess you can take Steve Harris' query and, instead of asking if it is a book, you can ask if it has an ISBN.
SELECT * WHERE {
?s <http://dbpedia.org/property/name> ?name .
?s <http://dbpedia.org/ontology/isbn> ?isbn .
FILTER(regex(STR(?name), "wizard of oz", "i"))
}

Related

How to get all property from an item based on its Q number?

I want to gather all properties of a item from wikidata.
All queries I see so far assume you know properties you are looking for, but in my case, I'm not.
For example, when querying for Q1798740, I would like a returned value that looks like
[{"item": "Q1798740",
"P31": ["Q1146"],
"P17": ["Q70972"],
...
"P2043":"70 metres"}
]
and that contains all statements from the wikidata page
What query should I perform?
You need only to ask for {wd:Q1798740 ?p ?value} but it would be useful also to get the labels of the properties, which is a bit trickier:
SELECT DISTINCT ?p ?property_label ?value
WHERE
{
wd:Q1798740 ?p ?value .
?property wikibase:directClaim ?p ;
rdfs:label ?property_label .
FILTER(LANG(?property_label)="en")
}

SPARQL: How to retrieve all dog breeds and all their infobox data from dbpedia?

I would like to know how is the best sparql way to retrieve all dog breeds and all their infobox data from dbpedia.
I've tried this:
SELECT * WHERE {
{
<http://dbpedia.org/resource/Dog_type> ?p ?o
}
UNION
{
?s ?p <http://dbpedia.org/resource/Dog_type> .
?s ?p ?o .
?p ?p2 ?o2
}
}
But the result is far away from I expect like:
http://dbpedia.org/resource/Basque_Shepherd_Dog dbpedia2:coat "moderately long"^^rdf:langString
First, note that <http://dbpedia.org/resource/Dog_type> is not the class of dog breeds.
For several reasons, I suggest you do this work on DBpedia Live, rather than DBpedia [Snapshot].
Start there with a look at the description of your example breed, http://dbpedia.org/resource/Basque_Shepherd_Dog.
Then consider whether a query like the following will get you what you want --
SELECT DISTINCT *
WHERE
{
?breed a <http://dbpedia.org/class/yago/DogBreeds> ;
?p ?o
}
ORDER BY ?breed ?p ?o
LIMIT 1000

SPARQL - select from skos:category - Virtuoso 37000

I have problem with SPARQL. I want to select something from category. For example subjects. I make query like this in http://dbpedia.org/snorql.
SELECT ?category ?subject WHERE
{
?category a skos:Concept .
?category skos:Concept: American_punk_rock_guitarists.
?category dct:subject ?subject .
} LIMIT 1000
I have error Virtuoso 37000. I don't understand why.
P.S. Is it good book for beginnier in SPARQL - Learning SPARQL, 2nd Edition
Querying and Updating with SPARQL 1.1 ?
You have at least one syntax error: the second colon (:) in the second triple.
Semantically... I don't really know the classes or predicates in dbpedia... but can skos:Concept be both a type and a predicate?
I wrote you a valid query that returns 10 members of the category "American_punk_rock_guitarists"
I put this together by going to dbpedia's faceted free text search and familiarizing myself with the concept of American punk rock guitarists, specifically Joey Ramone
prefix dbpcat: <http://dbpedia.org/resource/Category:>
SELECT ?subject ?category
WHERE
{ values ?category { dbpcat:American_punk_rock_guitarists } .
?subject dct:subject ?category }
LIMIT 10

SPARQL Query final label [duplicate]

This question already has an answer here:
Why does my SPARQL query return the URI of a resource instead of its name?
(1 answer)
Closed 6 years ago.
I have a SPARQL Query that returns the Europe capitals and their population. The query looks like this:
select ?s ?pop
where {
?s <http://dbpedia.org/ontology/populationTotal> ?pop .
?s a <http://dbpedia.org/ontology/place>
}
In this state, it returns the names of the cities in the following form: e.g. "<http://dbpedia.org/resource/London>" and what I want is to display only London in this case. So, is there a way I can tell SPARQL that I want only the final label?
I am querying against this endpoint: https://rdf.s4.ontotext.com/4730361296/demo01/repositories/test01
The advice here is similar to other questions - use SPARQL to inspect the data. So first try this query to see if there are any label properties defined:
select *
where {
?s <http://dbpedia.org/ontology/populationTotal> ?pop .
?s a <http://dbpedia.org/ontology/place> .
?s ?p ?o .
}
In this case you'll find that no label properties have been defined for place class definitions. If desired you can take the local name - the text after the last slash (or hash) as the name. Try this query:
select *
where {
?s <http://dbpedia.org/ontology/populationTotal> ?pop .
?s a <http://dbpedia.org/ontology/place> .
BIND(REPLACE(xsd:string(?s), ".*[/#]", "") AS ?label)
}

How do I restrict my search in dbpedia using SPARQL to "Persons" only

I am using a query to output the influences of all people listed in wikipedia (where possible). I am using http://dbpedia.org/snorql/. My code so far is:
SELECT *
WHERE {
?p a
<http://dbpedia.org/ontology/Person> .
?p <http://dbpedia.org/ontology/influenced> ?influenced.
}
The problem is that the influenced output includes things like genres and political ideologies. I want to restrict it to only output "people" and "people who were influenced by those people". Thanks in advanced.
Try:
SELECT *
WHERE {
?p a
<http://dbpedia.org/ontology/Person> .
?p <dbpedia-owl:birthYear> ?birthYear.
?p <http://dbpedia.org/ontology/influenced> ?influenced.
?influenced a <http://dbpedia.org/ontology/Person>.
}
EDITED TO ADD BIRTH YEAR