ontology-united 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ab561ca8455f27d70cbdd4cb9c20351da04f6a4e
4
- data.tar.gz: ff6f3bb6c32f3cb2b9fd3862e10cc2b140ab9269
3
+ metadata.gz: 5fa8e5afa2d08912d715348c106109de7e33b629
4
+ data.tar.gz: cd4910c791695d652a41efc8ee0c27c57b09014b
5
5
  SHA512:
6
- metadata.gz: 758a5eac126d84d58d6a46901b43299ec9040e7b4f4f1166c3c2e8e6333cbb389caef40a7ce4e017c065ba71eef119a8dc62877c967e49c441901844f9d03aec
7
- data.tar.gz: 6890fcda4eccbfc2b0d89aac0b8448e94bcd040d3fbdf0faa70c5fccb462b739e4749395a0a36d10c8975088c403f87a588f4368e515ef473d09c0a20ff32090
6
+ metadata.gz: 5bdcbbc3e8fa861ebc51da05fc8508bfd83bd69942a47fd67c8cf1c5f39151b834d8b26889a1c3d304f61cf321a0001c2e7952441b57c092563e64e642e80941
7
+ data.tar.gz: cef0f24b326c209e63a9776dbdc58a208a82da8539fc71ce43094c7553cec0465e93b2263c9ea0958658d0c3eadd5fe655c875ec70cf4073d65baa7c471da1c1
@@ -0,0 +1 @@
1
+ service-name: travis-ci
@@ -1,4 +1,5 @@
1
1
  language: ruby
2
- cache: bundler
2
+ cache:
3
+ bundler: true
3
4
  rvm:
4
- - 2.1.1
5
+ - 2.1.5
@@ -0,0 +1,55 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ontology-united (0.0.2)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ coderay (1.1.0)
10
+ coveralls (0.7.0)
11
+ multi_json (~> 1.3)
12
+ rest-client
13
+ simplecov (>= 0.7)
14
+ term-ansicolor
15
+ thor
16
+ diff-lcs (1.2.5)
17
+ method_source (0.8.2)
18
+ mime-types (2.2)
19
+ multi_json (1.9.2)
20
+ pry (0.9.12.6)
21
+ coderay (~> 1.0)
22
+ method_source (~> 0.8)
23
+ slop (~> 3.4)
24
+ rake (10.2.2)
25
+ rest-client (1.6.7)
26
+ mime-types (>= 1.16)
27
+ rspec (2.14.1)
28
+ rspec-core (~> 2.14.0)
29
+ rspec-expectations (~> 2.14.0)
30
+ rspec-mocks (~> 2.14.0)
31
+ rspec-core (2.14.8)
32
+ rspec-expectations (2.14.5)
33
+ diff-lcs (>= 1.1.3, < 2.0)
34
+ rspec-mocks (2.14.6)
35
+ simplecov (0.7.1)
36
+ multi_json (~> 1.0)
37
+ simplecov-html (~> 0.7.1)
38
+ simplecov-html (0.7.1)
39
+ slop (3.4.7)
40
+ term-ansicolor (1.3.0)
41
+ tins (~> 1.0)
42
+ thor (0.19.1)
43
+ tins (1.1.0)
44
+
45
+ PLATFORMS
46
+ ruby
47
+
48
+ DEPENDENCIES
49
+ bundler (>= 1.7.2)
50
+ coveralls (~> 0.7.0)
51
+ ontology-united!
52
+ pry (~> 0.9)
53
+ rake (~> 10.2)
54
+ rspec (~> 2.14)
55
+ simplecov (~> 0.7.1)
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # ontology-united
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/ontology-united.svg)](http://badge.fury.io/rb/ontology-united)
4
+ [![Build Status](https://travis-ci.org/0robustus1/ontology-united.svg?branch=master)](https://travis-ci.org/0robustus1/ontology-united)
5
+ [![Coverage Status](https://coveralls.io/repos/0robustus1/ontology-united/badge.png?branch=master)](https://coveralls.io/r/0robustus1/ontology-united?branch=master)
6
+
3
7
  ontology-united is a small DSL (domain specific language) for
4
8
  writing [OWL][owl] ontologies.
5
9
 
@@ -45,11 +49,11 @@ OntologyUnited::DSL::OntologyDSL.define('MyOntologyName') do
45
49
  end
46
50
  ```
47
51
 
48
- or by including the convience module, which will give you a more
52
+ or by including the convenience module, which will give you a more
49
53
  useful/shorter method call:
50
54
  ```ruby
51
55
  # you'll only need to do this once per namespace
52
- include OntologyUnited::Convience
56
+ include OntologyUnited::Convenience
53
57
 
54
58
  define_ontology('MyOntologyName') do
55
59
  end
@@ -3,6 +3,7 @@ require "ontology-united/version"
3
3
  module OntologyUnited
4
4
  end
5
5
 
6
+ require "ontology-united/stack"
6
7
  require "ontology-united/dsl"
7
8
  require "ontology-united/serializer"
8
9
  require "ontology-united/convenience"
@@ -9,11 +9,13 @@ module OntologyUnited
9
9
  end
10
10
  end
11
11
 
12
+ require "ontology-united/dsl/pseudo_set.rb"
13
+ require "ontology-united/dsl/variable_store.rb"
12
14
  require "ontology-united/dsl/base_dsl"
15
+ require "ontology-united/dsl/ontology_dsl"
13
16
  require "ontology-united/dsl/ontology_entity_base"
14
17
  require "ontology-united/dsl/ontology"
15
18
  require "ontology-united/dsl/ontology_class"
16
- require "ontology-united/dsl/ontology_dsl"
17
19
  require "ontology-united/dsl/ontology_import"
18
20
  require "ontology-united/dsl/ontology_prefix"
19
21
  require "ontology-united/dsl/ontology_sentence"
@@ -1,12 +1,13 @@
1
1
  module OntologyUnited
2
2
  module DSL
3
3
  class BaseDSL
4
+ extend Stack::Delegate
4
5
 
5
6
  class << self
7
+ include Stack
6
8
 
7
9
  attr_writer :stack
8
10
  attr_reader :the_attr_readers
9
- attr_reader :current
10
11
 
11
12
  def attr_reader_with_default(*readers, default: nil)
12
13
  raise ArgumentError, 'Default value for reader needed' if default.nil?
@@ -16,14 +17,6 @@ module OntologyUnited
16
17
  readers.each { |reader| @the_attr_readers[reader] = klass }
17
18
  end
18
19
 
19
- def stack
20
- @stack ||= []
21
- end
22
-
23
- def current
24
- self.stack.last
25
- end
26
-
27
20
  end
28
21
 
29
22
  def establish_defaults
@@ -32,13 +25,7 @@ module OntologyUnited
32
25
  end
33
26
  end
34
27
 
35
- def stack
36
- self.class.stack
37
- end
38
-
39
- def current
40
- self.class.current
41
- end
28
+ delegate_stack_to { |base_dsl| base_dsl.class }
42
29
 
43
30
  end
44
31
  end
@@ -3,11 +3,16 @@ require 'set'
3
3
 
4
4
  module OntologyUnited
5
5
  module DSL
6
- class Ontology < BaseDSL
6
+ class Ontology < OntologyDSL
7
+ include VariableStore::Declaration
8
+ include VariableStore::Helper
9
+
10
+ delegate_stack_to { |ontology| ontology.class.superclass }
11
+
7
12
  DEFAULT_EXTENSION = :owl
8
13
 
9
14
  attr_reader_with_default :the_classes, :the_imports,
10
- :the_sentences, :the_prefixes, default: Set
15
+ :the_sentences, :the_prefixes, default: PseudoSet
11
16
  attr_reader :name
12
17
 
13
18
  def initialize(name)
@@ -24,12 +29,13 @@ module OntologyUnited
24
29
  @iri
25
30
  end
26
31
 
27
- def class(name=nil)
32
+ def class(name=nil, as: nil)
28
33
  if name.nil?
29
34
  super()
30
35
  else
31
- ontology_class = OntologyClass.new(name)
32
- the_classes << ontology_class
36
+ sample = OntologyClass.new(name)
37
+ ontology_class = the_classes.add_or_fetch(sample)
38
+ ontology_class.as(as) if as
33
39
  ontology_class
34
40
  end
35
41
  end
@@ -47,15 +53,16 @@ module OntologyUnited
47
53
  def imports(arg, &block)
48
54
  if block && arg.is_a?(Ontology)
49
55
  ontology = arg
50
- arg = redefine(&block)
56
+ arg = redefine(ontology, &block)
51
57
  end
52
58
  the_import = OntologyImport.new(arg)
53
59
  the_imports << the_import
54
60
  the_import
55
61
  end
56
62
 
57
- def prefix(prefix, iri=self)
63
+ def prefix(prefix, iri=self, as: nil)
58
64
  the_prefix = OntologyPrefix.new(prefix, iri)
65
+ the_prefix.as(as) if as
59
66
  the_prefixes << the_prefix
60
67
  the_prefix
61
68
  end
@@ -66,7 +73,6 @@ module OntologyUnited
66
73
  'SubClassOf:',
67
74
  parent_ontology_class
68
75
  ])
69
- parent_ontology_class.part_of(sentence)
70
76
  the_sentences << sentence
71
77
  sentence
72
78
  end
@@ -2,22 +2,29 @@ module OntologyUnited
2
2
  module DSL
3
3
  class OntologyClass < OntologyEntityBase
4
4
 
5
+ delegate_equality_to method: :identifier
6
+
5
7
  attr_accessor :prefix
6
8
  attr_reader :name
7
- delegate_equality_to method: :name
8
9
 
9
10
  def initialize(name)
10
11
  @name = name
11
12
  end
12
13
 
13
- def sub_class_of(parent_ontology_class)
14
- parent.sub_class_of(self, parent_ontology_class)
14
+ def sub_class_of(parent_ontology_class, as: nil)
15
+ sentence = parent.sub_class_of(self, parent_ontology_class)
16
+ sentence.as(as) if as
17
+ sentence
15
18
  end
16
19
 
17
20
  def to_s(serializer: OntologyUnited::Serializer::DEFAULT.new)
18
21
  serializer.serialize_class(self)
19
22
  end
20
23
 
24
+ def identifier
25
+ prefix ? prefix.identifier + [name] : [name]
26
+ end
27
+
21
28
  end
22
29
  end
23
30
  end
@@ -2,13 +2,14 @@ module OntologyUnited
2
2
  module DSL
3
3
  class OntologyDSL < BaseDSL
4
4
 
5
- def self.define(name, &block)
5
+ def self.define(name, as: nil, &block)
6
6
  ontology = Ontology.new(name)
7
- redefine(ontology, &block)
7
+ redefine(ontology, as: as, &block)
8
8
  end
9
9
 
10
- def self.redefine(ontology, &block)
10
+ def self.redefine(ontology, as: nil, &block)
11
11
  stack.push(ontology)
12
+ ontology.as(as) if as
12
13
  if block
13
14
  if block.arity == 1
14
15
  block.call(ontology)
@@ -1,19 +1,25 @@
1
1
  module OntologyUnited
2
2
  module DSL
3
3
  class OntologyEntityBase
4
+ include VariableStore::Helper
4
5
 
5
6
  attr_reader :the_calls
6
7
 
7
8
  def self.delegate_equality_to(method: nil, variable: nil)
8
- define_method :eql? do |obj|
9
+ define_method :== do |obj|
9
10
  if method
10
- self.send(method.to_sym).eql?(obj.send(method.to_sym))
11
+ return false unless self.respond_to?(method.to_sym)
12
+ return false unless obj.respond_to?(method.to_sym)
13
+ self.send(method.to_sym) == obj.send(method.to_sym)
11
14
  elsif variable
12
15
  own = self.instance_variable_get(:"@#{variable}")
13
16
  other = obj.instance_variable_get(:"@#{variable}")
14
- own.eql?(other)
17
+ own == other
15
18
  end
16
19
  end
20
+ define_method :eql? do |obj|
21
+ self == obj
22
+ end
17
23
  define_method :hash do
18
24
  if method
19
25
  self.send(method).hash
@@ -28,25 +34,6 @@ module OntologyUnited
28
34
  OntologyDSL.current
29
35
  end
30
36
 
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
37
  end
51
38
  end
52
39
  end
@@ -3,7 +3,7 @@ module OntologyUnited
3
3
  class OntologyPrefix < OntologyEntityBase
4
4
 
5
5
  attr_reader :prefix, :iri, :ontology, :subject
6
- delegate_equality_to method: :prefix
6
+ delegate_equality_to method: :identifier
7
7
 
8
8
  def initialize(prefix, arg)
9
9
  @prefix = prefix
@@ -12,11 +12,11 @@ module OntologyUnited
12
12
  @subject = arg
13
13
  end
14
14
 
15
- def class(name=nil)
15
+ def class(name=nil, as: nil)
16
16
  if name.nil?
17
17
  super()
18
18
  else
19
- ontology_class = parent.class(name)
19
+ ontology_class = parent.class(name, as: as)
20
20
  ontology_class.prefix = self
21
21
  ontology_class
22
22
  end
@@ -32,6 +32,10 @@ module OntologyUnited
32
32
  serializer.serialize_prefix(self)
33
33
  end
34
34
 
35
+ def identifier
36
+ [@iri || @ontology.name, prefix]
37
+ end
38
+
35
39
  end
36
40
  end
37
41
  end
@@ -0,0 +1,38 @@
1
+ module OntologyUnited
2
+ module DSL
3
+ class PseudoSet < ::Array
4
+
5
+ alias_method :array_push, :push
6
+ alias_method :array_concat, :concat
7
+
8
+ def add_or_fetch(obj)
9
+ if include?(obj)
10
+ at(index(obj))
11
+ else
12
+ array_push(obj)
13
+ obj
14
+ end
15
+ end
16
+
17
+ def push(obj)
18
+ include?(obj) ? self : array_push(obj)
19
+ end
20
+
21
+ def <<(obj)
22
+ push(obj)
23
+ end
24
+
25
+ def concat(arr)
26
+ array = dup
27
+ arr.each { |el| array.push(el) }
28
+ array
29
+ end
30
+
31
+ def +(arr)
32
+ concat(arr)
33
+ end
34
+
35
+
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,25 @@
1
+ module OntologyUnited
2
+ module DSL
3
+ module VariableStore
4
+ class Error < ::StandardError; end
5
+ class ParentIsNilError < Error; end
6
+
7
+ module Helper
8
+ def as(name)
9
+ fail ParentIsNilError, 'Can\'t define variable on nil' unless parent
10
+ parent.declare(self, as: name.to_sym)
11
+ self
12
+ end
13
+ end
14
+
15
+ module Declaration
16
+ def declare(obj, as: nil)
17
+ if as
18
+ define_singleton_method(as) { obj }
19
+ end
20
+ end
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -1,6 +1,7 @@
1
1
  module OntologyUnited
2
2
  module Serializer
3
3
  class SerializerBase
4
+ include Stack
4
5
 
5
6
  def initialize(current: nil)
6
7
  stack.push(current) if current
@@ -21,18 +22,6 @@ module OntologyUnited
21
22
  stack.pop
22
23
  end
23
24
 
24
- def stack
25
- @stack ||= []
26
- end
27
-
28
- def current
29
- stack[-1]
30
- end
31
-
32
- def parent
33
- stack[-2]
34
- end
35
-
36
25
  def join(elements, sep)
37
26
  elements.reduce('') do |str, raw_element|
38
27
  str << sep unless str.empty?
@@ -0,0 +1,30 @@
1
+ module OntologyUnited
2
+ module Stack
3
+
4
+ def stack
5
+ @stack ||= []
6
+ end
7
+
8
+ def current
9
+ stack[-1]
10
+ end
11
+
12
+ def parent
13
+ stack[-2]
14
+ end
15
+
16
+ module Delegate
17
+ def delegate_stack_to(method_name=nil, &block)
18
+ action = ->(stack_operation) do
19
+ ->() do
20
+ block.call(self).send(stack_operation)
21
+ end
22
+ end
23
+ define_method :stack, &action[:stack]
24
+ define_method :current, &action[:current]
25
+ define_method :parent, &action[:parent]
26
+ end
27
+ end
28
+
29
+ end
30
+ end
@@ -1,3 +1,3 @@
1
1
  module OntologyUnited
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -18,8 +18,10 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", ">= 1.5.3"
21
+ spec.add_development_dependency "bundler", ">= 1.7.2"
22
22
  spec.add_development_dependency "rake", "~> 10.2"
23
23
  spec.add_development_dependency "rspec", "~> 2.14"
24
24
  spec.add_development_dependency "pry", "~> 0.9"
25
+ spec.add_development_dependency "simplecov", "~> 0.7.1"
26
+ spec.add_development_dependency "coveralls", "~> 0.7.0"
25
27
  end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe OntologyUnited::Convenience do
4
+ include OntologyUnited::Convenience
5
+
6
+ context 'when defining a valid ontology' do
7
+ let(:ontology) do
8
+ define_ontology('Foo') do
9
+ ontology_class('Something')
10
+ end
11
+ end
12
+
13
+ it 'should raise no errors' do
14
+ expect { ontology }.not_to raise_error
15
+ end
16
+
17
+ it 'should return an ontology instance' do
18
+ expect(ontology).to be_instance_of(OntologyUnited::DSL::Ontology)
19
+ end
20
+
21
+
22
+ end
23
+
24
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe OntologyUnited::DSL::BaseDSL do
4
+
5
+ context '#stack' do
6
+
7
+ context 'should be an alias for .stack' do
8
+ let(:instance) { described_class.new }
9
+
10
+ it 'should be the same on default' do
11
+ expect(instance.stack).to eq(described_class.stack)
12
+ end
13
+
14
+ it 'should be the same with added content' do
15
+ described_class.stack.push('Content')
16
+ expect(instance.stack).to eq(described_class.stack)
17
+ end
18
+
19
+ end
20
+
21
+ end
22
+
23
+ context '#current' do
24
+
25
+ context 'should be an alias for .current' do
26
+ let(:instance) { described_class.new }
27
+
28
+ it 'should be the same on default' do
29
+ expect(instance.current).to eq(described_class.current)
30
+ end
31
+
32
+ it 'should be the same with added content to stack' do
33
+ described_class.stack.push('Content')
34
+ expect(instance.current).to eq(described_class.current)
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+
41
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe OntologyUnited::DSL::OntologyDSL do
4
+
5
+ context '.define' do
6
+ let(:ontology) do
7
+ described_class.define('Foo') do |this|
8
+ this.class('Something')
9
+ end
10
+ end
11
+
12
+ it 'should be allowed to use an ontology argument in the block' do
13
+ expect { ontology }.not_to raise_error
14
+ end
15
+
16
+ context 'inner definition of ontology' do
17
+ let(:outer) do
18
+ described_class.define('Foo') do
19
+ define('Bar', as: :bar_ontology) do |this|
20
+ this.class('Something')
21
+ end
22
+ end
23
+ end
24
+
25
+ it 'should contain variable-assignment for inner ontology' do
26
+ expect(outer.bar_ontology.name).to eq('Bar')
27
+ end
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,100 @@
1
+ require 'spec_helper'
2
+
3
+ describe OntologyUnited::DSL::OntologyEntityBase do
4
+
5
+ context '.delegate_equality_to' do
6
+
7
+ context 'when delegating to a method' do
8
+ let(:klass) do
9
+ class MethodClass < described_class
10
+ delegate_equality_to method: :name
11
+
12
+ def initialize(name)
13
+ @name = name
14
+ end
15
+
16
+ def name
17
+ @name
18
+ end
19
+ end
20
+ MethodClass
21
+ end
22
+
23
+ let(:person) { klass.new('Person') }
24
+ let(:same_person) { klass.new('Person') }
25
+ let(:someone) { klass.new('Someone') }
26
+
27
+
28
+ it 'should be equal if methods return values are equal' do
29
+ expect(person).to eql(same_person)
30
+ end
31
+
32
+ it 'should be not equal if methods return values are not equal' do
33
+ expect(someone).not_to eql(person)
34
+ end
35
+
36
+ it 'should be equal(==) if methods return values are equal' do
37
+ expect(person).to eq(same_person)
38
+ end
39
+
40
+ it 'should be not equal(==) if methods return values are not equal' do
41
+ expect(someone).not_to eq(person)
42
+ end
43
+
44
+ it 'hash should be the same if return values are the same' do
45
+ expect(person.hash).to eql(same_person.hash)
46
+ end
47
+
48
+ it 'hash should be not the same if return values are not the same' do
49
+ expect(someone.hash).not_to eql(person.hash)
50
+ end
51
+
52
+ end
53
+
54
+ context 'when delegating to a method' do
55
+ let(:klass) do
56
+ class MethodClass < described_class
57
+ delegate_equality_to variable: :name
58
+
59
+ def initialize(name)
60
+ @name = name
61
+ end
62
+
63
+ end
64
+ MethodClass
65
+ end
66
+
67
+ let(:person) { klass.new('Person') }
68
+ let(:same_person) { klass.new('Person') }
69
+ let(:someone) { klass.new('Someone') }
70
+
71
+
72
+ it 'should be equal if variable values are equal' do
73
+ expect(person).to eql(same_person)
74
+ end
75
+
76
+ it 'should be not equal if variable values are not equal' do
77
+ expect(someone).not_to eql(person)
78
+ end
79
+
80
+ it 'should be equal(==) if variable values are equal' do
81
+ expect(person).to eq(same_person)
82
+ end
83
+
84
+ it 'should be not equal(==) if variable values are not equal' do
85
+ expect(someone).not_to eq(person)
86
+ end
87
+
88
+ it 'hash should be the same if variable values are the same' do
89
+ expect(person.hash).to eql(same_person.hash)
90
+ end
91
+
92
+ it 'hash should be not the same if variable values are not the same' do
93
+ expect(someone.hash).not_to eql(person.hash)
94
+ end
95
+
96
+ end
97
+
98
+ end
99
+
100
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe OntologyUnited::DSL::OntologyPrefix do
4
+
5
+ context '#class' do
6
+ let(:prefix) { described_class.new('prefix', 'http://example.com') }
7
+
8
+ it 'should also work in the expected ruby sense' do
9
+ expect(prefix.class).to eq(described_class)
10
+ end
11
+
12
+ end
13
+
14
+ end
@@ -0,0 +1,87 @@
1
+ require 'spec_helper'
2
+
3
+ describe OntologyUnited::DSL::Ontology do
4
+
5
+ context '#file' do
6
+ let(:ontology) do
7
+ OntologyUnited::DSL::OntologyDSL.define('Foo') do
8
+ ontology_class('Something')
9
+ end
10
+ end
11
+
12
+ it 'should produce an existing file' do
13
+ expect(File.exist?(ontology.file.path)).to be_true
14
+ end
15
+
16
+ end
17
+
18
+ context 'variable store' do
19
+ let(:ontology) do
20
+ OntologyUnited::DSL::OntologyDSL.define('Foo') do
21
+ this = prefix('this', as: :this_prefix)
22
+ this.class('Something', as: :something_class)
23
+ this.class('Something').sub_class_of this.class('Other'), as: :sub_class_sentence
24
+
25
+ imports define('Bar', as: :referenced_ontology) do
26
+ bar = prefix('this', as: :bar_prefix)
27
+ bar.class('Something', as: :something_class)
28
+ end
29
+
30
+ end
31
+ end
32
+
33
+ context '.prefix' do
34
+ it 'should not contain a nily variable assignment' do
35
+ expect(ontology.this_prefix).to_not be_nil
36
+ end
37
+
38
+ it 'should contain a variable assignment with correct prefix' do
39
+ expect(ontology.this_prefix.prefix).to eq('this')
40
+ end
41
+ end
42
+
43
+ context '.class' do
44
+ it 'should not contain a nily variable assignment' do
45
+ expect(ontology.something_class).to_not be_nil
46
+ end
47
+
48
+ it 'should contain a variable assignment with correct name' do
49
+ expect(ontology.something_class.name).to eq('Something')
50
+ end
51
+ end
52
+
53
+ context 'sub_class_of sentence' do
54
+ it 'should not contain a nily variable assignment' do
55
+ expect(ontology.sub_class_sentence).to_not be_nil
56
+ end
57
+ end
58
+
59
+ context '.imports' do
60
+
61
+ it 'should not contain a nily imported ontology' do
62
+ expect(ontology.referenced_ontology).to_not be_nil
63
+ end
64
+
65
+ context 'the imported ontology' do
66
+
67
+ let(:imported) { ontology.referenced_ontology }
68
+
69
+ it 'should have a prefix' do
70
+ expect(imported.bar_prefix).to_not be_nil
71
+ end
72
+
73
+ it 'should have a a symbol' do
74
+ expect(imported.something_class).to_not be_nil
75
+ end
76
+
77
+ it 'should have not the same symbol as the parent ontology' do
78
+ expect(imported.something_class).to_not eq(ontology.something_class)
79
+ end
80
+ end
81
+
82
+ end
83
+
84
+ end
85
+
86
+
87
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe OntologyUnited::DSL::VariableStore do
4
+ let(:declaration_klass) do
5
+ class DeclarationKlass
6
+ include OntologyUnited::DSL::VariableStore::Declaration
7
+ end
8
+ DeclarationKlass
9
+ end
10
+
11
+ let(:variable_klass) do
12
+ class VariableKlass
13
+ include OntologyUnited::DSL::VariableStore::Helper
14
+ attr_accessor :parent, :some_string
15
+
16
+ def initialize(parent, some_string)
17
+ self.parent = parent
18
+ self.some_string = some_string
19
+ end
20
+ end
21
+ VariableKlass
22
+ end
23
+
24
+ context 'assuming an object with parent' do
25
+ let(:parent) { declaration_klass.new }
26
+ let(:variable_instance) { variable_klass.new(parent, 'SomeString') }
27
+
28
+ it 'should respond with self to a variable assignment call' do
29
+ expect(variable_instance.as(:inner)).to eq(variable_instance)
30
+ end
31
+
32
+ context 'and a variable assignment' do
33
+ before do
34
+ variable_instance.as(:inner)
35
+ end
36
+
37
+ it 'should produce the same object as variable on parent' do
38
+ expect(parent.inner).to eq(variable_instance)
39
+ end
40
+
41
+ end
42
+ end
43
+
44
+ context 'assuming an object without parent' do
45
+ let(:variable_instance) { variable_klass.new(nil, 'SomeString') }
46
+
47
+ it 'should raise the correct error' do
48
+ expect { variable_instance.as(:inner) }.to raise_error(OntologyUnited::DSL::VariableStore::ParentIsNilError)
49
+ end
50
+
51
+ end
52
+
53
+ end
@@ -15,7 +15,7 @@ describe OntologyUnited do
15
15
  rr = prefix('rr', self)
16
16
  rr.class('SomeBar')
17
17
  end
18
- rr.class('Bar').sub_class_of rr.class('Foo')
18
+ rr.class('Bar').sub_class_of rr.class('Foo').as(:foo_class)
19
19
  rr.class('something')
20
20
  rr.class('something').sub_class_of rr.class('Foo')
21
21
  end
@@ -28,6 +28,11 @@ describe OntologyUnited do
28
28
  it 'should have a valid iri' do
29
29
  expect(ontology.iri).to match(URI.regexp)
30
30
  end
31
+
32
+ it 'should have an on-ontology variable of the right type defined' do
33
+ expect(ontology.foo_class).
34
+ to be_instance_of(OntologyUnited::DSL::OntologyClass)
35
+ end
31
36
  end
32
37
 
33
38
  end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe OntologyUnited::Serializer::SerializerBase do
4
+
5
+ let(:ontology) do
6
+ OntologyUnited::DSL::OntologyDSL.define('Foo') do
7
+ this = prefix('this', as: :this_prefix)
8
+ this.class('Something', as: :something_class)
9
+ this.class('Something').sub_class_of this.class('Other'), as: :sub_class_sentence
10
+ end
11
+ end
12
+
13
+ let(:serializer) { described_class.new }
14
+
15
+ context '.ontology?' do
16
+ it 'should recognize an ontology correctly' do
17
+ expect(serializer.ontology?(ontology)).to be_true
18
+ end
19
+
20
+ it 'should produce false for an ontology-class' do
21
+ expect(serializer.ontology?(ontology.something_class)).to be_false
22
+ end
23
+ end
24
+
25
+ context '.class?' do
26
+ it 'should recognize an ontology-class correctly' do
27
+ expect(serializer.class?(ontology.something_class)).to be_true
28
+ end
29
+
30
+ it 'should produce false for a sentence' do
31
+ expect(serializer.class?(ontology.sub_class_sentence)).to be_false
32
+ end
33
+ end
34
+
35
+ context 'sentence?' do
36
+ it 'should recognize a sentence correctly' do
37
+ expect(serializer.sentence?(ontology.sub_class_sentence)).to be_true
38
+ end
39
+
40
+ it 'should produce false for an ontology-class' do
41
+ expect(serializer.sentence?(ontology.something_class)).to be_false
42
+ end
43
+ end
44
+
45
+
46
+ end
@@ -0,0 +1,118 @@
1
+ require 'spec_helper'
2
+
3
+ describe OntologyUnited::Stack do
4
+
5
+ let(:instance) do
6
+ class Klass
7
+ include OntologyUnited::Stack
8
+ end
9
+
10
+ Klass.new
11
+ end
12
+
13
+ context '.stack' do
14
+ it 'should be empty per default' do
15
+ expect(instance.stack).to be_empty
16
+ end
17
+
18
+ it 'should contain a pushed element' do
19
+ instance.stack.push(1)
20
+ expect(instance.stack).to include(1)
21
+ end
22
+ end
23
+
24
+ context '.current' do
25
+ it 'should be nil per default' do
26
+ expect(instance.current).to be_nil
27
+ end
28
+
29
+ it 'should be equal to stack.last on a two-element stack' do
30
+ instance.stack.push(1,2)
31
+ expect(instance.current).to eq(instance.stack.last)
32
+ end
33
+ end
34
+
35
+ context '.parent' do
36
+ it 'should be nil per default' do
37
+ expect(instance.parent).to be_nil
38
+ end
39
+
40
+ it 'should be nil if only one element was pushed to the stack' do
41
+ instance.stack.push(1)
42
+ expect(instance.parent).to be_nil
43
+ end
44
+
45
+ it 'should be equal to stack.first on a two-element stack' do
46
+ instance.stack.push(1,2)
47
+ expect(instance.parent).to eq(instance.stack.first)
48
+ end
49
+
50
+ it 'should be the middle element on a three-element stack' do
51
+ instance.stack.push(1,2,3)
52
+ expect(instance.parent).to eq(2)
53
+ end
54
+ end
55
+
56
+ describe OntologyUnited::Stack::Delegate do
57
+
58
+ context '.delegate_stack_to' do
59
+ let(:klass) do
60
+ class Klass
61
+ extend OntologyUnited::Stack
62
+ end
63
+ Klass
64
+ end
65
+
66
+ let(:subklass) do
67
+ class SubKlass < klass
68
+ extend OntologyUnited::Stack::Delegate
69
+
70
+ delegate_stack_to { |subklass| subklass.class.superclass }
71
+ end
72
+ SubKlass
73
+ end
74
+
75
+ let(:instance) { subklass.new }
76
+
77
+ before do
78
+ klass.instance_variable_set(:@stack, [])
79
+ end
80
+
81
+ context 'alias SubKlass#stack to Klass.stack' do
82
+ it 'should equal empty stack on default' do
83
+ expect(instance.stack).to be_empty
84
+ end
85
+
86
+ it 'should equal the superclass stack on push' do
87
+ klass.stack.push(1)
88
+ expect(instance.stack).to eq(klass.stack)
89
+ end
90
+ end
91
+
92
+ context 'alias SubKlass#current to Klass.current' do
93
+ it 'should equal to empty stack on default' do
94
+ expect(instance.current).to be_nil
95
+ end
96
+
97
+ it 'should equal the superclass stack on push' do
98
+ klass.stack.push(1)
99
+ expect(instance.current).to eq(klass.current)
100
+ end
101
+ end
102
+
103
+ context 'alias SubKlass#parent to Klass.parent' do
104
+ it 'should equal nil on default' do
105
+ expect(instance.parent).to be_nil
106
+ end
107
+
108
+ it 'should equal the superclass stack on push' do
109
+ klass.stack.push(1, 2)
110
+ expect(instance.parent).to eq(klass.parent)
111
+ end
112
+ end
113
+
114
+ end
115
+
116
+ end
117
+
118
+ end
@@ -1,2 +1,12 @@
1
+ if ENV['COVERAGE']
2
+ require 'simplecov'
3
+ SimpleCov.start
4
+ else
5
+ require 'coveralls'
6
+ Coveralls.wear!
7
+ end
8
+
1
9
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
10
  require 'ontology-united'
11
+ require 'pry'
12
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ontology-united
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Reddehase
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-25 00:00:00.000000000 Z
11
+ date: 2014-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.5.3
19
+ version: 1.7.2
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 1.5.3
26
+ version: 1.7.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +66,34 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.7.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.7.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: coveralls
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.7.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.7.0
69
97
  description: a small domain specific language for writing owl based ontologies
70
98
  email:
71
99
  - robustus@rightsrestricted.com
@@ -73,9 +101,11 @@ executables: []
73
101
  extensions: []
74
102
  extra_rdoc_files: []
75
103
  files:
104
+ - ".coveralls.yml"
76
105
  - ".rspec"
77
106
  - ".travis.yml"
78
107
  - Gemfile
108
+ - Gemfile.lock
79
109
  - LICENSE.txt
80
110
  - README.md
81
111
  - Rakefile
@@ -90,14 +120,26 @@ files:
90
120
  - lib/ontology-united/dsl/ontology_import.rb
91
121
  - lib/ontology-united/dsl/ontology_prefix.rb
92
122
  - lib/ontology-united/dsl/ontology_sentence.rb
123
+ - lib/ontology-united/dsl/pseudo_set.rb
124
+ - lib/ontology-united/dsl/variable_store.rb
93
125
  - lib/ontology-united/serializer.rb
94
126
  - lib/ontology-united/serializer/owl.rb
95
127
  - lib/ontology-united/serializer/owl/manchester.rb
96
128
  - lib/ontology-united/serializer/serializer_base.rb
129
+ - lib/ontology-united/stack.rb
97
130
  - lib/ontology-united/version.rb
98
131
  - ontology-united.gemspec
132
+ - spec/ontology-united/convenience_spec.rb
133
+ - spec/ontology-united/dsl/base_dsl_spec.rb
134
+ - spec/ontology-united/dsl/ontology_dsl_spec.rb
135
+ - spec/ontology-united/dsl/ontology_entity_base_spec.rb
136
+ - spec/ontology-united/dsl/ontology_prefix_spec.rb
137
+ - spec/ontology-united/dsl/ontology_spec.rb
138
+ - spec/ontology-united/dsl/variable_store_spec.rb
99
139
  - spec/ontology-united/ontology-united_spec.rb
100
140
  - spec/ontology-united/serializer/owl/manchester_spec.rb
141
+ - spec/ontology-united/serializer/serializer_base_spec.rb
142
+ - spec/ontology-united/stack_spec.rb
101
143
  - spec/spec_helper.rb
102
144
  homepage: https://github.com/0robustus1/ontology-united
103
145
  licenses:
@@ -124,6 +166,15 @@ signing_key:
124
166
  specification_version: 4
125
167
  summary: small ontology definition dsl
126
168
  test_files:
169
+ - spec/ontology-united/convenience_spec.rb
170
+ - spec/ontology-united/dsl/base_dsl_spec.rb
171
+ - spec/ontology-united/dsl/ontology_dsl_spec.rb
172
+ - spec/ontology-united/dsl/ontology_entity_base_spec.rb
173
+ - spec/ontology-united/dsl/ontology_prefix_spec.rb
174
+ - spec/ontology-united/dsl/ontology_spec.rb
175
+ - spec/ontology-united/dsl/variable_store_spec.rb
127
176
  - spec/ontology-united/ontology-united_spec.rb
128
177
  - spec/ontology-united/serializer/owl/manchester_spec.rb
178
+ - spec/ontology-united/serializer/serializer_base_spec.rb
179
+ - spec/ontology-united/stack_spec.rb
129
180
  - spec/spec_helper.rb