clerezza-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ha...@apache.org
Subject svn commit: r1524825 - 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, 19 Sep 2013 20:27:06 GMT
Author: hasan
Date: Thu Sep 19 20:27:05 2013
New Revision: 1524825

URL: http://svn.apache.org/r1524825
Log:
CLEREZZA-761: Added support of INSERT DATA and DELETE DATA update operation in SparqlPreParser,
rearranged parsing of Prologue part

Added:
    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
Modified:
    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

Added: 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=1524825&view=auto
==============================================================================
--- clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/DeleteDataOperation.java
(added)
+++ clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/DeleteDataOperation.java
Thu Sep 19 20:27:05 2013
@@ -0,0 +1,37 @@
+/*
+ * 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;
+
+/**
+ *
+ * @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/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=1524825&view=auto
==============================================================================
--- clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/InsertDataOperation.java
(added)
+++ clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/InsertDataOperation.java
Thu Sep 19 20:27:05 2013
@@ -0,0 +1,37 @@
+/*
+ * 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;
+
+/**
+ *
+ * @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/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=1524825&view=auto
==============================================================================
--- clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/UpdateOperationWithQuads.java
(added)
+++ clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/UpdateOperationWithQuads.java
Thu Sep 19 20:27:05 2013
@@ -0,0 +1,61 @@
+/*
+ * 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.HashSet;
+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
{
+
+    private UriRefOrVariable destinationGraph = null;
+
+    public UpdateOperationWithQuads(Set<TriplePattern> triplePatterns) {
+        super(triplePatterns);
+    }
+
+    public void setDestinationGraph(UriRefOrVariable destinationGraph) {
+        this.destinationGraph = destinationGraph;
+    }
+
+    @Override
+    public Set<UriRef> getInputGraphs(UriRef defaultGraph, TcProvider tcProvider) {
+        return new HashSet<UriRef>();
+    }
+
+    @Override
+    public Set<UriRef> getDestinationGraphs(UriRef defaultGraph, TcProvider tcProvider)
{
+        Set<UriRef> graphs = new HashSet<UriRef>();
+        if (destinationGraph == null) {
+            graphs.add(defaultGraph);
+        } else if (!destinationGraph.isVariable()) {
+            graphs.add(destinationGraph.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=1524825&r1=1524824&r2=1524825&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 Sep 19 20:27:05 2013
@@ -95,11 +95,14 @@ import org.apache.clerezza.rdf.core.spar
 import org.apache.clerezza.rdf.core.sparql.update.impl.ClearOrDropOperation;
 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.DropOperation;
+import org.apache.clerezza.rdf.core.sparql.update.impl.InsertDataOperation;
 import org.apache.clerezza.rdf.core.sparql.update.impl.LoadOperation;
 import org.apache.clerezza.rdf.core.sparql.update.impl.MoveOperation;
 import org.apache.clerezza.rdf.core.sparql.update.impl.SimpleUpdate;
 import org.apache.clerezza.rdf.core.sparql.update.impl.SimpleUpdateOperation;
+import org.apache.clerezza.rdf.core.sparql.update.impl.UpdateOperationWithQuads;
 
 /**
  *
@@ -377,12 +380,10 @@ TOKEN [IGNORE_CASE] :
 |   < TO : "TO" >
 |   < MOVE : "MOVE" >
 |   < COPY : "COPY" >
-|   < INSERT_DATA : "INSERT DATA" >
-|   < DELETE_DATA : "DELETE DATA" >
-|   < DELETE_WHERE : "DELETE WHERE" >
-|   < WITH : "WITH" >
-|   < DELETE : "DELETE" >
 |   < INSERT : "INSERT" >
+|   < DELETE : "DELETE" >
+|   < DATA : "DATA" >
+|   < WITH : "WITH" >
 |   < USING : "USING" >
 |   < DEFAULT_T : "DEFAULT" >
 |   < ALL : "ALL" >
@@ -402,6 +403,8 @@ TOKEN [IGNORE_CASE] :
 private SparqlUnit SparqlUnit() : {
     Query query;
     Update update; } {
+
+    Prologue()
     (
         query=QueryUnit() {
         return new SimpleSparqlUnit(query); }
@@ -412,10 +415,9 @@ private SparqlUnit SparqlUnit() : {
 }
 
 /* [1]    QueryUnit ::= Query */
-/* [1]    QueryUnit ::= Prologue Query */
 private Query QueryUnit() : {
     Query query; } {
-    Prologue()
+
     query=Query() {
     return query; }
 }
@@ -755,6 +757,10 @@ private void Update1(Update update) : {
         updateOperation = Copy()
     |
         updateOperation = Create()
+    |
+        updateOperation = InsertData()
+    |
+        updateOperation = DeleteData()
     ) {
     if (updateOperation != null) {
         update.addOperation(updateOperation);
@@ -881,7 +887,23 @@ private UpdateOperation Copy() : {
 }
 
 /* [38]    InsertData ::= 'INSERT DATA' QuadData */
+private UpdateOperation InsertData() : {
+    InsertDataOperation operation; } {
+    <INSERT> <DATA> {
+    operation = new InsertDataOperation(); }
+    QuadData(operation) {
+    return operation; }
+}
+
 /* [39]    DeleteData ::= 'DELETE DATA' QuadData */
+private UpdateOperation DeleteData() : {
+    DeleteDataOperation operation; } {
+    <DELETE> <DATA> {
+    operation = new DeleteDataOperation(); }
+    QuadData(operation) {
+    return operation; }
+}
+
 /* [40]    DeleteWhere ::= 'DELETE WHERE' QuadPattern */
 /* [41]    Modify ::= ( 'WITH' iri )? ( DeleteClause InsertClause? | InsertClause ) UsingClause*
'WHERE' GroupGraphPattern */
 /* [42]    DeleteClause ::= 'DELETE' QuadPattern */
@@ -937,8 +959,44 @@ private GraphRefAllSpec GraphRefAll() : 
 
 /* [48]    QuadPattern ::= '{' Quads '}' */
 /* [49]    QuadData ::= '{' Quads '}' */
+private void QuadData(UpdateOperationWithQuads operation) : {} {
+    "{"
+    Quads(operation)
+    "}"
+}
+
 /* [50]    Quads ::= TriplesTemplate? ( QuadsNotTriples '.'? TriplesTemplate? )* */
+private void Quads(UpdateOperationWithQuads operation) : {
+    Set<TriplePattern> triplePatterns; } {
+    (
+        triplePatterns=TriplesTemplate() {
+        operation.addTriplePatterns(triplePatterns); }
+    )?
+    (
+        QuadsNotTriples(operation)
+        ( "." )?
+        (
+            triplePatterns=TriplesTemplate() {
+            operation.addTriplePatterns(triplePatterns); }
+        )?
+    )*
+}
+
 /* [51]    QuadsNotTriples ::= 'GRAPH' VarOrIri '{' TriplesTemplate? '}' */
+private void QuadsNotTriples(UpdateOperationWithQuads operation) : {
+    UriRefOrVariable graph;
+    Set<TriplePattern> triplePatterns; } {
+
+    <GRAPH>
+    graph=VarOrIri() {
+    operation.setDestinationGraph(graph); }
+    "{"
+    (
+        triplePatterns=TriplesTemplate() {
+        operation.addTriplePatterns(triplePatterns); }
+    )?
+    "}"
+}
 
 /* [52]    TriplesTemplate ::= TriplesSameSubject ( '.' TriplesTemplate? )? */
 private Set<TriplePattern> 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=1524825&r1=1524824&r2=1524825&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 Sep 19 20:27:05 2013
@@ -273,4 +273,66 @@ public class SparqlPreParserTest {
         expected.add(TEST_GRAPH);
         Assert.assertTrue(referredGraphs.containsAll(expected));
     }
+
+    @Test
+    public void testInsertDataToDefaultGraph() throws ParseException {
+
+        String queryStr = "PREFIX dc: <http://purl.org/dc/elements/1.1/> INSERT DATA
{ \n" +
+                "<http://example/book1> dc:title \"A new book\" ; dc:creator \"A.N.Other\"
. }";
+
+        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 testInsertDataToNamedGraph() throws ParseException {
+
+        String queryStr = "PREFIX ns: <http://example.org/ns#>\n" +
+                "INSERT DATA { GRAPH " + TEST_GRAPH.toString() + " { <http://example/book1>
 ns:price  42 } }";
+        SparqlPreParser parser;
+        parser = new SparqlPreParser(TcManager.getInstance());
+        Set<UriRef> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH);
+        Assert.assertTrue(referredGraphs.toArray()[0].equals(TEST_GRAPH));
+    }
+
+    @Test
+    public void testDeleteDataInDefaultGraph() throws ParseException {
+
+        String queryStr = "PREFIX dc: <http://purl.org/dc/elements/1.1/> DELETE DATA
{ \n" +
+                "<http://example/book1> dc:title \"A new book\" ; dc:creator \"A.N.Other\"
. }";
+
+        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 testDeleteDataInNamedGraph() throws ParseException {
+
+        String queryStr = "PREFIX ns: <http://example.org/ns#>\n" +
+                "DELETE DATA { GRAPH " + TEST_GRAPH.toString() + " { <http://example/book1>
 ns:price  42 } }";
+        SparqlPreParser parser;
+        parser = new SparqlPreParser(TcManager.getInstance());
+        Set<UriRef> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH);
+        Assert.assertTrue(referredGraphs.toArray()[0].equals(TEST_GRAPH));
+    }
+
+    @Test
+    public void testInsertAndDeleteData() throws ParseException {
+
+        String queryStr = "PREFIX ns: <http://example.org/ns#> " +
+                "INSERT DATA { <http://example/book1>  ns:price  42 }; " +
+                "DELETE DATA { GRAPH " + TEST_GRAPH.toString() + " { <http://example/book1>
 ns:price  42 } }";
+        SparqlPreParser parser;
+        parser = new SparqlPreParser(TcManager.getInstance());
+        Set<UriRef> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH);
+
+        Set<UriRef> expected = new HashSet<UriRef>();
+        expected.add(DEFAULT_GRAPH);
+        expected.add(TEST_GRAPH);
+        Assert.assertTrue(referredGraphs.containsAll(expected));
+    }
 }



Mime
View raw message