Repository: marmotta Updated Branches: refs/heads/develop 5261eaa03 -> becba188a
first experiments for EXISTS/NOT EXISTS: added a test and a naive (non-working) implementation (MARMOTTA-542) Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/3696d9d6 Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/3696d9d6 Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/3696d9d6 Branch: refs/heads/develop Commit: 3696d9d66850083d773f4543f3ba7d1395d4cf82 Parents: ee1f7b8 Author: Sebastian Schaffert <[email protected]> Authored: Thu Sep 18 18:18:27 2014 +0200 Committer: Sebastian Schaffert <[email protected]> Committed: Thu Sep 18 18:18:27 2014 +0200 ---------------------------------------------------------------------- .../kiwi/sparql/builder/SQLBuilder.java | 10 +++++++- .../evaluation/KiWiEvaluationStrategyImpl.java | 2 ++ .../kiwi/sparql/test/KiWiSparqlJoinTest.java | 13 ++++++++++ .../marmotta/kiwi/sparql/test/query32.sparql | 26 ++++++++++++++++++++ .../marmotta/kiwi/sparql/test/query33.sparql | 24 ++++++++++++++++++ 5 files changed, 74 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/marmotta/blob/3696d9d6/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/SQLBuilder.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/SQLBuilder.java b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/SQLBuilder.java index 982a5a9..e8ec9d1 100644 --- a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/SQLBuilder.java +++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/SQLBuilder.java @@ -709,7 +709,15 @@ public class SQLBuilder { } else if(expr instanceof Or) { return "(" + evaluateExpression(((Or) expr).getLeftArg(), optype) + " OR " + evaluateExpression(((Or) expr).getRightArg(), optype) + ")"; } else if(expr instanceof Not) { - return "NOT (" + evaluateExpression(((Not) expr).getArg(), optype) + ")"; + return "NOT (" + evaluateExpression(((Not) expr).getArg(), optype) + ")"; + } else if(expr instanceof Exists) { + + // TODO: need to make sure that variables of the parent are visible in the subquery + // - pattern names need to be unique even in subqueries + // - variable lookup for expressions in the subquery need to refer to the parent + SQLBuilder sq_builder = new SQLBuilder(((Exists) expr).getSubQuery(), bindings, dataset, converter, dialect, Collections.EMPTY_SET); + + return "EXISTS (" + sq_builder.build() + ")"; } else if(expr instanceof Str) { Str str = (Str)expr; http://git-wip-us.apache.org/repos/asf/marmotta/blob/3696d9d6/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/evaluation/KiWiEvaluationStrategyImpl.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/evaluation/KiWiEvaluationStrategyImpl.java b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/evaluation/KiWiEvaluationStrategyImpl.java index 487e851..f8c7c1d 100644 --- a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/evaluation/KiWiEvaluationStrategyImpl.java +++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/evaluation/KiWiEvaluationStrategyImpl.java @@ -321,6 +321,8 @@ public class KiWiEvaluationStrategyImpl extends EvaluationStrategyImpl{ return isSupported(((Or) expr).getLeftArg()) && isSupported(((Or) expr).getRightArg()); } else if(expr instanceof Not) { return isSupported(((Not) expr).getArg()); + } else if(expr instanceof Exists) { + return isSupported(((Exists) expr).getSubQuery()); } else if(expr instanceof ValueConstant) { return true; } else if(expr instanceof Var) { http://git-wip-us.apache.org/repos/asf/marmotta/blob/3696d9d6/libraries/kiwi/kiwi-sparql/src/test/java/org/apache/marmotta/kiwi/sparql/test/KiWiSparqlJoinTest.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-sparql/src/test/java/org/apache/marmotta/kiwi/sparql/test/KiWiSparqlJoinTest.java b/libraries/kiwi/kiwi-sparql/src/test/java/org/apache/marmotta/kiwi/sparql/test/KiWiSparqlJoinTest.java index e19c83b..9bc95e3 100644 --- a/libraries/kiwi/kiwi-sparql/src/test/java/org/apache/marmotta/kiwi/sparql/test/KiWiSparqlJoinTest.java +++ b/libraries/kiwi/kiwi-sparql/src/test/java/org/apache/marmotta/kiwi/sparql/test/KiWiSparqlJoinTest.java @@ -318,6 +318,19 @@ public class KiWiSparqlJoinTest { testQuery("query31.sparql"); } + // minus + @Test + @Ignore("not implemented yet, see MARMOTTA-541") + public void testQuery32() throws Exception { + testQuery("query32.sparql"); + } + + // not exists + @Test + public void testQuery33() throws Exception { + testQuery("query33.sparql"); + } + // INSERT/UPDATE @Test http://git-wip-us.apache.org/repos/asf/marmotta/blob/3696d9d6/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query32.sparql ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query32.sparql b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query32.sparql new file mode 100644 index 0000000..cd6a6e5 --- /dev/null +++ b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query32.sparql @@ -0,0 +1,26 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +PREFIX foaf: <http://xmlns.com/foaf/0.1/> +PREFIX dc: <http://purl.org/dc/elements/1.1/> + +SELECT DISTINCT ?s WHERE { + ?s ?p ?o . + MINUS { + ?s foaf:name "Hans Meier" . + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/marmotta/blob/3696d9d6/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query33.sparql ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query33.sparql b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query33.sparql new file mode 100644 index 0000000..ed2267b --- /dev/null +++ b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query33.sparql @@ -0,0 +1,24 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +PREFIX foaf: <http://xmlns.com/foaf/0.1/> +PREFIX dc: <http://purl.org/dc/elements/1.1/> + +SELECT DISTINCT ?s ?o WHERE { + ?s foaf:name ?o . + FILTER NOT EXISTS { ?s foaf:depiction [] } . +} \ No newline at end of file
