diff --git a/RDFSharp.Test/Store/Engines/RDFMemoryStoreTest.cs b/RDFSharp.Test/Store/Engines/RDFMemoryStoreTest.cs index 6b0c9c9f..83f5ec5d 100644 --- a/RDFSharp.Test/Store/Engines/RDFMemoryStoreTest.cs +++ b/RDFSharp.Test/Store/Engines/RDFMemoryStoreTest.cs @@ -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); @@ -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); diff --git a/RDFSharp/Query/Mirella/Algebra/RDFPattern.cs b/RDFSharp/Query/Mirella/Algebra/RDFPattern.cs index 10d000d0..97114f4f 100644 --- a/RDFSharp/Query/Mirella/Algebra/RDFPattern.cs +++ b/RDFSharp/Query/Mirella/Algebra/RDFPattern.cs @@ -69,6 +69,7 @@ public class RDFPattern : RDFPatternGroupMember /// 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)) @@ -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(); IsEvaluable = true; @@ -91,27 +93,18 @@ 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); } /// @@ -119,18 +112,17 @@ public RDFPattern(RDFPatternMember subject, RDFPatternMember predicate, RDFPatte /// 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 diff --git a/RDFSharp/Query/Mirella/Algebra/RDFPatternGroup.cs b/RDFSharp/Query/Mirella/Algebra/RDFPatternGroup.cs index 6c22aaaf..5677705c 100644 --- a/RDFSharp/Query/Mirella/Algebra/RDFPatternGroup.cs +++ b/RDFSharp/Query/Mirella/Algebra/RDFPatternGroup.cs @@ -64,19 +64,13 @@ public RDFPatternGroup() /// List-ctor to build a named pattern group with the given list of patterns /// public RDFPatternGroup(List patterns) : this() - { - if (patterns != null) - patterns.ForEach(p => AddPattern(p)); - } + => patterns?.ForEach(p => AddPattern(p)); /// /// List-ctor to build a named pattern group with the given list of patterns and filters /// public RDFPatternGroup(List patterns, List filters) : this(patterns) - { - if (filters != null) - filters.ForEach(f => AddFilter(f)); - } + => filters?.ForEach(f => AddFilter(f)); #endregion #region Interfaces