Merge branch 'master' of code-repo.d4science.org:MaDgIK/validator-engine
This commit is contained in:
commit
5abdc97c1c
|
@ -36,4 +36,11 @@ public class Reporter<T, R extends Rule<T>> {
|
||||||
logger.error("Failed to report error of applying " + rule + " to value: " + t, throwable);
|
logger.error("Failed to report error of applying " + rule + " to value: " + t, throwable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Reporter{" +
|
||||||
|
"diagnostics=" + diagnostics +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,9 +39,11 @@ public class XPathExpressionHelper {
|
||||||
public static XPathExpression compile(String xpath) {
|
public static XPathExpression compile(String xpath) {
|
||||||
return COMPILED_EXPRESSIONS.computeIfAbsent(xpath, s -> {
|
return COMPILED_EXPRESSIONS.computeIfAbsent(xpath, s -> {
|
||||||
try {
|
try {
|
||||||
logger.debug("Compiling {}", s);
|
if ( logger.isTraceEnabled() )
|
||||||
|
logger.trace("Compiling {}", s);
|
||||||
XPathExpression expr = XPATH.compile(s);
|
XPathExpression expr = XPATH.compile(s);
|
||||||
logger.debug("Compiled {} = {}", s, expr);
|
if ( logger.isTraceEnabled() )
|
||||||
|
logger.trace("Compiled {} = {}", s, expr);
|
||||||
return expr;
|
return expr;
|
||||||
} catch (XPathExpressionException e) {
|
} catch (XPathExpressionException e) {
|
||||||
logger.error("Compilation failure", e);
|
logger.error("Compilation failure", e);
|
||||||
|
|
|
@ -324,20 +324,20 @@ class ElementSpecCompiler {
|
||||||
private String xpath(boolean withText) {
|
private String xpath(boolean withText) {
|
||||||
String xpathForThis = xpathForNodeName(spec.nodeName(), spec.valuePrefix());
|
String xpathForThis = xpathForNodeName(spec.nodeName(), spec.valuePrefix());
|
||||||
String xpath;
|
String xpath;
|
||||||
if (parent == null) {
|
if ( parent == null ) {
|
||||||
// This is the top-level element rule
|
// This is the top-level element rule
|
||||||
List<String> pathComponents = spec.parents().stream().
|
List<String> pathComponents = spec.parents().stream().
|
||||||
map( s -> "*[" + xpathForNodeName(s) + "]").collect(Collectors.toList());
|
map( s -> "*[" + xpathForNodeName(s) + "]").collect(Collectors.toList());
|
||||||
pathComponents.add("*[" + xpathForThis + "]");
|
pathComponents.add("*[" + xpathForThis + "]");
|
||||||
xpath = "//" + String.join("/", pathComponents);
|
xpath = "//" + String.join("/", pathComponents);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
xpath = parent.xpath(false) + "/*[" + xpathForThis + "]";
|
xpath = parent.xpath(false) + "/*[" + xpathForThis + "]";
|
||||||
}
|
}
|
||||||
if (spec.position().xpath != null) {
|
if ( spec.position().xpath != null ) {
|
||||||
xpath = "(" + xpath + ")[" + spec.position().xpath + "]";
|
xpath = "(" + xpath + ")[" + spec.position().xpath + "]";
|
||||||
}
|
}
|
||||||
logger.debug(xpath);
|
if ( logger.isTraceEnabled() )
|
||||||
|
logger.trace(xpath);
|
||||||
return xpathWithText(xpath, withText);
|
return xpathWithText(xpath, withText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -135,6 +135,21 @@ class GuidelineEvaluation {
|
||||||
return ruleIdToRequirementLevel.get(ruleId);
|
return ruleIdToRequirementLevel.get(ruleId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "GuidelineEvaluation{" +
|
||||||
|
"subjectId='" + subjectId + '\'' +
|
||||||
|
", doc=" + doc +
|
||||||
|
", weight=" + weight +
|
||||||
|
", warnings=" + warnings +
|
||||||
|
", errors=" + errors +
|
||||||
|
", ruleIdToRequirementLevel=" + ruleIdToRequirementLevel +
|
||||||
|
", ruleIdToNodeList=" + ruleIdToNodeList +
|
||||||
|
", diagnostics=" + diagnostics +
|
||||||
|
", reporter=" + reporter +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private static final class Diagnostics extends StandardRuleDiagnostics<Document, SyntheticRule<Document>> {
|
private static final class Diagnostics extends StandardRuleDiagnostics<Document, SyntheticRule<Document>> {
|
||||||
|
|
||||||
|
@ -164,5 +179,12 @@ class GuidelineEvaluation {
|
||||||
private Status statusFor(String ruleId) {
|
private Status statusFor(String ruleId) {
|
||||||
return statusByRuleId.get(ruleId);
|
return statusByRuleId.get(ruleId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Diagnostics{" +
|
||||||
|
"statusByRuleId=" + statusByRuleId +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,13 +32,11 @@ public final class SyntheticGuideline extends AbstractGuideline<Document> {
|
||||||
String canonical = Helper.ensureNonEmpty(name, () -> new IllegalArgumentException("Name cannot be empty"));
|
String canonical = Helper.ensureNonEmpty(name, () -> new IllegalArgumentException("Name cannot be empty"));
|
||||||
|
|
||||||
// Here we define a guideline with a specific elementSpec as origin, we cannot allow null
|
// Here we define a guideline with a specific elementSpec as origin, we cannot allow null
|
||||||
if (elementSpec == null) {
|
if ( elementSpec == null )
|
||||||
throw new IllegalArgumentException("ElementSpec cannot be empty");
|
throw new IllegalArgumentException("ElementSpec cannot be empty");
|
||||||
}
|
|
||||||
|
|
||||||
if (weight < 0) {
|
if ( weight < 0 )
|
||||||
throw new IllegalArgumentException("Weight cannot be negative");
|
throw new IllegalArgumentException("Weight cannot be negative");
|
||||||
}
|
|
||||||
|
|
||||||
SyntheticGuideline guideline = new SyntheticGuideline(canonical, weight);
|
SyntheticGuideline guideline = new SyntheticGuideline(canonical, weight);
|
||||||
guideline.compilationResult = new ElementSpecCompiler().compile(elementSpec, evaluation::get);
|
guideline.compilationResult = new ElementSpecCompiler().compile(elementSpec, evaluation::get);
|
||||||
|
@ -49,17 +47,14 @@ public final class SyntheticGuideline extends AbstractGuideline<Document> {
|
||||||
public static SyntheticGuideline of(String name, int weight, RequirementLevel requirementLevel, Rule<Document> rule) {
|
public static SyntheticGuideline of(String name, int weight, RequirementLevel requirementLevel, Rule<Document> rule) {
|
||||||
String canonical = Helper.ensureNonEmpty(name, () -> new IllegalArgumentException("Name cannot be empty"));
|
String canonical = Helper.ensureNonEmpty(name, () -> new IllegalArgumentException("Name cannot be empty"));
|
||||||
|
|
||||||
if (weight < 0) {
|
if ( weight < 0 )
|
||||||
throw new IllegalArgumentException("Weight cannot be negative");
|
throw new IllegalArgumentException("Weight cannot be negative");
|
||||||
}
|
|
||||||
|
|
||||||
if (requirementLevel == null) {
|
if ( requirementLevel == null )
|
||||||
throw new IllegalArgumentException("Requirement level cannot be empty");
|
throw new IllegalArgumentException("Requirement level cannot be empty");
|
||||||
}
|
|
||||||
|
|
||||||
if (rule == null) {
|
if ( rule == null )
|
||||||
throw new IllegalArgumentException("Rule cannot be empty");
|
throw new IllegalArgumentException("Rule cannot be empty");
|
||||||
}
|
|
||||||
|
|
||||||
SyntheticGuideline guideline = new SyntheticGuideline(canonical, weight);
|
SyntheticGuideline guideline = new SyntheticGuideline(canonical, weight);
|
||||||
CompilationResult compilationResult = new CompilationResult();
|
CompilationResult compilationResult = new CompilationResult();
|
||||||
|
|
|
@ -41,13 +41,17 @@ public abstract class AbstractOpenAireProfile implements XMLApplicationProfile {
|
||||||
double score = 0;
|
double score = 0;
|
||||||
final Map<String, Guideline.Result> results = new HashMap<>();
|
final Map<String, Guideline.Result> results = new HashMap<>();
|
||||||
|
|
||||||
for (Guideline<Document> guideline: guidelines()) {
|
// Validate the document against all guideline-elements.
|
||||||
|
for ( Guideline<Document> guidelineElement : guidelines() )
|
||||||
Guideline.Result result = guideline.validate(document);
|
{
|
||||||
results.put(guideline.getName(), result);
|
String guidelineElementName = guidelineElement.getName();
|
||||||
|
if ( logger.isTraceEnabled() )
|
||||||
|
logger.trace("Evaluating guideline-element: " + guidelineElementName);
|
||||||
|
Guideline.Result result = guidelineElement.validate(document);
|
||||||
|
results.put(guidelineElementName, result);
|
||||||
|
|
||||||
score += (result.status() == Status.SUCCESS ? result.score() : 0);
|
score += (result.status() == Status.SUCCESS ? result.score() : 0);
|
||||||
logger.debug("Score after " + guideline.getName() + " = " + score);
|
logger.debug("Score after validating \"" + guidelineElementName + "\" = " + score);
|
||||||
}
|
}
|
||||||
|
|
||||||
double percentScore = (score / maxScore) * 100;
|
double percentScore = (score / maxScore) * 100;
|
||||||
|
@ -75,10 +79,10 @@ public abstract class AbstractOpenAireProfile implements XMLApplicationProfile {
|
||||||
// The nodes contain all the elementName nodes
|
// The nodes contain all the elementName nodes
|
||||||
int len = nodes.getLength();
|
int len = nodes.getLength();
|
||||||
if (len == 0) { return false; } // element is not present
|
if (len == 0) { return false; } // element is not present
|
||||||
for(int i = 0; i < len; i++) {
|
for ( int i = 0; i < len; i++ ) {
|
||||||
Node elem = nodes.item(i);
|
Node elem = nodes.item(i);
|
||||||
String value = Helper.getAttributeValue(elem, attrName);
|
String value = Helper.getAttributeValue(elem, attrName);
|
||||||
if (!attrValue.equals(value)) { return false; }
|
if ( !attrValue.equals(value) ) { return false; }
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package eu.dnetlib.validator2.engine
|
package eu.dnetlib.validator2.engine
|
||||||
|
|
||||||
|
import eu.dnetlib.validator2.engine.Helper
|
||||||
import groovy.xml.DOMBuilder
|
import groovy.xml.DOMBuilder
|
||||||
import groovy.xml.FactorySupport
|
import groovy.xml.FactorySupport
|
||||||
import org.w3c.dom.Document
|
import org.w3c.dom.Document
|
||||||
|
|
|
@ -29,18 +29,17 @@ public class Test {
|
||||||
LiteratureGuidelinesV3Profile profile = new LiteratureGuidelinesV3Profile();
|
LiteratureGuidelinesV3Profile profile = new LiteratureGuidelinesV3Profile();
|
||||||
logger.info("Max score: " + profile.maxScore());
|
logger.info("Max score: " + profile.maxScore());
|
||||||
Map<String, Double> scorePerDoc = new LinkedHashMap<>();
|
Map<String, Double> scorePerDoc = new LinkedHashMap<>();
|
||||||
for (String file: FILES) {
|
for ( String fileName : FILES ) {
|
||||||
try {
|
try {
|
||||||
logger.info("Processing \"" + file + "\"");
|
logger.info("Processing \"" + fileName + "\"");
|
||||||
Document doc = DOMBuilder.parse(new FileReader(file), false, true, true);
|
Document doc = DOMBuilder.parse(new FileReader(fileName), false, true, true);
|
||||||
XMLApplicationProfile.ValidationResult result = profile.validate(file, doc);
|
XMLApplicationProfile.ValidationResult result = profile.validate(fileName, doc);
|
||||||
scorePerDoc.put(file, result.score());
|
scorePerDoc.put(fileName, result.score());
|
||||||
Map<String, Guideline.Result> results = result.results();
|
Map<String, Guideline.Result> results = result.results();
|
||||||
for (Map.Entry entry : results.entrySet()) {
|
for ( Map.Entry<String, Guideline.Result> entry : results.entrySet() ) {
|
||||||
logger.info(entry.getKey() + " = " + entry.getValue());
|
logger.info(entry.getKey() + " = " + entry.getValue());
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch(Exception e) {
|
|
||||||
logger.error("", e);
|
logger.error("", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,17 +33,16 @@ public class Test_FAIR {
|
||||||
FAIR_Data_GuidelinesProfile profile = new FAIR_Data_GuidelinesProfile();
|
FAIR_Data_GuidelinesProfile profile = new FAIR_Data_GuidelinesProfile();
|
||||||
logger.info("Max score: " + profile.maxScore());
|
logger.info("Max score: " + profile.maxScore());
|
||||||
Map<String, Double> scorePerDoc = new LinkedHashMap<>();
|
Map<String, Double> scorePerDoc = new LinkedHashMap<>();
|
||||||
int i = 1;
|
for ( String fileName : FILES ) {
|
||||||
for (String file : FILES) {
|
|
||||||
try {
|
try {
|
||||||
logger.info("Processing \"" + file + "\"");
|
logger.info("Processing \"" + fileName + "\"");
|
||||||
Document doc = DOMBuilder.parse(new FileReader(file), false, true, true);
|
Document doc = DOMBuilder.parse(new FileReader(fileName), false, true, true);
|
||||||
XMLApplicationProfile.ValidationResult result = profile.validate(file, doc);
|
XMLApplicationProfile.ValidationResult result = profile.validate(fileName, doc);
|
||||||
scorePerDoc.put(file, result.score());
|
scorePerDoc.put(fileName, result.score());
|
||||||
Map<String, Guideline.Result> results = result.results();
|
Map<String, Guideline.Result> results = result.results();
|
||||||
|
|
||||||
if ( logger.isDebugEnabled() ) {
|
if ( logger.isDebugEnabled() ) {
|
||||||
for ( Map.Entry entry : results.entrySet() ) {
|
for ( Map.Entry<String, Guideline.Result> entry : results.entrySet() ) {
|
||||||
logger.debug(entry.getKey() + " = " + entry.getValue());
|
logger.debug(entry.getKey() + " = " + entry.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,16 +51,17 @@ public class Test_FAIR {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Individual scores
|
// Individual scores
|
||||||
String printout = scorePerDoc.entrySet().stream().
|
String printout = scorePerDoc.entrySet().stream().
|
||||||
map(entry -> entry.getValue() + ": " + entry.getKey()).collect(Collectors.joining("\n"));
|
map(entry -> entry.getValue() + ": " + entry.getKey()).collect(Collectors.joining("\n"));
|
||||||
|
|
||||||
// Average Score
|
logger.info(printout);
|
||||||
|
|
||||||
|
// Average Score
|
||||||
OptionalDouble optionalFinalScore = scorePerDoc.values().stream().mapToDouble(aDouble -> aDouble).average();
|
OptionalDouble optionalFinalScore = scorePerDoc.values().stream().mapToDouble(aDouble -> aDouble).average();
|
||||||
double finalScore = (optionalFinalScore.isPresent() ? optionalFinalScore.getAsDouble() : -1 );
|
double finalScore = (optionalFinalScore.isPresent() ? optionalFinalScore.getAsDouble() : -1 );
|
||||||
|
|
||||||
logger.info(printout);
|
logger.info("Validation Score: " + finalScore);
|
||||||
logger.info("\nValidation Score: " + finalScore);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,37 +31,40 @@ public class Test_v4 {
|
||||||
AbstractOpenAireProfile profile = new LiteratureGuidelinesV4Profile();
|
AbstractOpenAireProfile profile = new LiteratureGuidelinesV4Profile();
|
||||||
logger.info("Max score: " + profile.maxScore());
|
logger.info("Max score: " + profile.maxScore());
|
||||||
Map<String, Double> scorePerDoc = new LinkedHashMap<>();
|
Map<String, Double> scorePerDoc = new LinkedHashMap<>();
|
||||||
for (String file: FILES) {
|
for ( String fileName : FILES ) {
|
||||||
try {
|
try {
|
||||||
logger.info("Processing \"" + file + "\"");
|
logger.info("Processing \"" + fileName + "\"");
|
||||||
Document doc = DOMBuilder.parse(new FileReader(file), false, true, true);
|
Document doc = DOMBuilder.parse(new FileReader(fileName), false, true, true);
|
||||||
XMLApplicationProfile.ValidationResult result = profile.validate(file, doc);
|
XMLApplicationProfile.ValidationResult result = profile.validate(fileName, doc);
|
||||||
scorePerDoc.put(file, result.score());
|
scorePerDoc.put(fileName, result.score());
|
||||||
Map<String, Guideline.Result> results = result.results();
|
Map<String, Guideline.Result> results = result.results();
|
||||||
for (Map.Entry entry : results.entrySet()) {
|
for ( Map.Entry<String, Guideline.Result> entry : results.entrySet() ) {
|
||||||
if (entry.getKey().toString().contains("Date")) {
|
String key = entry.getKey();
|
||||||
logger.info("Warnings: " + results.get(entry.getKey()).warnings().toString());
|
Guideline.Result value = entry.getValue();
|
||||||
logger.info("Errors: " + results.get(entry.getKey()).errors().toString());
|
logger.debug(key + " = " + value);
|
||||||
logger.info("Result: " + entry.getKey() + " = " + entry.getValue() + "\n");
|
if ( key.contains("Date")) {
|
||||||
}
|
logger.info("Warnings: " + results.get(key).warnings().toString());
|
||||||
logger.debug(entry.getKey() + " = " + entry.getValue());
|
logger.info("Errors: " + results.get(key).errors().toString());
|
||||||
|
logger.info("Result: " + key + " = " + value + "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error(e.getMessage());
|
logger.error(e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Individual scores
|
|
||||||
|
// Individual scores
|
||||||
String printout = scorePerDoc.entrySet().stream().
|
String printout = scorePerDoc.entrySet().stream().
|
||||||
map(entry -> entry.getValue() + ": " + entry.getKey()).collect(Collectors.joining("\n"));
|
map(entry -> entry.getValue() + ": " + entry.getKey()).collect(Collectors.joining("\n"));
|
||||||
|
|
||||||
|
logger.info(printout);
|
||||||
|
|
||||||
// Average Score
|
// Average Score
|
||||||
OptionalDouble optionalFinalScore = scorePerDoc.values().stream().mapToDouble(aDouble -> aDouble).average();
|
OptionalDouble optionalFinalScore = scorePerDoc.values().stream().mapToDouble(aDouble -> aDouble).average();
|
||||||
double finalScore = (optionalFinalScore.isPresent() ? optionalFinalScore.getAsDouble() : -1 );
|
double finalScore = (optionalFinalScore.isPresent() ? optionalFinalScore.getAsDouble() : -1 );
|
||||||
|
|
||||||
logger.info(printout);
|
logger.info("Validation Score: " + finalScore);
|
||||||
logger.info("\nValidation Score: " + finalScore);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
<appender-ref ref="Console" />
|
<appender-ref ref="Console" />
|
||||||
</root>
|
</root>
|
||||||
|
|
||||||
<logger name="eu.dnetlib.validator2" level="trace"/>
|
<logger name="eu.dnetlib.validator2" level="debug"/>
|
||||||
|
|
||||||
<!-- </Loggers>-->
|
<!-- </Loggers>-->
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue