forked from eclipse-rdf4j/rdf4j
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Heshan Jayasinghe <shanujse@gmail.com> Signed-off-by: Heshan Jayasinghe <shanujse@gmail.com>
- Loading branch information
Showing
10 changed files
with
133 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 29 additions & 18 deletions
47
core/shacl/src/main/java/org/eclipse/rdf4j/AST/Shape.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,62 @@ | ||
package org.eclipse.rdf4j.AST; | ||
|
||
import org.eclipse.rdf4j.model.Resource; | ||
import org.eclipse.rdf4j.model.Statement; | ||
import org.eclipse.rdf4j.model.ValueFactory; | ||
import org.eclipse.rdf4j.model.vocabulary.RDF; | ||
import org.eclipse.rdf4j.model.vocabulary.RDFS; | ||
import org.eclipse.rdf4j.repository.RepositoryResult; | ||
import org.eclipse.rdf4j.repository.sail.SailRepositoryConnection; | ||
import org.eclipse.rdf4j.vocabulary.SH; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Created by heshanjayasinghe on 6/10/17. | ||
*/ | ||
public class Shape { | ||
Resource id; | ||
SailRepositoryConnection connection; | ||
List<PropertyShape> propertyShapes; | ||
TargetClass targetClass; | ||
|
||
|
||
public Shape(Resource id, SailRepositoryConnection connection) { | ||
this.id = id; | ||
this.connection = connection; | ||
propertyShapes = new PropertyShape.Factory().getProprtyShapes(id,connection); | ||
ValueFactory vf = connection.getValueFactory(); | ||
if(connection.hasStatement(id, vf.createIRI(SH.BASE_URI, "targetClass"), null, true)) { | ||
targetClass = new TargetClass(id, connection); | ||
} | ||
|
||
} | ||
|
||
static class Factory{ | ||
Shape shape; | ||
Shape getShapes(Resource id, SailRepositoryConnection connection){ | ||
if(!hasShape()){ | ||
shape = new Shape(id ,connection); | ||
public static class Factory{ | ||
|
||
private List<Shape> shapes; | ||
public List<Shape> getShapes(SailRepositoryConnection connection) { | ||
shapes = new ArrayList<>(); | ||
|
||
//SHACL.SHAPE --> RDFS.RESOURCE | ||
RepositoryResult<Statement> statements = connection.getStatements(null, RDF.TYPE, SHACL.SHAPE); | ||
while (statements.hasNext()) { | ||
Resource shapeId = statements.next().getSubject(); | ||
if (hasTargetClass(shapeId, connection)) { | ||
shapes.add(new TargetClass(shapeId, connection)); | ||
} else { | ||
shapes.add(new Shape(shapeId, connection)); | ||
} | ||
return shapes; | ||
} | ||
return shape; | ||
return shapes; | ||
} | ||
|
||
private boolean hasShape() { | ||
if (shape == null) | ||
return false; | ||
return true; | ||
private boolean hasTargetClass(Resource shapeId, SailRepositoryConnection connection) { | ||
for (Shape shape:shapes) { | ||
if(shape instanceof TargetClass) | ||
return true; | ||
} | ||
return false; | ||
} | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,55 @@ | ||
package org.eclipse.rdf4j; | ||
|
||
import org.eclipse.rdf4j.model.vocabulary.RDF; | ||
import org.eclipse.rdf4j.model.vocabulary.RDFS; | ||
import org.eclipse.rdf4j.sail.NotifyingSailConnection; | ||
import org.eclipse.rdf4j.model.Statement; | ||
import org.eclipse.rdf4j.repository.RepositoryResult; | ||
import org.eclipse.rdf4j.repository.sail.SailRepository; | ||
import org.eclipse.rdf4j.repository.sail.SailRepositoryConnection; | ||
import org.eclipse.rdf4j.rio.RDFFormat; | ||
import org.eclipse.rdf4j.rio.RDFParser; | ||
import org.eclipse.rdf4j.rio.Rio; | ||
import org.eclipse.rdf4j.rio.helpers.StatementCollector; | ||
import org.eclipse.rdf4j.sail.memory.MemoryStore; | ||
import org.eclipse.rdf4j.validation.ShaclSail; | ||
|
||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
public class Main { | ||
|
||
|
||
public static void main(String[] args) { | ||
ShaclSail shaclSail = new ShaclSail(new MemoryStore()); | ||
shaclSail.initialize(); | ||
|
||
try (NotifyingSailConnection connection = shaclSail.getConnection()) { | ||
connection.begin(); | ||
connection.addStatement(RDFS.CLASS, RDF.TYPE, RDFS.RESOURCE); | ||
connection.commit(); | ||
} | ||
try (NotifyingSailConnection connection = shaclSail.getConnection()) { | ||
connection.begin(); | ||
connection.removeStatements(RDFS.CLASS, RDF.TYPE, RDFS.RESOURCE); | ||
connection.commit(); | ||
SailRepository shacl = new SailRepository(new MemoryStore()); | ||
shacl.initialize(); | ||
|
||
try (SailRepositoryConnection connection = shacl.getConnection()) { | ||
RDFParser rdfParser = Rio.createParser(RDFFormat.TURTLE); | ||
rdfParser.setRDFHandler(new StatementCollector(){ | ||
@Override | ||
public void handleStatement(Statement st) { | ||
connection.add(st); | ||
} | ||
}); | ||
|
||
String filename = "shacl.ttl"; | ||
InputStream input = ShaclSail.class.getResourceAsStream("/" + filename); | ||
rdfParser.parse(input, ""); | ||
RepositoryResult<Statement> result = connection.getStatements(null, null, null); | ||
while (result.hasNext()) { | ||
Statement st = result.next(); | ||
System.out.println("db contains: " + st); | ||
} | ||
|
||
} catch (FileNotFoundException e) { | ||
e.printStackTrace(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
ShaclSail shaclSail = new ShaclSail(new MemoryStore(),shacl); | ||
shaclSail.initialize(); | ||
System.out.println("done"); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.eclipse.rdf4j; | ||
|
||
import org.eclipse.rdf4j.AST.MinCountPropertyShape; | ||
import org.eclipse.rdf4j.AST.Path; | ||
import org.eclipse.rdf4j.model.ValueFactory; | ||
import org.eclipse.rdf4j.model.impl.SimpleValueFactory; | ||
|
||
/** | ||
* Created by heshanjayasinghe on 6/20/17. | ||
*/ | ||
public class Main2 { | ||
static ValueFactory vf = SimpleValueFactory.getInstance(); | ||
|
||
public static void main(String[] args) { | ||
MinCountPropertyShape minCountPropertyShape = new MinCountPropertyShape(null,null); | ||
minCountPropertyShape.minCount = 1; | ||
Path path = new Path(null,null); | ||
path.path = vf.createIRI("http://example.org/ssn"); | ||
minCountPropertyShape.path =path; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,20 @@ | ||
@prefix ex: <http://example.org/> . | ||
@prefix foaf: <http://xmlns.com/foaf/0.1/> . | ||
ex:Picasso a ex:Artist ; | ||
foaf:firstName "Pablo" ; | ||
foaf:surname "Picasso"; | ||
ex:creatorOf ex:guernica ; | ||
ex:homeAddress _:node1 . | ||
@base <http://example.com/ns> . | ||
@prefix ex: <http://example.com/ns#> . | ||
@prefix owl: <http://www.w3.org/2002/07/owl#> . | ||
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . | ||
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . | ||
@prefix sh: <http://www.w3.org/ns/shacl#> . | ||
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . | ||
|
||
_:node1 ex:street "31 Art Gallery" ; | ||
ex:city "Madrid" ; | ||
ex:country "Spain" . | ||
<http://example.com/ns> | ||
rdf:type owl:Ontology ; | ||
owl:imports <http://example.com/person-ontology> . | ||
|
||
ex:guernica a ex:Painting ; | ||
rdfs:label "Guernica"; | ||
ex:technique "oil on canvas". | ||
ex:PersonShape | ||
a sh:Shape ; | ||
sh:targetClass ex:Person ; | ||
sh:property [ | ||
sh:path ex:ssn ; | ||
sh:minCount 1 ; | ||
|
||
ex:VanGogh a ex:Artist ; | ||
foaf:firstName "Vincent" ; | ||
foaf:surname "van Gogh"; | ||
ex:creatorOf ex:starryNight, ex:sunflowers, ex:potatoEaters . | ||
|
||
ex:starryNight a ex:Painting ; | ||
ex:technique "oil on canvas"; | ||
rdfs:label "Starry Night" . | ||
|
||
ex:sunflowers a ex:Painting ; | ||
ex:technique "oil on canvas"; | ||
rdfs:label "Sunflowers" . | ||
|
||
ex:potatoEaters a ex:Painting ; | ||
ex:technique "oil on canvas"; | ||
rdfs:label "The Potato Eaters" . | ||
] . |