Class: T2Flow::Parser
- Inherits:
-
Object
- Object
- T2Flow::Parser
- Defined in:
- lib/t2flow/parser.rb
Instance Method Summary collapse
-
#add_annotation(dataflow, annotation) ⇒ Object
:nodoc:.
-
#add_coordination(dataflow, condition) ⇒ Object
:nodoc:.
-
#add_link(dataflow, link) ⇒ Object
:nodoc:.
-
#add_processor(dataflow, element) ⇒ Object
:nodoc:.
-
#add_sink(dataflow, port) ⇒ Object
:nodoc:.
-
#add_source(dataflow, port) ⇒ Object
:nodoc:.
-
#create_model(element, version) ⇒ Object
:nodoc:.
-
#parse(t2flow) ⇒ Object
Returns the model for the given t2flow_file.
Instance Method Details
#add_annotation(dataflow, annotation) ⇒ Object
:nodoc:
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/t2flow/parser.rb', line 234 def add_annotation(dataflow, annotation) # :nodoc: node = LibXML::XML::Parser.string("#{annotation}").parse content_node = node.find_first("//annotationBean") case content_node["class"] when /freetextdescription/i dataflow.annotations.descriptions << content_node.find_first('./text').content when /descriptivetitle/i dataflow.annotations.titles << content_node.find_first('./text').content when /author/i dataflow.annotations. << content_node.find_first('./text').content when /semanticannotation/i dataflow.annotations.semantic_annotation = parse_semantic_annotation(dataflow, content_node) end # case end |
#add_coordination(dataflow, condition) ⇒ Object
:nodoc:
225 226 227 228 229 230 231 232 |
# File 'lib/t2flow/parser.rb', line 225 def add_coordination(dataflow, condition) # :nodoc: coordination = Coordination.new coordination.control = condition["control"] coordination.target = condition["target"] dataflow.coordinations << coordination end |
#add_link(dataflow, link) ⇒ Object
:nodoc:
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/t2flow/parser.rb', line 201 def add_link(dataflow, link) # :nodoc: datalink = Datalink.new if sink = link.find_first('./t2:sink') if processor = sink.find_first('./t2:processor') datalink.sink = "#{processor.content}:" else datalink.sink = "" end datalink.sink += "#{sink.find_first('./t2:port').content}" end if source = link.find_first('./t2:source') if processor = source.find_first('./t2:processor') datalink.source = "#{processor.content}:" else datalink.source = "" end datalink.source += "#{source.find_first('./t2:port').content}" end dataflow.datalinks << datalink end |
#add_processor(dataflow, element) ⇒ Object
:nodoc:
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 |
# File 'lib/t2flow/parser.rb', line 110 def add_processor(dataflow, element) # :nodoc: processor = Processor.new temp_inputs = [] temp_outputs = [] element.each_element do |elt| case elt.name when "name" processor.name = elt.content when /inputports/i # ports from services elt.each_element { |port| port.each_element { |x| temp_inputs << x.content if x.name=="name" }} when /outputports/i # ports from services elt.each_element { |port| port.each_element { |x| temp_outputs << x.content if x.name=="name" }} when "annotations" extract_annotations(processor, elt) when "activities" # a processor can only have one kind of activity activity = elt.find_first('./t2:activity') activity.each_element do |node| if node.name == "configBean" activity_node = node.child if activity_node.name == "net.sf.taverna.t2.component.ComponentActivityConfigurationBean" processor.configuration[:component] = {} processor.configuration[:component][:registry] = activity_node.find_first('./registryBase').content processor.configuration[:component][:family_name] = activity_node.find_first('./familyName').content processor.configuration[:component][:name] = activity_node.find_first('./componentName').content processor.configuration[:component][:version] = activity_node.find_first('./componentVersion').content.to_i end if node["encoding"] == "dataflow" processor.dataflow_id = activity_node["ref"] processor.type = "workflow" else processor.type = (activity_node.name =~ /martquery/i ? "biomart" : activity_node.name.split(".")[-2]) activity_node.each_element do |value_node| case value_node.name when "wsdl" processor.configuration[:wsdl] = value_node.content when "operation" processor.configuration[:wsdl_operation] = value_node.content when /endpoint/i processor.configuration[:endpoint] = value_node.content when /servicename/i processor.configuration[:biomoby_service_name] = value_node.content when /authorityname/i processor.configuration[:biomoby_authority_name] = value_node.content when "category" processor.configuration[:biomoby_category] = value_node.content when "script" processor.configuration[:script] = value_node.content when "value" processor.configuration[:value] = value_node.content when "presentationOrigin" processor.configuration[:interaction_page] = value_node.content when "connectionSettings" if processor.type == 'rshell' processor.configuration[:r_server] = value_node.find_first('./host').content + ":" + value_node.find_first('./port').content end when "xpathExpression" processor.configuration[:xpath_expression] = value_node.content when "inputs" # ALL ports present in beanshell value_node.each_element do |input| input.each_element do |x| processor.inputs = [] if processor.inputs.nil? processor.inputs << x.content if x.name == "name" end end when "outputs" # ALL ports present in beanshell value_node.each_element do |output| output.each_element do |x| processor.outputs = [] if processor.outputs.nil? processor.outputs << x.content if x.name == "name" end end end # case value_node.name end # activity_node.each end # if else node["encoding"] == "dataflow" end # if node.name == "configBean" end # activity.each end # case elt.name end # element.each processor.inputs = temp_inputs if processor.inputs.nil? && !temp_inputs.empty? processor.outputs = temp_outputs if processor.outputs.nil? && !temp_outputs.empty? dataflow.processors << processor end |
#add_sink(dataflow, port) ⇒ Object
:nodoc:
102 103 104 105 106 107 108 |
# File 'lib/t2flow/parser.rb', line 102 def add_sink(dataflow, port) # :nodoc: return if port.nil? || port.content.chomp.strip.empty? sink = Sink.new (sink, port) dataflow.sinks << sink end |
#add_source(dataflow, port) ⇒ Object
:nodoc:
94 95 96 97 98 99 100 |
# File 'lib/t2flow/parser.rb', line 94 def add_source(dataflow, port) # :nodoc: return if port.nil? || port.content.chomp.strip.empty? source = Source.new (source, port) dataflow.sources << source end |
#create_model(element, version) ⇒ Object
:nodoc:
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/t2flow/parser.rb', line 42 def create_model(element, version) # :nodoc: model = Model.new local_depends = element.find("//localDependencies") if local_depends local_depends.each do |dependency| dependency.each do |dep| model.dependencies = [] if model.dependencies.nil? model.dependencies << dep.content unless dep.content =~ /^\s*$/ end end model.dependencies.uniq! if model.dependencies end element.each_element do |dataflow| next if dataflow["id"].nil? || dataflow["id"].chomp.strip.empty? dataflow_obj = Dataflow.new dataflow_obj.dataflow_id = dataflow["id"] dataflow_obj.role = dataflow["role"] dataflow.each_element do |elt| case elt.name when "name" dataflow_obj.annotations.name = elt.content when "inputPorts" elt.each_element { |port| add_source(dataflow_obj, port) } when "outputPorts" elt.each_element { |port| add_sink(dataflow_obj, port) } when "processors" elt.each_element { |proc| add_processor(dataflow_obj, proc) } when "datalinks" elt.each_element { |link| add_link(dataflow_obj, link) } when "conditions" elt.each_element { |coord| add_coordination(dataflow_obj, coord) } when "annotations" elt.each_element { |ann| add_annotation(dataflow_obj, ann) } end # case elt.name end # dataflow.each model.dataflows << dataflow_obj end # element.each temp = model.processors.select { |x| x.type == "workflow" } temp.each do |proc| df = model.dataflow(proc.dataflow_id) df.annotations.name = proc.name end return model end |
#parse(t2flow) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/t2flow/parser.rb', line 22 def parse(t2flow) case t2flow.class.to_s when /^string$/i document = LibXML::XML::Parser.string(t2flow, :options => LibXML::XML::Parser::Options::NOBLANKS).parse when /^stringio|file$/i t2flow.rewind document = LibXML::XML::Parser.string(t2flow.read, :options => LibXML::XML::Parser::Options::NOBLANKS).parse else raise "Error parsing file." end root = document.root root.namespaces.default_prefix = "t2" raise "Doesn't appear to be a workflow!" if root.name != "workflow" version = root["version"] create_model(root, version) end |