yowl 0.4.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +15 -0
- data/INSTALL-MACOSX.md +107 -0
- data/README.md +92 -0
- data/Rakefile +76 -0
- data/bin/yowl +14 -0
- data/examples/introduction.html +5 -0
- data/lib/yowl/association.rb +66 -0
- data/lib/yowl/class.rb +296 -0
- data/lib/yowl/generator.rb +96 -0
- data/lib/yowl/import.rb +62 -0
- data/lib/yowl/individual.rb +398 -0
- data/lib/yowl/individual_association.rb +80 -0
- data/lib/yowl/ontology.rb +197 -0
- data/lib/yowl/options.rb +116 -0
- data/lib/yowl/optionsparser.rb +75 -0
- data/lib/yowl/person.rb +26 -0
- data/lib/yowl/property.rb +190 -0
- data/lib/yowl/repository.rb +100 -0
- data/lib/yowl/schema.rb +519 -0
- data/lib/yowl/template/css/jquery.ui.all.css +11 -0
- data/lib/yowl/template/css/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/lib/yowl/template/css/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/lib/yowl/template/css/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/lib/yowl/template/css/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/lib/yowl/template/css/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/lib/yowl/template/css/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/lib/yowl/template/css/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/lib/yowl/template/css/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/lib/yowl/template/css/smoothness/images/ui-icons_222222_256x240.png +0 -0
- data/lib/yowl/template/css/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
- data/lib/yowl/template/css/smoothness/images/ui-icons_454545_256x240.png +0 -0
- data/lib/yowl/template/css/smoothness/images/ui-icons_888888_256x240.png +0 -0
- data/lib/yowl/template/css/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/lib/yowl/template/css/smoothness/jquery-ui-1.8.23.custom.css +563 -0
- data/lib/yowl/template/css/yowl.css +414 -0
- data/lib/yowl/template/import-diagram.erb +29 -0
- data/lib/yowl/template/index.erb +56 -0
- data/lib/yowl/template/js/jquery-1.7.2.min.js +4 -0
- data/lib/yowl/template/js/jquery-ui-1.8.23.custom.min.js +125 -0
- data/lib/yowl/template/js/jquery.ui.accordion.js +611 -0
- data/lib/yowl/template/js/yowl.js +72 -0
- data/lib/yowl/template/ontology.erb +598 -0
- data/lib/yowl/template/themes/base/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/lib/yowl/template/themes/base/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/lib/yowl/template/themes/base/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/lib/yowl/template/themes/base/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/lib/yowl/template/themes/base/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/lib/yowl/template/themes/base/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/lib/yowl/template/themes/base/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/lib/yowl/template/themes/base/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/lib/yowl/template/themes/base/images/ui-icons_222222_256x240.png +0 -0
- data/lib/yowl/template/themes/base/images/ui-icons_2e83ff_256x240.png +0 -0
- data/lib/yowl/template/themes/base/images/ui-icons_454545_256x240.png +0 -0
- data/lib/yowl/template/themes/base/images/ui-icons_888888_256x240.png +0 -0
- data/lib/yowl/template/themes/base/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/lib/yowl/template/themes/base/jquery.ui.accordion.css +19 -0
- data/lib/yowl/template/themes/base/jquery.ui.all.css +11 -0
- data/lib/yowl/template/themes/base/jquery.ui.autocomplete.css +53 -0
- data/lib/yowl/template/themes/base/jquery.ui.base.css +11 -0
- data/lib/yowl/template/themes/base/jquery.ui.button.css +38 -0
- data/lib/yowl/template/themes/base/jquery.ui.core.css +38 -0
- data/lib/yowl/template/themes/base/jquery.ui.datepicker.css +66 -0
- data/lib/yowl/template/themes/base/jquery.ui.dialog.css +21 -0
- data/lib/yowl/template/themes/base/jquery.ui.progressbar.css +11 -0
- data/lib/yowl/template/themes/base/jquery.ui.resizable.css +20 -0
- data/lib/yowl/template/themes/base/jquery.ui.selectable.css +10 -0
- data/lib/yowl/template/themes/base/jquery.ui.slider.css +24 -0
- data/lib/yowl/template/themes/base/jquery.ui.tabs.css +18 -0
- data/lib/yowl/template/themes/base/jquery.ui.theme.css +247 -0
- data/lib/yowl/template/themes/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/lib/yowl/template/themes/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/lib/yowl/template/themes/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/lib/yowl/template/themes/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/lib/yowl/template/themes/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/lib/yowl/template/themes/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/lib/yowl/template/themes/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/lib/yowl/template/themes/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/lib/yowl/template/themes/smoothness/images/ui-icons_222222_256x240.png +0 -0
- data/lib/yowl/template/themes/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
- data/lib/yowl/template/themes/smoothness/images/ui-icons_454545_256x240.png +0 -0
- data/lib/yowl/template/themes/smoothness/images/ui-icons_888888_256x240.png +0 -0
- data/lib/yowl/template/themes/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/lib/yowl/template/themes/smoothness/jquery-ui-1.8.23.custom.css +563 -0
- data/lib/yowl/template/themes/smoothness/jquery.ui.accordion.css +19 -0
- data/lib/yowl/template/themes/smoothness/jquery.ui.all.css +11 -0
- data/lib/yowl/template/themes/smoothness/jquery.ui.autocomplete.css +53 -0
- data/lib/yowl/template/themes/smoothness/jquery.ui.base.css +11 -0
- data/lib/yowl/template/themes/smoothness/jquery.ui.button.css +38 -0
- data/lib/yowl/template/themes/smoothness/jquery.ui.core.css +38 -0
- data/lib/yowl/template/themes/smoothness/jquery.ui.datepicker.css +66 -0
- data/lib/yowl/template/themes/smoothness/jquery.ui.dialog.css +21 -0
- data/lib/yowl/template/themes/smoothness/jquery.ui.progressbar.css +11 -0
- data/lib/yowl/template/themes/smoothness/jquery.ui.resizable.css +20 -0
- data/lib/yowl/template/themes/smoothness/jquery.ui.selectable.css +10 -0
- data/lib/yowl/template/themes/smoothness/jquery.ui.slider.css +24 -0
- data/lib/yowl/template/themes/smoothness/jquery.ui.tabs.css +18 -0
- data/lib/yowl/template/themes/smoothness/jquery.ui.theme.css +249 -0
- data/lib/yowl/util.rb +221 -0
- data/lib/yowl/version.rb +3 -0
- data/lib/yowl.rb +42 -0
- data/test/input/base-with-comments.ttl +163 -0
- data/test/input/base.ttl +221 -0
- data/test/input/empty.ttl +8 -0
- data/test/input/example.ttl +73 -0
- data/test/test_example_ttl.rb +62 -0
- data/test/test_yowl.rb +4 -0
- data/test/testcases.md +24 -0
- metadata +311 -0
@@ -0,0 +1,197 @@
|
|
1
|
+
module YOWL
|
2
|
+
|
3
|
+
class Ontology < YOWL::LabelledDocObject
|
4
|
+
|
5
|
+
def initialize(resource, schema)
|
6
|
+
super(resource, schema)
|
7
|
+
end
|
8
|
+
|
9
|
+
def resourceNameHtml
|
10
|
+
return "#{@schema.name}.html"
|
11
|
+
end
|
12
|
+
|
13
|
+
def title()
|
14
|
+
dctermsTitle = get_literal(YOWL::Namespaces::DCTERMS.title)
|
15
|
+
if dctermsTitle
|
16
|
+
return dctermsTitle
|
17
|
+
end
|
18
|
+
dcTitle = get_literal(YOWL::Namespaces::DC.title)
|
19
|
+
if dcTitle
|
20
|
+
return dcTitle
|
21
|
+
end
|
22
|
+
return short_name() # We have to have a title
|
23
|
+
end
|
24
|
+
|
25
|
+
def ns()
|
26
|
+
@ns ||= init_ns()
|
27
|
+
return @ns
|
28
|
+
end
|
29
|
+
|
30
|
+
def init_ns()
|
31
|
+
_uri = @resource.to_s
|
32
|
+
@schema.prefixes.each do |prefix, namespace|
|
33
|
+
if _uri == namespace
|
34
|
+
return namespace
|
35
|
+
end
|
36
|
+
_tmp = "#{_uri}/"
|
37
|
+
if _tmp == namespace
|
38
|
+
return _tmp
|
39
|
+
end
|
40
|
+
_tmp = "#{_uri}#"
|
41
|
+
if "#{_uri}#" == namespace
|
42
|
+
return _tmp
|
43
|
+
end
|
44
|
+
end
|
45
|
+
if _uri[-1..1] == '/' or _uri[-1..1] == '#'
|
46
|
+
return _uri
|
47
|
+
end
|
48
|
+
#
|
49
|
+
# Basically make up a namespace... Don't know if this is such a good plan..
|
50
|
+
#
|
51
|
+
return "#{_uri}#"
|
52
|
+
end
|
53
|
+
|
54
|
+
def short_name()
|
55
|
+
return @schema.name
|
56
|
+
end
|
57
|
+
|
58
|
+
def comment()
|
59
|
+
dctermsAbstract = get_literal(YOWL::Namespaces::DCTERMS.abstract)
|
60
|
+
if dctermsAbstract
|
61
|
+
return dctermsAbstract
|
62
|
+
end
|
63
|
+
return super
|
64
|
+
end
|
65
|
+
|
66
|
+
def definition()
|
67
|
+
return get_literal(YOWL::Namespaces::SKOS.definition)
|
68
|
+
end
|
69
|
+
|
70
|
+
def created()
|
71
|
+
dctermsCreated = get_literal(YOWL::Namespaces::DCTERMS.created)
|
72
|
+
if dctermsCreated
|
73
|
+
return dctermsCreated
|
74
|
+
end
|
75
|
+
return get_literal(YOWL::Namespaces::DC.date)
|
76
|
+
end
|
77
|
+
|
78
|
+
def modified()
|
79
|
+
return get_literal(YOWL::Namespaces::DCTERMS.modified)
|
80
|
+
end
|
81
|
+
|
82
|
+
def rights()
|
83
|
+
return get_literal(YOWL::Namespaces::DC.rights)
|
84
|
+
end
|
85
|
+
|
86
|
+
public
|
87
|
+
def authors
|
88
|
+
@authors ||= init_authors
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
def init_authors()
|
93
|
+
authors = []
|
94
|
+
#
|
95
|
+
# First find the Authors by searching for foaf:maker
|
96
|
+
#
|
97
|
+
@schema.model.query(
|
98
|
+
RDF::Query::Pattern.new(@resource, YOWL::Namespaces::FOAF.maker)
|
99
|
+
) do |statement|
|
100
|
+
uri = statement.object
|
101
|
+
if (uri and uri.uri?)
|
102
|
+
authors << Person.new(uri, @schema)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
#
|
106
|
+
# Also scan for dc:creator and dc:contributor
|
107
|
+
#
|
108
|
+
@schema.model.query(
|
109
|
+
RDF::Query::Pattern.new(@resource, YOWL::Namespaces::DC.creator)
|
110
|
+
) do |statement|
|
111
|
+
person = Person.new(RDF::URI.new("#{ns}#{statement.object.to_s}"), @schema)
|
112
|
+
person.setName(statement.object)
|
113
|
+
authors << person
|
114
|
+
end
|
115
|
+
@schema.model.query(
|
116
|
+
RDF::Query::Pattern.new(@resource, YOWL::Namespaces::DC.contributor)
|
117
|
+
) do |statement|
|
118
|
+
person = Person.new(RDF::URI.new("#{ns}#{statement.object.to_s}"), @schema)
|
119
|
+
person.setName(statement.object)
|
120
|
+
authors << person
|
121
|
+
end
|
122
|
+
return authors
|
123
|
+
end
|
124
|
+
|
125
|
+
public
|
126
|
+
def hasAuthors?
|
127
|
+
return ! authors.empty?
|
128
|
+
end
|
129
|
+
|
130
|
+
def numberOfClasses()
|
131
|
+
return @schema.classes.size()
|
132
|
+
end
|
133
|
+
|
134
|
+
def numberOfProperties()
|
135
|
+
return @schema.properties.size()
|
136
|
+
end
|
137
|
+
|
138
|
+
def numberOfIndividuals()
|
139
|
+
return @schema.individuals.size()
|
140
|
+
end
|
141
|
+
|
142
|
+
public
|
143
|
+
def imports
|
144
|
+
@imports ||= init_imports
|
145
|
+
end
|
146
|
+
|
147
|
+
private
|
148
|
+
def init_imports
|
149
|
+
imports = {}
|
150
|
+
@schema.model.query(
|
151
|
+
RDF::Query::Pattern.new(@resource, YOWL::Namespaces::OWL.imports)
|
152
|
+
) do |statement|
|
153
|
+
importUri = statement.object.to_s
|
154
|
+
if importUri != uri
|
155
|
+
imports[importUri] = Import.new(statement.object, @schema)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
return imports.values
|
159
|
+
end
|
160
|
+
|
161
|
+
public
|
162
|
+
def see_alsos
|
163
|
+
@see_alsos ||= init_see_alsos
|
164
|
+
end
|
165
|
+
|
166
|
+
private
|
167
|
+
def init_see_alsos()
|
168
|
+
links = []
|
169
|
+
@schema.model.query(
|
170
|
+
RDF::Query::Pattern.new(@resource, YOWL::Namespaces::RDFS.seeAlso)
|
171
|
+
) do |statement|
|
172
|
+
links << statement.object.to_s
|
173
|
+
end
|
174
|
+
return links
|
175
|
+
end
|
176
|
+
|
177
|
+
public
|
178
|
+
#
|
179
|
+
# See YOWL::Individual::classWithURI(uri)
|
180
|
+
#
|
181
|
+
def classWithURI(uri_)
|
182
|
+
klass = @schema.classInSchemaWithURI(uri_)
|
183
|
+
if klass
|
184
|
+
return klass
|
185
|
+
end
|
186
|
+
imports.each do |import|
|
187
|
+
klass = import.classWithURI(uri_)
|
188
|
+
if klass
|
189
|
+
return klass
|
190
|
+
end
|
191
|
+
end
|
192
|
+
return nil
|
193
|
+
end
|
194
|
+
|
195
|
+
end
|
196
|
+
|
197
|
+
end
|
data/lib/yowl/options.rb
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
module YOWL
|
2
|
+
#
|
3
|
+
# Utility class representing all specified command line options
|
4
|
+
#
|
5
|
+
class Options
|
6
|
+
|
7
|
+
attr_accessor :ontology_file_names
|
8
|
+
attr_accessor :output_dir
|
9
|
+
attr_accessor :template_dirs
|
10
|
+
attr_accessor :noVann
|
11
|
+
|
12
|
+
attr_reader :templates
|
13
|
+
|
14
|
+
attr_accessor :verbose
|
15
|
+
attr_accessor :quiet
|
16
|
+
|
17
|
+
|
18
|
+
def initialize()
|
19
|
+
@verbose = false
|
20
|
+
@quiet = false
|
21
|
+
@ontology_file_names = []
|
22
|
+
@output_dir = Dir.pwd()
|
23
|
+
@template_dirs = []
|
24
|
+
@templates = Hash.new
|
25
|
+
@noVann = false
|
26
|
+
end
|
27
|
+
|
28
|
+
def validate()
|
29
|
+
if not @quiet
|
30
|
+
puts "Output will be generated in this directory: #{output_dir.to_s}"
|
31
|
+
end
|
32
|
+
if ! validate_ontology_file_names()
|
33
|
+
return false
|
34
|
+
end
|
35
|
+
if ! validate_template_dirs()
|
36
|
+
return false
|
37
|
+
end
|
38
|
+
if ! validate_templates()
|
39
|
+
return false
|
40
|
+
end
|
41
|
+
return true
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
def validate_ontology_file_names
|
46
|
+
if @ontology_file_names.empty?
|
47
|
+
return false
|
48
|
+
end
|
49
|
+
@ontology_file_names.each() do |filename|
|
50
|
+
if ! File.exists?(filename)
|
51
|
+
warn "File does not exist: " + filename
|
52
|
+
return false
|
53
|
+
end
|
54
|
+
if not @quiet
|
55
|
+
puts "Will process input file: #{filename}"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
return true
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
def validate_template_dirs
|
63
|
+
@template_dirs << File.join(ontology_dir(), "yowl/template")
|
64
|
+
@template_dirs << File.join(File.dirname(__FILE__), "template")
|
65
|
+
@template_dirs = @template_dirs.find_all do |dir|
|
66
|
+
Dir[dir]
|
67
|
+
end
|
68
|
+
return ! @template_dirs.empty?()
|
69
|
+
end
|
70
|
+
|
71
|
+
#
|
72
|
+
# TODO: Either we support one template per ontology or
|
73
|
+
# we support one template per input directory. That would
|
74
|
+
# then be the only way to specify input ontologies: by directory.
|
75
|
+
#
|
76
|
+
private
|
77
|
+
def ontology_dir()
|
78
|
+
return File.dirname(@ontology_file_names[0])
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
def load_template(templateName_, required_ = true)
|
83
|
+
@template_dirs.each do |template_dir|
|
84
|
+
templateFileName = File.join(template_dir, "#{templateName_}.erb")
|
85
|
+
if verbose()
|
86
|
+
puts "Checking template #{templateFileName}"
|
87
|
+
end
|
88
|
+
if File.exists?(templateFileName)
|
89
|
+
File.open(templateFileName) do |file|
|
90
|
+
@templates[templateName_] = ERB.new(file.read)
|
91
|
+
end
|
92
|
+
if verbose()
|
93
|
+
puts "Loaded template #{templateFileName}"
|
94
|
+
end
|
95
|
+
return
|
96
|
+
end
|
97
|
+
end
|
98
|
+
if required_
|
99
|
+
raise "ERROR: #{templateName_} could not be found"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
private
|
104
|
+
def validate_templates()
|
105
|
+
|
106
|
+
load_template('index');
|
107
|
+
#load_template('overview');
|
108
|
+
load_template('introduction', false);
|
109
|
+
load_template('import-diagram');
|
110
|
+
load_template('ontology');
|
111
|
+
|
112
|
+
return true
|
113
|
+
end
|
114
|
+
|
115
|
+
end # End of class Options
|
116
|
+
end # End of module YOWL
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module YOWL
|
2
|
+
|
3
|
+
class OptionsParser
|
4
|
+
|
5
|
+
def self.parse(args_)
|
6
|
+
|
7
|
+
options = Options.new
|
8
|
+
|
9
|
+
opts = OptionParser.new do |opts|
|
10
|
+
#
|
11
|
+
# Set a banner, displayed at the top of the help screen.
|
12
|
+
#
|
13
|
+
opts.banner = "Usage: YOWL [<options>]"
|
14
|
+
|
15
|
+
opts.separator ""
|
16
|
+
opts.separator "Specific options:"
|
17
|
+
|
18
|
+
opts.on('-i', '--ontology FILES', String, 'Read input FILES') do |ontology|
|
19
|
+
options.ontology_file_names << ontology
|
20
|
+
if args_.size > 0
|
21
|
+
for index in 0..(args_.size - 1)
|
22
|
+
arg = args_[index]
|
23
|
+
if arg[0,1] == '-'
|
24
|
+
break
|
25
|
+
end
|
26
|
+
options.ontology_file_names << arg
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
opts.on('-o', '--output DIR', 'Write HTML output to DIR') do |dir|
|
32
|
+
options.output_dir = dir
|
33
|
+
end
|
34
|
+
|
35
|
+
opts.on('-t', '--template DIR', 'Use ERB templates in DIR') do |dir|
|
36
|
+
options.template_dir = dir
|
37
|
+
end
|
38
|
+
|
39
|
+
opts.on('--no-vann', 'Skip looking for vann:preferedNamespacePrefix') do |value|
|
40
|
+
options.noVann = true
|
41
|
+
end
|
42
|
+
|
43
|
+
opts.separator ""
|
44
|
+
opts.separator "Common options:"
|
45
|
+
|
46
|
+
opts.on_tail("-?", "-h", "--help", "Show this message") do
|
47
|
+
puts opts
|
48
|
+
return nil
|
49
|
+
end
|
50
|
+
|
51
|
+
opts.on_tail("-V", "--version", "Show version") do
|
52
|
+
puts OptionParser::Version.join('.')
|
53
|
+
exit
|
54
|
+
end
|
55
|
+
|
56
|
+
opts.on_tail("-v", "--verbose", "Show verbose logging") do
|
57
|
+
options.verbose = true
|
58
|
+
end
|
59
|
+
|
60
|
+
opts.on_tail("-q", "--quiet", "Suppress most logging") do
|
61
|
+
options.quiet = true
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
opts.parse!(args_)
|
67
|
+
|
68
|
+
if ! options.validate()
|
69
|
+
puts opts
|
70
|
+
return nil
|
71
|
+
end
|
72
|
+
return options
|
73
|
+
end # parse()
|
74
|
+
end # class OptionParser
|
75
|
+
end
|
data/lib/yowl/person.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module YOWL
|
2
|
+
|
3
|
+
class Person < YOWL::LabelledDocObject
|
4
|
+
|
5
|
+
def initialize(resource, schema)
|
6
|
+
super(resource, schema)
|
7
|
+
@name = nil
|
8
|
+
end
|
9
|
+
|
10
|
+
def setName(name_)
|
11
|
+
@name = name_
|
12
|
+
end
|
13
|
+
|
14
|
+
def name()
|
15
|
+
name = get_literal(YOWL::Namespaces::FOAF.name)
|
16
|
+
if name.nil? or name.empty?
|
17
|
+
name = short_name()
|
18
|
+
end
|
19
|
+
return name
|
20
|
+
end
|
21
|
+
|
22
|
+
def <=>(other)
|
23
|
+
return name() <=> other.name()
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,190 @@
|
|
1
|
+
require 'yowl'
|
2
|
+
|
3
|
+
module YOWL
|
4
|
+
|
5
|
+
class Property < YOWL::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, YOWL::Namespaces::RDFS.seeAlso)
|
15
|
+
) do |statement|
|
16
|
+
links << statement.object.to_s
|
17
|
+
end
|
18
|
+
return links
|
19
|
+
end
|
20
|
+
|
21
|
+
def sub_property_of()
|
22
|
+
parent = @schema.model.first_value(
|
23
|
+
RDF::Query::Pattern.new(@resource, YOWL::Namespaces::RDFS.subPropertyOf)
|
24
|
+
)
|
25
|
+
if parent
|
26
|
+
uri = parent.to_s
|
27
|
+
if @schema.properties[uri]
|
28
|
+
return @schema.properties[uri]
|
29
|
+
else
|
30
|
+
return uri
|
31
|
+
end
|
32
|
+
end
|
33
|
+
return nil
|
34
|
+
end
|
35
|
+
|
36
|
+
def range()
|
37
|
+
ranges = []
|
38
|
+
@schema.model.query(
|
39
|
+
RDF::Query::Pattern.new(@resource, YOWL::Namespaces::RDFS.range)
|
40
|
+
) do |statement|
|
41
|
+
ranges << statement.object
|
42
|
+
end
|
43
|
+
classes = []
|
44
|
+
ranges.each do |o|
|
45
|
+
if o.resource?
|
46
|
+
uri = o.to_s
|
47
|
+
if @schema.classes[uri]
|
48
|
+
classes << @schema.classes[uri]
|
49
|
+
else
|
50
|
+
classes << uri
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
return classes
|
55
|
+
end
|
56
|
+
|
57
|
+
def domain()
|
58
|
+
domains = []
|
59
|
+
@schema.model.query(
|
60
|
+
RDF::Query::Pattern.new(@resource, YOWL::Namespaces::RDFS.domain)
|
61
|
+
) do |statement|
|
62
|
+
domains << statement.object
|
63
|
+
end
|
64
|
+
classes = []
|
65
|
+
domains.each do |o|
|
66
|
+
if o.resource?
|
67
|
+
uri = o.to_s
|
68
|
+
if @schema.classes[uri]
|
69
|
+
classes << @schema.classes[uri]
|
70
|
+
else
|
71
|
+
classes << uri
|
72
|
+
end
|
73
|
+
end
|
74
|
+
#TODO union
|
75
|
+
end
|
76
|
+
return classes
|
77
|
+
end
|
78
|
+
|
79
|
+
def sub_properties()
|
80
|
+
list = []
|
81
|
+
@schema.model.query(
|
82
|
+
RDF::Query::Pattern.new(nil, YOWL::Namespaces::RDFS.subPropertyOf, @resource)
|
83
|
+
) do |statement|
|
84
|
+
list << YOWL::Property.new(statement.subject, @schema)
|
85
|
+
end
|
86
|
+
return list
|
87
|
+
end
|
88
|
+
|
89
|
+
public
|
90
|
+
#
|
91
|
+
# Add the current class as a GraphViz node to the given collection of nodes
|
92
|
+
# and to the given graph. Return the collection of nodes.
|
93
|
+
#
|
94
|
+
def addAsGraphvizNode (graph_, nodes_, edges_)
|
95
|
+
name = short_name
|
96
|
+
if @schema.options.verbose
|
97
|
+
puts "- Processing property #{name}"
|
98
|
+
end
|
99
|
+
#
|
100
|
+
# No need to add a node twice
|
101
|
+
#
|
102
|
+
if nodes_.has_key? uri
|
103
|
+
return nodes_, edges_
|
104
|
+
end
|
105
|
+
node = graph_.add_nodes(escaped_uri)
|
106
|
+
node.URL = "#prop_#{short_name}"
|
107
|
+
|
108
|
+
if name.include?(':')
|
109
|
+
prefix = name.sub(/:\s*(.*)/, "")
|
110
|
+
name = name.sub(/(.*)\s*:/, "")
|
111
|
+
#
|
112
|
+
# Can't get HTML labels to work
|
113
|
+
#
|
114
|
+
#node.label = "<TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\"><TR><TD>#{name}</TD></TR><TR><TD><I>(#{prefix})</I></TD></TR></TABLE>"
|
115
|
+
node.label = "#{name}\n(#{prefix})"
|
116
|
+
else
|
117
|
+
node.label = name
|
118
|
+
end
|
119
|
+
if hasComment?
|
120
|
+
node.tooltip = comment
|
121
|
+
end
|
122
|
+
nodes_[uri] = node
|
123
|
+
return nodes_, edges_
|
124
|
+
end
|
125
|
+
|
126
|
+
public
|
127
|
+
#
|
128
|
+
# Generate a diagram for each Property, the "per property diagram"
|
129
|
+
#
|
130
|
+
def perPropertyDiagramAsSvg
|
131
|
+
#if @schema.options.verbose
|
132
|
+
# puts "Generating SVG Per Property Diagram for #{short_name}"
|
133
|
+
#end
|
134
|
+
|
135
|
+
g = GraphvizUtility.setDefaults(GraphViz.new(:G, :type => :digraph))
|
136
|
+
g[:rankdir] = "LR"
|
137
|
+
g.node[:fixedsize] = false
|
138
|
+
|
139
|
+
nodes = Hash.new
|
140
|
+
edges = Hash.new
|
141
|
+
nodes, edges = addAsGraphvizNode(g, nodes, edges)
|
142
|
+
|
143
|
+
#
|
144
|
+
# Do the "outbound" associations first
|
145
|
+
#
|
146
|
+
#associations.each do |association|
|
147
|
+
# nodes, edges = association.rangeClass.addAsGraphvizNode(g, nodes, edges)
|
148
|
+
# nodes, edges = association.addAsGraphVizEdge(g, nodes, edges)
|
149
|
+
#end
|
150
|
+
|
151
|
+
#
|
152
|
+
# Then do the "inbound" associations
|
153
|
+
#
|
154
|
+
#@schema.classes.values.to_set.each do |klass|
|
155
|
+
# klass.associations.each do |association|
|
156
|
+
# if self == association.rangeClass
|
157
|
+
# nodes, edges = association.rangeClass.addAsGraphvizNode(g, nodes, edges)
|
158
|
+
# nodes, edges = association.addAsGraphVizEdge(g, nodes, edges)
|
159
|
+
# end
|
160
|
+
# end
|
161
|
+
#end
|
162
|
+
|
163
|
+
return GraphvizUtility.embeddableSvg(g)
|
164
|
+
end
|
165
|
+
|
166
|
+
#
|
167
|
+
# Create the GraphVis Edge for all "is a" (rdf:type) associations from a node
|
168
|
+
# (representing a Class) to another node (always representing a Property)
|
169
|
+
#
|
170
|
+
def Property.newGraphVizEdge(graph_, domainNode_, rangeNode_, constraint_ = true)
|
171
|
+
options = {
|
172
|
+
:arrowhead => "empty",
|
173
|
+
:dir => "back",
|
174
|
+
:label => "is a",
|
175
|
+
:arrowsize => 0.5,
|
176
|
+
:penwidth => 0.5,
|
177
|
+
:constraint => constraint_
|
178
|
+
}
|
179
|
+
if not constraint_
|
180
|
+
options[:style] = :dashed
|
181
|
+
end
|
182
|
+
return graph_.add_edges(
|
183
|
+
rangeNode_,
|
184
|
+
domainNode_,
|
185
|
+
options
|
186
|
+
)
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
190
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
module YOWL
|
2
|
+
|
3
|
+
class Repository
|
4
|
+
|
5
|
+
attr_reader :schemas
|
6
|
+
attr_reader :options
|
7
|
+
|
8
|
+
def initialize(options)
|
9
|
+
@options = options
|
10
|
+
|
11
|
+
init_schemas()
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
def init_schemas()
|
16
|
+
@schemas = {}
|
17
|
+
|
18
|
+
@options.ontology_file_names.each() do | ontology_file_name |
|
19
|
+
if options.verbose
|
20
|
+
puts "Parsing #{ontology_file_name}"
|
21
|
+
end
|
22
|
+
schema = Schema.fromFile(ontology_file_name, self)
|
23
|
+
if schema
|
24
|
+
@schemas[schema.uri] = schema
|
25
|
+
#puts "Registered schema with URI #{schema.uri}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
public
|
31
|
+
def ontologies()
|
32
|
+
ontologies = @schemas.values.collect() { |schema|
|
33
|
+
schema.ontology
|
34
|
+
}
|
35
|
+
return ontologies.sort { |x,y| x.short_name <=> y.short_name }
|
36
|
+
end
|
37
|
+
|
38
|
+
public
|
39
|
+
def getSchemaForImport(import_)
|
40
|
+
begin
|
41
|
+
return @schemas[import_.uri]
|
42
|
+
rescue => exception
|
43
|
+
puts exception.backtrace
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
public
|
48
|
+
def knowsImport(import_)
|
49
|
+
return ! getSchemaForImport(import_).nil?
|
50
|
+
end
|
51
|
+
|
52
|
+
public
|
53
|
+
def getSchemaNameForImport(import_)
|
54
|
+
schema = getSchemaForImport(import_)
|
55
|
+
return schema.nil? ? '' : schema.name
|
56
|
+
end
|
57
|
+
|
58
|
+
public
|
59
|
+
def ontologiesAsSvg
|
60
|
+
if @options.verbose
|
61
|
+
puts "Generating SVG for Ontology Import Diagram"
|
62
|
+
end
|
63
|
+
|
64
|
+
g = GraphvizUtility.setDefaults(GraphViz.new(:G, :type => :digraph))
|
65
|
+
|
66
|
+
nodes = {}
|
67
|
+
ontologies.each() do |ontology|
|
68
|
+
nodeID = ontology.escaped_uri
|
69
|
+
node = g.add_nodes(nodeID)
|
70
|
+
node.URL = ontology.resourceNameHtml
|
71
|
+
node.label = ontology.short_name
|
72
|
+
node.tooltip = ontology.commentOrLabel
|
73
|
+
nodes[nodeID] = node
|
74
|
+
end
|
75
|
+
|
76
|
+
ontologies.each() do |ontology|
|
77
|
+
if @options.verbose
|
78
|
+
puts "- Processing ontology #{ontology.escaped_uri}"
|
79
|
+
end
|
80
|
+
ontology.imports.each() do |import|
|
81
|
+
importNode = nodes[import.name]
|
82
|
+
if importNode
|
83
|
+
if @options.verbose
|
84
|
+
puts " - Processing import #{import.name}"
|
85
|
+
end
|
86
|
+
g.add_edges(nodes[ontology.short_name], importNode)
|
87
|
+
else
|
88
|
+
if @options.verbose
|
89
|
+
puts " - Processing import #{import.name}, not found"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
#puts g.to_dot()
|
96
|
+
return GraphvizUtility.embeddableSvg(g)
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
end
|