Skip to content

Commit

Permalink
Commit of old local changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tfrancart committed May 24, 2022
1 parent 0e1e327 commit cf35a09
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class ApplicationData {
@Value("${shaclplay.validation.maxInputSize:500000}")
private int validationMaxInputSize;

@Value("${shaclplay.validation.maxInputSizeWithInference:50000}")
private int validationMaxInputSizeWithInference;

public ApplicationData() {
super();
}
Expand Down Expand Up @@ -69,5 +72,13 @@ public int getValidationMaxInputSize() {
public void setValidationMaxInputSize(int validationMaxInputSize) {
this.validationMaxInputSize = validationMaxInputSize;
}

public int getValidationMaxInputSizeWithInference() {
return validationMaxInputSizeWithInference;
}

public void setValidationMaxInputSizeWithInference(int validationMaxInputSizeWithInference) {
this.validationMaxInputSizeWithInference = validationMaxInputSizeWithInference;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.stream.Collectors;

import org.apache.jena.rdf.model.Model;
import org.apache.jena.riot.Lang;
import org.apache.jena.riot.RiotException;
import org.apache.jena.util.FileUtils;
import org.slf4j.Logger;
Expand Down Expand Up @@ -62,7 +63,9 @@ public void populateModel(
log.debug("Detected a zip extension");
ControllerCommons.populateModelFromZip(model, f.getInputStream());
} else {
ControllerCommons.populateModel(model, f.getInputStream(), FileUtils.guessLang(f.getOriginalFilename(), "RDF/XML"));
String lang = FileUtils.guessLang(f.getOriginalFilename(), "RDF/XML");
log.debug("Detected RDF format "+lang+" from file name "+f.getOriginalFilename());
ControllerCommons.populateModel(model, f.getInputStream(), lang);
}

// shape name is name of file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.jena.ontology.OntModel;
import org.apache.jena.ontology.OntModelSpec;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.riot.Lang;
Expand Down Expand Up @@ -51,6 +53,8 @@ public class ValidateController {
@Autowired
protected ShapesCatalogService catalogService;



@RequestMapping(
value = {"{shapes}/badge"},
params={"url"},
Expand Down Expand Up @@ -338,6 +342,8 @@ public ModelAndView validate(
@RequestParam(value="closeShapes", required=false) boolean closeShapes,
// createDetails option
@RequestParam(value="createDetails", required=false) boolean createDetails,
// infer option
@RequestParam(value="infer", required=false) Boolean infer,
HttpServletRequest request
) {
try {
Expand All @@ -351,6 +357,7 @@ public ModelAndView validate(

// initialize shapes first
log.debug("Determining Shapes source...");

Model shapesModel = ModelFactory.createDefaultModel();
ControllerModelFactory modelPopulator = new ControllerModelFactory(this.catalogService.getShapesCatalog());
modelPopulator.populateModel(
Expand All @@ -364,15 +371,38 @@ public ModelAndView validate(
log.debug("Done Loading Shapes. Model contains "+shapesModel.size()+" triples");

log.debug("Determining Data source...");
Model dataModel = ModelFactory.createDefaultModel();
modelPopulator.populateModel(
dataModel,
source,
url,
text,
files,
null
);
Model dataModel;
if(infer != null && infer) {
log.debug("Asked for inference, will use an ontology Model...");
OntModel tempModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_MICRO_RULE_INF);
modelPopulator.populateModel(
tempModel,
source,
url,
text,
files,
null
);

log.debug("Before inference model has "+tempModel.size()+" triples");
if(tempModel.size() > applicationData.getValidationMaxInputSizeWithInference()) {
throw new ControllerModelException("Input file is too large ("+tempModel.size()+" triples). Validation with inference is limited to "+applicationData.getValidationMaxInputSizeWithInference()+" triples");
}

dataModel = ModelFactory.createDefaultModel();
dataModel.add(tempModel);
} else {
dataModel = ModelFactory.createDefaultModel();
modelPopulator.populateModel(
dataModel,
source,
url,
text,
files,
null
);
}

log.debug("Done Loading Data to validate. Model contains "+dataModel.size()+" triples");

// compute permalink only if we can
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ validate.shapes.inline=Copy/paste SHACL content
validate.shapes.inline.help=Supported syntaxes : Turtle, RDF/XML, JSON-LD, TriG, TriX, N-Quads. We recommend Turtle.

validate.options.title=Options
validate.options.infer=Activate OWL-Micro inference before validation
validate.options.infer.help=Use this option if the data to be validated contains ontology triples and you need to apply <a href="https://jena.apache.org/documentation/inference/#owl">OWL-Micro inference</a> on the data before it is validated. /!\ Inference can take a very long time
validate.options.closeShapes=Closed World (adds sh:closed to NodeShapes)
validate.options.closeShapes.help=Check this option to verify that each shape uses <em>only</em> properties explicitely declared in the shape file. \
In other words, this verify that are no misplaced properties, and ensures no properties other than those explicitely listed are present in the data. It makes validation operate in "closed world". \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ validate.shapes.inline=Copier/coller les r
validate.shapes.inline.help=Syntaxes supportées : Turtle, RDF/XML, JSON-LD, TriG, TriX, N-Quads. Privilégiez Turtle.
validate.options.title=Options
validate.options.infer=Activer l'inférence OWL-Micro avant validation
validate.options.infer.help=Si les données à valider contiennent l'ontologie, vous pouvez activer une <a href="https://jena.apache.org/documentation/inference/#owl">inférence OWL-Micro</a> sur les données avant d'exécuter la validation. /!\ l'inférence peut être très longue
validate.options.closeShapes=Monde fermé (ajoute sh:closed sur les NodeShape)
validate.options.closeShapes.help=Cette option vérifie que chaque Shape porte <em>seulement</em> les propriétés déclarées explicitement dans le fichier de Shapes. \
En d'autres termes, cela vérifie que les propriétés sont "bien placées" sur leur domaine, et qu'aucune autre propriété que celles explicitement listées n'est présente dans les données. La validation opère en "monde fermé". \
Expand Down
15 changes: 14 additions & 1 deletion shacl-play/src/main/webapp/WEB-INF/jsp/validate-form.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@


<h2><i class="fal fa-tools"></i>&nbsp;&nbsp;<fmt:message key="validate.options.title" /></h2>
<blockquote class="blockquote bq-warning">
<blockquote class="blockquote bq-warning">
<div class="form-group row">
<div class="col-sm-12">
<div class="form-check">
Expand All @@ -315,6 +315,19 @@
</div>
</div>
</div>
<div class="form-group row">
<div class="col-sm-12">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="infer" name="infer" />
<label class="form-check-label" for="infer">
<fmt:message key="validate.options.infer" />
</label>
<small class="form-text text-muted">
<fmt:message key="validate.options.infer.help" />
</small>
</div>
</div>
</div>
</blockquote>

<button type="submit" id="validate-button" class="btn btn-info btn-lg"><fmt:message key="validate.validate" /></button>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@prefix questions: <https://data.europarl.europa.eu/def/parliamentary-questions#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .

questions:Question sh:target questions:Question-target .

questions:Question-target sh:select """PREFIX eli: <http://data.europa.eu/eli/ontology#>
PREFIX resource-type: <http://publications.europa.eu/resource/authority/resource-type/>
SELECT ?this
WHERE {
?this eli:work_type ?type .
VALUES ?type {
# all narrower terms of QUEST_EP
resource-type:INTERPELL_G
resource-type:INTERPELL_K
resource-type:QUEST_ORAL
resource-type:QUEST_PRIORITY
resource-type:QUEST_TIME
resource-type:QUEST_WRITTEN
}
# additional criteria to select only questions from a certain year
?this <http://data.europa.eu/eli/ontology#date_document> ?date . FILTER(year(?date) = 2019)
}""" .
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public Model validate(Model dataModel) throws ShaclValidatorException {

Model validatedModel;
if(this.complimentaryModel != null) {
log.info("Addind a complimentary model of "+complimentaryModel.size()+" triples...");
log.info("Adding a complimentary model of "+complimentaryModel.size()+" triples...");
validatedModel = ModelFactory.createModelForGraph(new MultiUnion(new Graph[] {
dataModel.getGraph(),
complimentaryModel.getGraph()
Expand Down

0 comments on commit cf35a09

Please sign in to comment.