Skip to content

Commit

Permalink
#65 Optimize new depth logics of property paths
Browse files Browse the repository at this point in the history
  • Loading branch information
mdesalvo committed Aug 15, 2019
1 parent b390cf6 commit f473af5
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions RDFSharp/Query/Mirella/Algebra/RDFPropertyPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,18 @@ internal String ToString(List<RDFNamespace> prefixes)
/// </summary>
public RDFPropertyPath AddAlternativeSteps(List<RDFPropertyPathStep> 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)
Expand All @@ -144,8 +146,9 @@ public RDFPropertyPath AddAlternativeSteps(List<RDFPropertyPathStep> 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;
Expand All @@ -155,6 +158,7 @@ public RDFPropertyPath AddAlternativeSteps(List<RDFPropertyPathStep> alternative
{
RDFQueryEvents.RaiseGENERICQueryEvaluation("AddAlternativeSteps: ground property path detected, evaluability not granted.");
}
#endregion
}
return this;
}
Expand All @@ -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;
Expand All @@ -180,6 +186,7 @@ public RDFPropertyPath AddSequenceStep(RDFPropertyPathStep sequenceStep)
{
RDFQueryEvents.RaiseGENERICQueryEvaluation("AddSequenceStep: ground property path detected, evaluability not granted.");
}
#endregion
}
return this;
}
Expand Down

0 comments on commit f473af5

Please sign in to comment.