rdf_process 0.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9682718b89d99227dd10e26890c8a0a51dfd074b
4
+ data.tar.gz: c37586033dea21fb3fe4c3917c826ef8eaadfdd2
5
+ SHA512:
6
+ metadata.gz: 731e070b397571a745b1983b95d676444565e863e38b217eea6a0f6e19fcf9e1bf9b4ff6687651621ab11aa28b9825652cae73f355558c3644e2357824f8607e
7
+ data.tar.gz: 712522f386aa0a3273603951d5b9f135b8f3864dd7d3eb2a94262eff13af233212416e11393a9cf0fcd6a06977b8748a1804d0707c301c7a8881aa668cb0adea
@@ -0,0 +1,229 @@
1
+ module RdfProcessDefinitionLike
2
+
3
+ def calculate_depends_on(variables)
4
+ depended_steps = []
5
+ @runtime_list.each do |step|
6
+ if variables.include?(step[:output_vrbl]) then
7
+ depended_steps << step[:step_id]
8
+ end
9
+ end
10
+ depended_steps
11
+ end
12
+
13
+ class ProcessVariable
14
+ attr_reader :parameters
15
+
16
+ def initialize(type)
17
+ @parameters = {}
18
+ @parameters[:type] = type
19
+ end
20
+
21
+ def name(name)
22
+ @name = name
23
+ end
24
+
25
+ def getName
26
+ @name
27
+ end
28
+
29
+ def method_missing(method, arg)
30
+ @parameters[method] = arg
31
+ end
32
+
33
+ end
34
+
35
+ def addVariable(type, &block)
36
+ # puts self
37
+ variable = ProcessVariable.new(type)
38
+ variable.instance_eval(&block)
39
+ # proc = self
40
+ puts "check #{type}"
41
+ @runtime_variable_list[variable.getName] = variable.parameters
42
+ # puts @runtime_variable_list[variable.name]
43
+ end
44
+
45
+ class ProcessStep
46
+ attr_reader :type, :vrbls
47
+ attr_accessor :parameters
48
+
49
+ def initialize( type )
50
+ @parameters = {}
51
+ @parameters[:type] = type
52
+ @vrbls = {}
53
+ end
54
+
55
+ def depends_on(*args)
56
+ @parameters[:depends_on] = args
57
+ end
58
+
59
+ def sheets(*args)
60
+ @parameters[:sheets] = args
61
+ end
62
+
63
+ def output_vrbl(name)
64
+ @parameters[:output_vrbl] = name
65
+ @vrbls[name] = {:type => 'graph', :value => nil}
66
+ end
67
+
68
+ def input_vrbl(name)
69
+ @parameters[:input_vrbl] = name
70
+ @vrbls[name] = {:type => 'graph', :value => nil}
71
+ end
72
+
73
+ def file_vrbl(name, type=nil, value=nil)
74
+ @parameters[:file_vrbl] = name
75
+ @vrbls[name] = {:type => type, :value => value}
76
+ end
77
+
78
+ def input_file_vrbl(name, value=nil)
79
+ @parameters[:input_file_vrbl] = name
80
+ @vrbls[name] = {:type => "input_file", :value => value}
81
+ end
82
+
83
+ def output_file_vrbl(name, value=nil)
84
+ @parameters[:output_file_vrbl] = name
85
+ @vrbls[name] = {:type => "output_file", :value => value}
86
+ end
87
+
88
+ def filtr_vrbl(name, value=nil)
89
+ @parameters[:filtr_vrbl] = name
90
+ @vrbls[name] = {:type => "filtr", :value => value}
91
+ end
92
+
93
+ def prefix_vrbl(name, value=nil)
94
+ @parameters[:prefix_vrbl] = name
95
+ @vrbls[name] = {:type => "prefix", :value => value}
96
+ end
97
+
98
+ def method_missing(method, arg)
99
+ @parameters[method] = arg
100
+ end
101
+ end
102
+
103
+
104
+ def addStep( type, &block)
105
+ depends = []
106
+ step = ProcessStep.new(type)
107
+ puts "check #{type}"
108
+ step.instance_eval(&block)
109
+ depends << step.parameters[:input_vrbl] if step.parameters[:input_vrbl]
110
+ depends << step.parameters[:rule_graph_vrlb] if step.parameters[:rule_graph_vrlb]
111
+ depends << step.parameters[:presentation_vrlb] if step.parameters[:presentation_vrlb]
112
+ step.parameters[:depends_on] = calculate_depends_on(depends)
113
+ step.vrbls.each do |key, value|
114
+ if @runtime_variable_list[key] == nil then
115
+ addVariable value[:type] do
116
+ name key
117
+ value value[:value]
118
+ step_id step.parameters[:step_id]
119
+ end
120
+ end
121
+ end
122
+ # step.prepare
123
+ if type == "GraphLoader" then # GraphLoader step definition________________________________________________________________
124
+ if step.parameters[:file_vrbl] == nil then
125
+ ttl_file = step.parameters[:file]
126
+ unless File::exists?( ttl_file )
127
+ raise "Graph loader - ttl file: #{ttl_file} - doesn't exist"
128
+ end
129
+
130
+ runtime_code = -> {
131
+ @runtime_variable_list[step.parameters[:output_vrbl]][:value] = RDF::Graph.load(ttl_file)
132
+ puts "step graphloader"
133
+ }
134
+ else
135
+ ttl_file = step.parameters[:file_vrbl]
136
+ runtime_code = -> {
137
+ @runtime_variable_list[step.parameters[:output_vrbl]][:value] = RDF::Graph.load(@runtime_variable_list[ttl_file][:value])
138
+ puts "step graphloader"
139
+ }
140
+ end
141
+
142
+ elsif type == "Filtr" then # Filtr step definition________________________________________________________________________
143
+ runtime_code = -> {
144
+ puts @runtime_variable_list[step.parameters[:filtr_vrbl]][:value]
145
+ query = @runtime_variable_list["prefix"][:value] + @runtime_variable_list[step.parameters[:filtr_vrbl]][:value]
146
+ inputt = step.parameters[:input_vrbl]
147
+ puts step.parameters[:input_vrbl]
148
+ @runtime_variable_list[step.parameters[:output_vrbl]][:value] = SPARQL.execute(query, @runtime_variable_list[inputt][:value])
149
+ }
150
+
151
+ runtime_code = -> {
152
+ if step.parameters[:filtr_vrbl]
153
+ query2 = @runtime_variable_list[step.parameters[:filtr_vrbl]][:value]
154
+ puts @runtime_variable_list[step.parameters[:filtr_vrbl]][:value]
155
+ else
156
+ query2 = step.parameters[:filtr]
157
+ end
158
+ query = @runtime_variable_list["prefix"][:value] + query2
159
+ inputt = step.parameters[:input_vrbl]
160
+ puts step.parameters[:input_vrbl]
161
+ @runtime_variable_list[step.parameters[:output_vrbl]][:value] = SPARQL.execute(query, @runtime_variable_list[inputt][:value])
162
+ }
163
+
164
+ elsif type == "RdfToGraphviz" then # RdfToGraphviz step definition_________________________________________________________________
165
+ @konwerter = RdfToGraphviz.new
166
+
167
+
168
+
169
+ runtime_code = -> {
170
+ paramiters = {}
171
+ if step.parameters[:presentation_vrlb]
172
+ paramiters[:presentation_attr] = @runtime_variable_list[step.parameters[:presentation_vrlb]][:value]
173
+ end
174
+ puts step.parameters
175
+ if step.parameters[:output_format]
176
+ paramiters[:format] = step.parameters[:output_format]
177
+ puts 'format'
178
+ end
179
+ paramiters[:file_name] = @runtime_variable_list[step.parameters[:output_file_vrbl]][:value]
180
+ puts "RdfToGraphviz"
181
+ puts step.parameters[:presentation_vrlb]
182
+ puts @runtime_variable_list[step.parameters[:presentation_vrlb]]
183
+ puts paramiters
184
+ @konwerter.save_rdf_graph_as(@runtime_variable_list[step.parameters[:input_vrbl]][:value], paramiters)
185
+ # tag <img>
186
+ if paramiters[:format] == 'html' then
187
+ file_png = paramiters[:file_name].gsub(/\.\w+$/, ".png")
188
+ File.open(paramiters[:file_name], "a") do |aFile|
189
+ hmlt_tag = "<IMG SRC='#{file_png}' USEMAP='#G' />"
190
+ aFile.puts hmlt_tag
191
+ end
192
+ end
193
+ }
194
+ elsif type == "ExcelLoader" then # XlsToRdfConwerter step definition_______________________________________________________________
195
+ @XlsToRdfConwerter = XlsToRdf.new
196
+ # @xls_options = { :sheets => ["Makiety", "Zrodlo_danych", "Mapowanie_Makieta_Dane", "Legacy", "IPI", "Microservices", "Zaleznosci_Microservice_Legacy", "BackLog"] }
197
+ @xls_options = { :sheets => step.parameters[:sheets]}
198
+ runtime_code = -> {
199
+ puts "ExcelLoader"
200
+ puts step.parameters
201
+ @runtime_variable_list[step.parameters[:output_vrbl]][:value] = @XlsToRdfConwerter.xls_to_rdf(@runtime_variable_list[step.parameters[:input_file_vrbl]][:value], @xls_options)
202
+ }
203
+ elsif type == "RuleEngine" then # RdfRulesEngine step definition__________________________________________________________________
204
+ @RdfRulesEngine = RdfRulesEngine.new
205
+ @RdfRulesEngine.prefix = @runtime_variable_list[step.parameters[:prefix_vrbl]][:value]
206
+ runtime_code = -> {
207
+ @runtime_variable_list[step.parameters[:output_vrbl]][:value] = @RdfRulesEngine.execute(step.parameters[:rule_family], @runtime_variable_list[step.parameters[:input_vrbl]][:value], @runtime_variable_list[step.parameters[:rule_graph_vrlb]][:value])
208
+ puts "RuleEngine"
209
+ puts step.parameters[:output_vrbl]
210
+ puts @runtime_variable_list[step.parameters[:output_vrbl]][:value].inspect
211
+ }
212
+ elsif type == "+" then # Graph + Graph step definition_____________________________________________________________________________
213
+ runtime_code = -> {
214
+ @runtime_variable_list[step.parameters[:output_vrbl]][:value] << @runtime_variable_list[step.parameters[:input_vrbl]][:value]
215
+ }
216
+ elsif type == "Inference" then # RdfInference step definition__________________________________________________________________
217
+ @RdfInference = RdfInference.new
218
+ runtime_code = -> {
219
+ @runtime_variable_list[step.parameters[:output_vrbl]][:value] = @RdfInference.inference(@runtime_variable_list[step.parameters[:input_vrbl]][:value])
220
+ puts "RdfInference"
221
+ puts step.parameters[:output_vrbl]
222
+ puts @runtime_variable_list[step.parameters[:output_vrbl]][:value].inspect
223
+ }
224
+ end
225
+ step.parameters[:runtime_code] = runtime_code
226
+ puts step.parameters
227
+ @runtime_list << step.parameters
228
+ end
229
+ end
@@ -0,0 +1,148 @@
1
+ # load "../rdf_inference/rdf_inference.rb"
2
+ require 'linkeddata'
3
+ require 'rdf_to_graphviz'
4
+ require 'rdf_rules_engine'
5
+ require 'xls_to_rdf'
6
+
7
+ require 'rdf_inference'
8
+ # load "../rdf_process/lib/rdf_process/RdfProcessDefinitionLike.rb"
9
+
10
+ require 'rdf_process/RdfProcessDefinitionLike'
11
+
12
+ class RdfProcess
13
+ include RdfProcessDefinitionLike
14
+ attr_reader :fresh_status, :runtime_list, :runtime_variable_list, :komunikat, :progress
15
+ attr_accessor :monitor_file_list
16
+ def initialize
17
+ @fresh_status = "old" #fresh lub old
18
+ @runtime_list = []
19
+ @monitor_file_list = []
20
+ @runtime_variable_list = {}
21
+
22
+ end
23
+
24
+ def reset
25
+ @fresh_status = "old" #fresh lub old
26
+ @runtime_list = []
27
+ @monitor_file_list = []
28
+ @runtime_variable_list = {}
29
+ end
30
+
31
+ def fresh_status=(new_fresh_status)
32
+ @fresh_status = new_fresh_status
33
+ # graphviz_filtr_value.value = @fresh_status
34
+ end
35
+
36
+ def processing
37
+ s = 0
38
+ current_step = 1
39
+ size = @runtime_list.size
40
+ process_pass = 0.0
41
+ @runtime_list.each do |step|
42
+ if step[:fresh_status] == nil or step[:fresh_status] == "old" then
43
+ s1 = Time.now
44
+ step[:runtime_code].call
45
+ # instance_eval(step[:runtime_code])
46
+ s2 = Time.now - s1
47
+ s += s2
48
+ log "#{step[:name]} - Elapse time: #{s2}s"
49
+ step[:fresh_status] = "fresh"
50
+ end
51
+ process_pass = current_step * 100 / size
52
+ log("#{step[:name]} - #{process_pass} - #{current_step} - #{size} %", process_pass.round)
53
+ current_step += 1
54
+ end
55
+ @fresh_status = "fresh"
56
+ log "Process - Elapse time: #{s}s, #{process_pass}"
57
+ # graphviz_filtr_value.value = @fresh_status
58
+ end
59
+
60
+ def set_runtime_variable(name, value)
61
+ @runtime_variable_list[name][:value] = value
62
+ # log @runtime_variable_list.to_s
63
+ refresh_status(@runtime_variable_list[name][:step_id])
64
+ @fresh_status = "old"
65
+ end
66
+
67
+ def set_monitor_file(index, file)
68
+ @monitor_file_list[index][:file] = file
69
+ # log @monitor_file_list.to_s
70
+ refresh_status(@monitor_file_list[index][:step_id])
71
+ @fresh_status = "old"
72
+ end
73
+
74
+ def refresh_status(step_id)
75
+ # puts "entry refresh_status"
76
+ @runtime_list.each do |step|
77
+ if step[:step_id] == step_id then
78
+ step[:fresh_status] = "old"
79
+ end
80
+
81
+ st = step[:depends_on]
82
+ if st
83
+
84
+ if st.include?(step_id) then
85
+ # step[:fresh_status] = "old"
86
+ # puts step[:step_id] , step[:name]
87
+ refresh_status(step[:step_id])
88
+ # puts step
89
+ end
90
+ end
91
+ end
92
+ # puts @runtime_list
93
+ end
94
+
95
+ def get_dependent_step_from(step_id)
96
+ dependent_steps = []
97
+ @runtime_list.each do |step|
98
+ st = step[:depends_on]
99
+ if st != nil then
100
+
101
+ if st.include?(step_id) then
102
+ # step[:fresh_status] = "old"
103
+ # puts step[:step_id] , step[:name]
104
+ dependent_steps << step[:step_id]
105
+ # puts step
106
+ end
107
+ end
108
+
109
+ end
110
+ dependent_steps
111
+ end
112
+
113
+ def log(komunikat, progress = nil)
114
+ @progress = progress
115
+
116
+ # @komunikat.disp_komunikat(komunikat, progress)
117
+ @komunikat = komunikat
118
+ puts komunikat
119
+ send_log
120
+ end
121
+
122
+ def send_log
123
+ puts "send log"
124
+ end
125
+
126
+ def eval_file(file)
127
+ instance_eval File.read(file), file
128
+ end
129
+
130
+ def save_variables(file)
131
+ File.open(file, "w") do |aFile|
132
+ @runtime_variable_list.each do | name, value |
133
+ if value[:type] != "graph" then #.gsub!("\"",'\\"')
134
+ # gvalue =
135
+ code = "addVariable '#{value[:type]}' do
136
+ name '#{name}'
137
+ value \"#{value[:value].gsub("\"",'\\"')}\"
138
+ step_id '#{value[:step_id]}'
139
+ end"
140
+ aFile.puts code
141
+ end
142
+ end
143
+
144
+ aFile.puts "# vieslav.pl "
145
+ end
146
+ end
147
+
148
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rdf_process
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - WiDu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-01-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: linkeddata
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sparql
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rdf_to_graphviz
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rdf_rules_engine
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: xls_to_rdf
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rdf_inference
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Process engine
98
+ email: wdulek@gmail.com
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - lib/rdf_process.rb
104
+ - lib/rdf_process/RdfProcessDefinitionLike.rb
105
+ homepage: https://github.com/widu/rdf_process
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.6.7
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Process engine
129
+ test_files: []