Skip to content

Commit

Permalink
Further optimizations to QueryPrinter
Browse files Browse the repository at this point in the history
  • Loading branch information
mdesalvo committed Dec 7, 2023
1 parent a51e42c commit 0e5bec4
Showing 1 changed file with 16 additions and 26 deletions.
42 changes: 16 additions & 26 deletions RDFSharp/Query/Mirella/RDFQueryPrinter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -446,32 +446,19 @@ internal static string PrintPatternGroup(RDFPatternGroup patternGroup, int space
#region PATTERN
if (pgMember is RDFPattern ptPgMember)
{
//Union pattern
if (ptPgMember.JoinAsUnion)
//Pattern is set as UNION with the next pg member and it IS NOT the last one => append UNION
if (ptPgMember.JoinAsUnion && !thisIsLastPgMemberOrNextPgMemberIsBind)
{
if (!thisIsLastPgMemberOrNextPgMemberIsBind)
{
//Begin a new Union block
printingUnion = true;
result.AppendLine(string.Concat(spaces, " { ", PrintPattern(ptPgMember, prefixes), " }"));
result.AppendLine(string.Concat(spaces, " UNION"));
}
else
{
//End the Union block
if (printingUnion)
{
printingUnion = false;
result.AppendLine(string.Concat(spaces, " { ", PrintPattern(ptPgMember, prefixes), " }"));
}
else
result.AppendLine(string.Concat(spaces, " ", PrintPattern(ptPgMember, prefixes), " ."));
}
//Begin new UNION block
printingUnion = true;
result.AppendLine(string.Concat(spaces, " { ", PrintPattern(ptPgMember, prefixes), " }"));
result.AppendLine(string.Concat(spaces, " UNION"));
}
//Intersect pattern

//Pattern is set as INTERSECT with the next pg member or it IS the last one => do not append UNION
else
{
//End the Union block
//End active UNION block
if (printingUnion)
{
printingUnion = false;
Expand All @@ -486,7 +473,7 @@ internal static string PrintPatternGroup(RDFPatternGroup patternGroup, int space
#region PROPERTY PATH
else if (pgMember is RDFPropertyPath ppPgMember && ppPgMember.IsEvaluable)
{
//End the Union block
//End active UNION block
if (printingUnion)
{
printingUnion = false;
Expand All @@ -500,7 +487,7 @@ internal static string PrintPatternGroup(RDFPatternGroup patternGroup, int space
#region VALUES
else if (pgMember is RDFValues vlPgMember && vlPgMember.IsEvaluable && !vlPgMember.IsInjected)
{
//End the Union block
//End active UNION block
if (printingUnion)
{
printingUnion = false;
Expand All @@ -514,7 +501,7 @@ internal static string PrintPatternGroup(RDFPatternGroup patternGroup, int space
#region BIND
else if (pgMember is RDFBind bdPgMember)
{
//End the Union block
//End active UNION block
if (printingUnion)
printingUnion = false;
result.AppendLine(string.Concat(spaces, " ", PrintBind(bdPgMember, prefixes), " ."));
Expand All @@ -531,13 +518,16 @@ internal static string PrintPatternGroup(RDFPatternGroup patternGroup, int space

#region CLOSURE
result.AppendLine(string.Concat(spaces, " }"));

//SERVICE
if (patternGroup.EvaluateAsService.HasValue)
{
result.AppendLine(string.Concat(spaces, "}"));
//In this case we must rewind an indentation level (2 spaces)
if (spaces.Length > 2)
spaces = spaces.Substring(2);
}

//OPTIONAL
if (patternGroup.IsOptional && !skipOptional)
result.AppendLine(string.Concat(spaces, "}"));
#endregion
Expand Down

0 comments on commit 0e5bec4

Please sign in to comment.