返回图中没有 rdfs:Class 或 rdf:Property 的 rdf:type 的节点

Returning nodes in a graph which do not have a rdf:type of rdfs:Class or 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”信息就足够了。

returns 此信息的 SPARQL 查询是什么?

如果您想要取回所有类型不属于 rdfs:Classrdf:Property 的资源,则查询可能类似于:

SELECT ?s
WHERE { 
     ?s ?p ?o .
     FILTER NOT EXISTS { 
             ?s a ?c .
             FILTER(?c IN (rdfs:Class, rdf:Property))
     }
}