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);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Reporter{" +
|
||||
"diagnostics=" + diagnostics +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,9 +39,11 @@ public class XPathExpressionHelper {
|
|||
public static XPathExpression compile(String xpath) {
|
||||
return COMPILED_EXPRESSIONS.computeIfAbsent(xpath, s -> {
|
||||
try {
|
||||
logger.debug("Compiling {}", s);
|
||||
if ( logger.isTraceEnabled() )
|
||||
logger.trace("Compiling {}", s);
|
||||
XPathExpression expr = XPATH.compile(s);
|
||||
logger.debug("Compiled {} = {}", s, expr);
|
||||
if ( logger.isTraceEnabled() )
|
||||
logger.trace("Compiled {} = {}", s, expr);
|
||||
return expr;
|
||||
} catch (XPathExpressionException e) {
|
||||
logger.error("Compilation failure", e);
|
||||
|
|
|
@ -324,20 +324,20 @@ class ElementSpecCompiler {
|
|||
private String xpath(boolean withText) {
|
||||
String xpathForThis = xpathForNodeName(spec.nodeName(), spec.valuePrefix());
|
||||
String xpath;
|
||||
if (parent == null) {
|
||||
if ( parent == null ) {
|
||||
// This is the top-level element rule
|
||||
List<String> pathComponents = spec.parents().stream().
|
||||
map( s -> "*[" + xpathForNodeName(s) + "]").collect(Collectors.toList());
|
||||
pathComponents.add("*[" + xpathForThis + "]");
|
||||
xpath = "//" + String.join("/", pathComponents);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
xpath = parent.xpath(false) + "/*[" + xpathForThis + "]";
|
||||
}
|
||||
if (spec.position().xpath != null) {
|
||||
if ( spec.position().xpath != null ) {
|
||||
xpath = "(" + xpath + ")[" + spec.position().xpath + "]";
|
||||
}
|
||||
logger.debug(xpath);
|
||||
if ( logger.isTraceEnabled() )
|
||||
logger.trace(xpath);
|
||||
return xpathWithText(xpath, withText);
|
||||
}
|
||||
|
||||
|
|
|
@ -135,6 +135,21 @@ class GuidelineEvaluation {
|
|||
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>> {
|
||||
|
||||
|
@ -164,5 +179,12 @@ class GuidelineEvaluation {
|
|||
private Status statusFor(String 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"));
|
||||
|
||||
// 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");
|
||||
}
|
||||
|
||||
if (weight < 0) {
|
||||
if ( weight < 0 )
|
||||
throw new IllegalArgumentException("Weight cannot be negative");
|
||||
}
|
||||
|
||||
SyntheticGuideline guideline = new SyntheticGuideline(canonical, weight);
|
||||
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) {
|
||||
String canonical = Helper.ensureNonEmpty(name, () -> new IllegalArgumentException("Name cannot be empty"));
|
||||
|
||||
if (weight < 0) {
|
||||
if ( weight < 0 )
|
||||
throw new IllegalArgumentException("Weight cannot be negative");
|
||||
}
|
||||
|
||||
if (requirementLevel == null) {
|
||||
if ( requirementLevel == null )
|
||||
throw new IllegalArgumentException("Requirement level cannot be empty");
|
||||
}
|
||||
|
||||
if (rule == null) {
|
||||
if ( rule == null )
|
||||
throw new IllegalArgumentException("Rule cannot be empty");
|
||||
}
|
||||
|
||||
SyntheticGuideline guideline = new SyntheticGuideline(canonical, weight);
|
||||
CompilationResult compilationResult = new CompilationResult();
|
||||
|
|
|
@ -38,16 +38,20 @@ public abstract class AbstractOpenAireProfile implements XMLApplicationProfile {
|
|||
@Override
|
||||
public ValidationResult validate(String id, Document document) {
|
||||
int maxScore = maxScore();
|
||||
double score = 0;
|
||||
final Map<String, Guideline.Result> results = new HashMap<>();
|
||||
double score = 0;
|
||||
final Map<String, Guideline.Result> results = new HashMap<>();
|
||||
|
||||
for (Guideline<Document> guideline: guidelines()) {
|
||||
|
||||
Guideline.Result result = guideline.validate(document);
|
||||
results.put(guideline.getName(), result);
|
||||
// Validate the document against all guideline-elements.
|
||||
for ( Guideline<Document> guidelineElement : guidelines() )
|
||||
{
|
||||
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);
|
||||
logger.debug("Score after " + guideline.getName() + " = " + score);
|
||||
logger.debug("Score after validating \"" + guidelineElementName + "\" = " + score);
|
||||
}
|
||||
|
||||
double percentScore = (score / maxScore) * 100;
|
||||
|
@ -75,10 +79,10 @@ public abstract class AbstractOpenAireProfile implements XMLApplicationProfile {
|
|||
// The nodes contain all the elementName nodes
|
||||
int len = nodes.getLength();
|
||||
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);
|
||||
String value = Helper.getAttributeValue(elem, attrName);
|
||||
if (!attrValue.equals(value)) { return false; }
|
||||
if ( !attrValue.equals(value) ) { return false; }
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package eu.dnetlib.validator2.engine
|
||||
|
||||
import eu.dnetlib.validator2.engine.Helper
|
||||
import groovy.xml.DOMBuilder
|
||||
import groovy.xml.FactorySupport
|
||||
import org.w3c.dom.Document
|
||||
|
|
|
@ -29,18 +29,17 @@ public class Test {
|
|||
LiteratureGuidelinesV3Profile profile = new LiteratureGuidelinesV3Profile();
|
||||
logger.info("Max score: " + profile.maxScore());
|
||||
Map<String, Double> scorePerDoc = new LinkedHashMap<>();
|
||||
for (String file: FILES) {
|
||||
for ( String fileName : FILES ) {
|
||||
try {
|
||||
logger.info("Processing \"" + file + "\"");
|
||||
Document doc = DOMBuilder.parse(new FileReader(file), false, true, true);
|
||||
XMLApplicationProfile.ValidationResult result = profile.validate(file, doc);
|
||||
scorePerDoc.put(file, result.score());
|
||||
logger.info("Processing \"" + fileName + "\"");
|
||||
Document doc = DOMBuilder.parse(new FileReader(fileName), false, true, true);
|
||||
XMLApplicationProfile.ValidationResult result = profile.validate(fileName, doc);
|
||||
scorePerDoc.put(fileName, result.score());
|
||||
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());
|
||||
}
|
||||
}
|
||||
catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
logger.error("", e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,17 +33,16 @@ public class Test_FAIR {
|
|||
FAIR_Data_GuidelinesProfile profile = new FAIR_Data_GuidelinesProfile();
|
||||
logger.info("Max score: " + profile.maxScore());
|
||||
Map<String, Double> scorePerDoc = new LinkedHashMap<>();
|
||||
int i = 1;
|
||||
for (String file : FILES) {
|
||||
for ( String fileName : FILES ) {
|
||||
try {
|
||||
logger.info("Processing \"" + file + "\"");
|
||||
Document doc = DOMBuilder.parse(new FileReader(file), false, true, true);
|
||||
XMLApplicationProfile.ValidationResult result = profile.validate(file, doc);
|
||||
scorePerDoc.put(file, result.score());
|
||||
logger.info("Processing \"" + fileName + "\"");
|
||||
Document doc = DOMBuilder.parse(new FileReader(fileName), false, true, true);
|
||||
XMLApplicationProfile.ValidationResult result = profile.validate(fileName, doc);
|
||||
scorePerDoc.put(fileName, result.score());
|
||||
Map<String, Guideline.Result> results = result.results();
|
||||
|
||||
if ( logger.isDebugEnabled() ) {
|
||||
for ( Map.Entry entry : results.entrySet() ) {
|
||||
for ( Map.Entry<String, Guideline.Result> entry : results.entrySet() ) {
|
||||
logger.debug(entry.getKey() + " = " + entry.getValue());
|
||||
}
|
||||
}
|
||||
|
@ -52,16 +51,17 @@ public class Test_FAIR {
|
|||
}
|
||||
}
|
||||
|
||||
// Individual scores
|
||||
// Individual scores
|
||||
String printout = scorePerDoc.entrySet().stream().
|
||||
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();
|
||||
double finalScore = (optionalFinalScore.isPresent() ? optionalFinalScore.getAsDouble() : -1 );
|
||||
|
||||
logger.info(printout);
|
||||
logger.info("\nValidation Score: " + finalScore);
|
||||
logger.info("Validation Score: " + finalScore);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,37 +31,40 @@ public class Test_v4 {
|
|||
AbstractOpenAireProfile profile = new LiteratureGuidelinesV4Profile();
|
||||
logger.info("Max score: " + profile.maxScore());
|
||||
Map<String, Double> scorePerDoc = new LinkedHashMap<>();
|
||||
for (String file: FILES) {
|
||||
for ( String fileName : FILES ) {
|
||||
try {
|
||||
logger.info("Processing \"" + file + "\"");
|
||||
Document doc = DOMBuilder.parse(new FileReader(file), false, true, true);
|
||||
XMLApplicationProfile.ValidationResult result = profile.validate(file, doc);
|
||||
scorePerDoc.put(file, result.score());
|
||||
logger.info("Processing \"" + fileName + "\"");
|
||||
Document doc = DOMBuilder.parse(new FileReader(fileName), false, true, true);
|
||||
XMLApplicationProfile.ValidationResult result = profile.validate(fileName, doc);
|
||||
scorePerDoc.put(fileName, result.score());
|
||||
Map<String, Guideline.Result> results = result.results();
|
||||
for (Map.Entry entry : results.entrySet()) {
|
||||
if (entry.getKey().toString().contains("Date")) {
|
||||
logger.info("Warnings: " + results.get(entry.getKey()).warnings().toString());
|
||||
logger.info("Errors: " + results.get(entry.getKey()).errors().toString());
|
||||
logger.info("Result: " + entry.getKey() + " = " + entry.getValue() + "\n");
|
||||
for ( Map.Entry<String, Guideline.Result> entry : results.entrySet() ) {
|
||||
String key = entry.getKey();
|
||||
Guideline.Result value = entry.getValue();
|
||||
logger.debug(key + " = " + value);
|
||||
if ( key.contains("Date")) {
|
||||
logger.info("Warnings: " + results.get(key).warnings().toString());
|
||||
logger.info("Errors: " + results.get(key).errors().toString());
|
||||
logger.info("Result: " + key + " = " + value + "\n");
|
||||
}
|
||||
logger.debug(entry.getKey() + " = " + entry.getValue());
|
||||
}
|
||||
}
|
||||
catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
// Individual scores
|
||||
|
||||
// Individual scores
|
||||
String printout = scorePerDoc.entrySet().stream().
|
||||
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();
|
||||
double finalScore = (optionalFinalScore.isPresent() ? optionalFinalScore.getAsDouble() : -1 );
|
||||
|
||||
logger.info(printout);
|
||||
logger.info("\nValidation Score: " + finalScore);
|
||||
logger.info("Validation Score: " + finalScore);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
<appender-ref ref="Console" />
|
||||
</root>
|
||||
|
||||
<logger name="eu.dnetlib.validator2" level="trace"/>
|
||||
<logger name="eu.dnetlib.validator2" level="debug"/>
|
||||
|
||||
<!-- </Loggers>-->
|
||||
|
||||
|
|
Loading…
Reference in New Issue