图形中不具有rdfs:Class或rdf:Property的rdf:type的返回节点

问题描述 投票:0回答:1

我正在使用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查询是什么?

sparql rdf json-ld turtle-rdf
1个回答
0
投票

如果要返回所有类型都不为rdfs:Classrdf:Property的资源,则查询可能类似于:

SELECT ?s
WHERE { 
     ?s ?p ?o .
     FILTER NOT EXISTS { 
             ?s a ?c .
             FILTER(?c IN (rdfs:Class, rdf:Property))
     }
}
© www.soinside.com 2019 - 2024. All rights reserved.