diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/QSkos.java b/src/main/java/at/ac/univie/mminf/qskos4j/QSkos.java index 593562d..4c9c073 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/QSkos.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/QSkos.java @@ -18,7 +18,7 @@ import at.ac.univie.mminf.qskos4j.issues.labels.*; import at.ac.univie.mminf.qskos4j.issues.labels.util.ResourceLabelsCollector; import at.ac.univie.mminf.qskos4j.issues.language.IncompleteLanguageCoverage; -import at.ac.univie.mminf.qskos4j.issues.language.CommonLanguages; +import at.ac.univie.mminf.qskos4j.issues.language.NoCommonLanguages; import at.ac.univie.mminf.qskos4j.issues.language.OmittedOrInvalidLanguageTags; import at.ac.univie.mminf.qskos4j.issues.language.util.LanguageCoverage; import at.ac.univie.mminf.qskos4j.issues.outlinks.BrokenLinks; @@ -112,7 +112,7 @@ private void addAnalyticalIssues() { registeredIssues.add(new OmittedOrInvalidLanguageTags()); registeredIssues.add(new IncompleteLanguageCoverage(languageCoverage)); registeredIssues.add(new UndocumentedConcepts(authoritativeConcepts)); - registeredIssues.add(new CommonLanguages(languageCoverage)); + registeredIssues.add(new NoCommonLanguages(languageCoverage)); registeredIssues.add(new MissingLabels(authoritativeConcepts, conceptSchemes)); registeredIssues.add(new OverlappingLabels(involvedConcepts)); registeredIssues.add(new OrphanConcepts(involvedConcepts)); diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/cmd/ReportCollector.java b/src/main/java/at/ac/univie/mminf/qskos4j/cmd/ReportCollector.java index d08cbd2..1b196b6 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/cmd/ReportCollector.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/cmd/ReportCollector.java @@ -74,15 +74,32 @@ private String createReportSummary() throws IOException, OpenRDFException { summary.append("* Summary of Quality Issue Occurrences:\n"); for (Issue issue : issues) { - long occurrenceCount = issue.getResult().occurrenceCount(); - String occurrenceText = occurrenceCount == 0 ? "OK (no occurrences found)" : Long.toString(occurrenceCount); - summary.append(issue.getName() + ": " + occurrenceText + "\n"); + summary.append(issue.getName() + ": " + prepareOccurrenceText(issue) + "\n"); } summary.append("\n"); return summary.toString(); } + private String prepareOccurrenceText(Issue issue) throws OpenRDFException { + String occurrenceText = ""; + if (issue.getResult().isProblematic()) { + occurrenceText = "FAIL"; + try { + String occurrenceCount = Long.toString(issue.getResult().occurrenceCount()); + occurrenceText += " (" +occurrenceCount+ ")"; + } + catch (UnsupportedOperationException e) { + // ignore this + } + } + else { + occurrenceText = "OK (no potential problems found)"; + } + + return occurrenceText; + } + private void writeReportBody(BufferedWriter reportWriter, File reportFile, boolean shouldWriteGraphs) @@ -118,10 +135,8 @@ private void writeTextReport(Issue issue, BufferedWriter writer) writer.newLine(); issue.getResult().generateReport(writer, Result.ReportFormat.TXT, Result.ReportStyle.SHORT); - if (issue.getResult().occurrenceCount() > 0) { - writer.newLine(); - issue.getResult().generateReport(writer, Result.ReportFormat.TXT, Result.ReportStyle.EXTENSIVE); - } + writer.newLine(); + issue.getResult().generateReport(writer, Result.ReportFormat.TXT, Result.ReportStyle.EXTENSIVE); writer.newLine(); writer.flush(); diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/LabelConflictsResult.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/LabelConflictsResult.java index 9e917f0..ecdea1e 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/LabelConflictsResult.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/LabelConflictsResult.java @@ -17,7 +17,7 @@ public LabelConflictsResult(Collection data) { @Override public void generateTextReport(BufferedWriter writer, ReportStyle style) throws IOException { if (style == ReportStyle.SHORT) { - writer.write("count: " +getDistinctConcepts()+ "\n"); + writer.write("count: " +getDistinctConcepts().size()+ "\n"); } else if (style == ReportStyle.EXTENSIVE) { generateExtensiveTextReport(writer); diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/CommonLanguages.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/NoCommonLanguages.java similarity index 74% rename from src/main/java/at/ac/univie/mminf/qskos4j/issues/language/CommonLanguages.java rename to src/main/java/at/ac/univie/mminf/qskos4j/issues/language/NoCommonLanguages.java index 084c7d1..29dace7 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/CommonLanguages.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/NoCommonLanguages.java @@ -1,8 +1,8 @@ package at.ac.univie.mminf.qskos4j.issues.language; import at.ac.univie.mminf.qskos4j.issues.Issue; +import at.ac.univie.mminf.qskos4j.issues.language.util.NoCommonLanguagesResult; import at.ac.univie.mminf.qskos4j.issues.language.util.LanguageCoverage; -import at.ac.univie.mminf.qskos4j.result.CollectionResult; import org.openrdf.OpenRDFException; import org.openrdf.model.Resource; @@ -11,15 +11,15 @@ import java.util.Map; import java.util.Set; -public class CommonLanguages extends Issue> { +public class NoCommonLanguages extends Issue { private LanguageCoverage languageCoverage; private Set commonLanguages; - public CommonLanguages(LanguageCoverage languageCoverage) { + public NoCommonLanguages(LanguageCoverage languageCoverage) { super(languageCoverage, - "clg", - "Common Languages", + "ncl", + "No Common Languages", "Checks for common languages in all concept literals", IssueType.ANALYTICAL); @@ -27,7 +27,7 @@ public CommonLanguages(LanguageCoverage languageCoverage) { } @Override - protected CollectionResult invoke() throws OpenRDFException { + protected NoCommonLanguagesResult invoke() throws OpenRDFException { Map> langCovData = languageCoverage.getResult().getData(); commonLanguages = new HashSet(); @@ -36,7 +36,7 @@ protected CollectionResult invoke() throws OpenRDFException { findCommonLanguages(); } - return new CollectionResult<>(commonLanguages); + return new NoCommonLanguagesResult(commonLanguages); } private void findCommonLanguages() throws OpenRDFException { diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/util/NoCommonLanguagesResult.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/util/NoCommonLanguagesResult.java new file mode 100644 index 0000000..b7071ac --- /dev/null +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/util/NoCommonLanguagesResult.java @@ -0,0 +1,41 @@ +package at.ac.univie.mminf.qskos4j.issues.language.util; + +import at.ac.univie.mminf.qskos4j.result.Result; + +import java.io.BufferedWriter; +import java.io.IOException; +import java.util.Collection; + +public class NoCommonLanguagesResult extends Result> { + + public NoCommonLanguagesResult(Collection data) { + super(data); + } + + @Override + protected void generateTextReport(BufferedWriter osw, ReportStyle style) throws IOException + { + switch (style) { + case SHORT: + if (getData().isEmpty()) { + osw.write("Concepts are not described in a common language"); + } + else { + osw.write("At least one common language for text literals of all concepts has been found"); + } + break; + + case EXTENSIVE: + if (!getData().isEmpty()) { + osw.write("Common language(s) for all concepts: " +getData().toString()); + } + break; + } + } + + @Override + public boolean isProblematic() { + return getData().isEmpty(); + } + +} diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/result/Result.java b/src/main/java/at/ac/univie/mminf/qskos4j/result/Result.java index 5d06c57..c0c5c2f 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/result/Result.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/result/Result.java @@ -61,6 +61,12 @@ public String toString() { } } - public abstract long occurrenceCount(); + public long occurrenceCount() { + throw new UnsupportedOperationException(); + } + + public boolean isProblematic() { + return occurrenceCount() != 0; + } } diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/CommonLanguagesTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/CommonLanguagesTest.java deleted file mode 100644 index d2034ea..0000000 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/CommonLanguagesTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package at.ac.univie.mminf.qskos4j.issues; - -import at.ac.univie.mminf.qskos4j.issues.concepts.InvolvedConcepts; -import at.ac.univie.mminf.qskos4j.issues.language.CommonLanguages; -import at.ac.univie.mminf.qskos4j.issues.language.util.LanguageCoverage; -import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; -import junit.framework.Assert; -import org.junit.Before; -import org.junit.Test; -import org.openrdf.OpenRDFException; - -import java.io.IOException; - -public class CommonLanguagesTest { - - private CommonLanguages commonLanguages; - - @Before - public void setUp() throws OpenRDFException, IOException { - commonLanguages = new CommonLanguages(new LanguageCoverage(new InvolvedConcepts())); - } - - @Test - public void oneCommonLang() throws OpenRDFException, IOException { - commonLanguages.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("commonlanguage_en.rdf").getConnection()); - Assert.assertEquals(1, commonLanguages.getResult().getData().size()); - } - - @Test - public void noCommonLang() throws OpenRDFException, IOException { - commonLanguages.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("nocommonlanguage.rdf").getConnection()); - Assert.assertEquals(0, commonLanguages.getResult().getData().size()); - } - -} diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/NoCommonLanguagesTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/NoCommonLanguagesTest.java new file mode 100644 index 0000000..91c933b --- /dev/null +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/NoCommonLanguagesTest.java @@ -0,0 +1,35 @@ +package at.ac.univie.mminf.qskos4j.issues; + +import at.ac.univie.mminf.qskos4j.issues.concepts.InvolvedConcepts; +import at.ac.univie.mminf.qskos4j.issues.language.NoCommonLanguages; +import at.ac.univie.mminf.qskos4j.issues.language.util.LanguageCoverage; +import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; +import junit.framework.Assert; +import org.junit.Before; +import org.junit.Test; +import org.openrdf.OpenRDFException; + +import java.io.IOException; + +public class NoCommonLanguagesTest { + + private NoCommonLanguages noCommonLanguages; + + @Before + public void setUp() throws OpenRDFException, IOException { + noCommonLanguages = new NoCommonLanguages(new LanguageCoverage(new InvolvedConcepts())); + } + + @Test + public void oneCommonLang() throws OpenRDFException, IOException { + noCommonLanguages.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("commonlanguage_en.rdf").getConnection()); + Assert.assertEquals(1, noCommonLanguages.getResult().getData().size()); + } + + @Test + public void noCommonLang() throws OpenRDFException, IOException { + noCommonLanguages.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("nocommonlanguage.rdf").getConnection()); + Assert.assertEquals(0, noCommonLanguages.getResult().getData().size()); + } + +}