Skip to content

Commit

Permalink
report output improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
cmader committed Dec 28, 2013
1 parent d4fc478 commit 1033fd4
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 53 deletions.
4 changes: 2 additions & 2 deletions src/main/java/at/ac/univie/mminf/qskos4j/QSkos.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
29 changes: 22 additions & 7 deletions src/main/java/at/ac/univie/mminf/qskos4j/cmd/ReportCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public LabelConflictsResult(Collection<LabelConflict> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -11,23 +11,23 @@
import java.util.Map;
import java.util.Set;

public class CommonLanguages extends Issue<CollectionResult<String>> {
public class NoCommonLanguages extends Issue<NoCommonLanguagesResult> {

private LanguageCoverage languageCoverage;
private Set<String> 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);

this.languageCoverage = languageCoverage;
}

@Override
protected CollectionResult<String> invoke() throws OpenRDFException {
protected NoCommonLanguagesResult invoke() throws OpenRDFException {
Map<Resource, Collection<String>> langCovData = languageCoverage.getResult().getData();
commonLanguages = new HashSet<String>();

Expand All @@ -36,7 +36,7 @@ protected CollectionResult<String> invoke() throws OpenRDFException {
findCommonLanguages();
}

return new CollectionResult<>(commonLanguages);
return new NoCommonLanguagesResult(commonLanguages);
}

private void findCommonLanguages() throws OpenRDFException {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Collection<String>> {

public NoCommonLanguagesResult(Collection<String> 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();
}

}
8 changes: 7 additions & 1 deletion src/main/java/at/ac/univie/mminf/qskos4j/result/Result.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ public String toString() {
}
}

public abstract long occurrenceCount();
public long occurrenceCount() {
throw new UnsupportedOperationException();
}

public boolean isProblematic() {
return occurrenceCount() != 0;
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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());
}

}

0 comments on commit 1033fd4

Please sign in to comment.