case_model 0.0.1 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -11
- data/case_model.gemspec +6 -1
- data/lib/models/action.rb +35 -33
- data/lib/models/answer.rb +23 -19
- data/lib/models/application.rb +54 -41
- data/lib/models/capability.rb +43 -15
- data/lib/models/deployment_plan.rb +36 -29
- data/lib/models/device.rb +24 -18
- data/lib/models/ecosystem_host.rb +5 -3
- data/lib/models/http_request.rb +20 -18
- data/lib/models/installation.rb +46 -0
- data/lib/models/installation_used_device.rb +18 -0
- data/lib/models/location.rb +13 -11
- data/lib/models/number.rb +27 -0
- data/lib/models/ontology.rb +54 -33
- data/lib/models/property.rb +46 -0
- data/lib/models/question.rb +42 -37
- data/lib/models/question_reply_type.rb +15 -11
- data/lib/models/requirement.rb +16 -10
- data/lib/models/scenario.rb +30 -0
- data/lib/models/selection.rb +25 -23
- data/lib/models/state_change.rb +15 -13
- data/lib/models/temperature.rb +13 -11
- data/lib/ontology/http_vocabulary.rb +14 -12
- data/lib/ontology/local_vocabulary.rb +24 -18
- data/lib/ontology/math_vocabulary.rb +13 -11
- data/lib/ontology/rdf_vocabulary.rb +10 -8
- data/lib/ontology/state_vocabulary.rb +8 -6
- data/lib/services/application_by_capability_finder.rb +29 -27
- data/lib/services/eye_serializer.rb +17 -15
- data/lib/services/helper.rb +12 -0
- data/lib/services/node_builder.rb +26 -24
- data/lib/services/node_query.rb +46 -40
- data/lib/services/reasoner.rb +60 -58
- data/spec/spec_helper.rb +2 -0
- metadata +64 -2
@@ -0,0 +1,27 @@
|
|
1
|
+
module Model
|
2
|
+
class Number
|
3
|
+
attr_reader :query
|
4
|
+
|
5
|
+
include Answer
|
6
|
+
|
7
|
+
def initialize(node, repository)
|
8
|
+
@query = NodeQuery.new(node, repository)
|
9
|
+
end
|
10
|
+
|
11
|
+
def value
|
12
|
+
query.value(LV.value)
|
13
|
+
end
|
14
|
+
|
15
|
+
def value=(value)
|
16
|
+
query.set_value(LV.value, value)
|
17
|
+
end
|
18
|
+
|
19
|
+
def min_value
|
20
|
+
question.query.value(LV.minValue)
|
21
|
+
end
|
22
|
+
|
23
|
+
def max_value
|
24
|
+
question.query.value(LV.maxValue)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/models/ontology.rb
CHANGED
@@ -3,50 +3,71 @@ require 'rdf/vocab'
|
|
3
3
|
|
4
4
|
require_relative '../services/repository_proxy'
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
module Model
|
7
|
+
class Ontology
|
8
|
+
attr_reader :repository
|
8
9
|
|
9
|
-
|
10
|
+
include RepositoryProxy
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
def self.from_n3(n3_input)
|
13
|
+
Ontology.new(RDF::Repository.new, n3_input)
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
def initialize(repository, n3_input = nil)
|
17
|
+
@repository = repository
|
18
|
+
load_and_process_n3 n3_input if n3_input
|
19
|
+
# initialize_state
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
def load_and_process_n3(n3_input)
|
23
|
+
(@n3_inputs ||= []) << n3_input
|
24
|
+
refresh
|
25
|
+
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
def applications
|
28
|
+
query([nil, RDF.type, LV.Application]).
|
29
|
+
map(&:subject).uniq.map do |subject|
|
30
|
+
Application.new(subject, self)
|
31
|
+
end
|
29
32
|
end
|
30
|
-
end
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
34
|
+
def installations
|
35
|
+
query([nil, RDF.type, LV.Installation]).map do |statement|
|
36
|
+
Installation.new(statement.subject, self)
|
37
|
+
end
|
35
38
|
end
|
36
|
-
end
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
-
|
40
|
+
def devices
|
41
|
+
query([nil, RDF.type, LV.Device]).map do |statement|
|
42
|
+
Device.new(statement.subject, self)
|
43
|
+
end
|
44
|
+
end
|
41
45
|
|
42
|
-
|
43
|
-
|
44
|
-
|
46
|
+
def scenarios
|
47
|
+
query([nil, RDF.type, LV.Scenario]).map do |statement|
|
48
|
+
Scenario.new(statement.subject, self)
|
49
|
+
end
|
50
|
+
end
|
45
51
|
|
46
|
-
|
52
|
+
def properties
|
53
|
+
query([nil, RDF.type, LV.Property]).map do |statement|
|
54
|
+
Property.new(statement.subject, self)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def device_with_description(description)
|
59
|
+
devices.find { |d| d.description == description }
|
60
|
+
end
|
47
61
|
|
48
|
-
|
49
|
-
|
50
|
-
|
62
|
+
def refresh
|
63
|
+
@n3_inputs.each { |input| Reasoner.new(self).load_and_process_n3(input) }
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
## load an empty State formula in case there are some StateChange statements
|
69
|
+
def initialize_state
|
70
|
+
load_and_process_n3 '{ <http://example.com/x> <http://example.com/y> <http://example.com/z>.} a <http://purl.org/restdesc/states#State>.'
|
71
|
+
end
|
51
72
|
end
|
52
73
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Model
|
2
|
+
class Property
|
3
|
+
attr_reader :query
|
4
|
+
|
5
|
+
def initialize(node, repository)
|
6
|
+
@query = NodeQuery.new(node, repository)
|
7
|
+
end
|
8
|
+
|
9
|
+
def uri
|
10
|
+
if query.value_exists?(LV.type)
|
11
|
+
query.value(LV.type).to_s
|
12
|
+
else
|
13
|
+
query.node_uri
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def description
|
18
|
+
query.value(LV.description)
|
19
|
+
end
|
20
|
+
|
21
|
+
def unit
|
22
|
+
val = query.value(LV.unit)
|
23
|
+
val.to_s if val
|
24
|
+
end
|
25
|
+
|
26
|
+
def value
|
27
|
+
val = query.value(LV.value)
|
28
|
+
val.to_s if val
|
29
|
+
end
|
30
|
+
|
31
|
+
def maximum
|
32
|
+
val = query.value(LV.maximum)
|
33
|
+
val.to_s if val
|
34
|
+
end
|
35
|
+
|
36
|
+
def minimum
|
37
|
+
val = query.value(LV.minimum)
|
38
|
+
val.to_s if val
|
39
|
+
end
|
40
|
+
|
41
|
+
def device
|
42
|
+
device_node = query.value(LV.device)
|
43
|
+
Device.new device_node, query.repository if device_node
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/models/question.rb
CHANGED
@@ -1,51 +1,56 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module Model
|
2
|
+
class Question
|
3
|
+
attr_reader :query
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
5
|
+
def initialize(node, repository)
|
6
|
+
@query = NodeQuery.new(node, repository)
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
def uri
|
10
|
+
query.node_uri
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
def text
|
14
|
+
query.value(QV.text).to_s
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
def reply_type
|
18
|
+
QuestionReplyType.to_sym(query)
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
return nil if node.nil?
|
21
|
+
def has_answer?
|
22
|
+
query.value_exists?(QV.has_answer)
|
23
|
+
end
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
# returns an existing one or nil if there is no
|
26
|
+
def answer
|
27
|
+
node = query.value(QV.has_answer)
|
28
|
+
return nil if node.nil?
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
-
answer || create_answer
|
31
|
-
end
|
30
|
+
Answer.create(reply_type, node, query.repository)
|
31
|
+
end
|
32
32
|
|
33
|
-
|
33
|
+
# creates a new answer or returns an existing one
|
34
|
+
def answer!
|
35
|
+
answer || create_answer
|
36
|
+
end
|
34
37
|
|
35
|
-
|
38
|
+
private
|
36
39
|
|
37
|
-
|
38
|
-
node = generate_answer_node
|
39
|
-
repository << [ node, RDF.type, QV.answer_type ]
|
40
|
-
answer_query = NodeQuery.new(node, repository)
|
41
|
-
answer_query.set_value(QV.answers, query.node)
|
42
|
-
query.set_value(QV.has_answer, node)
|
40
|
+
def repository; query.repository; end
|
43
41
|
|
44
|
-
|
45
|
-
|
42
|
+
def create_answer
|
43
|
+
node = generate_answer_node
|
44
|
+
repository << [ node, RDF.type, QV.answer_type ]
|
45
|
+
repository << [ node, QV.answers, query.node ]
|
46
|
+
repository << [ query.node, QV.has_answer, node ]
|
47
|
+
|
48
|
+
answer
|
49
|
+
end
|
46
50
|
|
47
|
-
|
48
|
-
|
49
|
-
|
51
|
+
def generate_answer_node
|
52
|
+
question_uri_hash = query.node.to_s.hash.to_s
|
53
|
+
('answer' + question_uri_hash).to_sym
|
54
|
+
end
|
50
55
|
end
|
51
56
|
end
|
@@ -1,14 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
1
|
+
module Model
|
2
|
+
class QuestionReplyType
|
3
|
+
def self.to_sym(query)
|
4
|
+
case query.value(QV.replyType)
|
5
|
+
when QV.Number
|
6
|
+
:number
|
7
|
+
when QV.Location
|
8
|
+
:location
|
9
|
+
when QV.Temperature
|
10
|
+
:temperature
|
11
|
+
when QV.Select
|
12
|
+
:select
|
13
|
+
else
|
14
|
+
nil
|
15
|
+
end
|
12
16
|
end
|
13
17
|
end
|
14
18
|
end
|
data/lib/models/requirement.rb
CHANGED
@@ -1,17 +1,23 @@
|
|
1
1
|
require_relative '../services/question_references'
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
module Model
|
4
|
+
class Requirement
|
5
|
+
attr_reader :query
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
def initialize(node, repository)
|
8
|
+
@query = NodeQuery.new(node, repository)
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
def uri
|
12
|
+
query.node_uri
|
13
|
+
end
|
14
|
+
|
15
|
+
def description
|
16
|
+
query.value(LV.description)
|
17
|
+
end
|
13
18
|
|
14
|
-
|
15
|
-
|
19
|
+
def satisfied?
|
20
|
+
query.value(LV.satisfied) == true
|
21
|
+
end
|
16
22
|
end
|
17
23
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Model
|
2
|
+
class Scenario
|
3
|
+
attr_reader :query
|
4
|
+
|
5
|
+
def initialize(node, repository)
|
6
|
+
@query = NodeQuery.new(node, repository)
|
7
|
+
end
|
8
|
+
|
9
|
+
def description
|
10
|
+
query.value(LV.description)
|
11
|
+
end
|
12
|
+
|
13
|
+
def value(key)
|
14
|
+
camelized_key = camelize(key.to_s)
|
15
|
+
query.value(LV.uri_for(camelized_key)).to_s
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def camelize(str)
|
21
|
+
str.split('_').each_with_index.map do |part, i|
|
22
|
+
if i == 0
|
23
|
+
part
|
24
|
+
else
|
25
|
+
part.capitalize
|
26
|
+
end
|
27
|
+
end.join
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/models/selection.rb
CHANGED
@@ -1,32 +1,34 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module Model
|
2
|
+
class Selection
|
3
|
+
attr_reader :query
|
3
4
|
|
4
|
-
|
5
|
+
include Answer
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
def initialize(node, repository)
|
8
|
+
@query = NodeQuery.new(node, repository)
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
def options
|
12
|
+
if question.query.value_exists?(QV.options)
|
13
|
+
RDF::List.new(question.query.value(QV.options), query.repository)
|
14
|
+
elsif question.query.value_exists?(QV.option)
|
15
|
+
question.query.values(QV.option)
|
16
|
+
else
|
17
|
+
nil
|
18
|
+
end
|
17
19
|
end
|
18
|
-
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
def selected
|
22
|
+
query.value(LV.selected)
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
def selected=(value)
|
26
|
+
# in case it is an array, store all the answers
|
27
|
+
if value.is_a? Array
|
28
|
+
value.each { |v| query.set_value(LV.selected, v, false) }
|
29
|
+
else
|
30
|
+
query.set_value(LV.selected, value)
|
31
|
+
end
|
30
32
|
end
|
31
33
|
end
|
32
34
|
end
|
data/lib/models/state_change.rb
CHANGED
@@ -1,19 +1,21 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module Model
|
2
|
+
class StateChange
|
3
|
+
attr_reader :query
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
5
|
+
def initialize(node, repository)
|
6
|
+
@query = NodeQuery.new(node, repository)
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
def apply
|
10
|
+
new_repo = query.repository.clone
|
11
|
+
new_repo.load_and_process_n3(state_rules)
|
12
|
+
new_repo
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
+
private
|
15
16
|
|
16
|
-
|
17
|
-
|
17
|
+
def state_rules
|
18
|
+
File.read(File.dirname(__FILE__) + '/../descriptions/states.n3')
|
19
|
+
end
|
18
20
|
end
|
19
21
|
end
|
data/lib/models/temperature.rb
CHANGED
@@ -1,17 +1,19 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module Model
|
2
|
+
class Temperature
|
3
|
+
attr_reader :query
|
3
4
|
|
4
|
-
|
5
|
+
include Answer
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
def initialize(node, repository)
|
8
|
+
@query = NodeQuery.new(node, repository)
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
def in_celsius
|
12
|
+
query.value(LV.in_celsius)
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
15
|
+
def in_celsius=(value)
|
16
|
+
query.set_value(LV.in_celsius, value)
|
17
|
+
end
|
16
18
|
end
|
17
19
|
end
|
@@ -1,17 +1,19 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module Model
|
2
|
+
class HttpVocabulary
|
3
|
+
def self.method_missing(name, *arguments, &block)
|
4
|
+
uri_for(name)
|
5
|
+
end
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
def self.method_name
|
8
|
+
uri_for('methodName')
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
def self.request_uri
|
12
|
+
uri_for('requestURI')
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
15
|
+
def self.uri_for(name)
|
16
|
+
RDF::URI("http://www.w3.org/2011/http##{name}")
|
17
|
+
end
|
16
18
|
end
|
17
19
|
end
|
@@ -1,26 +1,32 @@
|
|
1
1
|
require 'rdf'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
module Model
|
4
|
+
class LocalVocabulary
|
5
|
+
def self.method_missing(name, *arguments, &block)
|
6
|
+
uri_for(name)
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
def self.name
|
10
|
+
uri_for('name')
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
def self.question_type
|
14
|
+
uri_for('question')
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
def self.answer_type
|
18
|
+
uri_for('answer')
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
21
|
+
def self.uri_for(name)
|
22
|
+
RDF::URI("#{prefix}#{name}")
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.prefix
|
26
|
+
'http://matus.tomlein.org/case/'
|
27
|
+
end
|
22
28
|
end
|
23
|
-
end
|
24
29
|
|
25
|
-
LV = LocalVocabulary
|
26
|
-
QV = LocalVocabulary
|
30
|
+
LV = LocalVocabulary
|
31
|
+
QV = LocalVocabulary
|
32
|
+
end
|
@@ -1,15 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module Model
|
2
|
+
class MathVocabulary
|
3
|
+
def self.method_missing(name, *arguments, &block)
|
4
|
+
uri_for(name)
|
5
|
+
end
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
def self.less_than
|
8
|
+
uri_for('lessThan')
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
-
|
11
|
+
def self.uri_for(name)
|
12
|
+
RDF::URI("http://www.w3.org/2000/10/swap/math##{name}")
|
13
|
+
end
|
12
14
|
end
|
13
|
-
end
|
14
15
|
|
15
|
-
MV = MathVocabulary
|
16
|
+
MV = MathVocabulary
|
17
|
+
end
|
@@ -1,11 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module Model
|
2
|
+
class RDFVocabulary
|
3
|
+
def self.method_missing(name, *arguments, &block)
|
4
|
+
uri_for(name)
|
5
|
+
end
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
def self.uri_for(name)
|
8
|
+
RDF::URI("http://www.w3.org/1999/02/22-rdf-syntax-ns##{name}")
|
9
|
+
end
|
8
10
|
end
|
9
|
-
end
|
10
11
|
|
11
|
-
RDFV = RDFVocabulary
|
12
|
+
RDFV = RDFVocabulary
|
13
|
+
end
|
@@ -1,9 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module Model
|
2
|
+
class StateVocabulary
|
3
|
+
def self.method_missing(name, *arguments, &block)
|
4
|
+
uri_for(name)
|
5
|
+
end
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
def self.uri_for(name)
|
8
|
+
RDF::URI("http://matus.tomlein.org/case/#{name}")
|
9
|
+
end
|
8
10
|
end
|
9
11
|
end
|