I am a biology trying to understand the meaning of a triple from this SPARQL query. If "a" is a triple, what are the resources for subject, object and predicate in this sample query?
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX obo: <http://purl.obolibrary.org/obo/>
PREFIX sio: <http://semanticscience.org/resource/>
PREFIX efo: <http://www.ebi.ac.uk/efo/>
PREFIX atlas: <http://rdf.ebi.ac.uk/resource/atlas/>
PREFIX atlasterms: <http://rdf.ebi.ac.uk/terms/atlas/>
SELECT DISTINCT ?experiment ?description WHERE
{?experiment
a atlasterms:Experiment ;
dcterms:description ?description ;
atlasterms:hasAssay
[atlasterms:hasSample
[atlasterms:hasSampleCharacteristic
[ atlasterms:propertyType ?propertyType ;
atlasterms:propertyValue ?propertyValue]
]
]
filter regex (?description, "diabetes", "i")
}
I appreciate your help?
Thanks,
AD
?experiment
a atlasterms:Experiment ;
is the same as
?experiment a atlasterms:Experiment ;
is the same as
?experiment rdf:type atlasterms:Experiment ;
so the form in the query is just a whitespace rearrangement and using the built-in abbreviation "a" for property rdf:type.
See http://www.sparql.org/query-validator.html for an online formatter of SPARQL queries.
A simpler query is:
SELECT DISTINCT ?experiment ?description
WHERE
{ ?experiment rdf:type atlasterms:Experiment .
?experiment dcterms:description ?description
FILTER regex(?description, "diabetes", "i")
}
because
SELECT DISTINCT ?experiment ?description
means that the ?propertyType/?propertyValue part is not affecting the outcome.
Related
I'm trying to make a sparql query to: http://sparql.lynx-project.eu/
The graph: http://sparql.lynx-project.eu/graph/eurovoc
Which contains some entries with brackets in the prefLabel i.e. "sanction (EU)".
I'm trying to retrieve such exact match of such entries with:
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT ?c ?label
WHERE {
GRAPH <http://sparql.lynx-project.eu/graph/eurovoc> {
?c a skos:Concept .
?c ?p ?label.
FILTER regex(?label, "^sanction (EU)$", "i" )
FILTER (lang(?label) = "en")
FILTER (?p IN (skos:prefLabel, skos:altLabel ) )
}
}
It doesn't return anything. Also tried to escape the brackets with backslash but the query breaks. Do you know how to escape brackets in a sparql string?? thanks in advance!
I have also added the snippet below. This query will return the name of the company uri, its name and parent company. It is working with DBpedia.org/sparql but not with sparqlwrapper(not returning anything; )
query1 = """
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/property/>
PREFIX db: <http://dbpedia.org/resource/>
select distinct ?iri ?name ?parent (concat('[',group_concat(distinct ?location;separator=','),']') as ?location)
{
?iri a dbo:Company ;
rdfs:label ?label ;
foaf:name ?name
OPTIONAL { ?iri dbo:parentCompany ?parent.
filter (!isBlank(?parent)) }
OPTIONAL { ?iri dbo:location ?location.}
filter(regex(?name, "\\btata steel\\b","i" )) .
filter(regex(?label, "\\btata steel\\b","i" ))
}
GROUP BY ?iri ?name ?parent
"""
def get_country_description(query1):
sparql = SPARQLWrapper("http://dbpedia.org/sparql")
sparql.setReturnFormat('json')
sparql.setQuery(query1) # the previous query as a literal string
return sparql.query().convert()
get rid of \\b in your regex expression, and it works! (i dont know why it is needed as tata steel is a whole word)
Also you need to pass query1! to your function!
and use sparql.setReturnFormat('json') not JSON,
cheers
I have a problem, which I explain on following example:
I want to retrieve all information in any language on a category. I must use ?category as a label and the language labels en, as they are inputs in my program.
The query looks like this, but when I change the language I don't receive any information on the category. I know the problem lies in the dcterms:subject, because ?category returns http://dbpedia.org/resource/Category:Countries_in_Europe (see first example below).
For example to search for a category label in german you have to use http://de.dbpedia.org/resource/Kategorie:Staat_in_Europa (see second example below).
prefix dcterms: <http://purl.org/dc/terms/>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?objectLabel WHERE {
?subject dcterms:subject ?category ; rdfs:label ?objectLabel
?category rdfs:label "Countries in Europe"#en .
FILTER (LANG(?objectLabel)='en')
}
Equivalent query in different language that doesn't work as example:
prefix dcterms: <http://purl.org/dc/terms/>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?objectLabel WHERE {
?subject dcterms:subject ?category ; rdfs:label ?objectLabel
?category rdfs:label "Staat in Europa"#de .
FILTER (LANG(?objectLabel)='de')
}
Is there a similar or different way / method to solve the problem? Thanks in advance for any help.
I am working with Bio2RDF biological database and would like to get resource URL for Novobiocin which is [http://bio2rdf.org/drugbank:DB01051 ] using SPARQL query.Using yasgui.org I selected http://drugbank.bio2rdf.org/sparql service and executed the following query:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dcterms: <http://purl.org/dc/terms/>
SELECT ?resource WHERE { ?resource dcterms:identifier "drugbank:DB01051"}
However, It did not retrieve the result. Could you tell me why it does not work, please ?
This question already has answers here:
Why is dbpedia-owl:wikiPageRedirects not returning the full set of redirect links? (Sparql)
(2 answers)
Closed 7 years ago.
I wanted to get the "is dbo:wikiPageRedirects of" and use it as an alias to the label.
ex:
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX : <http://dbpedia.org/resource/>
PREFIX dbpedia2: <http://dbpedia.org/property/>
PREFIX dbpedia: <http://dbpedia.org/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT *
WHERE {
FILTER (?uri = <http://dbpedia.org/resource/Benigno_Aquino_III>)
OPTIONAL{
?uri rdfs:label ?label .
FILTER( LANG(?label) = "" || LANGMATCHES(LANG(?label), "en") )
}
OPTIONAL
{
?uri dbo:birthDate ?birthDate .
}
OPTIONAL
{
?uri rdfs:label "Benigno Aquino III"#en ;
dbo:wikiPageRedirects ?redirectsTo .
}
}
what I get is a blank wikiPageRedirects, But when i use http://dbpedia.org/resource/PNOY i get http://dbpedia.org/resource/Benigno_Aquino_III as redirectsTo. I want to do the opposite.
The relation is "dbo:wikiPageRedirects of" and not "dbo:wikiPageRedirects". In this case, it means that http://dbpedia.org/resource/Benigno_Aquino_III lists the resources which have a connection of the sort
?u dbo:wikiPageRedirects http://dbpedia.org/resource/Benigno_Aquino_III
you should use
?redirectsTo dbo:wikiPageRedirects ?uri .