64 lines
2.8 KiB
Java
64 lines
2.8 KiB
Java
package eu.dnetlib.validator2.engine;
|
|
|
|
import eu.dnetlib.validator2.validation.XMLApplicationProfile;
|
|
import eu.dnetlib.validator2.validation.guideline.Guideline;
|
|
import eu.dnetlib.validator2.validation.guideline.openaire.LiteratureGuidelinesV4Profile;
|
|
import groovy.xml.DOMBuilder;
|
|
import org.w3c.dom.Document;
|
|
|
|
import java.io.FileReader;
|
|
import java.util.LinkedHashMap;
|
|
import java.util.Map;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
public class Test_v4 {
|
|
|
|
private static final String[] FILES = new String[] {
|
|
"src/test/resources/openaireguidelinesV4/v4_literature_all_invalid_guidelines_record.xml",
|
|
"src/test/resources/openaireguidelinesV4/v4_literature_all_guidelines_record.xml",
|
|
// "src/test/resources/openaireguidelinesV4/oai_mediarep_org_doc_2534.xml",
|
|
// "src/test/resources/openaireguidelinesV4/01_gv4.xml"
|
|
};
|
|
|
|
public static void main(String[] args) {
|
|
// String xmlFile = args[0];
|
|
LiteratureGuidelinesV4Profile profile = new LiteratureGuidelinesV4Profile();
|
|
System.out.println("Max score: " + profile.maxScore());
|
|
Map<String, Double> scorePerDoc = new LinkedHashMap<>();
|
|
for (String file: FILES) {
|
|
try {
|
|
System.out.println("Processing \"" + file + "\"");
|
|
Document doc = DOMBuilder.parse(new FileReader(file), false, true, true);
|
|
XMLApplicationProfile.ValidationResult result = profile.validate(file, doc);
|
|
scorePerDoc.put(file, result.score());
|
|
Map<String, Guideline.Result> results = result.results();
|
|
for (Map.Entry entry : results.entrySet()) {
|
|
if (entry.getKey().toString().contains("Date")) {
|
|
System.out.println(results.get(entry.getKey()).warnings().toString());
|
|
System.out.println(results.get(entry.getKey()).errors().toString());
|
|
System.out.println(entry.getKey() + " = " + entry.getValue());
|
|
System.out.println("\n");
|
|
}
|
|
System.out.println(entry.getKey() + " = " + entry.getValue());
|
|
}
|
|
}
|
|
catch(Exception e) {
|
|
System.out.println(e.getMessage());
|
|
System.out.println(e);
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
// Individual scores
|
|
String printout = scorePerDoc.entrySet().stream().
|
|
map(entry -> entry.getValue() + ": " + entry.getKey()).collect(Collectors.joining("\n"));
|
|
// Average Score
|
|
double FinalScore = scorePerDoc.entrySet().stream().mapToDouble(entry -> entry.getValue()).average().getAsDouble();
|
|
|
|
System.out.println(printout);
|
|
System.out.println("\nValidation Score: "+FinalScore);
|
|
|
|
}
|
|
|
|
}
|