ontology-united 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +33 -0
- data/Rakefile +7 -0
- data/lib/ontology-united/convenience.rb +9 -0
- data/lib/ontology-united/dsl/base_dsl.rb +45 -0
- data/lib/ontology-united/dsl/ontology.rb +88 -0
- data/lib/ontology-united/dsl/ontology_class.rb +23 -0
- data/lib/ontology-united/dsl/ontology_dsl.rb +21 -0
- data/lib/ontology-united/dsl/ontology_entity_base.rb +52 -0
- data/lib/ontology-united/dsl/ontology_import.rb +20 -0
- data/lib/ontology-united/dsl/ontology_prefix.rb +37 -0
- data/lib/ontology-united/dsl/ontology_sentence.rb +18 -0
- data/lib/ontology-united/dsl.rb +19 -0
- data/lib/ontology-united/serializer/owl/manchester.rb +58 -0
- data/lib/ontology-united/serializer/owl.rb +9 -0
- data/lib/ontology-united/serializer/serializer_base.rb +47 -0
- data/lib/ontology-united/serializer.rb +8 -0
- data/lib/ontology-united/version.rb +3 -0
- data/lib/ontology-united.rb +8 -0
- data/ontology-united.gemspec +25 -0
- data/spec/ontology-united/ontology-united_spec.rb +33 -0
- data/spec/ontology-united/serializer/owl/manchester_spec.rb +60 -0
- data/spec/spec_helper.rb +2 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ef0bf5863b23a554f1dc5a86bd0be1d4307a1de3
|
4
|
+
data.tar.gz: 5220f4ed1b6c8515344fe4484eba00cdd525891b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b6a60f8c8ed792e131f0197af0220292a136db44e5d148e36f6caeb4445052f36f94d3f77b5bfd90c666cb545e909038fd1b45912e30775e6410a4448ce23866
|
7
|
+
data.tar.gz: ba969589d3eda647f2ecc4b48a2030072082183d75435203c8ee94d6c9f66c4f40c57ecdded28fd8cfd07f1dd5e8799f3088519b67c31f673a1de8e81f8a9d83
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Tim Reddehase
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# ontology-united
|
2
|
+
|
3
|
+
ontology-united is a small DSL (domain specific language) for
|
4
|
+
writing [OWL][owl] ontologies.
|
5
|
+
|
6
|
+
It is mainly intended as a gem to be used as part of
|
7
|
+
the [ontohub][ontohub] project to create ontologies for testing in
|
8
|
+
order to not rely on fixtures. See the corresponding issue
|
9
|
+
(ontohub/ontohub#786).
|
10
|
+
|
11
|
+
Currently it supports only the [manchester syntax][manchester]
|
12
|
+
as serialization
|
13
|
+
mechanism and is fairly limited in its owl support.
|
14
|
+
However it will be further developed, maintained and extended.
|
15
|
+
|
16
|
+
[owl]: http://www.w3.org/TR/owl2-overview/
|
17
|
+
[ontohub]: https://github.com/ontohub/ontohub
|
18
|
+
[manchester]: http://www.w3.org/2007/OWL/wiki/ManchesterSyntax
|
19
|
+
|
20
|
+
## Installation
|
21
|
+
|
22
|
+
Add this line to your application's Gemfile:
|
23
|
+
|
24
|
+
gem 'ontology-united'
|
25
|
+
|
26
|
+
And then execute:
|
27
|
+
|
28
|
+
$ bundle
|
29
|
+
|
30
|
+
Or install it yourself as:
|
31
|
+
|
32
|
+
$ gem install ontology-united
|
33
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
module OntologyUnited
|
2
|
+
module DSL
|
3
|
+
class BaseDSL
|
4
|
+
|
5
|
+
class << self
|
6
|
+
|
7
|
+
attr_writer :stack
|
8
|
+
attr_reader :the_attr_readers
|
9
|
+
attr_reader :current
|
10
|
+
|
11
|
+
def attr_reader_with_default(*readers, default: nil)
|
12
|
+
raise ArgumentError, 'Default value for reader needed' if default.nil?
|
13
|
+
attr_reader *readers
|
14
|
+
@the_attr_readers ||= {}
|
15
|
+
klass = default.is_a?(Class) ? default : default.class
|
16
|
+
readers.each { |reader| @the_attr_readers[reader] = klass }
|
17
|
+
end
|
18
|
+
|
19
|
+
def stack
|
20
|
+
@stack ||= []
|
21
|
+
end
|
22
|
+
|
23
|
+
def current
|
24
|
+
self.stack.last
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
def establish_defaults
|
30
|
+
self.class.the_attr_readers.each do |var, klass|
|
31
|
+
self.instance_variable_set(:"@#{var}", klass.new)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def stack
|
36
|
+
self.class.stack
|
37
|
+
end
|
38
|
+
|
39
|
+
def current
|
40
|
+
self.class.current
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
require 'set'
|
3
|
+
|
4
|
+
module OntologyUnited
|
5
|
+
module DSL
|
6
|
+
class Ontology < BaseDSL
|
7
|
+
|
8
|
+
attr_reader_with_default :the_classes, :the_imports,
|
9
|
+
:the_sentences, :the_prefixes, default: Set
|
10
|
+
attr_reader :name
|
11
|
+
|
12
|
+
def initialize(name)
|
13
|
+
establish_defaults
|
14
|
+
@name = name
|
15
|
+
end
|
16
|
+
|
17
|
+
def elements
|
18
|
+
the_prefixes + the_imports + the_classes + the_sentences
|
19
|
+
end
|
20
|
+
|
21
|
+
def iri
|
22
|
+
create_tempfile if @iri.nil?
|
23
|
+
@iri
|
24
|
+
end
|
25
|
+
|
26
|
+
def class(name=nil)
|
27
|
+
if name.nil?
|
28
|
+
super()
|
29
|
+
else
|
30
|
+
ontology_class = OntologyClass.new(name)
|
31
|
+
the_classes << ontology_class
|
32
|
+
ontology_class
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
alias_method :ontology_class, :class
|
37
|
+
|
38
|
+
def define(*args, &block)
|
39
|
+
OntologyDSL.define(*args, &block)
|
40
|
+
end
|
41
|
+
|
42
|
+
def imports(arg, &block)
|
43
|
+
if block || arg.is_a?(Ontology)
|
44
|
+
ontology = arg
|
45
|
+
arg = define(ontology.name, &block)
|
46
|
+
end
|
47
|
+
the_import = OntologyImport.new(arg)
|
48
|
+
the_imports << the_import
|
49
|
+
the_import
|
50
|
+
end
|
51
|
+
|
52
|
+
def prefix(prefix, iri=self)
|
53
|
+
the_prefix = OntologyPrefix.new(prefix, iri)
|
54
|
+
the_prefixes << the_prefix
|
55
|
+
the_prefix
|
56
|
+
end
|
57
|
+
|
58
|
+
def sub_class_of(child_ontology_class, parent_ontology_class)
|
59
|
+
sentence = OntologySentence.new([
|
60
|
+
child_ontology_class,
|
61
|
+
'SubClassOf:',
|
62
|
+
parent_ontology_class
|
63
|
+
])
|
64
|
+
parent_ontology_class.part_of(sentence)
|
65
|
+
the_sentences << sentence
|
66
|
+
sentence
|
67
|
+
end
|
68
|
+
|
69
|
+
def to_s(serializer: OntologyUnited::Serializer::DEFAULT.new)
|
70
|
+
serializer.serialize_ontology(self)
|
71
|
+
end
|
72
|
+
|
73
|
+
def file
|
74
|
+
@file ||= create_tempfile
|
75
|
+
end
|
76
|
+
|
77
|
+
def create_tempfile
|
78
|
+
filename = name.match(%r(([^/]+)\.\w+$))[1]
|
79
|
+
file = Tempfile.new([filename, '.owl'])
|
80
|
+
@iri = "file://#{file.path}"
|
81
|
+
file.write(self.to_s)
|
82
|
+
file.rewind
|
83
|
+
file
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module OntologyUnited
|
2
|
+
module DSL
|
3
|
+
class OntologyClass < OntologyEntityBase
|
4
|
+
|
5
|
+
attr_accessor :prefix
|
6
|
+
attr_reader :name
|
7
|
+
delegate_equality_to method: :name
|
8
|
+
|
9
|
+
def initialize(name)
|
10
|
+
@name = name
|
11
|
+
end
|
12
|
+
|
13
|
+
def sub_class_of(parent_ontology_class)
|
14
|
+
parent.sub_class_of(self, parent_ontology_class)
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_s(serializer: OntologyUnited::Serializer::DEFAULT.new)
|
18
|
+
serializer.serialize_class(self)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module OntologyUnited
|
2
|
+
module DSL
|
3
|
+
class OntologyDSL < BaseDSL
|
4
|
+
|
5
|
+
def self.define(name, &block)
|
6
|
+
ontology = Ontology.new(name)
|
7
|
+
stack.push(ontology)
|
8
|
+
if block
|
9
|
+
if block.arity == 1
|
10
|
+
block.call(ontology)
|
11
|
+
else
|
12
|
+
ontology.instance_eval(&block)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
stack.pop
|
16
|
+
ontology
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module OntologyUnited
|
2
|
+
module DSL
|
3
|
+
class OntologyEntityBase
|
4
|
+
|
5
|
+
attr_reader :the_calls
|
6
|
+
|
7
|
+
def self.delegate_equality_to(method: nil, variable: nil)
|
8
|
+
define_method :eql? do |obj|
|
9
|
+
if method
|
10
|
+
self.send(method.to_sym).eql?(obj.send(method.to_sym))
|
11
|
+
elsif variable
|
12
|
+
own = self.instance_variable_get(:"@#{variable}")
|
13
|
+
other = obj.instance_variable_get(:"@#{variable}")
|
14
|
+
own.eql?(other)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
define_method :hash do
|
18
|
+
if method
|
19
|
+
self.send(method).hash
|
20
|
+
elsif variable
|
21
|
+
self.instance_variable_get(:"@#{variable}")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
def parent
|
28
|
+
OntologyDSL.current
|
29
|
+
end
|
30
|
+
|
31
|
+
def part_of(element)
|
32
|
+
@part_of ||= Set.new
|
33
|
+
@part_of << element
|
34
|
+
end
|
35
|
+
|
36
|
+
def part_of?(element)
|
37
|
+
@part_of ||= Set.new
|
38
|
+
@part_of.member?(element)
|
39
|
+
end
|
40
|
+
|
41
|
+
def called_for_parent_before?(method)
|
42
|
+
@the_calls ||= {}
|
43
|
+
!! the_calls[[parent, method]]
|
44
|
+
end
|
45
|
+
|
46
|
+
def eql?(object)
|
47
|
+
(self <=> object) == 0
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module OntologyUnited
|
2
|
+
module DSL
|
3
|
+
class OntologyImport < OntologyEntityBase
|
4
|
+
|
5
|
+
attr_reader :iri, :ontology, :subject
|
6
|
+
delegate_equality_to method: :subject
|
7
|
+
|
8
|
+
def initialize(arg)
|
9
|
+
@iri = arg if arg.is_a?(String)
|
10
|
+
@ontology = arg if arg.is_a?(Ontology)
|
11
|
+
@subject = arg
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s(serializer: OntologyUnited::Serializer::DEFAULT.new)
|
15
|
+
serializer.serialize_import(self)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module OntologyUnited
|
2
|
+
module DSL
|
3
|
+
class OntologyPrefix < OntologyEntityBase
|
4
|
+
|
5
|
+
attr_reader :prefix, :iri, :ontology, :subject
|
6
|
+
delegate_equality_to method: :prefix
|
7
|
+
|
8
|
+
def initialize(prefix, arg)
|
9
|
+
@prefix = prefix
|
10
|
+
@iri = arg if arg.is_a?(String)
|
11
|
+
@ontology = arg if arg.is_a?(Ontology)
|
12
|
+
@subject = arg
|
13
|
+
end
|
14
|
+
|
15
|
+
def class(name=nil)
|
16
|
+
if name.nil?
|
17
|
+
super()
|
18
|
+
else
|
19
|
+
ontology_class = parent.class(name)
|
20
|
+
ontology_class.prefix = self
|
21
|
+
ontology_class
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
alias_method :ontology_class, :class
|
26
|
+
|
27
|
+
def apply(ontology_class)
|
28
|
+
"#{prefix}:#{ontology_class.name}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_s(serializer: OntologyUnited::Serializer::DEFAULT.new)
|
32
|
+
serializer.serialize_prefix(self)
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module OntologyUnited
|
2
|
+
module DSL
|
3
|
+
class OntologySentence < OntologyEntityBase
|
4
|
+
|
5
|
+
attr_reader :sentence
|
6
|
+
delegate_equality_to method: :sentence
|
7
|
+
|
8
|
+
def initialize(sentence)
|
9
|
+
@sentence = sentence
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s(serializer: OntologyUnited::Serializer::DEFAULT.new)
|
13
|
+
serializer.serialize_sentence(self)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module OntologyUnited
|
2
|
+
module DSL
|
3
|
+
class Error < ::StandardError; end
|
4
|
+
class NotImplementedError < Error; end
|
5
|
+
|
6
|
+
def self.define_ontology
|
7
|
+
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
require "ontology-united/dsl/base_dsl"
|
13
|
+
require "ontology-united/dsl/ontology_entity_base"
|
14
|
+
require "ontology-united/dsl/ontology"
|
15
|
+
require "ontology-united/dsl/ontology_class"
|
16
|
+
require "ontology-united/dsl/ontology_dsl"
|
17
|
+
require "ontology-united/dsl/ontology_import"
|
18
|
+
require "ontology-united/dsl/ontology_prefix"
|
19
|
+
require "ontology-united/dsl/ontology_sentence"
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module OntologyUnited::Serializer
|
2
|
+
module OWL
|
3
|
+
class Manchester < SerializerBase
|
4
|
+
|
5
|
+
def serialize_ontology(ontology)
|
6
|
+
process ontology do
|
7
|
+
str = "Ontology: <#{ontology.iri}>\n"
|
8
|
+
str << join(ontology.elements, "\n") do |element|
|
9
|
+
element.to_s(serializer: self)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def serialize_prefix(ontology_prefix)
|
15
|
+
process ontology_prefix do
|
16
|
+
"Prefix: #{ontology_prefix.prefix}: " <<
|
17
|
+
"<#{ontology_prefix.iri || ontology_prefix.ontology.iri}#>"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def serialize_import(ontology_import)
|
22
|
+
process ontology_import do
|
23
|
+
"Import: <#{ontology_import.iri || ontology_import.ontology.iri}>"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def serialize_class(ontology_class)
|
28
|
+
process ontology_class do
|
29
|
+
prefix = ontology_class.prefix
|
30
|
+
if prefix
|
31
|
+
print_name = prefix.apply(ontology_class)
|
32
|
+
else
|
33
|
+
print_name = "<#{ontology_class.name}>"
|
34
|
+
end
|
35
|
+
"#{'Class: ' if class_definition?(ontology_class)}#{print_name}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def serialize_sentence(ontology_sentence)
|
40
|
+
opts = {serializer: self}
|
41
|
+
process ontology_sentence do
|
42
|
+
first_class, middle, second_class = ontology_sentence.sentence
|
43
|
+
"#{first_class.to_s(opts)} #{middle} #{second_class.to_s(opts)}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def class_definition?(ontology_class)
|
48
|
+
# if no parent is set
|
49
|
+
parent_current.nil? ||
|
50
|
+
# or the parent is an ontology itself
|
51
|
+
ontology?(parent_current) ||
|
52
|
+
# or it is the first symbol of a sentence
|
53
|
+
sentence?(parent_current) && parent_current.sentence.first == ontology_class
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module OntologyUnited
|
2
|
+
module Serializer
|
3
|
+
class SerializerBase
|
4
|
+
attr_accessor :current, :parent_current
|
5
|
+
|
6
|
+
def initialize(current: nil)
|
7
|
+
self.current = current
|
8
|
+
self.parent_current = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
def process(subject, &block)
|
12
|
+
previous_parent = mark!(subject)
|
13
|
+
result = block.call
|
14
|
+
mark!(parent_current, previous_parent)
|
15
|
+
result
|
16
|
+
end
|
17
|
+
|
18
|
+
def mark!(subject, parent=nil)
|
19
|
+
previous_parent = parent_current
|
20
|
+
parent_current = parent || current
|
21
|
+
current = subject
|
22
|
+
previous_parent
|
23
|
+
end
|
24
|
+
|
25
|
+
def join(elements, sep)
|
26
|
+
elements.reduce('') do |str, raw_element|
|
27
|
+
str << sep unless str.empty?
|
28
|
+
element = yield raw_element
|
29
|
+
str << element
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def ontology?(subject)
|
34
|
+
subject.is_a?(OntologyUnited::DSL::Ontology)
|
35
|
+
end
|
36
|
+
|
37
|
+
def class?(subject)
|
38
|
+
subject.is_a?(OntologyUnited::DSL::OntologyClass)
|
39
|
+
end
|
40
|
+
|
41
|
+
def class?(subject)
|
42
|
+
subject.is_a?(OntologyUnited::DSL::OntologySentence)
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ontology-united/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ontology-united"
|
8
|
+
spec.version = OntologyUnited::VERSION
|
9
|
+
spec.authors = ["Tim Reddehase"]
|
10
|
+
spec.email = ["robustus@rightsrestricted.com"]
|
11
|
+
spec.summary = %q{small ontology definition dsl}
|
12
|
+
spec.description = %q{a small domain specific language for writing owl based ontologies}
|
13
|
+
spec.homepage = "https://github.com/0robustus1/ontology-united"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", ">= 1.5.3"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.2"
|
23
|
+
spec.add_development_dependency "rspec", "~> 2.14"
|
24
|
+
spec.add_development_dependency "pry", "~> 0.9"
|
25
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
describe OntologyUnited do
|
5
|
+
|
6
|
+
it 'has a version number' do
|
7
|
+
expect(OntologyUnited::VERSION).not_to be nil
|
8
|
+
end
|
9
|
+
|
10
|
+
context 'when issueing a standard definition' do
|
11
|
+
let(:ontology) do
|
12
|
+
OntologyUnited::DSL::OntologyDSL.define('Foo.owl') do
|
13
|
+
rr = prefix('rr', self)
|
14
|
+
imports define('Bar.owl') do
|
15
|
+
rr = prefix('rr', self)
|
16
|
+
rr.class('SomeBar')
|
17
|
+
end
|
18
|
+
rr.class('Bar').sub_class_of rr.class('Foo')
|
19
|
+
rr.class('something')
|
20
|
+
rr.class('something').sub_class_of rr.class('Foo')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should raise no errors' do
|
25
|
+
expect { ontology }.not_to raise_error
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should have a valid iri' do
|
29
|
+
expect(ontology.iri).to match(URI.regexp)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OntologyUnited::Serializer::OWL::Manchester do
|
4
|
+
let(:manchester) { OntologyUnited::Serializer::OWL::Manchester }
|
5
|
+
let(:name) { 'OntologyName' }
|
6
|
+
let(:list) do
|
7
|
+
the_prefix, ontology_class, sentence = nil
|
8
|
+
o = OntologyUnited::DSL::OntologyDSL.define("#{name}.owl") do
|
9
|
+
the_prefix = prefix('some', self)
|
10
|
+
ontology_class = the_prefix.class('Foobar')
|
11
|
+
sentence = ontology_class.sub_class_of the_prefix.class('NoBar')
|
12
|
+
end
|
13
|
+
[o, the_prefix, ontology_class, sentence]
|
14
|
+
end
|
15
|
+
let(:ontology) { list[0] }
|
16
|
+
let(:prefix) { list[1] }
|
17
|
+
let(:ontology_class) { list[2] }
|
18
|
+
let(:sentence) { list[3] }
|
19
|
+
|
20
|
+
context 'when serializing an ontology' do
|
21
|
+
let(:serialized) { ontology.to_s(serializer: manchester.new) }
|
22
|
+
|
23
|
+
it 'should contain the prefix definition' do
|
24
|
+
expect(serialized).to include(prefix.to_s(serializer: manchester.new))
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should contain the ontology class definition' do
|
28
|
+
expect(serialized).to include(ontology_class.to_s(serializer: manchester.new))
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should contain the sentence definition' do
|
32
|
+
expect(serialized).to include(sentence.to_s(serializer: manchester.new))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'when serializing an ontology class' do
|
37
|
+
let(:serialized) { ontology_class.to_s(serializer: manchester.new) }
|
38
|
+
|
39
|
+
it 'should be a valid manchester syntax class definition' do
|
40
|
+
expect(serialized).to eq("Class: some:Foobar")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'when serializing a prefix' do
|
45
|
+
let(:serialized) { prefix.to_s(serializer: manchester.new) }
|
46
|
+
|
47
|
+
it 'should be a valid manchester syntax prefix definition' do
|
48
|
+
expect(serialized).to match(/^Prefix: some: <[^>]+#>$/)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'when serializing a sentence' do
|
53
|
+
let(:serialized) { sentence.to_s(serializer: manchester.new) }
|
54
|
+
|
55
|
+
it 'should be a valid manchester syntax sentence definition' do
|
56
|
+
expect(serialized).to eq("Class: some:Foobar SubClassOf: Class: some:NoBar")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ontology-united
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tim Reddehase
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.5.3
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.5.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.2'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.14'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.14'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.9'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.9'
|
69
|
+
description: a small domain specific language for writing owl based ontologies
|
70
|
+
email:
|
71
|
+
- robustus@rightsrestricted.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".rspec"
|
77
|
+
- ".travis.yml"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- lib/ontology-united.rb
|
83
|
+
- lib/ontology-united/convenience.rb
|
84
|
+
- lib/ontology-united/dsl.rb
|
85
|
+
- lib/ontology-united/dsl/base_dsl.rb
|
86
|
+
- lib/ontology-united/dsl/ontology.rb
|
87
|
+
- lib/ontology-united/dsl/ontology_class.rb
|
88
|
+
- lib/ontology-united/dsl/ontology_dsl.rb
|
89
|
+
- lib/ontology-united/dsl/ontology_entity_base.rb
|
90
|
+
- lib/ontology-united/dsl/ontology_import.rb
|
91
|
+
- lib/ontology-united/dsl/ontology_prefix.rb
|
92
|
+
- lib/ontology-united/dsl/ontology_sentence.rb
|
93
|
+
- lib/ontology-united/serializer.rb
|
94
|
+
- lib/ontology-united/serializer/owl.rb
|
95
|
+
- lib/ontology-united/serializer/owl/manchester.rb
|
96
|
+
- lib/ontology-united/serializer/serializer_base.rb
|
97
|
+
- lib/ontology-united/version.rb
|
98
|
+
- ontology-united.gemspec
|
99
|
+
- spec/ontology-united/ontology-united_spec.rb
|
100
|
+
- spec/ontology-united/serializer/owl/manchester_spec.rb
|
101
|
+
- spec/spec_helper.rb
|
102
|
+
homepage: https://github.com/0robustus1/ontology-united
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.2.2
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: small ontology definition dsl
|
126
|
+
test_files:
|
127
|
+
- spec/ontology-united/ontology-united_spec.rb
|
128
|
+
- spec/ontology-united/serializer/owl/manchester_spec.rb
|
129
|
+
- spec/spec_helper.rb
|