This repository has been archived by the owner on Feb 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
eclipse-rdf4j/rdf4j#1109 support for language in
Signed-off-by: Håvard Ottestad <[email protected]>
- Loading branch information
1 parent
e279a2d
commit dae8c16
Showing
21 changed files
with
369 additions
and
18 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/AST/LanguageInPropertyShape.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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/******************************************************************************* | ||
* 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 | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
*******************************************************************************/ | ||
package org.eclipse.rdf4j.sail.shacl.AST; | ||
|
||
|
||
import org.eclipse.rdf4j.common.iteration.Iterations; | ||
import org.eclipse.rdf4j.model.Resource; | ||
import org.eclipse.rdf4j.model.Statement; | ||
import org.eclipse.rdf4j.model.Value; | ||
import org.eclipse.rdf4j.model.vocabulary.SHACL; | ||
import org.eclipse.rdf4j.repository.Repository; | ||
import org.eclipse.rdf4j.repository.sail.SailRepositoryConnection; | ||
import org.eclipse.rdf4j.sail.shacl.ShaclSailConnection; | ||
import org.eclipse.rdf4j.sail.shacl.planNodes.LanguageInFilter; | ||
import org.eclipse.rdf4j.sail.shacl.planNodes.PlanNode; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
/** | ||
* @author Håvard Ottestad | ||
*/ | ||
public class LanguageInPropertyShape extends PathPropertyShape { | ||
|
||
private final List<String> languageIn; | ||
private static final Logger logger = LoggerFactory.getLogger(LanguageInPropertyShape.class); | ||
|
||
LanguageInPropertyShape(Resource id, SailRepositoryConnection connection, NodeShape nodeShape) { | ||
super(id, connection, nodeShape); | ||
|
||
try (Stream<Statement> stream = Iterations.stream(connection.getStatements(id, SHACL.LANGUAGE_IN, null, true))) { | ||
Resource orList = stream.map(Statement::getObject).map(v -> (Resource) v).findAny().orElseThrow(() -> new RuntimeException("Expected to find sh:languageIn on " + id)); | ||
languageIn = toList(connection, orList).stream().map(Value::stringValue).collect(Collectors.toList()); | ||
} | ||
|
||
} | ||
|
||
|
||
@Override | ||
public PlanNode getPlan(ShaclSailConnection shaclSailConnection, NodeShape nodeShape, boolean printPlans, boolean assumeBaseSailValid) { | ||
|
||
PlanNode invalidValues = StandardisedPlanHelper.getGenericSingleObjectPlan( | ||
shaclSailConnection, | ||
nodeShape, | ||
(parent, trueNode, falseNode) -> new LanguageInFilter(parent, trueNode, falseNode, languageIn), | ||
this | ||
); | ||
|
||
if (printPlans) { | ||
String planAsGraphvizDot = getPlanAsGraphvizDot(invalidValues, shaclSailConnection); | ||
logger.info(planAsGraphvizDot); | ||
} | ||
|
||
return invalidValues; | ||
|
||
} | ||
|
||
@Override | ||
public boolean requiresEvaluation(Repository addedStatements, Repository removedStatements) { | ||
return true; | ||
} | ||
} |
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
49 changes: 49 additions & 0 deletions
49
shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/planNodes/LanguageInFilter.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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/******************************************************************************* | ||
* 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 | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.rdf4j.sail.shacl.planNodes; | ||
|
||
|
||
import org.eclipse.rdf4j.model.Literal; | ||
import org.eclipse.rdf4j.model.Resource; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
/** | ||
* @author Håvard Ottestad | ||
*/ | ||
public class LanguageInFilter extends FilterPlanNode { | ||
|
||
private final List<String> languageIn; | ||
|
||
public LanguageInFilter(PlanNode parent, PushBasedPlanNode trueNode, PushBasedPlanNode falseNode, List<String> languageIn) { | ||
super(parent, trueNode, falseNode); | ||
this.languageIn = languageIn; | ||
} | ||
|
||
@Override | ||
boolean checkTuple(Tuple t) { | ||
if(! (t.line.get(1) instanceof Literal)) return false; | ||
|
||
Optional<String> language = ((Literal) t.line.get(1)).getLanguage(); | ||
if(!language.isPresent()) return false; | ||
|
||
return languageIn.contains(language.get()); | ||
|
||
} | ||
|
||
|
||
@Override | ||
public String toString() { | ||
return "LanguageInFilter{" + | ||
"languageIn=" + Arrays.toString(languageIn.toArray()) + | ||
'}'; | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
shacl/src/test/resources/test-cases/languageIn/simple/invalid/case1/query1.rq
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,13 @@ | ||
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#> | ||
|
||
INSERT DATA { | ||
|
||
ex:validPerson1 a ex:Person ; | ||
ex:label "människa"@se. | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
shacl/src/test/resources/test-cases/languageIn/simple/invalid/case2/query1.rq
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,14 @@ | ||
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#> | ||
|
||
INSERT DATA { | ||
|
||
ex:validPerson1 a ex:Person ; | ||
ex:label "human"@en. | ||
|
||
|
||
} |
13 changes: 13 additions & 0 deletions
13
shacl/src/test/resources/test-cases/languageIn/simple/invalid/case2/query2.rq
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,13 @@ | ||
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#> | ||
|
||
INSERT DATA { | ||
|
||
ex:validPerson1 ex:label "människa"@se. | ||
|
||
|
||
} |
13 changes: 13 additions & 0 deletions
13
shacl/src/test/resources/test-cases/languageIn/simple/invalid/case3/query1.rq
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,13 @@ | ||
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#> | ||
|
||
INSERT DATA { | ||
|
||
ex:validPerson1 ex:label "människa"@se. | ||
|
||
|
||
} |
12 changes: 12 additions & 0 deletions
12
shacl/src/test/resources/test-cases/languageIn/simple/invalid/case3/query2.rq
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,12 @@ | ||
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#> | ||
|
||
INSERT DATA { | ||
|
||
ex:validPerson1 a ex:Person . | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
shacl/src/test/resources/test-cases/languageIn/simple/invalid/case4/query1.rq
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,13 @@ | ||
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#> | ||
|
||
INSERT DATA { | ||
|
||
ex:validPerson1 ex:label "människa"@se. | ||
|
||
|
||
} |
14 changes: 14 additions & 0 deletions
14
shacl/src/test/resources/test-cases/languageIn/simple/invalid/case4/query2.rq
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,14 @@ | ||
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#> | ||
|
||
INSERT DATA { | ||
|
||
ex:validPerson1 | ||
ex:label "human"@en ; | ||
a ex:Person . | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
shacl/src/test/resources/test-cases/languageIn/simple/invalid/case5/query1.rq
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,12 @@ | ||
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#> | ||
|
||
INSERT DATA { | ||
|
||
ex:validPerson1 ex:label "människa"@se. | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
shacl/src/test/resources/test-cases/languageIn/simple/invalid/case5/query2.rq
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,18 @@ | ||
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#> | ||
|
||
INSERT DATA { | ||
|
||
ex:validPerson1 | ||
ex:label "human"@en ; | ||
a ex:Person . | ||
|
||
ex:validPerson2 | ||
ex:label "human"@en ; | ||
a ex:Person . | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
shacl/src/test/resources/test-cases/languageIn/simple/shacl.ttl
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,16 @@ | ||
@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#> . | ||
|
||
ex:PersonShape | ||
a sh:NodeShape ; | ||
sh:targetClass ex:Person ; | ||
sh:property [ | ||
sh:path ex:label ; | ||
sh:languageIn ( "en" "no" ) ; | ||
] . | ||
|
13 changes: 13 additions & 0 deletions
13
shacl/src/test/resources/test-cases/languageIn/simple/valid/case1/query1.rq
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,13 @@ | ||
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#> | ||
|
||
INSERT DATA { | ||
|
||
ex:validPerson1 a ex:Person ; | ||
ex:label "human"@en, "menneske"@no. | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
shacl/src/test/resources/test-cases/languageIn/simple/valid/case2/query1.rq
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,13 @@ | ||
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#> | ||
|
||
INSERT DATA { | ||
|
||
ex:validPerson1 a ex:Person ; | ||
ex:label "human"@en. | ||
|
||
} |
Oops, something went wrong.