Skip to content

Commit

Permalink
Code optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
mdesalvo authored Sep 13, 2023
1 parent 65a2755 commit 0bd55cb
Showing 1 changed file with 14 additions and 27 deletions.
41 changes: 14 additions & 27 deletions RDFSharp/Query/Mirella/Algebra/RDFPatternGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,32 +94,20 @@ public RDFPatternGroup AddPattern(RDFPattern pattern)
GroupMembers.Add(pattern);

//Context
if (pattern.Context is RDFVariable patternContext)
{
if (!Variables.Any(v => v.Equals(patternContext)))
Variables.Add(patternContext);
}
if (pattern.Context is RDFVariable patternContext && !Variables.Any(v => v.Equals(patternContext)))
Variables.Add(patternContext);

//Subject
if (pattern.Subject is RDFVariable patternSubject)
{
if (!Variables.Any(v => v.Equals(patternSubject)))
Variables.Add(patternSubject);
}
if (pattern.Subject is RDFVariable patternSubject && !Variables.Any(v => v.Equals(patternSubject)))
Variables.Add(patternSubject);

//Predicate
if (pattern.Predicate is RDFVariable patternPredicate)
{
if (!Variables.Any(v => v.Equals(patternPredicate)))
Variables.Add(patternPredicate);
}
if (pattern.Predicate is RDFVariable patternPredicate && !Variables.Any(v => v.Equals(patternPredicate)))
Variables.Add(patternPredicate);

//Object
if (pattern.Object is RDFVariable patternObject)
{
if (!Variables.Any(v => v.Equals(patternObject)))
Variables.Add(patternObject);
}
if (pattern.Object is RDFVariable patternObject && !Variables.Any(v => v.Equals(patternObject)))
Variables.Add(patternObject);
}
return this;
}
Expand Down Expand Up @@ -169,8 +157,10 @@ public RDFPatternGroup AddBind(RDFBind bind)
{
if (bind != null && !GetBinds().Any(b => b.Equals(bind)))
{
#region Guards
if (Variables.Any(v => v.Equals(bind.Variable)))
throw new RDFQueryException($"Cannot add BIND to pattern group because its variable '{bind.Variable}' already exists at this moment!");
#endregion

GroupMembers.Add(bind);

Expand All @@ -185,16 +175,13 @@ public RDFPatternGroup AddBind(RDFBind bind)
/// </summary>
public RDFPatternGroup AddFilter(RDFFilter filter)
{
if (filter != null)
{
if (!GetFilters().Any(f => f.Equals(filter)))
GroupMembers.Add(filter);
}
if (filter != null && !GetFilters().Any(f => f.Equals(filter)))
GroupMembers.Add(filter);
return this;
}

/// <summary>
/// Sets the pattern group to be joined as optional with the previous query member
/// Sets the pattern group to be joined as Optional with the previous query member
/// </summary>
public RDFPatternGroup Optional()
{
Expand All @@ -204,7 +191,7 @@ public RDFPatternGroup Optional()
}

/// <summary>
/// Sets the pattern group to be joined as union with the next query member
/// Sets the pattern group to be joined as Union with the next query member
/// </summary>
public RDFPatternGroup UnionWithNext()
{
Expand Down

0 comments on commit 0bd55cb

Please sign in to comment.