How to catch correct resource among disambiguations / interrogate subresources in DBPedia using SPARQL? - sparql

I have the title of a Youtube music video and I need to gather additional information from DBPedia like album, artist, release date, etc. I'd also like to get the 'abstract' of all these entities from DBPedia. I already use Musicbrainz to differentiate between song and artist in the title and it works rather well, except a few cases.
However my main problem is: when I pass the song to ask DBPedia (using a query with resource/{song}), sometimes I get no answer because {song} causes disambiguation. Example: resource/It's_My_Life has 11 disambiguates, 6 of which are songs. I need the resource "It's_My_Life_(Bon_Jovi_song)". How can I tell DBPedia that I need a resource of 'MusicalWork' type of a certain artist?
I tried in many ways to do this with SPARQL, but I always get an empty result and I don't know what I'm doing wrong. So far I was able to only get the abstract of every disambiguation, but I cannot get a specific property (like abstract) of a subresource of a disambiguation.
SELECT ?x ?y WHERE {
<http://dbpedia.org/resource/It's_My_Life> dbo:wikiPageDisambiguates ?x .
?x dbo:abstract ?y .
}
I can't seem to go father than this. I tried with:
SELECT ?x ?y WHERE {
<http://dbpedia.org/resource/It's_My_Life> dbo:wikiPageDisambiguates ?x .
?x dbo:MusicalArtist ?y .
{ SELECT ?z WHERE {
?y dbo:abstract ?z}
}
}
and
SELECT ?x ?y WHERE {
<http://dbpedia.org/resource/It's_My_Life> dbo:wikiPageDisambiguates ?x
?x rdfs:type ?y .
}
But results are always empty. How am I supposed to interrogate a subresource of a resource? Can anyone help me?

Solution, pulled from comments by #AKSW --
SELECT ?x ?y
WHERE
{
<http://dbpedia.org/resource/It's_My_Life> dbo:wikiPageDisambiguates ?x .
?x rdf:type dbo:MusicalWork .
?x dbo:abstract ?y .
FILTER ( LANGMATCHES ( LANG (?y), 'en' ) )
}

Related

SPARQL: Dividing a BGP into multiple Groups

In a previous question, a comment suggests that
select ?x ?y where {
{?x rdf:type ex:someType}
{?x ex:someProperty ?y}
}
is like (not identical) to:
select ?x ?y where {
?x rdf:type ex:someType.
?x ex:someProperty ?y.
}
Same triple patterns are used. However, the first query contains two BGPs (each one in a group pattern), while the second contains one BGP (no group patterns).
The algebra for the first query is a JOIN between two BGPs while the algebra of the second is only a BGP.
First query algebra (Apache Jena)
(project (?x ?y)
(join
(bgp (triple ?x <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.example.com/someType>))
(bgp (triple ?x <http://www.example.com/someProperty> ?y))))
Second query algebra (Apache Jena):
(project (?x ?y)
(bgp
(triple ?x <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.example.com/someType>)
(triple ?x <http://www.example.com/someProperty> ?y)
))
In the original question, the answer suggest that they are not identical and argues
If the SPARQL entailment is supported, then the separate {} are evaluated for entailment separately.
if you use labels bnodes in queries there restrictions cross {}
if you add FILTERS, then they do not apply outside the {} they are written in.
its a different abstract syntax tree. All minor points but which may come into play later.
Now let's put the blank nodes (2) and the different syntax trees aside (4), and ask the following: Would the two queries, in any case, yield different results because of filter (3) or entailment(1)? I do not see any possibility for that. Well, those who have a different opinion, may you, please show with some example?
Scope of FILTER is affected.
In:
select ?x ?y where {
{?x rdf:type ex:someType FILTER (?y > 0 ) }
{?x ex:someProperty ?y}
}
The FILTER is false always because ?y is unbound so the expression is error and the FILTER is false regardless of the ?x ex:someProperty ?y.
(3) and (4) are related.

DBpedia Sparql by page template

I am trying to run a query on dbpedia using SPARQL syntax, to look for all pages of a certain template. Doesn't seem to be work, I am looking for all pages with dbpprop:wikiPageUsesTemplate. Does anyone know how to correct this to properly look for templates?
SELECT ?name ?member_Of ?country ?lat ?lng ?link
WHERE {
?x dbpprop:wikiPageUsesTemplate "dbpedia:Template:Infobox_settlement" .
?x a <http://dbpedia.org/ontology/Settlement> .
?x foaf:name ?name .
?x dbpedia-owl:isPartOf ?member_Of.
?x dbpedia-owl:country ?country.
?x geo:lat ?lat .
?x geo:long ?lng .
?x foaf:isPrimaryTopicOf ?link .
}
LIMIT 2500 OFFSET 0
I've also attempted to run it just by the dbprop to no avail.
SELECT * WHERE { ?page dbpprop:wikiPageUsesTemplate <http://dbpedia.org/resource/Template:Infobox_settlement> . ?page dbpedia:name ?name .}
If anyone is trying to do a similar thing, it is also possible via the wiki api, where you can pagananate over all results. http://en.wikipedia.org/w/api.php?action=query&list=embeddedin&eititle=Template:Infobox_settlement
There are at least two problems: (i) you need to use IRIs in places, and not strings; and (ii) you need to use properties that DBpedia uses.
Use IRIs
In
?x a <http://dbpedia.org/ontology/Settlement> .
and
?x foaf:isPrimaryTopicOf ?link .
you've demonstrated that you know that URIs need to be written in full with < and >, or abbreviated with a prefix. However,
?x dbpprop:wikiPageUsesTemplate "dbpedia:Template:Infobox_settlement" .
certainly isn't going to work. It's legal SPARQL, because a string can be the object of a triple, but you almost certainly want an IRI.
Use DBpedia's vocabulary
A query with dbpprop:wikiPageUsesTemplate like this returns no results:
select distinct ?template where {
[] dbpprop:wikiPageUsesTemplate ?template
}
SPARQL results
That's easy enough to check, and quickly confirms that there's no data that can possibly match your query. Where did you find this property? Have you seen it used somewhere? I'm not confident that you can query DBpedia based on infobox templates. DBpedia is not the same as Wikipedia, and even if the Wikipedia API supports it, it doesn't mean that DBpedia has a counterpart. There is a note on DBpedia Data Set Properties that says:
http://xx.dbpedia.org/property/wikiPageUsesTemplate (will be changed to http://dbpedia.org/ontology/wikiPageUsesTemplate)
but that latter property doesn't seem to be in use on the endpoints either. See my answer to Syntax for Sparql query for pages with specific infobox for more details.

Extract Chemical Data from DBpedia via SPARQL

I'd like to know how to submit a SPARQL query to DDBpedia and be given back a table that includes the information found in the Wikipedia "chembox" info box template, such as molecular weight or formula.
So, the first step was just to make a query whose results should be a list of chemical substances that had the formula and molecularWeight properties included. But the following returns no results:
SELECT * WHERE {
?y rdf:type dbpedia-owl:ChemicalSubstance.
?y rdfs:label ?Name .
?y dbpedia:molecularWeight ?molecularWeight .
?y dbpedia:formula ?formula .
OPTIONAL {?y dbpedia-owl:iupacName ?iupacname} .
FILTER (langMatches(lang(?Name),"en"))
}
LIMIT 50
SPARQL Explorer at dbpedia.org
And so I'm stuck. Is something wrong with this query or does DBPedia really not collect that information from the Wikipedia chemboxes?
You caught the wrong namespace for both dbpedia:molecularWeight and dbpedia:formula. The correct namespace here would be dbpedia2.
Furthermore, there seem rarely any entries having a dbpedia-owl:iupacName, dbpedia2:molecularWeight and dbpedia2:formula.
SELECT * WHERE {
?y rdf:type dbpedia-owl:ChemicalSubstance.
?y rdfs:label ?Name .
OPTIONAL {?y dbpedia2:formula ?formula }.
OPTIONAL {?y dbpedia2:molecularWeight ?molecularWeight}.
OPTIONAL {?y dbpedia-owl:iupacName ?iupacname} .
FILTER (langMatches(lang(?Name),"en"))
}
LIMIT 50
SPARQL Explorer #dbpedia.org
To get the correct namespaces, you could either look at one example like this or get a list of all used properties for type dbpedia-owl:ChemicalSubstance using
SELECT DISTINCT ?rel WHERE {
?y rdf:type dbpedia-owl:ChemicalSubstance.
?y ?rel ?x
}
SPARQL Explorer #dbpedia.org

sparql/snorql example, first step

I am struggling a bit to understand how SPARQL works. Can someone please tell me how I for instance find name and place of all persons who have last name Churchill on
http://dbpedia.org/snorql/
This gets the full names:
SELECT ?x ?name WHERE {
?x foaf:surname "Churchill"#en.
?x foaf:name ?name
}
People don't have a “place” as such. What would that be anyway? They may have birth and death places and the like.

How to query an RDF individual for its data properties?

I have an ontology where arc_cfp is an individual of class Arc. I would like to know how could I get all the data properties of the individual, given that I have the individual's URI?
Basically, I am doing this:
SELECT ?idRef ?name ?src ?dst ?perf
WHERE
{
?x rdf:type http://www.semanticweb.org/ontologies/2012/1/graph.owl#arc_cfp .
?x graph:idRef_arc ?idRef .
?x graph:name_arc ?name .
?x graph:hasSource ?src .
?x graph:hasDestination ?dst .
?x graph:hasPerformatif ?perf .
}
I am pretty sure, using rdf:type is the problem. But, I have no idea what I need to use.
Thanks.
~Codera
Assuming you want a purely exploratory query of the form "give me all the triples about a subject" it should look the following:
SELECT *
WHERE
{
<http://example.org/SomeThing> ?p ?o
}
This will give you all predicate object pairs associated with the constant URI you pass in. If you are interesting in incoming as well as outgoing properties you could do the following instead:
SELECT *
WHERE
{
{ <http://example.org/SomeThing> ?p ?o }
UNION
{ ?s ?p <http://example.org/SomeThing> }
}
You can also use a DESCRIBE query to grab all the RDF data about a Resource.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
DESCRIBE ?x
WHERE
{
?x rdf:type http://www.semanticweb.org/ontologies/2012/1/graph.owl#arc_cfp .
}
P.S. Don't forget to put prefixes in your queries.