Возвращение узлов в графе, которые не имеют rdf: тип rdfs: Class или rdf: Property - PullRequest
0 голосов
/ 06 апреля 2020

Я использую 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, который возвращает эту информацию?

1 Ответ

1 голос
/ 07 апреля 2020

Если вы хотите вернуть все ресурсы, которые не имеют типа rdfs:Class или rdf:Property, тогда запрос может выглядеть примерно так:

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