使用SPARQL从Turtle文件中提取同义词和标签



我正处于SPARQL的学习阶段。我正在使用一个Turtle文件来提取一些信息。条件是:如果确切的同义词具有子字符串"stroke"或"stroke",则查询应返回所有同义词和rdfs:label

我正在使用以下查询,但没有得到输出:

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 * where { 
?s ?p ?o . 
rdfs:label <http://www.geneontology.org/formats/oboInOwl#hasExactSynonym> "stroke"^^xsd:string
}

以下是示例Turtle文件:

###  https://ontology.aaaa.com/aaaa/meddra_10008196
:meddra_10008196 
rdf:type owl:Class ;
<http://www.geneontology.org/formats/oboInOwl#hasDbXref> "DOID:6713" , "EFO:0000712" , "EFO:0003763" , "HE:A10008190" ;
<http://www.geneontology.org/formats/oboInOwl#hasExactSynonym> 
"(cva) cerebrovascular accident" , 
"Acute Cerebrovascular Accident" , 
"Acute Cerebrovascular Accidents" , 
"Acute Stroke" , 
"Acute Strokes" ;
rdfs:label "Cerebrovascular disorder"@en ;
:hasSocs "Nervous system disorders [meddra:10029205]" , "Vascular disorders [meddra:10047065]" ;
:uid "6e46da69b727e4e924c31027cdf47b8a" .

我期待这个输出:

(cva) cerebrovascular accident
Acute Cerebrovascular Accident
Acute Cerebrovascular Accidents
Acute Stroke
Acute Strokes
Cerebrovascular disorder

使用此三重模式,您将查询rdfs:label作为主语,而不是谓词:

rdfs:label <http://www.geneontology.org/formats/oboInOwl#hasExactSynonym> "stroke"^^xsd:string

您要问的是:";资源rdfs:label是否具有字符串值为"stroke"的属性oboInOwl:hasExactSynonym">

但是你想问这个关于类的问题(例如:meddra_10008196(,而不是rdfs:label:

?class oboInOwl:hasExactSynonym "stroke" .

查找匹配项

由于您不想只找到完全匹配的字符串,因此可以使用CONTAINS:

?class oboInOwl:hasExactSynonym ?matchingSynonym .
FILTER( CONTAINS(?matchingSynonym, "stroke") ) .

如果您想忽略大小写,可以使用LCASE:查询小写同义词

?class oboInOwl:hasExactSynonym ?matchingSynonym .
FILTER( CONTAINS(LCASE(?matchingSynonym), "stroke") ) .

显示结果

要在同一列中显示标签和所有同义词,可以使用带有|(AlternativePath(的属性路径:

?class rdfs:label|oboInOwl:hasExactSynonym ?labelOrSynonym .

完整查询

# [prefixes]
SELECT ?class ?labelOrSynonym
WHERE {
?class rdfs:label|oboInOwl:hasExactSynonym ?labelOrSynonym .
FILTER EXISTS {
?class oboInOwl:hasExactSynonym ?matchingSynonym .
FILTER( CONTAINS(LCASE(?matchingSynonym), "stroke") ) .
}
}

最新更新