A problem with querying a graph with SPARQL on Bioportal - sparql

I am querying an ontology on the Bioportal endpoint. The ontology (NIF) is stored as a graph, so I put it in the FROM clause as the endpoint instructed.
SELECT DISTINCT ?p
FROM <http://bioportal.bioontology.org/ontologies/NIF>
WHERE{
?p a rdf:Property
}
limit 100
However, as can be seen below, the results came back showing few properties related to NIF and others to a different ontology called SKOS (Simple Knowledge Organization System).
In the Bioportal documentation it is said it maps some properties to SKOS properties, so I thought maybe the results are fine.
However, I had to test if I am querying the correct graph. So I used the below code to count the number of nodes since I know the NIF has around 3.6 million triples!
SELECT (count (*) as ?nodes)
FROM <http://bioportal.bioontology.org/ontologies/NIF>
WHERE{
?s ?p ?o
}
This resulted in 7984 nodes with and without the FROM clause! So I guessed I should be using the "count" incorrectly!
So I wonder how I should make sure that I am just querying the NIF ontology. Also, how to count its nodes?
Thanks :)

Try using SERVICE keyword.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT (count (*) as ?nodes)
WHERE
{
SERVICE <http://bioportal.bioontology.org/ontologies/NIF>
{
?s ?p ?o
}
}
If this fails, possibly the service you are connecting is not correct or up.
Try below example which connects to DBpedia:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT (count (*) as ?nodes)
WHERE
{
SERVICE <http://DBpedia.org/sparql>
{
?s ?p ?o
}
}
By the way I can;t access URL http://bioportal.bioontology.org/ontologies/NIF. Seems to be unavailable or down.

Related

SPARQL Query returns empty result set

I am querying marine data via SPARQL. I developed a SPARQL console with CodeMirror, RDFLib and SPARQLWrapper in order to display a number of predefined queries and results in my website. In the console, the query:
prefix geo: <https://www.w3.org/2003/01/geo/wgs84_pos#>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix ssn: <http://www.w3.org/ns/ssn/>
prefix xml: <http://www.w3.org/XML/1998/namespace>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix argo: <http://www.argodatamgt.org/argo-ontology#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix sosa: <http://www.w3.org/ns/sosa/>
prefix nerc: <http://vocab.nerc.ac.uk/collection/>
prefix dct: <http://purl.org/dc/terms/>
prefix prov: <https://www.w3.org/TR/prov-o/>
# stations/date of each cycle
SELECT distinct ?wmo ?lat ?lon ?date where{
?float argo:cycle ?cycle;
argo:wmoCode ?wmo.
?cycle geo:latitude ?lat;
geo:longitude ?lon;
argo:startDate ?date.
}
returns nothing. I cross-checked it by using https://www.orpha.net/sparql , a query editor, and the result was the same - empty result set.
However, when I try the exact same query in the research infrastructure's SPARQL Endpoint https://www.ifremer.fr/co/argo-linked-data/html/Argo-HTML-SPARQL/ , it works flawlessly.
I have tried very generic queries like:
SELECT DISTINCT * WHERE {
?s ?p ?o
}
LIMIT 10
or
select distinct ?p ?label
where {
?s ?p ?o .
OPTIONAL { ?p rdfs:label ?label }
}
and they return non-empty results both in my console and in the generic SPARQL editor I mentioned before.
Performing a CURL request, modifying the template query by the first mentioned "stations/date of each cycle" one I am able to get the data:
curl -X POST "https://sparql.ifremer.fr/argo/query" --data-urlencode "query=select ?s ?o ?p where{?s ?o ?p.} limit 10"
This makes me think that an outdated Virtuoso server on their side might be the culprit, however, I am very new in SPARQL and Semantics to tell and I would appreciate any clue.
As OP said in comment --
I found the culprit and it was an error from my side. I am using SPARQLWrapper and somewhere in my code I had a fixed SPARQL endpoint from another research infrastructure, I totally missed that.

SPARQL Federated Query Not Returning All Solutions

This is an evolution of this question.
Basically I am having trouble getting all the solutions to a SPARQL query from a remote endpoint. I have read through section 2.4 here because it seems to describe a situation almost identical to mine.
The idea is that I want to filter my results from DBPedia based on information in my local RDF graph. The query is here:
PREFIX ns1:
<http://www.semanticweb.org/caeleanb/ontologies/twittermap#>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT *
WHERE {
?p ns1:displayName ?name .
SERVICE <http://dbpedia.org/sparql> {
?s rdfs:label ?name .
?s rdf:type foaf:Person .
}
}
And the only result I get is dbpedia:John_McCain (for ?s). I think this is because John McCain is the only match in the first 'x' results, but I can't figure out how to get the query to return all matches. For example, if I add a filter like:
SERVICE <http://dbpedia.org/sparql> {
?s rdfs:label ?name .
?s rdf:type foaf:Person .
FILTER(?name = "John McCain"#en || ?name = "Jamie Oliver"#en)
}
Then it correctly returns BOTH dbpedia:Jamie_Oliver and dbpedia:John_McCain. There are dozens of other matches like Jamie Oliver that do not come through unless I specifically add it to a Filter like this.
Can someone explain a way to extract the rest of the matches? Thanks.
It looks like the cause of this issue is that the SERVICE block is attempting to pull all foaf:Persons from DBPedia, and then filter them based on my local Stardog db. Since there is a 10,000 result limit when querying DBPedia, only matches which occur in that set of 10,000 arbitrary Persons will be found. To fix this, I wrote a script to put together a FILTER block containing every string name in my Stardog db and attached it to the SERVICE block to filter remotely and thereby avoid hitting the 10,000 result limit. It looks something like this:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX ns1: <http://www.semanticweb.org/caeleanb/ontologies/twittermap#>
CONSTRUCT{
?s rdf:type ns1:Person ;
ns1:Politician .
}
WHERE {
?s rdfs:label ?name .
?s rdf:type dbo:Politician .
FILTER(?name IN ("John McCain"#en, ...)
}

SPARQL query returns no data

Why does this SPARQL query return no data?
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
PREFIX dbpedia: <http://dbpedia.org/resource/>
SELECT *
WHERE {
<http://dbpedia.org/resource/Louis,_Prince_of_Condé_(1530–1569)> dbpedia-owl:abstract ?abstract
}
LIMIT 1
If you look at the DBpedia page, it shows the person has an abstract. Is it to do with the brackets in the URL? If so, how can I get round this?
This URI does not lead to the same result as the DBpedia page - for what ever reason. You can see this with
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
PREFIX dbpedia: <http://dbpedia.org/resource/>
SELECT *
WHERE {
<http://dbpedia.org/resource/Louis,_Prince_of_Condé_(1530–1569)> ?p ?o
}
LIMIT 100
But it has an owl:sameAs relation to
http://dbpedia.org/resource/Louis,_Prince_of_Cond%C3%A9_(1530%E2%80%931569)
That means if you use this URI in your query, it should work as expected. But you should indeed apply a FILTER on the language, e.g. 'en' for English abstracts.
As AKSW mentions, the resource actually doesn't have many properties, but is connected to the "canonical" version by an owl:sameAs link. You can keep using the IRI that you're using now, follow owl:sameAs in either direction to any of its equal resources (let's call them ?s), and then ask for the abstract of ?s. (And then it's not a bad idea to filter by language, if that's applicable.) You can do this with a query like this (note that the current DBpedia endpoint uses dbo:, now, not the older dbpedia-owl:):
select ?abstract where {
<http://dbpedia.org/resource/Louis,_Prince_of_Condé_(1530–1569)> (owl:sameAs|^owl:sameAs)* ?s .
?s dbo:abstract ?abstract .
filter langMatches(lang(?abstract),'en')
}
It does not have dbpedia-owl:abstract predicate. If you list its predicates you find the following properties:
http://www.w3.org/2002/07/owl#sameAs
http://xmlns.com/foaf/0.1/name
http://purl.org/dc/elements/1.1/description
http://dbpedia.org/ontology/alias
http://dbpedia.org/ontology/birthYear
http://dbpedia.org/ontology/deathYear
http://dbpedia.org/ontology/viafId
http://dbpedia.org/ontology/deathPlace
http://dbpedia.org/ontology/deathDate
http://dbpedia.org/ontology/birthPlace
http://dbpedia.org/ontology/birthDate

Obtain linked resources with SPARQL query on DBpedia

Hello everybody i'm using a SPARQL query to retrieve properties and values of a specified resource. For example if i ask for Barry White, i obtain: birth place, associatedBand, recordLabels and so on.
Instead for any instance such as "Hammerfall", i obtain only this results:
Query results
But i want properties and values as shown in this page: Correct results.
My query is:
PREFIX db: <http://dbpedia.org/resource/>
PREFIX prop: <http://dbpedia.org/property/>
PREFIX onto: <http://dbpedia.org/ontology/>
SELECT ?property ?value
WHERE { db:Hammerfall?property ?value }
Anyone can tell me how to access to the correct resource and obtain corrects properties and values in every case?
select ?p ?o { dbpedia:HammerFall ?p ?o }
SPARQL results
The particular prefix doesn't matter; I just used dbpedia: because it's predefined on the endpoint as http://dbpedia.org/resource/, just like your db:. The issue is that HammerFall has a majuscule F in the middle, but your query uses a miniscule f.
As an alternative, since the results for Hammerfall (with a miniscule f) do include
http://dbpedia.org/ontology/wikiPageRedirects http://dbpedia.org/resource/HammerFall
you could use a property path to follow any wikiPageRedirects paths:
select ?p ?v {
dbpedia:Hammerfall dbpedia-owl:wikiPageRedirects* ?hammerfall .
?hammerfall ?p ?v
}
SPARQL results
See Retrieving dbpedia-owl:type value of resource with dbpedia-owl:wikiPageRedirect value? for more about that approach.

Returning properties from dbpedia Virtuoso

When I look at the HTML page: http://dbpedia.org/page/Bill_Nye I can see a lot of properties that are not returned in the following simple query from the Virtuoso page (http://pt.dbpedia.org/sparql):
prefix foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?s ?p WHERE {
?e foaf:name "Bill Nye"#en .
?e ?s ?p.
}
No results return when I try to access one of the properties I can see on this page- say foaf:depiction:
prefix foaf: <http://xmlns.com/foaf/0.1/>
SELECT $depiction WHERE {
?s foaf:name "Bill Nye"#en.
?e foaf:depiction ?depiction
}
When I run them via the sparql endpoint at http://dbpedia.org/sparql, after encoding
SELECT ?s ?p WHERE { ?e foaf:name "Bill Nye"#en.?e ?s ?p. }
I get
http://dbpedia.org/sparql?query=SELECT%20%3Fs%20%3Fp%20WHERE%20%7B%20%3Fe%20foaf%3Aname%20%22Bill%20Nye%22#en.%3Fe%20%3Fs%20%3Fp.%20%7D&format=json
And a result of what looks like all the properties shown at http://dbpedia.org/page/Bill_Nye. I would love an explaniation of the difference, is it simply the Virtuoso interface or something more? I'm pretty fresh at this semantic web, so please be gentle.
Please note that you are sending the queries to two different Virtuoso installations:
pt.dbpedia.org/sparql : is the international chapter for Portuguese language (PT stands for DBpedia Portuguese)
dbpedia.org/sparql : is the main SPARQL endpoint for DBpedia, containing data from multiple languages, but in an English-centric way.
You will also have different experiences with es.dbpedia.org, it.dbpedia.org, el.dbpedia.org, etc.
I18n chapters do not load exactly the same data sets as the main DBpedia. Please see:
http://mappings.dbpedia.org/index.php/DBpedia_datasets
I believe the following query (ordered) will enable you to more easily identify the missing results --
prefix foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?s ?p ?o WHERE
{
?s foaf:name "Bill Nye"#en .
?s ?p ?o.
}
order by 2
here you can easily identify that all the missing results have predicates of the form -
is ********** of
Basically, these are just eye candy in the human viewable Html view - and represent additional relationships wherever the object of some other subject is http://dbpedia.org/resource/Bill_Nye
That is -
<something else> ?p <http://dbpedia.org/resource/Bill_Nye>