SPARQL query failing to match literal on Pubchem RDF data - sparql

I have loaded part of the PubChem RDF data in Virtuoso and am trying to use SPARQL to query it, through iSQL.
While the following query works:
SELECT ?syno ?type ?value
WHERE {
?syno sio:is-attribute-of <http://rdf.ncbi.nlm.nih.gov/pubchem/compound/CID1829049> .
?syno rdf:type ?type .
?syno sio:has-value ?value .
} LIMIT 10;
I am not able to get any results for a query like (the value being taken from one of the above results):
SELECT ?syno
WHERE {?syno sio:has-value "AC1LXI26"};
In the previous case, I am simply trying to match a litteral.
Do I need to build an extra index? Is exact text match not supported in Virtuoso?

I solved my problem by simply adding #en at the end of the query string!
SELECT ?syno
WHERE {?syno sio:has-value "AC1LXI26"#en};

Related

Sparql filter on prefix does not work on dbpedia

I'm new to SPARQL hope someone could help me.
The problem is that if I run the following query on dbpedia sparql:
SELECT DISTINCT ?class WHERE {
?s a ?class.
}
it returns:
result query
I would like to remove the results that has this two prefix: "http://www.w3.org/2002/07/owl" and "http://www.w3.org/2000/01/rdf-schema", now the query is:
SELECT DISTINCT ?class WHERE {
?s a ?class.
FILTER ( !strstarts(str(?class), "http://www.w3.org/2002/07/owl") ).
FILTER ( !strstarts(str(?class), "http://www.w3.org/2000/01/rdf-schema") ).}
but it returns only one result:
http://www.w3.org/1999/02/22-rdf-syntax-ns#Property
If I execute the same query on istat sparql these queries work fine.
So the question is, why on dbpedia my queries does not work as expected?
Thanks

How to filter the simple Subject in a SPARQL Query

I guess I am stuck at the basics with SPARQL. Can someone help ?
I simply wnat to filter all subjects containing "Mountain" of an RDS database.
Prefix lgdr:<http://linkedgeodata.org/triplify/> Prefix lgdo:<http://linkedgeodata.org/ontology/>
Select * where {
?s ?p ?o .
filter (contains(?s, "Mountain"))
} Limit 1000
The query leads to an error:
Virtuoso 22023 Error SL001: The SPARQL 1.1 function CONTAINS() needs a string value as first argument
You can get it to "work" using:
Prefix lgdr:<http://linkedgeodata.org/triplify/> Prefix lgdo:<http://linkedgeodata.org/ontology/>
Select * where {
?s ?p ?o .
filter (contains(str(?s), "Mountain"))
} Limit 1000
Note the additional str in the query.
However, that results in
Virtuoso S1T00 Error SR171: Transaction timed out
and I am not sure how to deal with that.
But in principle in works: When you use
Limit 1
you get
s p o
http://linkedgeodata.org/ontology/MountainRescue http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://www.w3.org/2002/07/owl#Class

Getting a list of available hierarchies from statistics.gov.scot

I'm interested in obtaining a list of available distinct hierarchies from statistics.gov.scot. The best-fit hierarchies, which I would like to list, are as follow:
http://statistics.gov.scot/def/hierarchy/best-fit#community-health-partnership
http://statistics.gov.scot/def/hierarchy/best-fit#council-area
http://statistics.gov.scot/def/hierarchy/best-fit#country
As available through API section of this sample geography.
Desired results
I would like for the desired results to return:
community-health-partnership
council-area
country
How can I construct query that would actually produce that, I can get a list of available all geographies via:
PREFIX sdmx: <http://purl.org/linked-data/sdmx/2009/dimension#>
SELECT DISTINCT ?framework
WHERE {
?a sdmx:refArea ?framework .
} LIMIT 10
I was trying something on the lines:
PREFIX fits: <http://statistics.gov.scot/def/hierarchy/best-fit#>
SELECT DISTINCT ?framework
WHERE {
?a fits ?framework .
} LIMIT 10
but naturally this syntax is not correct.
Starting on their SPARQL endpoint, you could do something like this --
DESCRIBE <http://statistics.gov.scot/def/hierarchy/best-fit#country>
Then, based on those results, you might try something like this, which results aren't exactly what you say you want, but might be better --
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?hierarchy
?label
WHERE
{ ?hierarchy rdfs:subPropertyOf <http://statistics.gov.scot/def/hierarchy/best-fit>
; rdfs:label ?label
}

SPARQL How to get the type of an individual

I made this ontology:
SensorOntology:MedicalCabinet-01 rdf:type owl:NamedIndividual ,
SensorOntology:MedicalCabinetSensor ;
SensorOntology:hasId "57"^^xsd:int ;
SensorOntology:hasValue "0"^^xsd:int .
I am trying to write a query to get the type of MedicalCabinet-01 which is MedicalCabinetSensor by given id number. However, I am printing owl:NamedIndividual and SensorOntology:MedicalCabinetSensor. Is it anyway I print just SensorOntology:MedicalCabinetSensor. This is my query:
SELECT DISTINCT ?sensor ?sensorclass
WHERE {?sensor :hasId "100"^^xsd:int.
?sensor rdf:type ?sensorclass}
There are multiple ways to ignore results, so it's not clear which one you want to use - especially since some are quite obvious. Here are two options:
As you tagged it with Jena, use Java and ignore resources whose URI matches owl:NamedIndividual.
Use a FILTER in SPARQL, i.e. add FILTER(?sensorclass != owl:NamedIndividual) to the graph pattern of the SPARQL query.
Indeed, there are multiple ways. Here's another:
SELECT DISTINCT ?sensor ?sensorclass
WHERE {?sensor :hasId "100"^^xsd:int.
?sensor rdf:type ?sensorclass
FILTER ( strstarts(str(?sensorclass), "[sensor ontology URI]") )
}

SPARQL queries for Pizza ontology

i have to use ROWLKit
http://www.dis.uniroma1.it/quonto/?q=node/30
(1) can anybody suggest two sparql queries for the Pizza.owl ?
(2) is this query valid ?
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX pizza: <http://www.co-ode.org/ontologies/pizza/pizza.owl#>
SELECT *
WHERE { ?p rdf:type pizza:Pizza;
pizza:hasTopping ?t.
?t rdf:type pizza:TomatoTopping }
(3) if it is a valid query then: is the response an empty result?
SELECT DISTINCT *
WHERE {
?NombrePizza ?Relacion pizza:MushroomTopping .
?Relacion owl:inverseOf pizza:isToppingOf .
OPTIONAL {
?NombrePizza2 ?Relacion2 pizza:HamTopping .
?Relacion2 owl:inverseOf pizza:isToppingOf .
}
FILTER(?NombrePizza2 = ?NombrePizza)
}
(1) can anybody suggest two sparql queries for the Pizza.owl ?
Here are two examples:
SELECT * WHERE { ?s ?p ?o }
and:
SELECT ?class WHERE { ?class a owl:Class }
(2) is this query valid ?
Yes.
(3) if it is a valid query then: is the response an empty result?
I assume that you mean "if I query the RDF document that serialises the pizza ontology, is the response an empty result?". The answer is yes.
(2) appears to be a valid query
I don't understand part (3) of your question. (2) cannot be compared to a boolean since it returns a Result Set, if you want a boolean result then you need to use an ASK query. If an ASK query returns true then it means that there are solutions to the query in the data you are querying so it would not be an empty result.