Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
eclipse-rdf4j/rdf4j#1113 moved graph name constant and fixed complian…
Browse files Browse the repository at this point in the history
…ce test setup
  • Loading branch information
abrokenjester committed Jan 20, 2019
1 parent 08353d0 commit 59f71f6
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 111 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018 Eclipse RDF4J contributors, Aduna, and others.
* Copyright (c) 2018 Eclipse RDF4J contributors.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Distribution License v1.0
* which accompanies this distribution, and is available at
Expand All @@ -8,11 +8,6 @@
package org.eclipse.rdf4j.sail.shacl;

import org.eclipse.rdf4j.model.Model;
import org.eclipse.rdf4j.model.Resource;
import org.eclipse.rdf4j.model.impl.LinkedHashModel;
import org.eclipse.rdf4j.model.vocabulary.RDF;
import org.eclipse.rdf4j.model.vocabulary.SHACL;
import org.eclipse.rdf4j.repository.sail.SailRepository;
import org.eclipse.rdf4j.sail.NotifyingSail;
import org.eclipse.rdf4j.sail.Sail;
import org.eclipse.rdf4j.sail.memory.MemoryStore;
Expand Down Expand Up @@ -62,39 +57,9 @@ protected NotifyingSail newDataSail() {
return new MemoryStore();
}

protected SailRepository createShapesRepository() {
SailRepository repo = new SailRepository(new MemoryStore());
repo.initialize();
return repo;
}

@Override
protected Sail newSail(Model shapesGraph) {
SailRepository shapesRep = createShapesRepository();
if (shapesGraph != null) {
try {
upload(shapesRep, shapesGraph);
}
catch (Exception exc) {
try {
shapesRep.shutDown();
shapesRep = null;
}
catch (Exception e2) {
logger.error(e2.toString(), e2);
}
throw exc;
}
}
Model infer = new LinkedHashModel();
for (Resource subj : shapesGraph.filter(null, RDF.TYPE, SHACL.NODE_SHAPE).subjects()) {
infer.add(subj, RDF.TYPE, SHACL.SHAPE);
}
for (Resource subj : shapesGraph.filter(null, RDF.TYPE, SHACL.PROPERTY_SHAPE).subjects()) {
infer.add(subj, RDF.TYPE, SHACL.SHAPE);
}
upload(shapesRep, infer);
return new ShaclSail(newDataSail(), shapesRep);
protected Sail newSail() {
return new ShaclSail(newDataSail());
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package org.eclipse.rdf4j.sail.shacl;

import org.eclipse.rdf4j.model.vocabulary.RDF4J;

public class NoShapesLoadedException extends RuntimeException {

private static final long serialVersionUID = 1L;

public NoShapesLoadedException() {
super("Load shapes by adding them to named graph <"+ShaclSail.SHAPE_GRAPH+"> in the first transaction after initialization!");
super("Load shapes by adding them to named graph <" + RDF4J.SHACL_SHAPE_GRAPH
+ "> in the first transaction after initialization!");
}
}
47 changes: 22 additions & 25 deletions shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ShaclSail.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.apache.commons.io.IOUtils;
import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
import org.eclipse.rdf4j.model.vocabulary.RDF4J;
import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.sail.SailRepository;
import org.eclipse.rdf4j.repository.sail.SailRepositoryConnection;
Expand All @@ -29,25 +30,20 @@
import java.util.List;

/**
* A {@link Sail} implementation that adds support for the Shapes Constraint Language (SHACL)
* A {@link Sail} implementation that adds support for the Shapes Constraint Language (SHACL).
* <p>
* The ShaclSail looks for SHACL shape data in a special named graph {@link RDF4J#SHACL_SHAPE_GRAPH}.
*
* @author Heshan Jayasinghe
* @author Håvard Ottestad
* @see <a href="https://www.w3.org/TR/shacl/">SHACL W3C Recommendation</a>
*/
public class ShaclSail extends NotifyingSailWrapper {

/**
* The virtual context identifier for persisting the SHACL shapes information.
*/
@SuppressWarnings("WeakerAccess")
public final static IRI SHAPE_GRAPH = SimpleValueFactory
.getInstance()
.createIRI("http://rdf4j.org/schema/schacl#ShapeGraph");

private List<NodeShape> nodeShapes;

boolean debugPrintPlans = false;

private boolean ignoreNoShapesLoadedException = false;

ShaclSailConfig config = new ShaclSailConfig();
Expand All @@ -64,18 +60,14 @@ public class ShaclSail extends NotifyingSailWrapper {
static {
try {
SH_OR_UPDATE_QUERY = IOUtils.toString(
ShaclSail
.class
.getClassLoader()
.getResourceAsStream("shacl-sparql-inference/sh_or.rq"),
"UTF-8");
ShaclSail.class.getClassLoader().getResourceAsStream("shacl-sparql-inference/sh_or.rq"),
"UTF-8");
SH_OR_NODE_SHAPE_UPDATE_QUERY = IOUtils.toString(
ShaclSail
.class
.getClassLoader()
.getResourceAsStream("shacl-sparql-inference/sh_or_node_shape.rq"),
"UTF-8");
} catch (IOException e) {
ShaclSail.class.getClassLoader().getResourceAsStream(
"shacl-sparql-inference/sh_or_node_shape.rq"),
"UTF-8");
}
catch (IOException e) {
throw new IllegalStateException(e);
}

Expand All @@ -86,10 +78,12 @@ public ShaclSail(NotifyingSail baseSail) {
String path = null;
if (baseSail.getDataDir() != null) {
path = baseSail.getDataDir().getPath();
} else {
}
else {
try {
path = Files.createTempDirectory("shacl-shapes").toString();
} catch (IOException e) {
}
catch (IOException e) {
throw new SailConfigException(e);
}
}
Expand Down Expand Up @@ -118,7 +112,8 @@ void refreshShapes(SailRepositoryConnection shapesRepoConnection) throws SailExc
// Our inferencer both adds and removes statements.
// To support updates I recommend having two graphs, one raw one with the unmodified data.
// Then copy all that data into a new graph, run inferencing on that graph and use it to generate the java objects
throw new IllegalStateException("ShaclSail does not support modifying shapes that are already loaded or loading more shapes");
throw new IllegalStateException(
"ShaclSail does not support modifying shapes that are already loaded or loading more shapes");
}
}

Expand All @@ -130,15 +125,17 @@ void refreshShapes(SailRepositoryConnection shapesRepoConnection) throws SailExc
public void shutDown() throws SailException {
try {
shapesRepo.shutDown();
} finally {
}
finally {
shapesRepo = null;
}
super.shutDown();
}

@Override
public NotifyingSailConnection getConnection() throws SailException {
return new ShaclSailConnection(this, super.getConnection(), super.getConnection(), shapesRepo.getConnection());
return new ShaclSailConnection(this, super.getConnection(), super.getConnection(),
shapesRepo.getConnection());
}

public void disableValidation() {
Expand Down
Loading

0 comments on commit 59f71f6

Please sign in to comment.