dowl 0.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES ADDED
@@ -0,0 +1 @@
1
+ Changes
data/README ADDED
@@ -0,0 +1,19 @@
1
+ A simple command-line tool for generating HTML documentation from RDFS/OWL schemas
2
+
3
+ INSTALLATION
4
+
5
+ Once you have the code checked out simple do:
6
+
7
+ rake install
8
+
9
+ To install the dowl gem. This will give you a new command-line application called dowl.
10
+
11
+ The application takes two parameters. The first parameter is the location of the schema file to parse (currently in Turtle only) the second parameter is option and is the location of an ERB file that contains the template for output. A default template is provided and can be customized for specific purposes.
12
+
13
+ The script sends its output to STDOUT so just pipe it into a file.
14
+
15
+ E.g:
16
+
17
+ dowl examples/example.ttl >/tmp/example.html
18
+
19
+ The script will automatically include the contents of introduction.html, if found in the same directory as the schema, into the documentation. This file should contain an HTML fragment.
@@ -0,0 +1,64 @@
1
+ require 'rake'
2
+ require 'rake/gempackagetask'
3
+ require 'rake/rdoctask'
4
+ require 'rake/testtask'
5
+ require 'rake/clean'
6
+
7
+ NAME = "dowl"
8
+ VER = "0.2"
9
+
10
+ RDOC_OPTS = ['--quiet', '--title', 'dowl Reference', '--main', 'README']
11
+
12
+ PKG_FILES = %w( README Rakefile CHANGES ) +
13
+ Dir.glob("{bin,doc,tests,examples,lib}/**/*")
14
+
15
+ CLEAN.include ['*.gem', 'pkg']
16
+ SPEC =
17
+ Gem::Specification.new do |s|
18
+ s.name = NAME
19
+ s.version = VER
20
+ s.platform = Gem::Platform::RUBY
21
+ s.required_ruby_version = ">= 1.8.5"
22
+ s.has_rdoc = true
23
+ s.extra_rdoc_files = ["README", "CHANGES"]
24
+ s.rdoc_options = RDOC_OPTS
25
+ s.summary = "dowl OWL/RDF doc generator"
26
+ s.description = s.summary
27
+ s.author = "Leigh Dodds"
28
+ s.email = 'leigh.dodds@talis.com'
29
+ s.homepage = 'http://github.com/ldodds/dowl'
30
+ s.files = PKG_FILES
31
+ s.require_path = "lib"
32
+ s.bindir = "bin"
33
+ s.executables = ["dowl"]
34
+ s.test_file = "tests/ts_dowl.rb"
35
+ s.add_dependency("mocha", ">= 0.9.5")
36
+ s.add_dependency("rdf-raptor", ">= 0.4.0")
37
+ end
38
+
39
+ Rake::GemPackageTask.new(SPEC) do |pkg|
40
+ pkg.need_tar = true
41
+ end
42
+
43
+ Rake::RDocTask.new do |rdoc|
44
+ rdoc.rdoc_dir = 'doc/rdoc'
45
+ rdoc.options += RDOC_OPTS
46
+ rdoc.rdoc_files.include("README", "CHANGES", "lib/**/*.rb")
47
+ rdoc.main = "README"
48
+
49
+ end
50
+
51
+ Rake::TestTask.new do |test|
52
+ test.test_files = FileList['tests/tc_*.rb']
53
+ end
54
+
55
+ desc "Install from a locally built copy of the gem"
56
+ task :install do
57
+ sh %{rake package}
58
+ sh %{sudo gem install pkg/#{NAME}-#{VER}}
59
+ end
60
+
61
+ desc "Uninstall the gem"
62
+ task :uninstall => [:clean] do
63
+ sh %{sudo gem uninstall #{NAME}}
64
+ end
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
3
+ require 'rubygems'
4
+ require 'getoptlong'
5
+ require 'rdf/redland'
6
+ require 'dowl'
7
+ require 'erb'
8
+
9
+ PROGRAM = File::basename $0
10
+
11
+ schema = DOWL::Schema.create_from_file(ARGV[0])
12
+ if ARGV[1]
13
+ generator = DOWL::Generator.new( schema, ARGV[1] )
14
+ else
15
+ generator = DOWL::Generator.new( schema )
16
+ end
17
+ file = generator.run()
18
+ puts file
@@ -0,0 +1,73 @@
1
+ #General Namespaces
2
+ @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
3
+ @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
4
+ @prefix owl: <http://www.w3.org/2002/07/owl#>.
5
+ @prefix foaf: <http://xmlns.com/foaf/0.1/>.
6
+ @prefix dcterms: <http://purl.org/dc/terms/>.
7
+ @prefix dctypes: <http://purl.org/dc/dcmitype/>.
8
+ @prefix vs: <http://www.w3.org/2003/06/sw-vocab-status/ns#> .
9
+ @prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
10
+ @prefix ex: <http://www.example.org/dowl/>.
11
+
12
+ ############################################################################
13
+ # General description of the schema
14
+ ############################################################################
15
+
16
+ <http://www.example.org/dowl/>
17
+ a owl:Ontology;
18
+ dcterms:title "An Example"@en ;
19
+ rdfs:comment "This is a simple example"@en ;
20
+ foaf:maker <http://www.ldodds.com#me> ;
21
+ foaf:maker <http://www.example.org/unknown> ;
22
+ dcterms:created "2010-02-19"^^xsd:date ;
23
+ dcterms:modified "2010-09-28"^^xsd:date .
24
+
25
+ <http://www.ldodds.com#me> a foaf:Person ;
26
+ foaf:name "Leigh Dodds" .
27
+
28
+ <http://www.example.org/unknown> a foaf:Person .
29
+
30
+ ############################################################################
31
+ # Classes
32
+ ############################################################################
33
+
34
+ ex:SomeClass
35
+ a owl:Class;
36
+ rdfs:label "Some Class"@en;
37
+ rdfs:comment "A Class of Things."@en;
38
+ rdfs:seeAlso <http://en.wikipedia.org/>;
39
+ vs:term_status "testing".
40
+
41
+ ex:DerivedClass
42
+ a owl:Class;
43
+ rdfs:subClassOf ex:SomeClass;
44
+ rdfs:label "Derived"@en;
45
+ rdfs:comment "A Derived Class"@en ;
46
+ rdfs:seeAlso <http://www.google.com>;
47
+ vs:term_status "testing".
48
+
49
+ ############################################################################
50
+ # Object Properties
51
+ ############################################################################
52
+
53
+ ex:objectProperty
54
+ a owl:ObjectProperty;
55
+ rdfs:label "object property"@en;
56
+ rdfs:comment "associates Some Class with another thing"@en;
57
+ rdfs:range ex:SomeClass;
58
+ rdfs:domain ex:SomeClass;
59
+ vs:term_status "testing".
60
+
61
+ ############################################################################
62
+ # Datatype Properties
63
+ ############################################################################
64
+
65
+ ex:datatypeProperty
66
+ a owl:DatatypeProperty;
67
+ rdfs:label "datatype property"@en;
68
+ rdfs:comment "a datatype property"@en;
69
+ rdfs:range xsd:string;
70
+ rdfs:domain ex:DerivedClass;
71
+ vs:term_status "testing".
72
+
73
+
@@ -0,0 +1,5 @@
1
+ <h2>Introduction</h2>
2
+
3
+ <p>
4
+ Contents of introduction.html in the same directory is automatically included.
5
+ </p>
@@ -0,0 +1,24 @@
1
+ require 'rubygems'
2
+ require 'erb'
3
+ require 'rdf'
4
+ require 'rdf/raptor'
5
+ require 'dowl/util'
6
+ require 'dowl/schema'
7
+ require 'dowl/class'
8
+ require 'dowl/property'
9
+ require 'dowl/ontology'
10
+ require 'dowl/generator'
11
+
12
+ module DOWL
13
+
14
+ class Namespaces
15
+
16
+ OWL = RDF::Vocabulary.new("http://www.w3.org/2002/07/owl#")
17
+ RDFS = RDF::RDFS
18
+ VS = RDF::Vocabulary.new("http://www.w3.org/2003/06/sw-vocab-status/ns#")
19
+ DCTERMS = RDF::Vocabulary.new("http://purl.org/dc/terms/")
20
+ FOAF = RDF::Vocabulary.new("http://xmlns.com/foaf/0.1/")
21
+
22
+ end
23
+
24
+ end
@@ -0,0 +1,56 @@
1
+ module DOWL
2
+
3
+ class Class < DOWL::LabelledDocObject
4
+ include Comparable
5
+
6
+ attr_reader :resource
7
+
8
+ def initialize(resource, schema)
9
+ super(resource, schema)
10
+ end
11
+
12
+ def uri
13
+ return @resource.uri.to_s
14
+ end
15
+
16
+ def sub_class_of()
17
+ parent = @schema.model.first_value(
18
+ RDF::Query::Pattern.new( @resource, DOWL::Namespaces::RDFS.subClassOf ) )
19
+ if parent
20
+ uri = parent.to_s
21
+ if @schema.classes[uri]
22
+ return @schema.classes[uri]
23
+ else
24
+ return uri
25
+ end
26
+ end
27
+ return nil
28
+ end
29
+
30
+ def see_alsos()
31
+ links = []
32
+ @schema.model.query(
33
+ RDF::Query::Pattern.new( @resource, DOWL::Namespaces::RDFS.seeAlso ) ) do |statement|
34
+ links << statement.object.to_s
35
+ end
36
+ return links
37
+ end
38
+
39
+ def to_s
40
+ return short_name
41
+ end
42
+
43
+ def sub_classes()
44
+ list = []
45
+
46
+ @schema.model.query(
47
+ RDF::Query::Pattern.new( nil, DOWL::Namespaces::RDFS.subClassOf, @resource) ) do |statement|
48
+ list << DOWL::Class.new(statement.subject, @schema)
49
+ end
50
+ return list
51
+ end
52
+
53
+ end
54
+
55
+
56
+ end
@@ -0,0 +1,226 @@
1
+ <html>
2
+ <head>
3
+ <title><%= schema.ontology.title %></title>
4
+ </head>
5
+ <body>
6
+ <h1><%= schema.ontology.title %></h1>
7
+
8
+ <dl>
9
+ <dt>Latest Version</dt>
10
+ <dd><a href="<%= schema.ontology.uri %>"><%= schema.ontology.uri %></a></dd>
11
+ <% if schema.ontology.created %>
12
+ <dt>Created</dt>
13
+ <dd><%= schema.ontology.created %></dd>
14
+ <% end %>
15
+ <% if schema.ontology.modified %>
16
+ <dt>Last Modified</dt>
17
+ <dd><%= schema.ontology.modified %></dd>
18
+ <% end %>
19
+ <dt>Authors</dt>
20
+ <% schema.ontology.authors.each do |author| %><dd><a href="<%= author.uri %>"><%= author.name %></a></dd><%end%>
21
+ </dl>
22
+
23
+ <h1>Abstract</h1>
24
+
25
+ <%= schema.ontology.comment %>
26
+
27
+ <% if introduction %>
28
+ <%= introduction %>
29
+ <% end %>
30
+
31
+ <div id="overview">
32
+ <h2>Overview Of Terms</h2>
33
+ <p>An alphabetical index of the ontology terms, divided into classes, properties and individuals. All the terms are hyperlinked to their
34
+ detailed description for quick reference.
35
+ </p>
36
+
37
+ <p><strong>Classes</strong>:
38
+ <% schema.list_classes().each do |key,val| %>
39
+ | <a href="#class_<%= val.short_name %>"><%= val.short_name %></a>
40
+ <% end %>
41
+ </p>
42
+ <p><strong>Properties</strong>:
43
+ <% schema.list_properties().each do |key,val| %>
44
+ | <a href="#prop_<%= val.short_name %>"><%= val.short_name %></a>
45
+ <% end %>
46
+ </p>
47
+ </div>
48
+
49
+ <div id="terms">
50
+ <h2>Ontology Terms</h2>
51
+ </div>
52
+
53
+ <div id="classes">
54
+ <h3>Classes</h3>
55
+
56
+ <%schema.list_classes().each do |t| %>
57
+ <div class="term" id="class_<%= t[1].short_name %>">
58
+ <h4>Class: <%= t[1].short_name %></h4>
59
+ <table>
60
+ <tr><td class="label">Label</td><td><%= t[1].label %> </ts></tr>
61
+ <tr><td class="label">Status</td><td><%= t[1].status %> </ts></tr>
62
+ <% if t[1].sub_class_of %>
63
+ <% if t[1].sub_class_of.class.to_s == "String" %>
64
+ <tr><td class="label">Has Parent Class</td><td><a href="<%= t[1].sub_class_of %>"><%= t[1].sub_class_of %></a></td></tr>
65
+ <% else %>
66
+ <tr><td class="label">Has Parent Class</td><td><a href="#class_<%= t[1].sub_class_of.short_name %>"><%= t[1].sub_class_of.short_name %></a></td></tr>
67
+ <% end %>
68
+ <% end %>
69
+ <% if t[1].sub_classes.length > 0 %>
70
+ <tr>
71
+ <td class="label">Sub-Classes</td>
72
+ <td>
73
+ <% t[1].sub_classes.each do |child| %>
74
+ <a href="#class_<%= child.short_name %>"><%= child.short_name %></a>
75
+ <% end %>
76
+ </td>
77
+ </tr>
78
+ <% end %>
79
+ </table>
80
+ <p><%= t[1].comment %> </p>
81
+ <% if t[1].see_alsos.length > 0 %>
82
+ <p><em>Further Reading:</em></p>
83
+ <ul>
84
+ <% t[1].see_alsos.each do |link| %>
85
+ <li><a href="<%= link %>"><%= link %></a></li>
86
+ <% end %>
87
+ </ul>
88
+ <% end %>
89
+ </div>
90
+ <%end%>
91
+
92
+ </div>
93
+
94
+ <div id="properties">
95
+ <h3>Object Properties</h3>
96
+
97
+ <% schema.list_object_properties().each do |t| %>
98
+ <div class="term" id="prop_<%= t[1].short_name %>">
99
+ <h4>Property: <%= t[1].short_name %></h4>
100
+ <table>
101
+ <tr><td class="label">Label</td><td><%= t[1].label %> </ts></tr>
102
+ <tr><td class="label">Status</td><td><%= t[1].status %> </ts></tr>
103
+ <% if t[1].sub_property_of %>
104
+ <% if t[1].sub_property_of.class.to_s == "String" %>
105
+ <tr><td class="label">Has Parent Property</td><td><a href="<%= t[1].sub_property_of %>"><%= t[1].sub_property_of %></a></td></tr>
106
+ <% else %>
107
+ <tr><td class="label">Has Parent Property</td><td><a href="#prop_<%= t[1].sub_property_of.short_name %>"><%= t[1].sub_property_of.short_name %></a></td></tr>
108
+ <% end %>
109
+ <% end %>
110
+ <% if t[1].sub_properties.length > 0 %>
111
+ <tr>
112
+ <td class="label">Sub-Properties</td>
113
+ <td>
114
+ <% t[1].sub_properties.each do |child| %>
115
+ <a href="#class_<%= child.short_name %>"><%= child.short_name %></a>
116
+ <% end %>
117
+ </td>
118
+ </tr>
119
+ <% end %>
120
+ <% if t[1].range.length > 0 %>
121
+ <tr><td class="label">Range</td>
122
+ <td>
123
+ <% t[1].range.each do |cls| %>
124
+ <% if cls.class.to_s == "String" %>
125
+ <a href="<%= cls %>"><%= cls %></a>
126
+ <% else %>
127
+ <a href="#class_<%= cls.short_name %>"><%= cls.short_name %></a>
128
+ <% end %>
129
+ <% end %>
130
+ </td>
131
+ </tr>
132
+ <% end %>
133
+ <% if t[1].domain.length > 0 %>
134
+ <tr><td class="label">Domain</td>
135
+ <td>
136
+ <% t[1].domain.each do |cls| %>
137
+ <% if cls.class.to_s == "String" %>
138
+ <a href="<%= cls %>"><%= cls %></a>
139
+ <% else %>
140
+ <a href="#class_<%= cls.short_name %>"><%= cls.short_name %></a>
141
+ <% end %>
142
+ <% end %>
143
+ </td>
144
+ </tr>
145
+ <% end %>
146
+ </table>
147
+ <p><%= t[1].comment %> </p>
148
+ <% if t[1].see_alsos.length > 0 %>
149
+ <p><em>Further Reading:</em></p>
150
+ <ul>
151
+ <% t[1].see_alsos.each do |link| %>
152
+ <li><a href="<%= link %>"><%= link %></a></li>
153
+ <% end %>
154
+ </ul>
155
+ <% end %>
156
+ </div>
157
+ <%end%>
158
+
159
+
160
+ <h3>Datatype Properties</h3>
161
+
162
+ <%schema.list_datatype_properties().each do |t| %>
163
+ <div class="term" id="prop_<%= t[1].short_name %>">
164
+ <h4>Property: <%= t[1].short_name %></h4>
165
+ <table>
166
+ <tr><td class="label">Label</td><td><%= t[1].label %> </ts></tr>
167
+ <tr><td class="label">Status</td><td><%= t[1].status %> </ts></tr>
168
+ <% if t[1].sub_property_of %>
169
+ <% if t[1].sub_property_of.class.to_s == "String" %>
170
+ <tr><td class="label">Has Parent Property</td><td><a href="<%= t[1].sub_property_of %>"><%= t[1].sub_property_of %></a></td></tr>
171
+ <% else %>
172
+ <tr><td class="label">Has Parent Property</td><td><a href="#prop_<%= t[1].sub_property_of.short_name %>"><%= t[1].sub_property_of.short_name %></a></td></tr>
173
+ <% end %>
174
+ <% end %>
175
+ <% if t[1].sub_properties.length > 0 %>
176
+ <tr>
177
+ <td class="label">Sub-Properties</td>
178
+ <td>
179
+ <% t[1].sub_properties.each do |child| %>
180
+ <a href="#class_<%= child.short_name %>"><%= child.short_name %></a>
181
+ <% end %>
182
+ </td>
183
+ </tr>
184
+ <% end %>
185
+ <% if t[1].range.length > 0 %>
186
+ <tr><td class="label">Range</td>
187
+ <td>
188
+ <% t[1].range.each do |cls| %>
189
+ <% if cls.class.to_s == "String" %>
190
+ <a href="<%= cls %>"><%= cls %></a>
191
+ <% else %>
192
+ <a href="#class_<%= cls.short_name %>"><%= cls.short_name %></a>
193
+ <% end %>
194
+ <% end %>
195
+ </td>
196
+ </tr>
197
+ <% end %>
198
+ <% if t[1].domain.length > 0 %>
199
+ <tr><td class="label">Domain</td>
200
+ <td>
201
+ <% t[1].domain.each do |cls| %>
202
+ <% if cls.class.to_s == "String" %>
203
+ <a href="<%= cls %>"><%= cls %></a>
204
+ <% else %>
205
+ <a href="#class_<%= cls.short_name %>"><%= cls.short_name %></a>
206
+ <% end %>
207
+ <% end %>
208
+ </td>
209
+ </tr>
210
+ <% end %>
211
+ </table>
212
+ <p><%= t[1].comment %> </p>
213
+ <% if t[1].see_alsos.length > 0 %>
214
+ <p><em>Further Reading:</em></p>
215
+ <ul>
216
+ <% t[1].see_alsos.each do |link| %>
217
+ <li><a href="<%= link %>"><%= link %></a></li>
218
+ <% end %>
219
+ </ul>
220
+ <% end %>
221
+ </div>
222
+ <%end%>
223
+
224
+ </div>
225
+ </body>
226
+ </html>
@@ -0,0 +1,27 @@
1
+ module DOWL
2
+
3
+ class Generator
4
+
5
+ def initialize(schema, template=Generator.default_template())
6
+ @template = ERB.new(File.read(template))
7
+ @schema = schema
8
+ if schema.introduction
9
+ @introduction = File.read(schema.introduction)
10
+ end
11
+ end
12
+
13
+ def Generator.default_template()
14
+ dir = File.dirname( __FILE__ )
15
+ return default_template_file = File.join(dir, "default.erb")
16
+ end
17
+
18
+ def run()
19
+ b = binding
20
+ schema = @schema
21
+ introduction = @introduction
22
+ return @template.result(b)
23
+ end
24
+
25
+ end
26
+
27
+ end
@@ -0,0 +1,64 @@
1
+ require 'dowl'
2
+
3
+ module DOWL
4
+
5
+ class Person < DOWL::DocObject
6
+ def initialize(resource, schema)
7
+ super(resource, schema)
8
+ end
9
+
10
+ def uri()
11
+ return @resource.to_s
12
+ end
13
+
14
+ def name()
15
+ name = get_literal(DOWL::Namespaces::FOAF.name)
16
+ if name == nil
17
+ name = uri()
18
+ end
19
+ return name
20
+ end
21
+
22
+ def <=>(other)
23
+ return name() <=> other.name()
24
+ end
25
+
26
+ end
27
+
28
+ class Ontology < DOWL::DocObject
29
+
30
+ def initialize(resource, schema)
31
+ super(resource, schema)
32
+ end
33
+
34
+ def uri()
35
+ return @resource.to_s
36
+ end
37
+
38
+ def title()
39
+ return get_literal(DOWL::Namespaces::DCTERMS.title)
40
+ end
41
+
42
+ def comment()
43
+ return get_literal(DOWL::Namespaces::RDFS.comment)
44
+ end
45
+
46
+ def created()
47
+ return get_literal(DOWL::Namespaces::DCTERMS.created)
48
+ end
49
+
50
+ def modified()
51
+ return get_literal(DOWL::Namespaces::DCTERMS.modified)
52
+ end
53
+
54
+ def authors()
55
+ authors = []
56
+ @schema.model.query(
57
+ RDF::Query::Pattern.new( @resource, DOWL::Namespaces::FOAF.maker ) ) do |statement|
58
+ authors << Person.new( statement.object, @schema )
59
+ end
60
+ return authors.sort
61
+ end
62
+
63
+ end
64
+ end
@@ -0,0 +1,81 @@
1
+ require 'dowl'
2
+
3
+ module DOWL
4
+
5
+ class Property < DOWL::LabelledDocObject
6
+
7
+ def initialize(resource, schema)
8
+ super(resource, schema)
9
+ end
10
+
11
+ def see_alsos()
12
+ links = []
13
+ @schema.model.query(
14
+ RDF::Query::Pattern.new( @resource, DOWL::Namespaces::RDFS.seeAlso ) ) do |statement|
15
+ links << statement.object.to_s
16
+ end
17
+ return links
18
+ end
19
+
20
+ def sub_property_of()
21
+ parent = @schema.model.first_value(
22
+ RDF::Query::Pattern.new( @resource, DOWL::Namespaces::RDFS.subPropertyOf) )
23
+ if parent
24
+ uri = parent.to_s
25
+ if @schema.properties[uri]
26
+ return @schema.properties[uri]
27
+ else
28
+ return uri
29
+ end
30
+ end
31
+ return nil
32
+ end
33
+
34
+ def range()
35
+ ranges = []
36
+ @schema.model.query(RDF::Query::Pattern.new( @resource, DOWL::Namespaces::RDFS.range ) ) do |statement|
37
+ ranges << statement.object
38
+ end
39
+ classes = []
40
+ ranges.each do |o|
41
+ if o.resource?
42
+ uri = o.to_s
43
+ if @schema.classes[uri]
44
+ classes << @schema.classes[uri]
45
+ else
46
+ classes << uri
47
+ end
48
+ end
49
+ end
50
+ return classes
51
+ end
52
+
53
+ def domain()
54
+ domains = []
55
+ @schema.model.query(RDF::Query::Pattern.new( @resource, DOWL::Namespaces::RDFS.domain ) ) do |statement|
56
+ domains << statement.object
57
+ end
58
+ classes = []
59
+ domains.each do |o|
60
+ if o.resource?
61
+ uri = o.to_s
62
+ if @schema.classes[uri]
63
+ classes << @schema.classes[uri]
64
+ else
65
+ classes << uri
66
+ end
67
+ end
68
+ #TODO union
69
+ end
70
+ return classes
71
+ end
72
+
73
+ def sub_properties()
74
+ list = []
75
+ @schema.model.query(RDF::Query::Pattern.new( nil, DOWL::Namespaces::RDFS.subPropertyOf, @resource ) ) do |statement|
76
+ list << DOWL::Property.new( statement.subject, @schema )
77
+ end
78
+ return list
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,90 @@
1
+ module DOWL
2
+
3
+ #Utility class providing access to information about the schema, e.g. its description, lists of classes, etc
4
+ class Schema
5
+
6
+ attr_reader :model
7
+ attr_reader :introduction
8
+ attr_reader :datatype_properties
9
+ attr_reader :object_properties
10
+ attr_reader :classes
11
+
12
+ def initialize(model, introduction=nil)
13
+ @model = model
14
+ @introduction = introduction
15
+ init()
16
+ end
17
+
18
+ def Schema.create_from_file(file=nil)
19
+ if file == nil
20
+ raise "Filename should be provided"
21
+ end
22
+ model = RDF::Graph.new(file)
23
+ model.load!
24
+
25
+ dir = File.dirname(file)
26
+ introduction = File.join(dir, "introduction.html")
27
+ if File.exists?(introduction)
28
+ return Schema.new(model, introduction)
29
+ end
30
+ return Schema.new(model)
31
+ end
32
+
33
+ def init()
34
+ @classes = Hash.new
35
+ init_classes( DOWL::Namespaces::OWL.Class )
36
+ init_classes( DOWL::Namespaces::RDFS.Class )
37
+ ontology = @model.first_subject( RDF::Query::Pattern.new( nil, RDF.type, DOWL::Namespaces::OWL.Ontology ) )
38
+ if ontology
39
+ @ontology = Ontology.new(ontology, self)
40
+ end
41
+ @datatype_properties = init_properties( DOWL::Namespaces::OWL.DatatypeProperty)
42
+ @object_properties = init_properties( DOWL::Namespaces::OWL.ObjectProperty)
43
+ end
44
+
45
+ def ontology()
46
+ return @ontology
47
+ end
48
+
49
+ def init_classes(type)
50
+ @model.query( RDF::Query::Pattern.new( nil, RDF.type, type ) ) do |statement|
51
+ if !statement.subject.anonymous?
52
+ cls = DOWL::Class.new(statement.subject, self)
53
+ @classes[ statement.subject.to_s ] = cls
54
+ end
55
+ end
56
+ end
57
+
58
+ def init_properties(type)
59
+ properties = Hash.new
60
+ @model.query( RDF::Query::Pattern.new( nil, RDF.type, type ) ) do |statement|
61
+ properties[ statement.subject.to_s] = DOWL::Property.new(statement.subject, self)
62
+ end
63
+ return properties
64
+ end
65
+
66
+ def properties()
67
+ return @datatype_properties.merge( @object_properties )
68
+ end
69
+
70
+ def list_properties()
71
+ return properties().sort { |x,y| x[1] <=> y[1] }
72
+ end
73
+
74
+ def list_datatype_properties()
75
+ return datatype_properties().sort { |x,y| x[1] <=> y[1] }
76
+ end
77
+
78
+ def list_object_properties()
79
+ return object_properties().sort { |x,y| x[1] <=> y[1] }
80
+ end
81
+
82
+ #Return sorted, nested array
83
+ def list_classes()
84
+ sorted = classes().sort { |x,y| x[1] <=> y[1] }
85
+ return sorted
86
+ end
87
+
88
+ end
89
+
90
+ end
@@ -0,0 +1,47 @@
1
+ module DOWL
2
+
3
+ class DocObject
4
+ attr_reader :resource
5
+ attr_reader :schema
6
+ def initialize(resource, schema)
7
+ @resource = resource
8
+ @schema = schema
9
+ end
10
+
11
+ def get_literal(property)
12
+ return @schema.model.first_value(RDF::Query::Pattern.new( @resource, property ) )
13
+ end
14
+
15
+ end
16
+
17
+ class LabelledDocObject < DOWL::DocObject
18
+
19
+ def initialize(resource, schema)
20
+ super(resource, schema)
21
+ end
22
+
23
+ def short_name()
24
+ uri = @resource.to_s
25
+ ontology_uri = @schema.ontology.uri
26
+ return uri.gsub(ontology_uri, "")
27
+ end
28
+
29
+ def label()
30
+ return get_literal(DOWL::Namespaces::RDFS.label)
31
+ end
32
+
33
+ def comment()
34
+ return get_literal(DOWL::Namespaces::RDFS.comment)
35
+ end
36
+
37
+ def status()
38
+ return get_literal(DOWL::Namespaces::VS.status)
39
+ end
40
+
41
+ def <=>(other)
42
+ return label().downcase <=> other.label().downcase
43
+ end
44
+
45
+ end
46
+
47
+ end
@@ -0,0 +1,41 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
+ require 'dowl'
3
+ require 'test/unit'
4
+
5
+ class OntologyTest < Test::Unit::TestCase
6
+
7
+ def setup
8
+ file = "examples/example.ttl"
9
+ @schema = DOWL::Schema.create_from_file(File.expand_path(file))
10
+ end
11
+
12
+ def test_get_title
13
+ assert_equal( "An Example", @schema.ontology.title )
14
+ end
15
+
16
+ def test_get_comment
17
+ assert_equal( "This is a simple example", @schema.ontology.comment )
18
+ end
19
+
20
+ def test_get_created
21
+ assert_equal( "2010-02-19", @schema.ontology.created )
22
+ end
23
+
24
+ def test_get_created
25
+ assert_equal( "2010-09-28", @schema.ontology.modified )
26
+ end
27
+
28
+ def test_get_authors
29
+ assert_equal( 2 , @schema.ontology.authors.length )
30
+ author = @schema.ontology.authors[0]
31
+ assert_equal( "http://www.ldodds.com#me", author.uri )
32
+ assert_equal( "Leigh Dodds", author.name )
33
+
34
+ author = @schema.ontology.authors[1]
35
+ assert_equal( "http://www.example.org/unknown", author.uri )
36
+ assert_equal( "http://www.example.org/unknown", author.name )
37
+
38
+ end
39
+
40
+
41
+ end
@@ -0,0 +1,40 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
+ require 'dowl'
3
+ require 'test/unit'
4
+
5
+ class SchemaTest < Test::Unit::TestCase
6
+
7
+ def test_cannot_create_from_nil_file
8
+ assert_raise RuntimeError do
9
+ DOWL::Schema.create_from_file(nil)
10
+ end
11
+ end
12
+
13
+ def test_create_from_file
14
+ file = "examples/example.ttl"
15
+ DOWL::Schema.create_from_file(File.expand_path(file))
16
+ end
17
+
18
+ def test_read_classes_from_sample()
19
+ file = "examples/example.ttl"
20
+ schema = DOWL::Schema.create_from_file(File.expand_path(file))
21
+ classes = schema.classes()
22
+ assert_not_nil classes
23
+ assert_equal(2, classes.length)
24
+ end
25
+
26
+ def test_identify_owl_classes()
27
+ model = RDF::Graph.new()
28
+ model << RDF::Statement.new( RDF::URI.new("http://www.example.com/"), RDF.type, DOWL::Namespaces::OWL.Class)
29
+ schema = DOWL::Schema.new(model)
30
+ assert_equal(1, schema.classes.length)
31
+ end
32
+
33
+ def test_identify_rdf_classes()
34
+ model = RDF::Graph.new()
35
+ model << RDF::Statement.new( RDF::URI.new("http://www.example.com/"), RDF.type, DOWL::Namespaces::RDFS.Class)
36
+ schema = DOWL::Schema.new(model)
37
+ assert_equal(1, schema.classes.length)
38
+ end
39
+
40
+ end
@@ -0,0 +1,5 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+ require 'test/unit'
3
+
4
+ require 'tc_schema.rb'
5
+ require 'tc_ontology.rb'
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dowl
3
+ version: !ruby/object:Gem::Version
4
+ hash: 15
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 2
9
+ version: "0.2"
10
+ platform: ruby
11
+ authors:
12
+ - Leigh Dodds
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-09-28 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: mocha
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 49
29
+ segments:
30
+ - 0
31
+ - 9
32
+ - 5
33
+ version: 0.9.5
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: rdf-raptor
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 15
45
+ segments:
46
+ - 0
47
+ - 4
48
+ - 0
49
+ version: 0.4.0
50
+ type: :runtime
51
+ version_requirements: *id002
52
+ description: dowl OWL/RDF doc generator
53
+ email: leigh.dodds@talis.com
54
+ executables:
55
+ - dowl
56
+ extensions: []
57
+
58
+ extra_rdoc_files:
59
+ - README
60
+ - CHANGES
61
+ files:
62
+ - README
63
+ - Rakefile
64
+ - CHANGES
65
+ - bin/dowl
66
+ - tests/ts_dowl.rb
67
+ - tests/tc_schema.rb
68
+ - tests/tc_ontology.rb
69
+ - examples/example.ttl
70
+ - examples/introduction.html
71
+ - lib/dowl.rb
72
+ - lib/dowl/property.rb
73
+ - lib/dowl/default.erb
74
+ - lib/dowl/util.rb
75
+ - lib/dowl/class.rb
76
+ - lib/dowl/schema.rb
77
+ - lib/dowl/ontology.rb
78
+ - lib/dowl/generator.rb
79
+ has_rdoc: true
80
+ homepage: http://github.com/ldodds/dowl
81
+ licenses: []
82
+
83
+ post_install_message:
84
+ rdoc_options:
85
+ - --quiet
86
+ - --title
87
+ - dowl Reference
88
+ - --main
89
+ - README
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ hash: 61
98
+ segments:
99
+ - 1
100
+ - 8
101
+ - 5
102
+ version: 1.8.5
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ hash: 3
109
+ segments:
110
+ - 0
111
+ version: "0"
112
+ requirements: []
113
+
114
+ rubyforge_project:
115
+ rubygems_version: 1.3.7
116
+ signing_key:
117
+ specification_version: 3
118
+ summary: dowl OWL/RDF doc generator
119
+ test_files:
120
+ - tests/ts_dowl.rb