From 4f031b2c3734302919bb49d99920fffd1866093d Mon Sep 17 00:00:00 2001 From: Marco De Salvo Date: Sat, 16 Sep 2023 11:20:29 +0200 Subject: [PATCH] Sync to latest developments (#319) --- .../Operations/RDFInsertWhereOperationTest.cs | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/RDFSharp.Test/Query/Mirella/Algebra/Operations/RDFInsertWhereOperationTest.cs b/RDFSharp.Test/Query/Mirella/Algebra/Operations/RDFInsertWhereOperationTest.cs index 8e0841b4..c9aad4ff 100644 --- a/RDFSharp.Test/Query/Mirella/Algebra/Operations/RDFInsertWhereOperationTest.cs +++ b/RDFSharp.Test/Query/Mirella/Algebra/Operations/RDFInsertWhereOperationTest.cs @@ -417,6 +417,94 @@ public void ShouldPrintComplexOperationWithBindAndExpressions() Assert.IsTrue(string.Equals(operationString, @"PREFIX rdf: +INSERT { + ?Y rdf:type . +} +WHERE { + { + { + BIND(?Y AS ?YBIND3) . + { ?Y ?X } + UNION + { ?Y ?X } + BIND(?Y AS ?YBIND) . + ?Y ?X . + } + UNION + { + ?Y ?X . + BIND(?Y AS ?YBIND2) . + { ?Y ?X } + UNION + { ?Y ?X } + } + } + { + { + SELECT ?Y + WHERE { + { + ?Y (|) ?X . + } + } + } + UNION + { + SELECT ?Y ?X ((?X + 1) AS ?XADD1) + WHERE { + { + ?X ?Y . + } + } + ORDER BY DESC(?X) + } + } +}")); + } + + [TestMethod] + public void ShouldPrintComplexOperationWithBindAndExpressionsAndLastQueryMemberUnions() + { + RDFInsertWhereOperation operation = new RDFInsertWhereOperation() + .AddPrefix(RDFNamespaceRegister.GetByPrefix("rdf")) + .AddInsertTemplate(new RDFPattern(new RDFVariable("?Y"), RDFVocabulary.RDF.TYPE, new RDFResource("ex:dog")).Optional()) + .AddPatternGroup(new RDFPatternGroup() + .AddBind(new RDFBind(new RDFVariableExpression(new RDFVariable("?Y")), new RDFVariable("?YBIND3"))) + .AddPattern(new RDFPattern(new RDFVariable("?Y"), new RDFResource("ex:dogOf"), new RDFVariable("?X")) + .UnionWithNext()) + .AddPattern(new RDFPattern(new RDFVariable("?Y"), new RDFResource("ex:isDogOf"), new RDFVariable("?X"))) + .AddBind(new RDFBind(new RDFVariableExpression(new RDFVariable("?Y")), new RDFVariable("?YBIND"))) + .AddPattern(new RDFPattern(new RDFVariable("?Y"), new RDFResource("ex:isDoggyOf"), new RDFVariable("?X"))) + .UnionWithNext()) + .AddPatternGroup(new RDFPatternGroup() + .AddPattern(new RDFPattern(new RDFVariable("?Y"), new RDFResource("ex:isDogOf"), new RDFVariable("?X"))) + .AddBind(new RDFBind(new RDFVariableExpression(new RDFVariable("?Y")), new RDFVariable("?YBIND2"))) + .AddPattern(new RDFPattern(new RDFVariable("?Y"), new RDFResource("ex:dogOf"), new RDFVariable("?X")) + .UnionWithNext()) + .AddPattern(new RDFPattern(new RDFVariable("?Y"), new RDFResource("ex:isDoggyOf"), new RDFVariable("?X")))) + .AddSubQuery(new RDFSelectQuery() + .AddPatternGroup(new RDFPatternGroup() + .AddPropertyPath(new RDFPropertyPath(new RDFVariable("?Y"), new RDFVariable("?X")) + .AddAlternativeSteps(new List() { + new RDFPropertyPathStep(RDFVocabulary.RDFS.LABEL), + new RDFPropertyPathStep(RDFVocabulary.RDFS.COMMENT)})) + .UnionWithNext()) + .AddProjectionVariable(new RDFVariable("?Y")) + .UnionWithNext()) + .AddSubQuery(new RDFSelectQuery() + .AddPatternGroup(new RDFPatternGroup() + .AddPattern(new RDFPattern(new RDFVariable("?X"), new RDFResource("ex:hasDog"), new RDFVariable("?Y")))) + .UnionWithNext() + .AddProjectionVariable(new RDFVariable("?Y")) + .AddProjectionVariable(new RDFVariable("?X")) + .AddProjectionVariable(new RDFVariable("?XADD1"), new RDFAddExpression(new RDFVariable("?X"), new RDFTypedLiteral("1", RDFModelEnums.RDFDatatypes.XSD_INT))) + .AddModifier(new RDFOrderByModifier(new RDFVariable("?X"), RDFQueryEnums.RDFOrderByFlavors.DESC))) + .AddModifier(new RDFDistinctModifier()); + string operationString = operation.ToString(); + + Assert.IsTrue(string.Equals(operationString, +@"PREFIX rdf: + INSERT { ?Y rdf:type . }