Class: DecisionAgent::Dmn::DecisionGraphParser
- Inherits:
-
Object
- Object
- DecisionAgent::Dmn::DecisionGraphParser
- Defined in:
- lib/decision_agent/dmn/decision_graph.rb
Overview
Parser for DMN decision graphs from XML
Class Method Summary collapse
- .parse(xml_doc) ⇒ Object
- .parse_decision_node(decision_xml) ⇒ Object
- .parse_decision_table(table_xml) ⇒ Object
Class Method Details
.parse(xml_doc) ⇒ Object
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/decision_agent/dmn/decision_graph.rb', line 262 def self.parse(xml_doc) # Extract namespace and model info definitions = xml_doc.at_xpath("//dmn:definitions") || xml_doc.root model_id = definitions["id"] || "decision_graph" model_name = definitions["name"] || model_id graph = DecisionGraph.new(id: model_id, name: model_name) # Parse all decisions decisions = xml_doc.xpath("//dmn:decision") decisions.each do |decision_xml| decision_node = parse_decision_node(decision_xml) graph.add_decision(decision_node) # Parse information requirements (dependencies) decision_id = decision_xml["id"] decision_node = graph.get_decision(decision_id) # Find all information requirements decision_xml.xpath(".//dmn:informationRequirement").each do |req| required_decision = req.at_xpath(".//dmn:requiredDecision") next unless required_decision required_id = required_decision["href"]&.sub("#", "") decision_node.add_dependency(required_id) if required_id end end graph end |
.parse_decision_node(decision_xml) ⇒ Object
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
# File 'lib/decision_agent/dmn/decision_graph.rb', line 293 def self.parse_decision_node(decision_xml) decision_id = decision_xml["id"] decision_name = decision_xml["name"] || decision_id # Check for decision table decision_table = decision_xml.at_xpath(".//dmn:decisionTable") if decision_table # Parse decision table (simplified) decision_logic = parse_decision_table(decision_table) else # Check for literal expression (could be decision tree or simple expression) literal_expr = decision_xml.at_xpath(".//dmn:literalExpression") decision_logic = literal_expr&.text&.strip end DecisionNode.new( id: decision_id, name: decision_name, decision_logic: decision_logic ) end |
.parse_decision_table(table_xml) ⇒ Object
315 316 317 318 319 320 321 322 323 324 |
# File 'lib/decision_agent/dmn/decision_graph.rb', line 315 def self.parse_decision_table(table_xml) # Simplified decision table parsing # Full implementation would use the existing DecisionTable parser { type: "decision_table", hit_policy: table_xml["hitPolicy"] || "UNIQUE", inputs: [], rules: [] } end |