parent
46116c1f9e
commit
b63f09bfc4
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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