/// <summary>
 /// Serializes the object to ADSML xml form.
 /// </summary>
 /// <returns><see cref="XElement"/></returns>
 public XElement ToAdsml()
 {
     return(this.OuterNodeAttributes != null
 ? new XElement(
                NodeName,
                this.OuterNodeAttributes.Select(attrs => attrs),
                ContentNodes.Select(cnode => cnode.ToAdsml())
                )
 : new XElement(NodeName, ContentNodes.Select(cnode => cnode.ToAdsml())));
 }
예제 #2
0
        public string GetParameterSemanticKey(string parametername = null)
        {
            if (string.IsNullOrWhiteSpace(parametername))
            {
                parametername = QuestionFirstParameter?.Name;
            }
            var parameterSementicKey      = $"{Step.SemanticKey}.{parametername}";
            var parameterSementicKeyKeuze = $"{Step.SemanticKey}.keuze.{parametername}";

            if (ContentNodes.Any(c => c.Parameter.SemanticKey == parameterSementicKey))
            {
                return(parameterSementicKey);
            }
            if (ContentNodes.Any(c => c.Parameter.SemanticKey == parameterSementicKeyKeuze))
            {
                return(parameterSementicKeyKeuze);
            }
            return(Step.SemanticKey);
        }
예제 #3
0
        public ParseResult Parse(string yaml)
        {
            _contentNodes = new List <ContentNode>();
            try
            {
                YamlRuleParser parser = new YamlRuleParser(yaml, null);
                _model = new Model.Model(parser.Header(), parser.Formulas().ToList(), parser.Tabellen().ToList(), parser.Flow().ToList());
                List <string> inclusiveSituations = null;
                foreach (var step in _model.Steps)
                {
                    if (step.IsSituational)
                    {
                        inclusiveSituations = step.Situation.Split(',')
                                              .Select(x => x.Trim())
                                              .Where(x => !string.IsNullOrWhiteSpace(x))
                                              .ToList();
                        foreach (var inclusiveSituation in inclusiveSituations)
                        {
                            var contentNodeStep = new ContentNode($"{YamlRuleParser.Step}.{step.Name}.{YamlRuleParser.StepSituation}.{inclusiveSituation}")
                            {
                                Parameter = new Parameter(step.Name, false, TypeEnum.Step, ref _model)
                            };
                            contentNodeStep.Parameter.SemanticKey = contentNodeStep.Name;
                            contentNodeStep.Situation             = inclusiveSituation;
                            _contentNodes.Add(contentNodeStep);
                            step.SemanticKey = contentNodeStep.Name;

                            if (step.Choices != null)
                            {
                                foreach (var choice in step.Choices)
                                {
                                    var contentNode = new ContentNode($"{YamlRuleParser.Step}.{step.Name}.{YamlRuleParser.StepSituation}.{inclusiveSituation}.{YamlRuleParser.StepChoice}.{choice.Situation}")
                                    {
                                        Parameter = new Parameter(choice.Situation, false, TypeEnum.Boolean, ref _model)
                                    };
                                    contentNode.Parameter.SemanticKey = contentNode.Name;
                                    contentNode.Situation             = inclusiveSituation;
                                    _contentNodes.Add(contentNode);
                                }
                            }

                            if (!string.IsNullOrEmpty(step.Value))
                            {
                                var contentNode = new ContentNode($"{YamlRuleParser.Step}.{step.Name}.{YamlRuleParser.StepSituation}.{inclusiveSituation}.{step.Value}");
                                contentNode.Parameter             = new Parameter(step.Name, null, TypeEnum.Double, ref _model);
                                contentNode.Parameter.SemanticKey = contentNode.Name;
                                contentNodeStep.Situation         = inclusiveSituation;
                                _contentNodes.Add(contentNode);
                            }

                            ResolveToQuestion(step.Formula, ref _contentNodes, step.Situation, step.Name);

                            if (step.Break != null && !string.IsNullOrEmpty(step.Break.Expression))
                            {
                                ContentNode node = new ContentNode($"{YamlRuleParser.Step}.{step.Name}.{YamlRuleParser.StepSituation}.{inclusiveSituation}.geen_recht")
                                {
                                    IsBreak = true, IsSituational = step.IsSituational, Situation = inclusiveSituation, Parameter = new Parameter(name: "recht", value: null, type: TypeEnum.Boolean, model: ref _model)
                                };
                                step.Break.SemanticKey     = node.Name;
                                node.Parameter.SemanticKey = node.Name;
                                contentNodeStep.Situation  = inclusiveSituation;
                                _contentNodes.Add(node);
                            }
                        }
                    }
                    else
                    {
                        var contentNodeStep = new ContentNode($"{YamlRuleParser.Step}.{step.Name}")
                        {
                            Parameter = new Parameter(step.Name, false, TypeEnum.Step, ref _model)
                        };
                        contentNodeStep.Parameter.SemanticKey = contentNodeStep.Name;
                        _contentNodes.Add(contentNodeStep);
                        step.SemanticKey = contentNodeStep.Name;

                        if (step.Choices != null)
                        {
                            foreach (var choice in step.Choices)
                            {
                                var contentNode = new ContentNode($"{YamlRuleParser.Step}.{step.Name}.{YamlRuleParser.StepChoice}.{choice.Situation}")
                                {
                                    Parameter = new Parameter(choice.Situation, false, TypeEnum.Boolean, ref _model)
                                };
                                contentNode.Parameter.SemanticKey = contentNode.Name;
                                _contentNodes.Add(contentNode);
                            }
                        }
                        if (!string.IsNullOrEmpty(step.Value))
                        {
                            var contentNode = new ContentNode($"{YamlRuleParser.Step}.{step.Name}.{YamlRuleParser.StepValue}.{step.Value}");
                            contentNode.Parameter             = new Parameter(step.Name, null, TypeEnum.Double, ref _model);
                            contentNode.Parameter.SemanticKey = contentNode.Name;
                            _contentNodes.Add(contentNode);
                        }
                        ResolveToQuestion(step.Formula, ref _contentNodes, step.Situation, step.Name);

                        if (step.Break != null && !string.IsNullOrEmpty(step.Break.Expression))
                        {
                            step.Break.SemanticKey = string.Join('.', new[] { YamlRuleParser.Step, step.Name, "geen_recht" }.Where(s => !string.IsNullOrEmpty(s)));
                            ContentNode node = new ContentNode(step.Break.SemanticKey)
                            {
                                IsBreak = true, IsSituational = step.IsSituational, Situation = step.Situation, Parameter = new Parameter(name: "recht", value: null, type: TypeEnum.Boolean, model: ref _model)
                            };
                            node.Parameter.SemanticKey = step.Break.SemanticKey;
                            _contentNodes.Add(node);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var result = new ParseResult
                {
                    IsError = true,
                    Message = ex.Message
                };
                return(result);
            }
            ContentNodes.Add(new ContentNode("end")
            {
                Parameter = new Parameter("end", null, TypeEnum.Step, ref _model)
            });
            return(new ParseResult()
            {
                Message = Ok,
                ExpressionTree = new YamlDotNet.Serialization.Serializer().Serialize(_model),
                Model = _model
            });
        }