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#1290 fixed typo and reformat
Browse files Browse the repository at this point in the history
Signed-off-by: Håvard Ottestad <hmottestad@gmail.com>
  • Loading branch information
hmottestad committed Mar 31, 2019
1 parent 407d4d8 commit 378b505
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 146 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,67 +65,67 @@ public ShaclProperties(Resource propertyShapeId, SailRepositoryConnection connec
break;
case "http://www.w3.org/ns/shacl#languageIn":
if (languageIn != null) {
throw new IllegalStateException("sh:languageIn already populated");
throw new IllegalStateException(predicate + " already populated");
}
languageIn = (Resource) object;
break;
case "http://www.w3.org/ns/shacl#nodeKind":
if (nodeKind != null) {
throw new IllegalStateException("sh:nodeKind already populated");
throw new IllegalStateException(predicate + " already populated");
}
nodeKind = (Resource) object;
break;
case "http://www.w3.org/ns/shacl#datatype":
if (datatype != null) {
throw new IllegalStateException("sh:datatype already populated");
throw new IllegalStateException(predicate + " already populated");
}
datatype = (Resource) object;
break;
case "http://www.w3.org/ns/shacl#minCount":
if (minCount != null) {
throw new IllegalStateException("sh:minCount aleady populated");
throw new IllegalStateException(predicate + " already populated");
}
minCount = ((Literal) object).longValue();
break;
case "http://www.w3.org/ns/shacl#maxCount":
if (maxCount != null) {
throw new IllegalStateException("sh:maxCount aleady populated");
throw new IllegalStateException(predicate + " already populated");
}
maxCount = ((Literal) object).longValue();
break;
case "http://www.w3.org/ns/shacl#minLength":
if (minLength != null) {
throw new IllegalStateException("sh:minLength aleady populated");
throw new IllegalStateException(predicate + " already populated");
}
minLength = ((Literal) object).longValue();
break;
case "http://www.w3.org/ns/shacl#maxLength":
if (maxLength != null) {
throw new IllegalStateException("sh:maxLength aleady populated");
throw new IllegalStateException(predicate + " already populated");
}
maxLength = ((Literal) object).longValue();
break;
case "http://www.w3.org/ns/shacl#minExclusive":
if (minExclusive != null) {
throw new IllegalStateException("sh:minExclusive aleady populated");
throw new IllegalStateException(predicate + " already populated");
}
minExclusive = (Literal) object;
break;
case "http://www.w3.org/ns/shacl#maxExclusive":
if (maxExclusive != null) {
throw new IllegalStateException("sh:maxExclusive aleady populated");
throw new IllegalStateException(predicate + " already populated");
}
maxExclusive = (Literal) object;
break;
case "http://www.w3.org/ns/shacl#minInclusive":
if (minInclusive != null) {
throw new IllegalStateException("sh:minInclusive aleady populated");
throw new IllegalStateException(predicate + " already populated");
}
minInclusive = (Literal) object;
break;
case "http://www.w3.org/ns/shacl#maxInclusive":
if (maxInclusive != null) {
throw new IllegalStateException("sh:maxInclusive aleady populated");
throw new IllegalStateException(predicate + " already populated");
}
maxInclusive = (Literal) object;
break;
Expand Down Expand Up @@ -158,13 +158,13 @@ public ShaclProperties(Resource propertyShapeId, SailRepositoryConnection connec
break;
case "http://www.w3.org/ns/shacl#path":
if (path != null) {
throw new IllegalStateException("sh:path aleady populated");
throw new IllegalStateException(predicate + " already populated");
}
path = (Resource) object;
break;
case "http://www.w3.org/ns/shacl#in":
if (in != null) {
throw new IllegalStateException("sh:in aleady populated");
throw new IllegalStateException(predicate + " already populated");
}
in = (Resource) object;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,42 +41,40 @@ public void testDataAndShapes() {
Transaction transaction = new Transaction();

String join = String.join("\n", "",
"ex:shape_" + i + "_" + j,
" a sh:NodeShape ;",
" sh:targetClass ex:Person" + j + " ;",
" sh:property [",
" sh:path ex:age ;",
" sh:minCount 1 ;",
" ] .");
"ex:shape_" + i + "_" + j,
" a sh:NodeShape ;",
" sh:targetClass ex:Person" + j + " ;",
" sh:property [",
" sh:path ex:age ;",
" sh:minCount 1 ;",
" ] .");

transaction.add(join, RDF4J.SHACL_SHAPE_GRAPH);
transactions.add(transaction);
}
list.add(transactions);
}


for (int j = 0; j < 10; j++) {
ArrayList<Transaction> transactions = new ArrayList<>();
for (int i = 0; i < 10; i++) {
Transaction transaction = new Transaction();
String join;
if (i % 2 == 0) {
join = String.join("\n", "",
"ex:data_" + i + "_" + j + " a ex:Person" + j + "; ",
" ex:age" + i + " " + i + j,
" ."
"ex:data_" + i + "_" + j + " a ex:Person" + j + "; ",
" ex:age" + i + " " + i + j,
" ."

);
} else {
join = String.join("\n", "",
"ex:data_" + i + "_" + j + " a ex:Person" + j + "; ",
" ."
"ex:data_" + i + "_" + j + " a ex:Person" + j + "; ",
" ."

);
}


transaction.add(join, null);
transactions.add(transaction);
}
Expand All @@ -89,42 +87,40 @@ public void testDataAndShapes() {
Transaction transaction = new Transaction();

String join = String.join("\n", "",
"ex:shape_" + i + "_" + j,
" a sh:NodeShape ;",
" sh:targetClass ex:Person" + j + " ;",
" sh:property [",
" sh:path ex:age ;",
" sh:minCount 1 ;",
" ] .");
"ex:shape_" + i + "_" + j,
" a sh:NodeShape ;",
" sh:targetClass ex:Person" + j + " ;",
" sh:property [",
" sh:path ex:age ;",
" sh:minCount 1 ;",
" ] .");

transaction.remove(join, RDF4J.SHACL_SHAPE_GRAPH);
transactions.add(transaction);
}
list.add(transactions);
}


for (int j = 0; j < 10; j++) {
ArrayList<Transaction> transactions = new ArrayList<>();
for (int i = 0; i < 10; i++) {
Transaction transaction = new Transaction();
String join;
if (i % 2 == 0) {
join = String.join("\n", "",
"ex:data_" + i + "_" + j + " a ex:Person" + j + "; ",
" ex:age" + i + " " + i + j,
" ."
"ex:data_" + i + "_" + j + " a ex:Person" + j + "; ",
" ex:age" + i + " " + i + j,
" ."

);
} else {
join = String.join("\n", "",
"ex:data_" + i + "_" + j + " a ex:Person" + j + "; ",
" ."
"ex:data_" + i + "_" + j + " a ex:Person" + j + "; ",
" ."

);
}


transaction.remove(join, null);
transactions.add(transaction);
}
Expand All @@ -144,29 +140,29 @@ private void parallelTest(List<List<Transaction>> list, IsolationLevels isolatio
try {

list.stream()
.sorted(Comparator.comparingInt(System::identityHashCode))
.parallel()
.forEach(transactions -> {
try (SailRepositoryConnection connection = repository.getConnection()) {

transactions.forEach(transaction -> {
connection.begin(isolationLevel);
connection.add(transaction.addedStatements);
connection.remove(transaction.removedStatements);
try {
connection.commit();
} catch (RepositoryException e) {
System.out.println("here");
if (!(e.getCause() instanceof ShaclSailValidationException)) {
throw e;
.sorted(Comparator.comparingInt(System::identityHashCode))
.parallel()
.forEach(transactions -> {
try (SailRepositoryConnection connection = repository.getConnection()) {

transactions.forEach(transaction -> {
connection.begin(isolationLevel);
connection.add(transaction.addedStatements);
connection.remove(transaction.removedStatements);
try {
connection.commit();
} catch (RepositoryException e) {
System.out.println("here");
if (!(e.getCause() instanceof ShaclSailValidationException)) {
throw e;
}
connection.rollback();
}
connection.rollback();
}
});
});

}
}

});
});

} finally {
try (SailRepositoryConnection connection = repository.getConnection()) {
Expand All @@ -184,25 +180,25 @@ class Transaction {

private void add(String turtle, IRI graph) {
turtle = String.join("\n", "",
"@prefix ex: <http://example.com/ns#> .",
"@prefix sh: <http://www.w3.org/ns/shacl#> .",
"@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .",
"@prefix foaf: <http://xmlns.com/foaf/0.1/>.") + turtle;
"@prefix ex: <http://example.com/ns#> .",
"@prefix sh: <http://www.w3.org/ns/shacl#> .",
"@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .",
"@prefix foaf: <http://xmlns.com/foaf/0.1/>.") + turtle;

StringReader shaclRules = new StringReader(turtle);

try {
Model parse = Rio.parse(shaclRules, "", RDFFormat.TURTLE);
parse.stream()
.map(statement -> {
if (graph != null) {
return vf.createStatement(statement.getSubject(), statement.getPredicate(),
statement.getObject(), graph);
}
.map(statement -> {
if (graph != null) {
return vf.createStatement(statement.getSubject(), statement.getPredicate(),
statement.getObject(), graph);
}

return statement;
})
.forEach(statement -> addedStatements.add(statement));
return statement;
})
.forEach(statement -> addedStatements.add(statement));
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand All @@ -211,25 +207,25 @@ private void add(String turtle, IRI graph) {

private void remove(String turtle, IRI graph) {
turtle = String.join("\n", "",
"@prefix ex: <http://example.com/ns#> .",
"@prefix sh: <http://www.w3.org/ns/shacl#> .",
"@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .",
"@prefix foaf: <http://xmlns.com/foaf/0.1/>.") + turtle;
"@prefix ex: <http://example.com/ns#> .",
"@prefix sh: <http://www.w3.org/ns/shacl#> .",
"@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .",
"@prefix foaf: <http://xmlns.com/foaf/0.1/>.") + turtle;

StringReader shaclRules = new StringReader(turtle);

try {
Model parse = Rio.parse(shaclRules, "", RDFFormat.TURTLE);
parse.stream()
.map(statement -> {
if (graph != null) {
return vf.createStatement(statement.getSubject(), statement.getPredicate(),
statement.getObject(), graph);
}
.map(statement -> {
if (graph != null) {
return vf.createStatement(statement.getSubject(), statement.getPredicate(),
statement.getObject(), graph);
}

return statement;
})
.forEach(statement -> removedStatements.add(statement));
return statement;
})
.forEach(statement -> removedStatements.add(statement));
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
Loading

0 comments on commit 378b505

Please sign in to comment.