简体   繁体   English

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

[英]Returning nodes in a graph which do not have a rdf:type of rdfs:Class or rdf:Property

I am using the json-ld format.我使用的是 json-ld 格式。

Let say I have the following Data Graph假设我有以下数据图

{
    "@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 equivalent) (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" .

I would like returned to me the nodes:我想把节点还给我:

        {
            "@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"           
        }

because in one case the type is invalid, another has a typo, and the last is missing the type information.因为在一种情况下类型无效,另一种有错字,最后一种是缺少类型信息。

If only the "@id" information was returned, that would be sufficient.如果只返回“@id”信息,那就足够了。

What is the SPARQL query that returns this information?返回此信息的 SPARQL 查询是什么?

If you want back all resources that do not have a type of either rdfs:Class or rdf:Property , then the query could be something like:如果您想要返回不属于rdfs:Classrdf:Property类型的所有资源,则查询可能类似于:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM