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/31 01:42:20 UTC
svn commit: r542972 - in /labs/juuso: graph.m main.m n3.m rdfs.m
Author: jukka
Date: Wed May 30 16:42:19 2007
New Revision: 542972
URL: http://svn.apache.org/viewvc?view=rev&rev=542972
Log:
juuso: Optimized graph handling and improved RDF schema code
Modified:
labs/juuso/graph.m
labs/juuso/main.m
labs/juuso/n3.m
labs/juuso/rdfs.m
Modified: labs/juuso/graph.m
URL: http://svn.apache.org/viewvc/labs/juuso/graph.m?view=diff&rev=542972&r1=542971&r2=542972
==============================================================================
--- labs/juuso/graph.m (original)
+++ labs/juuso/graph.m Wed May 30 16:42:19 2007
@@ -20,22 +20,27 @@
:- interface.
:- import_module triple.
-:- import_module set.
+:- import_module list.
-:- type graph ---> graph(set(triple)).
+:- type graph.
:- func empty = graph is det.
+:- func create(list(triple)) = 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.
+:- import_module set.
+
+:- type graph ---> graph(set(triple)).
+
+empty = create([]).
-empty = graph(Set) :-
- solutions(rdfs.builtin, List),
- Set = from_list(List).
+create(Triples) = graph(Set) :-
+ Set = set.from_list(Triples).
-contains(graph(Set), Triple) :- member(Triple, Set).
+contains(graph(Set), Triple) :-
+ set.member(Triple, Set).
Modified: labs/juuso/main.m
URL: http://svn.apache.org/viewvc/labs/juuso/main.m?view=diff&rev=542972&r1=542971&r2=542972
==============================================================================
--- labs/juuso/main.m (original)
+++ labs/juuso/main.m Wed May 30 16:42:19 2007
@@ -25,7 +25,15 @@
:- implementation.
:- import_module graph.
+:- import_module list.
+:- import_module triple.
+:- import_module uri.
+:- import_module rdfs.
+:- import_module solutions.
:- import_module n3.
main(!IO) :-
- n3.write_graph(graph.empty, !IO).
+ G = graph.create([ triple(uri("A"), uri("P"), uri("B")),
+ triple(uri("P"), rdfs("range"), uri("C")) ]),
+ solutions((pred(X::out) is nondet :- rdfs.instance(G, uri("B"), X)), Xs),
+ io.write(Xs, !IO).
Modified: labs/juuso/n3.m
URL: http://svn.apache.org/viewvc/labs/juuso/n3.m?view=diff&rev=542972&r1=542971&r2=542972
==============================================================================
--- labs/juuso/n3.m (original)
+++ labs/juuso/n3.m Wed May 30 16:42:19 2007
@@ -38,7 +38,7 @@
:- import_module rdf.
:- import_module string.
:- import_module list.
-:- import_module set.
+:- import_module solutions.
:- pred write_url(uri::in, io::di, io::uo) is det.
@@ -73,5 +73,6 @@
write_triple(Head, !IO),
write_triples(Tail, !IO).
-write_graph(graph(S), !IO) :-
- write_triples(to_sorted_list(S), !IO).
+write_graph(G, !IO) :-
+ solutions((pred(T::out) is nondet :- graph.contains(G, T)), Triples),
+ write_triples(Triples, !IO).
Modified: labs/juuso/rdfs.m
URL: http://svn.apache.org/viewvc/labs/juuso/rdfs.m?view=diff&rev=542972&r1=542971&r2=542972
==============================================================================
--- labs/juuso/rdfs.m (original)
+++ labs/juuso/rdfs.m Wed May 30 16:42:19 2007
@@ -21,57 +21,58 @@
:- interface.
:- import_module string.
:- 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.
+:- mode property(in, out, out, out) is multi.
:- pred instance(graph, uri, uri).
:- 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, 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 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.
+:- mode range(in, out, out) 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.
+:- pred builtin(uri, uri, uri).
+:- mode builtin(out, out, out) is multi.
+
+:- pred contains(graph, uri, uri, uri).
+:- mode contains(in, out, out, out) is multi.
+
+contains(G, S, P, O) :-
+ builtin(S, P, O);
+ graph.contains(G, triple(S, P, O)).
+
rdfs(S) = prefix("http://www.w3.org/2000/01/rdf-schema#", S).
property(G, S, P, O) :-
- graph.contains(G, triple(S, P, O)).
+ contains(G, S, P, O).
instance(G, R, C) :-
property(G, R, rdf("type"), C).
@@ -81,21 +82,17 @@
% 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.
+% the class rdfs:Resource. This is the class of everything. All other
+% classes are subclasses of this class.
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").
+ contains(G, R, _, _);
+ contains(G, _, R, _);
+ contains(G, _, _, R).
% rdfs:Resource is an instance of rdfs:Class.
-builtin(triple(rdfs("Resource"), rdf("type"), rdfs("Class"))).
+builtin(rdfs("Resource"), rdf("type"), rdfs("Class")).
%-------------------------------------------------------------------------%
%
@@ -104,11 +101,11 @@
% This is the class of resources that are RDF classes.
class(G, C) :-
- property(G, C, rdf("type"), rdfs("Class")).
+ instance(G, C, rdfs("Class")).
% rdfs:Class is an instance of rdfs:Class.
-builtin(triple(rdfs("Class"), rdf("type"), rdfs("Class"))).
+builtin(rdfs("Class"), rdf("type"), rdfs("Class")).
%-------------------------------------------------------------------------%
%
@@ -117,7 +114,7 @@
% rdf:Property is the class of RDF properties.
% rdf:Property is an instance of rdfs:Class.
-builtin(triple(rdf("Property"), rdf("type"), rdf("Class"))).
+builtin(rdf("Property"), rdf("type"), rdfs("Class")).
%-------------------------------------------------------------------------%
%
@@ -126,7 +123,7 @@
% 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"))).
+builtin(rdfs("range"), rdf("type"), rdf("Property")).
range(G, Property, C) :-
property(G, Property, rdfs("range"), C).
@@ -157,14 +154,14 @@
% 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"))).
+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(triple(rdfs("range"), rdfs("domain"), rdf("Property"))).
+builtin(rdfs("range"), rdfs("domain"), rdf("Property")).
%-------------------------------------------------------------------------%
%
@@ -174,11 +171,11 @@
% any resource that has a given property is an instance of one or more
% classes.
-builtin(triple(rdfs("domain"), rdf("type"), rdf("Property"))).
+builtin(rdfs("domain"), rdf("type"), rdf("Property")).
instance(G, R, C) :-
- property(G, R, Property, _),
- domain(G, Property, C).
+ property(G, R, P, _),
+ domain(G, P, C).
% A triple of the form:
%
@@ -188,8 +185,8 @@
% 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).
+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
@@ -199,14 +196,13 @@
% 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"))).
+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(triple(rdfs("domain"), rdfs("range"), rdfs("Class"))).
-
+builtin(rdfs("domain"), rdfs("range"), rdfs("Class")).
%-------------------------------------------------------------------------%
%
@@ -215,7 +211,7 @@
% 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"))).
+builtin(rdf("type"), rdf("type"), rdf("Property")).
% A triple of the form:
%
@@ -229,8 +225,8 @@
% 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"))).
+builtin(rdf("type"), rdfs("domain"), rdfs("Resource")).
+builtin(rdf("type"), rdfs("range"), rdfs("Class")).
%-------------------------------------------------------------------------%
%
@@ -239,11 +235,11 @@
% 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"))).
+builtin(rdfs("subClassOf"), rdf("type"), rdf("Property")).
-instance(G, R, C) :-
- subClassOf(G, SubClass, C),
- instance(G, R, SubClass).
+instance(G, R, C1) :-
+ property(G, C2, rdfs("subClassOf"), C1),
+ instance(G, R, C2).
% A triple of the form:
%
@@ -253,14 +249,17 @@
% 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).
+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(triple(rdfs("subClassOf"), rdfs("domain"), rdfs("Class"))).
-builtin(triple(rdfs("subClassOf"), rdfs("range"), rdfs("Class"))).
+builtin(rdfs("subClassOf"), rdfs("domain"), rdfs("Class")).
+builtin(rdfs("subClassOf"), rdfs("range"), rdfs("Class")).
%-------------------------------------------------------------------------%
%
@@ -270,11 +269,11 @@
% used to state that all resources related by one property are also
% related by another.
-builtin(triple(rdfs("subPropertyOf"), rdf("type"), rdf("Property"))).
+builtin(rdfs("subPropertyOf"), rdf("type"), rdf("Property")).
-property(G, R, P, O) :-
- subPropertyOf(G, SubProperty, P),
- property(G, R, SubProperty, O).
+%property(G, S, P2, O) :-
+% property(G, P1, rdfs("subPropertyOf"), P2),
+% property(G, S, P1, O).
% A triple of the form:
%
@@ -284,11 +283,14 @@
% 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).
+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(triple(rdfs("subPropertyOf"), rdfs("domain"), rdf("Property"))).
-builtin(triple(rdfs("subPropertyOf"), rdfs("range"), rdf("Property"))).
+builtin(rdfs("subPropertyOf"), rdfs("domain"), rdf("Property")).
+builtin(rdfs("subPropertyOf"), rdfs("range"), rdf("Property")).
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org