I am new to SPARQL and currently struglling to fetch triples from a turtle file.
### https://ontology/1001
<https://ontology/1001> rdf:type owl:Class ;
rdfs:subClassOf <https://ontology/748>;
<http://www.geneontology.org/formats/oboInOwl#hasExactSynonym> "Injury, neuronal" ,
"Neurotrauma" ;
rdfs:label "Nervous system injury" .
### https://ontology/10021
<https://ontology/10021> rdf:type owl:Class ;
rdfs:subClassOf <https://ontology/2034> ;
rdfs:label "C3 glomerulopathy" .
I am trying to extract all classes with their superclasses, labels and Synonym. The query which I am running is below.
query_id = """
prefix oboInOwl: <http://www.geneontology.org/formats/oboInOwl#>
prefix obo: <http://purl.obolibrary.org/obo/>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT distinct ?cid ?label ?class ?synonyms
WHERE {
?cid rdfs:label ?label .
?cid rdfs:subClassOf ?class .
?cid oboInOwl:hasExactSynonym ?synonyms .
}
"""
However, this query is filtering the triple where 'hasExactSynonym' doesn't exists.
Following is the output:
cid label class synonyms
1001 Nervous system injury 748 Injury, neuronal , Neurotrauma
The expected output is:
cid label class synonyms
1001 Nervous system injury 748 Injury, neuronal , Neurotrauma
10021 C3 glomerulopathy 2034
You can use OPTIONAL
to make the synonyms optional:
WHERE {
?cid rdfs:label ?label .
?cid rdfs:subClassOf ?class .
OPTIONAL { ?cid oboInOwl:hasExactSynonym ?synonyms . }
}