Class: Model::Ontology

Inherits:
Object
  • Object
show all
Includes:
RepositoryProxy
Defined in:
lib/models/ontology.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RepositoryProxy

#facts_only, #graph, #method_missing

Constructor Details

#initialize(repository, n3_input = nil) ⇒ Ontology

Returns a new instance of Ontology.



16
17
18
19
20
# File 'lib/models/ontology.rb', line 16

def initialize(repository, n3_input = nil)
  @repository = repository
  load_and_process_n3 n3_input if n3_input
  # initialize_state
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RepositoryProxy

Instance Attribute Details

#repositoryObject (readonly)

Returns the value of attribute repository.



8
9
10
# File 'lib/models/ontology.rb', line 8

def repository
  @repository
end

Class Method Details

.from_n3(n3_input) ⇒ Object



12
13
14
# File 'lib/models/ontology.rb', line 12

def self.from_n3(n3_input)
  Ontology.new(RDF::Repository.new, n3_input)
end

Instance Method Details

#applicationsObject



27
28
29
30
31
32
# File 'lib/models/ontology.rb', line 27

def applications
  query([nil, RDF.type, LV.Application]).
    map(&:subject).uniq.map do |subject|
    Application.new(subject, self)
  end
end

#device_with_description(description) ⇒ Object



58
59
60
# File 'lib/models/ontology.rb', line 58

def device_with_description(description)
  devices.find { |d| d.description == description }
end

#devicesObject



40
41
42
43
44
# File 'lib/models/ontology.rb', line 40

def devices
  query([nil, RDF.type, LV.Device]).map do |statement|
    Device.new(statement.subject, self)
  end
end

#installationsObject



34
35
36
37
38
# File 'lib/models/ontology.rb', line 34

def installations
  query([nil, RDF.type, LV.Installation]).map do |statement|
    Installation.new(statement.subject, self)
  end
end

#load_and_process_n3(n3_input) ⇒ Object



22
23
24
25
# File 'lib/models/ontology.rb', line 22

def load_and_process_n3(n3_input)
  (@n3_inputs ||= []) << n3_input
  refresh
end

#propertiesObject



52
53
54
55
56
# File 'lib/models/ontology.rb', line 52

def properties
  query([nil, RDF.type, LV.Property]).map do |statement|
    Property.new(statement.subject, self)
  end
end

#refreshObject



62
63
64
# File 'lib/models/ontology.rb', line 62

def refresh
  @n3_inputs.each { |input| Reasoner.new(self).load_and_process_n3(input) }
end

#scenariosObject



46
47
48
49
50
# File 'lib/models/ontology.rb', line 46

def scenarios
  query([nil, RDF.type, LV.Scenario]).map do |statement|
    Scenario.new(statement.subject, self)
  end
end