http://git-wip-us.apache.org/repos/asf/clerezza/blob/f5d9dd84/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/DeleteDataOperation.java ---------------------------------------------------------------------- diff --git a/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/DeleteDataOperation.java b/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/DeleteDataOperation.java deleted file mode 100644 index c2318c6..0000000 --- a/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/DeleteDataOperation.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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 DeleteDataOperation extends UpdateOperationWithQuads { -}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/f5d9dd84/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/DeleteWhereOperation.java ---------------------------------------------------------------------- diff --git a/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/DeleteWhereOperation.java b/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/DeleteWhereOperation.java deleted file mode 100644 index 6704775..0000000 --- a/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/DeleteWhereOperation.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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 { -} http://git-wip-us.apache.org/repos/asf/clerezza/blob/f5d9dd84/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/DropOperation.java ---------------------------------------------------------------------- diff --git a/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/DropOperation.java b/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/DropOperation.java deleted file mode 100644 index e70a93f..0000000 --- a/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/DropOperation.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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 DropOperation extends ClearOrDropOperation { -} http://git-wip-us.apache.org/repos/asf/clerezza/blob/f5d9dd84/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/InsertDataOperation.java ---------------------------------------------------------------------- diff --git a/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/InsertDataOperation.java b/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/InsertDataOperation.java deleted file mode 100644 index 2c985d9..0000000 --- a/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/InsertDataOperation.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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 InsertDataOperation extends UpdateOperationWithQuads { -} http://git-wip-us.apache.org/repos/asf/clerezza/blob/f5d9dd84/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/LoadOperation.java ---------------------------------------------------------------------- diff --git a/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/LoadOperation.java b/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/LoadOperation.java deleted file mode 100644 index 8dfc69f..0000000 --- a/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/LoadOperation.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.commons.rdf.IRI; -import org.apache.clerezza.rdf.core.sparql.update.UpdateOperation; - -/** - * The LOAD operation reads an RDF document from a IRI and inserts its triples into the specified ImmutableGraph in the ImmutableGraph Store. - * If the destination ImmutableGraph already exists, then no data in that ImmutableGraph will be removed. - * If no destination ImmutableGraph IRI is provided to load the triples into, then the data will be loaded into the default ImmutableGraph. - * @see <a href="http://www.w3.org/TR/2013/REC-sparql11-update-20130321/#load">SPARQL 1.1 Update: 3.1.4 LOAD</a> - * @author hasan - */ -public class LoadOperation extends SimpleUpdateOperation { - - public void setSource(IRI source) { - setInputGraph(source); - } - - public IRI getSource() { - return getInputGraph(null); - } -} http://git-wip-us.apache.org/repos/asf/clerezza/blob/f5d9dd84/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/ModifyOperation.java ---------------------------------------------------------------------- diff --git a/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/ModifyOperation.java b/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/ModifyOperation.java deleted file mode 100644 index 97ce39b..0000000 --- a/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/ModifyOperation.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * 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.commons.rdf.IRI; -import org.apache.clerezza.rdf.core.access.TcProvider; -import org.apache.clerezza.rdf.core.sparql.query.GroupGraphPattern; -import org.apache.clerezza.rdf.core.sparql.query.impl.SimpleDataSet; -import org.apache.clerezza.rdf.core.sparql.update.UpdateOperation; - -/** - * This ModifyOperation is a DELETE/INSERT operation. - * @see <a href="http://www.w3.org/TR/2013/REC-sparql11-update-20130321/#deleteInsert">SPARQL 1.1 Update: 3.1.3 DELETE/INSERT</a> - * - * The DELETE/INSERT operation can be used to remove or add triples from/to the ImmutableGraph Store based on bindings - * for a query pattern specified in a WHERE clause. - * - * @author hasan - */ -public class ModifyOperation implements UpdateOperation { - private IRI fallbackGraph = null; - private UpdateOperationWithQuads deleteOperation = null; - private UpdateOperationWithQuads insertOperation = null; - private SimpleDataSet dataSet = null; - private GroupGraphPattern queryPattern = null; - - public void setFallbackGraph(IRI fallbackGraph) { - this.fallbackGraph = fallbackGraph; - } - - public void setDeleteOperation(UpdateOperationWithQuads deleteOperation) { - this.deleteOperation = deleteOperation; - } - - public void setInsertOperation(UpdateOperationWithQuads insertOperation) { - this.insertOperation = insertOperation; - } - - public void setDataSet(SimpleDataSet dataSet) { - this.dataSet = dataSet; - } - - public void addGraphToDataSet(IRI ImmutableGraph) { - if (dataSet == null) { - dataSet = new SimpleDataSet(); - } - dataSet.addDefaultGraph(ImmutableGraph); - } - - public void addNamedGraphToDataSet(IRI namedGraph) { - if (dataSet == null) { - dataSet = new SimpleDataSet(); - } - dataSet.addNamedGraph(namedGraph); - } - - public void setQueryPattern(GroupGraphPattern queryPattern) { - this.queryPattern = queryPattern; - } - - @Override - public Set<IRI> getInputGraphs(IRI defaultGraph, TcProvider tcProvider) { - Set<IRI> graphs = new HashSet<IRI>(); - if (dataSet != null) { - graphs.addAll(dataSet.getDefaultGraphs()); - graphs.addAll(dataSet.getNamedGraphs()); - } else { - if (fallbackGraph != null) { - graphs.add(fallbackGraph); - } - } - if (graphs.isEmpty()) { - graphs.add(defaultGraph); - } - if (queryPattern != null) { - graphs.addAll(queryPattern.getReferredGraphs()); - } - return graphs; - } - - @Override - public Set<IRI> getDestinationGraphs(IRI defaultGraph, TcProvider tcProvider) { - Set<IRI> graphs = new HashSet<IRI>(); - IRI dfltGraph = (fallbackGraph != null) ? fallbackGraph : defaultGraph; - if (deleteOperation != null) { - graphs.addAll(deleteOperation.getDestinationGraphs(dfltGraph, tcProvider)); - } - if (insertOperation != null) { - graphs.addAll(insertOperation.getDestinationGraphs(dfltGraph, tcProvider)); - } - return graphs; - } -} http://git-wip-us.apache.org/repos/asf/clerezza/blob/f5d9dd84/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/MoveOperation.java ---------------------------------------------------------------------- diff --git a/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/MoveOperation.java b/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/MoveOperation.java deleted file mode 100644 index 84bc569..0000000 --- a/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/MoveOperation.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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 MoveOperation extends SimpleUpdateOperation { -} http://git-wip-us.apache.org/repos/asf/clerezza/blob/f5d9dd84/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/Quad.java ---------------------------------------------------------------------- diff --git a/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/Quad.java b/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/Quad.java deleted file mode 100644 index ff26de0..0000000 --- a/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/Quad.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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 ImmutableGraph = null; - - public Quad(UriRefOrVariable ImmutableGraph, Set<TriplePattern> triplePatterns) { - super(triplePatterns); - this.ImmutableGraph = ImmutableGraph; - } - - public UriRefOrVariable getGraph() { - return this.ImmutableGraph; - } -} http://git-wip-us.apache.org/repos/asf/clerezza/blob/f5d9dd84/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/SimpleUpdate.java ---------------------------------------------------------------------- diff --git a/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/SimpleUpdate.java b/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/SimpleUpdate.java deleted file mode 100644 index c91ee95..0000000 --- a/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/SimpleUpdate.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import org.apache.clerezza.commons.rdf.IRI; -import org.apache.clerezza.rdf.core.access.TcProvider; -import org.apache.clerezza.rdf.core.sparql.update.Update; -import org.apache.clerezza.rdf.core.sparql.update.UpdateOperation; - -/** - * - * @author hasan - */ -public class SimpleUpdate implements Update { - protected List<UpdateOperation> operations = new ArrayList<UpdateOperation>(); - - @Override - public Set<IRI> getReferredGraphs(IRI defaultGraph, TcProvider tcProvider) { - Set<IRI> referredGraphs = new HashSet<IRI>(); - for (UpdateOperation operation : operations) { - referredGraphs.addAll(operation.getInputGraphs(defaultGraph, tcProvider)); - referredGraphs.addAll(operation.getDestinationGraphs(defaultGraph, tcProvider)); - } - return referredGraphs; - } - - @Override - public void addOperation(UpdateOperation updateOperation) { - operations.add(updateOperation); - } -} http://git-wip-us.apache.org/repos/asf/clerezza/blob/f5d9dd84/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/SimpleUpdateOperation.java ---------------------------------------------------------------------- diff --git a/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/SimpleUpdateOperation.java b/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/SimpleUpdateOperation.java deleted file mode 100644 index 6042536..0000000 --- a/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/SimpleUpdateOperation.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * 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.commons.rdf.IRI; -import org.apache.clerezza.rdf.core.sparql.update.UpdateOperation; - -/** - * - * @author hasan - */ -public class SimpleUpdateOperation extends BaseUpdateOperation { - - private boolean silent; - - public SimpleUpdateOperation() { - this.silent = false; - inputGraphSpec = UpdateOperation.GraphSpec.DEFAULT; - destinationGraphSpec = UpdateOperation.GraphSpec.DEFAULT; - } - - public void setSilent(boolean silent) { - this.silent = silent; - } - - public boolean isSilent() { - return silent; - } - - public void setInputGraph(IRI source) { - inputGraphSpec = UpdateOperation.GraphSpec.GRAPH; - inputGraphs.clear(); - inputGraphs.add(source); - } - - public IRI getInputGraph(IRI defaultGraph) { - Set<IRI> result = getInputGraphs(defaultGraph, null); - if (result.isEmpty()) { - return null; - } else { - return result.iterator().next(); - } - } - - public void setDestinationGraph(IRI destination) { - destinationGraphSpec = UpdateOperation.GraphSpec.GRAPH; - destinationGraphs.clear(); - destinationGraphs.add(destination); - } - - public IRI getDestinationGraph(IRI defaultGraph) { - Set<IRI> result = getDestinationGraphs(defaultGraph, null); - if (result.isEmpty()) { - return null; - } else { - return result.iterator().next(); - } - } -} http://git-wip-us.apache.org/repos/asf/clerezza/blob/f5d9dd84/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/UpdateOperationWithQuads.java ---------------------------------------------------------------------- diff --git a/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/UpdateOperationWithQuads.java b/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/UpdateOperationWithQuads.java deleted file mode 100644 index 5b2ea57..0000000 --- a/rdf/core/src/main/java/org/apache/clerezza/rdf/core/sparql/update/impl/UpdateOperationWithQuads.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * 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.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import org.apache.clerezza.commons.rdf.IRI; -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.update.UpdateOperation; - -/** - * - * @author hasan - */ -public class UpdateOperationWithQuads implements UpdateOperation { - - private Quad defaultQuad = null; - private List<Quad> quads = new ArrayList<Quad>(); - - public UpdateOperationWithQuads() { - } - - public void addQuad(Set<TriplePattern> triplePatterns) { - if (defaultQuad == null) { - defaultQuad = new Quad(null, triplePatterns); - } else { - defaultQuad.addTriplePatterns(triplePatterns); - } - } - - public void addQuad(UriRefOrVariable ImmutableGraph, Set<TriplePattern> triplePatterns) { - if (ImmutableGraph == null) { - addQuad(triplePatterns); - } else { - quads.add(new Quad(ImmutableGraph, triplePatterns)); - } - } - - @Override - public Set<IRI> getInputGraphs(IRI defaultGraph, TcProvider tcProvider) { - return new HashSet<IRI>(); - } - - @Override - public Set<IRI> getDestinationGraphs(IRI defaultGraph, TcProvider tcProvider) { - Set<IRI> graphs = new HashSet<IRI>(); - if (defaultQuad != null) { - graphs.add(defaultGraph); - } - for (Quad quad : quads) { - UriRefOrVariable ImmutableGraph = quad.getGraph(); - if (!ImmutableGraph.isVariable()) { - graphs.add(ImmutableGraph.getResource()); - } - } - return graphs; - } -} http://git-wip-us.apache.org/repos/asf/clerezza/blob/f5d9dd84/rdf/core/src/test/java/org/apache/clerezza/rdf/core/sparql/QueryParserSerializerCombinationTest.java ---------------------------------------------------------------------- diff --git a/rdf/core/src/test/java/org/apache/clerezza/rdf/core/sparql/QueryParserSerializerCombinationTest.java b/rdf/core/src/test/java/org/apache/clerezza/rdf/core/sparql/QueryParserSerializerCombinationTest.java deleted file mode 100644 index 50eeee5..0000000 --- a/rdf/core/src/test/java/org/apache/clerezza/rdf/core/sparql/QueryParserSerializerCombinationTest.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * 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; - -import org.apache.clerezza.rdf.core.sparql.query.Query; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * - * @author hasan - */ -public class QueryParserSerializerCombinationTest { - - public QueryParserSerializerCombinationTest() { - } - - @BeforeClass - public static void setUpClass() { - } - - @AfterClass - public static void tearDownClass() { - } - - @Before - public void setUp() { - } - - @After - public void tearDown() { - } - - @Test - public void testPatternOrderPreservation() throws Exception { - String queryString = - "SELECT ?property ?range ?property_description ?subproperty ?subproperty_description \n" - + "WHERE\n" - + "{ ?property <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#ObjectProperty> .\n" - + "{ { ?property <http://www.w3.org/2000/01/rdf-schema#domain> ?superclass .\n" - + "<http://example.org/ontologies/market_ontology.owl#Company> <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?superclass .\n" - + "} UNION { ?property <http://www.w3.org/2000/01/rdf-schema#domain> ?dunion .\n" - + "?dunion <http://www.w3.org/2002/07/owl#unionOf> ?dlist .\n" - + "?dlist <http://jena.hpl.hp.com/ARQ/list#member> ?superclass .\n" - + "<http://example.org/ontologies/market_ontology.owl#Company> <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?superclass .\n" - + "} } { { ?property <http://www.w3.org/2000/01/rdf-schema#range> ?superrange .\n" - + "?range <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?superrange .\n" - + "FILTER (! (isBLANK(?range)))\n" - + "} UNION { ?property <http://www.w3.org/2000/01/rdf-schema#range> ?range .\n" - + "FILTER (! (isBLANK(?range)))\n" - + "} } OPTIONAL { ?somesub <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?range .\n" - + "FILTER (((?somesub) != (<http://www.w3.org/2002/07/owl#Nothing>)) && ((?somesub) != (?range)))\n" - + "} OPTIONAL { ?subproperty <http://www.w3.org/2000/01/rdf-schema#subPropertyOf> ?property .\n" - + " OPTIONAL { ?subproperty <http://purl.org/dc/elements/1.1/description> ?subproperty_description .\n" - + "} FILTER (((?subproperty) != (<http://www.w3.org/2002/07/owl#bottomObjectProperty>)) && ((?subproperty) != (?property)))\n" - + "} OPTIONAL { ?property <http://purl.org/dc/elements/1.1/description> ?property_description .\n" - + "} FILTER ((?property) != (<http://www.w3.org/2002/07/owl#bottomObjectProperty>))\n" - + "FILTER ((?range) != (<http://www.w3.org/2002/07/owl#Nothing>))\n" - + "FILTER (! (BOUND(?somesub)))\n" - + "} \n"; - - Query query = QueryParser.getInstance().parse(queryString); - Assert.assertEquals(queryString.replaceAll("\\s", "").trim(), query.toString().replaceAll("\\s", "").trim()); - } - - @Test - public void testParsingAndSerializationStability() throws Exception { - String queryString = - "PREFIX mo: <http://example.org/ontologies/market_ontology.owl#>\n" - + "PREFIX list: <http://jena.hpl.hp.com/ARQ/list#>\n" - + "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n" - + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" - + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" - + "PREFIX dc: <http://purl.org/dc/elements/1.1/>\n" - + "SELECT ?property ?range ?property_description ?subproperty ?subproperty_description\n" - + "WHERE {\n" - + " ?property a owl:ObjectProperty .\n" - + " FILTER (?property != owl:bottomObjectProperty) .\n" - + " {\n" - + " {\n" - + " ?property rdfs:domain ?superclass .\n" - + " mo:Company rdfs:subClassOf ?superclass .\n" - + " }\n" - + " UNION\n" - + " {\n" - + " ?property rdfs:domain ?dunion .\n" - + " ?dunion owl:unionOf ?dlist .\n" - + " ?dlist list:member ?superclass .\n" - + " mo:Company rdfs:subClassOf ?superclass .\n" - + " }\n" - + " }\n" - + " {\n" - + " {\n" - + " ?property rdfs:range ?superrange .\n" - + " ?range rdfs:subClassOf ?superrange .\n" - + " FILTER (!isBlank(?range)) .\n" - + " }\n" - + " UNION\n" - + " {\n" - + " ?property rdfs:range ?range .\n" - + " FILTER (!isBlank(?range)) .\n" - + " }\n" - + " } .\n" - + " FILTER (?range != owl:Nothing) .\n" - + " OPTIONAL { ?somesub rdfs:subClassOf ?range . FILTER(?somesub != owl:Nothing && ?somesub != ?range)}\n" - + " FILTER (!bound(?somesub)) .\n" - + " OPTIONAL {\n" - + " ?subproperty rdfs:subPropertyOf ?property .\n" - + " FILTER(?subproperty != owl:bottomObjectProperty && ?subproperty != ?property)\n" - + " OPTIONAL { ?subproperty dc:description ?subproperty_description . }\n" - + " }\n" - + " OPTIONAL { ?property dc:description ?property_description . }\n" - + "} "; - - Query query1 = QueryParser.getInstance().parse(queryString); - Thread.sleep(5000l); - Query query2 = QueryParser.getInstance().parse(queryString); - Assert.assertEquals(query1.toString(), query2.toString()); - } -} http://git-wip-us.apache.org/repos/asf/clerezza/blob/f5d9dd84/rdf/core/src/test/java/org/apache/clerezza/rdf/core/sparql/QueryParserTest.java ---------------------------------------------------------------------- diff --git a/rdf/core/src/test/java/org/apache/clerezza/rdf/core/sparql/QueryParserTest.java b/rdf/core/src/test/java/org/apache/clerezza/rdf/core/sparql/QueryParserTest.java deleted file mode 100644 index f39e338..0000000 --- a/rdf/core/src/test/java/org/apache/clerezza/rdf/core/sparql/QueryParserTest.java +++ /dev/null @@ -1,383 +0,0 @@ -/* - * 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; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import org.junit.Assert; -import org.junit.Test; -import org.apache.clerezza.commons.rdf.Language; -import org.apache.clerezza.commons.rdf.IRI; -import org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl; -import org.apache.clerezza.rdf.core.sparql.query.AskQuery; -import org.apache.clerezza.rdf.core.sparql.query.BasicGraphPattern; -import org.apache.clerezza.rdf.core.sparql.query.BuiltInCall; -import org.apache.clerezza.rdf.core.sparql.query.ConstructQuery; -import org.apache.clerezza.rdf.core.sparql.query.DescribeQuery; -import org.apache.clerezza.rdf.core.sparql.query.Expression; -import org.apache.clerezza.rdf.core.sparql.query.GraphPattern; -import org.apache.clerezza.rdf.core.sparql.query.GroupGraphPattern; -import org.apache.clerezza.rdf.core.sparql.query.OptionalGraphPattern; -import org.apache.clerezza.rdf.core.sparql.query.OrderCondition; -import org.apache.clerezza.rdf.core.sparql.query.Query; -import org.apache.clerezza.rdf.core.sparql.query.QueryWithSolutionModifier; -import org.apache.clerezza.rdf.core.sparql.query.ResourceOrVariable; -import org.apache.clerezza.rdf.core.sparql.query.SelectQuery; -import org.apache.clerezza.rdf.core.sparql.query.TriplePattern; -import org.apache.clerezza.rdf.core.sparql.query.UnaryOperation; -import org.apache.clerezza.rdf.core.sparql.query.UriRefOrVariable; -import org.apache.clerezza.rdf.core.sparql.query.Variable; -import org.apache.clerezza.rdf.core.sparql.query.impl.SimpleTriplePattern; - -/** - * - * @author hasan - */ -public class QueryParserTest { - - @Test - public void testSelectQuery() throws ParseException { - -// SELECT ?title FROM <http://example.org/library> -// WHERE { <http://example.org/book/book1> <http://purl.org/dc/elements/1.1/title> ?title . } - - final String variable = "title"; - final String defaultGraph = "http://example.org/library"; - final String subject = "http://example.org/book/book1"; - final String predicate = "http://purl.org/dc/elements/1.1/title"; - - StringBuffer queryStrBuf = new StringBuffer(); - queryStrBuf.append("SELECT ?").append(variable) - .append(" FROM <").append(defaultGraph) - .append("> WHERE { <").append(subject).append("> <") - .append(predicate).append("> ?").append(variable).append(" . }"); - - Query q = QueryParser.getInstance().parse(queryStrBuf.toString()); - Assert.assertTrue(SelectQuery.class.isAssignableFrom(q.getClass())); - SelectQuery selectQuery = (SelectQuery) q; - Assert.assertTrue(selectQuery.getSelection().get(0) - .equals(new Variable(variable))); - Assert.assertTrue(selectQuery.getDataSet().getDefaultGraphs().toArray()[0] - .equals(new IRI(defaultGraph))); - - GraphPattern gp = (GraphPattern) selectQuery.getQueryPattern() - .getGraphPatterns().toArray()[0]; - Assert.assertTrue(BasicGraphPattern.class.isAssignableFrom(gp.getClass())); - BasicGraphPattern bgp = (BasicGraphPattern) gp; - - Set<TriplePattern> triplePatterns = bgp.getTriplePatterns(); - Assert.assertTrue(triplePatterns.size()==1); - - ResourceOrVariable s = new ResourceOrVariable(new IRI(subject)); - UriRefOrVariable p = new UriRefOrVariable(new IRI(predicate)); - ResourceOrVariable o = new ResourceOrVariable(new Variable(variable)); - - Assert.assertTrue(triplePatterns.contains( - new SimpleTriplePattern(s, p, o))); - } - - @Test(expected=ParseException.class) - public void testInvalidQuery() throws ParseException { - Query q = QueryParser.getInstance().parse("Hello"); - } - - @Test - public void testSelectQuerySelection() throws ParseException { - SelectQuery q = (SelectQuery) QueryParser.getInstance().parse( - "SELECT ?a ?b WHERE {?a ?x ?b}"); - Set<Variable> selectionSet = new HashSet<Variable>( - q.getSelection()); - Set<Variable> expected = new HashSet<Variable>(); - expected.add(new Variable("a")); - expected.add(new Variable("b")); - Assert.assertEquals(expected, selectionSet); - Assert.assertFalse(q.isSelectAll()); - - } - - @Test - public void testSelectAll() throws ParseException { - SelectQuery q = (SelectQuery) QueryParser.getInstance().parse( - "SELECT * WHERE {?a ?x ?b}"); - Set<Variable> selectionSet = new HashSet<Variable>( - q.getSelection()); - Set<Variable> expected = new HashSet<Variable>(); - expected.add(new Variable("a")); - expected.add(new Variable("b")); - expected.add(new Variable("x")); - Assert.assertEquals(expected, selectionSet); - Assert.assertTrue(q.isSelectAll()); - - } - - @Test - public void testPlainLiteral() throws ParseException { - SelectQuery q = (SelectQuery) QueryParser.getInstance().parse( - "SELECT * WHERE {?a ?x 'tiger' . ?a ?x 'lion'@en . }"); - - GraphPattern gp = (GraphPattern) q.getQueryPattern() - .getGraphPatterns().toArray()[0]; - Assert.assertTrue(BasicGraphPattern.class.isAssignableFrom(gp.getClass())); - BasicGraphPattern bgp = (BasicGraphPattern) gp; - - Set<TriplePattern> triplePatterns = bgp.getTriplePatterns(); - Assert.assertTrue(triplePatterns.size()==2); - - Assert.assertTrue(triplePatterns.contains(new SimpleTriplePattern( - new Variable("a"), new Variable("x"), - new PlainLiteralImpl("tiger")))); - - Assert.assertTrue(triplePatterns.contains(new SimpleTriplePattern( - new Variable("a"), new Variable("x"), - new PlainLiteralImpl("lion", new Language("en"))))); - } - - @Test - public void testOrderBy() throws ParseException { - SelectQuery q = (SelectQuery) QueryParser.getInstance().parse( - "SELECT * WHERE {?a ?x ?b} ORDER BY DESC(?b)"); - - List<OrderCondition> oc = ((QueryWithSolutionModifier) q).getOrderConditions(); - Assert.assertTrue(oc.size()==1); - Assert.assertFalse(oc.get(0).isAscending()); - Variable b = new Variable("b"); - Assert.assertEquals(b, oc.get(0).getExpression()); - } - - @Test - public void testConstructQuery() throws ParseException { - -// CONSTRUCT { <http://example.org/person#Alice> <http://www.w3.org/2001/vcard-rdf/3.0#FN> ?name} -// WHERE { ?x <http://xmlns.com/foaf/0.1/name> ?name} - - - final String variable1 = "name"; - final String variable2 = "x"; - final String subject1 = "http://example.org/person#Alice"; - final String predicate1 = "http://www.w3.org/2001/vcard-rdf/3.0#FN"; - final String predicate2 = "http://xmlns.com/foaf/0.1/name"; - - StringBuffer queryStrBuf = new StringBuffer(); - queryStrBuf.append("CONSTRUCT { <").append(subject1).append("> <") - .append(predicate1).append("> ?").append(variable1) - .append("} WHERE { ?").append(variable2).append(" <") - .append(predicate2).append("> ?").append(variable1).append("}"); - - Query q = QueryParser.getInstance().parse(queryStrBuf.toString()); - Assert.assertTrue(ConstructQuery.class.isAssignableFrom(q.getClass())); - ConstructQuery constructQuery = (ConstructQuery) q; - Set<TriplePattern> triplePatterns = constructQuery - .getConstructTemplate(); - Assert.assertTrue(triplePatterns.size()==1); - - ResourceOrVariable s = new ResourceOrVariable(new IRI(subject1)); - UriRefOrVariable p = new UriRefOrVariable(new IRI(predicate1)); - ResourceOrVariable o = new ResourceOrVariable(new Variable(variable1)); - - Assert.assertTrue(triplePatterns.contains( - new SimpleTriplePattern(s, p, o))); - - GraphPattern gp = (GraphPattern) constructQuery.getQueryPattern() - .getGraphPatterns().toArray()[0]; - Assert.assertTrue(BasicGraphPattern.class.isAssignableFrom(gp.getClass())); - BasicGraphPattern bgp = (BasicGraphPattern) gp; - triplePatterns = bgp.getTriplePatterns(); - Assert.assertTrue(triplePatterns.size()==1); - - s = new ResourceOrVariable(new Variable(variable2)); - p = new UriRefOrVariable(new IRI(predicate2)); - - Assert.assertTrue(triplePatterns.contains( - new SimpleTriplePattern(s, p, o))); - } - - @Test - public void testDescribeQuery() throws ParseException { - -// DESCRIBE <http://example.org/book/book1> - - final String resource = "http://example.org/book/book1"; - - StringBuffer queryStrBuf = new StringBuffer(); - queryStrBuf.append("DESCRIBE <").append(resource).append(">"); - - Query q = QueryParser.getInstance().parse(queryStrBuf.toString()); - Assert.assertTrue(DescribeQuery.class.isAssignableFrom(q.getClass())); - DescribeQuery describeQuery = (DescribeQuery) q; - Assert.assertTrue(describeQuery.getResourcesToDescribe().get(0) - .getResource().equals(new IRI(resource))); - } - - @Test - public void testAskQuery() throws ParseException { - -// ASK { ?x <http://xmlns.com/foaf/0.1/name> "Alice" } - - final String variable = "x"; - final String predicate = "http://xmlns.com/foaf/0.1/name"; - final String object = "Alice"; - - StringBuffer queryStrBuf = new StringBuffer(); - queryStrBuf.append("ASK { ?").append(variable).append(" <") - .append(predicate).append("> \"").append(object).append("\" }"); - - Query q = QueryParser.getInstance().parse(queryStrBuf.toString()); - Assert.assertTrue(AskQuery.class.isAssignableFrom(q.getClass())); - AskQuery askQuery = (AskQuery) q; - - GraphPattern gp = (GraphPattern) askQuery.getQueryPattern() - .getGraphPatterns().toArray()[0]; - Assert.assertTrue(BasicGraphPattern.class.isAssignableFrom(gp.getClass())); - BasicGraphPattern bgp = (BasicGraphPattern) gp; - - Set<TriplePattern> triplePatterns = bgp.getTriplePatterns(); - Assert.assertTrue(triplePatterns.size()==1); - - Assert.assertTrue(triplePatterns.contains(new SimpleTriplePattern(new Variable(variable), - new IRI(predicate), new PlainLiteralImpl(object)))); - } - - @Test - public void testBaseAndPrefix() throws ParseException { - -// BASE <http://example.org/book/> -// PREFIX dc: <http://purl.org/dc/elements/1.1/> -// -// SELECT $title -// WHERE { <book1> dc:title ?title } - - final String base = "http://example.org/book/"; - final String prefix = "dc"; - final String prefixUri = "http://purl.org/dc/elements/1.1/"; - final String variable = "title"; - final String subject = "book1"; - final String predicate = "title"; - - StringBuffer queryStrBuf = new StringBuffer(); - queryStrBuf.append("BASE <").append(base).append(">") - .append(" PREFIX ").append(prefix).append(": <") - .append(prefixUri).append("> SELECT $").append(variable) - .append(" WHERE { <").append(subject).append("> ") - .append(prefix).append(":").append(predicate).append(" ?") - .append(variable).append(" }"); - - Query q = QueryParser.getInstance().parse(queryStrBuf.toString()); - Assert.assertTrue(SelectQuery.class.isAssignableFrom(q.getClass())); - SelectQuery selectQuery = (SelectQuery) q; - Assert.assertTrue(selectQuery.getSelection().get(0) - .equals(new Variable(variable))); - - GraphPattern gp = (GraphPattern) selectQuery.getQueryPattern() - .getGraphPatterns().toArray()[0]; - Assert.assertTrue(BasicGraphPattern.class.isAssignableFrom(gp.getClass())); - BasicGraphPattern bgp = (BasicGraphPattern) gp; - - Set<TriplePattern> triplePatterns = bgp.getTriplePatterns(); - Assert.assertTrue(triplePatterns.size()==1); - - ResourceOrVariable s = new ResourceOrVariable(new IRI(base+subject)); - UriRefOrVariable p = new UriRefOrVariable(new IRI(prefixUri+predicate)); - ResourceOrVariable o = new ResourceOrVariable(new Variable(variable)); - - Assert.assertTrue(triplePatterns.contains( - new SimpleTriplePattern(s, p, o))); - } - - @Test - public void testOptionalAndFilter() throws ParseException { - -// PREFIX dc: <http://purl.org/dc/elements/1.1/> -// PREFIX books: <http://example.org/book/> -// -// SELECT ?book ?title -// WHERE -// { ?book dc:title ?title . -// OPTIONAL -// { ?book books:author ?author .} -// FILTER ( ! bound(?author) ) -// } - final String prefix1 = "dc"; - final String prefix1Uri = "http://purl.org/dc/elements/1.1/"; - final String prefix2 = "books"; - final String prefix2Uri = "http://example.org/book/"; - final String variable1 = "book"; - final String variable2 = "title"; - final String variable3 = "author"; - final String predicate1 = "title"; - final String predicate2 = "author"; - - StringBuffer queryStrBuf = new StringBuffer(); - queryStrBuf.append("PREFIX ").append(prefix1).append(": <").append(prefix1Uri) - .append("> PREFIX ").append(prefix2).append(": <").append(prefix2Uri) - .append("> SELECT ?").append(variable1).append(" ?").append(variable2) - .append(" WHERE { ?").append(variable1).append(" ") - .append(prefix1).append(":").append(predicate1) - .append(" ?").append(variable2).append(" . OPTIONAL { ?") - .append(variable1).append(" ").append(prefix2).append(":") - .append(predicate2).append(" ?").append(variable3) - .append(" .} FILTER ( ! bound(?").append(variable3).append(") ) }"); - - Query q = QueryParser.getInstance().parse(queryStrBuf.toString()); - Assert.assertTrue(SelectQuery.class.isAssignableFrom(q.getClass())); - SelectQuery selectQuery = (SelectQuery) q; - Assert.assertTrue(selectQuery.getSelection().size() == 2); - Set<Variable> vars = new HashSet<Variable>(2); - Variable var1 = new Variable(variable1); - Variable var2 = new Variable(variable2); - vars.add(var1); - vars.add(var2); - Assert.assertTrue(selectQuery.getSelection().containsAll(vars)); - - GroupGraphPattern ggp = selectQuery.getQueryPattern(); - List<Expression> constraints = ggp.getFilter(); - Assert.assertTrue(UnaryOperation.class.isAssignableFrom(constraints - .get(0).getClass())); - UnaryOperation uop = (UnaryOperation) constraints.get(0); - Assert.assertTrue(uop.getOperatorString().equals("!")); - Assert.assertTrue(BuiltInCall.class.isAssignableFrom(uop.getOperand() - .getClass())); - BuiltInCall bic = (BuiltInCall) uop.getOperand(); - Assert.assertTrue(bic.getName().equals("BOUND")); - Variable var3 = new Variable(variable3); - Assert.assertTrue(bic.getArguements().get(0).equals(var3)); - - GraphPattern gp = (GraphPattern) ggp.getGraphPatterns().toArray()[0]; - Assert.assertTrue(OptionalGraphPattern.class.isAssignableFrom(gp.getClass())); - OptionalGraphPattern ogp = (OptionalGraphPattern) gp; - Assert.assertTrue(BasicGraphPattern.class.isAssignableFrom( - ogp.getMainGraphPattern().getClass())); - BasicGraphPattern bgp = (BasicGraphPattern) ogp.getMainGraphPattern(); - - Set<TriplePattern> triplePatterns = bgp.getTriplePatterns(); - Assert.assertTrue(triplePatterns.size() == 1); - Assert.assertTrue(triplePatterns.contains(new SimpleTriplePattern(var1, new IRI(prefix1Uri + predicate1), - var2))); - - GraphPattern gp2 = (GraphPattern) ogp.getOptionalGraphPattern() - .getGraphPatterns().toArray()[0]; - Assert.assertTrue(BasicGraphPattern.class.isAssignableFrom(gp2.getClass())); - bgp = (BasicGraphPattern) gp2; - - triplePatterns = bgp.getTriplePatterns(); - Assert.assertTrue(triplePatterns.size() == 1); - Assert.assertTrue(triplePatterns.contains(new SimpleTriplePattern(var1, new IRI(prefix2Uri + predicate2), - var3))); - } -} http://git-wip-us.apache.org/repos/asf/clerezza/blob/f5d9dd84/rdf/core/src/test/java/org/apache/clerezza/rdf/core/sparql/QuerySerializerTest.java ---------------------------------------------------------------------- diff --git a/rdf/core/src/test/java/org/apache/clerezza/rdf/core/sparql/QuerySerializerTest.java b/rdf/core/src/test/java/org/apache/clerezza/rdf/core/sparql/QuerySerializerTest.java deleted file mode 100644 index eccf13f..0000000 --- a/rdf/core/src/test/java/org/apache/clerezza/rdf/core/sparql/QuerySerializerTest.java +++ /dev/null @@ -1,318 +0,0 @@ -/* - * 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; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import org.apache.clerezza.rdf.core.LiteralFactory; -import org.apache.clerezza.commons.rdf.IRI; -import org.apache.clerezza.rdf.core.sparql.query.BinaryOperation; -import org.apache.clerezza.rdf.core.sparql.query.BuiltInCall; -import org.apache.clerezza.rdf.core.sparql.query.Expression; -import org.apache.clerezza.rdf.core.sparql.query.LiteralExpression; -import org.apache.clerezza.rdf.core.sparql.query.ResourceOrVariable; -import org.apache.clerezza.rdf.core.sparql.query.TriplePattern; -import org.apache.clerezza.rdf.core.sparql.query.UriRefExpression; -import org.apache.clerezza.rdf.core.sparql.query.UriRefOrVariable; -import org.apache.clerezza.rdf.core.sparql.query.Variable; -import org.apache.clerezza.rdf.core.sparql.query.impl.SimpleAskQuery; -import org.apache.clerezza.rdf.core.sparql.query.impl.SimpleBasicGraphPattern; -import org.apache.clerezza.rdf.core.sparql.query.impl.SimpleConstructQuery; -import org.apache.clerezza.rdf.core.sparql.query.impl.SimpleDescribeQuery; -import org.apache.clerezza.rdf.core.sparql.query.impl.SimpleGroupGraphPattern; -import org.apache.clerezza.rdf.core.sparql.query.impl.SimpleOptionalGraphPattern; -import org.apache.clerezza.rdf.core.sparql.query.impl.SimpleOrderCondition; -import org.apache.clerezza.rdf.core.sparql.query.impl.SimpleSelectQuery; -import org.apache.clerezza.rdf.core.sparql.query.impl.SimpleTriplePattern; -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; - -/** - * - * @author hasan - */ -public class QuerySerializerTest { - - @Test - public void testSelectQuery() { - - final String queryString = "SELECT ?title FROM <http://example.org/library>" + - " WHERE { <http://example.org/book/book1>" + - " <http://purl.org/dc/elements/1.1/title> ?title . }"; - - SimpleSelectQuery selectQuery = new SimpleSelectQuery(); - Variable variable = new Variable("title"); - selectQuery.addSelection(variable); - IRI defaultGraph = new IRI("http://example.org/library"); - selectQuery.addDefaultGraph(defaultGraph); - ResourceOrVariable subject = new ResourceOrVariable( - new IRI("http://example.org/book/book1")); - UriRefOrVariable predicate = new UriRefOrVariable( - new IRI("http://purl.org/dc/elements/1.1/title")); - ResourceOrVariable object = new ResourceOrVariable(variable); - TriplePattern triplePattern = new SimpleTriplePattern(subject, predicate, object); - Set<TriplePattern> triplePatterns = new HashSet<TriplePattern>(); - triplePatterns.add(triplePattern); - - SimpleBasicGraphPattern bgp = new SimpleBasicGraphPattern(triplePatterns); - SimpleGroupGraphPattern queryPattern = new SimpleGroupGraphPattern(); - queryPattern.addGraphPattern(bgp); - selectQuery.setQueryPattern(queryPattern); - - Assert.assertTrue(selectQuery.toString() - .replaceAll("( |\n)+", " ").trim().equals(queryString)); - } - - @Test - public void testConstructQuery() { - - final String queryString = "CONSTRUCT { <http://example.org/person#Alice> " + - "<http://www.w3.org/2001/vcard-rdf/3.0#FN> ?name . } " + - "WHERE { ?x <http://xmlns.com/foaf/0.1/name> ?name . }"; - - ResourceOrVariable s = new ResourceOrVariable( - new IRI("http://example.org/person#Alice")); - UriRefOrVariable p = new UriRefOrVariable( - new IRI("http://www.w3.org/2001/vcard-rdf/3.0#FN")); - ResourceOrVariable o = new ResourceOrVariable(new Variable("name")); - Set<TriplePattern> constructTriplePatterns = new HashSet<TriplePattern>(); - constructTriplePatterns.add(new SimpleTriplePattern(s, p, o)); - SimpleConstructQuery constructQuery = new SimpleConstructQuery(constructTriplePatterns); - - s = new ResourceOrVariable(new Variable("x")); - p = new UriRefOrVariable(new IRI("http://xmlns.com/foaf/0.1/name")); - Set<TriplePattern> triplePatterns = new HashSet<TriplePattern>(); - triplePatterns.add(new SimpleTriplePattern(s, p, o)); - - SimpleBasicGraphPattern bgp = new SimpleBasicGraphPattern(triplePatterns); - SimpleGroupGraphPattern queryPattern = new SimpleGroupGraphPattern(); - queryPattern.addGraphPattern(bgp); - constructQuery.setQueryPattern(queryPattern); - - Assert.assertTrue(constructQuery.toString() - .replaceAll("( |\n)+", " ").trim().equals(queryString)); - } - - @Test - public void testDescribeQuery() { - - final String queryString = "DESCRIBE <http://example.org/book/book1>"; - - SimpleDescribeQuery describeQuery = new SimpleDescribeQuery(); - describeQuery.addResourceToDescribe(new ResourceOrVariable( - new IRI("http://example.org/book/book1"))); - - Assert.assertTrue(describeQuery.toString() - .replaceAll("( |\n)+", " ").trim().equals(queryString)); - } - - @Test - public void testAskQuery() { - - final String queryString = "ASK WHERE { ?x <http://xmlns.com/foaf/0.1/name> " + - "\"Alice\"^^<http://www.w3.org/2001/XMLSchema#string> . }"; - - ResourceOrVariable s = new ResourceOrVariable(new Variable("x")); - UriRefOrVariable p = new UriRefOrVariable( - new IRI("http://xmlns.com/foaf/0.1/name")); - ResourceOrVariable o = new ResourceOrVariable( - LiteralFactory.getInstance().createTypedLiteral("Alice")); - - Set<TriplePattern> triplePatterns = new HashSet<TriplePattern>(); - triplePatterns.add(new SimpleTriplePattern(s, p, o)); - SimpleAskQuery askQuery = new SimpleAskQuery(); - - SimpleBasicGraphPattern bgp = new SimpleBasicGraphPattern(triplePatterns); - SimpleGroupGraphPattern queryPattern = new SimpleGroupGraphPattern(); - queryPattern.addGraphPattern(bgp); - askQuery.setQueryPattern(queryPattern); - - Assert.assertTrue(askQuery.toString() - .replaceAll("( |\n)+", " ").trim().equals(queryString)); - } - - /** - * Ignoring: given that triplePatterns is a Set I don't see what is supposed - * to guarantee the expected ordering. - */ - @Ignore - @Test - public void testFilter() { - - final String queryString = "SELECT ?title ?price WHERE { " + - "?x <http://purl.org/dc/elements/1.1/title> ?title . " + - "?x <http://example.org/ns#price> ?price . " + - "FILTER ((?price) < (\"30.5\"^^<http://www.w3.org/2001/XMLSchema#double>)) " + - "}"; - - Variable price = new Variable("price"); - Variable title = new Variable("title"); - SimpleSelectQuery selectQuery = new SimpleSelectQuery(); - selectQuery.addSelection(title); - selectQuery.addSelection(price); - - Variable x = new Variable("x"); - Set<TriplePattern> triplePatterns = new HashSet<TriplePattern>(); - triplePatterns.add(new SimpleTriplePattern(x, - new IRI("http://example.org/ns#price"), price)); - triplePatterns.add(new SimpleTriplePattern(x, - new IRI("http://purl.org/dc/elements/1.1/title"), title)); - - SimpleBasicGraphPattern bgp = new SimpleBasicGraphPattern(triplePatterns); - SimpleGroupGraphPattern queryPattern = new SimpleGroupGraphPattern(); - queryPattern.addGraphPattern(bgp); - BinaryOperation constraint = new BinaryOperation("<", - price, new LiteralExpression(LiteralFactory.getInstance().createTypedLiteral(30.5))); - queryPattern.addConstraint(constraint); - selectQuery.setQueryPattern(queryPattern); - - Assert.assertTrue(selectQuery.toString() - .replaceAll("( |\n)+", " ").trim().equals(queryString)); - } - - @Test - public void testUriRefExpression() { - - final String queryString = "SELECT ?resource WHERE { " + - "?resource <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?myType . " + - "FILTER ((?resource) = (<http://example.org/ontology#special>)) " + - "}"; - - Variable resource = new Variable("resource"); - SimpleSelectQuery selectQuery = new SimpleSelectQuery(); - selectQuery.addSelection(resource); - - Variable myType = new Variable("myType"); - Set<TriplePattern> triplePatterns = new HashSet<TriplePattern>(); - triplePatterns.add(new SimpleTriplePattern(resource, - new IRI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), myType)); - - SimpleBasicGraphPattern bgp = new SimpleBasicGraphPattern(triplePatterns); - SimpleGroupGraphPattern queryPattern = new SimpleGroupGraphPattern(); - queryPattern.addGraphPattern(bgp); - BinaryOperation constraint = new BinaryOperation("=", - resource, new UriRefExpression(new IRI("http://example.org/ontology#special"))); - queryPattern.addConstraint(constraint); - selectQuery.setQueryPattern(queryPattern); - - Assert.assertTrue(selectQuery.toString() - .replaceAll("( |\n)+", " ").trim().equals(queryString)); - } - - @Test - public void testOrderBy() { - - final String queryString = "SELECT * WHERE { ?a ?b ?c . } ORDER BY DESC(?c)"; - - Variable a = new Variable("a"); - Variable b = new Variable("b"); - Variable c = new Variable("c"); - SimpleSelectQuery selectQuery = new SimpleSelectQuery(); - selectQuery.setSelectAll(); - selectQuery.addSelection(a); - selectQuery.addSelection(b); - selectQuery.addSelection(c); - - Set<TriplePattern> triplePatterns = new HashSet<TriplePattern>(); - triplePatterns.add(new SimpleTriplePattern(a, b, c)); - SimpleBasicGraphPattern bgp = new SimpleBasicGraphPattern(triplePatterns); - SimpleGroupGraphPattern queryPattern = new SimpleGroupGraphPattern(); - queryPattern.addGraphPattern(bgp); - selectQuery.setQueryPattern(queryPattern); - selectQuery.addOrderCondition(new SimpleOrderCondition(c, false)); - - Assert.assertTrue(selectQuery.toString() - .replaceAll("( |\n)+", " ").trim().equals(queryString)); - } - - @Test - public void testOptional() { - - final String queryString = "SELECT ?title ?price WHERE { " + - "?x <http://purl.org/dc/elements/1.1/title> ?title . " + - "OPTIONAL { ?x <http://example.org/ns#price> ?price . } " + - "}"; - - Variable title = new Variable("title"); - Variable price = new Variable("price"); - SimpleSelectQuery selectQuery = new SimpleSelectQuery(); - selectQuery.addSelection(title); - selectQuery.addSelection(price); - - Variable x = new Variable("x"); - Set<TriplePattern> triplePatterns = new HashSet<TriplePattern>(); - triplePatterns.add(new SimpleTriplePattern(x, - new IRI("http://purl.org/dc/elements/1.1/title"), title)); - - SimpleBasicGraphPattern bgp = new SimpleBasicGraphPattern(triplePatterns); - - Set<TriplePattern> triplePatternsOpt = new HashSet<TriplePattern>(); - triplePatternsOpt.add(new SimpleTriplePattern(x, - new IRI("http://example.org/ns#price"), price)); - - SimpleBasicGraphPattern bgpOpt = - new SimpleBasicGraphPattern(triplePatternsOpt); - - SimpleGroupGraphPattern ggpOpt = new SimpleGroupGraphPattern(); - ggpOpt.addGraphPattern(bgpOpt); - - SimpleOptionalGraphPattern ogp = new SimpleOptionalGraphPattern(bgp, ggpOpt); - - SimpleGroupGraphPattern queryPattern = new SimpleGroupGraphPattern(); - queryPattern.addGraphPattern(ogp); - selectQuery.setQueryPattern(queryPattern); - - Assert.assertTrue(selectQuery.toString() - .replaceAll("( |\n)+", " ").trim().equals(queryString)); - } - - @Test - public void testRegex() { - - final String queryString = "SELECT ?p WHERE { " + - "<http://localhost/testitem> ?p ?x . " + - "FILTER REGEX(?x,\".*uni.*\"^^<http://www.w3.org/2001/XMLSchema#string>) }"; - - Variable p = new Variable("p"); - SimpleSelectQuery selectQuery = new SimpleSelectQuery(); - selectQuery.addSelection(p); - - Variable x = new Variable("x"); - Set<TriplePattern> triplePatterns = new HashSet<TriplePattern>(); - triplePatterns.add(new SimpleTriplePattern( - new IRI("http://localhost/testitem"), p, x)); - - SimpleBasicGraphPattern bgp = new SimpleBasicGraphPattern(triplePatterns); - SimpleGroupGraphPattern queryPattern = new SimpleGroupGraphPattern(); - queryPattern.addGraphPattern(bgp); - - List<Expression> arguments = new ArrayList<Expression>(); - arguments.add(x); - arguments.add(new LiteralExpression(LiteralFactory.getInstance(). - createTypedLiteral(".*uni.*"))); - BuiltInCall constraint = new BuiltInCall("REGEX", arguments); - queryPattern.addConstraint(constraint); - selectQuery.setQueryPattern(queryPattern); - Assert.assertTrue(selectQuery.toString() - .replaceAll("( |\n)+", " ").trim().equals(queryString)); - } -} http://git-wip-us.apache.org/repos/asf/clerezza/blob/f5d9dd84/rdf/core/src/test/java/org/apache/clerezza/rdf/core/sparql/SparqlPreParserTest.java ---------------------------------------------------------------------- diff --git a/rdf/core/src/test/java/org/apache/clerezza/rdf/core/sparql/SparqlPreParserTest.java b/rdf/core/src/test/java/org/apache/clerezza/rdf/core/sparql/SparqlPreParserTest.java deleted file mode 100644 index c56170c..0000000 --- a/rdf/core/src/test/java/org/apache/clerezza/rdf/core/sparql/SparqlPreParserTest.java +++ /dev/null @@ -1,505 +0,0 @@ -/* - * 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; - -import java.util.HashSet; -import java.util.Set; -import org.apache.clerezza.commons.rdf.IRI; -import org.apache.clerezza.rdf.core.access.TcManager; -import org.apache.clerezza.rdf.core.access.TcManagerTest; -import org.apache.clerezza.rdf.core.access.providers.WeightedA; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -/** - * - * @author hasan - */ -public class SparqlPreParserTest { - - private TcManager graphAccess; - private final WeightedA weightedA = new WeightedA(); - private final static IRI DEFAULT_GRAPH = new IRI("http://example.org/default.graph"); - private final static IRI TEST_GRAPH = new IRI("http://example.org/test.graph"); - - @Before - public void setUp() { - graphAccess = TcManager.getInstance(); - graphAccess.addWeightedTcProvider(weightedA); - } - - @After - public void tearDown() { - graphAccess = TcManager.getInstance(); - graphAccess.removeWeightedTcProvider(weightedA); - } - - @Test - public void testDefaultGraphInSelectQuery() throws ParseException { - - StringBuilder queryStrBuilder = new StringBuilder(); - queryStrBuilder.append( - "PREFIX : <http://example.org/>\n" + - "SELECT ?x \n" + - "{\n" + - ":order :item/:price ?x\n" + - "}\n"); - - SparqlPreParser parser; - parser = new SparqlPreParser(TcManager.getInstance()); - Set<IRI> referredGraphs = parser.getReferredGraphs(queryStrBuilder.toString(), DEFAULT_GRAPH); - Assert.assertTrue(referredGraphs.toArray()[0].equals(DEFAULT_GRAPH)); - } - - @Test - public void testAllGraphReferenceInSelectQuery() throws ParseException { - - StringBuilder queryStrBuilder = new StringBuilder(); - queryStrBuilder.append("SELECT DISTINCT ?g { GRAPH ?g { ?s ?p ?o } }\n"); - - SparqlPreParser parser; - parser = new SparqlPreParser(TcManager.getInstance()); - Set<IRI> referredGraphs = parser.getReferredGraphs(queryStrBuilder.toString(), DEFAULT_GRAPH); - Assert.assertTrue(referredGraphs == null); - } - - @Test - public void testSelectQuery() throws ParseException { - - StringBuilder queryStrBuilder = new StringBuilder(); - queryStrBuilder.append( - "PREFIX : <http://example.org/>\n" + - "SELECT ?x (foo(2*3, ?x < ?y) AS ?f) (GROUP_CONCAT(?x ; separator=\"|\") AS ?gc) (sum(distinct *) AS ?total)\n" + - "FROM " + TEST_GRAPH.toString() + "\n" + - "{\n" + - ":order :item/:price ?x\n" + - "}\n"); - - SparqlPreParser parser; - parser = new SparqlPreParser(TcManager.getInstance()); - Set<IRI> referredGraphs = parser.getReferredGraphs(queryStrBuilder.toString(), DEFAULT_GRAPH); - Assert.assertTrue(referredGraphs.toArray()[0].equals(TEST_GRAPH)); - } - - @Test - public void testSimpleDescribe() throws ParseException { - - String queryStr = "DESCRIBE <http://example.org/>"; - - SparqlPreParser parser; - parser = new SparqlPreParser(TcManager.getInstance()); - Set<IRI> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH); - Assert.assertTrue(referredGraphs.toArray()[0].equals(DEFAULT_GRAPH)); - } - - @Test - public void testLoadingToDefaultGraph() throws ParseException { - - String queryStr = "LOAD SILENT <http://example.org/mydata>"; - - SparqlPreParser parser; - parser = new SparqlPreParser(TcManager.getInstance()); - Set<IRI> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH); - Set<IRI> expected = new HashSet<>(); - expected.add(DEFAULT_GRAPH); - expected.add(new IRI("http://example.org/mydata")); - Assert.assertTrue(referredGraphs.containsAll(expected)); - } - - @Test - public void testLoadingToGraph() throws ParseException { - - String queryStr = "LOAD SILENT <http://example.org/mydata> INTO GRAPH " + TEST_GRAPH.toString(); - - SparqlPreParser parser; - parser = new SparqlPreParser(TcManager.getInstance()); - Set<IRI> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH); - Set<IRI> expected = new HashSet<>(); - expected.add(TEST_GRAPH); - expected.add(new IRI("http://example.org/mydata")); - Assert.assertTrue(referredGraphs.containsAll(expected)); - } - - @Test - public void testClearingDefaultGraph() throws ParseException { - - String queryStr = "CLEAR SILENT DEFAULT"; - - SparqlPreParser parser; - parser = new SparqlPreParser(TcManager.getInstance()); - Set<IRI> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH); - Assert.assertTrue(referredGraphs.toArray()[0].equals(DEFAULT_GRAPH)); - } - - @Test - public void testClearingNamedGraph() throws ParseException { - - String queryStr = "CLEAR SILENT NAMED"; - - SparqlPreParser parser; - parser = new SparqlPreParser(TcManager.getInstance()); - Set<IRI> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH); - Assert.assertTrue(referredGraphs.contains(TcManagerTest.uriRefA)); - } - - @Test - public void testClearingGraph() throws ParseException { - - String queryStr = "CLEAR SILENT GRAPH " + TEST_GRAPH.toString(); - - SparqlPreParser parser; - parser = new SparqlPreParser(TcManager.getInstance()); - Set<IRI> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH); - Assert.assertTrue(referredGraphs.toArray()[0].equals(TEST_GRAPH)); - } - - @Test - public void testDroppingDefaultGraph() throws ParseException { - - String queryStr = "DROP SILENT DEFAULT"; - - SparqlPreParser parser; - parser = new SparqlPreParser(TcManager.getInstance()); - Set<IRI> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH); - Assert.assertTrue(referredGraphs.toArray()[0].equals(DEFAULT_GRAPH)); - } - - @Test - public void testDroppingNamedGraph() throws ParseException { - - String queryStr = "DROP SILENT NAMED"; - - SparqlPreParser parser; - parser = new SparqlPreParser(TcManager.getInstance()); - Set<IRI> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH); - Assert.assertTrue(referredGraphs.contains(TcManagerTest.uriRefA)); - } - - @Test - public void testDroppingGraph() throws ParseException { - - String queryStr = "DROP SILENT GRAPH " + TEST_GRAPH.toString(); - - SparqlPreParser parser; - parser = new SparqlPreParser(TcManager.getInstance()); - Set<IRI> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH); - Assert.assertTrue(referredGraphs.toArray()[0].equals(TEST_GRAPH)); - } - - @Test - public void testCreatingGraph() throws ParseException { - - String queryStr = "CREATE SILENT GRAPH " + TEST_GRAPH.toString(); - - SparqlPreParser parser; - parser = new SparqlPreParser(TcManager.getInstance()); - Set<IRI> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH); - Assert.assertTrue(referredGraphs.toArray()[0].equals(TEST_GRAPH)); - } - - @Test - public void testAddingTriplesFromDefaultGraphToNamedGraph() throws ParseException { - - String queryStr = "ADD SILENT DEFAULT TO GRAPH " + TEST_GRAPH.toString(); - - SparqlPreParser parser; - parser = new SparqlPreParser(TcManager.getInstance()); - Set<IRI> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH); - Set<IRI> expected = new HashSet<>(); - expected.add(DEFAULT_GRAPH); - expected.add(TEST_GRAPH); - Assert.assertTrue(referredGraphs.containsAll(expected)); - } - - @Test - public void testAddingTriplesFromNamedGraphToDefaultGraph() throws ParseException { - - String queryStr = "ADD SILENT GRAPH " + TEST_GRAPH.toString() + " TO DEFAULT"; - - SparqlPreParser parser; - parser = new SparqlPreParser(TcManager.getInstance()); - Set<IRI> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH); - Set<IRI> expected = new HashSet<>(); - expected.add(DEFAULT_GRAPH); - expected.add(TEST_GRAPH); - Assert.assertTrue(referredGraphs.containsAll(expected)); - } - - @Test - public void testMovingTriplesFromDefaultGraphToNamedGraph() throws ParseException { - - String queryStr = "MOVE SILENT DEFAULT TO GRAPH " + TEST_GRAPH.toString(); - - SparqlPreParser parser; - parser = new SparqlPreParser(TcManager.getInstance()); - Set<IRI> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH); - Set<IRI> expected = new HashSet<>(); - expected.add(DEFAULT_GRAPH); - expected.add(TEST_GRAPH); - Assert.assertTrue(referredGraphs.containsAll(expected)); - } - - @Test - public void testMovingTriplesFromNamedGraphToDefaultGraph() throws ParseException { - - String queryStr = "MOVE SILENT GRAPH " + TEST_GRAPH.toString() + " TO DEFAULT"; - - SparqlPreParser parser; - parser = new SparqlPreParser(TcManager.getInstance()); - Set<IRI> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH); - Set<IRI> expected = new HashSet<>(); - expected.add(DEFAULT_GRAPH); - expected.add(TEST_GRAPH); - Assert.assertTrue(referredGraphs.containsAll(expected)); - } - - @Test - public void testCopyingTriplesFromDefaultGraphToNamedGraph() throws ParseException { - - String queryStr = "COPY SILENT DEFAULT TO GRAPH " + TEST_GRAPH.toString(); - - SparqlPreParser parser; - parser = new SparqlPreParser(TcManager.getInstance()); - Set<IRI> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH); - Set<IRI> expected = new HashSet<>(); - expected.add(DEFAULT_GRAPH); - expected.add(TEST_GRAPH); - Assert.assertTrue(referredGraphs.containsAll(expected)); - } - - @Test - public void testCopyingTriplesFromNamedGraphToDefaultGraph() throws ParseException { - - String queryStr = "COPY SILENT GRAPH " + TEST_GRAPH.toString() + " TO DEFAULT"; - - SparqlPreParser parser; - parser = new SparqlPreParser(TcManager.getInstance()); - Set<IRI> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH); - Set<IRI> expected = new HashSet<>(); - expected.add(DEFAULT_GRAPH); - 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<IRI> 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<IRI> 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<IRI> 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<IRI> 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<IRI> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH); - - Set<IRI> expected = new HashSet<>(); - expected.add(DEFAULT_GRAPH); - 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<IRI> 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<IRI> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH); - - Set<IRI> expected = new HashSet<>(); - expected.add(new IRI("http://example.com/names")); - expected.add(new IRI("http://example.com/addresses")); - Assert.assertTrue(referredGraphs.containsAll(expected)); - } - - @Test - public void testModifyOperationWithFallbackGraph() throws ParseException { - String queryStr = "PREFIX foaf: <http://xmlns.com/foaf/0.1/> WITH " + TEST_GRAPH.toString() + - " DELETE { ?person foaf:givenName 'Bill' } INSERT { ?person foaf:givenName 'William' }" + - " WHERE { ?person foaf:givenName 'Bill' }"; - - SparqlPreParser parser; - parser = new SparqlPreParser(TcManager.getInstance()); - Set<IRI> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH); - Set<IRI> expected = new HashSet<>(); - expected.add(TEST_GRAPH); - expected.add(DEFAULT_GRAPH); - Assert.assertTrue(referredGraphs.containsAll(expected)); - } - - @Test - public void testDeleteOperationInDefaultGraph() throws ParseException { - String queryStr = "PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> " + - "DELETE { ?book ?p ?v } WHERE { ?book dc:date ?date . " + - "FILTER ( ?date > \"1970-01-01T00:00:00-02:00\"^^xsd:dateTime ) ?book ?p ?v }"; - - SparqlPreParser parser; - parser = new SparqlPreParser(TcManager.getInstance()); - Set<IRI> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH); - Assert.assertTrue(referredGraphs.toArray()[0].equals(DEFAULT_GRAPH)); - } - - @Test - public void testInsertOperationToNamedGraph() throws ParseException { - String queryStr = "PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> " + - "INSERT { GRAPH <http://example/bookStore2> { ?book ?p ?v } } " + - "WHERE { GRAPH <http://example/bookStore> { ?book dc:date ?date . " + - "FILTER ( ?date > \"1970-01-01T00:00:00-02:00\"^^xsd:dateTime ) ?book ?p ?v } }"; - - SparqlPreParser parser; - parser = new SparqlPreParser(TcManager.getInstance()); - Set<IRI> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH); - - Set<IRI> expected = new HashSet<>(); - expected.add(new IRI("http://example/bookStore2")); - expected.add(new IRI("http://example/bookStore")); - Assert.assertTrue(referredGraphs.containsAll(expected)); - } - - @Test - public void testInsertAndDeleteWithCommonPrefix() throws ParseException { - String queryStr = "PREFIX dc: <http://purl.org/dc/elements/1.1/>\n" + - "PREFIX dcmitype: <http://purl.org/dc/dcmitype/>\n" + - "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>\n\n" + - "INSERT\n" + - " { GRAPH <http://example/bookStore2> { ?book ?p ?v } }\n" + - "WHERE\n" + - " { GRAPH <http://example/bookStore>\n" + - " { ?book dc:date ?date . \n" + - " FILTER ( ?date < \"2000-01-01T00:00:00-02:00\"^^xsd:dateTime )\n" + - " ?book ?p ?v\n" + - " }\n" + - " } ;\n\n" + - "WITH <http://example/bookStore>\n" + - "DELETE\n" + - " { ?book ?p ?v }\n" + - "WHERE\n" + - " { ?book dc:date ?date ;\n" + - " dc:type dcmitype:PhysicalObject .\n" + - " FILTER ( ?date < \"2000-01-01T00:00:00-02:00\"^^xsd:dateTime ) \n" + - " ?book ?p ?v\n" + - " }"; - - SparqlPreParser parser; - parser = new SparqlPreParser(TcManager.getInstance()); - Set<IRI> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH); - - Set<IRI> expected = new HashSet<>(); - expected.add(new IRI("http://example/bookStore2")); - expected.add(new IRI("http://example/bookStore")); - Assert.assertTrue(referredGraphs.containsAll(expected)); - } - - @Test - public void testExistsFunction() throws ParseException { - String queryStr = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n" + - "PREFIX foaf: <http://xmlns.com/foaf/0.1/> \n\n" + - "SELECT ?person\n" + - "WHERE \n" + - "{\n" + - " ?person rdf:type foaf:Person .\n" + - " FILTER EXISTS { ?person foaf:name ?name }\n" + - "}"; - - SparqlPreParser parser; - parser = new SparqlPreParser(TcManager.getInstance()); - Set<IRI> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH); - Assert.assertTrue(referredGraphs.toArray()[0].equals(DEFAULT_GRAPH)); - } - - @Test - public void testNotExistsFunction() throws ParseException { - String queryStr = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n" + - "PREFIX foaf: <http://xmlns.com/foaf/0.1/> \n\n" + - "SELECT ?person\n" + - "WHERE \n" + - "{\n" + - " ?person rdf:type foaf:Person .\n" + - " FILTER NOT EXISTS { ?person foaf:name ?name }\n" + - "}"; - - SparqlPreParser parser; - parser = new SparqlPreParser(TcManager.getInstance()); - Set<IRI> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH); - Assert.assertTrue(referredGraphs.toArray()[0].equals(DEFAULT_GRAPH)); - } -}
