Class: OntologyUnited::DSL::Ontology

Inherits:
OntologyDSL show all
Includes:
VariableStore::Declaration, VariableStore::Helper
Defined in:
lib/ontology-united/dsl/ontology.rb

Constant Summary collapse

DEFAULT_EXTENSION =
:owl

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from VariableStore::Helper

#as

Methods included from VariableStore::Declaration

#declare

Methods inherited from OntologyDSL

define, redefine

Methods inherited from BaseDSL

attr_reader_with_default, #establish_defaults

Methods included from Stack

#current, #parent, #stack

Methods included from Stack::Delegate

#delegate_stack_to

Constructor Details

#initialize(name) ⇒ Ontology

Returns a new instance of Ontology.



18
19
20
21
# File 'lib/ontology-united/dsl/ontology.rb', line 18

def initialize(name)
  establish_defaults
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



16
17
18
# File 'lib/ontology-united/dsl/ontology.rb', line 16

def name
  @name
end

Instance Method Details

#class(name = nil, as: nil) ⇒ Object Also known as: ontology_class



32
33
34
35
36
37
38
39
40
41
# File 'lib/ontology-united/dsl/ontology.rb', line 32

def class(name=nil, as: nil)
  if name.nil?
    super()
  else
    sample = OntologyClass.new(name)
    ontology_class = the_classes.add_or_fetch(sample)
    ontology_class.as(as) if as
    ontology_class
  end
end

#create_tempfileObject



93
94
95
96
97
98
99
100
101
102
# File 'lib/ontology-united/dsl/ontology.rb', line 93

def create_tempfile
  filename = name
  file = Tempfile.new([filename, extension])
  @iri = "file://#{file.path}"
  @file = file
  file.write(self.to_s)
  file.flush
  file.rewind
  file
end

#define(*args, &block) ⇒ Object



45
46
47
# File 'lib/ontology-united/dsl/ontology.rb', line 45

def define(*args, &block)
  OntologyDSL.define(*args, &block)
end

#elementsObject



23
24
25
# File 'lib/ontology-united/dsl/ontology.rb', line 23

def elements
  the_prefixes + the_imports + the_classes + the_sentences
end

#extensionObject



89
90
91
# File 'lib/ontology-united/dsl/ontology.rb', line 89

def extension
  ".#{DEFAULT_EXTENSION}"
end

#fileObject



84
85
86
87
# File 'lib/ontology-united/dsl/ontology.rb', line 84

def file
  create_tempfile if @file.nil?
  @file
end

#imports(arg, &block) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/ontology-united/dsl/ontology.rb', line 53

def imports(arg, &block)
  if block && arg.is_a?(Ontology)
    ontology = arg
    arg = redefine(ontology, &block)
  end
  the_import = OntologyImport.new(arg)
  the_imports << the_import
  the_import
end

#iriObject



27
28
29
30
# File 'lib/ontology-united/dsl/ontology.rb', line 27

def iri
  create_tempfile if @iri.nil?
  @iri
end

#prefix(prefix, iri = self, as: nil) ⇒ Object



63
64
65
66
67
68
# File 'lib/ontology-united/dsl/ontology.rb', line 63

def prefix(prefix, iri=self, as: nil)
  the_prefix = OntologyPrefix.new(prefix, iri)
  the_prefix.as(as) if as
  the_prefixes << the_prefix
  the_prefix
end

#redefine(ontology = self, &block) ⇒ Object



49
50
51
# File 'lib/ontology-united/dsl/ontology.rb', line 49

def redefine(ontology = self, &block)
  OntologyDSL.redefine(ontology, &block)
end

#sub_class_of(child_ontology_class, parent_ontology_class) ⇒ Object



70
71
72
73
74
75
76
77
78
# File 'lib/ontology-united/dsl/ontology.rb', line 70

def sub_class_of(child_ontology_class, parent_ontology_class)
  sentence = OntologySentence.new([
    child_ontology_class,
    'SubClassOf:',
    parent_ontology_class
  ])
  the_sentences << sentence
  sentence
end

#to_s(serializer: OntologyUnited::Serializer::DEFAULT.new) ⇒ Object



80
81
82
# File 'lib/ontology-united/dsl/ontology.rb', line 80

def to_s(serializer: OntologyUnited::Serializer::DEFAULT.new)
  serializer.serialize_ontology(self)
end