clerezza-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ha...@apache.org
Subject svn commit: r1528709 - in /clerezza/trunk/rdf.core/src: main/java/org/apache/clerezza/rdf/core/sparql/update/impl/ main/javacc/org/apache/clerezza/rdf/core/sparql/ test/java/org/apache/clerezza/rdf/core/sparql/
Date Thu, 03 Oct 2013 03:58:18 GMT
Author: hasan
Date: Thu Oct  3 03:58:17 2013
New Revision: 1528709

URL: http://svn.apache.org/r1528709
Log:
CLEREZZA-761: Fixed parsing of Quads that may contain more than one named graph, added support
of DELETE WHERE update operation in SparqlPreParser, rearranged parsing of Prologue in update

Added:
    clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/DeleteWhereOperation.java
    clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/Quad.java
Modified:
    clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/DeleteDataOperation.java
    clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/InsertDataOperation.java
    clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/UpdateOperationWithQuads.java
    clerezza/trunk/rdf.core/src/main/javacc/org/apache/clerezza/rdf/core/sparql/JavaCCGeneratedSparqlPreParser.jj
    clerezza/trunk/rdf.core/src/test/java/org/apache/clerezza/rdf/core/sparql/SparqlPreParserTest.java

Modified: clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/DeleteDataOperation.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/DeleteDataOperation.java?rev=1528709&r1=1528708&r2=1528709&view=diff
==============================================================================
--- clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/DeleteDataOperation.java
(original)
+++ clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/DeleteDataOperation.java
Thu Oct  3 03:58:17 2013
@@ -18,20 +18,9 @@
  */
 package org.apache.clerezza.rdf.core.sparql.update.impl;
 
-import java.util.Set;
-import org.apache.clerezza.rdf.core.sparql.query.TriplePattern;
-
 /**
  *
  * @author hasan
  */
 public class DeleteDataOperation extends UpdateOperationWithQuads {
-
-    public DeleteDataOperation() {
-        super(null);
-    }
-
-    public DeleteDataOperation(Set<TriplePattern> triplePatterns) {
-        super(triplePatterns);
-    }
 }

Added: clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/DeleteWhereOperation.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/DeleteWhereOperation.java?rev=1528709&view=auto
==============================================================================
--- clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/DeleteWhereOperation.java
(added)
+++ clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/DeleteWhereOperation.java
Thu Oct  3 03:58:17 2013
@@ -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.
+ */
+package org.apache.clerezza.rdf.core.sparql.update.impl;
+
+/**
+ *
+ * @author hasan
+ */
+public class DeleteWhereOperation extends UpdateOperationWithQuads {
+}

Modified: clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/InsertDataOperation.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/InsertDataOperation.java?rev=1528709&r1=1528708&r2=1528709&view=diff
==============================================================================
--- clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/InsertDataOperation.java
(original)
+++ clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/InsertDataOperation.java
Thu Oct  3 03:58:17 2013
@@ -18,20 +18,9 @@
  */
 package org.apache.clerezza.rdf.core.sparql.update.impl;
 
-import java.util.Set;
-import org.apache.clerezza.rdf.core.sparql.query.TriplePattern;
-
 /**
  *
  * @author hasan
  */
 public class InsertDataOperation extends UpdateOperationWithQuads {
-
-    public InsertDataOperation() {
-        super(null);
-    }
-
-    public InsertDataOperation(Set<TriplePattern> triplePatterns) {
-        super(triplePatterns);
-    }
 }

Added: clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/Quad.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/Quad.java?rev=1528709&view=auto
==============================================================================
--- clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/Quad.java
(added)
+++ clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/Quad.java
Thu Oct  3 03:58:17 2013
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ */
+package org.apache.clerezza.rdf.core.sparql.update.impl;
+
+import java.util.Set;
+import org.apache.clerezza.rdf.core.sparql.query.TriplePattern;
+import org.apache.clerezza.rdf.core.sparql.query.UriRefOrVariable;
+import org.apache.clerezza.rdf.core.sparql.query.impl.SimpleBasicGraphPattern;
+
+/**
+ *
+ * @author hasan
+ */
+public class Quad extends SimpleBasicGraphPattern {
+
+    private UriRefOrVariable graph = null;
+
+    public Quad(UriRefOrVariable graph, Set<TriplePattern> triplePatterns) {
+        super(triplePatterns);
+        this.graph = graph;
+    }
+
+    public UriRefOrVariable getGraph() {
+        return this.graph;
+    }
+}

Modified: clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/UpdateOperationWithQuads.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/UpdateOperationWithQuads.java?rev=1528709&r1=1528708&r2=1528709&view=diff
==============================================================================
--- clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/UpdateOperationWithQuads.java
(original)
+++ clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/UpdateOperationWithQuads.java
Thu Oct  3 03:58:17 2013
@@ -18,29 +18,42 @@
  */
 package org.apache.clerezza.rdf.core.sparql.update.impl;
 
+import java.util.ArrayList;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 import org.apache.clerezza.rdf.core.UriRef;
 import org.apache.clerezza.rdf.core.access.TcProvider;
 import org.apache.clerezza.rdf.core.sparql.query.TriplePattern;
 import org.apache.clerezza.rdf.core.sparql.query.UriRefOrVariable;
-import org.apache.clerezza.rdf.core.sparql.query.impl.SimpleBasicGraphPattern;
 import org.apache.clerezza.rdf.core.sparql.update.UpdateOperation;
 
 /**
  *
  * @author hasan
  */
-public class UpdateOperationWithQuads extends SimpleBasicGraphPattern implements UpdateOperation
{
+public class UpdateOperationWithQuads implements UpdateOperation {
 
-    private UriRefOrVariable destinationGraph = null;
+    private Quad defaultQuad = null;
+    private List<Quad> quads = new ArrayList<Quad>();
 
-    public UpdateOperationWithQuads(Set<TriplePattern> triplePatterns) {
-        super(triplePatterns);
+    public UpdateOperationWithQuads() {
     }
 
-    public void setDestinationGraph(UriRefOrVariable destinationGraph) {
-        this.destinationGraph = destinationGraph;
+    public void addQuad(Set<TriplePattern> triplePatterns) {
+        if (defaultQuad == null) {
+            defaultQuad = new Quad(null, triplePatterns);
+        } else {
+            defaultQuad.addTriplePatterns(triplePatterns);
+        }
+    }
+
+    public void addQuad(UriRefOrVariable graph, Set<TriplePattern> triplePatterns)
{
+        if (graph == null) {
+            addQuad(triplePatterns);
+        } else {
+            quads.add(new Quad(graph, triplePatterns));
+        }
     }
 
     @Override
@@ -51,10 +64,14 @@ public class UpdateOperationWithQuads ex
     @Override
     public Set<UriRef> getDestinationGraphs(UriRef defaultGraph, TcProvider tcProvider)
{
         Set<UriRef> graphs = new HashSet<UriRef>();
-        if (destinationGraph == null) {
+        if (defaultQuad != null) {
             graphs.add(defaultGraph);
-        } else if (!destinationGraph.isVariable()) {
-            graphs.add(destinationGraph.getResource());
+        }
+        for (Quad quad : quads) {
+            UriRefOrVariable graph = quad.getGraph();
+            if (!graph.isVariable()) {
+                graphs.add(graph.getResource());
+            }
         }
         return graphs;
     }

Modified: clerezza/trunk/rdf.core/src/main/javacc/org/apache/clerezza/rdf/core/sparql/JavaCCGeneratedSparqlPreParser.jj
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.core/src/main/javacc/org/apache/clerezza/rdf/core/sparql/JavaCCGeneratedSparqlPreParser.jj?rev=1528709&r1=1528708&r2=1528709&view=diff
==============================================================================
--- clerezza/trunk/rdf.core/src/main/javacc/org/apache/clerezza/rdf/core/sparql/JavaCCGeneratedSparqlPreParser.jj
(original)
+++ clerezza/trunk/rdf.core/src/main/javacc/org/apache/clerezza/rdf/core/sparql/JavaCCGeneratedSparqlPreParser.jj
Thu Oct  3 03:58:17 2013
@@ -96,6 +96,7 @@ import org.apache.clerezza.rdf.core.spar
 import org.apache.clerezza.rdf.core.sparql.update.impl.CopyOperation;
 import org.apache.clerezza.rdf.core.sparql.update.impl.CreateOperation;
 import org.apache.clerezza.rdf.core.sparql.update.impl.DeleteDataOperation;
+import org.apache.clerezza.rdf.core.sparql.update.impl.DeleteWhereOperation;
 import org.apache.clerezza.rdf.core.sparql.update.impl.DropOperation;
 import org.apache.clerezza.rdf.core.sparql.update.impl.InsertDataOperation;
 import org.apache.clerezza.rdf.core.sparql.update.impl.LoadOperation;
@@ -728,12 +729,13 @@ private void ValuesClause(Query query) :
 }
 
 /* [29]    Update ::= Prologue ( Update1 ( ';' Update )? )? */
+/* [29]    Update ::= ( Update1 ( ';' Prologue Update )? )? */
 private void Update(Update update) : {} {
-    Prologue()
     (
         Update1(update)
         (
             ";"
+            Prologue()
             Update(update)
         )?
     )?
@@ -760,7 +762,10 @@ private void Update1(Update update) : {
     |
         updateOperation = InsertData()
     |
+        LOOKAHEAD(2)
         updateOperation = DeleteData()
+    |
+        updateOperation = DeleteWhere()
     ) {
     if (updateOperation != null) {
         update.addOperation(updateOperation);
@@ -905,6 +910,14 @@ private UpdateOperation DeleteData() : {
 }
 
 /* [40]    DeleteWhere ::= 'DELETE WHERE' QuadPattern */
+private UpdateOperation DeleteWhere() : {
+    DeleteWhereOperation operation; } {
+    <DELETE> <WHERE> {
+    operation = new DeleteWhereOperation(); }
+    QuadPattern(operation) {
+    return operation; }
+}
+
 /* [41]    Modify ::= ( 'WITH' iri )? ( DeleteClause InsertClause? | InsertClause ) UsingClause*
'WHERE' GroupGraphPattern */
 /* [42]    DeleteClause ::= 'DELETE' QuadPattern */
 /* [43]    InsertClause ::= 'INSERT' QuadPattern */
@@ -958,6 +971,12 @@ private GraphRefAllSpec GraphRefAll() : 
 }
 
 /* [48]    QuadPattern ::= '{' Quads '}' */
+private void QuadPattern(UpdateOperationWithQuads operation) : {} {
+    "{"
+    Quads(operation)
+    "}"
+}
+
 /* [49]    QuadData ::= '{' Quads '}' */
 private void QuadData(UpdateOperationWithQuads operation) : {} {
     "{"
@@ -970,14 +989,14 @@ private void Quads(UpdateOperationWithQu
     Set<TriplePattern> triplePatterns; } {
     (
         triplePatterns=TriplesTemplate() {
-        operation.addTriplePatterns(triplePatterns); }
+        operation.addQuad(triplePatterns); }
     )?
     (
         QuadsNotTriples(operation)
         ( "." )?
         (
             triplePatterns=TriplesTemplate() {
-            operation.addTriplePatterns(triplePatterns); }
+            operation.addQuad(triplePatterns); }
         )?
     )*
 }
@@ -985,17 +1004,16 @@ private void Quads(UpdateOperationWithQu
 /* [51]    QuadsNotTriples ::= 'GRAPH' VarOrIri '{' TriplesTemplate? '}' */
 private void QuadsNotTriples(UpdateOperationWithQuads operation) : {
     UriRefOrVariable graph;
-    Set<TriplePattern> triplePatterns; } {
+    Set<TriplePattern> triplePatterns = null; } {
 
     <GRAPH>
-    graph=VarOrIri() {
-    operation.setDestinationGraph(graph); }
+    graph=VarOrIri()
     "{"
     (
-        triplePatterns=TriplesTemplate() {
-        operation.addTriplePatterns(triplePatterns); }
+        triplePatterns=TriplesTemplate()
     )?
-    "}"
+    "}" {
+    operation.addQuad(graph, triplePatterns); }
 }
 
 /* [52]    TriplesTemplate ::= TriplesSameSubject ( '.' TriplesTemplate? )? */

Modified: clerezza/trunk/rdf.core/src/test/java/org/apache/clerezza/rdf/core/sparql/SparqlPreParserTest.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.core/src/test/java/org/apache/clerezza/rdf/core/sparql/SparqlPreParserTest.java?rev=1528709&r1=1528708&r2=1528709&view=diff
==============================================================================
--- clerezza/trunk/rdf.core/src/test/java/org/apache/clerezza/rdf/core/sparql/SparqlPreParserTest.java
(original)
+++ clerezza/trunk/rdf.core/src/test/java/org/apache/clerezza/rdf/core/sparql/SparqlPreParserTest.java
Thu Oct  3 03:58:17 2013
@@ -335,4 +335,34 @@ public class SparqlPreParserTest {
         expected.add(TEST_GRAPH);
         Assert.assertTrue(referredGraphs.containsAll(expected));
     }
+
+    @Test
+    public void testDeleteWhereInDefaultGraph() throws ParseException {
+
+        String queryStr = "PREFIX foaf: <http://xmlns.com/foaf/0.1/> " +
+                "DELETE WHERE { ?person foaf:givenName 'Fred'; ?property ?value }";
+
+        SparqlPreParser parser;
+        parser = new SparqlPreParser(TcManager.getInstance());
+        Set<UriRef> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH);
+
+        Assert.assertTrue(referredGraphs.toArray()[0].equals(DEFAULT_GRAPH));
+    }
+
+    @Test
+    public void testDeleteWhereInNamedGraphs() throws ParseException {
+
+        String queryStr = "PREFIX foaf: <http://xmlns.com/foaf/0.1/> DELETE WHERE "
+
+                "{ GRAPH <http://example.com/names> { ?person foaf:givenName 'Fred'
; ?property1 ?value1 } " +
+                "  GRAPH <http://example.com/addresses> { ?person ?property2 ?value2
} }";
+
+        SparqlPreParser parser;
+        parser = new SparqlPreParser(TcManager.getInstance());
+        Set<UriRef> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH);
+
+        Set<UriRef> expected = new HashSet<UriRef>();
+        expected.add(new UriRef("http://example.com/names"));
+        expected.add(new UriRef("http://example.com/addresses"));
+        Assert.assertTrue(referredGraphs.containsAll(expected));
+    }
 }



Mime
View raw message