sparql - 返回图中没有 rdf:type 的 rdfs:Class 或 rdf:Property 的节点
问题描述
我使用的是 json-ld 格式。
假设我有以下数据图
{
"@context": {
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
"xsd": "http://www.w3.org/2001/XMLSchema#",
"hr": "http://learningsparql.com/ns/humanResources#",
"d": "http://learningsparql.com/ns/data#",
"sh": "http://www.w3.org/ns/shacl#"
},
"@graph": [
{
"@id": "hr:Employee",
"@type": "rdfs:Class",
"rdfs:comment": "a good employee",
"rdfs:label": "model"
},
{
"@id": "hr:Another",
"@type": "rdfs:Class"
},
{
"@id": "hr:name",
"@type": "rdf:Property"
},
{
"@id": "hr:randomtype",
"@type": "hr:invalidtype",
"rdfs:comment": "some comment about randomtype",
"rdfs:label": "some label about randomtype"
},
{
"@id": "hr:typo",
"@type": "rdfs:Classs",
"rdfs:comment": "some comment about typo",
"rdfs:label": "some label about typo"
},
{
"@id": "hr:missing",
"rdfs:comment": "some comment about missing"
}
]
}
(ttl 等价物)
@prefix d: <http://learningsparql.com/ns/data#> .
@prefix hr: <http://learningsparql.com/ns/humanResources#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
hr:Another a rdfs:Class .
hr:Employee a rdfs:Class ;
rdfs:label "model" ;
rdfs:comment "a good employee" .
hr:missing rdfs:comment "some comment about missing" .
hr:name a rdf:Property .
hr:randomtype a hr:invalidtype ;
rdfs:label "some label about randomtype" ;
rdfs:comment "some comment about randomtype" .
hr:typo a rdfs:Classs ;
rdfs:label "some label about typo" ;
rdfs:comment "some comment about typo" .
我想把节点还给我:
{
"@id": "hr:randomtype",
"@type": "hr:invalidtype",
"rdfs:comment": "some comment about randomtype",
"rdfs:label": "some label about randomtype"
}
and
{
"@id": "hr:typo",
"@type": "rdfs:Classs",
"rdfs:comment": "some comment about typo",
"rdfs:label": "some label about typo"
}
and
{
"@id": "hr:missing",
"rdfs:comment": "some comment about missing"
}
因为在一种情况下类型无效,另一种有错字,最后一种是缺少类型信息。
如果只返回“@id”信息,那就足够了。
返回此信息的 SPARQL 查询是什么?
解决方案
如果您想要返回不属于rdfs:Class
or类型的所有资源rdf:Property
,则查询可能类似于:
SELECT ?s
WHERE {
?s ?p ?o .
FILTER NOT EXISTS {
?s a ?c .
FILTER(?c IN (rdfs:Class, rdf:Property))
}
}
推荐阅读
- windows - 在 Windows 上使用 emscripten 将 Rust 编译为 webassembly 时出错
- python - Python argparse.ArgumentParser - 以数字开头的选项名称?
- java - Jackson - 反序列化嵌套的 JSON 字符串
- python - 为什么多处理会减慢嵌套的 for 循环?
- java - 为什么我在 servlet 的请求参数中得到空值?
- reactjs - 使用 props 和 HOC 测试组件
- r - 如何根据 R 中的多个条件定义新的数据框列?
- testing - 多线程重用空手道功能时出错
- java - 在docker容器中输出Spring Boot日志
- laravel - 在 Laravel Cashier 中创建一次性订阅