You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by ju...@apache.org on 2007/05/30 23:58:48 UTC

svn commit: r542948 - in /labs/juuso: graph.m main.m n3.m rdf.m rdfs.m triple.m uri.m xsd.m

Author: jukka
Date: Wed May 30 14:58:47 2007
New Revision: 542948

URL: http://svn.apache.org/viewvc?view=rev&rev=542948
Log:
juuso: Implemented the builtin rules of RDF Schema

Added:
    labs/juuso/graph.m   (with props)
    labs/juuso/triple.m   (with props)
Modified:
    labs/juuso/main.m
    labs/juuso/n3.m
    labs/juuso/rdf.m
    labs/juuso/rdfs.m
    labs/juuso/uri.m
    labs/juuso/xsd.m

Added: labs/juuso/graph.m
URL: http://svn.apache.org/viewvc/labs/juuso/graph.m?view=auto&rev=542948
==============================================================================
--- labs/juuso/graph.m (added)
+++ labs/juuso/graph.m Wed May 30 14:58:47 2007
@@ -0,0 +1,41 @@
+%-------------------------------------------------------------------------%
+%
+% 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 graph.
+
+:- interface.
+:- import_module triple.
+:- import_module set.
+
+:- type graph  ---> graph(set(triple)).
+
+:- func empty = graph is det.
+
+:- pred contains(graph, triple).
+:- mode contains(in, in) is semidet.
+:- mode contains(in, out) is nondet.
+
+:- implementation.
+:- import_module rdfs.
+:- import_module solutions.
+
+empty = graph(Set) :-
+        solutions(rdfs.builtin, List),
+        Set = from_list(List).
+
+contains(graph(Set), Triple) :- member(Triple, Set).

Propchange: labs/juuso/graph.m
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: labs/juuso/main.m
URL: http://svn.apache.org/viewvc/labs/juuso/main.m?view=diff&rev=542948&r1=542947&r2=542948
==============================================================================
--- labs/juuso/main.m (original)
+++ labs/juuso/main.m Wed May 30 14:58:47 2007
@@ -1,4 +1,4 @@
-%--------------------------------------------------%
+%-------------------------------------------------------------------------%
 %
 % Licensed to the Apache Software Foundation (ASF) under one or more
 % contributor license agreements.  See the NOTICE file distributed with
@@ -15,7 +15,7 @@
 % See the License for the specific language governing permissions and
 % limitations under the License.
 %
-%--------------------------------------------------%
+%-------------------------------------------------------------------------%
 :- module main.
 
 :- interface.
@@ -24,12 +24,8 @@
 :- pred main(io::di, io::uo) is det.
 
 :- implementation.
-:- import_module string.
-:- import_module rdf.
-:- import_module set.
-:- import_module list.
+:- import_module graph.
 :- import_module n3.
 
 main(!IO) :-
-        write_triple(triple("foo", "bar", "baz"), !IO),
-        write_graph(graph(from_list([ triple("a", "b", "c"), triple("x", "y", "z") ])), !IO).
+        n3.write_graph(graph.empty, !IO).

Modified: labs/juuso/n3.m
URL: http://svn.apache.org/viewvc/labs/juuso/n3.m?view=diff&rev=542948&r1=542947&r2=542948
==============================================================================
--- labs/juuso/n3.m (original)
+++ labs/juuso/n3.m Wed May 30 14:58:47 2007
@@ -25,7 +25,8 @@
 %
 %-------------------------------------------------------------------------%
 :- interface.
-:- import_module rdf.
+:- import_module triple.
+:- import_module graph.
 :- import_module io.
 
 :- pred write_triple(triple::in, io::di, io::uo) is det.
@@ -33,23 +34,25 @@
 :- pred write_graph(graph::in, io::di, io::uo) is det.
 
 :- implementation.
+:- import_module uri.
+:- import_module rdf.
 :- import_module string.
 :- import_module list.
 :- import_module set.
 
-:- pred write_url(string::in, io::di, io::uo) is det.
+:- pred write_url(uri::in, io::di, io::uo) is det.
 
-write_url(U, !IO) :-
+write_url(uri(U), !IO) :-
         write_string("<", !IO), write_string(U, !IO), write_string(">", !IO).
 
-:- pred write_predicate(string::in, io::di, io::uo) is det.
+:- pred write_predicate(uri::in, io::di, io::uo) is det.
 
 write_predicate(P, !IO) :-
-        if P = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
+        if P = rdf("type")
             then write_string("a", !IO)
-        else if P = "http://www.w3.org/2002/07/owl#sameAs"
+        else if P = uri("http://www.w3.org/2002/07/owl#sameAs")
             then write_string("=", !IO)
-        else if P = "http://www.w3.org/2000/10/swap/log#implies"
+        else if P = uri("http://www.w3.org/2000/10/swap/log#implies")
             then write_string("=>", !IO)
         else
             write_url(P, !IO).

Modified: labs/juuso/rdf.m
URL: http://svn.apache.org/viewvc/labs/juuso/rdf.m?view=diff&rev=542948&r1=542947&r2=542948
==============================================================================
--- labs/juuso/rdf.m (original)
+++ labs/juuso/rdf.m Wed May 30 14:58:47 2007
@@ -18,38 +18,23 @@
 %-------------------------------------------------------------------------%
 :- module rdf.
 
-%-------------------------------------------------------------------------%
-%
-% This file defines the RDF types "triple" and "graph".
-% Currently all triple components are just strings.
-%
-%-------------------------------------------------------------------------%
 :- interface.
 :- import_module string.
 :- import_module uri.
-:- import_module set.
+:- import_module graph.
 
-:- type blank ---> blank(string).
+:- func rdf(string) = uri is det.
 
-:- type subject ---> subject(uri); subject(blank).
-:- type predicate ---> predicate(uri).
-:- type object ---> object(uri); object(blank); object(string).
-
-:- type triple ---> triple(subject, predicate, object).
-
-:- type graph  ---> graph( set(triple) ).
-
-:- pred graph_contains(graph::in, triple::out) is semidet.
+:- pred type(graph, uri, uri).
+:- mode type(in, in, in) is semidet.
+:- mode type(in, out, in) is nondet.
+:- mode type(in, in, out) is nondet.
+:- mode type(in, out, out) is nondet.
 
 :- implementation.
+:- import_module triple.
 
-:- func graph_set(graph::in) = set(triple) is det.
-
-graph_set(graph(S)) = S.
-
-graph_contains(Graph, Triple) :-
-        set.member(T, graph_set(G)).
+rdf(S) = prefix("http://www.w3.org/1999/02/22-rdf-syntax-ns#", S).
 
-graph_contains(Graph, triple(S, P1, O)) :-
-        graph_contains(Graph, triple(P1, "http://www.w3.org/2002/07/owl#sameAs", P2)),
-        graph_contains(S, P2, O).
\ No newline at end of file
+type(Graph, Subject, Type) :-
+        contains(Graph, triple(Subject, rdf("type"), Type)).

Modified: labs/juuso/rdfs.m
URL: http://svn.apache.org/viewvc/labs/juuso/rdfs.m?view=diff&rev=542948&r1=542947&r2=542948
==============================================================================
--- labs/juuso/rdfs.m (original)
+++ labs/juuso/rdfs.m Wed May 30 14:58:47 2007
@@ -18,27 +18,277 @@
 %-------------------------------------------------------------------------%
 :- module rdfs.
 
-%-------------------------------------------------------------------------%
-%
-%-------------------------------------------------------------------------%
 :- interface.
 :- import_module string.
-:- import_module rdf.
+:- import_module uri.
+:- import_module triple.
+:- import_module graph.
+
+:- func rdfs(string) = uri is det.
+
+:- pred builtin(triple::out) is multi.
+
+:- pred property(graph, uri, uri, uri).
+:- 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 nondet.
 
-:- func rdfs(string) = string.
-:- mode rdfs(in) = out is det.
-:- mode rdfs(out) = in is semidet.
+:- pred instance(graph, uri, uri).
+:- mode instance(in, in, in) is semidet.
+:- mode instance(in, in, out) is nondet.
 
-:- pred subClassOf(graph, string, string).
+:- pred class(graph, uri).
+:- mode class(in, in) is semidet.
+:- mode class(in, out) is nondet.
+
+:- pred subClassOf(graph, uri, uri).
 :- mode subClassOf(in, in, in) is semidet.
-:- mode subClassOf(in, in, out) is multi.
-:- mode subClassOf(in, out, in) is multi.
-:- mode subClassOf(in, out, out) is multi.
+:- mode subClassOf(in, in, out) is nondet.
+:- mode subClassOf(in, out, in) is nondet.
+
+:- pred subPropertyOf(graph, uri, uri).
+:- mode subPropertyOf(in, in, in) is semidet.
+:- mode subPropertyOf(in, in, out) is nondet.
+:- mode subPropertyOf(in, out, in) is nondet.
+
+:- pred range(graph, uri, uri).
+:- mode range(in, in, in) is semidet.
+:- mode range(in, in, out) is nondet.
+:- mode range(in, out, in) is nondet.
+
+:- pred domain(graph, uri, uri).
+:- mode domain(in, in, in) is semidet.
+:- mode domain(in, in, out) is nondet.
+:- mode domain(in, out, in) is nondet.
 
 :- implementation.
+:- import_module triple.
+:- import_module rdf.
+
+rdfs(S) = prefix("http://www.w3.org/2000/01/rdf-schema#", S).
+
+property(G, S, P, O) :-
+        graph.contains(G, triple(S, P, 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.
+
+instance(G, R, rdfs("Resource")) :-
+        graph.contains(G, T),
+        triple.contains(T, R).
+
+% All other classes are subclasses of this class.
+
+subClassOf(G, C, rdfs("Resource")) :-
+        class(G, C),
+        C \= rdfs("Resource").
+
+% rdfs:Resource is an instance of rdfs:Class.
+
+builtin(triple(rdfs("Resource"), rdf("type"), rdfs("Class"))).
+
+%-------------------------------------------------------------------------%
+%
+% 2.2 rdfs:Class
+%
+% This is the class of resources that are RDF classes.
+
+class(G, C) :-
+        property(G, C, rdf("type"), rdfs("Class")).
+
+% rdfs:Class is an instance of rdfs:Class.
+
+builtin(triple(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(triple(rdf("Property"), rdf("type"), rdf("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(triple(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(triple(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(triple(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(triple(rdfs("domain"), rdf("type"), rdf("Property"))).
+
+instance(G, R, C) :-
+        property(G, R, Property, _),
+        domain(G, Property, 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, Property, C) :-
+        property(G, Property, 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(triple(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(triple(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(triple(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(triple(rdf("type"), rdfs("domain"), rdfs("Resource"))).
+builtin(triple(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(triple(rdfs("subClassOf"), rdf("type"), rdf("Property"))).
+
+instance(G, R, C) :-
+        subClassOf(G, SubClass, C),
+        instance(G, R, SubClass).
+
+% 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.
+
+subClassOf(G, C, Base) :-
+        property(G, C, rdfs("subClassOf"), Base).
+
+% The rdfs:domain of rdfs:subClassOf is rdfs:Class. The rdfs:range of
+% rdfs:subClassOf is rdfs:Class.
+
+builtin(triple(rdfs("subClassOf"), rdfs("domain"), rdfs("Class"))).
+builtin(triple(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(triple(rdfs("subPropertyOf"), rdf("type"), rdf("Property"))).
+
+property(G, R, P, O) :-
+        subPropertyOf(G, SubProperty, P),
+        property(G, R, SubProperty, O).
+
+% 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.
+
+subPropertyOf(G, Property, Base) :-
+        property(G, Property, rdfs("subPropertyOf"), Base).
 
-rdfs(S) = "http://www.w3.org/2000/01/rdf-schema#" ++ S.
+% The rdfs:domain of rdfs:subPropertyOf is rdf:Property. The rdfs:range
+% of rdfs:subPropertyOf is rdf:Property.
 
-subClassOf(G, A, B) :-
-        B = rdfs("Class");
-        graph_contains(G, triple(A, rdfs("subClassOf"), B)).
+builtin(triple(rdfs("subPropertyOf"), rdfs("domain"), rdf("Property"))).
+builtin(triple(rdfs("subPropertyOf"), rdfs("range"), rdf("Property"))).

Added: labs/juuso/triple.m
URL: http://svn.apache.org/viewvc/labs/juuso/triple.m?view=auto&rev=542948
==============================================================================
--- labs/juuso/triple.m (added)
+++ labs/juuso/triple.m Wed May 30 14:58:47 2007
@@ -0,0 +1,36 @@
+%-------------------------------------------------------------------------%
+%
+% 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 triple.
+
+:- interface.
+:- import_module uri.
+
+:- type triple ---> triple( subject   :: uri,
+                            predicate :: uri,
+                            object    :: uri ).
+
+:- pred contains(triple, uri).
+:- mode contains(in, in) is semidet.
+:- mode contains(in, out) is multi.
+
+:- implementation.
+
+contains(triple(Subject, _, _), Subject).
+contains(triple(_, Predicate, _), Predicate).
+contains(triple(_, _, Object), Object).

Propchange: labs/juuso/triple.m
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: labs/juuso/uri.m
URL: http://svn.apache.org/viewvc/labs/juuso/uri.m?view=diff&rev=542948&r1=542947&r2=542948
==============================================================================
--- labs/juuso/uri.m (original)
+++ labs/juuso/uri.m Wed May 30 14:58:47 2007
@@ -20,7 +20,9 @@
 
 %-------------------------------------------------------------------------%
 %
-% This module defines the "uri" type used for URI references. 
+% This module defines the "uri" type used for URIs and URI references.
+%
+% The "prefix" function is used to construct URIs from two strings.
 %
 %-------------------------------------------------------------------------%
 :- interface.
@@ -28,14 +30,8 @@
 
 :- type uri ---> uri(string).
 
-:- func rdf(string::in) = uri::out is det.
-:- func rdfs(string::in) = uri::out is det.
-:- func owl(string::in) = uri::out is det.
-:- func xsd(string::in) = uri::out is det.
+:- func prefix(string, string) = uri is det.
 
 :- implementation.
 
-rdf(S) = uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#" ++ S).
-rdfs(S) = uri("http://www.w3.org/2000/01/rdf-schema#" ++ S).
-xsd(S) = uri("http://www.w3.org/2001/XMLSchema#" ++ S).
-owl(S) = uri("http://www.w3.org/2002/07/owl#" ++S).
+prefix(A, B) = uri(A ++ B).

Modified: labs/juuso/xsd.m
URL: http://svn.apache.org/viewvc/labs/juuso/xsd.m?view=diff&rev=542948&r1=542947&r2=542948
==============================================================================
--- labs/juuso/xsd.m (original)
+++ labs/juuso/xsd.m Wed May 30 14:58:47 2007
@@ -20,15 +20,16 @@
 
 %-------------------------------------------------------------------------%
 %
+% The "xsd" function constructs an URI reference relative to
+% "http://www.w3.org/2001/XMLSchema#"
+%
 %-------------------------------------------------------------------------%
 :- interface.
+:- import_module uri.
 :- import_module string.
 
-:- func xsd(string) = string.
-:- mode xsd(in) = out is det.
-:- mode xsd(out) = in is semidet.
-
+:- func xsd(string::in) = uri::out is det.
 
 :- implementation.
 
-xsd(S) = "http://www.w3.org/2002/07/owl#" ++ S.
+xsd(S) = prefix("http://www.w3.org/2001/XMLSchema#", S).



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org