Skip to content

Commit

Permalink
Code cleanups and test Uri adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
mdesalvo authored Sep 9, 2023
1 parent e5e573f commit 57778b6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 30 deletions.
4 changes: 2 additions & 2 deletions RDFSharp.Test/Store/Engines/RDFMemoryStoreTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1676,7 +1676,7 @@ public void ShouldRaiseExceptionOnImportingFromDataTableHavingRowWithNullObjectA
[TestMethod]
public void ShouldImportFromUri()
{
RDFMemoryStore store = RDFMemoryStore.FromUri(new Uri("https://w3c.github.io/rdf-tests/nquads/nq-syntax-uri-01.nq"));
RDFMemoryStore store = RDFMemoryStore.FromUri(new Uri("https://w3c.github.io/rdf-tests/rdf/rdf11/rdf-n-quads/nq-syntax-uri-01.nq"));

Assert.IsNotNull(store);
Assert.IsTrue(store.QuadruplesCount > 0);
Expand All @@ -1693,7 +1693,7 @@ public void ShouldRaiseExceptionOnImportingFromRelativeUri()
[TestMethod]
public async Task ShouldImportFromUriAsync()
{
RDFMemoryStore store = await RDFMemoryStore.FromUriAsync(new Uri("https://w3c.github.io/rdf-tests/nquads/nq-syntax-uri-01.nq"));
RDFMemoryStore store = await RDFMemoryStore.FromUriAsync(new Uri("https://w3c.github.io/rdf-tests/rdf/rdf11/rdf-n-quads/nq-syntax-uri-01.nq"));

Assert.IsNotNull(store);
Assert.IsTrue(store.QuadruplesCount > 0);
Expand Down
32 changes: 12 additions & 20 deletions RDFSharp/Query/Mirella/Algebra/RDFPattern.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public class RDFPattern : RDFPatternGroupMember
/// </summary>
public RDFPattern(RDFPatternMember subject, RDFPatternMember predicate, RDFPatternMember objLit)
{
#region Guards
if (subject == null)
throw new RDFQueryException("Cannot create RDFPattern because given \"subject\" parameter is null");
if (!(subject is RDFResource || subject is RDFVariable))
Expand All @@ -83,6 +84,7 @@ public RDFPattern(RDFPatternMember subject, RDFPatternMember predicate, RDFPatte
throw new RDFQueryException("Cannot create RDFPattern because given \"objLit\" parameter is null");
if (!(objLit is RDFResource || objLit is RDFLiteral || objLit is RDFVariable))
throw new RDFQueryException("Cannot create RDFPattern because given \"objLit\" parameter (" + objLit + ") is neither a resource, or a literal or a variable");
#endregion

Variables = new List<RDFVariable>();
IsEvaluable = true;
Expand All @@ -91,46 +93,36 @@ public RDFPattern(RDFPatternMember subject, RDFPatternMember predicate, RDFPatte

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

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

//Object/Literal
Object = objLit;
if (objLit is RDFVariable)
{
if (!Variables.Any(v => v.Equals(objLit)))
Variables.Add((RDFVariable)objLit);
}
if (objLit is RDFVariable objVar && !Variables.Any(v => v.Equals(objVar)))
Variables.Add(objVar);
}

/// <summary>
/// Default ctor for CSPO pattern
/// </summary>
public RDFPattern(RDFPatternMember context, RDFPatternMember subject, RDFPatternMember predicate, RDFPatternMember objLit) : this(subject, predicate, objLit)
{
#region Guards
if (context == null)
throw new RDFQueryException("Cannot create RDFPattern because given \"context\" parameter is null");
if (!(context is RDFContext || context is RDFVariable))
throw new RDFQueryException("Cannot create RDFPattern because given \"context\" parameter (" + context + ") is neither a context or a variable");
#endregion

//Context
Context = context;
if (context is RDFVariable)
{
if (!Variables.Any(v => v.Equals(context)))
Variables.Add((RDFVariable)context);
}
if (context is RDFVariable ctxVar && !Variables.Any(v => v.Equals(ctxVar)))
Variables.Add(ctxVar);
}
#endregion

Expand Down
10 changes: 2 additions & 8 deletions RDFSharp/Query/Mirella/Algebra/RDFPatternGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,13 @@ public RDFPatternGroup()
/// List-ctor to build a named pattern group with the given list of patterns
/// </summary>
public RDFPatternGroup(List<RDFPattern> patterns) : this()
{
if (patterns != null)
patterns.ForEach(p => AddPattern(p));
}
=> patterns?.ForEach(p => AddPattern(p));

/// <summary>
/// List-ctor to build a named pattern group with the given list of patterns and filters
/// </summary>
public RDFPatternGroup(List<RDFPattern> patterns, List<RDFFilter> filters) : this(patterns)
{
if (filters != null)
filters.ForEach(f => AddFilter(f));
}
=> filters?.ForEach(f => AddFilter(f));
#endregion

#region Interfaces
Expand Down

0 comments on commit 57778b6

Please sign in to comment.