From 2aa96f254180565af033e3e511a300f6fbb00c24 Mon Sep 17 00:00:00 2001 From: Christian Mader Date: Thu, 5 Dec 2013 16:03:33 +0100 Subject: [PATCH 01/19] refactored interfaces to provide better reports (with summaries) --- README.rdoc | 6 +- pom.xml | 2 +- .../mminf/qskos4j/cmd/ReportCollector.java | 75 +++++++++++++------ .../univie/mminf/qskos4j/cmd/VocEvaluate.java | 11 +-- .../qskos4j/issues/HierarchyGraphBuilder.java | 9 ++- .../ac/univie/mminf/qskos4j/issues/Issue.java | 15 +--- .../issues/clusters/ClustersReport.java | 61 --------------- .../issues/clusters/ClustersResult.java | 31 ++++++++ .../clusters/DisconnectedConceptClusters.java | 42 +++++------ .../concepts/AuthoritativeConcepts.java | 18 ++--- .../issues/concepts/InvolvedConcepts.java | 14 +--- .../issues/concepts/OrphanConcepts.java | 18 ++--- .../issues/concepts/UndocumentedConcepts.java | 17 ++--- .../issues/conceptscheme/ConceptSchemes.java | 14 +--- .../conceptscheme/MappingRelationsMisuse.java | 15 ++-- .../conceptscheme/OmittedTopConcepts.java | 16 ++-- .../TopConceptsHavingBroaderConcepts.java | 14 +--- .../issues/count/AggregationRelations.java | 14 +--- .../qskos4j/issues/count/Collections.java | 14 +--- .../issues/count/SemanticRelations.java | 14 +--- .../issues/cycles/HierarchicalCycles.java | 32 ++++---- ...ort.java => HierarchicalCyclesResult.java} | 25 ++++--- .../issues/inlinks/MissingInLinks.java | 20 ++--- .../labels/DisjointLabelsViolations.java | 14 ++-- .../issues/labels/InconsistentPrefLabels.java | 14 +--- .../issues/labels/LexicalRelations.java | 16 ++-- .../qskos4j/issues/labels/MissingLabels.java | 18 ++--- .../issues/labels/OverlappingLabels.java | 18 ++--- .../issues/labels/util/LabelConflict.java | 20 +---- .../labels/util/LabelConflictsResult.java | 46 ++++++++++++ .../issues/labels/util/LabeledConcept.java | 27 ++----- ...port.java => IncompleteLangCovResult.java} | 23 +++--- .../language/IncompleteLanguageCoverage.java | 14 +--- .../issues/language/MissingLangTagReport.java | 54 ------------- .../OmittedOrInvalidLanguageTags.java | 69 +++++++---------- .../qskos4j/issues/outlinks/BrokenLinks.java | 22 +++--- .../qskos4j/issues/outlinks/HttpURIs.java | 14 +--- .../outlinks/HttpUriSchemeViolations.java | 17 +---- .../issues/outlinks/MissingOutLinks.java | 16 ++-- .../SolelyTransitivelyRelatedConcepts.java | 71 ++++++++++-------- .../UnidirectionallyRelatedConcepts.java | 54 +++++-------- ...UnidirectionallyRelatedConceptsReport.java | 45 ----------- .../ValuelessAssociativeRelations.java | 74 +++++++++++++----- .../skosintegrity/HierarchicalRedundancy.java | 22 ++---- .../issues/skosintegrity/MappingClashes.java | 22 ++---- .../issues/skosintegrity/RelationClashes.java | 37 ++++----- .../skosintegrity/UndefinedSkosResources.java | 14 +--- .../qskos4j/report/CollectionReport.java | 74 ------------------ .../mminf/qskos4j/report/HtmlRenderable.java | 7 -- .../qskos4j/result/CollectionResult.java | 43 +++++++++++ .../ExtrapolatedCollectionResult.java} | 6 +- .../NumberResult.java} | 19 +++-- .../result/ResourceCollectionsResult.java | 47 ++++++++++++ .../Report.java => result/Result.java} | 26 ++++--- .../UnsupportedReportFormatException.java | 6 +- .../at/ac/univie/mminf/qskos4j/util/Pair.java | 43 ----------- .../ac/univie/mminf/qskos4j/util/Tuple.java | 68 +++++++++++++++++ .../qskos4j/util/TupleQueryResultUtil.java | 11 +-- .../util/graph/AssociativeRelation.java | 38 ++++++++++ .../qskos4j/util/graph/GraphExporter.java | 30 ++++---- .../util/graph/UnidirectionalRelation.java | 31 ++++++++ .../issues/AggregationRelationsTest.java | 2 +- .../issues/AuthoritativeConceptsTest.java | 2 +- .../mminf/qskos4j/issues/BrokenLinksTest.java | 2 +- .../qskos4j/issues/ConceptSchemesTest.java | 2 +- .../DisconnectedConceptClustersTest.java | 11 ++- .../issues/HierarchicalCyclesTest.java | 4 +- .../issues/HierarchicalRedundancyTest.java | 2 +- .../qskos4j/issues/LexicalRelationsTest.java | 2 +- .../qskos4j/issues/MappingClashesTest.java | 2 +- .../issues/MappingRelationsMisuseTest.java | 4 +- .../qskos4j/issues/MissingInLinksTest.java | 8 +- .../qskos4j/issues/NonHttpResourcesTest.java | 4 +- .../qskos4j/issues/RelationClashesTest.java | 2 +- .../mminf/qskos4j/issues/SkosXlTest.java | 8 +- .../issues/UndocumentedConceptsTest.java | 2 +- .../UnidirectionallyRelatedConceptsTest.java | 4 +- .../ValuelessAssociativeRelationsTest.java | 4 +- .../mminf/qskos4j/report/HtmlReportsTest.java | 58 -------------- 79 files changed, 811 insertions(+), 999 deletions(-) delete mode 100644 src/main/java/at/ac/univie/mminf/qskos4j/issues/clusters/ClustersReport.java create mode 100644 src/main/java/at/ac/univie/mminf/qskos4j/issues/clusters/ClustersResult.java rename src/main/java/at/ac/univie/mminf/qskos4j/issues/cycles/{HierarchicalCyclesReport.java => HierarchicalCyclesResult.java} (55%) create mode 100644 src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/LabelConflictsResult.java rename src/main/java/at/ac/univie/mminf/qskos4j/issues/language/{IncompleteLangCovReport.java => IncompleteLangCovResult.java} (63%) delete mode 100644 src/main/java/at/ac/univie/mminf/qskos4j/issues/language/MissingLangTagReport.java delete mode 100644 src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/UnidirectionallyRelatedConceptsReport.java delete mode 100644 src/main/java/at/ac/univie/mminf/qskos4j/report/CollectionReport.java delete mode 100644 src/main/java/at/ac/univie/mminf/qskos4j/report/HtmlRenderable.java create mode 100644 src/main/java/at/ac/univie/mminf/qskos4j/result/CollectionResult.java rename src/main/java/at/ac/univie/mminf/qskos4j/{report/ExtrapolatedCollectionReport.java => result/ExtrapolatedCollectionResult.java} (83%) rename src/main/java/at/ac/univie/mminf/qskos4j/{report/NumberReport.java => result/NumberResult.java} (51%) create mode 100644 src/main/java/at/ac/univie/mminf/qskos4j/result/ResourceCollectionsResult.java rename src/main/java/at/ac/univie/mminf/qskos4j/{report/Report.java => result/Result.java} (80%) rename src/main/java/at/ac/univie/mminf/qskos4j/{report => result}/UnsupportedReportFormatException.java (61%) delete mode 100644 src/main/java/at/ac/univie/mminf/qskos4j/util/Pair.java create mode 100644 src/main/java/at/ac/univie/mminf/qskos4j/util/Tuple.java create mode 100644 src/main/java/at/ac/univie/mminf/qskos4j/util/graph/AssociativeRelation.java create mode 100644 src/main/java/at/ac/univie/mminf/qskos4j/util/graph/UnidirectionalRelation.java delete mode 100644 src/test/java/at/ac/univie/mminf/qskos4j/report/HtmlReportsTest.java diff --git a/README.rdoc b/README.rdoc index 0f85689..8077ca0 100644 --- a/README.rdoc +++ b/README.rdoc @@ -86,12 +86,12 @@ Every concept in a SKOS vocabulary is a resource and should be identified by an qSKOS is to some extent able to perform this distinction by examining the host part of the concept's URIs. Depending on the vocabulary's structure in some cases it might be needed to pass an "Authoritative resource identifier" (command line argument -a) to qSKOS. This is a substring of an URI that identifies a concept as authoritative. -=== How can I write the report to a file? +=== How can I write the result to a file? Report output is performed directly on the console (+stdout+). If you want them to be contained in text files, you can use the output redirection operator (>) of your operating system's command line shell. Here's an example: -java -jar qSKOS-cmd.jar summarize -q -c ac ipsv_skos.rdf > auth_concepts.txt generates a text file auth_concepts.txt containing the report. +java -jar qSKOS-cmd.jar summarize -q -c ac ipsv_skos.rdf > auth_concepts.txt generates a text file auth_concepts.txt containing the result. -A command-line parameter that might be handy when redirecting qSKOS' output into a file is -np. It suppresses output of the progress indicator which is thus not written into the generated report. +A command-line parameter that might be handy when redirecting qSKOS' output into a file is -np. It suppresses output of the progress indicator which is thus not written into the generated result. === What version of qSKOS do I use? Simply pass the command line switch -v like this: diff --git a/pom.xml b/pom.xml index b145038..fbddfed 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 at.ac.univie.mminf qSKOS - 0.10.4 + 0.11.0 qSKOS 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 8a09887..4a12199 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 @@ -1,16 +1,13 @@ package at.ac.univie.mminf.qskos4j.cmd; import at.ac.univie.mminf.qskos4j.issues.Issue; -import at.ac.univie.mminf.qskos4j.report.Report; +import at.ac.univie.mminf.qskos4j.result.Result; import org.openrdf.OpenRDFException; import org.openrdf.model.URI; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; +import java.io.*; import java.text.SimpleDateFormat; import java.util.Collection; import java.util.Date; @@ -29,14 +26,18 @@ public ReportCollector(Collection issues, String reportFileName) { this.reportFileName = reportFileName; } - void outputIssuesReport(boolean outputExtendedReport, boolean shouldWriteGraphs) + void outputIssuesReport(boolean shouldWriteGraphs) throws IOException, OpenRDFException { File reportFile = createReportFile(); BufferedWriter reportWriter = new BufferedWriter(new FileWriter(reportFile)); + processIssues(); writeReportHeader(reportWriter, reportFile); - writeReportBody(reportWriter, reportFile, outputExtendedReport, shouldWriteGraphs); + writeReportSummary(reportWriter); + writeReportBody(reportWriter, reportFile, shouldWriteGraphs); + + reportWriter.close(); } private void writeReportHeader(BufferedWriter reportWriter, @@ -46,22 +47,57 @@ private void writeReportHeader(BufferedWriter reportWriter, reportWriter.write("This is the quality report of file " +fileName+ ", generated on " +issuedDate); reportWriter.newLine(); reportWriter.newLine(); + + } + + private void processIssues() throws OpenRDFException { + int issueNumber = 0; + Iterator issueIt = issues.iterator(); + while (issueIt.hasNext()) { + Issue issue = issueIt.next(); + issueNumber++; + + logger.info("Processing issue " + issueNumber + " of " + issues.size() + " (" + issue.getName() + ")"); + issue.getResult(); + + } + + logger.info("Result complete!"); + + + } + + private void writeReportSummary(BufferedWriter reportWriter) throws IOException, OpenRDFException { + reportWriter.write("Summary of Quality Issues:\n"); + + for (Issue issue : issues) { + issue.getResult().indicatesProblem(); + + + StringWriter stringWriter = new StringWriter(); + BufferedWriter writer = new BufferedWriter(stringWriter); + issue.getResult().generateReport( + writer, + Result.ReportFormat.TXT, + Result.ReportStyle.SHORT); + writer.close(); + reportWriter.write(issue.getName() + ": " +stringWriter.toString()+ "\n"); + } + + reportWriter.newLine(); } private void writeReportBody(BufferedWriter reportWriter, File reportFile, - boolean outputExtendedReport, boolean shouldWriteGraphs) throws IOException, OpenRDFException { - int issueNumber = 0; Iterator issueIt = issues.iterator(); while (issueIt.hasNext()) { Issue issue = issueIt.next(); - issueNumber++; - logger.info("Processing issue " +issueNumber+ " of " +issues.size()+ " (" +issue.getName()+ ")"); - writeTextReport(issue, reportWriter, outputExtendedReport); + writeTextReport(issue, reportWriter); + if (issueIt.hasNext()) { reportWriter.newLine(); } @@ -70,9 +106,6 @@ private void writeReportBody(BufferedWriter reportWriter, writeGraphFiles(issue, getDotFilesPath(reportFile)); } } - - logger.info("Report complete!"); - reportWriter.close(); } private File createReportFile() throws IOException { @@ -81,17 +114,15 @@ private File createReportFile() throws IOException { return file; } - private void writeTextReport(Issue issue, BufferedWriter writer, boolean outputExtendedReport) + private void writeTextReport(Issue issue, BufferedWriter writer) throws IOException, OpenRDFException { writer.write(createIssueHeader(issue)); writer.newLine(); - issue.getReport().generateReport(writer, Report.ReportFormat.TXT, Report.ReportStyle.SHORT); + issue.getResult().generateReport(writer, Result.ReportFormat.TXT, Result.ReportStyle.SHORT); - if (outputExtendedReport) { - writer.newLine(); - issue.getReport().generateReport(writer, Report.ReportFormat.TXT, Report.ReportStyle.EXTENSIVE); - } + writer.newLine(); + issue.getResult().generateReport(writer, Result.ReportFormat.TXT, Result.ReportStyle.EXTENSIVE); writer.newLine(); writer.flush(); @@ -115,7 +146,7 @@ private String getDotFilesPath(File reportFile) { private void writeGraphFiles(Issue issue, String dotFilesPath) throws IOException, OpenRDFException { BufferedWriter graphFileWriter = new BufferedWriter(new FileWriter(dotFilesPath + issue.getId() + ".dot")); - issue.getReport().generateReport(graphFileWriter, Report.ReportFormat.DOT); + issue.getResult().generateReport(graphFileWriter, Result.ReportFormat.DOT); graphFileWriter.close(); } diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/cmd/VocEvaluate.java b/src/main/java/at/ac/univie/mminf/qskos4j/cmd/VocEvaluate.java index 39f6177..3c74055 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/cmd/VocEvaluate.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/cmd/VocEvaluate.java @@ -77,10 +77,7 @@ private class CommandAnalyze extends CommandSummarize { @SuppressWarnings("unused") @Parameter(names = {"-sp", "--use-subset-percentage"}, description = "Use a specified percentage of the vocabulary triples for evaluation") private Float randomSubsetSize_percent; - - @Parameter(names = {"-e", "--extensive"}, description = "Output extensive report") - private boolean extensiveReport = false; - + @Parameter(names = {"-wg", "--write-graphs"}, description = "Writes graphs as .dot files to current directory") private boolean writeGraphs = false; @@ -194,7 +191,7 @@ private void evaluate() throws OpenRDFException, IOException setup(); reportCollector = new ReportCollector(extractMeasures(), parsedCommand.reportFileName); - reportCollector.outputIssuesReport(shouldOutputExtReport(), shouldWriteGraphs()); + reportCollector.outputIssuesReport(shouldWriteGraphs()); } private void setup() throws OpenRDFException, IOException { @@ -231,10 +228,6 @@ private void setupLogging() { } } - private boolean shouldOutputExtReport() { - return parsedCommand instanceof CommandAnalyze && ((CommandAnalyze) parsedCommand).extensiveReport; - } - private boolean shouldWriteGraphs() { return parsedCommand instanceof CommandAnalyze && ((CommandAnalyze) parsedCommand).writeGraphs; } diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/HierarchyGraphBuilder.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/HierarchyGraphBuilder.java index 0a854f0..ec5cc49 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/HierarchyGraphBuilder.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/HierarchyGraphBuilder.java @@ -2,7 +2,8 @@ import at.ac.univie.mminf.qskos4j.util.graph.NamedEdge; import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; -import org.jgrapht.graph.DirectedMultigraph; +import org.jgrapht.DirectedGraph; +import org.jgrapht.graph.DefaultDirectedGraph; import org.openrdf.OpenRDFException; import org.openrdf.model.Resource; import org.openrdf.model.Value; @@ -18,15 +19,17 @@ public class HierarchyGraphBuilder { private final Logger logger = LoggerFactory.getLogger(HierarchyGraphBuilder.class); - private DirectedMultigraph graph = new DirectedMultigraph(NamedEdge.class); + private DirectedGraph graph; private RepositoryConnection repCon; - public DirectedMultigraph createGraph() throws OpenRDFException + public DirectedGraph createGraph() throws OpenRDFException { logger.debug("Creating hierarchy graph"); + graph = new DefaultDirectedGraph(NamedEdge.class); addResultsToGraph(findTriples("skos:broaderTransitive"), false); addResultsToGraph(findTriples("skos:narrowerTransitive"), true); + return graph; } diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/Issue.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/Issue.java index 3005551..2556ae8 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/Issue.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/Issue.java @@ -2,12 +2,12 @@ import at.ac.univie.mminf.qskos4j.progress.IProgressMonitor; import at.ac.univie.mminf.qskos4j.progress.StubProgressMonitor; -import at.ac.univie.mminf.qskos4j.report.Report; +import at.ac.univie.mminf.qskos4j.result.Result; import org.openrdf.OpenRDFException; import org.openrdf.model.URI; import org.openrdf.repository.RepositoryConnection; -public abstract class Issue { +public abstract class Issue> { public enum IssueType {STATISTICAL, ANALYTICAL} @@ -47,22 +47,15 @@ public Issue(Issue dependentIssue, String id, String name, String description, I this.weblink = weblink; } - - protected abstract T computeResult() throws OpenRDFException; - protected abstract Report generateReport(T preparedData); + protected abstract T invoke() throws OpenRDFException; public final T getResult() throws OpenRDFException { if (result == null) { - result = computeResult(); + result = invoke(); } return result; } - public final Report getReport() throws OpenRDFException - { - return generateReport(getResult()); - } - protected final void reset() { result = null; if (progressMonitor != null) { diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/clusters/ClustersReport.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/clusters/ClustersReport.java deleted file mode 100644 index 8c41074..0000000 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/clusters/ClustersReport.java +++ /dev/null @@ -1,61 +0,0 @@ -package at.ac.univie.mminf.qskos4j.issues.clusters; - -import at.ac.univie.mminf.qskos4j.report.CollectionReport; -import at.ac.univie.mminf.qskos4j.util.graph.GraphExporter; -import at.ac.univie.mminf.qskos4j.util.graph.NamedEdge; -import org.jgrapht.DirectedGraph; -import org.openrdf.model.Value; - -import java.io.BufferedWriter; -import java.io.IOException; -import java.util.Collection; -import java.util.Iterator; -import java.util.Set; - -public class ClustersReport extends CollectionReport> -{ - private DirectedGraph graph; - private Collection> data; - - ClustersReport(Collection> data, DirectedGraph graph) { - super(data); - this.graph = graph; - this.data = data; - } - - @Override - protected void generateTextReport(BufferedWriter osw, ReportStyle style) throws IOException { - StringBuilder report = new StringBuilder(); - long compCount = 1; - - if (style == ReportStyle.SHORT) { - report.append("count: ").append(data.size()).append("\n"); - } - - Iterator> componentIt = data.iterator(); - while (componentIt.hasNext()) { - Set component = componentIt.next(); - - report.append("component ").append(compCount).append(", size: ").append(component.size()); - if (style == ReportStyle.EXTENSIVE) { - for (Value resource : component) { - report.append("\n\t").append(resource.toString()); - } - } - compCount++; - - if (componentIt.hasNext()) report.append("\n"); - } - - osw.write(report.toString()); - } - - @Override - public void generateDotReport(BufferedWriter writer) throws IOException { - for (String dotGraph : new GraphExporter(graph).exportSubGraphs(data)) { - writer.write(dotGraph); - writer.newLine(); - } - } - -} diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/clusters/ClustersResult.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/clusters/ClustersResult.java new file mode 100644 index 0000000..2ce4df4 --- /dev/null +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/clusters/ClustersResult.java @@ -0,0 +1,31 @@ +package at.ac.univie.mminf.qskos4j.issues.clusters; + +import at.ac.univie.mminf.qskos4j.result.ResourceCollectionsResult; +import at.ac.univie.mminf.qskos4j.util.graph.GraphExporter; +import at.ac.univie.mminf.qskos4j.util.graph.NamedEdge; +import org.jgrapht.DirectedGraph; +import org.openrdf.model.Resource; + +import java.io.BufferedWriter; +import java.io.IOException; +import java.util.Collection; + +public class ClustersResult extends ResourceCollectionsResult +{ + private DirectedGraph graph; + + ClustersResult(Collection> data, DirectedGraph graph) { + super(data, "Cluster"); + + this.graph = graph; + } + + @Override + public void generateDotReport(BufferedWriter writer) throws IOException { + for (String dotGraph : new GraphExporter(graph).exportDotGraphs(getData())) { + writer.write(dotGraph); + writer.newLine(); + } + } + +} diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/clusters/DisconnectedConceptClusters.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/clusters/DisconnectedConceptClusters.java index da39b36..0c65e15 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/clusters/DisconnectedConceptClusters.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/clusters/DisconnectedConceptClusters.java @@ -2,15 +2,15 @@ import at.ac.univie.mminf.qskos4j.issues.Issue; import at.ac.univie.mminf.qskos4j.issues.concepts.InvolvedConcepts; -import at.ac.univie.mminf.qskos4j.report.Report; -import at.ac.univie.mminf.qskos4j.util.graph.NamedEdge; import at.ac.univie.mminf.qskos4j.progress.MonitoredIterator; +import at.ac.univie.mminf.qskos4j.util.graph.NamedEdge; import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; import org.jgrapht.DirectedGraph; import org.jgrapht.alg.ConnectivityInspector; import org.jgrapht.graph.DirectedMultigraph; import org.openrdf.OpenRDFException; import org.openrdf.model.Resource; +import org.openrdf.model.URI; import org.openrdf.model.Value; import org.openrdf.model.impl.URIImpl; import org.openrdf.query.BindingSet; @@ -23,7 +23,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; -import java.util.Set; /** * Created by christian @@ -33,11 +32,11 @@ * Finds all * Disconnected Concept Clusters. */ -public class DisconnectedConceptClusters extends Issue>> { +public class DisconnectedConceptClusters extends Issue { private final Logger logger = LoggerFactory.getLogger(DisconnectedConceptClusters.class); - private DirectedGraph graph; + private DirectedGraph graph; private InvolvedConcepts involvedConcepts; public DisconnectedConceptClusters(InvolvedConcepts involvedConcepts) { @@ -52,23 +51,20 @@ public DisconnectedConceptClusters(InvolvedConcepts involvedConcepts) { } @Override - protected Collection> computeResult() throws OpenRDFException { + protected ClustersResult invoke() throws OpenRDFException { createGraph(); - return new ConnectivityInspector(graph).connectedSets(); - } + Collection> connectedSets = new ArrayList>(); + connectedSets.addAll(new ConnectivityInspector(graph).connectedSets()); - @Override - protected Report generateReport(Collection> preparedData) { - return new ClustersReport(preparedData, graph); + return new ClustersResult(connectedSets, graph); } - private void createGraph() - throws OpenRDFException + private void createGraph() throws OpenRDFException { - graph = new DirectedMultigraph(NamedEdge.class); + graph = new DirectedMultigraph(NamedEdge.class); - Iterator conceptIt = new MonitoredIterator(involvedConcepts.getResult(), progressMonitor); + Iterator conceptIt = new MonitoredIterator(involvedConcepts.getResult().getData(), progressMonitor); while (conceptIt.hasNext()) { Resource concept = conceptIt.next(); Collection relations = findRelations(concept); @@ -82,7 +78,7 @@ private void createGraph() } } - private Collection findRelations(Value concept) + private Collection findRelations(Resource concept) { Collection allRelations = new ArrayList(); @@ -92,8 +88,8 @@ private Collection findRelations(Value concept) while (result.hasNext()) { BindingSet bindingSet = result.next(); - Value otherConcept = bindingSet.getValue("otherConcept"); - Value semanticRelation = bindingSet.getValue("semanticRelation"); + Resource otherConcept = (Resource) bindingSet.getValue("otherConcept"); + URI semanticRelation = (URI) bindingSet.getValue("semanticRelation"); if (otherConcept != null && semanticRelation != null) { allRelations.add(new Relation(concept, otherConcept, semanticRelation)); @@ -117,9 +113,9 @@ private String createConnectionsQuery(Value concept) throws OpenRDFException { } private void addNodesToGraph( - Value skosResource, - Value otherResource, - Value skosRelation) + Resource skosResource, + Resource otherResource, + Resource skosRelation) { graph.addVertex(skosResource); @@ -140,9 +136,9 @@ private String extractFragmentString(Value skosRelation) { } private class Relation { - private Value sourceConcept, targetConcept, property; + private Resource sourceConcept, targetConcept, property; - private Relation(Value sourceConcept, Value targetConcept, Value property) { + private Relation(Resource sourceConcept, Resource targetConcept, Resource property) { this.sourceConcept = sourceConcept; this.targetConcept = targetConcept; this.property = property; diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/concepts/AuthoritativeConcepts.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/concepts/AuthoritativeConcepts.java index 5d800d1..65ae2d3 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/concepts/AuthoritativeConcepts.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/concepts/AuthoritativeConcepts.java @@ -2,8 +2,7 @@ import at.ac.univie.mminf.qskos4j.issues.Issue; import at.ac.univie.mminf.qskos4j.progress.MonitoredIterator; -import at.ac.univie.mminf.qskos4j.report.CollectionReport; -import at.ac.univie.mminf.qskos4j.report.Report; +import at.ac.univie.mminf.qskos4j.result.CollectionResult; import org.openrdf.OpenRDFException; import org.openrdf.model.Resource; import org.slf4j.Logger; @@ -19,7 +18,7 @@ * Finds all "authoritative concepts". See the * qSKOS readme for further information. */ -public class AuthoritativeConcepts extends Issue> { +public class AuthoritativeConcepts extends Issue> { private final Logger logger = LoggerFactory.getLogger(AuthoritativeConcepts.class); @@ -38,14 +37,9 @@ public AuthoritativeConcepts(InvolvedConcepts involvedConcepts) { } @Override - protected Collection computeResult() throws OpenRDFException { + protected CollectionResult invoke() throws OpenRDFException { getAuthResourceIdentifier(); - return extractAuthoritativeConceptsFromInvolved(); - } - - @Override - protected Report generateReport(Collection preparedData) { - return new CollectionReport(preparedData); + return new CollectionResult(extractAuthoritativeConceptsFromInvolved()); } private void determineAuthResourceIdentifier() throws OpenRDFException { @@ -65,7 +59,7 @@ private void guessAuthoritativeResourceIdentifier() throws OpenRDFException { HostNameOccurrencies hostNameOccurencies = new HostNameOccurrencies(); Iterator resourcesListIt = new MonitoredIterator( - involvedConcepts.getResult(), + involvedConcepts.getResult().getData(), progressMonitor, "guessing publishing host"); @@ -87,7 +81,7 @@ private Collection extractAuthoritativeConceptsFromInvolved() throws O { Collection authoritativeConcepts = new HashSet(); - for (Resource concept : involvedConcepts.getResult()) { + for (Resource concept : involvedConcepts.getResult().getData()) { String lowerCaseUriValue = concept.toString().toLowerCase(); if (lowerCaseUriValue.contains(authResourceIdentifier.toLowerCase())) diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/concepts/InvolvedConcepts.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/concepts/InvolvedConcepts.java index 2cb1eac..68ca5f3 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/concepts/InvolvedConcepts.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/concepts/InvolvedConcepts.java @@ -1,8 +1,7 @@ package at.ac.univie.mminf.qskos4j.issues.concepts; import at.ac.univie.mminf.qskos4j.issues.Issue; -import at.ac.univie.mminf.qskos4j.report.CollectionReport; -import at.ac.univie.mminf.qskos4j.report.Report; +import at.ac.univie.mminf.qskos4j.result.CollectionResult; import at.ac.univie.mminf.qskos4j.util.vocab.SkosOntology; import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; import org.openrdf.OpenRDFException; @@ -17,7 +16,7 @@ /** * Finds all SKOS Concepts involved in the vocabulary. */ -public class InvolvedConcepts extends Issue> { +public class InvolvedConcepts extends Issue> { public InvolvedConcepts() { super("c", @@ -28,8 +27,7 @@ public InvolvedConcepts() { } @Override - protected Collection computeResult() throws OpenRDFException - { + protected CollectionResult invoke() throws OpenRDFException { RepositoryResult result = repCon.getStatements( null, RDF.TYPE, @@ -40,12 +38,8 @@ protected Collection computeResult() throws OpenRDFException while (result.hasNext()) { involvedConcepts.add(result.next().getSubject()); } - return involvedConcepts; - } - @Override - protected Report generateReport(Collection preparedData) { - return new CollectionReport(preparedData); + return new CollectionResult(involvedConcepts); } private String createConceptsQuery() throws OpenRDFException { diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/concepts/OrphanConcepts.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/concepts/OrphanConcepts.java index 4fe0992..8876da1 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/concepts/OrphanConcepts.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/concepts/OrphanConcepts.java @@ -1,17 +1,16 @@ package at.ac.univie.mminf.qskos4j.issues.concepts; import at.ac.univie.mminf.qskos4j.issues.Issue; -import at.ac.univie.mminf.qskos4j.report.CollectionReport; -import at.ac.univie.mminf.qskos4j.report.Report; +import at.ac.univie.mminf.qskos4j.result.CollectionResult; import at.ac.univie.mminf.qskos4j.util.TupleQueryResultUtil; import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; import org.openrdf.OpenRDFException; +import org.openrdf.model.Resource; import org.openrdf.model.Value; import org.openrdf.model.impl.URIImpl; import org.openrdf.query.QueryLanguage; import org.openrdf.query.TupleQuery; -import java.util.Collection; import java.util.HashSet; import java.util.Set; @@ -19,7 +18,7 @@ * Finds all "orphan concepts". Further info on Orphan * Concepts. */ -public class OrphanConcepts extends Issue> { +public class OrphanConcepts extends Issue> { private InvolvedConcepts involvedConcepts; @@ -36,19 +35,14 @@ public OrphanConcepts(InvolvedConcepts involvedConcepts) { } @Override - protected Collection computeResult() throws OpenRDFException { + protected CollectionResult invoke() throws OpenRDFException { TupleQuery query = repCon.prepareTupleQuery(QueryLanguage.SPARQL, createOrphanConceptsQuery()); Set connectedConcepts = TupleQueryResultUtil.getValuesForBindingName(query.evaluate(), "concept"); - Set orphanConcepts = new HashSet(involvedConcepts.getResult()); + Set orphanConcepts = new HashSet(involvedConcepts.getResult().getData()); orphanConcepts.removeAll(connectedConcepts); - return orphanConcepts; - } - - @Override - protected Report generateReport(Collection preparedData) { - return new CollectionReport(preparedData); + return new CollectionResult(orphanConcepts); } private String createOrphanConceptsQuery() throws OpenRDFException diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/concepts/UndocumentedConcepts.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/concepts/UndocumentedConcepts.java index 5e45cbe..d90379b 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/concepts/UndocumentedConcepts.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/concepts/UndocumentedConcepts.java @@ -1,9 +1,8 @@ package at.ac.univie.mminf.qskos4j.issues.concepts; import at.ac.univie.mminf.qskos4j.issues.Issue; -import at.ac.univie.mminf.qskos4j.report.CollectionReport; -import at.ac.univie.mminf.qskos4j.report.Report; import at.ac.univie.mminf.qskos4j.progress.MonitoredIterator; +import at.ac.univie.mminf.qskos4j.result.CollectionResult; import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; import org.openrdf.OpenRDFException; import org.openrdf.model.Resource; @@ -15,7 +14,6 @@ import org.slf4j.LoggerFactory; import java.util.ArrayList; -import java.util.Collection; import java.util.Iterator; import java.util.List; @@ -24,7 +22,7 @@ * Undocumented Concepts * ). */ -public class UndocumentedConcepts extends Issue> { +public class UndocumentedConcepts extends Issue> { private final Logger logger = LoggerFactory.getLogger(UndocumentedConcepts.class); @@ -47,11 +45,11 @@ public UndocumentedConcepts(AuthoritativeConcepts authoritativeConcepts) { } @Override - protected Collection computeResult() throws OpenRDFException { + protected CollectionResult invoke() throws OpenRDFException { List undocumentedConcepts = new ArrayList(); Iterator conceptIt = new MonitoredIterator( - authoritativeConcepts.getResult(), + authoritativeConcepts.getResult().getData(), progressMonitor); while (conceptIt.hasNext()) { @@ -61,14 +59,9 @@ protected Collection computeResult() throws OpenRDFException { } } - return undocumentedConcepts; + return new CollectionResult(undocumentedConcepts); } - @Override - protected Report generateReport(Collection preparedData) { - return new CollectionReport(preparedData); - } - private boolean isConceptDocumented(Value concept) throws OpenRDFException { diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/conceptscheme/ConceptSchemes.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/conceptscheme/ConceptSchemes.java index dbc31f8..15d5b86 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/conceptscheme/ConceptSchemes.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/conceptscheme/ConceptSchemes.java @@ -1,8 +1,7 @@ package at.ac.univie.mminf.qskos4j.issues.conceptscheme; import at.ac.univie.mminf.qskos4j.issues.Issue; -import at.ac.univie.mminf.qskos4j.report.CollectionReport; -import at.ac.univie.mminf.qskos4j.report.Report; +import at.ac.univie.mminf.qskos4j.result.CollectionResult; import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; import org.openrdf.OpenRDFException; import org.openrdf.model.Resource; @@ -23,7 +22,7 @@ * * Finds the number of SKOS ConceptSchemes. */ -public class ConceptSchemes extends Issue> { +public class ConceptSchemes extends Issue> { private final Logger logger = LoggerFactory.getLogger(ConceptSchemes.class); @@ -35,14 +34,9 @@ public ConceptSchemes() { } @Override - protected Collection computeResult() throws OpenRDFException { + protected CollectionResult invoke() throws OpenRDFException { TupleQueryResult result = repCon.prepareTupleQuery(QueryLanguage.SPARQL, createConceptSchemeQuery()).evaluate(); - return identifyResources(result); - } - - @Override - protected Report generateReport(Collection preparedData) { - return new CollectionReport(preparedData); + return new CollectionResult(identifyResources(result)); } private String createConceptSchemeQuery() { diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/conceptscheme/MappingRelationsMisuse.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/conceptscheme/MappingRelationsMisuse.java index e5c44d5..66bc2b5 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/conceptscheme/MappingRelationsMisuse.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/conceptscheme/MappingRelationsMisuse.java @@ -2,8 +2,7 @@ import at.ac.univie.mminf.qskos4j.issues.Issue; import at.ac.univie.mminf.qskos4j.issues.concepts.AuthoritativeConcepts; -import at.ac.univie.mminf.qskos4j.report.CollectionReport; -import at.ac.univie.mminf.qskos4j.report.Report; +import at.ac.univie.mminf.qskos4j.result.CollectionResult; import at.ac.univie.mminf.qskos4j.util.vocab.SkosOntology; import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; import org.openrdf.OpenRDFException; @@ -16,7 +15,7 @@ import java.util.ArrayList; import java.util.Collection; -public class MappingRelationsMisuse extends Issue> { +public class MappingRelationsMisuse extends Issue> { private AuthoritativeConcepts authoritativeConcepts; @@ -31,7 +30,7 @@ public MappingRelationsMisuse(AuthoritativeConcepts authoritativeConcepts) { } @Override - protected Collection computeResult() throws OpenRDFException { + protected CollectionResult invoke() throws OpenRDFException { Collection problematicRelations = new ArrayList(); RepositoryResult result = repCon.getStatements( @@ -51,13 +50,13 @@ protected Collection computeResult() throws OpenRDFException { } } - return problematicRelations; + return new CollectionResult(problematicRelations); } private boolean areAuthoritativeConcepts(Resource... concepts) throws OpenRDFException { for (Resource concept : concepts) { boolean isAuthoritativeConcept = false; - for (Resource authoritativeConcept : authoritativeConcepts.getResult()) { + for (Resource authoritativeConcept : authoritativeConcepts.getResult().getData()) { if (concept.equals(authoritativeConcept)) isAuthoritativeConcept = true; } if (!isAuthoritativeConcept) return false; @@ -87,8 +86,4 @@ private String createInSchemeQuery(Resource... concepts) { return query + "}"; } - @Override - protected Report generateReport(Collection preparedData) { - return new CollectionReport(preparedData); - } } diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/conceptscheme/OmittedTopConcepts.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/conceptscheme/OmittedTopConcepts.java index 2eafbb7..377394e 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/conceptscheme/OmittedTopConcepts.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/conceptscheme/OmittedTopConcepts.java @@ -1,8 +1,7 @@ package at.ac.univie.mminf.qskos4j.issues.conceptscheme; import at.ac.univie.mminf.qskos4j.issues.Issue; -import at.ac.univie.mminf.qskos4j.report.CollectionReport; -import at.ac.univie.mminf.qskos4j.report.Report; +import at.ac.univie.mminf.qskos4j.result.CollectionResult; import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; import org.openrdf.OpenRDFException; import org.openrdf.model.Resource; @@ -19,7 +18,7 @@ * Omitted Top Concepts * ). */ -public class OmittedTopConcepts extends Issue> { +public class OmittedTopConcepts extends Issue> { private ConceptSchemes conceptSchemes; @@ -35,10 +34,10 @@ public OmittedTopConcepts(ConceptSchemes conceptSchemes) { } @Override - protected Collection computeResult() throws OpenRDFException { + protected CollectionResult invoke() throws OpenRDFException { Collection csWithOmittedTopConcepts = new HashSet(); - for (Resource conceptScheme : conceptSchemes.getResult()) { + for (Resource conceptScheme : conceptSchemes.getResult().getData()) { BooleanQuery hasTopConceptQuery = repCon.prepareBooleanQuery( QueryLanguage.SPARQL, @@ -49,12 +48,7 @@ protected Collection computeResult() throws OpenRDFException { } } - return csWithOmittedTopConcepts; - } - - @Override - protected Report generateReport(Collection preparedData) { - return new CollectionReport(preparedData); + return new CollectionResult(csWithOmittedTopConcepts); } private String createConceptSchemeWithoutTopConceptQuery(Value conceptScheme) { diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/conceptscheme/TopConceptsHavingBroaderConcepts.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/conceptscheme/TopConceptsHavingBroaderConcepts.java index 647efd1..ea67dab 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/conceptscheme/TopConceptsHavingBroaderConcepts.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/conceptscheme/TopConceptsHavingBroaderConcepts.java @@ -1,8 +1,7 @@ package at.ac.univie.mminf.qskos4j.issues.conceptscheme; import at.ac.univie.mminf.qskos4j.issues.Issue; -import at.ac.univie.mminf.qskos4j.report.CollectionReport; -import at.ac.univie.mminf.qskos4j.report.Report; +import at.ac.univie.mminf.qskos4j.result.CollectionResult; import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; import org.openrdf.OpenRDFException; import org.openrdf.model.URI; @@ -21,7 +20,7 @@ * Finds top concepts that have broader concepts ( * Top Concepts Having Broader Concepts */ -public class TopConceptsHavingBroaderConcepts extends Issue> { +public class TopConceptsHavingBroaderConcepts extends Issue> { public TopConceptsHavingBroaderConcepts() { super("tchbc", @@ -33,14 +32,9 @@ public TopConceptsHavingBroaderConcepts() { } @Override - protected Collection computeResult() throws OpenRDFException { + protected CollectionResult invoke() throws OpenRDFException { TupleQuery query = repCon.prepareTupleQuery(QueryLanguage.SPARQL, createTopConceptsHavingBroaderConceptQuery()); - return createUriResultList(query.evaluate()); - } - - @Override - protected Report generateReport(Collection preparedData) { - return new CollectionReport(preparedData); + return new CollectionResult(createUriResultList(query.evaluate())); } private String createTopConceptsHavingBroaderConceptQuery() { diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/count/AggregationRelations.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/count/AggregationRelations.java index e5163fe..b7607b1 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/count/AggregationRelations.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/count/AggregationRelations.java @@ -1,8 +1,7 @@ package at.ac.univie.mminf.qskos4j.issues.count; import at.ac.univie.mminf.qskos4j.issues.Issue; -import at.ac.univie.mminf.qskos4j.report.NumberReport; -import at.ac.univie.mminf.qskos4j.report.Report; +import at.ac.univie.mminf.qskos4j.result.NumberResult; import at.ac.univie.mminf.qskos4j.util.TupleQueryResultUtil; import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; import org.openrdf.OpenRDFException; @@ -16,7 +15,7 @@ * * Finds the number of triples that assign concepts to concept schemes or lists. */ -public class AggregationRelations extends Issue { +public class AggregationRelations extends Issue> { private final String AGGREGATION_RELATIONS = "skos:topConceptOf, skos:hasTopConcept, skos:inScheme, skos:member, skos:memberList"; @@ -30,14 +29,9 @@ public AggregationRelations() { } @Override - protected Long computeResult() throws OpenRDFException { + protected NumberResult invoke() throws OpenRDFException { TupleQuery query = repCon.prepareTupleQuery(QueryLanguage.SPARQL, createAggregationRelationsQuery()); - return TupleQueryResultUtil.countResults(query.evaluate()); - } - - @Override - protected Report generateReport(Long preparedData) { - return new NumberReport(preparedData); + return new NumberResult(TupleQueryResultUtil.countResults(query.evaluate())); } private String createAggregationRelationsQuery() { diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/count/Collections.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/count/Collections.java index 5379c86..2cbd196 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/count/Collections.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/count/Collections.java @@ -1,8 +1,7 @@ package at.ac.univie.mminf.qskos4j.issues.count; import at.ac.univie.mminf.qskos4j.issues.Issue; -import at.ac.univie.mminf.qskos4j.report.NumberReport; -import at.ac.univie.mminf.qskos4j.report.Report; +import at.ac.univie.mminf.qskos4j.result.NumberResult; import at.ac.univie.mminf.qskos4j.util.vocab.SkosOntology; import org.openrdf.OpenRDFException; import org.openrdf.model.Statement; @@ -16,7 +15,7 @@ * * Finds the number of SKOS Collections. */ -public class Collections extends Issue { +public class Collections extends Issue> { public Collections() { super("cc", @@ -27,7 +26,7 @@ public Collections() { } @Override - protected Long computeResult() throws OpenRDFException { + protected NumberResult invoke() throws OpenRDFException { RepositoryResult result = repCon.getStatements(null, RDF.TYPE, SkosOntology.getInstance().getUri("Collection"), true); long collectionCount = 0; @@ -37,12 +36,7 @@ protected Long computeResult() throws OpenRDFException { } result.close(); - return collectionCount; - } - - @Override - protected Report generateReport(Long preparedData) { - return new NumberReport(preparedData); + return new NumberResult(collectionCount); } } diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/count/SemanticRelations.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/count/SemanticRelations.java index 1a35df9..5f3f06f 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/count/SemanticRelations.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/count/SemanticRelations.java @@ -1,8 +1,7 @@ package at.ac.univie.mminf.qskos4j.issues.count; import at.ac.univie.mminf.qskos4j.issues.Issue; -import at.ac.univie.mminf.qskos4j.report.NumberReport; -import at.ac.univie.mminf.qskos4j.report.Report; +import at.ac.univie.mminf.qskos4j.result.NumberResult; import at.ac.univie.mminf.qskos4j.util.vocab.SkosOntology; import org.openrdf.OpenRDFException; import org.openrdf.model.Statement; @@ -15,7 +14,7 @@ * * Finds the number of triples involving (subproperties of) skos:semanticRelation. */ -public class SemanticRelations extends Issue { +public class SemanticRelations extends Issue> { public SemanticRelations() { super("sr", @@ -26,7 +25,7 @@ public SemanticRelations() { } @Override - protected Long computeResult() throws OpenRDFException { + protected NumberResult invoke() throws OpenRDFException { RepositoryResult result = repCon.getStatements( null, SkosOntology.getInstance().getUri("semanticRelation"), @@ -38,12 +37,7 @@ protected Long computeResult() throws OpenRDFException { result.next(); semanticRelationsCount++; } - return semanticRelationsCount; - } - - @Override - protected Report generateReport(Long preparedData) { - return new NumberReport(preparedData); + return new NumberResult(semanticRelationsCount); } } diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/cycles/HierarchicalCycles.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/cycles/HierarchicalCycles.java index 843ca08..bf8e699 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/cycles/HierarchicalCycles.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/cycles/HierarchicalCycles.java @@ -2,13 +2,12 @@ import at.ac.univie.mminf.qskos4j.issues.HierarchyGraphBuilder; import at.ac.univie.mminf.qskos4j.issues.Issue; -import at.ac.univie.mminf.qskos4j.report.Report; import at.ac.univie.mminf.qskos4j.util.graph.NamedEdge; import org.jgrapht.DirectedGraph; import org.jgrapht.alg.CycleDetector; import org.jgrapht.alg.StrongConnectivityInspector; import org.openrdf.OpenRDFException; -import org.openrdf.model.Value; +import org.openrdf.model.Resource; import org.openrdf.model.impl.URIImpl; import org.openrdf.repository.RepositoryConnection; import org.slf4j.Logger; @@ -26,11 +25,11 @@ * * Finds all Cyclic Hierarchical Relations. */ -public class HierarchicalCycles extends Issue>> { +public class HierarchicalCycles extends Issue { private final Logger logger = LoggerFactory.getLogger(HierarchicalCycles.class); - private DirectedGraph hierarchyGraph; + private DirectedGraph hierarchyGraph; private HierarchyGraphBuilder hierarchyGraphBuilder; public HierarchicalCycles(HierarchyGraphBuilder hierarchyGraphBuilder) { @@ -44,31 +43,26 @@ public HierarchicalCycles(HierarchyGraphBuilder hierarchyGraphBuilder) { } @Override - protected Collection> computeResult() throws OpenRDFException { + protected HierarchicalCyclesResult invoke() throws OpenRDFException { hierarchyGraph = hierarchyGraphBuilder.createGraph(); - return findCycleContainingComponents(); + return new HierarchicalCyclesResult(findCycleContainingComponents(), hierarchyGraph); } - @Override - protected Report generateReport(Collection> preparedData) { - return new HierarchicalCyclesReport(preparedData, hierarchyGraph); - } - - private List> findCycleContainingComponents() { + private List> findCycleContainingComponents() { logger.debug("Finding cycles"); - Set nodesInCycles = new CycleDetector(hierarchyGraph).findCycles(); + Set nodesInCycles = new CycleDetector(hierarchyGraph).findCycles(); return trackNodesInCycles(nodesInCycles); } - private List> trackNodesInCycles(Set nodesInCycles) + private List> trackNodesInCycles(Set nodesInCycles) { - List> ret = new ArrayList>(); - List> stronglyConnectedSets = - new StrongConnectivityInspector(hierarchyGraph).stronglyConnectedSets(); + List> ret = new ArrayList>(); + List> stronglyConnectedSets = + new StrongConnectivityInspector(hierarchyGraph).stronglyConnectedSets(); - for (Value node : nodesInCycles) { - for (Set stronglyConnectedSet : stronglyConnectedSets) { + for (Resource node : nodesInCycles) { + for (Set stronglyConnectedSet : stronglyConnectedSets) { if (stronglyConnectedSet.contains(node)) { if (!ret.contains(stronglyConnectedSet)) { ret.add(stronglyConnectedSet); diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/cycles/HierarchicalCyclesReport.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/cycles/HierarchicalCyclesResult.java similarity index 55% rename from src/main/java/at/ac/univie/mminf/qskos4j/issues/cycles/HierarchicalCyclesReport.java rename to src/main/java/at/ac/univie/mminf/qskos4j/issues/cycles/HierarchicalCyclesResult.java index 33d4485..64937df 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/cycles/HierarchicalCyclesReport.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/cycles/HierarchicalCyclesResult.java @@ -1,9 +1,10 @@ package at.ac.univie.mminf.qskos4j.issues.cycles; -import at.ac.univie.mminf.qskos4j.report.CollectionReport; +import at.ac.univie.mminf.qskos4j.result.ResourceCollectionsResult; import at.ac.univie.mminf.qskos4j.util.graph.GraphExporter; import at.ac.univie.mminf.qskos4j.util.graph.NamedEdge; import org.jgrapht.DirectedGraph; +import org.openrdf.model.Resource; import org.openrdf.model.Value; import java.io.BufferedWriter; @@ -11,20 +12,22 @@ import java.util.Collection; import java.util.Set; -public class HierarchicalCyclesReport extends CollectionReport> { +public class HierarchicalCyclesResult extends ResourceCollectionsResult { - private DirectedGraph graph; - private Collection> data; - - public HierarchicalCyclesReport(Collection> data, DirectedGraph graph) { - super(data); - this.graph = graph; - this.data = data; - } + private DirectedGraph graph; + + public HierarchicalCyclesResult( + Collection> data, + DirectedGraph graph) + { + super(data, "Cycle"); + + this.graph = graph; + } @Override public void generateDotReport(BufferedWriter writer) throws IOException { - for (String hierarchyCycleDot : new GraphExporter(graph).exportSubGraphs(data)) { + for (String hierarchyCycleDot : new GraphExporter(graph).exportDotGraphs(getData())) { writer.write(hierarchyCycleDot); writer.newLine(); } diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/inlinks/MissingInLinks.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/inlinks/MissingInLinks.java index e5d4585..d2c1902 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/inlinks/MissingInLinks.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/inlinks/MissingInLinks.java @@ -2,10 +2,9 @@ import at.ac.univie.mminf.qskos4j.issues.Issue; import at.ac.univie.mminf.qskos4j.issues.concepts.AuthoritativeConcepts; -import at.ac.univie.mminf.qskos4j.report.ExtrapolatedCollectionReport; -import at.ac.univie.mminf.qskos4j.report.Report; -import at.ac.univie.mminf.qskos4j.util.RandomSubSet; import at.ac.univie.mminf.qskos4j.progress.MonitoredIterator; +import at.ac.univie.mminf.qskos4j.result.CollectionResult; +import at.ac.univie.mminf.qskos4j.util.RandomSubSet; import org.openrdf.OpenRDFException; import org.openrdf.model.Resource; import org.openrdf.model.URI; @@ -28,7 +27,7 @@ * Missing In-Links * ). */ -public class MissingInLinks extends Issue> { +public class MissingInLinks extends Issue> { private final Logger logger = LoggerFactory.getLogger(MissingInLinks.class); @@ -50,7 +49,7 @@ public MissingInLinks(AuthoritativeConcepts authoritativeConcepts) { } @Override - protected Collection computeResult() throws OpenRDFException { + protected CollectionResult invoke() throws OpenRDFException { Collection conceptsToCheck = getConceptsToCheck(randomSubsetSize_percent); if (randomSubsetSize_percent != null) { @@ -66,21 +65,16 @@ protected Collection computeResult() throws OpenRDFException { rankConcept(conceptIt.next()); } - return extractUnreferencedConcepts(); - } - - @Override - protected Report generateReport(Collection preparedData) { - return new ExtrapolatedCollectionReport(preparedData, randomSubsetSize_percent); + return new CollectionResult(extractUnreferencedConcepts()); } private Collection getConceptsToCheck(Float randomSubsetSize_percent) throws OpenRDFException { if (randomSubsetSize_percent == null) { - return authoritativeConcepts.getResult(); + return authoritativeConcepts.getResult().getData(); } else { - return new RandomSubSet(authoritativeConcepts.getResult(), randomSubsetSize_percent); + return new RandomSubSet(authoritativeConcepts.getResult().getData(), randomSubsetSize_percent); } } diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/DisjointLabelsViolations.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/DisjointLabelsViolations.java index e02ef55..fd4c8c9 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/DisjointLabelsViolations.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/DisjointLabelsViolations.java @@ -4,8 +4,7 @@ import at.ac.univie.mminf.qskos4j.issues.labels.util.LabelConflict; import at.ac.univie.mminf.qskos4j.issues.labels.util.LabeledConcept; import at.ac.univie.mminf.qskos4j.issues.labels.util.ResourceLabelsCollector; -import at.ac.univie.mminf.qskos4j.report.CollectionReport; -import at.ac.univie.mminf.qskos4j.report.Report; +import at.ac.univie.mminf.qskos4j.issues.labels.util.LabelConflictsResult; import org.openrdf.OpenRDFException; import org.openrdf.model.Literal; import org.openrdf.model.impl.URIImpl; @@ -21,7 +20,7 @@ * Disjoint Labels Violation * ). */ -public class DisjointLabelsViolations extends Issue> { +public class DisjointLabelsViolations extends Issue { private Map nonDisjointLabels; private ResourceLabelsCollector resourceLabelsCollector; @@ -37,14 +36,11 @@ public DisjointLabelsViolations(ResourceLabelsCollector resourceLabelsCollector) } @Override - protected Map computeResult() throws OpenRDFException { + protected LabelConflictsResult invoke() throws OpenRDFException { findNonDisjointLabels(); - return nonDisjointLabels; - } - @Override - protected Report generateReport(Map preparedData) { - return new CollectionReport(nonDisjointLabels.values()); + LabelConflictsResult labelConflictsResult = new LabelConflictsResult(nonDisjointLabels.values()); + return labelConflictsResult; } private void findNonDisjointLabels() throws OpenRDFException { diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/InconsistentPrefLabels.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/InconsistentPrefLabels.java index 0bf67a6..fa1d815 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/InconsistentPrefLabels.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/InconsistentPrefLabels.java @@ -5,8 +5,7 @@ import at.ac.univie.mminf.qskos4j.issues.labels.util.LabelType; import at.ac.univie.mminf.qskos4j.issues.labels.util.LabeledConcept; import at.ac.univie.mminf.qskos4j.issues.labels.util.ResourceLabelsCollector; -import at.ac.univie.mminf.qskos4j.report.CollectionReport; -import at.ac.univie.mminf.qskos4j.report.Report; +import at.ac.univie.mminf.qskos4j.issues.labels.util.LabelConflictsResult; import org.openrdf.OpenRDFException; import org.openrdf.model.Value; import org.openrdf.model.impl.URIImpl; @@ -21,7 +20,7 @@ * * Finds concepts with more than one preferred label ( * Inconsistent Preferred Labels */ -public class InconsistentPrefLabels extends Issue> { +public class InconsistentPrefLabels extends Issue { private Map ambigPrefLabels; private ResourceLabelsCollector resourceLabelsCollector; @@ -37,18 +36,13 @@ public InconsistentPrefLabels(ResourceLabelsCollector resourceLabelsCollector) { } @Override - protected Map computeResult() throws OpenRDFException { + protected LabelConflictsResult invoke() throws OpenRDFException { Map> prefLabelsByUri = orderPrefLabelsByResource(); extractPrefLabelConflicts(prefLabelsByUri); - return ambigPrefLabels; + return new LabelConflictsResult(ambigPrefLabels.values()); } - @Override - protected Report generateReport(Map preparedData) { - return new CollectionReport(preparedData.values()); - } - private Map> orderPrefLabelsByResource() throws OpenRDFException { Map> prefLabelsByResource = new HashMap>(); diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/LexicalRelations.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/LexicalRelations.java index eace15d..11ad47b 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/LexicalRelations.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/LexicalRelations.java @@ -2,8 +2,7 @@ import at.ac.univie.mminf.qskos4j.issues.Issue; import at.ac.univie.mminf.qskos4j.issues.concepts.InvolvedConcepts; -import at.ac.univie.mminf.qskos4j.report.NumberReport; -import at.ac.univie.mminf.qskos4j.report.Report; +import at.ac.univie.mminf.qskos4j.result.NumberResult; import at.ac.univie.mminf.qskos4j.util.TupleQueryResultUtil; import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; import org.openrdf.OpenRDFException; @@ -21,7 +20,7 @@ * Finds the number of relations involving SKOS lexical labels (prefLabel, altLabel, hiddenLabel). * */ -public class LexicalRelations extends Issue { +public class LexicalRelations extends Issue> { private final Logger logger = LoggerFactory.getLogger(LexicalRelations.class); @@ -39,10 +38,10 @@ public LexicalRelations(InvolvedConcepts involvedConcepts) { } @Override - protected Long computeResult() throws OpenRDFException { + protected NumberResult invoke() throws OpenRDFException { long relationsCount = 0; - for (Value concept : involvedConcepts.getResult()) { + for (Value concept : involvedConcepts.getResult().getData()) { try { TupleQueryResult result = repCon.prepareTupleQuery( QueryLanguage.SPARQL, @@ -56,12 +55,7 @@ protected Long computeResult() throws OpenRDFException { } } - return relationsCount; - } - - @Override - protected Report generateReport(Long preparedData) { - return new NumberReport(preparedData); + return new NumberResult(relationsCount); } private String createLexicalLabelQuery(Value concept) { diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/MissingLabels.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/MissingLabels.java index 430acd4..b19ae73 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/MissingLabels.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/MissingLabels.java @@ -3,8 +3,7 @@ import at.ac.univie.mminf.qskos4j.issues.Issue; import at.ac.univie.mminf.qskos4j.issues.concepts.AuthoritativeConcepts; import at.ac.univie.mminf.qskos4j.issues.conceptscheme.ConceptSchemes; -import at.ac.univie.mminf.qskos4j.report.CollectionReport; -import at.ac.univie.mminf.qskos4j.report.Report; +import at.ac.univie.mminf.qskos4j.result.CollectionResult; import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; import org.openrdf.OpenRDFException; import org.openrdf.model.Resource; @@ -18,7 +17,7 @@ import java.util.ArrayList; import java.util.Collection; -public class MissingLabels extends Issue> { +public class MissingLabels extends Issue> { private final Logger logger = LoggerFactory.getLogger(MissingLabels.class); @@ -38,24 +37,19 @@ public MissingLabels(AuthoritativeConcepts authConcepts, ConceptSchemes conceptS } @Override - protected Collection computeResult() throws OpenRDFException { + protected CollectionResult invoke() throws OpenRDFException { unlabeledConceptsAndConceptSchemes = new ArrayList(); unlabeledConceptsAndConceptSchemes.addAll(findUnlabeledConcepts()); unlabeledConceptsAndConceptSchemes.addAll(findUnlabeledConceptSchemes()); - return unlabeledConceptsAndConceptSchemes; - } - - @Override - protected Report generateReport(Collection preparedData) { - return new CollectionReport(unlabeledConceptsAndConceptSchemes); + return new CollectionResult(unlabeledConceptsAndConceptSchemes); } private Collection findUnlabeledConcepts() throws OpenRDFException { Collection unlabeledConcepts = new ArrayList(); - for (Resource authConcept : allAuthConcepts.getResult()) { + for (Resource authConcept : allAuthConcepts.getResult().getData()) { if (hasNoPrefLabel(authConcept)) unlabeledConcepts.add(authConcept); } @@ -77,7 +71,7 @@ private boolean hasNoPrefLabel(Value concept) { private Collection findUnlabeledConceptSchemes() throws OpenRDFException { Collection unlabeledConceptSchemes = new ArrayList(); - for (Resource conceptScheme : allConceptSchemes.getResult()) { + for (Resource conceptScheme : allConceptSchemes.getResult().getData()) { if (hasNoRdfsLabelAndNoDcTitle(conceptScheme)) unlabeledConceptSchemes.add(conceptScheme); } diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/OverlappingLabels.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/OverlappingLabels.java index 06fefa1..689d80f 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/OverlappingLabels.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/OverlappingLabels.java @@ -6,9 +6,8 @@ import at.ac.univie.mminf.qskos4j.issues.labels.util.LabelType; import at.ac.univie.mminf.qskos4j.issues.labels.util.LabeledConcept; import at.ac.univie.mminf.qskos4j.issues.labels.util.SimilarityLiteral; -import at.ac.univie.mminf.qskos4j.report.CollectionReport; -import at.ac.univie.mminf.qskos4j.report.Report; import at.ac.univie.mminf.qskos4j.progress.MonitoredIterator; +import at.ac.univie.mminf.qskos4j.result.CollectionResult; import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; import org.openrdf.OpenRDFException; import org.openrdf.model.Literal; @@ -26,7 +25,7 @@ * Overlapping Labels * ). */ -public class OverlappingLabels extends Issue> { +public class OverlappingLabels extends Issue> { private final Logger logger = LoggerFactory.getLogger(OverlappingLabels.class); @@ -46,22 +45,17 @@ public OverlappingLabels(InvolvedConcepts involvedConcepts) { } @Override - protected Set computeResult() throws OpenRDFException { + protected CollectionResult invoke() throws OpenRDFException { generateConceptsLabelMap(); generateLabelConflictResults(); - return labelConflicts; + return new CollectionResult(labelConflicts); } - @Override - protected Report generateReport(Set preparedData) { - return new CollectionReport(preparedData); - } - private void generateConceptsLabelMap() throws OpenRDFException { conceptLabels = new HashMap>(); - Iterator it = new MonitoredIterator(involvedConcepts.getResult(), progressMonitor); + Iterator it = new MonitoredIterator(involvedConcepts.getResult().getData(), progressMonitor); progressMonitor.setTaskDescription("Collecting resource labels"); while (it.hasNext()) { @@ -109,7 +103,7 @@ private String createConceptLabelQuery(Value concept) { "{<"+concept.stringValue()+"> skos:hiddenLabel ?hiddenLabel .}}"; } - private Set createLabeledConceptsFromResult(Value concept, TupleQueryResult result) + private Set createLabeledConceptsFromResult(Resource concept, TupleQueryResult result) throws QueryEvaluationException { Set ret = new HashSet(); diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/LabelConflict.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/LabelConflict.java index cb802dc..15fe8d5 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/LabelConflict.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/LabelConflict.java @@ -1,13 +1,12 @@ package at.ac.univie.mminf.qskos4j.issues.labels.util; -import at.ac.univie.mminf.qskos4j.report.HtmlRenderable; -import org.openrdf.model.Value; +import org.openrdf.model.Resource; import java.util.HashSet; import java.util.Set; -public class LabelConflict implements HtmlRenderable { +public class LabelConflict { private Set conflicts; @@ -20,8 +19,8 @@ public LabelConflict(Set conflicts) this.conflicts = conflicts; } - public Set getAffectedResources() { - Set affectedResources = new HashSet(); + public Set getAffectedResources() { + Set affectedResources = new HashSet(); for (LabeledConcept labeledConcept : conflicts) { affectedResources.add(labeledConcept.getConcept()); @@ -48,15 +47,4 @@ public boolean equals(Object obj) { return obj instanceof LabeledConcept && conflicts.equals(obj); } - @Override - public String toHtml() { - String htmlString = "
"; - - for (LabeledConcept conflict : conflicts) { - htmlString += conflict.toHtml(); - } - - htmlString += "
"; - return htmlString; - } } 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 new file mode 100644 index 0000000..9e917f0 --- /dev/null +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/LabelConflictsResult.java @@ -0,0 +1,46 @@ +package at.ac.univie.mminf.qskos4j.issues.labels.util; + +import at.ac.univie.mminf.qskos4j.result.CollectionResult; +import org.openrdf.model.Resource; + +import java.io.BufferedWriter; +import java.io.IOException; +import java.util.Collection; +import java.util.HashSet; + +public class LabelConflictsResult extends CollectionResult { + + public LabelConflictsResult(Collection data) { + super(data); + } + + @Override + public void generateTextReport(BufferedWriter writer, ReportStyle style) throws IOException { + if (style == ReportStyle.SHORT) { + writer.write("count: " +getDistinctConcepts()+ "\n"); + } + else if (style == ReportStyle.EXTENSIVE) { + generateExtensiveTextReport(writer); + } + } + + private Collection getDistinctConcepts() { + Collection distinctConcepts = new HashSet(); + + for (LabelConflict labelConflict : getData()) { + for (Resource labeledConcept : labelConflict.getAffectedResources()) { + distinctConcepts.add(labeledConcept); + } + } + + return distinctConcepts; + } + + private void generateExtensiveTextReport(BufferedWriter writer) throws IOException { + for (LabelConflict labelConflict : getData()) { + writer.write(labelConflict.toString()); + writer.write("\n"); + } + } + +} \ No newline at end of file diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/LabeledConcept.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/LabeledConcept.java index a823aae..55f59f1 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/LabeledConcept.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/LabeledConcept.java @@ -1,17 +1,15 @@ package at.ac.univie.mminf.qskos4j.issues.labels.util; -import at.ac.univie.mminf.qskos4j.report.HtmlRenderable; import org.openrdf.model.Literal; -import org.openrdf.model.URI; -import org.openrdf.model.Value; +import org.openrdf.model.Resource; -public class LabeledConcept implements HtmlRenderable { +public class LabeledConcept { private Literal literal; private LabelType labelType; - private Value concept; + private Resource concept; - public LabeledConcept(Value concept, Literal literal, LabelType labelType) + public LabeledConcept(Resource concept, Literal literal, LabelType labelType) { this.concept = concept; this.literal = literal; @@ -22,7 +20,7 @@ public Literal getLiteral() { return literal; } - public Value getConcept() { + public Resource getConcept() { return concept; } @@ -50,19 +48,4 @@ public boolean equals(Object obj) { return concept.equals(other.concept) && literal.equals(other.literal) && labelType.equals(other.labelType); } - @Override - public String toHtml() { - String htmlString = "
"; - - if (concept instanceof URI) { - htmlString += "" +concept.stringValue()+ ""; - } - else { - htmlString += concept.stringValue(); - } - htmlString += " ("+ literal +", "+ labelType +")"; - - htmlString += "
"; - return htmlString; - } } diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/IncompleteLangCovReport.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/IncompleteLangCovResult.java similarity index 63% rename from src/main/java/at/ac/univie/mminf/qskos4j/issues/language/IncompleteLangCovReport.java rename to src/main/java/at/ac/univie/mminf/qskos4j/issues/language/IncompleteLangCovResult.java index f5aeccd..0f755dd 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/IncompleteLangCovReport.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/IncompleteLangCovResult.java @@ -1,7 +1,7 @@ package at.ac.univie.mminf.qskos4j.issues.language; -import at.ac.univie.mminf.qskos4j.report.CollectionReport; -import at.ac.univie.mminf.qskos4j.report.Report; +import at.ac.univie.mminf.qskos4j.result.CollectionResult; +import at.ac.univie.mminf.qskos4j.result.Result; import org.openrdf.model.Value; import java.io.BufferedWriter; @@ -11,12 +11,10 @@ import java.util.Map; import java.util.Map.Entry; -public class IncompleteLangCovReport extends Report { +public class IncompleteLangCovResult extends Result>> { - private Map> data; - - IncompleteLangCovReport(Map> data) { - this.data = data; + IncompleteLangCovResult(Map> data) { + super(data); } @Override @@ -24,7 +22,7 @@ protected void generateTextReport(BufferedWriter writer, ReportStyle style) thro { switch (style) { case SHORT: - new CollectionReport(data.keySet()).generateReport(writer, ReportFormat.TXT, ReportStyle.SHORT); + new CollectionResult(getData().keySet()).generateReport(writer, ReportFormat.TXT, ReportStyle.SHORT); break; case EXTENSIVE: @@ -37,7 +35,7 @@ protected void generateTextReport(BufferedWriter writer, ReportStyle style) thro private String generateExtensiveTextReport() { StringBuilder extensiveReport = new StringBuilder(); - Iterator>> entryIt = data.entrySet().iterator(); + Iterator>> entryIt = getData().entrySet().iterator(); while (entryIt.hasNext()) { Entry> entry = entryIt.next(); extensiveReport.append("concept: '") @@ -47,11 +45,16 @@ private String generateExtensiveTextReport() { .append(entryIt.hasNext() ? "\n" : ""); } - for (Entry> entry : data.entrySet()) { + for (Entry> entry : getData().entrySet()) { } return extensiveReport.toString(); } + @Override + public boolean indicatesProblem() { + return !getData().isEmpty(); + } + } diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/IncompleteLanguageCoverage.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/IncompleteLanguageCoverage.java index 5c24380..1989e5a 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/IncompleteLanguageCoverage.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/IncompleteLanguageCoverage.java @@ -2,7 +2,6 @@ import at.ac.univie.mminf.qskos4j.issues.Issue; import at.ac.univie.mminf.qskos4j.issues.concepts.InvolvedConcepts; -import at.ac.univie.mminf.qskos4j.report.Report; import at.ac.univie.mminf.qskos4j.progress.MonitoredIterator; import org.openrdf.OpenRDFException; import org.openrdf.model.Literal; @@ -18,7 +17,7 @@ /** * Finds all concepts with incomplete language coverage (Incomplete Language Coverage */ -public class IncompleteLanguageCoverage extends Issue>> { +public class IncompleteLanguageCoverage extends Issue { private final Logger logger = LoggerFactory.getLogger(IncompleteLanguageCoverage.class); @@ -39,25 +38,20 @@ public IncompleteLanguageCoverage(InvolvedConcepts involvedConcepts) { } @Override - protected Map> computeResult() throws OpenRDFException { + protected IncompleteLangCovResult invoke() throws OpenRDFException { incompleteLanguageCoverage = new HashMap>(); checkLanguageCoverage(); generateIncompleteLanguageCoverageMap(); - return incompleteLanguageCoverage; + return new IncompleteLangCovResult(incompleteLanguageCoverage); } - @Override - protected Report generateReport(Map> preparedData) { - return new IncompleteLangCovReport(incompleteLanguageCoverage); - } - private void checkLanguageCoverage() throws OpenRDFException { languageCoverage = new HashMap>(); - Iterator it = new MonitoredIterator(involvedConcepts.getResult(), progressMonitor); + Iterator it = new MonitoredIterator(involvedConcepts.getResult().getData(), progressMonitor); while (it.hasNext()) { Resource concept = it.next(); diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/MissingLangTagReport.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/MissingLangTagReport.java deleted file mode 100644 index 8ceee74..0000000 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/MissingLangTagReport.java +++ /dev/null @@ -1,54 +0,0 @@ -package at.ac.univie.mminf.qskos4j.issues.language; - -import at.ac.univie.mminf.qskos4j.report.CollectionReport; -import at.ac.univie.mminf.qskos4j.report.Report; -import org.openrdf.model.Literal; -import org.openrdf.model.Resource; - -import java.io.BufferedWriter; -import java.io.IOException; -import java.util.Collection; -import java.util.Iterator; -import java.util.Map; - -public class MissingLangTagReport extends Report { - - private Map> data; - - MissingLangTagReport(Map> data) { - this.data = data; - } - - @Override - protected void generateTextReport(BufferedWriter writer, ReportStyle style) throws IOException - { - switch (style) { - case SHORT: - new CollectionReport(data.keySet()).generateReport(writer, ReportFormat.TXT, ReportStyle.SHORT); - break; - - case EXTENSIVE: - writer.write(generateExtensiveReport()); - break; - } - } - - private String generateExtensiveReport() { - StringBuilder extensiveReport = new StringBuilder(); - - Iterator resourceIt = data.keySet().iterator(); - while (resourceIt.hasNext()) { - Resource resource = resourceIt.next(); - Collection affectedLiterals = data.get(resource); - - extensiveReport.append("resource: '") - .append(resource) - .append("', affected literals: ") - .append(affectedLiterals.toString()) - .append(resourceIt.hasNext() ? "\n" : ""); - } - - return extensiveReport.toString(); - } - -} diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/OmittedOrInvalidLanguageTags.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/OmittedOrInvalidLanguageTags.java index 3b235d7..1052480 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/OmittedOrInvalidLanguageTags.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/OmittedOrInvalidLanguageTags.java @@ -1,12 +1,11 @@ package at.ac.univie.mminf.qskos4j.issues.language; import at.ac.univie.mminf.qskos4j.issues.Issue; -import at.ac.univie.mminf.qskos4j.report.Report; -import at.ac.univie.mminf.qskos4j.util.vocab.SkosOntology; +import at.ac.univie.mminf.qskos4j.result.CollectionResult; import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; import org.openrdf.OpenRDFException; -import org.openrdf.model.Literal; -import org.openrdf.model.Resource; +import org.openrdf.model.*; +import org.openrdf.model.impl.StatementImpl; import org.openrdf.model.impl.URIImpl; import org.openrdf.query.BindingSet; import org.openrdf.query.QueryEvaluationException; @@ -18,9 +17,9 @@ /** * Finds Omitted or Invalid Language Tags. */ -public class OmittedOrInvalidLanguageTags extends Issue>> { +public class OmittedOrInvalidLanguageTags extends Issue> { - private Map> missingLangTags; + private Collection affectedStatements; private Map checkedLanguageTags; public OmittedOrInvalidLanguageTags() { @@ -33,18 +32,14 @@ public OmittedOrInvalidLanguageTags() { } @Override - protected Map> computeResult() throws OpenRDFException { - TupleQueryResult result = repCon.prepareTupleQuery(QueryLanguage.SPARQL, createMissingLangTagQuery()).evaluate(); - generateMissingLangTagMap(result); + protected CollectionResult invoke() throws OpenRDFException { + TupleQueryResult result = repCon.prepareTupleQuery(QueryLanguage.SPARQL, createMissingLangTagQuery()) + .evaluate(); - return missingLangTags; + findAffectedStatements(result); + return new CollectionResult(affectedStatements); } - @Override - protected Report generateReport(Map> preparedData) { - return new MissingLangTagReport(preparedData); - } - private String createMissingLangTagQuery() throws OpenRDFException { return SparqlPrefix.SKOS +" "+ SparqlPrefix.SKOSXL +" "+ SparqlPrefix.RDFS + @@ -60,31 +55,28 @@ private String createMissingLangTagQuery() throws OpenRDFException "}"; } - private void generateMissingLangTagMap(TupleQueryResult result) - throws QueryEvaluationException - { - missingLangTags = new HashMap>(); + private void findAffectedStatements(TupleQueryResult result) + throws QueryEvaluationException + { checkedLanguageTags = new HashMap(); - - while (result.hasNext()) { - BindingSet queryResult = result.next(); + + while (result.hasNext()) { + BindingSet queryResult = result.next(); Resource subject = (Resource) queryResult.getValue("s"); - Literal literal = (Literal) queryResult.getValue("literal"); + URI predicate = (URI) queryResult.getValue("textProp"); + Literal literal = (Literal) queryResult.getValue("literal"); - if (!SkosOntology.getInstance().isSkosResource(subject) && hasNoOrInvalidTag(literal)) { - addToMissingLangTagMap(subject, literal); - } - } - } + if (subject instanceof BNode) continue; - private boolean hasNoOrInvalidTag(Literal literal) { - if (literal.getDatatype() == null) { - String langTag = literal.getLanguage(); - return langTag == null || !isValidLangTag(langTag); + if (literal.getDatatype() == null) { + String langTag = literal.getLanguage(); + if (langTag == null || !isValidLangTag(langTag)) { + affectedStatements.add(new StatementImpl(subject, predicate, literal)); + } + } } - return false; } - + private boolean isValidLangTag(String langTag) { Boolean validTag = checkedLanguageTags.get(langTag); @@ -120,14 +112,5 @@ private boolean hasIsoLanguage(String langTag) { return hasIsoLanguage; } - - private void addToMissingLangTagMap(Resource resource, Literal literal) { - Collection literals = missingLangTags.get(resource); - if (literals == null) { - literals = new HashSet(); - missingLangTags.put(resource, literals); - } - literals.add(literal); - } } diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/outlinks/BrokenLinks.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/outlinks/BrokenLinks.java index 5603dc6..6c7d8c0 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/outlinks/BrokenLinks.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/outlinks/BrokenLinks.java @@ -1,10 +1,9 @@ package at.ac.univie.mminf.qskos4j.issues.outlinks; import at.ac.univie.mminf.qskos4j.issues.Issue; -import at.ac.univie.mminf.qskos4j.report.ExtrapolatedCollectionReport; -import at.ac.univie.mminf.qskos4j.report.Report; -import at.ac.univie.mminf.qskos4j.util.RandomSubSet; import at.ac.univie.mminf.qskos4j.progress.MonitoredIterator; +import at.ac.univie.mminf.qskos4j.result.CollectionResult; +import at.ac.univie.mminf.qskos4j.util.RandomSubSet; import at.ac.univie.mminf.qskos4j.util.url.NoContentTypeProvidedException; import at.ac.univie.mminf.qskos4j.util.url.UrlDereferencer; import at.ac.univie.mminf.qskos4j.util.url.UrlNotDereferencableException; @@ -25,7 +24,7 @@ * * Finds Broken Links. */ -public class BrokenLinks extends Issue> { +public class BrokenLinks extends Issue> { private final Logger logger = LoggerFactory.getLogger(BrokenLinks.class); private final static String NO_CONTENT_TYPE = "n/a"; @@ -49,16 +48,11 @@ public BrokenLinks(HttpURIs httpURIs) { } @Override - protected Collection computeResult() throws OpenRDFException { + protected CollectionResult invoke() throws OpenRDFException { dereferenceURIs(); - return collectUnavailableURLs(); + return new CollectionResult(collectUnavailableURLs()); } - @Override - protected Report generateReport(Collection preparedData) { - return new ExtrapolatedCollectionReport(preparedData, randomSubsetSize_percent); - } - private void dereferenceURIs() throws OpenRDFException { Collection urisToBeDereferenced = collectUrisToBeDereferenced(); @@ -85,10 +79,12 @@ private void dereferenceURIs() throws OpenRDFException private Collection collectUrisToBeDereferenced() throws OpenRDFException { if (randomSubsetSize_percent == null) { - return httpURIs.getResult(); + return httpURIs.getResult().getData(); } - RandomSubSet urisToBeDereferenced = new RandomSubSet(httpURIs.getResult(), randomSubsetSize_percent); + RandomSubSet urisToBeDereferenced = new RandomSubSet( + httpURIs.getResult().getData(), + randomSubsetSize_percent); logger.info("Using subset of " +urisToBeDereferenced.size()+ " URIs for broken link checking"); return urisToBeDereferenced; diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/outlinks/HttpURIs.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/outlinks/HttpURIs.java index 1b52d8e..074db5e 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/outlinks/HttpURIs.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/outlinks/HttpURIs.java @@ -1,8 +1,7 @@ package at.ac.univie.mminf.qskos4j.issues.outlinks; import at.ac.univie.mminf.qskos4j.issues.Issue; -import at.ac.univie.mminf.qskos4j.report.CollectionReport; -import at.ac.univie.mminf.qskos4j.report.Report; +import at.ac.univie.mminf.qskos4j.result.CollectionResult; import org.openrdf.OpenRDFException; import org.openrdf.model.Resource; import org.openrdf.model.Statement; @@ -18,7 +17,7 @@ * Date: 26.01.13 * Time: 15:23 */ -public class HttpURIs extends Issue> { +public class HttpURIs extends Issue> { private Set httpURIs = new HashSet(); private Set invalidResources = new HashSet(); @@ -32,7 +31,7 @@ public HttpURIs() { } @Override - protected Collection computeResult() throws OpenRDFException { + protected CollectionResult invoke() throws OpenRDFException { RepositoryResult result = repCon.getStatements(null, null, null, false, (Resource) null); while (result.hasNext()) { Statement st = result.next(); @@ -45,12 +44,7 @@ protected Collection computeResult() throws OpenRDFException { } } - return httpURIs; - } - - @Override - protected Report generateReport(Collection preparedData) { - return new CollectionReport(preparedData); + return new CollectionResult(httpURIs); } private void addToUrlList(Value iri) { diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/outlinks/HttpUriSchemeViolations.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/outlinks/HttpUriSchemeViolations.java index 373f1b5..ed8f41c 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/outlinks/HttpUriSchemeViolations.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/outlinks/HttpUriSchemeViolations.java @@ -1,8 +1,7 @@ package at.ac.univie.mminf.qskos4j.issues.outlinks; import at.ac.univie.mminf.qskos4j.issues.Issue; -import at.ac.univie.mminf.qskos4j.report.CollectionReport; -import at.ac.univie.mminf.qskos4j.report.Report; +import at.ac.univie.mminf.qskos4j.result.CollectionResult; import org.openrdf.OpenRDFException; import org.openrdf.model.Resource; import org.openrdf.model.Statement; @@ -10,7 +9,6 @@ import org.openrdf.model.impl.URIImpl; import org.openrdf.repository.RepositoryResult; -import java.util.Collection; import java.util.HashSet; import java.util.Set; @@ -21,7 +19,7 @@ * * Finds resources not within the HTTP URI scheme (HTTP URI Scheme Violation. */ -public class HttpUriSchemeViolations extends Issue> { +public class HttpUriSchemeViolations extends Issue> { public HttpUriSchemeViolations() { super("husv", @@ -33,7 +31,7 @@ public HttpUriSchemeViolations() { } @Override - protected Collection computeResult() throws OpenRDFException { + protected CollectionResult invoke() throws OpenRDFException { Set nonHttpURIs = new HashSet(); RepositoryResult allStatements = repCon.getStatements(null, null, null, false); @@ -44,7 +42,7 @@ protected Collection computeResult() throws OpenRDFException { } } - return nonHttpURIs; + return new CollectionResult(nonHttpURIs); } private boolean isNonHttpURI(Resource resource) { @@ -57,11 +55,4 @@ private boolean isNonHttpURI(Resource resource) { return false; } - @Override - protected Report generateReport(Collection preparedData) { - return new CollectionReport(preparedData); - } - - - } diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/outlinks/MissingOutLinks.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/outlinks/MissingOutLinks.java index f458f85..512e70f 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/outlinks/MissingOutLinks.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/outlinks/MissingOutLinks.java @@ -2,9 +2,8 @@ import at.ac.univie.mminf.qskos4j.issues.Issue; import at.ac.univie.mminf.qskos4j.issues.concepts.AuthoritativeConcepts; -import at.ac.univie.mminf.qskos4j.report.CollectionReport; -import at.ac.univie.mminf.qskos4j.report.Report; import at.ac.univie.mminf.qskos4j.progress.MonitoredIterator; +import at.ac.univie.mminf.qskos4j.result.CollectionResult; import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; import org.openrdf.OpenRDFException; import org.openrdf.model.Resource; @@ -20,7 +19,7 @@ /** * Finds concepts without links to "external" resources (Missing Out-Links. */ -public class MissingOutLinks extends Issue> { +public class MissingOutLinks extends Issue> { private Map> extResourcesForConcept; private AuthoritativeConcepts authoritativeConcepts; @@ -38,19 +37,14 @@ public MissingOutLinks(AuthoritativeConcepts authoritativeConcepts) { } @Override - public Collection computeResult() throws OpenRDFException { + protected CollectionResult invoke() throws OpenRDFException { extResourcesForConcept = new HashMap>(); - findResourcesForConcepts(authoritativeConcepts.getResult()); + findResourcesForConcepts(authoritativeConcepts.getResult().getData()); - return extractUnlinkedConcepts(); + return new CollectionResult(extractUnlinkedConcepts()); } - @Override - protected Report generateReport(Collection preparedData) { - return new CollectionReport(preparedData); - } - private void findResourcesForConcepts(Collection concepts) throws OpenRDFException { Iterator conceptIt = new MonitoredIterator(concepts, progressMonitor, "finding resources"); diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/SolelyTransitivelyRelatedConcepts.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/SolelyTransitivelyRelatedConcepts.java index 6eab0cd..ef9b67e 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/SolelyTransitivelyRelatedConcepts.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/SolelyTransitivelyRelatedConcepts.java @@ -1,29 +1,32 @@ package at.ac.univie.mminf.qskos4j.issues.relations; import at.ac.univie.mminf.qskos4j.issues.Issue; -import at.ac.univie.mminf.qskos4j.report.CollectionReport; -import at.ac.univie.mminf.qskos4j.report.Report; -import at.ac.univie.mminf.qskos4j.util.Pair; +import at.ac.univie.mminf.qskos4j.result.CollectionResult; +import at.ac.univie.mminf.qskos4j.util.Tuple; import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; import org.openrdf.OpenRDFException; +import org.openrdf.model.Resource; +import org.openrdf.model.Statement; import org.openrdf.model.URI; +import org.openrdf.model.Value; +import org.openrdf.model.impl.StatementImpl; import org.openrdf.model.impl.URIImpl; import org.openrdf.query.*; +import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; -import java.util.Set; /** * Finds Solely Transitively Related Concepts. */ -public class SolelyTransitivelyRelatedConcepts extends Issue>> { +public class SolelyTransitivelyRelatedConcepts extends Issue>> { private String[][] transitiveNontransiviteInverseProperties = { {"skos:broaderTransitive", "skos:broader", "skos:narrower"}, {"skos:narrowerTransitive", "skos:narrower", "skos:broader"}}; - - private Set> solitaryTransitiveRelations = new HashSet>(); + + private Collection solitaryTransitiveRelations; public SolelyTransitivelyRelatedConcepts() { super("strc", @@ -35,22 +38,27 @@ public SolelyTransitivelyRelatedConcepts() { } @Override - protected Collection> computeResult() throws OpenRDFException { - for (String[] transitivePropertyPair : transitiveNontransiviteInverseProperties) { - TupleQuery query = repCon.prepareTupleQuery( - QueryLanguage.SPARQL, - createSolitaryTransitiveRelationsQuery(transitivePropertyPair)); - addToResults(query.evaluate()); - } - - return solitaryTransitiveRelations; + protected CollectionResult> invoke() throws OpenRDFException { + solitaryTransitiveRelations = new ArrayList(); + for (String[] transitivePropertyPair : transitiveNontransiviteInverseProperties) { + String query = createSolitaryTransitiveRelationsQuery(transitivePropertyPair); + TupleQuery tupleQuery = repCon.prepareTupleQuery(QueryLanguage.SPARQL, query); + addToResults(tupleQuery.evaluate(), transitivePropertyPair[0]); + } + + return createReport(); } - @Override - protected Report generateReport(Collection> preparedData) { - return new CollectionReport>(preparedData); + private CollectionResult> createReport() { + Collection> relatedConcepts = new HashSet>(); + for (Statement statement : solitaryTransitiveRelations) { + relatedConcepts.add(new Tuple(statement.getSubject(), (Resource) statement.getObject())); + } + + return new CollectionResult(relatedConcepts); } + private String createSolitaryTransitiveRelationsQuery( String[] transitiveNontransiviteInverseProperties) { @@ -61,17 +69,18 @@ private String createSolitaryTransitiveRelationsQuery( "FILTER NOT EXISTS {?resource1 ("+transitiveNontransiviteInverseProperties[1]+ "|^"+transitiveNontransiviteInverseProperties[2]+")* ?resource2}" + "}"; } - - private void addToResults(TupleQueryResult result) - throws QueryEvaluationException - { - while (result.hasNext()) { - BindingSet queryResult = result.next(); - URI resource1 = (URI) queryResult.getValue("resource1"); - URI resource2 = (URI) queryResult.getValue("resource2"); - - solitaryTransitiveRelations.add(new Pair(resource1, resource2)); - } - } + + private void addToResults(TupleQueryResult result, String solitaryRelation) + throws QueryEvaluationException + { + while (result.hasNext()) { + BindingSet queryResult = result.next(); + Resource resource1 = (Resource) queryResult.getValue("resource1"); + Value resource2 = queryResult.getValue("resource2"); + URI relation = new URIImpl(solitaryRelation.replace("skos:", SparqlPrefix.SKOS.getNameSpace())); + + solitaryTransitiveRelations.add(new StatementImpl(resource1, relation, resource2)); + } + } } diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/UnidirectionallyRelatedConcepts.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/UnidirectionallyRelatedConcepts.java index c8eaa18..4b8eaaa 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/UnidirectionallyRelatedConcepts.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/UnidirectionallyRelatedConcepts.java @@ -2,8 +2,9 @@ import at.ac.univie.mminf.qskos4j.issues.Issue; import at.ac.univie.mminf.qskos4j.issues.concepts.AuthoritativeConcepts; -import at.ac.univie.mminf.qskos4j.report.Report; -import at.ac.univie.mminf.qskos4j.util.Pair; +import at.ac.univie.mminf.qskos4j.result.CollectionResult; +import at.ac.univie.mminf.qskos4j.util.Tuple; +import at.ac.univie.mminf.qskos4j.util.graph.UnidirectionalRelation; import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; import org.openrdf.OpenRDFException; import org.openrdf.model.Resource; @@ -13,13 +14,14 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.HashMap; -import java.util.Map; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; /** * Finds Unidirectionally Related Concepts. */ - public class UnidirectionallyRelatedConcepts extends Issue, String>> { + public class UnidirectionallyRelatedConcepts extends Issue> { private String[][] inversePropertyPairs = { {"skos:broader", "skos:narrower"}, @@ -33,7 +35,8 @@ public class UnidirectionallyRelatedConcepts extends Issue, S }; private final Logger logger = LoggerFactory.getLogger(UnidirectionallyRelatedConcepts.class); - private Map, String> omittedInverseRelations = new HashMap, String>(); + + private Collection unidirectionalRelations; private AuthoritativeConcepts authoritativeConcepts; public UnidirectionallyRelatedConcepts(AuthoritativeConcepts authoritativeConcepts) { @@ -48,23 +51,19 @@ public UnidirectionallyRelatedConcepts(AuthoritativeConcepts authoritativeConcep } @Override - protected Map, String> computeResult() throws OpenRDFException { - + protected CollectionResult invoke() throws OpenRDFException { + unidirectionalRelations = new HashSet(); String authResourceIdentifier = authoritativeConcepts.getAuthResourceIdentifier(); for (String[] inversePropertyPair : inversePropertyPairs) { TupleQuery query = repCon.prepareTupleQuery(QueryLanguage.SPARQL, createOmittedRelationsQuery(inversePropertyPair)); - addToOmittedInverseRelationsMap(query.evaluate(), inversePropertyPair, authResourceIdentifier); + + addToOmittedInverseRelationsMap(query.evaluate(), inversePropertyPair, authResourceIdentifier); } - return omittedInverseRelations; + return new CollectionResult(unidirectionalRelations); } - @Override - protected Report generateReport(Map, String> preparedData) { - return new UnidirectionallyRelatedConceptsReport(preparedData); - } - private String createOmittedRelationsQuery(String[] inverseRelations) { return SparqlPrefix.SKOS +" "+ SparqlPrefix.RDFS + "SELECT DISTINCT ?resource1 ?resource2 "+ @@ -85,12 +84,14 @@ private void addToOmittedInverseRelationsMap( while (result.hasNext()) { BindingSet queryResult = result.next(); - Value value1 = queryResult.getValue("resource1"); - Value value2 = queryResult.getValue("resource2"); + Resource resource1 = (Resource) queryResult.getValue("resource1"); + Resource resource2 = (Resource) queryResult.getValue("resource2"); String inverseProperties = inversePropertyPair[0] +"/"+ inversePropertyPair[1]; - if (bothResourcesAreAuthoritative(value1, value2, authResourceIdentifier)) { - addToMap(value1, value2, inverseProperties); + if (bothResourcesAreAuthoritative(resource1, resource2, authResourceIdentifier)) { + unidirectionalRelations.add(new UnidirectionalRelation( + new Tuple(resource1, resource2), + Arrays.asList(inversePropertyPair))); } } } @@ -102,19 +103,4 @@ private boolean bothResourcesAreAuthoritative(Value res1, Value res2, String aut res2.stringValue().contains(authResourceIdentifier); } - private void addToMap(Value value1, Value value2, String inverseProperties) - { - try { - Resource resource1 = (Resource) value1; - Resource resource2 = (Resource) value2; - - omittedInverseRelations.put( - new Pair(resource1, resource2), - inverseProperties); - } - catch (ClassCastException e) { - logger.error("Resource expected for relation " +inverseProperties+ " (" +value1+ " <-> " +value2+ ")"); - } - } - } diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/UnidirectionallyRelatedConceptsReport.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/UnidirectionallyRelatedConceptsReport.java deleted file mode 100644 index 1f07aea..0000000 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/UnidirectionallyRelatedConceptsReport.java +++ /dev/null @@ -1,45 +0,0 @@ -package at.ac.univie.mminf.qskos4j.issues.relations; - -import at.ac.univie.mminf.qskos4j.report.CollectionReport; -import at.ac.univie.mminf.qskos4j.report.Report; -import at.ac.univie.mminf.qskos4j.util.Pair; -import org.openrdf.model.Resource; - -import java.io.BufferedWriter; -import java.io.IOException; -import java.util.Map; - -public class UnidirectionallyRelatedConceptsReport extends Report { - - private Map, String> data; - - public UnidirectionallyRelatedConceptsReport(Map, String> data) { - this.data = data; - } - - @Override - protected void generateTextReport(BufferedWriter writer, ReportStyle style) throws IOException - { - switch (style) { - case SHORT: - new CollectionReport>(data.keySet()).generateReport(writer, ReportFormat.TXT, ReportStyle.SHORT); - break; - - case EXTENSIVE: - writer.write(generateExtensiveReport()); - break; - } - } - - private String generateExtensiveReport() - { - StringBuilder extensiveReport = new StringBuilder(); - - for (Pair concepts : data.keySet()) { - extensiveReport.append("concepts: ").append(concepts.toString()).append(", related by: '").append(data.get(concepts)).append("'\n"); - } - - return extensiveReport.toString(); - } - -} diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/ValuelessAssociativeRelations.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/ValuelessAssociativeRelations.java index d8583b6..ef6db73 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/ValuelessAssociativeRelations.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/ValuelessAssociativeRelations.java @@ -1,11 +1,11 @@ package at.ac.univie.mminf.qskos4j.issues.relations; import at.ac.univie.mminf.qskos4j.issues.Issue; -import at.ac.univie.mminf.qskos4j.report.CollectionReport; -import at.ac.univie.mminf.qskos4j.report.Report; -import at.ac.univie.mminf.qskos4j.util.Pair; +import at.ac.univie.mminf.qskos4j.result.CollectionResult; +import at.ac.univie.mminf.qskos4j.util.graph.AssociativeRelation; import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; import org.openrdf.OpenRDFException; +import org.openrdf.model.Resource; import org.openrdf.model.URI; import org.openrdf.model.impl.URIImpl; import org.openrdf.query.*; @@ -16,7 +16,7 @@ /** * Finds all Valueless Associative Relations. */ -public class ValuelessAssociativeRelations extends Issue>> { +public class ValuelessAssociativeRelations extends Issue> { public ValuelessAssociativeRelations() { super("var", @@ -27,23 +27,18 @@ public ValuelessAssociativeRelations() { } @Override - protected Collection> computeResult() throws OpenRDFException { - Collection> redundantAssociativeRelations = new HashSet>(); + protected CollectionResult invoke() throws OpenRDFException { + Collection foundValuelessRelations = new HashSet(); TupleQuery query = repCon.prepareTupleQuery(QueryLanguage.SPARQL, createRedundantAssociativeRelationsQuery()); - generateResultsList(redundantAssociativeRelations, query.evaluate()); + generateResultsList(foundValuelessRelations, query.evaluate()); - return redundantAssociativeRelations; + return new CollectionResult(foundValuelessRelations); } - @Override - protected Report generateReport(Collection> preparedData) { - return new CollectionReport>(preparedData); - } - private String createRedundantAssociativeRelationsQuery() { return SparqlPrefix.SKOS + - "SELECT ?parent ?child ?otherchild "+ + "SELECT ?parent ?child ?otherchild ?relation "+ "WHERE {" + "{" + "?parent skos:narrower|skos:narrowerTransitive|^skos:broader|^skos:broaderTransitive ?child . " + @@ -55,20 +50,61 @@ private String createRedundantAssociativeRelationsQuery() { "?otherchild skos:narrower|skos:narrowerTransitive|^skos:broader|^skos:broaderTransitive ?parent . " + "}" + - "?child skos:related|skos:relatedMatch ?otherchild. "+ + "?child ?relation ?otherchild. "+ + "FILTER (?relation IN (skos:related, skos:relatedMatch))"+ "}"; } - private void generateResultsList(Collection> allResults, TupleQueryResult result) + private void generateResultsList(Collection allResults, TupleQueryResult result) throws QueryEvaluationException { while (result.hasNext()) { BindingSet queryResult = result.next(); - URI child = (URI) queryResult.getValue("child"); - URI otherchild = (URI) queryResult.getValue("otherchild"); - allResults.add(new Pair(child, otherchild)); + Resource parent = (Resource) queryResult.getValue("parent"); + Resource child = (Resource) queryResult.getValue("child"); + Resource otherchild = (Resource) queryResult.getValue("otherchild"); + + URI relation = (URI) queryResult.getValue("relation"); + + allResults.add(new ValuelessAssociativeRelation( + new AssociativeRelation(child, otherchild, relation), + parent)); } } + public class ValuelessAssociativeRelation { + + private AssociativeRelation relatedConcepts; + private Resource commonParent; + + ValuelessAssociativeRelation(AssociativeRelation relatedConcepts, Resource commonParent) { + this.relatedConcepts = relatedConcepts; + this.commonParent = commonParent; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof ValuelessAssociativeRelation) { + ValuelessAssociativeRelation other = (ValuelessAssociativeRelation) obj; + return relatedConcepts.equals(other.relatedConcepts) && commonParent.equals(other.commonParent); + } + return false; + } + + @Override + public int hashCode() { + return relatedConcepts.hashCode() + commonParent.hashCode(); + } + + public AssociativeRelation getRelatedConcepts() { + return relatedConcepts; + } + + public Resource getCommonParent() { + return commonParent; + } + + } + } diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/skosintegrity/HierarchicalRedundancy.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/skosintegrity/HierarchicalRedundancy.java index 8c136d9..2da459d 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/skosintegrity/HierarchicalRedundancy.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/skosintegrity/HierarchicalRedundancy.java @@ -1,9 +1,8 @@ package at.ac.univie.mminf.qskos4j.issues.skosintegrity; import at.ac.univie.mminf.qskos4j.issues.Issue; -import at.ac.univie.mminf.qskos4j.report.CollectionReport; -import at.ac.univie.mminf.qskos4j.report.Report; -import at.ac.univie.mminf.qskos4j.util.Pair; +import at.ac.univie.mminf.qskos4j.result.CollectionResult; +import at.ac.univie.mminf.qskos4j.util.Tuple; import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; import org.openrdf.OpenRDFException; import org.openrdf.model.Resource; @@ -15,10 +14,10 @@ import java.util.Collection; import java.util.HashSet; -public class HierarchicalRedundancy extends Issue>> { +public class HierarchicalRedundancy extends Issue>> { private String HIER_PROPERTIES = "skos:broaderTransitive|^skos:narrowerTransitive"; - private Collection> hierarchicalRedundancies; + private Collection> hierarchicalRedundancies; public HierarchicalRedundancy() { super("hr", @@ -29,8 +28,8 @@ public HierarchicalRedundancy() { } @Override - protected Collection> computeResult() throws OpenRDFException { - hierarchicalRedundancies = new HashSet>(); + protected CollectionResult> invoke() throws OpenRDFException { + hierarchicalRedundancies = new HashSet>(); TupleQueryResult result = repCon.prepareTupleQuery(QueryLanguage.SPARQL, createQuery()).evaluate(); while (result.hasNext()) { @@ -38,10 +37,10 @@ protected Collection> computeResult() throws OpenRDFException { Resource concept = (Resource) bs.getValue("concept"); Resource otherConcept = (Resource) bs.getValue("otherConcept"); - hierarchicalRedundancies.add(new Pair(concept, otherConcept)); + hierarchicalRedundancies.add(new Tuple(concept, otherConcept)); } - return hierarchicalRedundancies; + return new CollectionResult>(hierarchicalRedundancies); } private String createQuery() { @@ -52,9 +51,4 @@ private String createQuery() { "}"; } - @Override - protected Report generateReport(Collection> preparedData) { - return new CollectionReport>(hierarchicalRedundancies); - } - } diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/skosintegrity/MappingClashes.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/skosintegrity/MappingClashes.java index c087b0a..3501a08 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/skosintegrity/MappingClashes.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/skosintegrity/MappingClashes.java @@ -1,13 +1,12 @@ package at.ac.univie.mminf.qskos4j.issues.skosintegrity; import at.ac.univie.mminf.qskos4j.issues.Issue; -import at.ac.univie.mminf.qskos4j.report.CollectionReport; -import at.ac.univie.mminf.qskos4j.report.Report; -import at.ac.univie.mminf.qskos4j.util.Pair; +import at.ac.univie.mminf.qskos4j.result.CollectionResult; +import at.ac.univie.mminf.qskos4j.util.Tuple; import at.ac.univie.mminf.qskos4j.util.TupleQueryResultUtil; import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; import org.openrdf.OpenRDFException; -import org.openrdf.model.Value; +import org.openrdf.model.Resource; import org.openrdf.model.impl.URIImpl; import org.openrdf.query.QueryLanguage; import org.openrdf.query.TupleQuery; @@ -18,7 +17,7 @@ /** * Finds Exact vs. Associative and Hierarchical Mapping Clashes. */ -public class MappingClashes extends Issue>> { +public class MappingClashes extends Issue>> { public MappingClashes() { super("mc", @@ -30,21 +29,16 @@ public MappingClashes() { } @Override - protected Collection> computeResult() throws OpenRDFException { + protected CollectionResult> invoke() throws OpenRDFException { TupleQuery query = repCon.prepareTupleQuery(QueryLanguage.SPARQL, createExVsAssMappingQuery()); - Collection> valuePairs = TupleQueryResultUtil.createCollectionOfValuePairs( + Collection> valuePairs = TupleQueryResultUtil.createCollectionOfResourcePairs( query.evaluate(), "concept1", "concept2"); - Collection> distinctPairs = new HashSet>(); + Collection> distinctPairs = new HashSet>(); distinctPairs.addAll(valuePairs); - return distinctPairs; - } - - @Override - protected Report generateReport(Collection> preparedData) { - return new CollectionReport>(preparedData); + return new CollectionResult>(distinctPairs); } private String createExVsAssMappingQuery() { diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/skosintegrity/RelationClashes.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/skosintegrity/RelationClashes.java index 20c9f11..7d7ecc8 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/skosintegrity/RelationClashes.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/skosintegrity/RelationClashes.java @@ -2,16 +2,16 @@ import at.ac.univie.mminf.qskos4j.issues.HierarchyGraphBuilder; import at.ac.univie.mminf.qskos4j.issues.Issue; -import at.ac.univie.mminf.qskos4j.report.CollectionReport; -import at.ac.univie.mminf.qskos4j.report.Report; -import at.ac.univie.mminf.qskos4j.util.Pair; +import at.ac.univie.mminf.qskos4j.progress.MonitoredIterator; +import at.ac.univie.mminf.qskos4j.result.CollectionResult; +import at.ac.univie.mminf.qskos4j.util.Tuple; import at.ac.univie.mminf.qskos4j.util.TupleQueryResultUtil; import at.ac.univie.mminf.qskos4j.util.graph.NamedEdge; -import at.ac.univie.mminf.qskos4j.progress.MonitoredIterator; import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; import org.jgrapht.Graph; import org.jgrapht.alg.DijkstraShortestPath; import org.openrdf.OpenRDFException; +import org.openrdf.model.Resource; import org.openrdf.model.Value; import org.openrdf.model.impl.URIImpl; import org.openrdf.query.QueryLanguage; @@ -25,7 +25,7 @@ /** * Finds Associative vs. Hierarchical Relation Clashes. */ -public class RelationClashes extends Issue>> { +public class RelationClashes extends Issue>> { private HierarchyGraphBuilder hierarchyGraphBuilder; @@ -41,17 +41,17 @@ public RelationClashes(HierarchyGraphBuilder hierarchyGraphBuilder) { } @Override - protected Collection> computeResult() throws OpenRDFException { - Graph hierarchyGraph = hierarchyGraphBuilder.createGraph(); + protected CollectionResult> invoke() throws OpenRDFException { + Graph hierarchyGraph = hierarchyGraphBuilder.createGraph(); - Collection> clashes = new HashSet>(); + Collection> clashes = new HashSet>(); - Iterator> it = new MonitoredIterator>( + Iterator> it = new MonitoredIterator>( findRelatedConcepts(), progressMonitor); while (it.hasNext()) { - Pair conceptPair = it.next(); + Tuple conceptPair = it.next(); try { if (pathExists(hierarchyGraph, conceptPair)) { clashes.add(conceptPair); @@ -62,17 +62,12 @@ protected Collection> computeResult() throws OpenRDFException { } } - return clashes; - } - - @Override - protected Report generateReport(Collection> preparedData) { - return new CollectionReport>(preparedData); + return new CollectionResult>(clashes); } - private Collection> findRelatedConcepts() throws OpenRDFException { + private Collection> findRelatedConcepts() throws OpenRDFException { TupleQueryResult result = repCon.prepareTupleQuery(QueryLanguage.SPARQL, createRelatedConceptsQuery()).evaluate(); - return TupleQueryResultUtil.createCollectionOfValuePairs(result, "concept1", "concept2"); + return TupleQueryResultUtil.createCollectionOfResourcePairs(result, "concept1", "concept2"); } private String createRelatedConceptsQuery() { @@ -82,13 +77,13 @@ private String createRelatedConceptsQuery() { "}"; } - private boolean pathExists(Graph hierarchyGraph, Pair conceptPair) { - if (new DijkstraShortestPath( + private boolean pathExists(Graph hierarchyGraph, Tuple conceptPair) { + if (new DijkstraShortestPath( hierarchyGraph, conceptPair.getFirst(), conceptPair.getSecond()).getPathEdgeList() == null) { - return new DijkstraShortestPath( + return new DijkstraShortestPath( hierarchyGraph, conceptPair.getSecond(), conceptPair.getFirst()).getPathEdgeList() != null; diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/skosintegrity/UndefinedSkosResources.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/skosintegrity/UndefinedSkosResources.java index 4b17a58..46ffed0 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/skosintegrity/UndefinedSkosResources.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/skosintegrity/UndefinedSkosResources.java @@ -1,8 +1,7 @@ package at.ac.univie.mminf.qskos4j.issues.skosintegrity; import at.ac.univie.mminf.qskos4j.issues.Issue; -import at.ac.univie.mminf.qskos4j.report.CollectionReport; -import at.ac.univie.mminf.qskos4j.report.Report; +import at.ac.univie.mminf.qskos4j.result.CollectionResult; import at.ac.univie.mminf.qskos4j.util.TupleQueryResultUtil; import at.ac.univie.mminf.qskos4j.util.vocab.SkosOntology; import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; @@ -23,7 +22,7 @@ * Undefined SKOS Resources * ). */ -public class UndefinedSkosResources extends Issue> { +public class UndefinedSkosResources extends Issue> { private Map> deprecatedProperties, illegalTerms; @@ -37,18 +36,13 @@ public UndefinedSkosResources() { } @Override - protected Collection computeResult() throws OpenRDFException { + protected CollectionResult invoke() throws OpenRDFException { findDeprecatedProperties(); findIllegalTerms(); - return collectUndefinedResources(); + return new CollectionResult(collectUndefinedResources()); } - @Override - protected Report generateReport(Collection preparedData) { - return new CollectionReport(preparedData); - } - private void findDeprecatedProperties() throws OpenRDFException { TupleQuery query = repCon.prepareTupleQuery(QueryLanguage.SPARQL, createDeprecatedPropertiesQuery()); diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/report/CollectionReport.java b/src/main/java/at/ac/univie/mminf/qskos4j/report/CollectionReport.java deleted file mode 100644 index b320e27..0000000 --- a/src/main/java/at/ac/univie/mminf/qskos4j/report/CollectionReport.java +++ /dev/null @@ -1,74 +0,0 @@ -package at.ac.univie.mminf.qskos4j.report; - -import java.io.BufferedWriter; -import java.io.IOException; -import java.util.Collection; -import java.util.Iterator; - -/** - * Report class that holds a collection of objects of interest - * - * @author christian - * - * @param type of the collection's content - */ -public class CollectionReport extends Report { - - private Collection data; - - public CollectionReport(Collection data) { - this.data = data; - } - - @Override - protected void generateTextReport(BufferedWriter osw, ReportStyle style) throws IOException - { - switch (style) { - case SHORT: - osw.write("count: " + data.size()); - break; - - case EXTENSIVE: - osw.write(generateExtensiveTextReport()); - break; - } - } - - public String generateExtensiveTextReport() { - StringBuilder report = new StringBuilder(); - Iterator dataIt = data.iterator(); - while (dataIt.hasNext()) { - report.append(dataIt.next().toString()).append(dataIt.hasNext() ? "\n" : ""); - } - - return report.toString(); - } - - @Override - public void generateHtmlReport(BufferedWriter writer, ReportStyle style) throws IOException { - writer.write("
"); - - switch (style) { - case SHORT: - generateTextReport(writer, ReportStyle.SHORT); - break; - - case EXTENSIVE: - generateExtensiveHtmlReport(writer); - break; - } - - writer.write("
"); - } - - public void generateExtensiveHtmlReport(BufferedWriter writer) throws IOException { - for (T collectionElement : data) { - if (collectionElement instanceof HtmlRenderable) { - writer.write("

" +((HtmlRenderable) collectionElement).toHtml()+ "

"); - } - else { - throw new UnsupportedOperationException("Collection elements of type " +collectionElement.getClass().getName()+ " have no HTML representation"); - } - } - } -} diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/report/HtmlRenderable.java b/src/main/java/at/ac/univie/mminf/qskos4j/report/HtmlRenderable.java deleted file mode 100644 index aefe7f2..0000000 --- a/src/main/java/at/ac/univie/mminf/qskos4j/report/HtmlRenderable.java +++ /dev/null @@ -1,7 +0,0 @@ -package at.ac.univie.mminf.qskos4j.report; - -public interface HtmlRenderable { - - public String toHtml(); - -} diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/result/CollectionResult.java b/src/main/java/at/ac/univie/mminf/qskos4j/result/CollectionResult.java new file mode 100644 index 0000000..579e0d0 --- /dev/null +++ b/src/main/java/at/ac/univie/mminf/qskos4j/result/CollectionResult.java @@ -0,0 +1,43 @@ +package at.ac.univie.mminf.qskos4j.result; + +import java.io.BufferedWriter; +import java.io.IOException; +import java.util.Collection; +import java.util.Iterator; + +public class CollectionResult extends Result> { + + public CollectionResult(Collection data) { + super(data); + } + + @Override + protected void generateTextReport(BufferedWriter osw, ReportStyle style) throws IOException + { + switch (style) { + case SHORT: + osw.write("count: " + getData().size()); + break; + + case EXTENSIVE: + osw.write(generateExtensiveTextReport()); + break; + } + } + + @Override + public boolean indicatesProblem() { + return !getData().isEmpty(); + } + + public String generateExtensiveTextReport() { + StringBuilder report = new StringBuilder(); + Iterator dataIt = getData().iterator(); + while (dataIt.hasNext()) { + report.append(dataIt.next().toString()).append(dataIt.hasNext() ? "\n" : ""); + } + + return report.toString(); + } + +} diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/report/ExtrapolatedCollectionReport.java b/src/main/java/at/ac/univie/mminf/qskos4j/result/ExtrapolatedCollectionResult.java similarity index 83% rename from src/main/java/at/ac/univie/mminf/qskos4j/report/ExtrapolatedCollectionReport.java rename to src/main/java/at/ac/univie/mminf/qskos4j/result/ExtrapolatedCollectionResult.java index 9f8c65b..ac94666 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/report/ExtrapolatedCollectionReport.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/result/ExtrapolatedCollectionResult.java @@ -1,15 +1,15 @@ -package at.ac.univie.mminf.qskos4j.report; +package at.ac.univie.mminf.qskos4j.result; import java.io.BufferedWriter; import java.io.IOException; import java.util.Collection; -public class ExtrapolatedCollectionReport extends CollectionReport { +public class ExtrapolatedCollectionResult extends CollectionResult { private Float subsetSize_percent; private Collection data; - public ExtrapolatedCollectionReport(Collection data, Float subsetSize_percent) + public ExtrapolatedCollectionResult(Collection data, Float subsetSize_percent) { super(data); this.data = data; diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/report/NumberReport.java b/src/main/java/at/ac/univie/mminf/qskos4j/result/NumberResult.java similarity index 51% rename from src/main/java/at/ac/univie/mminf/qskos4j/report/NumberReport.java rename to src/main/java/at/ac/univie/mminf/qskos4j/result/NumberResult.java index e7499a4..3375fd4 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/report/NumberReport.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/result/NumberResult.java @@ -1,22 +1,20 @@ -package at.ac.univie.mminf.qskos4j.report; +package at.ac.univie.mminf.qskos4j.result; import java.io.BufferedWriter; import java.io.IOException; -public class NumberReport extends Report { +public class NumberResult extends Result { - private T data; - - public NumberReport(T data) { - this.data = data; - } + public NumberResult(T data) { + super(data); + } @Override protected void generateTextReport(BufferedWriter osw, ReportStyle style) throws IOException { switch (style) { case SHORT: - osw.write("value: " +data.toString()); + osw.write("value: " +getData().toString()); break; case EXTENSIVE: @@ -24,4 +22,9 @@ protected void generateTextReport(BufferedWriter osw, ReportStyle style) throws } } + @Override + public boolean indicatesProblem() { + return getData().intValue() != 0; + } + } diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/result/ResourceCollectionsResult.java b/src/main/java/at/ac/univie/mminf/qskos4j/result/ResourceCollectionsResult.java new file mode 100644 index 0000000..afe1b33 --- /dev/null +++ b/src/main/java/at/ac/univie/mminf/qskos4j/result/ResourceCollectionsResult.java @@ -0,0 +1,47 @@ +package at.ac.univie.mminf.qskos4j.result; + +import org.openrdf.model.Resource; +import org.openrdf.model.Value; + +import java.io.BufferedWriter; +import java.io.IOException; +import java.util.Collection; +import java.util.Iterator; + +public class ResourceCollectionsResult extends CollectionResult> { + + private String valueSetName; + + public ResourceCollectionsResult(Collection> data, String valueSetName) { + super(data); + this.valueSetName = valueSetName; + } + + @Override + public void generateTextReport(BufferedWriter osw, ReportStyle style) throws IOException { + StringBuilder report = new StringBuilder(); + long compCount = 1; + + if (style == ReportStyle.SHORT) { + report.append("count: ").append(getData().size()).append("\n"); + } + + Iterator> componentIt = getData().iterator(); + while (componentIt.hasNext()) { + Collection component = componentIt.next(); + + report.append(valueSetName +" ").append(compCount).append(", size: ").append(component.size()); + if (style == ReportStyle.EXTENSIVE) { + for (Value value : component) { + report.append("\n\t").append(value.toString()); + } + } + compCount++; + + if (componentIt.hasNext()) report.append("\n"); + } + + osw.write(report.toString()); + } + +} diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/report/Report.java b/src/main/java/at/ac/univie/mminf/qskos4j/result/Result.java similarity index 80% rename from src/main/java/at/ac/univie/mminf/qskos4j/report/Report.java rename to src/main/java/at/ac/univie/mminf/qskos4j/result/Result.java index bee518f..d65d4a5 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/report/Report.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/result/Result.java @@ -1,14 +1,24 @@ -package at.ac.univie.mminf.qskos4j.report; +package at.ac.univie.mminf.qskos4j.result; import java.io.BufferedWriter; import java.io.IOException; import java.io.StringWriter; -public abstract class Report { +public abstract class Result { - public enum ReportFormat {TXT, DOT, RDF, HTML} + public enum ReportFormat {TXT, DOT} public enum ReportStyle {SHORT, EXTENSIVE} + private T data; + + protected Result(T data) { + this.data = data; + } + + public T getData() { + return data; + } + public final void generateReport(BufferedWriter writer, ReportFormat format) throws IOException { generateReport(writer, format, ReportStyle.SHORT); @@ -25,10 +35,6 @@ public final void generateReport(BufferedWriter writer, ReportFormat format, Rep generateDotReport(writer); break; - case HTML: - generateHtmlReport(writer, style); - break; - default: throw new UnsupportedReportFormatException(format); } @@ -42,10 +48,6 @@ public void generateDotReport(BufferedWriter writer) throws IOException { throw new UnsupportedOperationException(); } - public void generateHtmlReport(BufferedWriter writer, ReportStyle style) throws IOException { - throw new UnsupportedOperationException(); - } - @Override public String toString() { try { @@ -58,5 +60,7 @@ public String toString() { return "Could not create short text report (" +e.getMessage()+ ")"; } } + + public abstract boolean indicatesProblem(); } diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/report/UnsupportedReportFormatException.java b/src/main/java/at/ac/univie/mminf/qskos4j/result/UnsupportedReportFormatException.java similarity index 61% rename from src/main/java/at/ac/univie/mminf/qskos4j/report/UnsupportedReportFormatException.java rename to src/main/java/at/ac/univie/mminf/qskos4j/result/UnsupportedReportFormatException.java index 43f0621..1280a27 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/report/UnsupportedReportFormatException.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/result/UnsupportedReportFormatException.java @@ -1,14 +1,14 @@ -package at.ac.univie.mminf.qskos4j.report; +package at.ac.univie.mminf.qskos4j.result; public class UnsupportedReportFormatException extends RuntimeException { - private final static String MESSAGE = "Unsupported Report Format: '"; + private final static String MESSAGE = "Unsupported Result Format: '"; public UnsupportedReportFormatException(String reportFormat) { super(MESSAGE +reportFormat+ "'"); } - public UnsupportedReportFormatException(Report.ReportFormat format) { + public UnsupportedReportFormatException(Result.ReportFormat format) { super(MESSAGE +format.toString()+ "'"); } diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/util/Pair.java b/src/main/java/at/ac/univie/mminf/qskos4j/util/Pair.java deleted file mode 100644 index 1f9c434..0000000 --- a/src/main/java/at/ac/univie/mminf/qskos4j/util/Pair.java +++ /dev/null @@ -1,43 +0,0 @@ -package at.ac.univie.mminf.qskos4j.util; - -public class Pair { - - private T first, second; - - public Pair(T first, T second) { - this.first = first; - this.second = second; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof Pair) { - Pair other = (Pair) obj; - - return (first.equals(other.first) && second.equals(other.second)) || - (first.equals(other.second) && second.equals(other.first)); - } - return false; - } - - public int hashCode() { - int hashFirst = first != null ? first.hashCode() : 0; - int hashSecond = second != null ? second.hashCode() : 0; - - return hashFirst + hashSecond; - } - - @Override - public String toString() { - return "("+first.toString() +", "+ second.toString() +")"; - } - - public T getFirst() { - return first; - } - - public T getSecond() { - return second; - } - -} \ No newline at end of file diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/util/Tuple.java b/src/main/java/at/ac/univie/mminf/qskos4j/util/Tuple.java new file mode 100644 index 0000000..26cd71d --- /dev/null +++ b/src/main/java/at/ac/univie/mminf/qskos4j/util/Tuple.java @@ -0,0 +1,68 @@ +package at.ac.univie.mminf.qskos4j.util; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; + +public class Tuple { + + private List elements; + + public Tuple(T ... initElements) { + elements = new ArrayList(); + elements.addAll(Arrays.asList(initElements)); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof Tuple)) return false; + + Tuple other = (Tuple) obj; + if (other.elements.size() != elements.size()) return false; + + for (T element : elements) { + if (!other.elements.contains(element)) return false; + } + + return true; + } + + public int hashCode() { + int hashCode = 0; + for (T element : elements) { + hashCode += element.hashCode(); + } + return hashCode; + } + + @Override + public String toString() { + String ret = "("; + + Iterator it = elements.iterator(); + while (it.hasNext()) { + ret += it.next().toString() + (it.hasNext() ? ", " : ""); + } + + ret += ")"; + return ret; + } + + public T get(int index) { + return elements.get(index); + } + + public T getFirst() { + return elements.get(0); + } + + public T getSecond() { + return elements.get(1); + } + + public List getElements() { + return elements; + } + +} \ No newline at end of file diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/util/TupleQueryResultUtil.java b/src/main/java/at/ac/univie/mminf/qskos4j/util/TupleQueryResultUtil.java index 42ce672..dff6e77 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/util/TupleQueryResultUtil.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/util/TupleQueryResultUtil.java @@ -1,6 +1,7 @@ package at.ac.univie.mminf.qskos4j.util; import org.openrdf.OpenRDFException; +import org.openrdf.model.Resource; import org.openrdf.model.Value; import org.openrdf.query.BindingSet; import org.openrdf.query.QueryEvaluationException; @@ -44,17 +45,17 @@ public static long countResults(TupleQueryResult result) throws QueryEvaluationE return count; } - public static Collection> createCollectionOfValuePairs(TupleQueryResult result, String value1, String value2) + public static Collection> createCollectionOfResourcePairs(TupleQueryResult result, String value1, String value2) throws OpenRDFException { - Collection> resultCollection = new ArrayList>(); + Collection> resultCollection = new ArrayList>(); while (result.hasNext()) { BindingSet queryResult = result.next(); - Value concept1 = queryResult.getValue(value1); - Value concept2 = queryResult.getValue(value2); + Resource concept1 = (Resource) queryResult.getValue(value1); + Resource concept2 = (Resource) queryResult.getValue(value2); - resultCollection.add(new Pair(concept1, concept2)); + resultCollection.add(new Tuple(concept1, concept2)); } return resultCollection; diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/util/graph/AssociativeRelation.java b/src/main/java/at/ac/univie/mminf/qskos4j/util/graph/AssociativeRelation.java new file mode 100644 index 0000000..793af73 --- /dev/null +++ b/src/main/java/at/ac/univie/mminf/qskos4j/util/graph/AssociativeRelation.java @@ -0,0 +1,38 @@ +package at.ac.univie.mminf.qskos4j.util.graph; + +import at.ac.univie.mminf.qskos4j.util.Tuple; +import org.openrdf.model.Resource; +import org.openrdf.model.URI; + +public class AssociativeRelation { + + private Tuple concepts; + private URI uri; + + public AssociativeRelation(Resource src, Resource dst, URI uri) { + concepts = new Tuple(src, dst); + this.uri = uri; + } + + public Tuple getConcepts() { + return concepts; + } + + public URI getUri() { + return uri; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof AssociativeRelation) { + AssociativeRelation other = (AssociativeRelation) obj; + return other.concepts.equals(concepts) && other.uri.equals(uri); + } + return false; + } + + @Override + public int hashCode() { + return concepts.hashCode() + uri.hashCode(); + } +} diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/util/graph/GraphExporter.java b/src/main/java/at/ac/univie/mminf/qskos4j/util/graph/GraphExporter.java index 931deb3..85a3c5d 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/util/graph/GraphExporter.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/util/graph/GraphExporter.java @@ -7,44 +7,42 @@ import org.jgrapht.ext.StringEdgeNameProvider; import org.jgrapht.ext.VertexNameProvider; import org.jgrapht.graph.DirectedSubgraph; -import org.openrdf.model.Value; +import org.openrdf.model.Resource; import java.io.StringWriter; import java.util.Collection; import java.util.HashSet; -import java.util.Iterator; import java.util.Set; public class GraphExporter { - private DirectedGraph graph; + private DirectedGraph graph; - public GraphExporter(DirectedGraph graph) { + public GraphExporter(DirectedGraph graph) { this.graph = graph; } - public Collection exportSubGraphs(Collection> vertexSubSets) { + public Collection exportDotGraphs(Collection> vertexSubSets) { Set dotGraphs = new HashSet(); - - Iterator> it = vertexSubSets.iterator(); - while (it.hasNext()) { - Graph componentGraph = getGraphForComponent(it.next()); + + for (Collection component : vertexSubSets) { + Graph componentGraph = getGraphForComponent(component); dotGraphs.add(exportGraph(componentGraph)); } return dotGraphs; } - private Graph getGraphForComponent(Collection component) + private Graph getGraphForComponent(Collection component) { - return new DirectedSubgraph(graph, new HashSet(component), null); + return new DirectedSubgraph(graph, new HashSet(component), null); } - private String exportGraph(Graph componentGraph) { + private String exportGraph(Graph componentGraph) { StringWriter outputWriter = new StringWriter(); - new DOTExporter( - new IntegerNameProvider(), + new DOTExporter( + new IntegerNameProvider(), new URIVertexNameProvider(), new StringEdgeNameProvider() ).export(outputWriter, componentGraph); @@ -52,10 +50,10 @@ private String exportGraph(Graph componentGraph) { return outputWriter.toString(); } - private class URIVertexNameProvider implements VertexNameProvider + private class URIVertexNameProvider implements VertexNameProvider { @Override - public String getVertexName(Value vertex) { + public String getVertexName(Resource vertex) { return vertex.stringValue(); } } diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/util/graph/UnidirectionalRelation.java b/src/main/java/at/ac/univie/mminf/qskos4j/util/graph/UnidirectionalRelation.java new file mode 100644 index 0000000..ee0bf45 --- /dev/null +++ b/src/main/java/at/ac/univie/mminf/qskos4j/util/graph/UnidirectionalRelation.java @@ -0,0 +1,31 @@ +package at.ac.univie.mminf.qskos4j.util.graph; + +import at.ac.univie.mminf.qskos4j.util.Tuple; +import org.openrdf.model.Resource; + +import java.util.Collection; + +public class UnidirectionalRelation { + + private Tuple resources; + private Collection inverseRelations; + + public UnidirectionalRelation(Tuple resources, Collection inverseRelations) { + this.resources = resources; + this.inverseRelations = inverseRelations; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof UnidirectionalRelation) { + UnidirectionalRelation other = (UnidirectionalRelation) obj; + return resources.equals(other.resources) && inverseRelations.equals(other.inverseRelations); + } + return false; + } + + @Override + public int hashCode() { + return resources.hashCode() + inverseRelations.hashCode(); + } +} \ No newline at end of file diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/AggregationRelationsTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/AggregationRelationsTest.java index 9a56229..b054a1a 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/AggregationRelationsTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/AggregationRelationsTest.java @@ -27,7 +27,7 @@ public void setUp() throws OpenRDFException, IOException { @Test public void testAggregationRelationsCount() throws OpenRDFException { - Assert.assertEquals(6, aggregationRelations.getResult().longValue()); + Assert.assertEquals(6, aggregationRelations.getResult().getData().longValue()); } } diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/AuthoritativeConceptsTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/AuthoritativeConceptsTest.java index 3e93319..0500d02 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/AuthoritativeConceptsTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/AuthoritativeConceptsTest.java @@ -31,7 +31,7 @@ public void setUp() throws OpenRDFException, IOException { @Test public void testAuthoritativeConceptsCount() throws OpenRDFException { - Collection authoritativeConceptValues = authoritativeConcepts.getResult(); + Collection authoritativeConceptValues = authoritativeConcepts.getResult().getData(); Assert.assertEquals(9, authoritativeConceptValues.size()); } } diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/BrokenLinksTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/BrokenLinksTest.java index dc3d2f1..c651196 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/BrokenLinksTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/BrokenLinksTest.java @@ -30,7 +30,7 @@ public void setUp() throws OpenRDFException, IOException { @Test public void testBrokenLinks() throws OpenRDFException { - Collection brokenLinkURLs = brokenLinks.getResult(); + Collection brokenLinkURLs = brokenLinks.getResult().getData(); Assert.assertEquals(1, brokenLinkURLs.size()); } diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/ConceptSchemesTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/ConceptSchemesTest.java index cb75e4f..8f99941 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/ConceptSchemesTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/ConceptSchemesTest.java @@ -27,6 +27,6 @@ public void setUp() throws OpenRDFException, IOException { @Test public void testLexicalRelationsCount() throws OpenRDFException { - Assert.assertEquals(3, conceptSchemes.getResult().size()); + Assert.assertEquals(3, conceptSchemes.getResult().getData().size()); } } diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/DisconnectedConceptClustersTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/DisconnectedConceptClustersTest.java index 7e7670e..0842df0 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/DisconnectedConceptClustersTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/DisconnectedConceptClustersTest.java @@ -7,11 +7,10 @@ import org.junit.Before; import org.junit.Test; import org.openrdf.OpenRDFException; -import org.openrdf.model.Value; +import org.openrdf.model.Resource; import java.io.IOException; import java.util.Collection; -import java.util.Set; /** * Created by christian @@ -32,17 +31,17 @@ public void setUp() throws OpenRDFException, IOException { @Test public void testComponentCount() throws OpenRDFException { - long conceptCount = involvedConcepts.getResult().size(); - Collection> components = disconnectedConceptClusters.getResult(); + long conceptCount = involvedConcepts.getResult().getData().size(); + Collection> components = disconnectedConceptClusters.getResult().getData(); Assert.assertEquals(7, components.size()); Assert.assertTrue(getVertexCount(components) <= conceptCount); } - private long getVertexCount(Collection> components) { + private long getVertexCount(Collection> components) { long ret = 0; - for (Set component : components) { + for (Collection component : components) { ret += component.size(); } diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/HierarchicalCyclesTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/HierarchicalCyclesTest.java index 644c628..d9e782d 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/HierarchicalCyclesTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/HierarchicalCyclesTest.java @@ -29,12 +29,12 @@ public void setUp() throws OpenRDFException, IOException { @Test public void testCycleCount() throws OpenRDFException { - Assert.assertEquals(3, hierarchicalCycles.getResult().size()); + Assert.assertEquals(3, hierarchicalCycles.getResult().getData().size()); } @Test public void testComponentsCycleCount() throws OpenRDFException { - Assert.assertEquals(3, hierarchicalCyclesForComponents.getResult().size()); + Assert.assertEquals(3, hierarchicalCyclesForComponents.getResult().getData().size()); } } diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/HierarchicalRedundancyTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/HierarchicalRedundancyTest.java index b4126b5..6d946a7 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/HierarchicalRedundancyTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/HierarchicalRedundancyTest.java @@ -21,6 +21,6 @@ public void setUp() throws OpenRDFException, IOException { @Test public void redundancyCount() throws OpenRDFException { - Assert.assertEquals(5, hierarchicalRedundancy.getResult().size()); + Assert.assertEquals(5, hierarchicalRedundancy.getResult().getData().size()); } } diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/LexicalRelationsTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/LexicalRelationsTest.java index 0209494..10cef09 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/LexicalRelationsTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/LexicalRelationsTest.java @@ -28,7 +28,7 @@ public void setUp() throws OpenRDFException, IOException @Test public void testLexicalRelationsCount() throws OpenRDFException { - Assert.assertEquals(29, lexicalRelations.getResult().longValue()); + Assert.assertEquals(29, lexicalRelations.getResult().getData().longValue()); } } diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/MappingClashesTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/MappingClashesTest.java index 845b360..8ca7a2f 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/MappingClashesTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/MappingClashesTest.java @@ -21,6 +21,6 @@ public void setUp() throws OpenRDFException, IOException { @Test public void testExactVsAssociativeMappingClashes() throws OpenRDFException { - Assert.assertEquals(5, mappingClashes.getResult().size()); + Assert.assertEquals(5, mappingClashes.getResult().getData().size()); } } diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/MappingRelationsMisuseTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/MappingRelationsMisuseTest.java index fc9cc08..716a463 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/MappingRelationsMisuseTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/MappingRelationsMisuseTest.java @@ -27,12 +27,12 @@ public void setUp() throws IOException, OpenRDFException @Test public void mappingRelationsMisuseCount() throws OpenRDFException { - Assert.assertEquals(5, mappingRelationsMisuse.getResult().size()); + Assert.assertEquals(5, mappingRelationsMisuse.getResult().getData().size()); } @Test public void affectedConcepts() throws OpenRDFException { - Collection result = mappingRelationsMisuse.getResult(); + Collection result = mappingRelationsMisuse.getResult().getData(); Assert.assertTrue(isAffected("conceptA", "conceptB", result)); Assert.assertTrue(isAffected("conceptC", "conceptD", result)); diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/MissingInLinksTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/MissingInLinksTest.java index 69fca56..b4ee206 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/MissingInLinksTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/MissingInLinksTest.java @@ -31,7 +31,7 @@ public void setUp() throws OpenRDFException, IOException { public void testInLinksAsDbPedia() throws OpenRDFException { authoritativeConcepts.setAuthResourceIdentifier("dbpedia.org"); - Collection conceptsMissingInLinks = missingInLinks.getResult(); + Collection conceptsMissingInLinks = missingInLinks.getResult().getData(); Assert.assertTrue(conceptsMissingInLinks.isEmpty()); } @@ -39,7 +39,7 @@ public void testInLinksAsDbPedia() throws OpenRDFException { public void testInLinksAsSTW() throws OpenRDFException { authoritativeConcepts.setAuthResourceIdentifier("zbw.eu"); - Collection conceptsMissingInLinks = missingInLinks.getResult(); + Collection conceptsMissingInLinks = missingInLinks.getResult().getData(); Assert.assertEquals(2, conceptsMissingInLinks.size()); } @@ -47,7 +47,7 @@ public void testInLinksAsSTW() throws OpenRDFException { public void testInLinksAsBnf() throws OpenRDFException { authoritativeConcepts.setAuthResourceIdentifier("data.bnf.fr"); - Collection conceptsMissingInLinks = missingInLinks.getResult(); + Collection conceptsMissingInLinks = missingInLinks.getResult().getData(); Assert.assertEquals(1, conceptsMissingInLinks.size()); } @@ -56,7 +56,7 @@ public void testInLinksAsBnf() throws OpenRDFException { public void testInLinksAsLocal() throws OpenRDFException { authoritativeConcepts.setAuthResourceIdentifier("myvocab.org"); - Collection conceptsMissingInLinks = missingInLinks.getResult(); + Collection conceptsMissingInLinks = missingInLinks.getResult().getData(); Assert.assertEquals(1, conceptsMissingInLinks.size()); } } diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/NonHttpResourcesTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/NonHttpResourcesTest.java index cd9f3f2..414b445 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/NonHttpResourcesTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/NonHttpResourcesTest.java @@ -30,11 +30,11 @@ public void setUp() throws OpenRDFException, IOException { @Test public void testConceptsNonHttpUriCount() throws OpenRDFException { - Assert.assertEquals(1, httpUriSchemeViolationsForConcepts.getResult().size()); + Assert.assertEquals(1, httpUriSchemeViolationsForConcepts.getResult().getData().size()); } @Test public void testResourcesNonHttpUriCount() throws OpenRDFException { - Assert.assertEquals(4, httpResourcesForUriSchemeViolations.getResult().size()); + Assert.assertEquals(4, httpResourcesForUriSchemeViolations.getResult().getData().size()); } } diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/RelationClashesTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/RelationClashesTest.java index 0c3f87b..a76c119 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/RelationClashesTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/RelationClashesTest.java @@ -21,7 +21,7 @@ public void setUp() throws OpenRDFException, IOException { @Test public void testAssociativeVsHierarchicalClashes() throws OpenRDFException { - Assert.assertEquals(10, relationClashes.getResult().size()); + Assert.assertEquals(10, relationClashes.getResult().getData().size()); } } diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/SkosXlTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/SkosXlTest.java index ea87a05..c0eb3cb 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/SkosXlTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/SkosXlTest.java @@ -42,22 +42,22 @@ public void setUp() throws OpenRDFException, IOException { @Test public void lexicalRelationsCountTest() throws OpenRDFException { - Assert.assertEquals(5, lexicalRelations.getResult().intValue()); + Assert.assertEquals(5, lexicalRelations.getResult().getData().intValue()); } @Test public void omittedLangTagCount() throws OpenRDFException { - Assert.assertEquals(2, omittedOrInvalidLanguageTags.getResult().size()); + Assert.assertEquals(2, omittedOrInvalidLanguageTags.getResult().getData().size()); } @Test public void incompleteLangCovCount() throws OpenRDFException { - Assert.assertEquals(2, incompleteLanguageCoverage.getResult().size()); + Assert.assertEquals(2, incompleteLanguageCoverage.getResult().getData().size()); } @Test public void labelConflictCount() throws OpenRDFException { - Assert.assertEquals(1, overlappingLabels.getResult().size()); + Assert.assertEquals(1, overlappingLabels.getResult().getData().size()); } } diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/UndocumentedConceptsTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/UndocumentedConceptsTest.java index c1c8e51..66572c0 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/UndocumentedConceptsTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/UndocumentedConceptsTest.java @@ -27,7 +27,7 @@ public void setUp() throws OpenRDFException, IOException { @Test public void testAverageDocumentationCoverageRatio() throws OpenRDFException { - Assert.assertEquals(1, undocumentedConcepts.getResult().size()); + Assert.assertEquals(1, undocumentedConcepts.getResult().getData().size()); } } diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/UnidirectionallyRelatedConceptsTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/UnidirectionallyRelatedConceptsTest.java index d2dcf8d..fd9c79b 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/UnidirectionallyRelatedConceptsTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/UnidirectionallyRelatedConceptsTest.java @@ -3,7 +3,7 @@ import at.ac.univie.mminf.qskos4j.issues.concepts.AuthoritativeConcepts; import at.ac.univie.mminf.qskos4j.issues.concepts.InvolvedConcepts; import at.ac.univie.mminf.qskos4j.issues.relations.UnidirectionallyRelatedConcepts; -import at.ac.univie.mminf.qskos4j.util.Pair; +import at.ac.univie.mminf.qskos4j.util.Tuple; import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; import junit.framework.Assert; import org.junit.Before; @@ -26,7 +26,7 @@ public void setUp() throws OpenRDFException, IOException { @Test public void testMissingInverseRelationsCount() throws OpenRDFException { - Map, String> missingRelations = unidirectionallyRelatedConcepts.getResult(); + Map, String> missingRelations = unidirectionallyRelatedConcepts.getResult(); Assert.assertEquals(8, missingRelations.size()); } } diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/ValuelessAssociativeRelationsTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/ValuelessAssociativeRelationsTest.java index aa95f2b..49732a9 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/ValuelessAssociativeRelationsTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/ValuelessAssociativeRelationsTest.java @@ -1,13 +1,11 @@ package at.ac.univie.mminf.qskos4j.issues; import at.ac.univie.mminf.qskos4j.issues.relations.ValuelessAssociativeRelations; -import at.ac.univie.mminf.qskos4j.util.Pair; 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 org.openrdf.model.URI; import java.io.IOException; import java.util.Collection; @@ -24,7 +22,7 @@ public void setUp() throws OpenRDFException, IOException { @Test public void testRedundantAssociativeRelationsCount() throws OpenRDFException { - Collection> redAssRels = valuelessAssociativeRelations.getResult(); + Collection redAssRels = valuelessAssociativeRelations.getResult().getData(); Assert.assertEquals(6, redAssRels.size()); } } diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/report/HtmlReportsTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/report/HtmlReportsTest.java deleted file mode 100644 index e8e7694..0000000 --- a/src/test/java/at/ac/univie/mminf/qskos4j/report/HtmlReportsTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package at.ac.univie.mminf.qskos4j.report; - -import at.ac.univie.mminf.qskos4j.issues.clusters.DisconnectedConceptClusters; -import at.ac.univie.mminf.qskos4j.issues.concepts.InvolvedConcepts; -import at.ac.univie.mminf.qskos4j.issues.labels.DisjointLabelsViolations; -import at.ac.univie.mminf.qskos4j.issues.labels.util.ResourceLabelsCollector; -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.BufferedWriter; -import java.io.IOException; -import java.io.StringWriter; -import java.util.Arrays; - -public class HtmlReportsTest { - - private DisjointLabelsViolations disjointLabelsViolations; - private DisconnectedConceptClusters disconnectedConceptClusters; - - @Before - public void setUp() throws OpenRDFException, IOException { - disjointLabelsViolations = new DisjointLabelsViolations(new ResourceLabelsCollector()); - disjointLabelsViolations.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("ambiguousLabels.rdf").getConnection()); - - disconnectedConceptClusters = new DisconnectedConceptClusters(new InvolvedConcepts()); - disconnectedConceptClusters.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("components.rdf").getConnection()); - } - - @Test - public void issuesProvideHtmlReport() throws OpenRDFException, IOException { - Assert.assertTrue(providesHtmlReport(disjointLabelsViolations.getReport())); - } - - @Test(expected = UnsupportedOperationException.class) - public void issuesDontProvideHtmlReport() throws OpenRDFException, IOException { - providesHtmlReport(disconnectedConceptClusters.getReport()); - } - - private boolean providesHtmlReport(Report report) throws IOException { - boolean providesReport = true; - - for (Report.ReportStyle style : Arrays.asList(Report.ReportStyle.values())) { - StringWriter htmlStringWriter = new StringWriter(); - BufferedWriter htmlReportWriter = new BufferedWriter(htmlStringWriter); - - report.generateHtmlReport(htmlReportWriter, style); - htmlReportWriter.close(); - - providesReport &= (htmlStringWriter.toString().trim().length() != 0); - } - - return providesReport; - } - -} From 253bf131e4c8c36074a0fd2377398de2570d8476 Mon Sep 17 00:00:00 2001 From: cmader Date: Thu, 5 Dec 2013 18:06:07 +0100 Subject: [PATCH 02/19] fixed some tests --- .../OmittedOrInvalidLanguageTags.java | 21 +++++++++---------- .../OmittedOrInvalidLanguageTagsResult.java | 19 +++++++++++++++++ .../mminf/qskos4j/issues/CollectionsTest.java | 2 +- .../issues/DisjointLabelsViolationsTest.java | 2 +- .../mminf/qskos4j/issues/HttpURIsTest.java | 4 ++-- .../IncompleteLanguageCoverageTest.java | 6 +++--- .../issues/InconsistentPrefLabelsTest.java | 2 +- .../qskos4j/issues/InvolvedConceptsTest.java | 4 ++-- .../qskos4j/issues/MissingLabelsTest.java | 6 +++--- .../qskos4j/issues/MissingOutLinksTest.java | 5 +++-- .../OmittedOrInvalidLanguageTagsTest.java | 13 +++--------- .../issues/OmittedTopConceptsTest.java | 2 +- .../qskos4j/issues/OrphanConceptsTest.java | 6 +++--- .../qskos4j/issues/OverlappingLabelsTest.java | 6 +++--- .../qskos4j/issues/SemanticRelationsTest.java | 2 +- ...SolelyTransitivelyRelatedConceptsTest.java | 2 +- .../TopConceptsHavingBroaderConceptsTest.java | 2 +- .../issues/UndefinedSkosResourcesTest.java | 4 ++-- .../UnidirectionallyRelatedConceptsTest.java | 9 ++++---- 19 files changed, 64 insertions(+), 53 deletions(-) create mode 100644 src/main/java/at/ac/univie/mminf/qskos4j/issues/language/OmittedOrInvalidLanguageTagsResult.java diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/OmittedOrInvalidLanguageTags.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/OmittedOrInvalidLanguageTags.java index 1052480..fe9fb1a 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/OmittedOrInvalidLanguageTags.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/OmittedOrInvalidLanguageTags.java @@ -17,9 +17,9 @@ /** * Finds Omitted or Invalid Language Tags. */ -public class OmittedOrInvalidLanguageTags extends Issue> { +public class OmittedOrInvalidLanguageTags extends Issue { - private Collection affectedStatements; + private Map> untaggedLiterals; private Map checkedLanguageTags; public OmittedOrInvalidLanguageTags() { @@ -32,24 +32,24 @@ public OmittedOrInvalidLanguageTags() { } @Override - protected CollectionResult invoke() throws OpenRDFException { + protected OmittedOrInvalidLanguageTagsResult invoke() throws OpenRDFException { TupleQueryResult result = repCon.prepareTupleQuery(QueryLanguage.SPARQL, createMissingLangTagQuery()) .evaluate(); findAffectedStatements(result); - return new CollectionResult(affectedStatements); + return new OmittedOrInvalidLanguageTagsResult(untaggedLiterals); } private String createMissingLangTagQuery() throws OpenRDFException { return SparqlPrefix.SKOS +" "+ SparqlPrefix.SKOSXL +" "+ SparqlPrefix.RDFS + - "SELECT ?literal ?s "+ + "SELECT ?s ?p ?literal "+ "WHERE {" + - "?s ?textProp ?literal . " + + "?s ?p ?literal . " + - "{?textProp rdfs:subPropertyOf rdfs:label}" + + "{?p rdfs:subPropertyOf rdfs:label}" + "UNION" + - "{?textProp rdfs:subPropertyOf skos:note}" + + "{?p rdfs:subPropertyOf skos:note}" + "FILTER isLiteral(?literal) " + "}"; @@ -59,15 +59,14 @@ private void findAffectedStatements(TupleQueryResult result) throws QueryEvaluationException { checkedLanguageTags = new HashMap(); + affectedStatements = new ArrayList<>(); while (result.hasNext()) { BindingSet queryResult = result.next(); Resource subject = (Resource) queryResult.getValue("s"); - URI predicate = (URI) queryResult.getValue("textProp"); + URI predicate = (URI) queryResult.getValue("p"); Literal literal = (Literal) queryResult.getValue("literal"); - if (subject instanceof BNode) continue; - if (literal.getDatatype() == null) { String langTag = literal.getLanguage(); if (langTag == null || !isValidLangTag(langTag)) { diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/OmittedOrInvalidLanguageTagsResult.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/OmittedOrInvalidLanguageTagsResult.java new file mode 100644 index 0000000..f2b2e52 --- /dev/null +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/OmittedOrInvalidLanguageTagsResult.java @@ -0,0 +1,19 @@ +package at.ac.univie.mminf.qskos4j.issues.language; + +import at.ac.univie.mminf.qskos4j.result.Result; +import org.openrdf.model.Resource; + +import java.util.Collection; +import java.util.Map; + +public class OmittedOrInvalidLanguageTagsResult extends Result>> { + + OmittedOrInvalidLanguageTagsResult(Map> data) { + super(data); + } + + @Override + public boolean indicatesProblem() { + return false; //To change body of implemented methods use File | Settings | File Templates. + } +} diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/CollectionsTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/CollectionsTest.java index ed8bb99..e40735e 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/CollectionsTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/CollectionsTest.java @@ -27,7 +27,7 @@ public void setUp() throws OpenRDFException, IOException { @Test public void testCollectionsCount() throws OpenRDFException { - Assert.assertEquals(4, collections.getResult().longValue()); + Assert.assertEquals(4, collections.getResult().getData().longValue()); } } diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/DisjointLabelsViolationsTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/DisjointLabelsViolationsTest.java index 06f1d4c..953aab1 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/DisjointLabelsViolationsTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/DisjointLabelsViolationsTest.java @@ -25,7 +25,7 @@ public void setUp() throws OpenRDFException, IOException { @Test public void testDisjointLabels() throws OpenRDFException { - Collection ambiguousResources = disjointLabelsViolations.getResult().values(); + Collection ambiguousResources = disjointLabelsViolations.getResult().getData(); Assert.assertTrue(UriSuffixFinder.isPartOfConflict(ambiguousResources, "conceptD")); Assert.assertTrue(UriSuffixFinder.isPartOfConflict(ambiguousResources, "conceptF")); diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/HttpURIsTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/HttpURIsTest.java index 424fb6f..bccdb1f 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/HttpURIsTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/HttpURIsTest.java @@ -29,11 +29,11 @@ public void setUp() throws OpenRDFException, IOException { @Test public void testConceptsHttpUriCount() throws OpenRDFException { - Assert.assertEquals(21, httpURIs1.getResult().size()); + Assert.assertEquals(21, httpURIs1.getResult().getData().size()); } @Test public void testResourcesHttpUriCount() throws OpenRDFException { - Assert.assertEquals(8, httpURIs2.getResult().size()); + Assert.assertEquals(8, httpURIs2.getResult().getData().size()); } } diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/IncompleteLanguageCoverageTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/IncompleteLanguageCoverageTest.java index 19c3ddf..a55aaca 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/IncompleteLanguageCoverageTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/IncompleteLanguageCoverageTest.java @@ -34,7 +34,7 @@ public void setUp() throws OpenRDFException, IOException { public void testIncompleteLanguageCoverageCount() throws OpenRDFException { - Map> incompleteLangCoverage = incompleteLanguageCoverage.getResult(); + Map> incompleteLangCoverage = incompleteLanguageCoverage.getResult().getData(); Assert.assertEquals(13, incompleteLangCoverage.size()); } @@ -42,7 +42,7 @@ public void testIncompleteLanguageCoverageCount() public void testExistResourcesNotHavingEnglishLabels() throws OpenRDFException { - Map> incompleteLangCoverage = incompleteLanguageCoverage.getResult(); + Map> incompleteLangCoverage = incompleteLanguageCoverage.getResult().getData(); boolean englishTagFound = false; for (Collection missingLanguages : incompleteLangCoverage.values()) { @@ -57,7 +57,7 @@ public void testExistResourcesNotHavingEnglishLabels() public void testResourcesMissingOnlyFrenchLabelsCount() throws OpenRDFException { - Map> incompleteLangCoverage = incompleteLanguageCoverage.getResult(); + Map> incompleteLangCoverage = incompleteLanguageCoverage.getResult().getData(); List foundResources = new ArrayList(); for (Value resource : incompleteLangCoverage.keySet()) { diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/InconsistentPrefLabelsTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/InconsistentPrefLabelsTest.java index cbbbea4..7b77788 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/InconsistentPrefLabelsTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/InconsistentPrefLabelsTest.java @@ -25,7 +25,7 @@ public void setUp() throws OpenRDFException, IOException { @Test public void testUniquePrefLabels() throws OpenRDFException { - Collection ambiguousResources = inconsistentPrefLabels.getResult().values(); + Collection ambiguousResources = inconsistentPrefLabels.getResult().getData(); Assert.assertTrue(UriSuffixFinder.isPartOfConflict(ambiguousResources, "conceptA")); Assert.assertTrue(UriSuffixFinder.isPartOfConflict(ambiguousResources, "conceptA2")); diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/InvolvedConceptsTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/InvolvedConceptsTest.java index 0f9ca9b..c2eec8d 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/InvolvedConceptsTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/InvolvedConceptsTest.java @@ -27,14 +27,14 @@ public void setUp() throws OpenRDFException, IOException { @Test public void testConceptCount_1() throws OpenRDFException { - Collection involvedConceptValues = involvedConceptsForConcepts.getResult(); + Collection involvedConceptValues = involvedConceptsForConcepts.getResult().getData(); Assert.assertEquals(10, involvedConceptValues.size()); } @Test public void testConceptCount_2() throws OpenRDFException { - Collection involvedConceptValues = involvedConceptsForComponents.getResult(); + Collection involvedConceptValues = involvedConceptsForComponents.getResult().getData(); Assert.assertEquals(21, involvedConceptValues.size()); } } diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/MissingLabelsTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/MissingLabelsTest.java index 023dccd..50b3330 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/MissingLabelsTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/MissingLabelsTest.java @@ -33,7 +33,7 @@ public void setUp() throws OpenRDFException, IOException { @Test public void checkLabeledConcepts() throws OpenRDFException { - conceptsAndConceptSchemesWithMissingLabels = missingLabels.getResult(); + conceptsAndConceptSchemesWithMissingLabels = missingLabels.getResult().getData(); Assert.assertTrue(isUnlabeled("conceptA")); Assert.assertTrue(isUnlabeled("conceptC")); @@ -49,7 +49,7 @@ public void checkLabeledConcepts() throws OpenRDFException { @Test public void checkLabeledConceptSchemes() throws OpenRDFException { - conceptsAndConceptSchemesWithMissingLabels = missingLabels.getResult(); + conceptsAndConceptSchemesWithMissingLabels = missingLabels.getResult().getData(); Assert.assertTrue(isUnlabeled("conceptSchemeC")); @@ -62,7 +62,7 @@ public void checkLabeledConceptSchemes() throws OpenRDFException { @Test public void countMissingLabels() throws OpenRDFException { - conceptsAndConceptSchemesWithMissingLabels = missingLabels.getResult(); + conceptsAndConceptSchemesWithMissingLabels = missingLabels.getResult().getData(); Assert.assertEquals(7, conceptsAndConceptSchemesWithMissingLabels.size()); } diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/MissingOutLinksTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/MissingOutLinksTest.java index 5eac180..711caf5 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/MissingOutLinksTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/MissingOutLinksTest.java @@ -33,11 +33,12 @@ public void setUp() throws OpenRDFException, IOException { @Test public void testComponentsMissingOutLinkCount() throws OpenRDFException { - Assert.assertEquals(involvedConceptsForComponents.getResult().size(), missingOutLinksForComponents.getResult().size()); + Assert.assertEquals(involvedConceptsForComponents.getResult().getData().size(), + missingOutLinksForComponents.getResult().getData().size()); } @Test public void testConceptsMissingOutLinkCount() throws OpenRDFException { - Assert.assertEquals(7, missingOutLinksForConcepts.getResult().size()); + Assert.assertEquals(7, missingOutLinksForConcepts.getResult().getData().size()); } } diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/OmittedOrInvalidLanguageTagsTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/OmittedOrInvalidLanguageTagsTest.java index cfc58db..4432dc4 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/OmittedOrInvalidLanguageTagsTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/OmittedOrInvalidLanguageTagsTest.java @@ -7,11 +7,9 @@ import org.junit.Test; import org.openrdf.OpenRDFException; import org.openrdf.model.Literal; -import org.openrdf.model.Resource; import java.io.IOException; import java.util.Collection; -import java.util.Map; /** * Created by christian @@ -36,16 +34,12 @@ public void setUp() throws OpenRDFException, IOException { @Test public void testMissingLangTagCount_1() throws OpenRDFException { - Map> missingLangTags = oiltComponents.getResult(); - Assert.assertEquals(3, missingLangTags.size()); + Assert.assertEquals(3, oiltComponents.getResult().getData().size()); } @Test public void testMissingLangTagCount_2() throws OpenRDFException { - Map> missingLangTags = oiltDeprecatedAndIllegal.getResult(); - - Assert.assertEquals(1, missingLangTags.keySet().size()); - Assert.assertEquals(2, countEntries(missingLangTags.values())); + Assert.assertEquals(2, oiltDeprecatedAndIllegal.getResult().getData().size()); } private int countEntries(Collection> allLiterals) { @@ -58,8 +52,7 @@ private int countEntries(Collection> allLiterals) { @Test public void testMissingLangTagCount_3() throws OpenRDFException { - Map> missingLangTags = oiltLangTags.getResult(); - Assert.assertEquals(1, countEntries(missingLangTags.values())); + Assert.assertEquals(1, oiltLangTags.getResult().getData().size()); } } diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/OmittedTopConceptsTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/OmittedTopConceptsTest.java index a5fb0bf..75a7c80 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/OmittedTopConceptsTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/OmittedTopConceptsTest.java @@ -23,7 +23,7 @@ public void setUp() throws OpenRDFException, IOException { @Test public void testConceptSchemesWithoutTopConceptsCount() throws OpenRDFException { - Assert.assertEquals(2, omittedTopConcepts.getResult().size()); + Assert.assertEquals(2, omittedTopConcepts.getResult().getData().size()); } } diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/OrphanConceptsTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/OrphanConceptsTest.java index 306ffa8..4425d9e 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/OrphanConceptsTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/OrphanConceptsTest.java @@ -7,7 +7,7 @@ import org.junit.Before; import org.junit.Test; import org.openrdf.OpenRDFException; -import org.openrdf.model.Value; +import org.openrdf.model.Resource; import java.io.IOException; import java.util.Collection; @@ -32,13 +32,13 @@ public void setUp() throws OpenRDFException, IOException { @Test public void testConceptsLooseConceptCount() throws OpenRDFException { - Collection orphanConceptValues = orphanConceptsForConcepts.getResult(); + Collection orphanConceptValues = orphanConceptsForConcepts.getResult().getData(); Assert.assertEquals(7, orphanConceptValues.size()); } @Test public void testComponentsLooseConceptCount() throws OpenRDFException { - Collection orphanConceptValues = orphanConceptsForComponents.getResult(); + Collection orphanConceptValues = orphanConceptsForComponents.getResult().getData(); Assert.assertEquals(2, orphanConceptValues.size()); } } diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/OverlappingLabelsTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/OverlappingLabelsTest.java index 9cf5593..57bf5e6 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/OverlappingLabelsTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/OverlappingLabelsTest.java @@ -33,7 +33,7 @@ public void setUp() throws OpenRDFException, IOException { @Test public void testLabelConflictCount_1() throws OpenRDFException { - Collection allLabelConflicts = overlappingLabelsForComponents.getResult(); + Collection allLabelConflicts = overlappingLabelsForComponents.getResult().getData(); Assert.assertEquals(2, allLabelConflicts.size()); Assert.assertEquals(4, getDifferentResources(allLabelConflicts).size()); @@ -41,7 +41,7 @@ public void testLabelConflictCount_1() throws OpenRDFException { @Test public void testCaseInsensitive() throws OpenRDFException { - Assert.assertEquals(2, overlappingLabels.getResult().size()); + Assert.assertEquals(2, overlappingLabels.getResult().getData().size()); } private Collection getDifferentResources(Collection labelConflicts) @@ -57,6 +57,6 @@ private Collection getDifferentResources(Collection labelC @Test public void testLabelConflictCount_2() throws OpenRDFException { - Assert.assertEquals(0, overlappingLabelsForRelatedConcepts.getResult().size()); + Assert.assertEquals(0, overlappingLabelsForRelatedConcepts.getResult().getData().size()); } } diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/SemanticRelationsTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/SemanticRelationsTest.java index b6e82e2..c7eb16a 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/SemanticRelationsTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/SemanticRelationsTest.java @@ -27,7 +27,7 @@ public void setUp() throws OpenRDFException, IOException { @Test public void testLexicalRelationsCount() throws OpenRDFException { - Assert.assertEquals(18, semanticRelations.getResult().longValue()); + Assert.assertEquals(18, semanticRelations.getResult().getData().longValue()); } } diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/SolelyTransitivelyRelatedConceptsTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/SolelyTransitivelyRelatedConceptsTest.java index fd2faba..0b94e5b 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/SolelyTransitivelyRelatedConceptsTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/SolelyTransitivelyRelatedConceptsTest.java @@ -21,7 +21,7 @@ public void setUp() throws OpenRDFException, IOException { @Test public void testSolitaryTransitiveRelationsCount() throws OpenRDFException { - Assert.assertEquals(4, solelyTransitivelyRelatedConcepts.getResult().size()); + Assert.assertEquals(4, solelyTransitivelyRelatedConcepts.getResult().getData().size()); } } diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/TopConceptsHavingBroaderConceptsTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/TopConceptsHavingBroaderConceptsTest.java index 148c25a..3a04a2a 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/TopConceptsHavingBroaderConceptsTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/TopConceptsHavingBroaderConceptsTest.java @@ -22,7 +22,7 @@ public void setUp() throws OpenRDFException, IOException { @Test public void testTopConceptsHavingBroaderConceptCount() throws OpenRDFException { - Assert.assertEquals(4, topConceptsHavingBroaderConcepts.getResult().size()); + Assert.assertEquals(4, topConceptsHavingBroaderConcepts.getResult().getData().size()); } } diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/UndefinedSkosResourcesTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/UndefinedSkosResourcesTest.java index 5012ef3..1d7d074 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/UndefinedSkosResourcesTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/UndefinedSkosResourcesTest.java @@ -26,13 +26,13 @@ public void setUp() throws OpenRDFException, IOException { @Test public void testUndefinedSkosResourcesCount_1() throws OpenRDFException { - Collection undefRes = undefinedSkosResourcesInConcepts.getResult(); + Collection undefRes = undefinedSkosResourcesInConcepts.getResult().getData(); Assert.assertEquals(3, undefRes.size()); } @Test public void testUndefinedSkosResourcesCount_2() throws OpenRDFException { - Collection undefRes = undefinedSkosResourcesInDeprecatedAndIllegal.getResult(); + Collection undefRes = undefinedSkosResourcesInDeprecatedAndIllegal.getResult().getData(); Assert.assertEquals(12, undefRes.size()); } diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/UnidirectionallyRelatedConceptsTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/UnidirectionallyRelatedConceptsTest.java index fd9c79b..e319dd7 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/UnidirectionallyRelatedConceptsTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/UnidirectionallyRelatedConceptsTest.java @@ -3,16 +3,15 @@ import at.ac.univie.mminf.qskos4j.issues.concepts.AuthoritativeConcepts; import at.ac.univie.mminf.qskos4j.issues.concepts.InvolvedConcepts; import at.ac.univie.mminf.qskos4j.issues.relations.UnidirectionallyRelatedConcepts; -import at.ac.univie.mminf.qskos4j.util.Tuple; +import at.ac.univie.mminf.qskos4j.util.graph.UnidirectionalRelation; 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 org.openrdf.model.Resource; import java.io.IOException; -import java.util.Map; +import java.util.Collection; public class UnidirectionallyRelatedConceptsTest { @@ -26,7 +25,7 @@ public void setUp() throws OpenRDFException, IOException { @Test public void testMissingInverseRelationsCount() throws OpenRDFException { - Map, String> missingRelations = unidirectionallyRelatedConcepts.getResult(); - Assert.assertEquals(8, missingRelations.size()); + Collection unidirectionalRelations = unidirectionallyRelatedConcepts.getResult().getData(); + Assert.assertEquals(8, unidirectionalRelations.size()); } } From 3ae7ce0efc3fd679b7537465b8a1bf650d895129 Mon Sep 17 00:00:00 2001 From: Christian Mader Date: Fri, 6 Dec 2013 11:09:02 +0100 Subject: [PATCH 03/19] fixed some tests --- .../language/IncompleteLangCovResult.java | 4 - .../OmittedOrInvalidLanguageTags.java | 80 +++++++----- .../OmittedOrInvalidLanguageTagsResult.java | 42 ++++++- .../UnidirectionallyRelatedConcepts.java | 119 +++++++++--------- ...UnidirectionallyRelatedConceptsResult.java | 19 +++ .../util/graph/UnidirectionalRelation.java | 31 ----- .../OmittedOrInvalidLanguageTagsTest.java | 7 +- .../UnidirectionallyRelatedConceptsTest.java | 1 - 8 files changed, 173 insertions(+), 130 deletions(-) create mode 100644 src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/UnidirectionallyRelatedConceptsResult.java delete mode 100644 src/main/java/at/ac/univie/mminf/qskos4j/util/graph/UnidirectionalRelation.java diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/IncompleteLangCovResult.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/IncompleteLangCovResult.java index 0f755dd..994e421 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/IncompleteLangCovResult.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/IncompleteLangCovResult.java @@ -45,10 +45,6 @@ private String generateExtensiveTextReport() { .append(entryIt.hasNext() ? "\n" : ""); } - for (Entry> entry : getData().entrySet()) { - - } - return extensiveReport.toString(); } diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/OmittedOrInvalidLanguageTags.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/OmittedOrInvalidLanguageTags.java index fe9fb1a..1d92773 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/OmittedOrInvalidLanguageTags.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/OmittedOrInvalidLanguageTags.java @@ -1,11 +1,11 @@ package at.ac.univie.mminf.qskos4j.issues.language; import at.ac.univie.mminf.qskos4j.issues.Issue; -import at.ac.univie.mminf.qskos4j.result.CollectionResult; +import at.ac.univie.mminf.qskos4j.util.vocab.SkosOntology; import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; import org.openrdf.OpenRDFException; -import org.openrdf.model.*; -import org.openrdf.model.impl.StatementImpl; +import org.openrdf.model.Literal; +import org.openrdf.model.Resource; import org.openrdf.model.impl.URIImpl; import org.openrdf.query.BindingSet; import org.openrdf.query.QueryEvaluationException; @@ -15,68 +15,71 @@ import java.util.*; /** -* Finds Omitted or Invalid Language Tags. -*/ + * Finds Omitted or Invalid Language Tags. + */ public class OmittedOrInvalidLanguageTags extends Issue { - private Map> untaggedLiterals; + private Map> missingLangTags; private Map checkedLanguageTags; public OmittedOrInvalidLanguageTags() { super("oilt", - "Omitted or Invalid Language Tags", - "Finds omitted or invalid language tags of text literals", - IssueType.ANALYTICAL, - new URIImpl("https://github.com/cmader/qSKOS/wiki/Quality-Issues#omitted-or-invalid-language-tags") + "Omitted or Invalid Language Tags", + "Finds omitted or invalid language tags of text literals", + IssueType.ANALYTICAL, + new URIImpl("https://github.com/cmader/qSKOS/wiki/Quality-Issues#omitted-or-invalid-language-tags") ); } @Override protected OmittedOrInvalidLanguageTagsResult invoke() throws OpenRDFException { - TupleQueryResult result = repCon.prepareTupleQuery(QueryLanguage.SPARQL, createMissingLangTagQuery()) - .evaluate(); + TupleQueryResult result = repCon.prepareTupleQuery(QueryLanguage.SPARQL, createMissingLangTagQuery()).evaluate(); + generateMissingLangTagMap(result); - findAffectedStatements(result); - return new OmittedOrInvalidLanguageTagsResult(untaggedLiterals); - } + return new OmittedOrInvalidLanguageTagsResult(missingLangTags); + } private String createMissingLangTagQuery() throws OpenRDFException { - return SparqlPrefix.SKOS +" "+ SparqlPrefix.SKOSXL +" "+ SparqlPrefix.RDFS + - "SELECT ?s ?p ?literal "+ - "WHERE {" + - "?s ?p ?literal . " + + return SparqlPrefix.SKOS +" "+ SparqlPrefix.SKOSXL +" "+ SparqlPrefix.RDFS + + "SELECT ?literal ?s "+ + "WHERE {" + + "?s ?textProp ?literal . " + - "{?p rdfs:subPropertyOf rdfs:label}" + + "{?textProp rdfs:subPropertyOf rdfs:label}" + "UNION" + - "{?p rdfs:subPropertyOf skos:note}" + + "{?textProp rdfs:subPropertyOf skos:note}" + - "FILTER isLiteral(?literal) " + - "}"; - } + "FILTER isLiteral(?literal) " + + "}"; + } - private void findAffectedStatements(TupleQueryResult result) + private void generateMissingLangTagMap(TupleQueryResult result) throws QueryEvaluationException { + missingLangTags = new HashMap>(); checkedLanguageTags = new HashMap(); - affectedStatements = new ArrayList<>(); while (result.hasNext()) { BindingSet queryResult = result.next(); Resource subject = (Resource) queryResult.getValue("s"); - URI predicate = (URI) queryResult.getValue("p"); Literal literal = (Literal) queryResult.getValue("literal"); - if (literal.getDatatype() == null) { - String langTag = literal.getLanguage(); - if (langTag == null || !isValidLangTag(langTag)) { - affectedStatements.add(new StatementImpl(subject, predicate, literal)); - } + if (!SkosOntology.getInstance().isSkosResource(subject) && hasNoOrInvalidTag(literal)) { + addToMissingLangTagMap(subject, literal); } } } - private boolean isValidLangTag(String langTag) { + private boolean hasNoOrInvalidTag(Literal literal) { + if (literal.getDatatype() == null) { + String langTag = literal.getLanguage(); + return langTag == null || !isValidLangTag(langTag); + } + return false; + } + + private boolean isValidLangTag(String langTag) { Boolean validTag = checkedLanguageTags.get(langTag); if (validTag == null) { @@ -110,6 +113,15 @@ private boolean hasIsoLanguage(String langTag) { } return hasIsoLanguage; - } + } + + private void addToMissingLangTagMap(Resource resource, Literal literal) { + Collection literals = missingLangTags.get(resource); + if (literals == null) { + literals = new HashSet(); + missingLangTags.put(resource, literals); + } + literals.add(literal); + } } diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/OmittedOrInvalidLanguageTagsResult.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/OmittedOrInvalidLanguageTagsResult.java index f2b2e52..a253850 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/OmittedOrInvalidLanguageTagsResult.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/OmittedOrInvalidLanguageTagsResult.java @@ -1,19 +1,55 @@ package at.ac.univie.mminf.qskos4j.issues.language; +import at.ac.univie.mminf.qskos4j.result.CollectionResult; import at.ac.univie.mminf.qskos4j.result.Result; +import org.openrdf.model.Literal; import org.openrdf.model.Resource; +import java.io.BufferedWriter; +import java.io.IOException; import java.util.Collection; +import java.util.Iterator; import java.util.Map; -public class OmittedOrInvalidLanguageTagsResult extends Result>> { +public class OmittedOrInvalidLanguageTagsResult extends Result>> { - OmittedOrInvalidLanguageTagsResult(Map> data) { + OmittedOrInvalidLanguageTagsResult(Map> data) { super(data); } + @Override + protected void generateTextReport(BufferedWriter writer, ReportStyle style) throws IOException + { + switch (style) { + case SHORT: + new CollectionResult(getData().keySet()).generateReport(writer, ReportFormat.TXT, ReportStyle.SHORT); + break; + + case EXTENSIVE: + writer.write(generateExtensiveTextReport()); + break; + } + + } + + private String generateExtensiveTextReport() { + StringBuilder extensiveReport = new StringBuilder(); + + Iterator>> entryIt = getData().entrySet().iterator(); + while (entryIt.hasNext()) { + Map.Entry> entry = entryIt.next(); + extensiveReport.append("concept: '") + .append(entry.getKey().stringValue()) + .append("', literals with no or invalid language tags: ") + .append(entry.getValue().toString()) + .append(entryIt.hasNext() ? "\n" : ""); + } + + return extensiveReport.toString(); + } + @Override public boolean indicatesProblem() { - return false; //To change body of implemented methods use File | Settings | File Templates. + return !getData().isEmpty(); } } diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/UnidirectionallyRelatedConcepts.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/UnidirectionallyRelatedConcepts.java index 4b8eaaa..6444352 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/UnidirectionallyRelatedConcepts.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/UnidirectionallyRelatedConcepts.java @@ -2,9 +2,7 @@ import at.ac.univie.mminf.qskos4j.issues.Issue; import at.ac.univie.mminf.qskos4j.issues.concepts.AuthoritativeConcepts; -import at.ac.univie.mminf.qskos4j.result.CollectionResult; import at.ac.univie.mminf.qskos4j.util.Tuple; -import at.ac.univie.mminf.qskos4j.util.graph.UnidirectionalRelation; import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; import org.openrdf.OpenRDFException; import org.openrdf.model.Resource; @@ -14,84 +12,78 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashSet; +import java.util.HashMap; +import java.util.Map; /** * Finds Unidirectionally Related Concepts. */ - public class UnidirectionallyRelatedConcepts extends Issue> { - - private String[][] inversePropertyPairs = { - {"skos:broader", "skos:narrower"}, - {"skos:broaderTransitive", "skos:narrowerTransitive"}, - {"skos:topConceptOf", "skos:hasTopConcept"}, - {"skos:narrowMatch", "skos:broadMatch"}, - {"skos:related", "skos:related"}, - {"skos:relatedMatch", "skos:relatedMatch"}, - {"skos:exactMatch", "skos:exactMatch"}, - {"skos:closeMatch", "skos:closeMatch"} +public class UnidirectionallyRelatedConcepts extends Issue { + + private String[][] inversePropertyPairs = { + {"skos:broader", "skos:narrower"}, + {"skos:broaderTransitive", "skos:narrowerTransitive"}, + {"skos:topConceptOf", "skos:hasTopConcept"}, + {"skos:narrowMatch", "skos:broadMatch"}, + {"skos:related", "skos:related"}, + {"skos:relatedMatch", "skos:relatedMatch"}, + {"skos:exactMatch", "skos:exactMatch"}, + {"skos:closeMatch", "skos:closeMatch"} }; private final Logger logger = LoggerFactory.getLogger(UnidirectionallyRelatedConcepts.class); - - private Collection unidirectionalRelations; + private Map, String> omittedInverseRelations = new HashMap, String>(); private AuthoritativeConcepts authoritativeConcepts; public UnidirectionallyRelatedConcepts(AuthoritativeConcepts authoritativeConcepts) { super(authoritativeConcepts, - "urc", - "Unidirectionally Related Concepts", - "Concepts not including reciprocal relations", - IssueType.ANALYTICAL, - new URIImpl("https://github.com/cmader/qSKOS/wiki/Quality-Issues#unidirectionally-related-concepts")); + "urc", + "Unidirectionally Related Concepts", + "Concepts not including reciprocal relations", + IssueType.ANALYTICAL, + new URIImpl("https://github.com/cmader/qSKOS/wiki/Quality-Issues#unidirectionally-related-concepts")); this.authoritativeConcepts = authoritativeConcepts; } @Override - protected CollectionResult invoke() throws OpenRDFException { - unidirectionalRelations = new HashSet(); + protected UnidirectionallyRelatedConceptsResult invoke() throws OpenRDFException { String authResourceIdentifier = authoritativeConcepts.getAuthResourceIdentifier(); for (String[] inversePropertyPair : inversePropertyPairs) { TupleQuery query = repCon.prepareTupleQuery(QueryLanguage.SPARQL, createOmittedRelationsQuery(inversePropertyPair)); - addToOmittedInverseRelationsMap(query.evaluate(), inversePropertyPair, authResourceIdentifier); - } - - return new CollectionResult(unidirectionalRelations); - } + } + + return new UnidirectionallyRelatedConceptsResult(omittedInverseRelations); + } private String createOmittedRelationsQuery(String[] inverseRelations) { - return SparqlPrefix.SKOS +" "+ SparqlPrefix.RDFS + - "SELECT DISTINCT ?resource1 ?resource2 "+ - "WHERE {" + - "{?resource1 " +inverseRelations[0]+ " ?resource2 . "+ - "FILTER NOT EXISTS {?resource2 "+inverseRelations[1]+ " ?resource1}}" + - "UNION" + - "{?resource1 " +inverseRelations[1]+ " ?resource2 . "+ - "FILTER NOT EXISTS {?resource2 "+inverseRelations[0]+ " ?resource1}}" + - "}"; - } - - private void addToOmittedInverseRelationsMap( - TupleQueryResult result, - String[] inversePropertyPair, - String authResourceIdentifier) throws QueryEvaluationException - { - while (result.hasNext()) { - BindingSet queryResult = result.next(); - - Resource resource1 = (Resource) queryResult.getValue("resource1"); - Resource resource2 = (Resource) queryResult.getValue("resource2"); + return SparqlPrefix.SKOS +" "+ SparqlPrefix.RDFS + + "SELECT DISTINCT ?resource1 ?resource2 "+ + "WHERE {" + + "{?resource1 " +inverseRelations[0]+ " ?resource2 . "+ + "FILTER NOT EXISTS {?resource2 "+inverseRelations[1]+ " ?resource1}}" + + "UNION" + + "{?resource1 " +inverseRelations[1]+ " ?resource2 . "+ + "FILTER NOT EXISTS {?resource2 "+inverseRelations[0]+ " ?resource1}}" + + "}"; + } + + private void addToOmittedInverseRelationsMap( + TupleQueryResult result, + String[] inversePropertyPair, + String authResourceIdentifier) throws QueryEvaluationException + { + while (result.hasNext()) { + BindingSet queryResult = result.next(); + + Value value1 = queryResult.getValue("resource1"); + Value value2 = queryResult.getValue("resource2"); String inverseProperties = inversePropertyPair[0] +"/"+ inversePropertyPair[1]; - if (bothResourcesAreAuthoritative(resource1, resource2, authResourceIdentifier)) { - unidirectionalRelations.add(new UnidirectionalRelation( - new Tuple(resource1, resource2), - Arrays.asList(inversePropertyPair))); + if (bothResourcesAreAuthoritative(value1, value2, authResourceIdentifier)) { + addToMap(value1, value2, inverseProperties); } } } @@ -100,7 +92,22 @@ private boolean bothResourcesAreAuthoritative(Value res1, Value res2, String aut if (authResourceIdentifier.isEmpty()) return true; return res1.stringValue().contains(authResourceIdentifier) && - res2.stringValue().contains(authResourceIdentifier); + res2.stringValue().contains(authResourceIdentifier); + } + + private void addToMap(Value value1, Value value2, String inverseProperties) + { + try { + Resource resource1 = (Resource) value1; + Resource resource2 = (Resource) value2; + + omittedInverseRelations.put( + new Tuple(resource1, resource2), + inverseProperties); + } + catch (ClassCastException e) { + logger.error("Resource expected for relation " +inverseProperties+ " (" +value1+ " <-> " +value2+ ")"); + } } } diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/UnidirectionallyRelatedConceptsResult.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/UnidirectionallyRelatedConceptsResult.java new file mode 100644 index 0000000..3a75fc5 --- /dev/null +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/UnidirectionallyRelatedConceptsResult.java @@ -0,0 +1,19 @@ +package at.ac.univie.mminf.qskos4j.issues.relations; + +import at.ac.univie.mminf.qskos4j.result.Result; +import at.ac.univie.mminf.qskos4j.util.Tuple; +import org.openrdf.model.Resource; + +import java.util.Map; + +public class UnidirectionallyRelatedConceptsResult extends Result, String>> { + + protected UnidirectionallyRelatedConceptsResult(Map, String> data) { + super(data); + } + + @Override + public boolean indicatesProblem() { + return !getData().isEmpty(); + } +} diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/util/graph/UnidirectionalRelation.java b/src/main/java/at/ac/univie/mminf/qskos4j/util/graph/UnidirectionalRelation.java deleted file mode 100644 index ee0bf45..0000000 --- a/src/main/java/at/ac/univie/mminf/qskos4j/util/graph/UnidirectionalRelation.java +++ /dev/null @@ -1,31 +0,0 @@ -package at.ac.univie.mminf.qskos4j.util.graph; - -import at.ac.univie.mminf.qskos4j.util.Tuple; -import org.openrdf.model.Resource; - -import java.util.Collection; - -public class UnidirectionalRelation { - - private Tuple resources; - private Collection inverseRelations; - - public UnidirectionalRelation(Tuple resources, Collection inverseRelations) { - this.resources = resources; - this.inverseRelations = inverseRelations; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof UnidirectionalRelation) { - UnidirectionalRelation other = (UnidirectionalRelation) obj; - return resources.equals(other.resources) && inverseRelations.equals(other.inverseRelations); - } - return false; - } - - @Override - public int hashCode() { - return resources.hashCode() + inverseRelations.hashCode(); - } -} \ No newline at end of file diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/OmittedOrInvalidLanguageTagsTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/OmittedOrInvalidLanguageTagsTest.java index 4432dc4..4c3e4a9 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/OmittedOrInvalidLanguageTagsTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/OmittedOrInvalidLanguageTagsTest.java @@ -7,9 +7,11 @@ import org.junit.Test; import org.openrdf.OpenRDFException; import org.openrdf.model.Literal; +import org.openrdf.model.Resource; import java.io.IOException; import java.util.Collection; +import java.util.Map; /** * Created by christian @@ -39,7 +41,10 @@ public void testMissingLangTagCount_1() throws OpenRDFException { @Test public void testMissingLangTagCount_2() throws OpenRDFException { - Assert.assertEquals(2, oiltDeprecatedAndIllegal.getResult().getData().size()); + Map> missingLangTags = oiltDeprecatedAndIllegal.getResult().getData(); + + Assert.assertEquals(1, missingLangTags.keySet().size()); + Assert.assertEquals(2, countEntries(missingLangTags.values())); } private int countEntries(Collection> allLiterals) { diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/UnidirectionallyRelatedConceptsTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/UnidirectionallyRelatedConceptsTest.java index e319dd7..4f692f7 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/UnidirectionallyRelatedConceptsTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/UnidirectionallyRelatedConceptsTest.java @@ -3,7 +3,6 @@ import at.ac.univie.mminf.qskos4j.issues.concepts.AuthoritativeConcepts; import at.ac.univie.mminf.qskos4j.issues.concepts.InvolvedConcepts; import at.ac.univie.mminf.qskos4j.issues.relations.UnidirectionallyRelatedConcepts; -import at.ac.univie.mminf.qskos4j.util.graph.UnidirectionalRelation; import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; import junit.framework.Assert; import org.junit.Before; From b85747fd02fa05a8ba2ed8a82691f85afa9ab15f Mon Sep 17 00:00:00 2001 From: Christian Mader Date: Fri, 6 Dec 2013 11:37:11 +0100 Subject: [PATCH 04/19] code cleanup --- .../mminf/qskos4j/cmd/ConceptIterator.java | 44 ------- .../clusters/DisconnectedConceptClusters.java | 2 +- .../issues/concepts/InvolvedConcepts.java | 8 -- .../issues/concepts/OrphanConcepts.java | 3 +- .../issues/concepts/UndocumentedConcepts.java | 4 +- .../issues/inlinks/MissingInLinks.java | 8 +- .../labels/DisjointLabelsViolations.java | 3 +- .../labels/util/ResourceLabelsCollector.java | 2 +- .../OmittedOrInvalidLanguageTags.java | 3 +- ...UnidirectionallyRelatedConceptsResult.java | 28 +++++ .../ValuelessAssociativeRelations.java | 118 ++++++------------ .../UnsupportedReportFormatException.java | 4 - .../util/graph/AssociativeRelation.java | 38 ------ .../url/NoContentTypeProvidedException.java | 2 +- .../qskos4j/util/url/UrlDereferencer.java | 4 +- .../UnidirectionallyRelatedConceptsTest.java | 8 +- .../ValuelessAssociativeRelationsTest.java | 4 +- 17 files changed, 83 insertions(+), 200 deletions(-) delete mode 100644 src/main/java/at/ac/univie/mminf/qskos4j/cmd/ConceptIterator.java delete mode 100644 src/main/java/at/ac/univie/mminf/qskos4j/util/graph/AssociativeRelation.java diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/cmd/ConceptIterator.java b/src/main/java/at/ac/univie/mminf/qskos4j/cmd/ConceptIterator.java deleted file mode 100644 index 0e16fd0..0000000 --- a/src/main/java/at/ac/univie/mminf/qskos4j/cmd/ConceptIterator.java +++ /dev/null @@ -1,44 +0,0 @@ -package at.ac.univie.mminf.qskos4j.cmd; - -import java.io.*; -import java.util.Iterator; - -/** - * Iterates over a file which contains (substrings of) concept URIs in each lines - */ -class ConceptIterator implements Iterator { - - private BufferedReader br; - private String currentLine; - - ConceptIterator(File conceptsFile) throws IOException - { - FileInputStream fstream = new FileInputStream(conceptsFile); - DataInputStream in = new DataInputStream(fstream); - - br = new BufferedReader(new InputStreamReader(in)); - } - - @Override - public boolean hasNext() { - try { - currentLine = br.readLine(); - } - catch (IOException e) { - return false; - } - - return currentLine != null; - } - - @Override - public String next() { - return currentLine; - } - - @Override - public void remove() { - // not implemented intentionally - } - -} diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/clusters/DisconnectedConceptClusters.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/clusters/DisconnectedConceptClusters.java index 0c65e15..e0b2d6f 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/clusters/DisconnectedConceptClusters.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/clusters/DisconnectedConceptClusters.java @@ -103,7 +103,7 @@ private Collection findRelations(Resource concept) return allRelations; } - private String createConnectionsQuery(Value concept) throws OpenRDFException { + private String createConnectionsQuery(Value concept) { return SparqlPrefix.SKOS +" "+ SparqlPrefix.RDFS+ "SELECT DISTINCT ?otherConcept ?semanticRelation WHERE " + "{" + diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/concepts/InvolvedConcepts.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/concepts/InvolvedConcepts.java index 68ca5f3..2ec6c13 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/concepts/InvolvedConcepts.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/concepts/InvolvedConcepts.java @@ -3,7 +3,6 @@ import at.ac.univie.mminf.qskos4j.issues.Issue; import at.ac.univie.mminf.qskos4j.result.CollectionResult; import at.ac.univie.mminf.qskos4j.util.vocab.SkosOntology; -import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; import org.openrdf.OpenRDFException; import org.openrdf.model.Resource; import org.openrdf.model.Statement; @@ -42,11 +41,4 @@ protected CollectionResult invoke() throws OpenRDFException { return new CollectionResult(involvedConcepts); } - private String createConceptsQuery() throws OpenRDFException { - return SparqlPrefix.SKOS +" "+ SparqlPrefix.RDF+ - "SELECT DISTINCT ?concept WHERE {" + - "?concept rdf:type skos:Concept"+ - "}"; - } - } diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/concepts/OrphanConcepts.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/concepts/OrphanConcepts.java index 8876da1..3ae0908 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/concepts/OrphanConcepts.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/concepts/OrphanConcepts.java @@ -45,8 +45,7 @@ protected CollectionResult invoke() throws OpenRDFException { return new CollectionResult(orphanConcepts); } - private String createOrphanConceptsQuery() throws OpenRDFException - { + private String createOrphanConceptsQuery() { return SparqlPrefix.SKOS +" "+ SparqlPrefix.RDF +" "+ SparqlPrefix.RDFS + "SELECT DISTINCT ?concept WHERE " + "{" + diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/concepts/UndocumentedConcepts.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/concepts/UndocumentedConcepts.java index d90379b..bc382c4 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/concepts/UndocumentedConcepts.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/concepts/UndocumentedConcepts.java @@ -62,9 +62,7 @@ protected CollectionResult invoke() throws OpenRDFException { return new CollectionResult(undocumentedConcepts); } - private boolean isConceptDocumented(Value concept) - throws OpenRDFException - { + private boolean isConceptDocumented(Value concept) { for (String docProperty : documentationProperties) { if (conceptHasProperty(concept, docProperty)) { return true; diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/inlinks/MissingInLinks.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/inlinks/MissingInLinks.java index d2c1902..1b11fc6 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/inlinks/MissingInLinks.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/inlinks/MissingInLinks.java @@ -85,17 +85,11 @@ private void rankConcept(Resource concept) } for (RepositoryConnection connection : connections) { - try { - rankConceptForConnection(concept, connection); - } - catch (OpenRDFException e) { - logger.error("Error ranking concept '" +concept+ "', " + e.toString()); - } + rankConceptForConnection(concept, connection); } } private void rankConceptForConnection(Resource concept, RepositoryConnection connection) - throws OpenRDFException { String query = "SELECT distinct ?resource WHERE " + "{?resource ?p <"+concept.toString()+"> " + diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/DisjointLabelsViolations.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/DisjointLabelsViolations.java index fd4c8c9..6fc7732 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/DisjointLabelsViolations.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/DisjointLabelsViolations.java @@ -39,8 +39,7 @@ public DisjointLabelsViolations(ResourceLabelsCollector resourceLabelsCollector) protected LabelConflictsResult invoke() throws OpenRDFException { findNonDisjointLabels(); - LabelConflictsResult labelConflictsResult = new LabelConflictsResult(nonDisjointLabels.values()); - return labelConflictsResult; + return new LabelConflictsResult(nonDisjointLabels.values()); } private void findNonDisjointLabels() throws OpenRDFException { diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/ResourceLabelsCollector.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/ResourceLabelsCollector.java index a94c3ad..573bbe5 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/ResourceLabelsCollector.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/ResourceLabelsCollector.java @@ -22,7 +22,7 @@ public class ResourceLabelsCollector { private RepositoryConnection repCon; private Collection labeledResources; - public Collection getLabeledConcepts() throws OpenRDFException { + public Collection getLabeledConcepts() { labeledResources = new HashSet(); createLabeledResources(); return labeledResources; diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/OmittedOrInvalidLanguageTags.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/OmittedOrInvalidLanguageTags.java index 1d92773..c88fdfe 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/OmittedOrInvalidLanguageTags.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/OmittedOrInvalidLanguageTags.java @@ -39,8 +39,7 @@ protected OmittedOrInvalidLanguageTagsResult invoke() throws OpenRDFException { return new OmittedOrInvalidLanguageTagsResult(missingLangTags); } - private String createMissingLangTagQuery() throws OpenRDFException - { + private String createMissingLangTagQuery() { return SparqlPrefix.SKOS +" "+ SparqlPrefix.SKOSXL +" "+ SparqlPrefix.RDFS + "SELECT ?literal ?s "+ "WHERE {" + diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/UnidirectionallyRelatedConceptsResult.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/UnidirectionallyRelatedConceptsResult.java index 3a75fc5..68a6430 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/UnidirectionallyRelatedConceptsResult.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/UnidirectionallyRelatedConceptsResult.java @@ -1,9 +1,12 @@ package at.ac.univie.mminf.qskos4j.issues.relations; +import at.ac.univie.mminf.qskos4j.result.CollectionResult; import at.ac.univie.mminf.qskos4j.result.Result; import at.ac.univie.mminf.qskos4j.util.Tuple; import org.openrdf.model.Resource; +import java.io.BufferedWriter; +import java.io.IOException; import java.util.Map; public class UnidirectionallyRelatedConceptsResult extends Result, String>> { @@ -12,6 +15,31 @@ protected UnidirectionallyRelatedConceptsResult(Map, String> dat super(data); } + @Override + protected void generateTextReport(BufferedWriter writer, ReportStyle style) throws IOException + { + switch (style) { + case SHORT: + new CollectionResult>(getData().keySet()).generateReport(writer, ReportFormat.TXT, ReportStyle.SHORT); + break; + + case EXTENSIVE: + writer.write(generateExtensiveReport()); + break; + } + } + + private String generateExtensiveReport() + { + StringBuilder extensiveReport = new StringBuilder(); + + for (Tuple concepts : getData().keySet()) { + extensiveReport.append("concepts: ").append(concepts.toString()).append(", related by: '").append(getData().get(concepts)).append("'\n"); + } + + return extensiveReport.toString(); + } + @Override public boolean indicatesProblem() { return !getData().isEmpty(); diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/ValuelessAssociativeRelations.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/ValuelessAssociativeRelations.java index ef6db73..e577c15 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/ValuelessAssociativeRelations.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/ValuelessAssociativeRelations.java @@ -2,10 +2,9 @@ import at.ac.univie.mminf.qskos4j.issues.Issue; import at.ac.univie.mminf.qskos4j.result.CollectionResult; -import at.ac.univie.mminf.qskos4j.util.graph.AssociativeRelation; +import at.ac.univie.mminf.qskos4j.util.Tuple; import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; import org.openrdf.OpenRDFException; -import org.openrdf.model.Resource; import org.openrdf.model.URI; import org.openrdf.model.impl.URIImpl; import org.openrdf.query.*; @@ -14,97 +13,56 @@ import java.util.HashSet; /** -* Finds all Valueless Associative Relations. -*/ -public class ValuelessAssociativeRelations extends Issue> { + * Finds all Valueless Associative Relations. + */ +public class ValuelessAssociativeRelations extends Issue>> { public ValuelessAssociativeRelations() { super("var", - "Valueless Associative Relations", - "Finds sibling concept pairs that are also connected by an associative relation", - IssueType.ANALYTICAL, - new URIImpl("https://github.com/cmader/qSKOS/wiki/Quality-Issues#valueless-associative-relations")); + "Valueless Associative Relations", + "Finds sibling concept pairs that are also connected by an associative relation", + IssueType.ANALYTICAL, + new URIImpl("https://github.com/cmader/qSKOS/wiki/Quality-Issues#valueless-associative-relations")); } @Override - protected CollectionResult invoke() throws OpenRDFException { - Collection foundValuelessRelations = new HashSet(); + protected CollectionResult> invoke() throws OpenRDFException { + Collection> redundantAssociativeRelations = new HashSet>(); TupleQuery query = repCon.prepareTupleQuery(QueryLanguage.SPARQL, createRedundantAssociativeRelationsQuery()); - generateResultsList(foundValuelessRelations, query.evaluate()); - - return new CollectionResult(foundValuelessRelations); - } + generateResultsList(redundantAssociativeRelations, query.evaluate()); - private String createRedundantAssociativeRelationsQuery() { - return SparqlPrefix.SKOS + - "SELECT ?parent ?child ?otherchild ?relation "+ - "WHERE {" + - "{" + - "?parent skos:narrower|skos:narrowerTransitive|^skos:broader|^skos:broaderTransitive ?child . " + - "?parent skos:narrower|skos:narrowerTransitive|^skos:broader|^skos:broaderTransitive ?otherchild . " + - "}" + - "UNION" + - "{" + - "?child skos:narrower|skos:narrowerTransitive|^skos:broader|^skos:broaderTransitive ?parent . " + - "?otherchild skos:narrower|skos:narrowerTransitive|^skos:broader|^skos:broaderTransitive ?parent . " + - "}" + - - "?child ?relation ?otherchild. "+ - "FILTER (?relation IN (skos:related, skos:relatedMatch))"+ - "}"; - } - - private void generateResultsList(Collection allResults, TupleQueryResult result) - throws QueryEvaluationException - { - while (result.hasNext()) { - BindingSet queryResult = result.next(); - - Resource parent = (Resource) queryResult.getValue("parent"); - Resource child = (Resource) queryResult.getValue("child"); - Resource otherchild = (Resource) queryResult.getValue("otherchild"); - - URI relation = (URI) queryResult.getValue("relation"); - - allResults.add(new ValuelessAssociativeRelation( - new AssociativeRelation(child, otherchild, relation), - parent)); - } - } - - public class ValuelessAssociativeRelation { - - private AssociativeRelation relatedConcepts; - private Resource commonParent; - - ValuelessAssociativeRelation(AssociativeRelation relatedConcepts, Resource commonParent) { - this.relatedConcepts = relatedConcepts; - this.commonParent = commonParent; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof ValuelessAssociativeRelation) { - ValuelessAssociativeRelation other = (ValuelessAssociativeRelation) obj; - return relatedConcepts.equals(other.relatedConcepts) && commonParent.equals(other.commonParent); - } - return false; - } + return new CollectionResult>(redundantAssociativeRelations); + } - @Override - public int hashCode() { - return relatedConcepts.hashCode() + commonParent.hashCode(); - } + private String createRedundantAssociativeRelationsQuery() { + return SparqlPrefix.SKOS + + "SELECT ?parent ?child ?otherchild "+ + "WHERE {" + + "{" + + "?parent skos:narrower|skos:narrowerTransitive|^skos:broader|^skos:broaderTransitive ?child . " + + "?parent skos:narrower|skos:narrowerTransitive|^skos:broader|^skos:broaderTransitive ?otherchild . " + + "}" + + "UNION" + + "{" + + "?child skos:narrower|skos:narrowerTransitive|^skos:broader|^skos:broaderTransitive ?parent . " + + "?otherchild skos:narrower|skos:narrowerTransitive|^skos:broader|^skos:broaderTransitive ?parent . " + + "}" + + + "?child skos:related|skos:relatedMatch ?otherchild. "+ + "}"; + } - public AssociativeRelation getRelatedConcepts() { - return relatedConcepts; - } + private void generateResultsList(Collection> allResults, TupleQueryResult result) + throws QueryEvaluationException + { + while (result.hasNext()) { + BindingSet queryResult = result.next(); + URI child = (URI) queryResult.getValue("child"); + URI otherchild = (URI) queryResult.getValue("otherchild"); - public Resource getCommonParent() { - return commonParent; + allResults.add(new Tuple(child, otherchild)); } - } } diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/result/UnsupportedReportFormatException.java b/src/main/java/at/ac/univie/mminf/qskos4j/result/UnsupportedReportFormatException.java index 1280a27..d494545 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/result/UnsupportedReportFormatException.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/result/UnsupportedReportFormatException.java @@ -4,10 +4,6 @@ public class UnsupportedReportFormatException extends RuntimeException { private final static String MESSAGE = "Unsupported Result Format: '"; - public UnsupportedReportFormatException(String reportFormat) { - super(MESSAGE +reportFormat+ "'"); - } - public UnsupportedReportFormatException(Result.ReportFormat format) { super(MESSAGE +format.toString()+ "'"); } diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/util/graph/AssociativeRelation.java b/src/main/java/at/ac/univie/mminf/qskos4j/util/graph/AssociativeRelation.java deleted file mode 100644 index 793af73..0000000 --- a/src/main/java/at/ac/univie/mminf/qskos4j/util/graph/AssociativeRelation.java +++ /dev/null @@ -1,38 +0,0 @@ -package at.ac.univie.mminf.qskos4j.util.graph; - -import at.ac.univie.mminf.qskos4j.util.Tuple; -import org.openrdf.model.Resource; -import org.openrdf.model.URI; - -public class AssociativeRelation { - - private Tuple concepts; - private URI uri; - - public AssociativeRelation(Resource src, Resource dst, URI uri) { - concepts = new Tuple(src, dst); - this.uri = uri; - } - - public Tuple getConcepts() { - return concepts; - } - - public URI getUri() { - return uri; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof AssociativeRelation) { - AssociativeRelation other = (AssociativeRelation) obj; - return other.concepts.equals(concepts) && other.uri.equals(uri); - } - return false; - } - - @Override - public int hashCode() { - return concepts.hashCode() + uri.hashCode(); - } -} diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/util/url/NoContentTypeProvidedException.java b/src/main/java/at/ac/univie/mminf/qskos4j/util/url/NoContentTypeProvidedException.java index dc60866..1590684 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/util/url/NoContentTypeProvidedException.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/util/url/NoContentTypeProvidedException.java @@ -1,6 +1,6 @@ package at.ac.univie.mminf.qskos4j.util.url; @SuppressWarnings("serial") -public class NoContentTypeProvidedException extends Exception { +public class NoContentTypeProvidedException extends RuntimeException { } diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/util/url/UrlDereferencer.java b/src/main/java/at/ac/univie/mminf/qskos4j/util/url/UrlDereferencer.java index 2305120..bbf63e7 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/util/url/UrlDereferencer.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/util/url/UrlDereferencer.java @@ -19,9 +19,7 @@ public class UrlDereferencer { private final Logger logger = LoggerFactory.getLogger(UrlDereferencer.class); private final int HTTP_GET_TIMOUT_MILLIS = 60000; - public String getContentType(URL url) - throws UrlNotDereferencableException, NoContentTypeProvidedException - { + public String getContentType(URL url) throws UrlNotDereferencableException { try { HttpResponse response = sendRequest(url); diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/UnidirectionallyRelatedConceptsTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/UnidirectionallyRelatedConceptsTest.java index 4f692f7..5b0851d 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/UnidirectionallyRelatedConceptsTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/UnidirectionallyRelatedConceptsTest.java @@ -3,14 +3,16 @@ import at.ac.univie.mminf.qskos4j.issues.concepts.AuthoritativeConcepts; import at.ac.univie.mminf.qskos4j.issues.concepts.InvolvedConcepts; import at.ac.univie.mminf.qskos4j.issues.relations.UnidirectionallyRelatedConcepts; +import at.ac.univie.mminf.qskos4j.util.Tuple; 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 org.openrdf.model.Resource; import java.io.IOException; -import java.util.Collection; +import java.util.Map; public class UnidirectionallyRelatedConceptsTest { @@ -24,7 +26,7 @@ public void setUp() throws OpenRDFException, IOException { @Test public void testMissingInverseRelationsCount() throws OpenRDFException { - Collection unidirectionalRelations = unidirectionallyRelatedConcepts.getResult().getData(); - Assert.assertEquals(8, unidirectionalRelations.size()); + Map, String> missingRelations = unidirectionallyRelatedConcepts.getResult().getData(); + Assert.assertEquals(8, missingRelations.size()); } } diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/ValuelessAssociativeRelationsTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/ValuelessAssociativeRelationsTest.java index 49732a9..064d4d4 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/ValuelessAssociativeRelationsTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/ValuelessAssociativeRelationsTest.java @@ -1,11 +1,13 @@ package at.ac.univie.mminf.qskos4j.issues; import at.ac.univie.mminf.qskos4j.issues.relations.ValuelessAssociativeRelations; +import at.ac.univie.mminf.qskos4j.util.Tuple; 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 org.openrdf.model.URI; import java.io.IOException; import java.util.Collection; @@ -22,7 +24,7 @@ public void setUp() throws OpenRDFException, IOException { @Test public void testRedundantAssociativeRelationsCount() throws OpenRDFException { - Collection redAssRels = valuelessAssociativeRelations.getResult().getData(); + Collection> redAssRels = valuelessAssociativeRelations.getResult().getData(); Assert.assertEquals(6, redAssRels.size()); } } From 3f0dd144edd64c423ddf67fa2659de8a61c09734 Mon Sep 17 00:00:00 2001 From: Christian Mader Date: Fri, 6 Dec 2013 11:45:09 +0100 Subject: [PATCH 05/19] code cleanup --- .../mminf/qskos4j/issues/inlinks/MissingInLinks.java | 8 ++++---- .../mminf/qskos4j/issues/outlinks/BrokenLinks.java | 8 ++++---- .../mminf/qskos4j/issues/outlinks/MissingOutLinks.java | 10 ++++------ 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/inlinks/MissingInLinks.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/inlinks/MissingInLinks.java index 1b11fc6..ef58526 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/inlinks/MissingInLinks.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/inlinks/MissingInLinks.java @@ -3,7 +3,7 @@ import at.ac.univie.mminf.qskos4j.issues.Issue; import at.ac.univie.mminf.qskos4j.issues.concepts.AuthoritativeConcepts; import at.ac.univie.mminf.qskos4j.progress.MonitoredIterator; -import at.ac.univie.mminf.qskos4j.result.CollectionResult; +import at.ac.univie.mminf.qskos4j.result.ExtrapolatedCollectionResult; import at.ac.univie.mminf.qskos4j.util.RandomSubSet; import org.openrdf.OpenRDFException; import org.openrdf.model.Resource; @@ -27,7 +27,7 @@ * Missing In-Links * ). */ -public class MissingInLinks extends Issue> { +public class MissingInLinks extends Issue> { private final Logger logger = LoggerFactory.getLogger(MissingInLinks.class); @@ -49,7 +49,7 @@ public MissingInLinks(AuthoritativeConcepts authoritativeConcepts) { } @Override - protected CollectionResult invoke() throws OpenRDFException { + protected ExtrapolatedCollectionResult invoke() throws OpenRDFException { Collection conceptsToCheck = getConceptsToCheck(randomSubsetSize_percent); if (randomSubsetSize_percent != null) { @@ -65,7 +65,7 @@ protected CollectionResult invoke() throws OpenRDFException { rankConcept(conceptIt.next()); } - return new CollectionResult(extractUnreferencedConcepts()); + return new ExtrapolatedCollectionResult(extractUnreferencedConcepts(), randomSubsetSize_percent); } private Collection getConceptsToCheck(Float randomSubsetSize_percent) throws OpenRDFException diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/outlinks/BrokenLinks.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/outlinks/BrokenLinks.java index 6c7d8c0..56e8344 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/outlinks/BrokenLinks.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/outlinks/BrokenLinks.java @@ -2,7 +2,7 @@ import at.ac.univie.mminf.qskos4j.issues.Issue; import at.ac.univie.mminf.qskos4j.progress.MonitoredIterator; -import at.ac.univie.mminf.qskos4j.result.CollectionResult; +import at.ac.univie.mminf.qskos4j.result.ExtrapolatedCollectionResult; import at.ac.univie.mminf.qskos4j.util.RandomSubSet; import at.ac.univie.mminf.qskos4j.util.url.NoContentTypeProvidedException; import at.ac.univie.mminf.qskos4j.util.url.UrlDereferencer; @@ -24,7 +24,7 @@ * * Finds Broken Links. */ -public class BrokenLinks extends Issue> { +public class BrokenLinks extends Issue> { private final Logger logger = LoggerFactory.getLogger(BrokenLinks.class); private final static String NO_CONTENT_TYPE = "n/a"; @@ -48,9 +48,9 @@ public BrokenLinks(HttpURIs httpURIs) { } @Override - protected CollectionResult invoke() throws OpenRDFException { + protected ExtrapolatedCollectionResult invoke() throws OpenRDFException { dereferenceURIs(); - return new CollectionResult(collectUnavailableURLs()); + return new ExtrapolatedCollectionResult(collectUnavailableURLs(), randomSubsetSize_percent); } private void dereferenceURIs() throws OpenRDFException diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/outlinks/MissingOutLinks.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/outlinks/MissingOutLinks.java index 512e70f..627eaaa 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/outlinks/MissingOutLinks.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/outlinks/MissingOutLinks.java @@ -57,12 +57,10 @@ private void findResourcesForConcepts(Collection concepts) throws Open private Collection getURIsOfConcept(Resource concept) throws RepositoryException { Collection urisForConcept = new ArrayList(); - if (concept instanceof Resource) { - RepositoryResult conceptAsSubject = repCon.getStatements((Resource) concept, null, null, false); - while (conceptAsSubject.hasNext()) { - Value object = conceptAsSubject.next().getObject(); - addToUriCollection(object, urisForConcept); - } + RepositoryResult conceptAsSubject = repCon.getStatements((Resource) concept, null, null, false); + while (conceptAsSubject.hasNext()) { + Value object = conceptAsSubject.next().getObject(); + addToUriCollection(object, urisForConcept); } RepositoryResult conceptAsObject = repCon.getStatements(null, null, concept, false); From 247eb67804b7f8f70bc5134cab0687ee63e6494b Mon Sep 17 00:00:00 2001 From: Christian Mader Date: Fri, 6 Dec 2013 12:26:20 +0100 Subject: [PATCH 06/19] issue #27 --- .../mminf/qskos4j/cmd/ReportCollector.java | 47 +++++++++---------- .../language/IncompleteLangCovResult.java | 4 +- .../OmittedOrInvalidLanguageTagsResult.java | 4 +- ...UnidirectionallyRelatedConceptsResult.java | 4 +- .../qskos4j/result/CollectionResult.java | 4 +- .../mminf/qskos4j/result/NumberResult.java | 4 +- .../univie/mminf/qskos4j/result/Result.java | 2 +- 7 files changed, 34 insertions(+), 35 deletions(-) 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 4a12199..d08cbd2 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 @@ -33,21 +33,25 @@ void outputIssuesReport(boolean shouldWriteGraphs) BufferedWriter reportWriter = new BufferedWriter(new FileWriter(reportFile)); processIssues(); - writeReportHeader(reportWriter, reportFile); - writeReportSummary(reportWriter); + String reportSummary = createReportSummary(); + logger.info("\n" +reportSummary); + + writeReportHeader(reportWriter, reportFile, reportSummary); writeReportBody(reportWriter, reportFile, shouldWriteGraphs); reportWriter.close(); } private void writeReportHeader(BufferedWriter reportWriter, - File reportFile) throws IOException { + File reportFile, + String reportSummary) throws IOException + { String issuedDate = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z").format(new Date()); String fileName = reportFile.getAbsolutePath(); - reportWriter.write("This is the quality report of file " +fileName+ ", generated on " +issuedDate); + reportWriter.write("This is the quality report of file " +fileName+ ", generated by qSKOS on " +issuedDate); reportWriter.newLine(); reportWriter.newLine(); - + reportWriter.write(reportSummary); } private void processIssues() throws OpenRDFException { @@ -62,29 +66,21 @@ private void processIssues() throws OpenRDFException { } - logger.info("Result complete!"); - - + logger.info("Report complete!"); } - private void writeReportSummary(BufferedWriter reportWriter) throws IOException, OpenRDFException { - reportWriter.write("Summary of Quality Issues:\n"); + private String createReportSummary() throws IOException, OpenRDFException { + StringBuffer summary = new StringBuffer(); + summary.append("* Summary of Quality Issue Occurrences:\n"); for (Issue issue : issues) { - issue.getResult().indicatesProblem(); - - - StringWriter stringWriter = new StringWriter(); - BufferedWriter writer = new BufferedWriter(stringWriter); - issue.getResult().generateReport( - writer, - Result.ReportFormat.TXT, - Result.ReportStyle.SHORT); - writer.close(); - reportWriter.write(issue.getName() + ": " +stringWriter.toString()+ "\n"); + long occurrenceCount = issue.getResult().occurrenceCount(); + String occurrenceText = occurrenceCount == 0 ? "OK (no occurrences found)" : Long.toString(occurrenceCount); + summary.append(issue.getName() + ": " + occurrenceText + "\n"); } - reportWriter.newLine(); + summary.append("\n"); + return summary.toString(); } private void writeReportBody(BufferedWriter reportWriter, @@ -92,6 +88,7 @@ private void writeReportBody(BufferedWriter reportWriter, boolean shouldWriteGraphs) throws IOException, OpenRDFException { + reportWriter.write("* Detailed coverage of each Quality Issue:\n\n"); Iterator issueIt = issues.iterator(); while (issueIt.hasNext()) { Issue issue = issueIt.next(); @@ -121,8 +118,10 @@ private void writeTextReport(Issue issue, BufferedWriter writer) writer.newLine(); issue.getResult().generateReport(writer, Result.ReportFormat.TXT, Result.ReportStyle.SHORT); - writer.newLine(); - issue.getResult().generateReport(writer, Result.ReportFormat.TXT, Result.ReportStyle.EXTENSIVE); + if (issue.getResult().occurrenceCount() > 0) { + 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/language/IncompleteLangCovResult.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/IncompleteLangCovResult.java index 994e421..3d895c0 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/IncompleteLangCovResult.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/IncompleteLangCovResult.java @@ -49,8 +49,8 @@ private String generateExtensiveTextReport() { } @Override - public boolean indicatesProblem() { - return !getData().isEmpty(); + public long occurrenceCount() { + return getData().size(); } } diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/OmittedOrInvalidLanguageTagsResult.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/OmittedOrInvalidLanguageTagsResult.java index a253850..48b72f9 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/OmittedOrInvalidLanguageTagsResult.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/OmittedOrInvalidLanguageTagsResult.java @@ -49,7 +49,7 @@ private String generateExtensiveTextReport() { } @Override - public boolean indicatesProblem() { - return !getData().isEmpty(); + public long occurrenceCount() { + return getData().size(); } } diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/UnidirectionallyRelatedConceptsResult.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/UnidirectionallyRelatedConceptsResult.java index 68a6430..4e86b5c 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/UnidirectionallyRelatedConceptsResult.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/UnidirectionallyRelatedConceptsResult.java @@ -41,7 +41,7 @@ private String generateExtensiveReport() } @Override - public boolean indicatesProblem() { - return !getData().isEmpty(); + public long occurrenceCount() { + return getData().size(); } } diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/result/CollectionResult.java b/src/main/java/at/ac/univie/mminf/qskos4j/result/CollectionResult.java index 579e0d0..8b719a9 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/result/CollectionResult.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/result/CollectionResult.java @@ -26,8 +26,8 @@ protected void generateTextReport(BufferedWriter osw, ReportStyle style) throws } @Override - public boolean indicatesProblem() { - return !getData().isEmpty(); + public long occurrenceCount() { + return getData().size(); } public String generateExtensiveTextReport() { diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/result/NumberResult.java b/src/main/java/at/ac/univie/mminf/qskos4j/result/NumberResult.java index 3375fd4..5b18034 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/result/NumberResult.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/result/NumberResult.java @@ -23,8 +23,8 @@ protected void generateTextReport(BufferedWriter osw, ReportStyle style) throws } @Override - public boolean indicatesProblem() { - return getData().intValue() != 0; + public long occurrenceCount() { + return getData().longValue(); } } 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 d65d4a5..5d06c57 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,6 @@ public String toString() { } } - public abstract boolean indicatesProblem(); + public abstract long occurrenceCount(); } From 1b67c7380ae118cfc6b80f6d6da288265f81ef5f Mon Sep 17 00:00:00 2001 From: Christian Mader Date: Tue, 17 Dec 2013 17:08:34 +0100 Subject: [PATCH 07/19] Merge branch 'devel', version bump Conflicts: pom.xml src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/SolelyTransitivelyRelatedConcepts.java src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/UnidirectionallyRelatedConcepts.java src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/UnidirectionallyRelatedConceptsReport.java src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/ValuelessAssociativeRelations.java src/main/java/at/ac/univie/mminf/qskos4j/issues/skosintegrity/MappingClashes.java src/main/java/at/ac/univie/mminf/qskos4j/issues/skosintegrity/RelationClashes.java src/main/java/at/ac/univie/mminf/qskos4j/util/Tuple.java src/main/java/at/ac/univie/mminf/qskos4j/util/TupleQueryResultUtil.java src/test/java/at/ac/univie/mminf/qskos4j/issues/OmittedOrInvalidLanguageTagsTest.java src/test/java/at/ac/univie/mminf/qskos4j/issues/UnidirectionallyRelatedConceptsTest.java src/test/java/at/ac/univie/mminf/qskos4j/issues/ValuelessAssociativeRelationsTest.java --- README.rdoc | 37 +++++++++++++------------------------ pom.xml | 2 +- 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/README.rdoc b/README.rdoc index de56a0e..384be12 100644 --- a/README.rdoc +++ b/README.rdoc @@ -10,13 +10,13 @@ Currently we work on integrating qSKOS into the {PoolParty Thesaurus Server}[htt * Verify that Java v.1.7 or greater is installed: javac -version * Make sure Maven v.3.0 or greater is installed: mvn -v -* Optional: Make sure you have the current version of the {git version control system}[http://git-scm.com/] installed on your system. +* Make sure you have the current version of the {git version control system}[http://git-scm.com/] installed on your system === 1) Get the source code You have two options: * Clone the project (git clone https://github.com/cmader/qSKOS.git) to your system using git. -* Download the packaged source files as {zip archive}[https://github.com/cmader/qSKOS/archive/master.zip] and extract it to a properly named directory, e.g., +qSKOS+. +* Download the latest {release}[https://github.com/cmader/qSKOS/releases] of the project and extract it to a properly named directory, e.g., +qSKOS+. === 2) Build the tool @@ -29,6 +29,7 @@ You have two options: === General Usage +* Change to the +qSKOS/target+ directory * Run the tool using java -jar qSKOS-cmd.jar * A synopsis on the application's parameters is displayed. @@ -37,16 +38,16 @@ You have two options: The following examples demonstrate typical qSKOS use cases. For demonstration purposes we use the IPSV vocabulary available from the {qSKOS-data}[https://github.com/cmader/qSKOS-data] repository: {Download IPSV vocabulary}[https://github.com/cmader/qSKOS-data/raw/master/IPSV/ipsv_skos.rdf.bz2]. In the examples below we assume that the vocabulary file is placed in the same directory than the +qSKOS-cmd.jar+ file. ==== 1) Retrieving basic vocabulary statistics -Basic statistical properties (e.g., number of concepts, semantic relations or concept schemes) can be retrieved by issuing the command: +Basic statistical properties (e.g., number of concepts, semantic relations or concept schemes) can be retrieved and stored into the file +report.txt+ by issuing the command: -java -jar qSKOS-cmd.jar summarize ipsv_skos.rdf +java -jar qSKOS-cmd.jar summarize ipsv_skos.rdf -o report.txt ==== 2) Finding quality issues -To perform a complete analysis of all quality issues, use the following command: +To perform an analysis for quality issues, use the following command: -java -jar qSKOS-cmd.jar analyze -dc mil,mol,bl ipsv_skos.rdf +java -jar qSKOS-cmd.jar analyze -dc mil,bl ipsv_skos.rdf -o report.txt -Please keep in mind that a full analysis can take quite some time, depending on the vocabulary size and structure. Especially link checking sometimes can take hours, so it is often useful to analyze only a subset of all issues. In the following examples you'll learn how this can be done. In the example above, checking for missing inlinks, missing outlinks and broken links has been disabled to speed up the checking process (using the parameter -dc mil,mol,bl). +Please keep in mind that a full analysis can take quite some time, depending on the vocabulary size and structure. Especially link checking sometimes can take hours, so it is often useful to analyze only a subset of all issues. In the following examples you'll learn how this can be done. In the example above, checking for missing inlinks and broken links has been disabled to speed up the checking process (using the parameter -dc mil,bl). ==== 3) Output a list of *supported* statistical properties and quality issues By starting the evaluation using either the +summarize+ or +analyze+ command and omitting the vocabulary filename, you get an overview about the supported statistical properties and quality issues: @@ -68,19 +69,14 @@ Every property/issue is identified by an ID string, has a name and a description ==== 4) Testing for a specific issue or a subset of issues Specific issues can be tested by passing the -c parameter followed by one or more (comma-separated) issue IDs (see example above). Keep in mind, that the -c parameter has to be placed between between the +analyze+ command and the vocabulary file like this: -java -jar qSKOS-cmd.jar analyze -c ol,oc ipsv_skos.rdf +java -jar qSKOS-cmd.jar analyze -c ol,oc ipsv_skos.rdf -o report.txt The command above triggers analysis of the "Overlapping Labels" and "Orphan Concepts" issues. In a very similar way it is possible to explicitly *exclude* issues from testing. For example, the command -java -jar qSKOS-cmd.jar analyze -dc mil ipsv_skos.rdf +java -jar qSKOS-cmd.jar analyze -dc mil ipsv_skos.rdf -o report.txt checks for all issues except "Missing In-Links". -==== 5) Producing more detailed reports -In most cases it is not sufficient to know about the presence and number of quality issues but also which resource cause these potential problems. This can be reported by using the -e (extensive) command line switch. - -For example, the command java -jar qSKOS-cmd.jar analyze -c usr ipsv_skos.rdf reports one "Undefined SKOS Resources". Issuing the command java -jar qSKOS-cmd.jar analyze -e -c usr ipsv_skos.rdf (mind the additional -e parameter after the +analyze+ command) reports the resource (http://www.w3.org/2004/02/skos/core#prefSymbol) causing a potential problem. - == FAQ === What are "Authoritative Concepts"? @@ -88,13 +84,6 @@ Every concept in a SKOS vocabulary is a resource and should be identified by an qSKOS is to some extent able to perform this distinction by examining the host part of the concept's URIs. Depending on the vocabulary's structure in some cases it might be needed to pass an "Authoritative resource identifier" (command line argument -a) to qSKOS. This is a substring of an URI that identifies a concept as authoritative. -=== How can I write the result to a file? -Report output is performed directly on the console (+stdout+). If you want them to be contained in text files, you can use the output redirection operator (>) of your operating system's command line shell. Here's an example: - -java -jar qSKOS-cmd.jar summarize -q -c ac ipsv_skos.rdf > auth_concepts.txt generates a text file auth_concepts.txt containing the result. - -A command-line parameter that might be handy when redirecting qSKOS' output into a file is -np. It suppresses output of the progress indicator which is thus not written into the generated result. - === What version of qSKOS do I use? Simply pass the command line switch -v like this: @@ -108,11 +97,11 @@ The +QSkos+ class serves as facade for calculating all criteria. For each criter // instantiation qskos = new QSkos(new File("stw.rdf")); - qskos.setAuthoritativeResourceIdentifier("zbw.eu"); + qskos.setAuthResourceIdentifier("zbw.eu"); // the fun part - DisconnectedConceptClusters dcc = qskos.getDisconnectedConceptClusters(); - dcc.getResult(); + Issue orphanConcepts = qSkos.getIssues("oc").iterator().next(); + long numberOfOrphans = issue.getResult().occurrenceCount()); == Publications A subset of the quality issues qSKOS supports (including an analysis of several existing vocabularies) have been published in our paper {Finding Quality Issues in SKOS Vocabularies}[http://arxiv.org/abs/1206.1339v1]. diff --git a/pom.xml b/pom.xml index fbddfed..563dca4 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 at.ac.univie.mminf qSKOS - 0.11.0 + 1.0.0 qSKOS From a31d0a252d73eb78fca0bc6dd1d86c14f5824959 Mon Sep 17 00:00:00 2001 From: Christian Mader Date: Tue, 17 Dec 2013 17:14:05 +0100 Subject: [PATCH 08/19] Merge branch 'devel', version bump Conflicts: pom.xml src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/SolelyTransitivelyRelatedConcepts.java src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/UnidirectionallyRelatedConcepts.java src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/UnidirectionallyRelatedConceptsReport.java src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/ValuelessAssociativeRelations.java src/main/java/at/ac/univie/mminf/qskos4j/issues/skosintegrity/MappingClashes.java src/main/java/at/ac/univie/mminf/qskos4j/issues/skosintegrity/RelationClashes.java src/main/java/at/ac/univie/mminf/qskos4j/util/Tuple.java src/main/java/at/ac/univie/mminf/qskos4j/util/TupleQueryResultUtil.java src/test/java/at/ac/univie/mminf/qskos4j/issues/OmittedOrInvalidLanguageTagsTest.java src/test/java/at/ac/univie/mminf/qskos4j/issues/UnidirectionallyRelatedConceptsTest.java src/test/java/at/ac/univie/mminf/qskos4j/issues/ValuelessAssociativeRelationsTest.java --- .../mminf/qskos4j/issues/OmittedOrInvalidLanguageTagsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/OmittedOrInvalidLanguageTagsTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/OmittedOrInvalidLanguageTagsTest.java index 4c3e4a9..33ccb80 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/OmittedOrInvalidLanguageTagsTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/OmittedOrInvalidLanguageTagsTest.java @@ -57,7 +57,7 @@ private int countEntries(Collection> allLiterals) { @Test public void testMissingLangTagCount_3() throws OpenRDFException { - Assert.assertEquals(1, oiltLangTags.getResult().getData().size()); + Assert.assertEquals(2, oiltLangTags.getResult().getData().size()); } } From 0cbb5411fc90538fb691cad61f6944e3ad37baab Mon Sep 17 00:00:00 2001 From: Christian Mader Date: Tue, 17 Dec 2013 17:22:35 +0100 Subject: [PATCH 09/19] Merge branch 'devel', version bump Conflicts: pom.xml src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/SolelyTransitivelyRelatedConcepts.java src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/UnidirectionallyRelatedConcepts.java src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/UnidirectionallyRelatedConceptsReport.java src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/ValuelessAssociativeRelations.java src/main/java/at/ac/univie/mminf/qskos4j/issues/skosintegrity/MappingClashes.java src/main/java/at/ac/univie/mminf/qskos4j/issues/skosintegrity/RelationClashes.java src/main/java/at/ac/univie/mminf/qskos4j/util/Tuple.java src/main/java/at/ac/univie/mminf/qskos4j/util/TupleQueryResultUtil.java src/test/java/at/ac/univie/mminf/qskos4j/issues/OmittedOrInvalidLanguageTagsTest.java src/test/java/at/ac/univie/mminf/qskos4j/issues/UnidirectionallyRelatedConceptsTest.java src/test/java/at/ac/univie/mminf/qskos4j/issues/ValuelessAssociativeRelationsTest.java --- src/main/resources/qskos_logo.png | Bin 0 -> 6022 bytes src/main/resources/qskos_logo.svg | 246 ------------------------------ 2 files changed, 246 deletions(-) create mode 100644 src/main/resources/qskos_logo.png delete mode 100644 src/main/resources/qskos_logo.svg diff --git a/src/main/resources/qskos_logo.png b/src/main/resources/qskos_logo.png new file mode 100644 index 0000000000000000000000000000000000000000..83fd4e540decc298e267f456e5fe3dfc49d731d8 GIT binary patch literal 6022 zcmV;17kTK3P)8T6HOUtyEp&txx1BL;~^>FoEzeAqj*)UX#Zp znauON_P&3da5zjR5fHk%?sET;m9x*@`+WO%zVG)v_8G(&gYVn5X!v^wu2tgzpt-r} zlTSY3dHyQqD~hse)laNe>-SJ{0O0rgPnYYq9}?0fDjS{!DKT1 zleZU*MkPrC0F%jNHk+?vg-|G@sww~wLIgqJIBqB?5kiEJtCN*dE?y_wv**i-ii+-T zpC*SUNDF84BJ}P1>gnkzE89_9TN@090GNgn z&-00ii5`!qsAyb4K|vfSuVG`1ojiGB-MV#tzn|kcbg9%npRcj8@xX!o2)#99#>|x~ zS7O``N@Zo`zJ2?&H!90=W@hF2F{`|Y>e+r4^EVPWBd1+hwS{`~pZUtjC>dSe9W z?(VLutJ}JD>jMw09zA;WU|WzRY2(I?+qP}R7!TC2j*gB~r%r9%y47yCuUfV0h8rea z7bqEH8#a8pb?a7)aa`s_2qA4-FHP%94LUMR-sVnuYY~A`Dis<&<1MhHQdVL}*R8Kro=-fi2q={U-=Ja_KgtgNgUeO$kOy)4Ud z--M0@rF8xJ^))r82Ht(=opV_c17)-C1fxq|OdZUI4f-q*x7?;aU2#!X@o}TXZ z_I9t=dv*H$`RCh=mu|Ov>C$B}!!~Z*7!HSZ95KfE`S~7?hcRevZKnym%cGdX=7vK^Uptb6^pmGdn+p|^-Ds?9e4a7Mt53UTaO&6)a{)y zcGq2ZmzI`lx}zvcMMcHC@4lnE!G?y0rl#iH++2Ny^737})~l*IapI&^t5)efTIWX} zeY9&=`SlIa>+9=v)Kpcy_0~D*>FGv8!x$UIx}x@ve|!*)MsBT=-3B?1D=8_-&(GJhJ4I0r9N1@wI%r#4tG)uqam$x4j}e#nKWIL)# zWl2>;P(`eYSP_vdQbks&sxn{$Lr5bP316&P82-$2li^an8{N;G3 zNF?&{#~Cs*|+58jvUAUp-@O)&|()aEV|+>} zegFOS16MGaOgzuqY&JqjOz^-BM4ccZBVR}^^yAcOl>}5KtH2Ngf)J0fjhV1&g|H*q zn0aciU!Pb|P@t-+&R-bgKmF;MrAwDhojTQScW9mI>FKY&`kJ<1#)d*tzgJmV(c9ar z_a`MKEm^W;;P|$-cH zxVpOf>8Jm&Y}vB0V+(b|U%Yt9;>EWk!~jr?YF+{*1Il4b!2+hZD2wa9;`jF$FB20J2V30fbar%f=X3czzk!I5r;8G7#Lyz z2mk>?1LG#_V?cym|BEP6>x2#!Iu=GT7pRVAdr>2n7NcBb(IJ)cfwc-zYyqNKq88*ZbC6 zfBV(19@(^MQ&(5lU}edRT1jP;KQ&Rw*-N7Y0WhSPNuqRmRL?mqM;Ye8?7&Im+C|HG zVDT9?F)``E2OoO#%{Q8xn~lDY5CT9dD=Vw2s`B#k7A;ylX3UtO(d2nP#<7T^xN_ya zgC!xdEMLlKgI2lBX5rHG=8|_XbLLD{Ro1Uxe?jbv6d8#`Kl^M$dHK%b;^L)Cm+Gt) zM=PxfR!c#h9Hj^l00=0tYe(^k?ZLK&V0T-nt0{Em>ww&ujL1-)H#^(&^wZBQT)1#x zzM)B0Utj;i3v2f5*?q+&ERH*L=-?2Xa4F+oLGT~bGkf+efBDOEBSz#7q;HPnB9X{} z0|);2$3OafzW7iw#_TR63tb3!0AN@V>qa#Dd{OxaVm6w+fS#YANs;a7Lj0z4NI&|X1@j)JnW2O&LV7*j- zv^(zj!GZ+~eLi1#`OYuD{8EdA^k8N4=1rqVkB(bOQxs*{vSkw{6w9*w$}2DT_4R2J zIgZ=Bd2@dL=z*brOr1>>qk{<+4u^Fy7-ITUoHf=h6`m`RO z5JG~%z#DJ8{@7!W>pY-qCGZKd1|>r(QS6aE70`D*_7MajBO~L-KVJF#^Z%WfmmgD7 z9jxBW7)wn}&B(~e&dy%2V1Y4cI(_=|!Gm87oZ@iUjh9AeGQijO86T9KoI3OtY&KhA zVbO1Y`@{nethU)~MwjLFde5CZ7o(L70YW@Q{V50o%Bu>!BGjs?s%mO#OeS7c)xyHU z!onis-K3r`B6IKcUdBW)gE(CC ziWMvL5K3d-b?e@W8Rl}ijmq2G+uPh6=RGwwH3fq~J-Tu@9O>!lIxYte?Em76va+(W z-Me=OgQ0k=HEiU_kw&GKBss?IAONODF8F?i6)s@5lNb-f*o9zo$oxdh9KJPVVT{>q zmvy){e*6t3B_+DMKnOK7G#oi{B!(+TjL6lU1IKY?Wjo@XQtZ|Fj#64wH10A(0$pmO z*U}EGVm&w}AoiO2gLpu)8crT1Q-$d(GDa~7f={V%j+}u)KU1JP> zJ)W#suEZDz+QGrhDntPQQBKG|<33l=-qfq1Nr*Xrc7m9?k4fZPEr0v=?Ov~U(xl05 zx7%W|M5EEBrl!rCH?_C7>pL-<&EFcR8={lcY13}f6%8TO)YSCJCm%0ccBejO^5iL* znVCMHPqPn7>1(gOdgqYvR`0&FIj3tlk?ChMJoWY*>+;h)OpFX{yU`$d{ zG9e@w3?4gnY|EC-#yG_3bb375ak8CYx6Ju+<+LMMH3J|Kbq||&BBjG6^_dAzO{ra~ z{iGrR0(3bFSW!`N`0!z#=Q)m76j_#K?MOrqcgBw&Z!EihYg@c{@u5Qp{eHi;6G0Hl z%E~58C^jy#WXbJszx{V(g7nTiZ)-LvilXtc(j0jYz-#|BhM zdA)GS^SrSxo0*xpdiBq*G_Jb$-uq%oiW@e3YUJN()22R8%z1WHQOJ95>lujA^=AQZntyCw~`1MwC)jrFx57GAJr4y79&v zRl~TNni@U2(%S0PKfm?XIfM{nrlbp?fii#og8T3Px0uDPR_mNObF;FtH0%Znz!;;H zN|Kb6lyuKM_bgt#c&M`-ULeh9JNvplo+;TDPm5yqQBW{&oRlP;%RIdYXHSo!Bw$J$ zD06Z~JoL~*-QC^Cj~_pL_|Um?=c3W5h8JTDA>?woCQqI`eR}DzVZ#QJy36It%gfUg zITDFD9F9TEd`T!2)+_Lo(t`)TnlfdIF@Ct~uDfo!>82e!wjVuuR3}Hqn9XLJI(6#& z`SUX~hsX6ZbLPw`EiG+nX*qoO(DCEPJ32bF`kq$yw^%G5k7ve=8RN&_5LZ0J7^|-S z=B1ZjGAam_a6*D3A&KYAOc7DAR|y9EjI!~!3)EA^6aqvMdJ9hcuUSID7uLKuu!g9r zYG-FhAP`hl)n>D$q$FFdHu$GEuh$z01hf#+?RH<$+)yaw^ZCNz5YL-zHd|U++R)#y zaB<%cHbYqI4Yg^Z5yJ>L0jnYb3ILZCx)Va&?({1Z{@ORU+wHzuA#66A&2|N^9}f{& z5e^d$5rUC!kLY^s*%xU%*|9Akbpk+G?m5`=b1IT8eawg2COrDCL;G<*Qd*Bq$}J&nR=PykF{_3xcbqyVD)!^ z^16K?j1gxdR*ZN6xN-Q(BG;mc?&Scm@7(L}9e-nRA$kRaAmeHDKeD zIc$n50Z|RfYJ?{iyD2S3CYLRLZtkNdViT2Mcce*FgHgpFl6(|Y48&?mMt~x+U#1ZY z@8q#XPi_5TTS)R*`6P$nBG@FUp`K_9Wr|ZsxAI8<5LNnQHEJ~__la#0xi86*W#Jrt zu{9ud2wXxyYGiU$F#P`2$dH;y_qf*aLC#C=JaO-;qn$|5V zc;02p|Mb)oouShTm8^VXar&JzJU_dnUgzDg=lt5+@_z3Po~reg^Vq!o%<~u#44loB z{G*~*d1Cqe%(LfuEAJ|LDLrAVHfwj|E63Y6h84d+Y|F>4Ni=7CQuA1QsE#q3WXW1M z>USRJ#69QM*7e*synx5Cr&x$ z{p<&0o^{#sH`o8c8?0qaO|_1gH}Y|hbK;e`oj6*}q2{{oGl!yQzm7H>iZ&kaHlFi* z)wJ$p$JX?O!WD%tB$+dUQinn%3aUzFl`5LfDpX=jwQz~a=B#@Zn*vgYOe5Xl^E?*Z3H@1oOW(1h-cK;% zZpnFMO6EPoYF)rtYex)qq#}b zauO#iRGOH+e1d!Fn3P*ZCD_zgMXBN!y}8LZp$qai^&JC%{M4Io9KLdf=VuIPTi|4p zC2MB(&nIWx?XrytE4{w(Sp*0HF7^C$yzBOYw0Qt1B>5(~mjQr7aL>zqG}B(BG3NBF zpR5@BLV_u^BXk-ga?6Nc-kkG`L~}-S;Dkyg1mrsz_z*3s_K9kc!zLbEH3b~nNmaD| z<7CI?s1l4SeHK13?spnmmqKL#q%a8pCZsPt*!=eS-pcfZF(KJEHg(>`a9Z*KfK%u% zi3h|E0A%5u3>YA=@D2p1PwLPP)HG`55U=sS%tVc9Wh$D8MXT4Chy?%?DvD~*M63cy z0Dxrch>q}?fYd=S_g%GeaF4{|)lJcWONJ3w-~Hw8#+NB$H)gIh^G<>|G`JW>jGaRI zaOZ^fP;GtpK8I;oma{mf@XRhmGsq|v>n~N{{-^YR`Nb}KN9g?9qLiH^SWF=X$SUhbK zhz$UIk#ies|Fdw|LLOiIZp+Liq*_J<#P%(9PxHhQl)6SF-bfG+037D`o_ixK_ZAJi z?HXr0GqWE|vySoxYZ`mMP82e=bIbgc*(uhXpxD_O_-0|=lUa@lePa9AwE5}wv0=HF z$L48S_hZDVR37fU!Nw=~MQ=;sn1ypV1-HQ203bJUnvGBH3ZHH1I{^S`wowVDG#;BX z5(_q~x_e7gp11E>73|(2uCCh8pyr5NvBsCO~{Q_s-TK`O~Z`XrUHadm$s1k@OeI{bH z@<~ypk072W7Euk#YShd*Fv3wKVBwsAP)O=hnPTCb7!gU0n23eL0%J5J`&6n3T!NXi z1HihfdqpL1--N$gxY%-3Q0h{t#1o5|b6`Yd8jZ-kz?hkLYS2h(SfP@@*$Cog8kN007LK+aIJsS z+ZjHyw{fkRv(NCX{ueA4X+Jr-#)~e>`>**UAF~UtYrE_)TizojI~;;b*Q|f3h8Sa! zNTj8ug%Erdm@-DQvvV%zH$(sL8~XmI_1CKXA1|-d_ItNtw*UYD07*qoM6N<$f|5R^ AYybcN literal 0 HcmV?d00001 diff --git a/src/main/resources/qskos_logo.svg b/src/main/resources/qskos_logo.svg deleted file mode 100644 index 9c0f8ce..0000000 --- a/src/main/resources/qskos_logo.svg +++ /dev/null @@ -1,246 +0,0 @@ - - - - - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From a9264f94bba8cfb8a2aee1d3436284ab4035266e Mon Sep 17 00:00:00 2001 From: Christian Mader Date: Tue, 17 Dec 2013 17:33:48 +0100 Subject: [PATCH 10/19] Updated Documentation for Release 1.0 --- README.rdoc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.rdoc b/README.rdoc index 384be12..ee419d5 100644 --- a/README.rdoc +++ b/README.rdoc @@ -6,8 +6,13 @@ Currently we work on integrating qSKOS into the {PoolParty Thesaurus Server}[htt == Installation -=== Requirements +=== Use latest Release Version +You can find the released versions on the {qSKOS GitHub page}[https://github.com/cmader/qSKOS/releases] and download the latest .jar file, e.g. for {qSKOS Version 1.0}[https://github.com/cmader/qSKOS/releases/download/1.0/qSKOS-cmd.jar]. + +=== Build from Source + +Requirements: * Verify that Java v.1.7 or greater is installed: javac -version * Make sure Maven v.3.0 or greater is installed: mvn -v * Make sure you have the current version of the {git version control system}[http://git-scm.com/] installed on your system From 581238054f6741b7c3a19aa65688f115e38a467b Mon Sep 17 00:00:00 2001 From: Christian Mader Date: Tue, 17 Dec 2013 17:35:20 +0100 Subject: [PATCH 11/19] Updated Documentation for Release 1.0 --- README.rdoc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.rdoc b/README.rdoc index ee419d5..991e352 100644 --- a/README.rdoc +++ b/README.rdoc @@ -6,9 +6,10 @@ Currently we work on integrating qSKOS into the {PoolParty Thesaurus Server}[htt == Installation -=== Use latest Release Version +=== Use the latest released version You can find the released versions on the {qSKOS GitHub page}[https://github.com/cmader/qSKOS/releases] and download the latest .jar file, e.g. for {qSKOS Version 1.0}[https://github.com/cmader/qSKOS/releases/download/1.0/qSKOS-cmd.jar]. +Alternatively you can === Build from Source From 96af6a6e5fe7ce468516ee1e98799395b01d4173 Mon Sep 17 00:00:00 2001 From: Christian Mader Date: Tue, 17 Dec 2013 17:37:51 +0100 Subject: [PATCH 12/19] Updated Documentation for Release 1.0 --- README.rdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rdoc b/README.rdoc index 991e352..8e568d6 100644 --- a/README.rdoc +++ b/README.rdoc @@ -8,7 +8,7 @@ Currently we work on integrating qSKOS into the {PoolParty Thesaurus Server}[htt === Use the latest released version -You can find the released versions on the {qSKOS GitHub page}[https://github.com/cmader/qSKOS/releases] and download the latest .jar file, e.g. for {qSKOS Version 1.0}[https://github.com/cmader/qSKOS/releases/download/1.0/qSKOS-cmd.jar]. +You can find the released versions on the {qSKOS GitHub page}[https://github.com/cmader/qSKOS/releases] and download the latest .jar file, e.g. for {qSKOS Version 1.0.0}[https://github.com/cmader/qSKOS/releases/download/1.0.0/qSKOS-cmd.jar]. Alternatively you can === Build from Source From 87b12784c74fb65eb64064edbca9d7210637fee9 Mon Sep 17 00:00:00 2001 From: Christian Mader Date: Tue, 17 Dec 2013 17:43:28 +0100 Subject: [PATCH 13/19] added svg version of logo --- src/main/resources/qSKOS.svg | 146 +++++++++++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 src/main/resources/qSKOS.svg diff --git a/src/main/resources/qSKOS.svg b/src/main/resources/qSKOS.svg new file mode 100644 index 0000000..5ed542b --- /dev/null +++ b/src/main/resources/qSKOS.svg @@ -0,0 +1,146 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 63fd22b67985b959eb3dc478ebc0fd12cd486fad Mon Sep 17 00:00:00 2001 From: Christian Mader Date: Wed, 18 Dec 2013 11:14:48 +0100 Subject: [PATCH 14/19] addition of 2 new issues --- pom.xml | 2 +- .../qskos4j/issues/labels/EmptyLabels.java | 56 +++++++++++++++++++ .../issues/language/NoCommonLanguage.java | 5 ++ .../qskos4j/util/vocab/SparqlPrefix.java | 1 + 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/EmptyLabels.java create mode 100644 src/main/java/at/ac/univie/mminf/qskos4j/issues/language/NoCommonLanguage.java diff --git a/pom.xml b/pom.xml index 563dca4..8d2175e 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 at.ac.univie.mminf qSKOS - 1.0.0 + 1.1.0 qSKOS diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/EmptyLabels.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/EmptyLabels.java new file mode 100644 index 0000000..f64d4c5 --- /dev/null +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/EmptyLabels.java @@ -0,0 +1,56 @@ +package at.ac.univie.mminf.qskos4j.issues.labels; + +import at.ac.univie.mminf.qskos4j.issues.Issue; +import at.ac.univie.mminf.qskos4j.issues.labels.util.LabeledConcept; +import at.ac.univie.mminf.qskos4j.result.CollectionResult; +import at.ac.univie.mminf.qskos4j.result.NumberResult; +import at.ac.univie.mminf.qskos4j.util.TupleQueryResultUtil; +import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; +import org.openrdf.OpenRDFException; +import org.openrdf.model.Resource; +import org.openrdf.model.Value; +import org.openrdf.query.QueryLanguage; +import org.openrdf.query.TupleQueryResult; + +public class EmptyLabels extends Issue> { + + public EmptyLabels() { + super("el", "Empty Labels", "Finds empty labels or labels containing only whitespaces", IssueType.ANALYTICAL); + } + + @Override + protected CollectionResult invoke() throws OpenRDFException { + implement me! + return null; + } + + @Override + protected NumberResult invoke() throws OpenRDFException { + long relationsCount = 0; + + for (Value concept : involvedConcepts.getResult().getData()) { + try { + TupleQueryResult result = repCon.prepareTupleQuery( + QueryLanguage.SPARQL, + createLexicalLabelQuery(concept) + ).evaluate(); + + relationsCount += TupleQueryResultUtil.countResults(result); + } + catch (OpenRDFException e) { + logger.error("Error finding labels for concept '" +concept+ "'", e); + } + } + + return new NumberResult(relationsCount); + } + + private String createLexicalLabelQuery(Value concept) { + return SparqlPrefix.SKOS +" "+ SparqlPrefix.DCTERMS +" "+ SparqlPrefix.RDFS + + "SELECT DISTINCT ?resource ?literal WHERE " + + "{" + + "?resource ?labelType ?literal ." + + "FILTER (?labelType IN (rdfs:label, dcterms:title, skos:prefLabel, skos:altLabel, skos:hiddenLabel))" + + "}"; + } +} diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/NoCommonLanguage.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/NoCommonLanguage.java new file mode 100644 index 0000000..f753b02 --- /dev/null +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/NoCommonLanguage.java @@ -0,0 +1,5 @@ +package at.ac.univie.mminf.qskos4j.issues.language; + +public class NoCommonLanguage { + implement me! +} diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/util/vocab/SparqlPrefix.java b/src/main/java/at/ac/univie/mminf/qskos4j/util/vocab/SparqlPrefix.java index 0c48e0c..fbaa266 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/util/vocab/SparqlPrefix.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/util/vocab/SparqlPrefix.java @@ -5,6 +5,7 @@ public enum SparqlPrefix { SKOS("skos", "http://www.w3.org/2004/02/skos/core#"), SKOSXL("skosxl", "http://www.w3.org/2008/05/skos-xl#"), DC("dc", "http://purl.org/dc/elements/1.1/"), + DCTERMS("dcterms", "http://purl.org/dc/terms/"), RDF("rdf", org.openrdf.model.vocabulary.RDF.NAMESPACE), RDFS("rdfs", org.openrdf.model.vocabulary.RDFS.NAMESPACE); From f38dcd159d9ceebb4832b66ceb554fd7362bd2a0 Mon Sep 17 00:00:00 2001 From: cmader Date: Tue, 24 Dec 2013 17:05:20 +0100 Subject: [PATCH 15/19] added empty labels check --- .../at/ac/univie/mminf/qskos4j/QSkos.java | 2 +- .../issues/labels/EmptyLabeledResources.java | 65 +++++++++++++++++++ .../qskos4j/issues/labels/EmptyLabels.java | 56 ---------------- .../issues/labels/util/EmptyLabelsResult.java | 37 +++++++++++ .../qskos4j/issues/labels/util/LabelType.java | 49 +++++++++++--- .../labels/util/ResourceLabelsCollector.java | 8 +-- .../issues/language/NoCommonLanguage.java | 2 +- .../mminf/qskos4j/issues/BrokenLinksTest.java | 2 + .../issues/EmptyLabeledResourcesTest.java | 29 +++++++++ src/test/resources/emptyLabels.rdf | 23 +++++++ 10 files changed, 202 insertions(+), 71 deletions(-) create mode 100644 src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/EmptyLabeledResources.java delete mode 100644 src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/EmptyLabels.java create mode 100644 src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/EmptyLabelsResult.java create mode 100644 src/test/java/at/ac/univie/mminf/qskos4j/issues/EmptyLabeledResourcesTest.java create mode 100644 src/test/resources/emptyLabels.rdf 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 21956fa..cc74e17 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/QSkos.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/QSkos.java @@ -104,6 +104,7 @@ private void addStatisticalIssues() { private void addAnalyticalIssues() { HierarchyGraphBuilder hierarchyGraphBuilder = new HierarchyGraphBuilder(); + registeredIssues.add(new EmptyLabeledResources()); registeredIssues.add(new OmittedOrInvalidLanguageTags()); registeredIssues.add(new IncompleteLanguageCoverage(involvedConcepts)); registeredIssues.add(new UndocumentedConcepts(authoritativeConcepts)); @@ -125,7 +126,6 @@ private void addAnalyticalIssues() { registeredIssues.add(new HttpUriSchemeViolations()); registeredIssues.add(new RelationClashes(hierarchyGraphBuilder)); registeredIssues.add(new MappingClashes()); - } private void addSkosIntegrityIssues() { diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/EmptyLabeledResources.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/EmptyLabeledResources.java new file mode 100644 index 0000000..592406c --- /dev/null +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/EmptyLabeledResources.java @@ -0,0 +1,65 @@ +package at.ac.univie.mminf.qskos4j.issues.labels; + +import at.ac.univie.mminf.qskos4j.issues.Issue; +import at.ac.univie.mminf.qskos4j.issues.labels.util.EmptyLabelsResult; +import at.ac.univie.mminf.qskos4j.issues.labels.util.LabelType; +import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; +import org.openrdf.OpenRDFException; +import org.openrdf.model.Resource; +import org.openrdf.model.URI; +import org.openrdf.model.Value; +import org.openrdf.query.BindingSet; +import org.openrdf.query.QueryLanguage; +import org.openrdf.query.TupleQueryResult; + +import java.util.*; + +public class EmptyLabeledResources extends Issue { + + private Map> result; + + public EmptyLabeledResources() { + super("el", "Empty Labels", "Finds empty labels or labels containing only whitespaces", IssueType.ANALYTICAL); + } + + @Override + protected EmptyLabelsResult invoke() throws OpenRDFException { + result = new HashMap>(); + + TupleQueryResult result = repCon.prepareTupleQuery( + QueryLanguage.SPARQL, + createLexicalLabelQuery() + ).evaluate(); + + while (result.hasNext()) { + BindingSet bs = result.next(); + Resource resource = (Resource) bs.getBinding("resource").getValue(); + URI labelType = (URI) bs.getBinding("labelType").getValue(); + Value literal = bs.getBinding("literal").getValue(); + + if (literal.stringValue().trim().isEmpty()) { + addToResults(resource, LabelType.getFromUri(labelType)); + } + } + + return new EmptyLabelsResult(this.result); + } + + private String createLexicalLabelQuery() { + return SparqlPrefix.SKOS +" "+ SparqlPrefix.DCTERMS +" "+ SparqlPrefix.RDFS + + "SELECT ?resource ?labelType ?literal WHERE " + + "{" + + "?resource ?labelType ?literal ." + + "FILTER (?labelType IN (dcterms:title, skos:prefLabel, skos:altLabel, skos:hiddenLabel))" + + "}"; + } + + private void addToResults(Resource resource, LabelType labelType) { + Collection values = result.get(resource); + if (values == null) { + values = new HashSet(); + result.put(resource, values); + } + values.add(labelType); + } +} diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/EmptyLabels.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/EmptyLabels.java deleted file mode 100644 index f64d4c5..0000000 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/EmptyLabels.java +++ /dev/null @@ -1,56 +0,0 @@ -package at.ac.univie.mminf.qskos4j.issues.labels; - -import at.ac.univie.mminf.qskos4j.issues.Issue; -import at.ac.univie.mminf.qskos4j.issues.labels.util.LabeledConcept; -import at.ac.univie.mminf.qskos4j.result.CollectionResult; -import at.ac.univie.mminf.qskos4j.result.NumberResult; -import at.ac.univie.mminf.qskos4j.util.TupleQueryResultUtil; -import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; -import org.openrdf.OpenRDFException; -import org.openrdf.model.Resource; -import org.openrdf.model.Value; -import org.openrdf.query.QueryLanguage; -import org.openrdf.query.TupleQueryResult; - -public class EmptyLabels extends Issue> { - - public EmptyLabels() { - super("el", "Empty Labels", "Finds empty labels or labels containing only whitespaces", IssueType.ANALYTICAL); - } - - @Override - protected CollectionResult invoke() throws OpenRDFException { - implement me! - return null; - } - - @Override - protected NumberResult invoke() throws OpenRDFException { - long relationsCount = 0; - - for (Value concept : involvedConcepts.getResult().getData()) { - try { - TupleQueryResult result = repCon.prepareTupleQuery( - QueryLanguage.SPARQL, - createLexicalLabelQuery(concept) - ).evaluate(); - - relationsCount += TupleQueryResultUtil.countResults(result); - } - catch (OpenRDFException e) { - logger.error("Error finding labels for concept '" +concept+ "'", e); - } - } - - return new NumberResult(relationsCount); - } - - private String createLexicalLabelQuery(Value concept) { - return SparqlPrefix.SKOS +" "+ SparqlPrefix.DCTERMS +" "+ SparqlPrefix.RDFS + - "SELECT DISTINCT ?resource ?literal WHERE " + - "{" + - "?resource ?labelType ?literal ." + - "FILTER (?labelType IN (rdfs:label, dcterms:title, skos:prefLabel, skos:altLabel, skos:hiddenLabel))" + - "}"; - } -} diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/EmptyLabelsResult.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/EmptyLabelsResult.java new file mode 100644 index 0000000..9c4f333 --- /dev/null +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/EmptyLabelsResult.java @@ -0,0 +1,37 @@ +package at.ac.univie.mminf.qskos4j.issues.labels.util; + +import at.ac.univie.mminf.qskos4j.result.Result; +import org.openrdf.model.Resource; + +import java.io.BufferedWriter; +import java.io.IOException; +import java.util.Collection; +import java.util.Map; + +public class EmptyLabelsResult extends Result>> { + + public EmptyLabelsResult(Map> data) { + super(data); + } + + @Override + public void generateTextReport(BufferedWriter writer, ReportStyle style) throws IOException { + if (style == ReportStyle.SHORT) { + writer.write("count: " +occurrenceCount()+ "\n"); + } + else if (style == ReportStyle.EXTENSIVE) { + generateExtensiveTextReport(writer); + } + } + + @Override + public long occurrenceCount() { + return getData().keySet().size(); + } + + private void generateExtensiveTextReport(BufferedWriter writer) throws IOException { + for (Resource resource : getData().keySet()) { + writer.write(resource.stringValue() +": "+ getData().get(resource).toString() +"\n"); + } + } +} diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/LabelType.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/LabelType.java index 39d1bfd..3aa3f4a 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/LabelType.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/LabelType.java @@ -1,18 +1,51 @@ package at.ac.univie.mminf.qskos4j.issues.labels.util; +import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; +import org.openrdf.model.URI; + +import java.util.ArrayList; +import java.util.Collection; + public enum LabelType { - PREF_LABEL("skos:prefLabel"), - ALT_LABEL("skos:altLabel"), - HIDDEN_LABEL("skos:hiddenLabel"); + PREF_LABEL(SparqlPrefix.SKOS.getNameSpace() + "prefLabel", true), + ALT_LABEL(SparqlPrefix.SKOS.getNameSpace() + "altLabel", true), + HIDDEN_LABEL(SparqlPrefix.SKOS.getNameSpace() + "hiddenLabel", true), + TITLE(SparqlPrefix.DCTERMS.getNameSpace() + "title"), + LABEL(SparqlPrefix.RDFS.getNameSpace() + "label"), + UNKNOWN(null); + + private String predicate; + private boolean definedInSkos; - private String skosProperty; + private LabelType(String predicate) { + this(predicate, false); + } + + private LabelType(String predicate, boolean definedInSkos) { + this.predicate = predicate; + this.definedInSkos = definedInSkos; + } - LabelType(String skosProperty) { - this.skosProperty = skosProperty; + public String getPredicate() { + return predicate; } - public String getSkosProperty() { - return skosProperty; + public static LabelType getFromUri(URI uri) { + for (LabelType labelType : values()) { + if (uri.stringValue().contains(labelType.predicate)) return labelType; + } + return UNKNOWN; } + + public static Collection getSkosLabels() { + Collection skosLabels = new ArrayList(); + + for (LabelType labelType : values()) { + if (labelType.definedInSkos) skosLabels.add(labelType); + } + + return skosLabels; + } + } diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/ResourceLabelsCollector.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/ResourceLabelsCollector.java index 573bbe5..8bd07db 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/ResourceLabelsCollector.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/ResourceLabelsCollector.java @@ -1,6 +1,5 @@ package at.ac.univie.mminf.qskos4j.issues.labels.util; -import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; import org.openrdf.OpenRDFException; import org.openrdf.model.Literal; import org.openrdf.model.Resource; @@ -29,7 +28,7 @@ public Collection getLabeledConcepts() { } private void createLabeledResources() { - for (LabelType labelType : LabelType.values()) { + for (LabelType labelType : LabelType.getSkosLabels()) { String labelQuery = createLabelQuery(labelType); try { TupleQueryResult result = repCon.prepareTupleQuery(QueryLanguage.SPARQL, labelQuery).evaluate(); @@ -42,10 +41,9 @@ private void createLabeledResources() { } private String createLabelQuery(LabelType labelType) { - return SparqlPrefix.SKOS + - "SELECT DISTINCT ?resource ?label"+ + return "SELECT DISTINCT ?resource ?label"+ "{" + - "?resource "+labelType.getSkosProperty()+" ?label ." + + "?resource <"+labelType.getPredicate()+"> ?label ." + "}"; } diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/NoCommonLanguage.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/NoCommonLanguage.java index f753b02..1ac4184 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/NoCommonLanguage.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/NoCommonLanguage.java @@ -1,5 +1,5 @@ package at.ac.univie.mminf.qskos4j.issues.language; public class NoCommonLanguage { - implement me! + //TODO: implement me! } diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/BrokenLinksTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/BrokenLinksTest.java index c651196..42ca866 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/BrokenLinksTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/BrokenLinksTest.java @@ -5,6 +5,7 @@ import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; import junit.framework.Assert; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.openrdf.OpenRDFException; @@ -28,6 +29,7 @@ public void setUp() throws OpenRDFException, IOException { brokenLinks.setExtAccessDelayMillis(0); } + @Ignore @Test public void testBrokenLinks() throws OpenRDFException { Collection brokenLinkURLs = brokenLinks.getResult().getData(); diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/EmptyLabeledResourcesTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/EmptyLabeledResourcesTest.java new file mode 100644 index 0000000..a5eee3a --- /dev/null +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/EmptyLabeledResourcesTest.java @@ -0,0 +1,29 @@ +package at.ac.univie.mminf.qskos4j.issues; + +import at.ac.univie.mminf.qskos4j.issues.labels.EmptyLabeledResources; +import at.ac.univie.mminf.qskos4j.issues.labels.util.EmptyLabelsResult; +import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.openrdf.OpenRDFException; + +import java.io.IOException; + +public class EmptyLabeledResourcesTest { + + private EmptyLabeledResources emptyLabeledResources; + + @Before + public void setUp() throws IOException, OpenRDFException { + emptyLabeledResources = new EmptyLabeledResources(); + emptyLabeledResources.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("emptyLabels.rdf").getConnection()); + } + + @Test + public void testEmptyLabels() throws OpenRDFException { + EmptyLabelsResult result = emptyLabeledResources.getResult(); + Assert.assertEquals(3, result.occurrenceCount()); + } + +} diff --git a/src/test/resources/emptyLabels.rdf b/src/test/resources/emptyLabels.rdf new file mode 100644 index 0000000..196fb6d --- /dev/null +++ b/src/test/resources/emptyLabels.rdf @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + somelabel + + + + + + + + From bad933d35835b2d004aa31da42736a12002b29ae Mon Sep 17 00:00:00 2001 From: cmader Date: Thu, 26 Dec 2013 11:40:02 +0100 Subject: [PATCH 16/19] started implementation of common language test --- pom.xml | 2 +- .../issues/language/NoCommonLanguage.java | 20 +++++++++++-- .../qskos4j/issues/NoCommonLanguageTest.java | 30 +++++++++++++++++++ src/test/resources/nocommonlanguage.rdf | 0 4 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 src/test/java/at/ac/univie/mminf/qskos4j/issues/NoCommonLanguageTest.java create mode 100644 src/test/resources/nocommonlanguage.rdf diff --git a/pom.xml b/pom.xml index 8d2175e..36703b1 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 at.ac.univie.mminf qSKOS - 1.1.0 + 1.2.0 qSKOS diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/NoCommonLanguage.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/NoCommonLanguage.java index 1ac4184..4ca003e 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/NoCommonLanguage.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/NoCommonLanguage.java @@ -1,5 +1,21 @@ package at.ac.univie.mminf.qskos4j.issues.language; -public class NoCommonLanguage { - //TODO: implement me! +import at.ac.univie.mminf.qskos4j.issues.Issue; +import at.ac.univie.mminf.qskos4j.result.Result; +import org.openrdf.OpenRDFException; + +public class NoCommonLanguage extends Issue { + + public NoCommonLanguage() { + super("ncl", + "No Common Language", + "Checks if concept labels are available in at least one common language", + IssueType.ANALYTICAL); + } + + @Override + protected Result invoke() throws OpenRDFException { + return null; + } + } diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/NoCommonLanguageTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/NoCommonLanguageTest.java new file mode 100644 index 0000000..83444b6 --- /dev/null +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/NoCommonLanguageTest.java @@ -0,0 +1,30 @@ +package at.ac.univie.mminf.qskos4j.issues; + +import at.ac.univie.mminf.qskos4j.issues.language.NoCommonLanguage; +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 NoCommonLanguageTest { + + private NoCommonLanguage noCommonLanguage; + + @Before + public void setUp() throws OpenRDFException, IOException { + noCommonLanguage = new NoCommonLanguage(); + noCommonLanguage.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("nocommonlanguage.rdf").getConnection()); + } + + @Test + public void testIncompleteLanguageCoverageCount() + throws OpenRDFException + { + noCommonLanguage.getResult().getData(); + Assert.fail(); + } + +} diff --git a/src/test/resources/nocommonlanguage.rdf b/src/test/resources/nocommonlanguage.rdf new file mode 100644 index 0000000..e69de29 From a912552d59ade1d2a325b396cc9f43ba380f0781 Mon Sep 17 00:00:00 2001 From: cmader Date: Fri, 27 Dec 2013 20:31:45 +0100 Subject: [PATCH 17/19] started implementation of common language test --- .../at/ac/univie/mminf/qskos4j/QSkos.java | 2 + .../ac/univie/mminf/qskos4j/issues/Issue.java | 37 +-------- .../language/IncompleteLangCovResult.java | 12 +-- .../language/IncompleteLanguageCoverage.java | 81 ++++--------------- .../issues/language/NoCommonLanguage.java | 6 +- .../language/util/LanguageCoverage.java | 73 +++++++++++++++++ .../IncompleteLanguageCoverageTest.java | 7 +- .../qskos4j/issues/NoCommonLanguageTest.java | 5 +- 8 files changed, 112 insertions(+), 111 deletions(-) create mode 100644 src/main/java/at/ac/univie/mminf/qskos4j/issues/language/util/LanguageCoverage.java 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 cc74e17..bf01d24 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/QSkos.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/QSkos.java @@ -18,6 +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.NoCommonLanguage; import at.ac.univie.mminf.qskos4j.issues.language.OmittedOrInvalidLanguageTags; import at.ac.univie.mminf.qskos4j.issues.outlinks.BrokenLinks; import at.ac.univie.mminf.qskos4j.issues.outlinks.HttpURIs; @@ -108,6 +109,7 @@ private void addAnalyticalIssues() { registeredIssues.add(new OmittedOrInvalidLanguageTags()); registeredIssues.add(new IncompleteLanguageCoverage(involvedConcepts)); registeredIssues.add(new UndocumentedConcepts(authoritativeConcepts)); + registeredIssues.add(new NoCommonLanguage(authoritativeConcepts)); 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/issues/Issue.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/Issue.java index 2556ae8..183de49 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/Issue.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/Issue.java @@ -11,14 +11,10 @@ public abstract class Issue> { public enum IssueType {STATISTICAL, ANALYTICAL} - protected RepositoryConnection repCon; - protected IProgressMonitor progressMonitor = new StubProgressMonitor(); private String id, name, description; private IssueType type; - private T result; - private Issue dependentIssue; private URI weblink; private Issue(String name, String description, IssueType type) { @@ -32,50 +28,25 @@ public Issue(String id, String name, String description, IssueType type) { this.id = id; } - public Issue(Issue dependentIssue, String id, String name, String description, IssueType type) { - this(id, name, description, type); - this.dependentIssue = dependentIssue; - } - public Issue(String id, String name, String description, IssueType type, URI weblink) { this(id, name, description, type); this.weblink = weblink; } - public Issue(Issue dependentIssue, String id, String name, String description, IssueType type, URI weblink) { - this(dependentIssue, id, name, description, type); - this.weblink = weblink; - } + protected abstract T invoke(RepositoryConnection repCon) throws OpenRDFException; - protected abstract T invoke() throws OpenRDFException; - - public final T getResult() throws OpenRDFException { - if (result == null) { - result = invoke(); - } - return result; - } - - protected final void reset() { - result = null; + public final T getResult(RepositoryConnection repCon) throws OpenRDFException { if (progressMonitor != null) { progressMonitor.reset(); } + + return invoke(repCon); } public void setProgressMonitor(IProgressMonitor progressMonitor) { this.progressMonitor = progressMonitor; } - public void setRepositoryConnection(RepositoryConnection repCon) { - if (dependentIssue != null) { - dependentIssue.setRepositoryConnection(repCon); - } - - this.repCon = repCon; - reset(); - } - public String getId() { return id; } diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/IncompleteLangCovResult.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/IncompleteLangCovResult.java index 3d895c0..38040fd 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/IncompleteLangCovResult.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/IncompleteLangCovResult.java @@ -2,7 +2,7 @@ import at.ac.univie.mminf.qskos4j.result.CollectionResult; import at.ac.univie.mminf.qskos4j.result.Result; -import org.openrdf.model.Value; +import org.openrdf.model.Resource; import java.io.BufferedWriter; import java.io.IOException; @@ -11,9 +11,9 @@ import java.util.Map; import java.util.Map.Entry; -public class IncompleteLangCovResult extends Result>> { +public class IncompleteLangCovResult extends Result>> { - IncompleteLangCovResult(Map> data) { + IncompleteLangCovResult(Map> data) { super(data); } @@ -22,7 +22,7 @@ protected void generateTextReport(BufferedWriter writer, ReportStyle style) thro { switch (style) { case SHORT: - new CollectionResult(getData().keySet()).generateReport(writer, ReportFormat.TXT, ReportStyle.SHORT); + new CollectionResult(getData().keySet()).generateReport(writer, ReportFormat.TXT, ReportStyle.SHORT); break; case EXTENSIVE: @@ -35,9 +35,9 @@ protected void generateTextReport(BufferedWriter writer, ReportStyle style) thro private String generateExtensiveTextReport() { StringBuilder extensiveReport = new StringBuilder(); - Iterator>> entryIt = getData().entrySet().iterator(); + Iterator>> entryIt = getData().entrySet().iterator(); while (entryIt.hasNext()) { - Entry> entry = entryIt.next(); + Entry> entry = entryIt.next(); extensiveReport.append("concept: '") .append(entry.getKey().stringValue()) .append("', not covered languages: ") diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/IncompleteLanguageCoverage.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/IncompleteLanguageCoverage.java index 1989e5a..d0145a7 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/IncompleteLanguageCoverage.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/IncompleteLanguageCoverage.java @@ -2,13 +2,11 @@ import at.ac.univie.mminf.qskos4j.issues.Issue; import at.ac.univie.mminf.qskos4j.issues.concepts.InvolvedConcepts; -import at.ac.univie.mminf.qskos4j.progress.MonitoredIterator; +import at.ac.univie.mminf.qskos4j.issues.language.util.LanguageCoverage; import org.openrdf.OpenRDFException; -import org.openrdf.model.Literal; import org.openrdf.model.Resource; import org.openrdf.model.Value; import org.openrdf.model.impl.URIImpl; -import org.openrdf.query.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -21,7 +19,7 @@ public class IncompleteLanguageCoverage extends Issue { private final Logger logger = LoggerFactory.getLogger(IncompleteLanguageCoverage.class); - private Map> languageCoverage, incompleteLanguageCoverage; + private Map> languageCoverage, incompleteLanguageCoverage; private Set distinctLanguages; private InvolvedConcepts involvedConcepts; @@ -39,74 +37,29 @@ public IncompleteLanguageCoverage(InvolvedConcepts involvedConcepts) { @Override protected IncompleteLangCovResult invoke() throws OpenRDFException { - incompleteLanguageCoverage = new HashMap>(); - - checkLanguageCoverage(); + incompleteLanguageCoverage = new HashMap>(); + + languageCoverage = new LanguageCoverage().findLanguageCoverage( + involvedConcepts.getResult().getData(), + progressMonitor, + repCon); + findDistinctLanguages(); generateIncompleteLanguageCoverageMap(); return new IncompleteLangCovResult(incompleteLanguageCoverage); } - private void checkLanguageCoverage() throws OpenRDFException - { - languageCoverage = new HashMap>(); - - Iterator it = new MonitoredIterator(involvedConcepts.getResult().getData(), progressMonitor); - while (it.hasNext()) { - Resource concept = it.next(); + private void findDistinctLanguages() { + distinctLanguages = new HashSet(); + for (Collection languages : languageCoverage.values()) { + distinctLanguages.addAll(languages); + } + } - try { - TupleQuery query = repCon.prepareTupleQuery(QueryLanguage.SPARQL, createLanguageLiteralQuery(concept)); - addToLanguageCoverageMap(concept, query.evaluate()); - } - catch (OpenRDFException e) { - logger.error("Error finding languages for concept '" +concept+ "'"); - } - } - } - - private String createLanguageLiteralQuery(Value concept) { - return "SELECT DISTINCT ?literal "+ - "WHERE {" + - "<"+concept+"> ?p ?literal ."+ - "FILTER isLiteral(?literal) "+ - "FILTER langMatches(lang(?literal), \"*\")" + - "}"; - } - - private void addToLanguageCoverageMap(Value concept, TupleQueryResult result) - throws QueryEvaluationException - { - while (result.hasNext()) { - BindingSet queryResult = result.next(); - Literal literal = (Literal) queryResult.getValue("literal"); - - String language = literal.getLanguage(); - addToLanguageCoverageMap(concept, language); - addToDistinctLanguages(language); - } - } - - private void addToLanguageCoverageMap(Value value, String langTag) { - Collection langTags = languageCoverage.get(value); - if (langTags == null) { - langTags = new HashSet(); - languageCoverage.put(value, langTags); - } - langTags.add(langTag); - } - - private void addToDistinctLanguages(String langTag) { - if (distinctLanguages == null) { - distinctLanguages = new HashSet(); - } - distinctLanguages.add(langTag); - } - private void generateIncompleteLanguageCoverageMap() { - incompleteLanguageCoverage = new HashMap>(); + incompleteLanguageCoverage = new HashMap>(); - for (Value resource : languageCoverage.keySet()) { + for (Resource resource : languageCoverage.keySet()) { Collection coveredLanguages = languageCoverage.get(resource); Collection notCoveredLanguages = getNotCoveredLanguages(coveredLanguages); if (!notCoveredLanguages.isEmpty()) { diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/NoCommonLanguage.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/NoCommonLanguage.java index 4ca003e..d35c9e1 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/NoCommonLanguage.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/NoCommonLanguage.java @@ -1,13 +1,15 @@ package at.ac.univie.mminf.qskos4j.issues.language; import at.ac.univie.mminf.qskos4j.issues.Issue; +import at.ac.univie.mminf.qskos4j.issues.concepts.AuthoritativeConcepts; import at.ac.univie.mminf.qskos4j.result.Result; import org.openrdf.OpenRDFException; public class NoCommonLanguage extends Issue { - public NoCommonLanguage() { - super("ncl", + public NoCommonLanguage(AuthoritativeConcepts authoritativeConcepts) { + super(authoritativeConcepts, + "ncl", "No Common Language", "Checks if concept labels are available in at least one common language", IssueType.ANALYTICAL); diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/util/LanguageCoverage.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/util/LanguageCoverage.java new file mode 100644 index 0000000..906fb27 --- /dev/null +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/util/LanguageCoverage.java @@ -0,0 +1,73 @@ +package at.ac.univie.mminf.qskos4j.issues.language.util; + +import at.ac.univie.mminf.qskos4j.progress.IProgressMonitor; +import at.ac.univie.mminf.qskos4j.progress.MonitoredIterator; +import org.openrdf.OpenRDFException; +import org.openrdf.model.Literal; +import org.openrdf.model.Resource; +import org.openrdf.model.Value; +import org.openrdf.query.*; +import org.openrdf.repository.RepositoryConnection; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.*; + +public class LanguageCoverage { + + private final Logger logger = LoggerFactory.getLogger(LanguageCoverage.class); + + private Map> languageCoverage; + + public Map> findLanguageCoverage( + Collection resources, + IProgressMonitor progressMonitor, + RepositoryConnection repCon) throws OpenRDFException + { + languageCoverage = new HashMap>(); + + Iterator it = new MonitoredIterator(resources, progressMonitor); + while (it.hasNext()) { + Resource concept = it.next(); + + try { + TupleQuery query = repCon.prepareTupleQuery(QueryLanguage.SPARQL, createLanguageLiteralQuery(concept)); + addToLanguageCoverageMap(concept, query.evaluate()); + } + catch (OpenRDFException e) { + logger.error("Error finding languages for concept '" +concept+ "'"); + } + } + + return languageCoverage; + } + + private String createLanguageLiteralQuery(Value concept) { + return "SELECT DISTINCT ?literal "+ + "WHERE {" + + "<"+concept+"> ?p ?literal ."+ + "FILTER isLiteral(?literal) "+ + "FILTER langMatches(lang(?literal), \"*\")" + + "}"; + } + + private void addToLanguageCoverageMap(Resource concept, TupleQueryResult result) throws QueryEvaluationException { + while (result.hasNext()) { + BindingSet queryResult = result.next(); + Literal literal = (Literal) queryResult.getValue("literal"); + + String language = literal.getLanguage(); + addToLanguageCoverageMap(concept, language); + } + } + + private void addToLanguageCoverageMap(Resource value, String langTag) { + Collection langTags = languageCoverage.get(value); + if (langTags == null) { + langTags = new HashSet(); + languageCoverage.put(value, langTags); + } + langTags.add(langTag); + } + +} diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/IncompleteLanguageCoverageTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/IncompleteLanguageCoverageTest.java index a55aaca..91a9882 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/IncompleteLanguageCoverageTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/IncompleteLanguageCoverageTest.java @@ -7,6 +7,7 @@ import org.junit.Before; import org.junit.Test; import org.openrdf.OpenRDFException; +import org.openrdf.model.Resource; import org.openrdf.model.Value; import java.io.IOException; @@ -34,7 +35,7 @@ public void setUp() throws OpenRDFException, IOException { public void testIncompleteLanguageCoverageCount() throws OpenRDFException { - Map> incompleteLangCoverage = incompleteLanguageCoverage.getResult().getData(); + Map> incompleteLangCoverage = incompleteLanguageCoverage.getResult().getData(); Assert.assertEquals(13, incompleteLangCoverage.size()); } @@ -42,7 +43,7 @@ public void testIncompleteLanguageCoverageCount() public void testExistResourcesNotHavingEnglishLabels() throws OpenRDFException { - Map> incompleteLangCoverage = incompleteLanguageCoverage.getResult().getData(); + Map> incompleteLangCoverage = incompleteLanguageCoverage.getResult().getData(); boolean englishTagFound = false; for (Collection missingLanguages : incompleteLangCoverage.values()) { @@ -57,7 +58,7 @@ public void testExistResourcesNotHavingEnglishLabels() public void testResourcesMissingOnlyFrenchLabelsCount() throws OpenRDFException { - Map> incompleteLangCoverage = incompleteLanguageCoverage.getResult().getData(); + Map> incompleteLangCoverage = incompleteLanguageCoverage.getResult().getData(); List foundResources = new ArrayList(); for (Value resource : incompleteLangCoverage.keySet()) { diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/NoCommonLanguageTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/NoCommonLanguageTest.java index 83444b6..8f91433 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/NoCommonLanguageTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/NoCommonLanguageTest.java @@ -1,7 +1,6 @@ package at.ac.univie.mminf.qskos4j.issues; import at.ac.univie.mminf.qskos4j.issues.language.NoCommonLanguage; -import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; import junit.framework.Assert; import org.junit.Before; import org.junit.Test; @@ -15,8 +14,8 @@ public class NoCommonLanguageTest { @Before public void setUp() throws OpenRDFException, IOException { - noCommonLanguage = new NoCommonLanguage(); - noCommonLanguage.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("nocommonlanguage.rdf").getConnection()); + //noCommonLanguage = new NoCommonLanguage(); + //noCommonLanguage.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("nocommonlanguage.rdf").getConnection()); } @Test From d4fc47870a0762f46e196b7d8bc3685f7821b31a Mon Sep 17 00:00:00 2001 From: cmader Date: Sat, 28 Dec 2013 16:04:10 +0100 Subject: [PATCH 18/19] common language issue complete and tests pass --- .../at/ac/univie/mminf/qskos4j/QSkos.java | 9 ++-- .../ac/univie/mminf/qskos4j/issues/Issue.java | 37 +++++++++++++-- .../issues/labels/LexicalRelations.java | 2 +- .../issues/language/CommonLanguages.java | 47 +++++++++++++++++++ .../language/IncompleteLanguageCoverage.java | 30 +++++------- .../issues/language/NoCommonLanguage.java | 23 --------- .../language/util/LanguageCoverage.java | 28 +++++++---- .../language/util/LanguageCoverageResult.java | 20 ++++++++ .../qskos4j/issues/CommonLanguagesTest.java | 35 ++++++++++++++ .../IncompleteLanguageCoverageTest.java | 11 ++--- .../qskos4j/issues/NoCommonLanguageTest.java | 29 ------------ .../mminf/qskos4j/issues/SkosXlTest.java | 3 +- src/test/resources/commonlanguage_en.rdf | 28 +++++++++++ src/test/resources/nocommonlanguage.rdf | 27 +++++++++++ 14 files changed, 233 insertions(+), 96 deletions(-) create mode 100644 src/main/java/at/ac/univie/mminf/qskos4j/issues/language/CommonLanguages.java delete mode 100644 src/main/java/at/ac/univie/mminf/qskos4j/issues/language/NoCommonLanguage.java create mode 100644 src/main/java/at/ac/univie/mminf/qskos4j/issues/language/util/LanguageCoverageResult.java create mode 100644 src/test/java/at/ac/univie/mminf/qskos4j/issues/CommonLanguagesTest.java delete mode 100644 src/test/java/at/ac/univie/mminf/qskos4j/issues/NoCommonLanguageTest.java create mode 100644 src/test/resources/commonlanguage_en.rdf 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 bf01d24..593562d 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/QSkos.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/QSkos.java @@ -18,8 +18,9 @@ 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.NoCommonLanguage; +import at.ac.univie.mminf.qskos4j.issues.language.CommonLanguages; 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; import at.ac.univie.mminf.qskos4j.issues.outlinks.HttpURIs; import at.ac.univie.mminf.qskos4j.issues.outlinks.HttpUriSchemeViolations; @@ -59,6 +60,7 @@ public class QSkos { private String baseURI; + private LanguageCoverage languageCoverage; private BrokenLinks brokenLinks; private InvolvedConcepts involvedConcepts; private AuthoritativeConcepts authoritativeConcepts; @@ -91,6 +93,7 @@ private void addStatisticalIssues() { authoritativeConcepts.setBaseURI(baseURI); conceptSchemes = new ConceptSchemes(); httpURIs = new HttpURIs(); + languageCoverage = new LanguageCoverage(involvedConcepts); registeredIssues.add(involvedConcepts); registeredIssues.add(authoritativeConcepts); @@ -107,9 +110,9 @@ private void addAnalyticalIssues() { registeredIssues.add(new EmptyLabeledResources()); registeredIssues.add(new OmittedOrInvalidLanguageTags()); - registeredIssues.add(new IncompleteLanguageCoverage(involvedConcepts)); + registeredIssues.add(new IncompleteLanguageCoverage(languageCoverage)); registeredIssues.add(new UndocumentedConcepts(authoritativeConcepts)); - registeredIssues.add(new NoCommonLanguage(authoritativeConcepts)); + registeredIssues.add(new CommonLanguages(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/issues/Issue.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/Issue.java index 183de49..2556ae8 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/Issue.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/Issue.java @@ -11,10 +11,14 @@ public abstract class Issue> { public enum IssueType {STATISTICAL, ANALYTICAL} + protected RepositoryConnection repCon; + protected IProgressMonitor progressMonitor = new StubProgressMonitor(); private String id, name, description; private IssueType type; + private T result; + private Issue dependentIssue; private URI weblink; private Issue(String name, String description, IssueType type) { @@ -28,25 +32,50 @@ public Issue(String id, String name, String description, IssueType type) { this.id = id; } + public Issue(Issue dependentIssue, String id, String name, String description, IssueType type) { + this(id, name, description, type); + this.dependentIssue = dependentIssue; + } + public Issue(String id, String name, String description, IssueType type, URI weblink) { this(id, name, description, type); this.weblink = weblink; } - protected abstract T invoke(RepositoryConnection repCon) throws OpenRDFException; + public Issue(Issue dependentIssue, String id, String name, String description, IssueType type, URI weblink) { + this(dependentIssue, id, name, description, type); + this.weblink = weblink; + } - public final T getResult(RepositoryConnection repCon) throws OpenRDFException { + protected abstract T invoke() throws OpenRDFException; + + public final T getResult() throws OpenRDFException { + if (result == null) { + result = invoke(); + } + return result; + } + + protected final void reset() { + result = null; if (progressMonitor != null) { progressMonitor.reset(); } - - return invoke(repCon); } public void setProgressMonitor(IProgressMonitor progressMonitor) { this.progressMonitor = progressMonitor; } + public void setRepositoryConnection(RepositoryConnection repCon) { + if (dependentIssue != null) { + dependentIssue.setRepositoryConnection(repCon); + } + + this.repCon = repCon; + reset(); + } + public String getId() { return id; } diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/LexicalRelations.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/LexicalRelations.java index 11ad47b..6cc6ccb 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/LexicalRelations.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/LexicalRelations.java @@ -28,7 +28,7 @@ public class LexicalRelations extends Issue> { public LexicalRelations(InvolvedConcepts involvedConcepts) { super(involvedConcepts, - "cl", + "clb", "Concept Labels", "Counts the number of relations between all concepts and lexical labels (prefLabel, altLabel, hiddenLabel and subproperties thereof)", IssueType.STATISTICAL 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/CommonLanguages.java new file mode 100644 index 0000000..084c7d1 --- /dev/null +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/CommonLanguages.java @@ -0,0 +1,47 @@ +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.LanguageCoverage; +import at.ac.univie.mminf.qskos4j.result.CollectionResult; +import org.openrdf.OpenRDFException; +import org.openrdf.model.Resource; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public class CommonLanguages extends Issue> { + + private LanguageCoverage languageCoverage; + private Set commonLanguages; + + public CommonLanguages(LanguageCoverage languageCoverage) { + super(languageCoverage, + "clg", + "Common Languages", + "Checks for common languages in all concept literals", + IssueType.ANALYTICAL); + + this.languageCoverage = languageCoverage; + } + + @Override + protected CollectionResult invoke() throws OpenRDFException { + Map> langCovData = languageCoverage.getResult().getData(); + commonLanguages = new HashSet(); + + if (!langCovData.isEmpty()) { + commonLanguages.addAll(langCovData.entrySet().iterator().next().getValue()); + findCommonLanguages(); + } + + return new CollectionResult<>(commonLanguages); + } + + private void findCommonLanguages() throws OpenRDFException { + for (Map.Entry> entry : languageCoverage.getResult().getData().entrySet()) { + commonLanguages.retainAll(entry.getValue()); + } + } +} diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/IncompleteLanguageCoverage.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/IncompleteLanguageCoverage.java index d0145a7..f18ebfc 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/IncompleteLanguageCoverage.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/IncompleteLanguageCoverage.java @@ -1,11 +1,9 @@ package at.ac.univie.mminf.qskos4j.issues.language; import at.ac.univie.mminf.qskos4j.issues.Issue; -import at.ac.univie.mminf.qskos4j.issues.concepts.InvolvedConcepts; import at.ac.univie.mminf.qskos4j.issues.language.util.LanguageCoverage; import org.openrdf.OpenRDFException; import org.openrdf.model.Resource; -import org.openrdf.model.Value; import org.openrdf.model.impl.URIImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -19,12 +17,12 @@ public class IncompleteLanguageCoverage extends Issue { private final Logger logger = LoggerFactory.getLogger(IncompleteLanguageCoverage.class); - private Map> languageCoverage, incompleteLanguageCoverage; + private Map> incompleteLanguageCoverage; + private LanguageCoverage languageCoverage; private Set distinctLanguages; - private InvolvedConcepts involvedConcepts; - public IncompleteLanguageCoverage(InvolvedConcepts involvedConcepts) { - super(involvedConcepts, + public IncompleteLanguageCoverage(LanguageCoverage languageCoverage) { + super(languageCoverage, "ilc", "Incomplete Language Coverage", "Finds concepts lacking description in languages that are present for other concepts", @@ -32,35 +30,33 @@ public IncompleteLanguageCoverage(InvolvedConcepts involvedConcepts) { new URIImpl("https://github.com/cmader/qSKOS/wiki/Quality-Issues#incomplete-language-coverage") ); - this.involvedConcepts = involvedConcepts; + this.languageCoverage = languageCoverage; } @Override protected IncompleteLangCovResult invoke() throws OpenRDFException { incompleteLanguageCoverage = new HashMap>(); - languageCoverage = new LanguageCoverage().findLanguageCoverage( - involvedConcepts.getResult().getData(), - progressMonitor, - repCon); findDistinctLanguages(); generateIncompleteLanguageCoverageMap(); return new IncompleteLangCovResult(incompleteLanguageCoverage); } - private void findDistinctLanguages() { + private void findDistinctLanguages() throws OpenRDFException { distinctLanguages = new HashSet(); - for (Collection languages : languageCoverage.values()) { + for (Collection languages : languageCoverage.getResult().getData().values()) { distinctLanguages.addAll(languages); } } - private void generateIncompleteLanguageCoverageMap() { + private void generateIncompleteLanguageCoverageMap() throws OpenRDFException { incompleteLanguageCoverage = new HashMap>(); - - for (Resource resource : languageCoverage.keySet()) { - Collection coveredLanguages = languageCoverage.get(resource); + + Map> langCovData = languageCoverage.getResult().getData(); + + for (Resource resource : langCovData.keySet()) { + Collection coveredLanguages = langCovData.get(resource); Collection notCoveredLanguages = getNotCoveredLanguages(coveredLanguages); if (!notCoveredLanguages.isEmpty()) { incompleteLanguageCoverage.put(resource, notCoveredLanguages); diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/NoCommonLanguage.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/NoCommonLanguage.java deleted file mode 100644 index d35c9e1..0000000 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/NoCommonLanguage.java +++ /dev/null @@ -1,23 +0,0 @@ -package at.ac.univie.mminf.qskos4j.issues.language; - -import at.ac.univie.mminf.qskos4j.issues.Issue; -import at.ac.univie.mminf.qskos4j.issues.concepts.AuthoritativeConcepts; -import at.ac.univie.mminf.qskos4j.result.Result; -import org.openrdf.OpenRDFException; - -public class NoCommonLanguage extends Issue { - - public NoCommonLanguage(AuthoritativeConcepts authoritativeConcepts) { - super(authoritativeConcepts, - "ncl", - "No Common Language", - "Checks if concept labels are available in at least one common language", - IssueType.ANALYTICAL); - } - - @Override - protected Result invoke() throws OpenRDFException { - return null; - } - -} diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/util/LanguageCoverage.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/util/LanguageCoverage.java index 906fb27..1b11f38 100644 --- a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/util/LanguageCoverage.java +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/util/LanguageCoverage.java @@ -1,32 +1,40 @@ package at.ac.univie.mminf.qskos4j.issues.language.util; -import at.ac.univie.mminf.qskos4j.progress.IProgressMonitor; +import at.ac.univie.mminf.qskos4j.issues.Issue; +import at.ac.univie.mminf.qskos4j.issues.concepts.InvolvedConcepts; import at.ac.univie.mminf.qskos4j.progress.MonitoredIterator; import org.openrdf.OpenRDFException; import org.openrdf.model.Literal; import org.openrdf.model.Resource; import org.openrdf.model.Value; import org.openrdf.query.*; -import org.openrdf.repository.RepositoryConnection; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.*; -public class LanguageCoverage { +public class LanguageCoverage extends Issue { private final Logger logger = LoggerFactory.getLogger(LanguageCoverage.class); private Map> languageCoverage; + private InvolvedConcepts involvedConcepts; - public Map> findLanguageCoverage( - Collection resources, - IProgressMonitor progressMonitor, - RepositoryConnection repCon) throws OpenRDFException - { + public LanguageCoverage(InvolvedConcepts involvedConcepts) { + super(involvedConcepts, + "lc", + "Language Coverage", + "Finds all languages used in concept labels", + IssueType.STATISTICAL); + + this.involvedConcepts = involvedConcepts; + } + + @Override + protected LanguageCoverageResult invoke() throws OpenRDFException { languageCoverage = new HashMap>(); - Iterator it = new MonitoredIterator(resources, progressMonitor); + Iterator it = new MonitoredIterator(involvedConcepts.getResult().getData(), progressMonitor); while (it.hasNext()) { Resource concept = it.next(); @@ -39,7 +47,7 @@ public Map> findLanguageCoverage( } } - return languageCoverage; + return new LanguageCoverageResult(languageCoverage); } private String createLanguageLiteralQuery(Value concept) { diff --git a/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/util/LanguageCoverageResult.java b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/util/LanguageCoverageResult.java new file mode 100644 index 0000000..5ac97ee --- /dev/null +++ b/src/main/java/at/ac/univie/mminf/qskos4j/issues/language/util/LanguageCoverageResult.java @@ -0,0 +1,20 @@ +package at.ac.univie.mminf.qskos4j.issues.language.util; + +import at.ac.univie.mminf.qskos4j.result.Result; +import org.openrdf.model.Resource; + +import java.util.Collection; +import java.util.Map; + +public class LanguageCoverageResult extends Result>> { + + protected LanguageCoverageResult(Map> data) { + super(data); + } + + @Override + public long occurrenceCount() { + return getData().size(); + } + +} 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 new file mode 100644 index 0000000..d2034ea --- /dev/null +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/CommonLanguagesTest.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.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/IncompleteLanguageCoverageTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/IncompleteLanguageCoverageTest.java index 91a9882..7978c8d 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/IncompleteLanguageCoverageTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/IncompleteLanguageCoverageTest.java @@ -2,6 +2,7 @@ import at.ac.univie.mminf.qskos4j.issues.concepts.InvolvedConcepts; import at.ac.univie.mminf.qskos4j.issues.language.IncompleteLanguageCoverage; +import at.ac.univie.mminf.qskos4j.issues.language.util.LanguageCoverage; import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; import org.junit.Assert; import org.junit.Before; @@ -16,24 +17,18 @@ import java.util.List; import java.util.Map; -/** - * Created by christian - * Date: 27.01.13 - * Time: 00:54 - */ public class IncompleteLanguageCoverageTest { private IncompleteLanguageCoverage incompleteLanguageCoverage; @Before public void setUp() throws OpenRDFException, IOException { - incompleteLanguageCoverage = new IncompleteLanguageCoverage(new InvolvedConcepts()); + incompleteLanguageCoverage = new IncompleteLanguageCoverage(new LanguageCoverage(new InvolvedConcepts())); incompleteLanguageCoverage.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("components.rdf").getConnection()); } @Test - public void testIncompleteLanguageCoverageCount() - throws OpenRDFException + public void testIncompleteLanguageCoverageCount() throws OpenRDFException { Map> incompleteLangCoverage = incompleteLanguageCoverage.getResult().getData(); Assert.assertEquals(13, incompleteLangCoverage.size()); diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/NoCommonLanguageTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/NoCommonLanguageTest.java deleted file mode 100644 index 8f91433..0000000 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/NoCommonLanguageTest.java +++ /dev/null @@ -1,29 +0,0 @@ -package at.ac.univie.mminf.qskos4j.issues; - -import at.ac.univie.mminf.qskos4j.issues.language.NoCommonLanguage; -import junit.framework.Assert; -import org.junit.Before; -import org.junit.Test; -import org.openrdf.OpenRDFException; - -import java.io.IOException; - -public class NoCommonLanguageTest { - - private NoCommonLanguage noCommonLanguage; - - @Before - public void setUp() throws OpenRDFException, IOException { - //noCommonLanguage = new NoCommonLanguage(); - //noCommonLanguage.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("nocommonlanguage.rdf").getConnection()); - } - - @Test - public void testIncompleteLanguageCoverageCount() - throws OpenRDFException - { - noCommonLanguage.getResult().getData(); - Assert.fail(); - } - -} diff --git a/src/test/java/at/ac/univie/mminf/qskos4j/issues/SkosXlTest.java b/src/test/java/at/ac/univie/mminf/qskos4j/issues/SkosXlTest.java index c0eb3cb..4374162 100644 --- a/src/test/java/at/ac/univie/mminf/qskos4j/issues/SkosXlTest.java +++ b/src/test/java/at/ac/univie/mminf/qskos4j/issues/SkosXlTest.java @@ -5,6 +5,7 @@ import at.ac.univie.mminf.qskos4j.issues.labels.OverlappingLabels; import at.ac.univie.mminf.qskos4j.issues.language.IncompleteLanguageCoverage; 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.util.vocab.RepositoryBuilder; import junit.framework.Assert; import org.junit.Before; @@ -33,7 +34,7 @@ public void setUp() throws OpenRDFException, IOException { omittedOrInvalidLanguageTags = new OmittedOrInvalidLanguageTags(); omittedOrInvalidLanguageTags.setRepositoryConnection(repo.getConnection()); - incompleteLanguageCoverage = new IncompleteLanguageCoverage(new InvolvedConcepts()); + incompleteLanguageCoverage = new IncompleteLanguageCoverage(new LanguageCoverage(new InvolvedConcepts())); incompleteLanguageCoverage.setRepositoryConnection(repo.getConnection()); overlappingLabels = new OverlappingLabels(new InvolvedConcepts()); diff --git a/src/test/resources/commonlanguage_en.rdf b/src/test/resources/commonlanguage_en.rdf new file mode 100644 index 0000000..3662338 --- /dev/null +++ b/src/test/resources/commonlanguage_en.rdf @@ -0,0 +1,28 @@ + + + + + + conceptA + + + + + conceptB + konzeptB + + + + + conceptC + + + + + conceptD + + + diff --git a/src/test/resources/nocommonlanguage.rdf b/src/test/resources/nocommonlanguage.rdf index e69de29..4b25452 100644 --- a/src/test/resources/nocommonlanguage.rdf +++ b/src/test/resources/nocommonlanguage.rdf @@ -0,0 +1,27 @@ + + + + + + conceptA + + + + + konzeptB + + + + + conceptC + + + + + conceptD + + + From 1033fd445359a1f0f2d1787edcc6db4ba4b022c8 Mon Sep 17 00:00:00 2001 From: cmader Date: Sat, 28 Dec 2013 17:17:03 +0100 Subject: [PATCH 19/19] report output improvements --- .../at/ac/univie/mminf/qskos4j/QSkos.java | 4 +- .../mminf/qskos4j/cmd/ReportCollector.java | 29 +++++++++---- .../labels/util/LabelConflictsResult.java | 2 +- ...nLanguages.java => NoCommonLanguages.java} | 14 +++---- .../util/NoCommonLanguagesResult.java | 41 +++++++++++++++++++ .../univie/mminf/qskos4j/result/Result.java | 8 +++- .../qskos4j/issues/CommonLanguagesTest.java | 35 ---------------- .../qskos4j/issues/NoCommonLanguagesTest.java | 35 ++++++++++++++++ 8 files changed, 115 insertions(+), 53 deletions(-) rename src/main/java/at/ac/univie/mminf/qskos4j/issues/language/{CommonLanguages.java => NoCommonLanguages.java} (74%) create mode 100644 src/main/java/at/ac/univie/mminf/qskos4j/issues/language/util/NoCommonLanguagesResult.java delete mode 100644 src/test/java/at/ac/univie/mminf/qskos4j/issues/CommonLanguagesTest.java create mode 100644 src/test/java/at/ac/univie/mminf/qskos4j/issues/NoCommonLanguagesTest.java 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()); + } + +}