%-------------------------------------------------------------------------% % % Licensed to the Apache Software Foundation (ASF) under one or more % contributor license agreements. See the NOTICE file distributed with % this work for additional information regarding copyright ownership. % The ASF licenses this file to You under the Apache License, Version 2.0 % (the "License"); you may not use this file except in compliance with % the License. You may obtain a copy of the License at % % http://www.apache.org/licenses/LICENSE-2.0 % % Unless required by applicable law or agreed to in writing, software % distributed under the License is distributed on an "AS IS" BASIS, % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % See the License for the specific language governing permissions and % limitations under the License. % %-------------------------------------------------------------------------% :- module rdfs. :- interface. :- import_module string. :- import_module graph. :- func rdfs(string) = string is det. :- pred property(graph, string, string, string). :- mode property(in, in, in, in) is semidet. :- mode property(in, in, in, out) is nondet. :- mode property(in, in, out, in) is nondet. :- mode property(in, out, in, in) is nondet. :- mode property(in, in, out, out) is nondet. :- mode property(in, out, out, out) is multi. :- pred instance(graph, string, string). :- mode instance(in, in, in) is semidet. :- mode instance(in, in, out) is nondet. :- mode instance(in, out, in) is nondet. :- mode instance(in, out, out) is multi. :- pred class(graph, string). :- mode class(in, in) is semidet. :- mode class(in, out) is nondet. :- pred range(graph, string, string). :- mode range(in, in, in) is semidet. :- mode range(in, in, out) is nondet. :- mode range(in, out, in) is nondet. :- mode range(in, out, out) is nondet. :- pred domain(graph, string, string). :- mode domain(in, in, in) is semidet. :- mode domain(in, in, out) is nondet. :- mode domain(in, out, in) is nondet. %-------------------------------------------------------------------------% :- implementation. :- import_module rdf. rdfs(S) = "http://www.w3.org/2000/01/rdf-schema#" ++ S. :- pred builtin(string, string, string). :- mode builtin(out, out, out) is multi. :- pred contains(graph, string, string, string). :- mode contains(in, out, out, out) is multi. contains(G, S, P, O) :- builtin(S, P, O); graph.contains(G, S, P, O). property(G, S, P, O) :- rdfs.contains(G, S, P, O). property(G, S, P, O) :- rdfs.contains(G, X, rdfs("subPropertyOf"), P), property(G, S, X, O). instance(G, R, C) :- property(G, R, rdf("type"), C). %-------------------------------------------------------------------------% % % 2.1 rdfs:Resource % % All things described by RDF are called resources, and are instances of % the class rdfs:Resource. This is the class of everything. All other % classes are subclasses of this class. instance(G, R, rdfs("Resource")) :- property(G, R, _, _); property(G, _, R, _); property(G, _, _, R). % rdfs:Resource is an instance of rdfs:Class. builtin(rdfs("Resource"), rdf("type"), rdfs("Class")). %-------------------------------------------------------------------------% % % 2.2 rdfs:Class % % This is the class of resources that are RDF classes. class(G, C) :- instance(G, C, rdfs("Class")). % rdfs:Class is an instance of rdfs:Class. builtin(rdfs("Class"), rdf("type"), rdfs("Class")). %-------------------------------------------------------------------------% % % 2.6 rdf:Property % % rdf:Property is the class of RDF properties. % rdf:Property is an instance of rdfs:Class. builtin(rdf("Property"), rdf("type"), rdfs("Class")). %-------------------------------------------------------------------------% % % 3.1 rdfs:range % % rdfs:range is an instance of rdf:Property that is used to state that the % values of a property are instances of one or more classes. builtin(rdfs("range"), rdf("type"), rdf("Property")). range(G, Property, C) :- property(G, Property, rdfs("range"), C). % The triple % % P rdfs:range C % % states that P is an instance of the class rdf:Property, that C is an % instance of the class rdfs:Class and that the resources denoted by the % objects of triples whose predicate is P are instances of the class C. instance(G, P, rdf("Property")) :- range(G, P, _). instance(G, C, rdfs("Class")) :- range(G, _, C). instance(G, O, C) :- property(G, _, P, O), range(G, P, C). % Where P has more than one rdfs:range property, then the resources % denoted by the objects of triples with predicate P are instances of all % the classes stated by the rdfs:range properties. % % The rdfs:range property can be applied to itself. The rdfs:range of % rdfs:range is the class rdfs:Class. This states that any resource that % is the value of an rdfs:range property is an instance of rdfs:Class. builtin(rdfs("range"), rdfs("range"), rdfs("Class")). % The rdfs:range property is applied to properties. This can be % represented in RDF using the rdfs:domain property. The rdfs:domain of % rdfs:range is the class rdf:Property. This states that any resource % with an rdfs:range property is an instance of rdf:Property. builtin(rdfs("range"), rdfs("domain"), rdf("Property")). %-------------------------------------------------------------------------% % % 3.2 rdfs:domain % % rdfs:domain is an instance of rdf:Property that is used to state that % any resource that has a given property is an instance of one or more % classes. builtin(rdfs("domain"), rdf("type"), rdf("Property")). instance(G, R, C) :- property(G, R, P, _), domain(G, P, C). % A triple of the form: % % P rdfs:domain C % % states that P is an instance of the class rdf:Property, that C is a % instance of the class rdfs:Class and that the resources denoted by the % subjects of triples whose predicate is P are instances of the class C. domain(G, P, C) :- property(G, P, rdfs("domain"), C). % Where a property P has more than one rdfs:domain property, then the % resources denoted by subjects of triples with predicate P are instances % of all the classes stated by the rdfs:domain properties. % % The rdfs:domain property may be applied to itself. The rdfs:domain of % rdfs:domain is the class rdf:Property. This states that any resource % with an rdfs:domain property is an instance of rdf:Property. builtin(rdfs("domain"), rdfs("domain"), rdf("Property")). % The rdfs:range of rdfs:domain is the class rdfs:Class. This states that % any resource that is the value of an rdfs:domain property is an instance % of rdfs:Class. builtin(rdfs("domain"), rdfs("range"), rdfs("Class")). %-------------------------------------------------------------------------% % % 3.3 rdf:type % % rdf:type is an instance of rdf:Property that is used to state that a % resource is an instance of a class. builtin(rdf("type"), rdf("type"), rdf("Property")). % A triple of the form: % % R rdf:type C % % states that C is an instance of rdfs:Class and R is an instance of C. instance(G, R, C) :- property(G, R, rdf("type"), C). % The rdfs:domain of rdf:type is rdfs:R. The rdfs:range of % rdf:type is rdfs:Class. builtin(rdf("type"), rdfs("domain"), rdfs("Resource")). builtin(rdf("type"), rdfs("range"), rdfs("Class")). %-------------------------------------------------------------------------% % % 3.4 rdfs:subClassOf % % The property rdfs:subClassOf is an instance of rdf:Property that is used % to state that all the instances of one class are instances of another. builtin(rdfs("subClassOf"), rdf("type"), rdf("Property")). instance(G, R, C1) :- property(G, C2, rdfs("subClassOf"), C1), instance(G, R, C2). % A triple of the form: % % C1 rdfs:subClassOf C2 % % states that C1 is an instance of rdfs:Class, C2 is an instance of % rdfs:Class and C1 is a subclass of C2. The rdfs:subClassOf property % is transitive. instance(G, C1, rdfs("Class")) :- property(G, _, rdfs("subClassOf"), C1). instance(G, C2, rdfs("Class")) :- property(G, C2, rdfs("subClassOf"), _). % The rdfs:domain of rdfs:subClassOf is rdfs:Class. The rdfs:range of % rdfs:subClassOf is rdfs:Class. builtin(rdfs("subClassOf"), rdfs("domain"), rdfs("Class")). builtin(rdfs("subClassOf"), rdfs("range"), rdfs("Class")). %-------------------------------------------------------------------------% % % 3.5 rdfs:subPropertyOf % % The property rdfs:subPropertyOf is an instance of rdf:Property that is % used to state that all resources related by one property are also % related by another. builtin(rdfs("subPropertyOf"), rdf("type"), rdf("Property")). % A triple of the form: % % P1 rdfs:subPropertyOf P2 % % states that P1 is an instance of rdf:Property, P2 is an instance of % rdf:Property and P1 is a subproperty of P2. The rdfs:subPropertyOf % property is transitive. instance(G, P1, rdf("Property")) :- property(G, P1, rdfs("subPropertyOf"), _). instance(G, P2, rdf("Property")) :- property(G, _, rdfs("subPropertyOf"), P2). % The rdfs:domain of rdfs:subPropertyOf is rdf:Property. The rdfs:range % of rdfs:subPropertyOf is rdf:Property. builtin(rdfs("subPropertyOf"), rdfs("domain"), rdf("Property")). builtin(rdfs("subPropertyOf"), rdfs("range"), rdf("Property")).