diff --git a/RDFSharp/Query/Mirella/Algebra/RDFPropertyPath.cs b/RDFSharp/Query/Mirella/Algebra/RDFPropertyPath.cs index fba2e4ab..063d6dcb 100644 --- a/RDFSharp/Query/Mirella/Algebra/RDFPropertyPath.cs +++ b/RDFSharp/Query/Mirella/Algebra/RDFPropertyPath.cs @@ -121,16 +121,18 @@ internal String ToString(List prefixes) /// public RDFPropertyPath AddAlternativeSteps(List alternativeSteps) { - //Avoid chaining of alternative steps - if (this.Steps.LastOrDefault()?.StepFlavor == RDFQueryEnums.RDFPropertyPathStepFlavors.Alternative) - { - RDFQueryEvents.RaiseGENERICQueryEvaluation("AddAlternativeSteps: chaining of alternative steps detected, discarding last ones."); - return this; - } - if (alternativeSteps != null && alternativeSteps.Any()) { - this.Depth++; + #region Depth Guard + if (this.Steps.Count == 0 + || alternativeSteps.Count == 1 + || this.Steps.LastOrDefault()?.StepFlavor == RDFQueryEnums.RDFPropertyPathStepFlavors.Sequence) + { + this.Depth++; + } + #endregion + + #region Steps Update if (alternativeSteps.Count == 1) { this.Steps.Add(alternativeSteps[0].SetOrdinal(this.Steps.Count) @@ -144,8 +146,9 @@ public RDFPropertyPath AddAlternativeSteps(List alternative .SetFlavor(RDFQueryEnums.RDFPropertyPathStepFlavors.Alternative)); }); } + #endregion - //Avoid evaluability of ground property paths + #region Evaluability Guard if (this.Start is RDFVariable || this.End is RDFVariable || this.Depth > 1) { this.IsEvaluable = true; @@ -155,6 +158,7 @@ public RDFPropertyPath AddAlternativeSteps(List alternative { RDFQueryEvents.RaiseGENERICQueryEvaluation("AddAlternativeSteps: ground property path detected, evaluability not granted."); } + #endregion } return this; } @@ -166,11 +170,13 @@ public RDFPropertyPath AddSequenceStep(RDFPropertyPathStep sequenceStep) { if (sequenceStep != null) { + #region Steps Update this.Depth++; this.Steps.Add(sequenceStep.SetOrdinal(this.Steps.Count) .SetFlavor(RDFQueryEnums.RDFPropertyPathStepFlavors.Sequence)); + #endregion - //Avoid evaluability of ground property paths + #region Evaluability Guard if (this.Start is RDFVariable || this.End is RDFVariable || this.Depth > 1) { this.IsEvaluable = true; @@ -180,6 +186,7 @@ public RDFPropertyPath AddSequenceStep(RDFPropertyPathStep sequenceStep) { RDFQueryEvents.RaiseGENERICQueryEvaluation("AddSequenceStep: ground property path detected, evaluability not granted."); } + #endregion } return this; }