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