Module: RdfProcessDefinitionLike
- Included in:
- RdfProcess
- Defined in:
- lib/rdf_process/RdfProcessDefinitionLike.rb
Defined Under Namespace
Classes: ProcessStep, ProcessVariable
Instance Method Summary
collapse
Instance Method Details
#addStep(type, &block) ⇒ Object
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
|
# File 'lib/rdf_process/RdfProcessDefinitionLike.rb', line 104
def addStep( type, &block)
depends = []
step = ProcessStep.new(type)
puts "check #{type}"
step.instance_eval(&block)
depends << step.parameters[:input_vrbl] if step.parameters[:input_vrbl]
depends << step.parameters[:rule_graph_vrlb] if step.parameters[:rule_graph_vrlb]
depends << step.parameters[:presentation_vrlb] if step.parameters[:presentation_vrlb]
step.parameters[:depends_on] = calculate_depends_on(depends)
step.vrbls.each do |key, value|
if @runtime_variable_list[key] == nil then
addVariable value[:type] do
name key
value value[:value]
step_id step.parameters[:step_id]
end
end
end
if type == "GraphLoader" then if step.parameters[:file_vrbl] == nil then
ttl_file = step.parameters[:file]
unless File::exists?( ttl_file )
raise "Graph loader - ttl file: #{ttl_file} - doesn't exist"
end
runtime_code = -> {
@runtime_variable_list[step.parameters[:output_vrbl]][:value] = RDF::Graph.load(ttl_file)
puts "step graphloader"
}
else
ttl_file = step.parameters[:file_vrbl]
runtime_code = -> {
@runtime_variable_list[step.parameters[:output_vrbl]][:value] = RDF::Graph.load(@runtime_variable_list[ttl_file][:value])
puts "step graphloader"
}
end
elsif type == "Filtr" then runtime_code = -> {
puts @runtime_variable_list[step.parameters[:filtr_vrbl]][:value]
query = @runtime_variable_list["prefix"][:value] + @runtime_variable_list[step.parameters[:filtr_vrbl]][:value]
inputt = step.parameters[:input_vrbl]
puts step.parameters[:input_vrbl]
@runtime_variable_list[step.parameters[:output_vrbl]][:value] = SPARQL.execute(query, @runtime_variable_list[inputt][:value])
}
runtime_code = -> {
if step.parameters[:filtr_vrbl]
query2 = @runtime_variable_list[step.parameters[:filtr_vrbl]][:value]
puts @runtime_variable_list[step.parameters[:filtr_vrbl]][:value]
else
query2 = step.parameters[:filtr]
end
query = @runtime_variable_list["prefix"][:value] + query2
inputt = step.parameters[:input_vrbl]
puts step.parameters[:input_vrbl]
@runtime_variable_list[step.parameters[:output_vrbl]][:value] = SPARQL.execute(query, @runtime_variable_list[inputt][:value])
}
elsif type == "RdfToGraphviz" then @konwerter = RdfToGraphviz.new
runtime_code = -> {
paramiters = {}
if step.parameters[:presentation_vrlb]
paramiters[:presentation_attr] = @runtime_variable_list[step.parameters[:presentation_vrlb]][:value]
end
puts step.parameters
if step.parameters[:output_format]
paramiters[:format] = step.parameters[:output_format]
puts 'format'
end
paramiters[:file_name] = @runtime_variable_list[step.parameters[:output_file_vrbl]][:value]
puts "RdfToGraphviz"
puts step.parameters[:presentation_vrlb]
puts @runtime_variable_list[step.parameters[:presentation_vrlb]]
puts paramiters
@konwerter.save_rdf_graph_as(@runtime_variable_list[step.parameters[:input_vrbl]][:value], paramiters)
if paramiters[:format] == 'html' then
file_png = paramiters[:file_name].gsub(/\.\w+$/, ".png")
File.open(paramiters[:file_name], "a") do |aFile|
hmlt_tag = "<IMG SRC='#{file_png}' USEMAP='#G' />"
aFile.puts hmlt_tag
end
end
}
elsif type == "ExcelLoader" then @XlsToRdfConwerter = XlsToRdf.new
@xls_options = { :sheets => step.parameters[:sheets]}
runtime_code = -> {
puts "ExcelLoader"
puts step.parameters
@runtime_variable_list[step.parameters[:output_vrbl]][:value] = @XlsToRdfConwerter.xls_to_rdf(@runtime_variable_list[step.parameters[:input_file_vrbl]][:value], @xls_options)
}
elsif type == "RuleEngine" then @RdfRulesEngine = RdfRulesEngine.new
@RdfRulesEngine.prefix = @runtime_variable_list[step.parameters[:prefix_vrbl]][:value]
runtime_code = -> {
@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])
puts "RuleEngine"
puts step.parameters[:output_vrbl]
puts @runtime_variable_list[step.parameters[:output_vrbl]][:value].inspect
}
elsif type == "+" then runtime_code = -> {
@runtime_variable_list[step.parameters[:output_vrbl]][:value] << @runtime_variable_list[step.parameters[:input_vrbl]][:value]
}
elsif type == "Inference" then @RdfInference = RdfInference.new
runtime_code = -> {
@runtime_variable_list[step.parameters[:output_vrbl]][:value] = @RdfInference.inference(@runtime_variable_list[step.parameters[:input_vrbl]][:value])
puts "RdfInference"
puts step.parameters[:output_vrbl]
puts @runtime_variable_list[step.parameters[:output_vrbl]][:value].inspect
}
end
step.parameters[:runtime_code] = runtime_code
puts step.parameters
@runtime_list << step.parameters
end
|
#addVariable(type, &block) ⇒ Object
35
36
37
38
39
40
41
42
43
|
# File 'lib/rdf_process/RdfProcessDefinitionLike.rb', line 35
def addVariable(type, &block)
variable = ProcessVariable.new(type)
variable.instance_eval(&block)
puts "check #{type}"
@runtime_variable_list[variable.getName] = variable.parameters
end
|
#calculate_depends_on(variables) ⇒ Object
3
4
5
6
7
8
9
10
11
|
# File 'lib/rdf_process/RdfProcessDefinitionLike.rb', line 3
def calculate_depends_on(variables)
depended_steps = []
@runtime_list.each do |step|
if variables.include?(step[:output_vrbl]) then
depended_steps << step[:step_id]
end
end
depended_steps
end
|