Commit ddec1f0f authored by Maxime Lefrançois's avatar Maxime Lefrançois

check examples and terms

parent ae422769
......@@ -25,7 +25,16 @@
*/
package fr.emse.gitlab.saref;
import java.nio.file.FileSystems;
import java.nio.file.PathMatcher;
import java.util.ResourceBundle;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import fr.emse.gitlab.saref.entities.SAREFCore;
import fr.emse.gitlab.saref.entities.SAREFExtension;
import fr.emse.gitlab.saref.entities.SAREFProject;
import fr.emse.gitlab.saref.entities.SAREFVersionName;
/**
*
......@@ -33,7 +42,10 @@ import java.util.ResourceBundle;
*
*/
public class SAREF {
public static final PathMatcher TTL_MATCHER = FileSystems.getDefault().getPathMatcher("glob:**/*.ttl");
public static final PathMatcher CSV_MATCHER = FileSystems.getDefault().getPathMatcher("glob:**/*.csv");
private final static ResourceBundle BUNDLE = ResourceBundle.getBundle("messages/SAREF");
public final static String BASE = "https://saref.etsi.org/";
public final static String FORGE = "https://forge.etsi.org/rep/SAREF/";
......@@ -45,6 +57,84 @@ public class SAREF {
public static final String LOGGER_BASE = "saref.pipeline";
public static final String NAME_SITE = "site";
// project acronym
public static final String REGEX_ACRONYM_VAR = "acronym";
public static final String REGEX_ACRONYM = String.format("(?<%s>[a-z]{4})", REGEX_ACRONYM_VAR);
// project name
public static final String REGEX_NAME_EXTENSION = "saref4" + REGEX_ACRONYM;
public static final String REGEX_NAME_PROJECT = String.format("(%s|%s)", REGEX_NAME_EXTENSION,
SAREFCore.INSTANCE.getRepositoryName());
// project paths
public static final String REGEX_PATH_CORE = "core";
public static final String REGEX_PATH_EXTENSION = "saref4" + REGEX_ACRONYM;
public static final String REGEX_PATH_PROJECT = String.format("(%s|%s)", REGEX_PATH_CORE, REGEX_PATH_EXTENSION);
// project version
public static final String REGEX_VERSION_MAJOR_VAR = "major";
public static final String REGEX_VERSION_MINOR_VAR = "minor";
public static final String REGEX_VERSION_PATCH_VAR = "patch";
public static final String REGEX_VERSION_NUMBER = String.format("v(?<%s>[0-9]+)\\.(?<%s>[0-9]+)\\.(?<%s>[0-9]+)", REGEX_VERSION_MAJOR_VAR, REGEX_VERSION_MINOR_VAR, REGEX_VERSION_PATCH_VAR);
// project version prefix, namespace, ontology IRI, ontology version IRI,
public static final String REGEX_CORE_PREFIX = "saref";
public static final String REGEX_EXTENSION_PREFIX = "s4" + REGEX_ACRONYM;
public static final String REGEX_ONTOLOGY_IRI = String.format("^%s%s/$", BASE, REGEX_PATH_PROJECT);
public static final String REGEX_ONTOLOGY_VERSION_IRI = String.format("^%s%s/%s/$", BASE, REGEX_PATH_PROJECT,
REGEX_VERSION_NUMBER);
// example
public static final String REGEX_EXAMPLE_NAME_VAR = "examplename";
public static final String REGEX_EXAMPLE_NAME = String.format("(?<%s>([^/]+))", REGEX_EXAMPLE_NAME_VAR);
public static final String REGEX_EXAMPLE_FILE_NAME = String.format("^(?<%s>([^/]+))\\.ttl$", REGEX_EXAMPLE_NAME_VAR);
// example namespace, IRI
public static final String REGEX_EXAMPLE_IRI = String.format("^%s%s/%s/example/%s#$", BASE, REGEX_PATH_PROJECT,
REGEX_VERSION_NUMBER, REGEX_EXAMPLE_NAME);
// terms
public static final String REGEX_TERM_NAME_VAR = "localName";
public static final String REGEX_TERM_NAME = String.format("(?<%s>[^/]+)", REGEX_TERM_NAME_VAR);
public static final String REGEX_TERM = String.format("^%s%s/%s$", BASE, REGEX_PATH_PROJECT, REGEX_TERM_NAME);
public static SAREFProject extractProject(String uri) {
final Matcher matcher = Pattern.compile(String.format("^%s%s/", BASE, REGEX_PATH_PROJECT))
.matcher(uri);
if (!matcher.find()) {
return null;
}
final String acronym = matcher.group(REGEX_ACRONYM_VAR);
if (acronym == null) {
return SAREFCore.INSTANCE;
} else {
return new SAREFExtension(acronym);
}
}
public static SAREFVersionName extractVersionName(String uri) {
final Matcher matcher = Pattern.compile(String.format("^%s%s/%s/", BASE, REGEX_PATH_PROJECT,
REGEX_VERSION_NUMBER)).matcher(uri);
if (!matcher.find()) {
return null;
}
int major = Integer.parseInt(matcher.group(REGEX_VERSION_MAJOR_VAR));
int minor = Integer.parseInt(matcher.group(REGEX_VERSION_MINOR_VAR));
int patch = Integer.parseInt(matcher.group(REGEX_VERSION_PATCH_VAR));
return new SAREFVersionName(major, minor, patch);
}
public static String extractExampleName(String uri) {
final Matcher matcher = Pattern.compile(REGEX_EXAMPLE_IRI).matcher(uri);
if (!matcher.find()) {
return null;
}
return matcher.group(REGEX_EXAMPLE_NAME_VAR);
}
public static <T> String getMessage(String key, Object... args) {
String msg = BUNDLE.getString(key);
......
......@@ -127,7 +127,9 @@ public class SAREFPipeline {
siteManager.prepareSite();
sourcesManager = new SourcesManager(this, logger);
sourcesManager.initTargetRepositoryManager();
sourcesManager.fetchRepositories();
sourcesManager.loadRepositories();
sourcesManager.checkClauses();
sourcesManager.checkTerms();
sourcesManager.generateSite();
......
......@@ -27,13 +27,12 @@ package fr.emse.gitlab.saref.checkers;
import java.io.File;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.util.Optional;
import java.util.stream.Collectors;
import fr.emse.gitlab.saref.SAREF;
import fr.emse.gitlab.saref.SAREFPipelineException;
import fr.emse.gitlab.saref.managers.RepositoryManager;
......@@ -43,7 +42,6 @@ import fr.emse.gitlab.saref.managers.RepositoryManager;
*/
public class Clause_9_3_Checker extends AbstractClauseChecker {
private static final PathMatcher csvMatcher = FileSystems.getDefault().getPathMatcher("glob:**/*.csv");
private static final String FIRST_LINE = "Id;Category;Requirement";
private static enum MESSAGE {
......@@ -82,7 +80,7 @@ public class Clause_9_3_Checker extends AbstractClauseChecker {
String nonCsv = Files.walk(path, 1).filter(p -> {
try {
return p.toFile().isFile() && !csvMatcher.matches(p) && !p.toFile().getName().startsWith(".");
return p.toFile().isFile() && !SAREF.CSV_MATCHER.matches(p) && !p.toFile().getName().startsWith(".");
} catch (Exception ex) {
return false;
}
......@@ -92,7 +90,7 @@ public class Clause_9_3_Checker extends AbstractClauseChecker {
}
boolean containsFile = Files.walk(path, 1).anyMatch(p -> {
return csvMatcher.matches(p);
return SAREF.CSV_MATCHER.matches(p);
});
if (!containsFile) {
logWarning(getMessage(MESSAGE.missing));
......@@ -101,7 +99,7 @@ public class Clause_9_3_Checker extends AbstractClauseChecker {
private void checkFirstLine(Path path) throws IOException {
Files.walk(path).filter(p -> {
return csvMatcher.matches(p);
return SAREF.CSV_MATCHER.matches(p);
}).forEach(p -> {
Optional<String> firstLine;
try {
......
......@@ -26,17 +26,9 @@
package fr.emse.gitlab.saref.checkers;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.nio.charset.MalformedInputException;
import java.nio.file.Files;
import org.apache.jena.atlas.RuntimeIOException;
import org.apache.jena.riot.Lang;
import fr.emse.gitlab.saref.SAREF;
import fr.emse.gitlab.saref.SAREFPipelineException;
import fr.emse.gitlab.saref.managers.RepositoryManager;
import fr.emse.gitlab.saref.utils.Languages;
......@@ -73,25 +65,6 @@ public class Clause_9_4_1_Checker extends AbstractClauseChecker {
logError(msg);
throw new SAREFPipelineException(msg);
}
try (FileInputStream input = new FileInputStream(file)) {
version.getModel().read(input, SAREF.BASE, Lang.TTL.getLabel());
} catch (Exception ex) {
if (ex instanceof RuntimeIOException && ex.getCause() instanceof MalformedInputException) {
version.getModel().removeAll();
try (InputStreamReader input2 = new InputStreamReader(new FileInputStream(file),
Charset.defaultCharset())) {
version.getModel().read(input2, SAREF.BASE, Lang.TTL.getLabel());
} catch (Exception ex2) {
String msg = getMessage(MESSAGE.turtle);
logError(msg, ex2);
throw new SAREFPipelineException(msg, ex2);
}
} else {
String msg = getMessage(MESSAGE.turtle);
logError(msg, ex);
throw new SAREFPipelineException(msg, ex);
}
}
}
}
......@@ -30,9 +30,9 @@ import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import fr.emse.gitlab.saref.SAREF;
import fr.emse.gitlab.saref.SAREFPipelineException;
import fr.emse.gitlab.saref.entities.SAREFExtension;
import fr.emse.gitlab.saref.entities.SAREFProject;
import fr.emse.gitlab.saref.managers.RepositoryManager;
/**
......@@ -41,7 +41,7 @@ import fr.emse.gitlab.saref.managers.RepositoryManager;
*/
public class Clause_9_4_2_Checker extends AbstractClauseChecker {
private final static Pattern PATTERN_PREFIX = Pattern.compile(SAREFProject.REGEX_EXTENSION_PREFIX);
private final static Pattern PATTERN_PREFIX = Pattern.compile(SAREF.REGEX_EXTENSION_PREFIX);
private static final Map<String, String> PREFIXES = new HashMap<String, String>();
static {
......@@ -78,7 +78,7 @@ public class Clause_9_4_2_Checker extends AbstractClauseChecker {
for (String s : prefixes.keySet()) {
Matcher m = PATTERN_PREFIX.matcher(s);
if (m.matches()) {
String acronym = m.group(SAREFProject.REGEX_ACRONYM_VAR);
String acronym = m.group(SAREF.REGEX_ACRONYM_VAR);
String expected = new SAREFExtension(acronym).getNamespace();
if(!prefixes.get(s).equals(expected)) {
logError(getMessage(MESSAGE.different, s, expected, prefixes.get(s)));
......
......@@ -25,9 +25,7 @@
*/
package fr.emse.gitlab.saref.checkers;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
......@@ -37,10 +35,7 @@ import org.apache.jena.rdf.model.Resource;
import org.apache.jena.vocabulary.OWL2;
import org.apache.jena.vocabulary.RDF;
import fr.emse.gitlab.saref.SAREF;
import fr.emse.gitlab.saref.SAREFPipelineException;
import fr.emse.gitlab.saref.entities.SAREFProject;
import fr.emse.gitlab.saref.entities.SAREFRepository;
import fr.emse.gitlab.saref.entities.SAREFTerm;
import fr.emse.gitlab.saref.managers.RepositoryManager;
......@@ -55,15 +50,13 @@ public class Clause_9_4_4_1_Checker extends AbstractClauseChecker {
private static final Pattern PATTERN_MIXED_CASE = Pattern.compile("^[a-z0-9][a-zA-Z0-9]+$");
private static enum MESSAGE {
no_project, no_repository_manager, pattern, classs, namedindividual, objectproperty, datatypeproperty
pattern, classs, namedindividual, objectproperty, datatypeproperty
}
public Clause_9_4_4_1_Checker(RepositoryManager repositoryManager) {
super(repositoryManager, Clause_9_4_4_1_Checker.class);
}
private final Set<Resource> noProject = new HashSet<>();
private final Map<SAREFProject,Set<Resource>> noRepositoryManager = new HashMap<>();
private final Set<Resource> termsBadPattern = new HashSet<>();
private final Set<Resource> classesBadCase = new HashSet<>();
private final Set<Resource> namedIndividualsBadCase = new HashSet<>();
......@@ -74,21 +67,6 @@ public class Clause_9_4_4_1_Checker extends AbstractClauseChecker {
@Override
public void checkClause() throws SAREFPipelineException {
computeTerms();
if (!noProject.isEmpty()) {
logWarning(getMessage(MESSAGE.no_project,
noProject.stream().map(Object::toString).collect(Collectors.joining(", "))));
}
if (!noRepositoryManager.isEmpty()) {
for(SAREFProject project: noRepositoryManager.keySet()) {
logWarning(getMessage(MESSAGE.no_repository_manager,
project, project,
noRepositoryManager.get(project).stream().map(Object::toString).collect(Collectors.joining(", "))));
}
}
Model model = version.getModel();
for (SAREFTerm term : version.getDefinedTerms()) {
String localName = term.getLocalName();
......@@ -130,54 +108,4 @@ public class Clause_9_4_4_1_Checker extends AbstractClauseChecker {
}
}
private void computeTerms() {
version.getModel().listStatements().forEachRemaining(stmt -> {
Resource s = stmt.getSubject();
Resource p = stmt.getPredicate();
Resource o = stmt.getObject().isResource() ? (Resource) stmt.getObject() : null;
computeTerms(s);
computeTerms(p);
computeTerms(o);
});
}
private void computeTerms(Resource t) {
if (t == null || !t.isURIResource()) {
return;
}
String iri = t.getURI();
if(!iri.startsWith(SAREF.BASE) || iri.endsWith("/") || iri.endsWith("#")) {
return;
}
SAREFProject project = sourcesManager.getProject(iri);
if(project == null) {
noProject.add(t);
return;
}
RepositoryManager otherRepositoryManager = sourcesManager.findRepositoryManager(project);
if(otherRepositoryManager == null) {
Set<Resource> terms = noRepositoryManager.get(project);
if(terms == null) {
terms = new HashSet<>();
noRepositoryManager.put(project, terms);
}
terms.add(t);
return;
}
SAREFRepository otherRepository = otherRepositoryManager.getRepository();
SAREFTerm term = otherRepository.getTerms().get(iri);
if (term == null) {
term = new SAREFTerm(otherRepository, iri);
otherRepository.getTerms().put(iri, term);
}
if(this.project.equals(project)) {
version.definesTerm(term);
term.isDefinedBy(version);
} else {
version.usesTerm(term);
term.isUsedBy(version);
}
}
}
\ No newline at end of file
......@@ -26,22 +26,12 @@
package fr.emse.gitlab.saref.checkers;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.nio.charset.MalformedInputException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.PathMatcher;
import java.util.stream.Collectors;
import org.apache.jena.atlas.RuntimeIOException;
import org.apache.jena.riot.Lang;
import fr.emse.gitlab.saref.SAREF;
import fr.emse.gitlab.saref.SAREFPipelineException;
import fr.emse.gitlab.saref.entities.SAREFExample;
import fr.emse.gitlab.saref.managers.RepositoryManager;
/**
......@@ -50,8 +40,6 @@ import fr.emse.gitlab.saref.managers.RepositoryManager;
*/
public class Clause_9_6_1_Checker extends AbstractClauseChecker {
private static final PathMatcher TTL_MATCHER = FileSystems.getDefault().getPathMatcher("glob:**/*.ttl");
private static enum MESSAGE {
directories, one, ttl, turtle, write_error;
}
......@@ -84,7 +72,7 @@ public class Clause_9_6_1_Checker extends AbstractClauseChecker {
String nonTtl = Files.walk(dir.toPath(), 1).filter(p -> {
try {
return p.toFile().isFile() && !TTL_MATCHER.matches(p) && !p.toFile().getName().startsWith(".");
return p.toFile().isFile() && !SAREF.TTL_MATCHER.matches(p) && !p.toFile().getName().startsWith(".");
} catch (Exception ex) {
return false;
}
......@@ -93,31 +81,6 @@ public class Clause_9_6_1_Checker extends AbstractClauseChecker {
logError(getMessage(MESSAGE.ttl, nonTtl));
}
Files.walk(dir.toPath(), 1).filter(p -> {
return TTL_MATCHER.matches(p);
}).forEach(p -> {
SAREFExample example = new SAREFExample(version, p);
try (FileInputStream input = new FileInputStream(p.toFile())) {
example.getModel().read(input, SAREF.BASE, Lang.TTL.getLabel());
} catch (Exception ex) {
if (ex instanceof RuntimeIOException && ex.getCause() instanceof MalformedInputException) {
example.getModel().removeAll();
try (InputStreamReader input2 = new InputStreamReader(new FileInputStream(p.toFile()),
Charset.defaultCharset())) {
example.getModel().read(input2, SAREF.BASE, Lang.TTL.getLabel());
} catch (Exception ex2) {
String msg = getMessage(MESSAGE.turtle);
logError(msg, ex2);
return;
}
} else {
String msg = getMessage(MESSAGE.turtle);
logError(msg, ex);
return;
}
}
version.getExamples().put(example.getName(), example);
});
} catch (IOException ex) {
throw new SAREFPipelineException(ex);
}
......
......@@ -30,6 +30,7 @@ import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import fr.emse.gitlab.saref.SAREF;
import fr.emse.gitlab.saref.SAREFPipelineException;
import fr.emse.gitlab.saref.entities.SAREFExample;
import fr.emse.gitlab.saref.entities.SAREFExtension;
......@@ -43,7 +44,7 @@ import fr.emse.gitlab.saref.managers.RepositoryManager;
*/
public class Clause_9_6_2_Checker extends AbstractClauseChecker {
private final static Pattern PATTERN_PREFIX = Pattern.compile(SAREFProject.REGEX_EXTENSION_PREFIX);
private final static Pattern PATTERN_PREFIX = Pattern.compile(SAREF.REGEX_EXTENSION_PREFIX);
private static final Map<String, String> PREFIXES = new HashMap<String, String>();
static {
......@@ -86,7 +87,7 @@ public class Clause_9_6_2_Checker extends AbstractClauseChecker {
for (String s : prefixes.keySet()) {
Matcher m = PATTERN_PREFIX.matcher(s);
if (m.matches()) {
String acronym = m.group(SAREFProject.REGEX_ACRONYM_VAR);
String acronym = m.group(SAREF.REGEX_ACRONYM_VAR);
String expected = new SAREFExtension(acronym).getNamespace();
if (!prefixes.get(s).equals(expected)) {
logError(getMessage(MESSAGE.different, s, expected, prefixes.get(s)));
......@@ -109,7 +110,7 @@ public class Clause_9_6_2_Checker extends AbstractClauseChecker {
logError(getMessage(MESSAGE.namespace, example.getNamespace(), exNamespace));
}
} else {
String regex = "^" + example.getNamespace().replace(versionName.toString(), SAREFVersionName.REGEX_VERSION_NUMBER) + "$";
String regex = "^" + example.getNamespace().replace(versionName.toString(), SAREF.REGEX_VERSION_NUMBER) + "$";
if(!Pattern.matches(regex, exNamespace)) {
String ver = example.getNamespace().replace(versionName.toString(), "<<some version>>");
logError(getMessage(MESSAGE.namespace, ver, exNamespace));
......
......@@ -61,7 +61,7 @@ public class Clause_9_6_3_Checker extends AbstractShaclChecker {
@Override
protected Model getModel() {
Model model = example.getModel();
final String regex = "^" + example.getIRI().replace("v0.0.1", SAREFVersionName.REGEX_VERSION_NUMBER) + "$";
final String regex = "^" + example.getIRI().replace("v0.0.1", SAREF.REGEX_VERSION_NUMBER) + "$";
int onto = 0;
boolean found = false;
......
......@@ -25,8 +25,20 @@
*/
package fr.emse.gitlab.saref.checkers;
import java.util.Set;
import java.util.stream.Collectors;
import org.semanticweb.owl.explanation.api.Explanation;
import org.semanticweb.owl.explanation.api.ExplanationGenerator;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.parameters.Imports;
import org.semanticweb.owlapi.profiles.OWL2DLProfile;
import org.semanticweb.owlapi.profiles.OWLProfileReport;
import fr.emse.gitlab.saref.SAREFPipelineException;
import fr.emse.gitlab.saref.entities.SAREFExample;
import fr.emse.gitlab.saref.managers.OntologyManager;
import fr.emse.gitlab.saref.managers.RepositoryManager;
/**
......@@ -48,36 +60,42 @@ public class Clause_9_6_4_Checker extends AbstractClauseChecker {
@Override
public void checkClause() throws SAREFPipelineException {
final OWLOntology ontology = pipeline.getOntologyManager().loadOntology(example, errorLogger);
if (ontology == null) {
return;
}
final OWLProfileReport report = new OWL2DLProfile().checkOntology(ontology);
if(!report.getViolations().isEmpty()) {
String violations = report.getViolations().stream().map(Object::toString)
.collect(Collectors.joining("\n- ", "\n\n- ", "\n\n"));
logError(getMessage(MESSAGE.profile, violations));
}
// TODO
// final OWLOntology ontology = ontologyManager.loadOntology(version, errorLogger);
// if (ontology == null) {
// return;
// }
//
// final OWLProfileReport report = new OWL2DLProfile().checkOntology(ontology);
// String violations = report.getViolations().stream().map(Object::toString)
// .collect(Collectors.joining("\n\n- ", "\n- ", "\n\n"));
// log(getMessage(MESSAGE.profile, violations), Mode.RELEASE, Mode.PORTAL);
//
// Set<Explanation<OWLAxiom>> incExplanation = ontologyManager.getInconsistenceExplanations(ontology, errorLogger);
// if (incExplanation != null && !incExplanation.isEmpty()) {
// String explanation = incExplanation.stream().map(e -> e.getAxioms().toString())
// .collect(Collectors.joining("\n\n- ", "\n- ", "\n\n"));
// log(getMessage(MESSAGE.consistent, explanation), Mode.RELEASE, Mode.PORTAL);
// }
//
// ExplanationGenerator<OWLAxiom> generator = ontologyManager.getExplanationGenerator(ontology);
// ontology.classesInSignature().forEach(c -> {
// Set<Explanation<OWLAxiom>> incExplanation2 = ontologyManager.getIncoherenceExplanations(generator, c);
// if (!incExplanation.isEmpty()) {
// String explanation = incExplanation2.stream().map(e -> e.getAxioms().toString())
// .collect(Collectors.joining("\n\n- ", "\n- ", "\n\n"));
// log(getMessage(MESSAGE.satisfiable, c, explanation), Mode.RELEASE, Mode.PORTAL);
//
// }
// });
OntologyManager ontologyManager = pipeline.getOntologyManager();
Set<Explanation<OWLAxiom>> incExplanation = ontologyManager.getInconsistenceExplanations(ontology, errorLogger);
if (incExplanation != null && !incExplanation.isEmpty()) {
String explanation = incExplanation.stream().map(e -> e.getAxioms().toString())
.collect(Collectors.joining("\n- ", "\n\n- ", "\n\n"));
logError(getMessage(MESSAGE.consistent, explanation));
} else {
ExplanationGenerator<OWLAxiom> generator = ontologyManager.getExplanationGenerator(ontology);
ontology.classesInSignature(Imports.INCLUDED).forEach(c -> {
if(c.isOWLNothing()) {
return;
}
Set<Explanation<OWLAxiom>> incExplanation2 = ontologyManager.getIncoherenceExplanations(generator, c);
if (!incExplanation2.isEmpty()) {
String explanation = incExplanation2.stream().map(e -> e.getAxioms().toString())
.collect(Collectors.joining("\n- ", "\n\n- ", "\n\n"));
logError(getMessage(MESSAGE.satisfiable, c, explanation));
}
});
}
}
}
......@@ -10,31 +10,72 @@ import fr.emse.gitlab.saref.SAREFPipelineException;
import fr.emse.gitlab.saref.SAREFRepositoryErrorLogger;
import fr.emse.gitlab.saref.entities.SAREFRepository;
import fr.emse.gitlab.saref.entities.SAREFTerm;
import fr.emse.gitlab.saref.entities.SAREFVersion;
public class TermsChecker extends SAREFRepositoryErrorLogger {
private static final String TERMS = "terms";
public TermsChecker(SAREFPipeline pipeline, SAREFRepository repository) {
super(pipeline, repository, pipeline.getLogger(SAREF.getMessage(TERMS)));
super(pipeline, repository, pipeline.getLogger(SAREF.getMessage(TERMS, repository.getProject())));
}
private static enum MESSAGE {
not_defined
used_not_defined, defined_not_exemplified, exemplified_not_defined
}
public void check() throws SAREFPipelineException {
final Set<SAREFTerm> notDefined = new HashSet<>();
for (SAREFVersion version : repository.getVersions().values()) {
checkUsedNotDefined(version);
checkLocalExemplifiedNotDefined(version);
checkSourceExemplifiedNotDefined(version);
checkDefinedNotExemplified(version);
}
}
private void checkUsedNotDefined(SAREFVersion version) {
String msg = version.getUsedTerms().stream().filter(term -> !term.isDefined()).map(SAREFTerm::getPrefixedName)
.collect(Collectors.joining("\n"));
if (!msg.isEmpty()) {
logWarning(getMessage(MESSAGE.used_not_defined, project.getName(), version.getVersionName(), msg));
}
}
for (SAREFTerm term : repository.getTerms().values()) {
if (term.getIsDefinedBy().isEmpty() && !term.getIsUsedBy().isEmpty()) {
notDefined.add(term);
}
private void checkLocalExemplifiedNotDefined(SAREFVersion version) {
Set<SAREFTerm> localExemplifiedNotDefined = new HashSet<>();
version.getExamples().values().forEach(example -> {
example.getExemplifiedTerms().stream()
.filter(term -> term.getRepository().equals(repository)
&& !term.getIsDefinedBy().stream().anyMatch(v -> v.equals(version)))
.forEach(localExemplifiedNotDefined::add);
});
if (!localExemplifiedNotDefined.isEmpty()) {
String msg = localExemplifiedNotDefined.stream().map(SAREFTerm::getPrefixedName)
.collect(Collectors.joining(", "));
logError(getMessage(MESSAGE.exemplified_not_defined, project.getName(), version.getVersionName(), msg));
}
}
private void checkSourceExemplifiedNotDefined(SAREFVersion version) {
Set<SAREFTerm> localSourceNotDefined = new HashSet<>();
version.getExamples().values().forEach(example -> {
example.getExemplifiedTerms().stream()
.filter(term -> !term.getRepository().equals(repository) && !term.isDefined())
.forEach(localSourceNotDefined::add);
});
if (!localSourceNotDefined.isEmpty()) {
String msg = localSourceNotDefined.stream().map(SAREFTerm::getPrefixedName)
.collect(Collectors.joining(", "));
logWarning(getMessage(MESSAGE.exemplified_not_defined, project.getName(), version.getVersionName(), msg));
}
}
if (!notDefined.isEmpty()) {
logWarning(getMessage(MESSAGE.not_defined,
notDefined.stream().map(Object::toString).collect(Collectors.joining(", "))));
private void checkDefinedNotExemplified(SAREFVersion version) {
String msg = version.getDefinedTerms().stream().filter(
term -> !term.getIsExemplifiedBy().stream().anyMatch(example -> example.getVersion().equals(version)))
.map(SAREFTerm::getPrefixedName).collect(Collectors.joining(", "));
if (!msg.isEmpty()) {
logWarning(getMessage(MESSAGE.defined_not_exemplified, project.getName(), version.getVersionName(), msg));
}
}
......
......@@ -25,6 +25,8 @@
*/
package fr.emse.gitlab.saref.entities;
import fr.emse.gitlab.saref.SAREF;
public class SAREFAcronym {
private final String acronym;
......@@ -33,7 +35,7 @@ public class SAREFAcronym {
if(acronym == null) {
throw new NullPointerException();
}
if(!acronym.matches(SAREFProject.REGEX_ACRONYM)) {