英文:
Fetching triples using SPARQL query from turtle file
问题
我是新手使用SPARQL,目前在尝试从一个Turtle文件中提取三元组时遇到困难。
我正在尝试提取所有类别及其超类、标签和同义词。我运行的查询如下。
但是,此查询会过滤掉不存在'hasExactSynonym'的三元组。
以下是输出:
预期输出是:
英文:
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
答案1
得分: 3
你可以使用 OPTIONAL
来使同义词变成可选的:
WHERE {
?cid rdfs:label ?label .
?cid rdfs:subClassOf ?class .
OPTIONAL { ?cid oboInOwl:hasExactSynonym ?synonyms . }
}
英文:
You can use OPTIONAL
to make the synonyms optional:
<!-- language: lang-none -->
WHERE {
?cid rdfs:label ?label .
?cid rdfs:subClassOf ?class .
OPTIONAL { ?cid oboInOwl:hasExactSynonym ?synonyms . }
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论