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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7975b117f28b3b97b7280d00cfa2ed0ed2ed5f88
4
- data.tar.gz: e6afbc109997f137b98fa31d54041a1f51bd0b97
3
+ metadata.gz: 72e29c0014b3114f458188576bd4dff663b229f5
4
+ data.tar.gz: b09b410f07d55180399626468d2238d0262171f3
5
5
  SHA512:
6
- metadata.gz: db40192af1d3e44978dce73891cca821f5a00cff05b1d6b42a029afb2e3c4d7728f14920ca68f767e1111742faa99826ff7100a6b7fbbc171f4c785a636bde61
7
- data.tar.gz: 04bbf2ca4ba64e812318d6b1b20a79210baf416ce8d3872d27eb8107af0f6e72498274dc40af6d46e6cace603901ad22a792eb38ea85bdc5802383579e82bc71
6
+ metadata.gz: 0ae5a7b702617b06ee831a41a367f9c0a096933ebc4c3258792b0ac292e13040fafb732d10aa9e288fcb4b47864ad34f37aa75ee15670ae90c40501042515e18
7
+ data.tar.gz: 206f32e422a9e239d7c63560e4aeeeb7cd284acd90e8631d66e51aa32a5d211f2963da69994da57d7bf3aeec9eabbf62f7cedf8c4ea69d4283d857fc1daa681b
data/README.md CHANGED
@@ -4,13 +4,6 @@ CASE (Context-aware Software Ecosystem)
4
4
  Evaluation of application models
5
5
  --------------------------------
6
6
 
7
- Supplementary evaluation for the paper **Semantic Model of Variability and Capabilities of IoT Applications for Embedded Software Ecosystems**.
8
-
9
- # Browsing the sample scenarios
10
-
11
- To investigate the tested application models and scenarios, see the folder
12
- [spec/use_cases](spec/use_cases).
13
-
14
7
  # Installation
15
8
 
16
9
  1. Install the Eye reasoner
@@ -21,7 +14,3 @@ To investigate the tested application models and scenarios, see the folder
21
14
  2. Install [Ruby](https://www.ruby-lang.org/en/) version 2.x.x
22
15
  3. Run in inside a folder for this repository: `gem install bundler`
23
16
  4. Run in inside a folder for this repository: `bundle install`
24
-
25
- # Running the specs
26
-
27
- To run the tests, simply execute `rspec` in the folder of this repository.
data/case_model.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'case_model'
3
- s.version = '0.0.1'
3
+ s.version = '0.0.4'
4
4
  s.date = '2016-01-28'
5
5
  s.summary = 'Resolver for the CASE ecosystem application models'
6
6
  s.description = 'Built for the Context-Aware Software Ecosystem. Resolves application model requirements using semantic reasoning.'
@@ -12,6 +12,11 @@ Gem::Specification.new do |s|
12
12
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
13
13
  s.require_paths = ["lib"]
14
14
 
15
+ s.add_runtime_dependency 'rdf-n3', '1.99.0'
16
+ s.add_runtime_dependency 'rdf-vocab', '0.8.7.1'
17
+ s.add_runtime_dependency 'webmock', '1.22.3'
18
+ s.add_runtime_dependency 'rest-client', '1.8.0'
19
+
15
20
  s.homepage = 'https://github.com/case-iot/app_model'
16
21
  s.license = 'MIT'
17
22
  end
data/lib/models/action.rb CHANGED
@@ -1,48 +1,50 @@
1
1
  require_relative '../services/question_references'
2
2
 
3
- class Action
4
- attr_reader :query
3
+ module Model
4
+ class Action
5
+ attr_reader :query
5
6
 
6
- include QuestionReferences
7
+ include QuestionReferences
7
8
 
8
- def initialize(node, repository)
9
- @query = NodeQuery.new(node, repository)
10
- end
9
+ def initialize(node, repository)
10
+ @query = NodeQuery.new(node, repository)
11
+ end
11
12
 
12
- def description
13
- query.value(LV.description)
14
- end
13
+ def description
14
+ query.value(LV.description)
15
+ end
15
16
 
16
- def requirements
17
- list = RDF::List.new(query.value(LV.requirement), query.repository)
18
- list.map { |node| Requirement.new(node, query.repository) }
19
- end
17
+ def requirements
18
+ list = RDF::List.new(query.value(LV.requirement), query.repository)
19
+ list.map { |node| Requirement.new(node, query.repository) }
20
+ end
20
21
 
21
- def failed_requirements
22
- requirements.select {|r| not r.satisfied? }
23
- end
22
+ def failed_requirements
23
+ requirements.select {|r| not r.satisfied? }
24
+ end
24
25
 
25
- def compatible?
26
- not failed_requirements.any?
27
- end
26
+ def compatible?
27
+ not failed_requirements.any?
28
+ end
28
29
 
29
- def questions
30
- q = []
31
- q << question if has_question?
30
+ def questions
31
+ q = []
32
+ q << question if has_question?
32
33
 
33
- with_question = requirements.select { |r| r.has_question? }
34
- q + with_question.map { |r| r.question }
35
- end
34
+ with_question = requirements.select { |r| r.has_question? }
35
+ q + with_question.map { |r| r.question }
36
+ end
36
37
 
37
- def open_questions
38
- questions.select { |q| not q.has_answer? }
39
- end
38
+ def open_questions
39
+ questions.select { |q| not q.has_answer? }
40
+ end
40
41
 
41
- def execution
42
- ActionExecution.new(query.value(LV.executes), query.repository)
43
- end
42
+ def execution
43
+ ActionExecution.new(query.value(LV.executes), query.repository)
44
+ end
44
45
 
45
- def effect
46
- StateChange.new(query.value(LV.effect), query.repository)
46
+ def effect
47
+ StateChange.new(query.value(LV.effect), query.repository)
48
+ end
47
49
  end
48
50
  end
data/lib/models/answer.rb CHANGED
@@ -1,25 +1,29 @@
1
- module Answer
2
- def self.create(reply_type, node, repository)
3
- case reply_type
4
- when :location
5
- Location.new(node, repository)
6
- when :temperature
7
- Temperature.new(node, repository)
8
- when :select
9
- Selection.new(node, repository)
10
- else
11
- nil
1
+ module Model
2
+ module Answer
3
+ def self.create(reply_type, node, repository)
4
+ case reply_type
5
+ when :number
6
+ Number.new(node, repository)
7
+ when :location
8
+ Location.new(node, repository)
9
+ when :temperature
10
+ Temperature.new(node, repository)
11
+ when :select
12
+ Selection.new(node, repository)
13
+ else
14
+ nil
15
+ end
12
16
  end
13
- end
14
17
 
15
- def reply_type
16
- question.reply_type
17
- end
18
+ def reply_type
19
+ question.reply_type
20
+ end
18
21
 
19
- def question
20
- node = query.value(QV.answers)
21
- return nil if node.nil?
22
+ def question
23
+ node = query.value(QV.answers)
24
+ return nil if node.nil?
22
25
 
23
- Question.new(node, query.repository)
26
+ Question.new(node, query.repository)
27
+ end
24
28
  end
25
29
  end
@@ -1,57 +1,70 @@
1
- class Application
2
- attr_reader :query
1
+ module Model
2
+ class Application
3
+ attr_reader :query
3
4
 
4
- def initialize(node, repository)
5
- @query = NodeQuery.new(node, repository)
6
- end
5
+ def initialize(node, repository)
6
+ @query = NodeQuery.new(node, repository)
7
+ end
7
8
 
8
- def name
9
- if query.value_exists?(RDF::Vocab::FOAF.name)
10
- query.value(RDF::Vocab::FOAF.name)
11
- else
12
- query.value(LV.name)
9
+ def uri
10
+ query.node_uri
13
11
  end
14
- end
15
12
 
16
- def description
17
- query.value(LV.description)
18
- end
13
+ def name
14
+ if query.value_exists?(RDF::Vocab::FOAF.name)
15
+ query.value(RDF::Vocab::FOAF.name)
16
+ else
17
+ query.value(LV.name)
18
+ end
19
+ end
19
20
 
20
- def questions
21
- list = repo.query([nil, RDF.type, QV.Question]).map { |s| s.subject }
22
- list.map { |node| Question.new(node, repo) }
23
- end
21
+ def description
22
+ query.value(LV.description)
23
+ end
24
24
 
25
- def open_questions
26
- questions.select { |q| not q.has_answer? }
27
- end
25
+ def questions
26
+ list = repo.query([nil, RDF.type, QV.Question]).map { |s| s.subject }
27
+ list.map { |node| Question.new(node, repo) }
28
+ end
28
29
 
29
- def question_with_text(text)
30
- questions.find { |q| q.text == text }
31
- end
30
+ def open_questions
31
+ questions.select { |q| not q.has_answer? }
32
+ end
32
33
 
33
- def requirements
34
- list = repo.query([nil, RDF.type, QV.Requirement]).map { |s| s.subject }
35
- list.map { |node| Requirement.new(node, repo) }
36
- end
34
+ def question_with_text(text)
35
+ questions.find { |q| q.text == text }
36
+ end
37
37
 
38
- def requirement_with_description(description)
39
- requirements.find { |r| r.description == description }
40
- end
38
+ def requirements
39
+ list = repo.query([nil, RDF.type, QV.Requirement]).map { |s| s.subject }
40
+ list.map { |node| Requirement.new(node, repo) }
41
+ end
41
42
 
42
- def deployment_plans
43
- query.values(LV.hasDeploymentPlan).map do |node|
44
- DeploymentPlan.new(node, repo)
43
+ def requirement_with_description(description)
44
+ requirements.find { |r| r.description == description }
45
45
  end
46
- end
47
46
 
48
- def deployment_plan_with_description(description)
49
- deployment_plans.find { |a| a.description == description }
50
- end
47
+ def deployment_plans
48
+ query.values(LV.hasDeploymentPlan).map do |node|
49
+ DeploymentPlan.new(node, repo)
50
+ end
51
+ end
51
52
 
52
- private
53
+ def deployment_plan_with_description(description)
54
+ deployment_plans.find { |a| a.description == description }
55
+ end
56
+
57
+ def category
58
+ value = query.value(LV.category)
59
+ return nil if value.nil?
60
+ t = value.to_s.remove LV.prefix
61
+ Helper.underscore(t).to_sym
62
+ end
53
63
 
54
- def repo
55
- query.repository
64
+ private
65
+
66
+ def repo
67
+ query.repository
68
+ end
56
69
  end
57
70
  end
@@ -1,23 +1,51 @@
1
- class Capability
2
- attr_reader :query
1
+ module Model
2
+ class Capability
3
+ attr_reader :query
3
4
 
4
- def initialize(node, repository)
5
- @query = NodeQuery.new(node, repository)
6
- end
5
+ def initialize(node, repository)
6
+ @query = NodeQuery.new(node, repository)
7
+ end
7
8
 
8
- def description
9
- query.value(LV.description)
10
- end
9
+ def description
10
+ query.value(LV.description)
11
+ end
11
12
 
12
- def actuators
13
- query.values(LV.actuator).map do |node|
14
- Device.new node, query.repository
13
+ def value
14
+ query.value(LV.value).to_s if query.value_exists?(LV.value)
15
+ end
16
+
17
+ def type
18
+ value = query.value(RDF.type)
19
+ return nil if value.nil?
20
+ t = value.to_s.remove LV.prefix
21
+ Helper.underscore(t).to_sym
22
+ end
23
+
24
+ def device
25
+ device_node = query.value(LV.device)
26
+ Device.new device_node, query.repository if device_node
27
+ end
28
+
29
+ def property
30
+ node = query.value(LV.property)
31
+ Property.new node, query.repository if node
32
+ end
33
+
34
+ def question
35
+ node = query.value(LV.question)
36
+ Question.new node, query.repository if node
37
+ end
38
+
39
+ def actuators
40
+ query.values(LV.actuator).map do |node|
41
+ Device.new node, query.repository
42
+ end
15
43
  end
16
- end
17
44
 
18
- def sensors
19
- query.values(LV.sensor).map do |node|
20
- Device.new node, query.repository
45
+ def sensors
46
+ query.values(LV.sensor).map do |node|
47
+ Device.new node, query.repository
48
+ end
21
49
  end
22
50
  end
23
51
  end
@@ -1,44 +1,51 @@
1
1
  require_relative '../services/question_references'
2
2
 
3
- class DeploymentPlan
4
- attr_reader :query
3
+ module Model
4
+ class DeploymentPlan
5
+ attr_reader :query
5
6
 
6
- include QuestionReferences
7
+ include QuestionReferences
7
8
 
8
- def initialize(node, repository)
9
- @query = NodeQuery.new(node, repository)
10
- end
9
+ def initialize(node, repository)
10
+ @query = NodeQuery.new(node, repository)
11
+ end
11
12
 
12
- def description
13
- query.value(LV.description)
14
- end
13
+ def description
14
+ query.value(LV.description)
15
+ end
15
16
 
16
- def host
17
- nil unless query.value_exists?(LV.host)
18
- EcosystemHost.new(query.value(LV.host), query.repository)
19
- end
17
+ def host
18
+ return nil unless query.value_exists?(LV.host)
19
+ EcosystemHost.new(query.value(LV.host), query.repository)
20
+ end
20
21
 
21
- def arguments
22
- node = query.value(LV.arguments)
23
- arg_query = NodeQuery.new(node, query.repository)
22
+ def arguments
23
+ node = query.value(LV.arguments)
24
+ arg_query = NodeQuery.new(node, query.repository)
24
25
 
25
- if arg_query.value_exists?(RDFV.first)
26
- RDF::List.new(node, query.repository)
27
- else
28
- arg_query.predicates_and_objects
26
+ if arg_query.value_exists?(RDFV.first)
27
+ RDF::List.new(node, query.repository)
28
+ else
29
+ arg_query.predicates_and_objects
30
+ end
29
31
  end
30
- end
31
32
 
32
- def deployment_plans
33
- query.values(LV.hasDeploymentPlan).map do |node|
34
- DeploymentPlan.new(node, query.repository)
33
+ def deployment_plans
34
+ query.values(LV.hasDeploymentPlan).map do |node|
35
+ DeploymentPlan.new(node, query.repository)
36
+ end
37
+ end
38
+
39
+ def properties
40
+ query.values(LV.property).map do |node|
41
+ Property.new(node, query.repository)
42
+ end
35
43
  end
36
- end
37
44
 
38
- def capabilities
39
- list = RDF::List.new(query.value(LV.capabilities), query.repository)
40
- list.map do |node|
41
- Capability.new(node, query.repository)
45
+ def capabilities
46
+ query.values(LV.capability).map do |node|
47
+ Capability.new(node, query.repository)
48
+ end
42
49
  end
43
50
  end
44
51
  end
data/lib/models/device.rb CHANGED
@@ -1,26 +1,32 @@
1
- class Device
2
- attr_reader :query
1
+ module Model
2
+ class Device
3
+ attr_reader :query
3
4
 
4
- def initialize(node, repository)
5
- @query = NodeQuery.new(node, repository)
6
- end
5
+ def initialize(node, repository)
6
+ @query = NodeQuery.new(node, repository)
7
+ end
7
8
 
8
- def manufacturer_name
9
- query.value(LV.manufacturerName)
10
- end
9
+ def uri
10
+ query.node_uri
11
+ end
11
12
 
12
- def description
13
- query.value(LV.description)
14
- end
13
+ def manufacturer_name
14
+ query.value(LV.manufacturerName)
15
+ end
15
16
 
16
- def location
17
- node = query.value(LV.locatedAt)
18
- return nil if node.nil?
17
+ def description
18
+ query.value(LV.description)
19
+ end
19
20
 
20
- Location.new(node, query.repository)
21
- end
21
+ def location
22
+ node = query.value(LV.locatedAt)
23
+ return nil if node.nil?
24
+
25
+ Location.new(node, query.repository)
26
+ end
22
27
 
23
- def node
24
- query.node
28
+ def node
29
+ query.node
30
+ end
25
31
  end
26
32
  end
@@ -1,5 +1,7 @@
1
- class EcosystemHost < Device
2
- def initialize(node, repository)
3
- super(node, repository)
1
+ module Model
2
+ class EcosystemHost < Device
3
+ def initialize(node, repository)
4
+ super(node, repository)
5
+ end
4
6
  end
5
7
  end
@@ -1,27 +1,29 @@
1
1
  require 'rest-client'
2
2
 
3
- class HttpRequest
4
- attr_reader :query
3
+ module Model
4
+ class HttpRequest
5
+ attr_reader :query
5
6
 
6
- def initialize(node, repository)
7
- @query = NodeQuery.new(node, repository)
8
- end
7
+ def initialize(node, repository)
8
+ @query = NodeQuery.new(node, repository)
9
+ end
9
10
 
10
- def uri
11
- query.value(HttpVocabulary.request_uri)
12
- end
11
+ def uri
12
+ query.value(HttpVocabulary.request_uri)
13
+ end
13
14
 
14
- def body
15
- query.value(HttpVocabulary.body)
16
- end
15
+ def body
16
+ query.value(HttpVocabulary.body)
17
+ end
17
18
 
18
- def method_name
19
- query.value(HttpVocabulary.method_name)
20
- end
19
+ def method_name
20
+ query.value(HttpVocabulary.method_name)
21
+ end
21
22
 
22
- def execute
23
- raise "Unsupported method #{method_name}" unless method_name == 'POST'
24
- RestClient.post(uri.to_s, body.to_s)
25
- true
23
+ def execute
24
+ raise "Unsupported method #{method_name}" unless method_name == 'POST'
25
+ RestClient.post(uri.to_s, body.to_s)
26
+ true
27
+ end
26
28
  end
27
29
  end
@@ -0,0 +1,46 @@
1
+ module Model
2
+ class Installation
3
+ attr_reader :query
4
+
5
+ def initialize(node, repository)
6
+ @query = NodeQuery.new(node, repository)
7
+ end
8
+
9
+ def type
10
+ query.value(LV.type).to_s
11
+ end
12
+
13
+ def name
14
+ query.value(LV.name)
15
+ end
16
+
17
+ def description
18
+ query.value(LV.description)
19
+ end
20
+
21
+ def category
22
+ value = query.value(LV.category)
23
+ return nil if value.nil?
24
+ t = value.to_s.remove LV.prefix
25
+ Helper.underscore(t).to_sym
26
+ end
27
+
28
+ def used_devices
29
+ query.values(LV.uses).map do |node|
30
+ InstallationUsedDevice.new(node, query.repository)
31
+ end
32
+ end
33
+
34
+ def questions
35
+ query.values(LV.question).map do |node|
36
+ Question.new(node, query.repository)
37
+ end
38
+ end
39
+
40
+ def properties
41
+ query.values(LV.property).map do |node|
42
+ Property.new(node, query.repository)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,18 @@
1
+ module Model
2
+ class InstallationUsedDevice
3
+ attr_reader :query
4
+
5
+ def initialize(node, repository)
6
+ @query = NodeQuery.new(node, repository)
7
+ end
8
+
9
+ def device
10
+ return nil unless query.value_exists?(LV.target)
11
+ Device.new(query.value(LV.target), query.repository)
12
+ end
13
+
14
+ def role
15
+ query.value(LV.role)
16
+ end
17
+ end
18
+ end
@@ -1,17 +1,19 @@
1
- class Location
2
- attr_reader :query
1
+ module Model
2
+ class Location
3
+ attr_reader :query
3
4
 
4
- include Answer
5
+ include Answer
5
6
 
6
- def initialize(node, repository)
7
- @query = NodeQuery.new(node, repository)
8
- end
7
+ def initialize(node, repository)
8
+ @query = NodeQuery.new(node, repository)
9
+ end
9
10
 
10
- def name
11
- query.value(LV.locationName)
12
- end
11
+ def name
12
+ query.value(LV.locationName)
13
+ end
13
14
 
14
- def name=(value)
15
- query.set_value(LV.locationName, value)
15
+ def name=(value)
16
+ query.set_value(LV.locationName, value)
17
+ end
16
18
  end
17
19
  end