├── src ├── main │ ├── resources │ │ ├── qskos_logo.png │ │ └── logback.xml │ └── java │ │ └── at │ │ └── ac │ │ └── univie │ │ └── mminf │ │ └── qskos4j │ │ ├── util │ │ ├── url │ │ │ ├── NoContentTypeProvidedException.java │ │ │ ├── UnhandledHTTPResponseException.java │ │ │ ├── UrlNotDereferencableException.java │ │ │ └── UrlDereferencer.java │ │ ├── vocab │ │ │ ├── InvalidRdfException.java │ │ │ ├── SparqlPrefix.java │ │ │ └── SkosOntology.java │ │ ├── graph │ │ │ ├── NamedEdge.java │ │ │ └── GraphExporter.java │ │ ├── Pair.java │ │ ├── RandomSubSet.java │ │ ├── Tuple.java │ │ ├── TupleQueryResultUtil.java │ │ └── IssueDescriptor.java │ │ ├── issues │ │ ├── labels │ │ │ ├── util │ │ │ │ ├── AmbiguousNotation.java │ │ │ │ ├── UriSuffixFinder.java │ │ │ │ ├── SimilarityLiteral.java │ │ │ │ ├── AmbiguousNotationMultipleResources.java │ │ │ │ ├── AmbiguousNotationWithinOneResource.java │ │ │ │ ├── EmptyLabelsResult.java │ │ │ │ ├── LabeledConcept.java │ │ │ │ ├── LabelConflict.java │ │ │ │ ├── LabelConflictsResult.java │ │ │ │ ├── LabelType.java │ │ │ │ └── ResourceLabelsCollector.java │ │ │ ├── EmptyLabeledResources.java │ │ │ └── LexicalRelations.java │ │ ├── language │ │ │ ├── util │ │ │ │ ├── LanguageCoverageResult.java │ │ │ │ └── NoCommonLanguagesResult.java │ │ │ ├── IncompleteLangCovResult.java │ │ │ ├── NoCommonLanguages.java │ │ │ ├── OmittedOrInvalidLanguageTagsResult.java │ │ │ └── IncompleteLanguageCoverage.java │ │ ├── concepts │ │ │ ├── HostNameOccurrencies.java │ │ │ ├── InvolvedConcepts.java │ │ │ └── OrphanConcepts.java │ │ ├── cycles │ │ │ └── HierarchicalCyclesResult.java │ │ ├── clusters │ │ │ └── ClustersResult.java │ │ ├── count │ │ │ ├── Collections.java │ │ │ ├── SemanticRelations.java │ │ │ └── AggregationRelations.java │ │ ├── conceptscheme │ │ │ ├── ConceptSchemeUtil.java │ │ │ ├── OmittedTopConcepts.java │ │ │ ├── MappingRelationsMisuse.java │ │ │ ├── TopConceptsHavingBroaderConcepts.java │ │ │ └── ConceptSchemes.java │ │ ├── relations │ │ │ └── UnidirectionallyRelatedConceptsResult.java │ │ ├── Issue.java │ │ ├── outlinks │ │ │ ├── HttpUriSchemeViolations.java │ │ │ └── HttpURIs.java │ │ └── skosintegrity │ │ │ ├── MappingClashes.java │ │ │ └── HierarchicalRedundancy.java │ │ ├── UnknownIssueIdException.java │ │ ├── result │ │ ├── UnsupportedReportFormatException.java │ │ ├── NumberResult.java │ │ ├── CollectionResult.java │ │ ├── ExtrapolatedCollectionResult.java │ │ ├── ResourceCollectionsResult.java │ │ └── Result.java │ │ └── progress │ │ ├── IProgressMonitor.java │ │ ├── StubProgressMonitor.java │ │ ├── StreamProgressMonitor.java │ │ ├── MonitoredIterator.java │ │ └── ConsoleProgressMonitor.java └── test │ ├── resources │ ├── nocontent.rdf │ ├── invalidCharacters.rdf │ ├── relatedConcepts.rdf │ ├── reflexivelyRelatedConcepts.rdf │ ├── emptyLabels.rdf │ ├── rankConcepts.rdf │ ├── hierarchicalAndAssociativeRelations.rdf │ ├── nocommonlanguage.rdf │ ├── overlappingLabels.rdf │ ├── commonlanguage_en.rdf │ ├── missingTopConcepts.rdf │ ├── topConceptsHavingBroaderConcept.rdf │ ├── labelMatch.rdf │ ├── documentedConcepts.rdf │ ├── exactVsAssociativeMappingClashes.rdf │ ├── resources.rdf │ ├── aggregations.rdf │ ├── cycles.rdf │ ├── skosxl.rdf │ ├── solitaryTransitiveRelations.rdf │ ├── labelsWithUnprintableCharacters.rdf │ ├── noBroaderAndNotTopConcepts.rdf │ ├── deprecatedAndIllegalTerms.rdf │ ├── hierarchicalRedundancy.rdf │ ├── redundantAssociativeRelations.rdf │ └── concepts.rdf │ └── java │ └── at │ └── ac │ └── univie │ └── mminf │ └── qskos4j │ ├── issues │ ├── MappingClashesTest.java │ ├── RelationClashesTest.java │ ├── CollectionsTest.java │ ├── HierarchicalRedundancyTest.java │ ├── ConceptSchemesTest.java │ ├── SemanticRelationsTest.java │ ├── OmittedTopConceptsTest.java │ ├── AggregationRelationsTest.java │ ├── EmptyLabeledResourcesTest.java │ ├── SolelyTransitivelyRelatedConceptsTest.java │ ├── TopConceptsHavingBroaderConceptsTest.java │ ├── InvalidCharactersTest.java │ ├── LexicalRelationsTest.java │ ├── BrokenLinksTest.java │ ├── ValuelessAssociativeRelationsTest.java │ ├── ReflexivelyRelatedConceptsTest.java │ ├── UndocumentedConceptsTest.java │ ├── HttpURIsTest.java │ ├── AmbiguousNotationReferencesTest.java │ ├── AuthoritativeConceptsTest.java │ ├── NoCommonLanguagesTest.java │ ├── UnidirectionallyRelatedConceptsTest.java │ ├── UnprintableCharactersInLabelsTest.java │ ├── HierarchicalCyclesTest.java │ ├── NonHttpResourcesTest.java │ ├── InvolvedConceptsTest.java │ ├── UndefinedSkosResourcesTest.java │ ├── DisjointLabelsViolationsTest.java │ ├── OrphanConceptsTest.java │ ├── InconsistentPrefLabelsTest.java │ ├── MissingOutLinksTest.java │ ├── DisconnectedConceptClustersTest.java │ ├── MappingRelationsMisuseTest.java │ ├── MissingInLinksTest.java │ ├── OmittedOrInvalidLanguageTagsTest.java │ ├── OverlappingLabelsTest.java │ ├── SkosXlTest.java │ └── IncompleteLanguageCoverageTest.java │ ├── cmd │ └── IssueInvocationTest.java │ └── qskos │ └── IssueIdTest.java ├── .gitignore └── CHANGELOG.rdoc /src/main/resources/qskos_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmader/qSKOS/HEAD/src/main/resources/qskos_logo.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .metadata 2 | .classpath 3 | .project 4 | *~ 5 | .settings/ 6 | target/ 7 | doc/ 8 | *.jar 9 | .idea* 10 | *.iml 11 | -------------------------------------------------------------------------------- /src/test/resources/nocontent.rdf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/util/url/NoContentTypeProvidedException.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.util.url; 2 | 3 | @SuppressWarnings("serial") 4 | public class NoContentTypeProvidedException extends RuntimeException { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/AmbiguousNotation.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues.labels.util; 2 | 3 | /** 4 | * Created by christian on 26.09.14. 5 | */ 6 | public abstract class AmbiguousNotation { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/util/vocab/InvalidRdfException.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.util.vocab; 2 | 3 | public class InvalidRdfException extends RuntimeException { 4 | 5 | public InvalidRdfException(String message) { 6 | super(message); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/test/resources/invalidCharacters.rdf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/UnknownIssueIdException.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j; 2 | 3 | public class UnknownIssueIdException extends RuntimeException { 4 | 5 | public UnknownIssueIdException(String issueId, String supportedIds) { 6 | super("Issue ID not supported: '" +issueId+ "'; valid IDs: '" +supportedIds+ "'"); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/util/url/UnhandledHTTPResponseException.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.util.url; 2 | 3 | @SuppressWarnings("serial") 4 | class UnhandledHTTPResponseException extends RuntimeException { 5 | 6 | UnhandledHTTPResponseException(int statusCode) { 7 | super("Unhandled HTTP response code: '" +statusCode+ '"'); 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/util/url/UrlNotDereferencableException.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.util.url; 2 | 3 | import java.net.URL; 4 | 5 | @SuppressWarnings("serial") 6 | public class UrlNotDereferencableException extends Exception { 7 | 8 | public UrlNotDereferencableException(URL url) { 9 | super("Unable to dereference URL '"+url+"'"); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %msg%n 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /CHANGELOG.rdoc: -------------------------------------------------------------------------------- 1 | = Changelog 2 | 3 | == Release 1.2.0, Jan 2014 4 | 5 | * Additional Quality Issues 6 | * Revised API 7 | * Usability Improvements (new command line options, quality issue descriptions) 8 | 9 | == Release 0.9.5, May 2013 10 | * RDFS inferencing support 11 | * performance improvements 12 | * API improvements 13 | 14 | == Release 0.9, June 2012 15 | * first "official" release (announced at public-esw-thes-request@w3.org) -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/result/UnsupportedReportFormatException.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.result; 2 | 3 | public class UnsupportedReportFormatException extends RuntimeException { 4 | 5 | private final static String MESSAGE = "Unsupported Result Format: '"; 6 | 7 | public UnsupportedReportFormatException(Result.ReportFormat format) { 8 | super(MESSAGE +format.toString()+ "'"); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/util/graph/NamedEdge.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.util.graph; 2 | 3 | import org.jgrapht.graph.DefaultEdge; 4 | 5 | @SuppressWarnings("serial") 6 | public class NamedEdge extends DefaultEdge { 7 | 8 | private String name = ""; 9 | 10 | public NamedEdge() { 11 | this(""); 12 | } 13 | 14 | public NamedEdge(String name) { 15 | super(); 16 | this.name = name; 17 | } 18 | 19 | @Override 20 | public String toString() { 21 | return name; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/progress/IProgressMonitor.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.progress; 2 | 3 | public interface IProgressMonitor { 4 | 5 | /** 6 | * Called if a task's progress changes 7 | * @param progress value between 0 and 1 8 | */ 9 | public void onUpdateProgress(float progress); 10 | 11 | /** 12 | * Textual description for the currently performed task 13 | * @param description 14 | */ 15 | public void setTaskDescription(String description); 16 | 17 | /** 18 | * Resets the internal state 19 | */ 20 | public void reset(); 21 | 22 | public void onFinish(); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/issues/language/util/LanguageCoverageResult.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues.language.util; 2 | 3 | import at.ac.univie.mminf.qskos4j.result.Result; 4 | import org.eclipse.rdf4j.model.Resource; 5 | 6 | import java.util.Collection; 7 | import java.util.Map; 8 | 9 | public class LanguageCoverageResult extends Result>> { 10 | 11 | protected LanguageCoverageResult(Map> data) { 12 | super(data); 13 | } 14 | 15 | @Override 16 | public long occurrenceCount() { 17 | return getData().size(); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/progress/StubProgressMonitor.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.progress; 2 | 3 | public class StubProgressMonitor implements IProgressMonitor { 4 | 5 | @Override 6 | public void onUpdateProgress(float progress) { 7 | // TODO Auto-generated method stub 8 | 9 | } 10 | 11 | @Override 12 | public void setTaskDescription(String description) { 13 | // TODO Auto-generated method stub 14 | 15 | } 16 | 17 | @Override 18 | public void reset() { 19 | // TODO Auto-generated method stub 20 | } 21 | 22 | @Override 23 | public void onFinish() { 24 | // TODO Auto-generated method stub 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/UriSuffixFinder.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues.labels.util; 2 | 3 | import org.eclipse.rdf4j.model.Value; 4 | 5 | import java.util.Collection; 6 | 7 | public class UriSuffixFinder { 8 | 9 | public static boolean isPartOfConflict(Collection conflicts, String uriSuffix) 10 | { 11 | if (conflicts != null) { 12 | for (LabelConflict conflict : conflicts) { 13 | for (Value resource : conflict.getAffectedResources()) { 14 | if (resource.stringValue().endsWith(uriSuffix)) { 15 | return true; 16 | } 17 | } 18 | } 19 | } 20 | 21 | return false; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/test/resources/relatedConcepts.rdf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Coix lachryma jobi 7 | 8 | 9 | 10 | 11 | Mammiferi nocivi 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/result/NumberResult.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.result; 2 | 3 | import java.io.BufferedWriter; 4 | import java.io.IOException; 5 | 6 | public class NumberResult extends Result { 7 | 8 | public NumberResult(T data) { 9 | super(data); 10 | } 11 | 12 | @Override 13 | protected void generateTextReport(BufferedWriter osw, ReportStyle style) throws IOException 14 | { 15 | switch (style) { 16 | case SHORT: 17 | osw.write("value: " +getData().toString()); 18 | break; 19 | 20 | case EXTENSIVE: 21 | // not needed for this type 22 | } 23 | } 24 | 25 | @Override 26 | public long occurrenceCount() { 27 | return getData().longValue(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/SimilarityLiteral.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues.labels.util; 2 | 3 | import org.eclipse.rdf4j.model.Literal; 4 | import org.eclipse.rdf4j.model.impl.SimpleLiteral; 5 | 6 | public class SimilarityLiteral extends SimpleLiteral { 7 | 8 | public SimilarityLiteral(Literal literal) { 9 | super(literal.getLabel().toUpperCase()); 10 | if(literal.getLanguage().isPresent()) { 11 | setLanguage(literal.getLanguage().get()); 12 | } 13 | setDatatype(literal.getDatatype()); 14 | } 15 | 16 | @Override 17 | public boolean equals(Object obj) { 18 | return obj instanceof SimilarityLiteral && isSimilar((SimilarityLiteral) obj); 19 | } 20 | 21 | private boolean isSimilar(SimilarityLiteral other) { 22 | return super.equals(other); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/util/vocab/SparqlPrefix.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.util.vocab; 2 | 3 | 4 | public enum SparqlPrefix { 5 | SKOS("skos", "http://www.w3.org/2004/02/skos/core#"), 6 | SKOSXL("skosxl", "http://www.w3.org/2008/05/skos-xl#"), 7 | DC("dc", "http://purl.org/dc/elements/1.1/"), 8 | DCTERMS("dcterms", "http://purl.org/dc/terms/"), 9 | RDF("rdf", org.eclipse.rdf4j.model.vocabulary.RDF.NAMESPACE), 10 | RDFS("rdfs", org.eclipse.rdf4j.model.vocabulary.RDFS.NAMESPACE); 11 | 12 | private String abbrv, nameSpace; 13 | 14 | private SparqlPrefix(String abbrv, String nameSpace) { 15 | this.abbrv = abbrv; 16 | this.nameSpace = nameSpace; 17 | } 18 | 19 | @Override 20 | public String toString() { 21 | return "PREFIX " +abbrv+ ":<" +nameSpace+ ">"; 22 | } 23 | 24 | public String getNameSpace() { 25 | return nameSpace; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/test/resources/reflexivelyRelatedConcepts.rdf: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/test/resources/emptyLabels.rdf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | somelabel 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/test/java/at/ac/univie/mminf/qskos4j/issues/MappingClashesTest.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.skosintegrity.MappingClashes; 4 | import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; 5 | import org.junit.Assert; 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | import org.eclipse.rdf4j.RDF4JException; 9 | 10 | import java.io.IOException; 11 | 12 | public class MappingClashesTest { 13 | 14 | private MappingClashes mappingClashes; 15 | 16 | @Before 17 | public void setUp() throws RDF4JException, IOException { 18 | mappingClashes = new MappingClashes(); 19 | mappingClashes.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("exactVsAssociativeMappingClashes.rdf").getConnection()); 20 | } 21 | 22 | @Test 23 | public void testExactVsAssociativeMappingClashes() throws RDF4JException { 24 | Assert.assertEquals(5, mappingClashes.getResult().getData().size()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/at/ac/univie/mminf/qskos4j/issues/RelationClashesTest.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.skosintegrity.RelationClashes; 4 | import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; 5 | import org.junit.Assert; 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | import org.eclipse.rdf4j.RDF4JException; 9 | 10 | import java.io.IOException; 11 | 12 | public class RelationClashesTest { 13 | 14 | private RelationClashes relationClashes; 15 | 16 | @Before 17 | public void setUp() throws RDF4JException, IOException { 18 | relationClashes = new RelationClashes(new HierarchyGraphBuilder()); 19 | relationClashes.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("relationClashes.rdf").getConnection()); 20 | } 21 | 22 | @Test 23 | public void testAssociativeVsHierarchicalClashes() throws RDF4JException { 24 | Assert.assertEquals(10, relationClashes.getResult().getData().size()); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/at/ac/univie/mminf/qskos4j/issues/CollectionsTest.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.count.Collections; 4 | import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; 5 | import junit.framework.Assert; 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | import org.eclipse.rdf4j.RDF4JException; 9 | 10 | import java.io.IOException; 11 | 12 | /** 13 | * Created by christian 14 | * Date: 26.01.13 15 | * Time: 14:47 16 | */ 17 | public class CollectionsTest { 18 | 19 | private Collections collections; 20 | 21 | @Before 22 | public void setUp() throws RDF4JException, IOException { 23 | collections = new Collections(); 24 | collections.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("aggregations.rdf").getConnection()); 25 | } 26 | 27 | @Test 28 | public void testCollectionsCount() throws RDF4JException 29 | { 30 | Assert.assertEquals(4, collections.getResult().getData().longValue()); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/at/ac/univie/mminf/qskos4j/issues/HierarchicalRedundancyTest.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.skosintegrity.HierarchicalRedundancy; 4 | import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; 5 | import org.junit.Assert; 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | import org.eclipse.rdf4j.RDF4JException; 9 | 10 | import java.io.IOException; 11 | 12 | public class HierarchicalRedundancyTest { 13 | 14 | private HierarchicalRedundancy hierarchicalRedundancy; 15 | 16 | @Before 17 | public void setUp() throws RDF4JException, IOException { 18 | hierarchicalRedundancy = new HierarchicalRedundancy(new HierarchyGraphBuilder()); 19 | hierarchicalRedundancy.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("hierarchicalRedundancy.rdf").getConnection()); 20 | } 21 | 22 | @Test 23 | public void redundancyCount() throws RDF4JException { 24 | Assert.assertEquals(5, hierarchicalRedundancy.getResult().getData().size()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/at/ac/univie/mminf/qskos4j/issues/ConceptSchemesTest.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.conceptscheme.ConceptSchemes; 4 | import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; 5 | import junit.framework.Assert; 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | import org.eclipse.rdf4j.RDF4JException; 9 | 10 | import java.io.IOException; 11 | 12 | /** 13 | * Created by christian 14 | * Date: 26.01.13 15 | * Time: 14:47 16 | */ 17 | public class ConceptSchemesTest { 18 | 19 | private ConceptSchemes conceptSchemes; 20 | 21 | @Before 22 | public void setUp() throws RDF4JException, IOException { 23 | conceptSchemes = new ConceptSchemes(); 24 | conceptSchemes.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("aggregations.rdf").getConnection()); 25 | } 26 | 27 | @Test 28 | public void testLexicalRelationsCount() throws RDF4JException 29 | { 30 | Assert.assertEquals(3, conceptSchemes.getResult().getData().size()); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/test/resources/rankConcepts.rdf: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/test/resources/hierarchicalAndAssociativeRelations.rdf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/test/java/at/ac/univie/mminf/qskos4j/issues/SemanticRelationsTest.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.count.SemanticRelations; 4 | import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; 5 | import junit.framework.Assert; 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | import org.eclipse.rdf4j.RDF4JException; 9 | 10 | import java.io.IOException; 11 | 12 | /** 13 | * Created by christian 14 | * Date: 26.01.13 15 | * Time: 14:22 16 | */ 17 | public class SemanticRelationsTest { 18 | 19 | private SemanticRelations semanticRelations; 20 | 21 | @Before 22 | public void setUp() throws RDF4JException, IOException { 23 | semanticRelations = new SemanticRelations(); 24 | semanticRelations.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("components_1.rdf").getConnection()); 25 | } 26 | 27 | @Test 28 | public void testLexicalRelationsCount() throws RDF4JException 29 | { 30 | Assert.assertEquals(18, semanticRelations.getResult().getData().longValue()); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/issues/concepts/HostNameOccurrencies.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues.concepts; 2 | 3 | import java.util.*; 4 | 5 | class HostNameOccurrencies extends HashMap { 6 | 7 | void put(String hostname) { 8 | Integer occurencies = get(hostname); 9 | put(hostname, occurencies == null ? 1 : ++occurencies); 10 | } 11 | 12 | String getMostOftenOccuringHostName() { 13 | SortedSet> sortedEntries = new TreeSet>( 14 | new Comparator>() 15 | { 16 | @Override 17 | public int compare(Map.Entry e1, Map.Entry e2) { 18 | return e2.getValue().compareTo(e1.getValue()); 19 | } 20 | } 21 | ); 22 | 23 | sortedEntries.addAll(entrySet()); 24 | if (!sortedEntries.isEmpty()) { 25 | return sortedEntries.first().getKey(); 26 | } 27 | 28 | return ""; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/at/ac/univie/mminf/qskos4j/issues/OmittedTopConceptsTest.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.conceptscheme.ConceptSchemes; 4 | import at.ac.univie.mminf.qskos4j.issues.conceptscheme.OmittedTopConcepts; 5 | import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; 6 | import junit.framework.Assert; 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | import org.eclipse.rdf4j.RDF4JException; 10 | 11 | import java.io.IOException; 12 | 13 | 14 | public class OmittedTopConceptsTest { 15 | 16 | private OmittedTopConcepts omittedTopConcepts; 17 | 18 | @Before 19 | public void setUp() throws RDF4JException, IOException { 20 | omittedTopConcepts = new OmittedTopConcepts(new ConceptSchemes()); 21 | omittedTopConcepts.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("missingTopConcepts.rdf").getConnection()); 22 | } 23 | 24 | @Test 25 | public void testConceptSchemesWithoutTopConceptsCount() throws RDF4JException { 26 | Assert.assertEquals(2, omittedTopConcepts.getResult().getData().size()); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/at/ac/univie/mminf/qskos4j/issues/AggregationRelationsTest.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.count.AggregationRelations; 4 | import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; 5 | import junit.framework.Assert; 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | import org.eclipse.rdf4j.RDF4JException; 9 | 10 | import java.io.IOException; 11 | 12 | /** 13 | * Created by christian 14 | * Date: 26.01.13 15 | * Time: 14:47 16 | */ 17 | public class AggregationRelationsTest { 18 | 19 | private AggregationRelations aggregationRelations; 20 | 21 | @Before 22 | public void setUp() throws RDF4JException, IOException { 23 | aggregationRelations = new AggregationRelations(); 24 | aggregationRelations.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("aggregations.rdf").getConnection()); 25 | } 26 | 27 | @Test 28 | public void testAggregationRelationsCount() throws RDF4JException 29 | { 30 | Assert.assertEquals(6, aggregationRelations.getResult().getData().longValue()); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/at/ac/univie/mminf/qskos4j/issues/EmptyLabeledResourcesTest.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.labels.EmptyLabeledResources; 4 | import at.ac.univie.mminf.qskos4j.issues.labels.util.EmptyLabelsResult; 5 | import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; 6 | import org.junit.Assert; 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | import org.eclipse.rdf4j.RDF4JException; 10 | 11 | import java.io.IOException; 12 | 13 | public class EmptyLabeledResourcesTest { 14 | 15 | private EmptyLabeledResources emptyLabeledResources; 16 | 17 | @Before 18 | public void setUp() throws IOException, RDF4JException { 19 | emptyLabeledResources = new EmptyLabeledResources(); 20 | emptyLabeledResources.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("emptyLabels.rdf").getConnection()); 21 | } 22 | 23 | @Test 24 | public void testEmptyLabels() throws RDF4JException { 25 | EmptyLabelsResult result = emptyLabeledResources.getResult(); 26 | Assert.assertEquals(3, result.occurrenceCount()); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/at/ac/univie/mminf/qskos4j/issues/SolelyTransitivelyRelatedConceptsTest.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.relations.SolelyTransitivelyRelatedConcepts; 4 | import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; 5 | import org.junit.Assert; 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | import org.eclipse.rdf4j.RDF4JException; 9 | 10 | import java.io.IOException; 11 | 12 | public class SolelyTransitivelyRelatedConceptsTest { 13 | 14 | private SolelyTransitivelyRelatedConcepts solelyTransitivelyRelatedConcepts; 15 | 16 | @Before 17 | public void setUp() throws RDF4JException, IOException { 18 | solelyTransitivelyRelatedConcepts = new SolelyTransitivelyRelatedConcepts(); 19 | solelyTransitivelyRelatedConcepts.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("solitaryTransitiveRelations.rdf").getConnection()); 20 | } 21 | 22 | @Test 23 | public void testSolitaryTransitiveRelationsCount() throws RDF4JException { 24 | Assert.assertEquals(4, solelyTransitivelyRelatedConcepts.getResult().getData().size()); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/at/ac/univie/mminf/qskos4j/issues/TopConceptsHavingBroaderConceptsTest.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.conceptscheme.TopConceptsHavingBroaderConcepts; 4 | import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; 5 | import junit.framework.Assert; 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | import org.eclipse.rdf4j.RDF4JException; 9 | 10 | import java.io.IOException; 11 | 12 | 13 | public class TopConceptsHavingBroaderConceptsTest { 14 | 15 | private TopConceptsHavingBroaderConcepts topConceptsHavingBroaderConcepts; 16 | 17 | @Before 18 | public void setUp() throws RDF4JException, IOException { 19 | topConceptsHavingBroaderConcepts = new TopConceptsHavingBroaderConcepts(); 20 | topConceptsHavingBroaderConcepts.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("topConceptsHavingBroaderConcept.rdf").getConnection()); 21 | } 22 | 23 | @Test 24 | public void testTopConceptsHavingBroaderConceptCount() throws RDF4JException { 25 | Assert.assertEquals(4, topConceptsHavingBroaderConcepts.getResult().getData().size()); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/util/Pair.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.util; 2 | 3 | public class Pair { 4 | 5 | private T first, second; 6 | 7 | public Pair(T first, T second) { 8 | this.first = first; 9 | this.second = second; 10 | } 11 | 12 | @Override 13 | public boolean equals(Object obj) { 14 | if (obj instanceof Pair) { 15 | Pair other = (Pair) obj; 16 | 17 | return (first.equals(other.first) && second.equals(other.second)) || 18 | (first.equals(other.second) && second.equals(other.first)); 19 | } 20 | return false; 21 | } 22 | 23 | public int hashCode() { 24 | int hashFirst = first != null ? first.hashCode() : 0; 25 | int hashSecond = second != null ? second.hashCode() : 0; 26 | 27 | return hashFirst + hashSecond; 28 | } 29 | 30 | @Override 31 | public String toString() { 32 | return "("+first.toString() +", "+ second.toString() +")"; 33 | } 34 | 35 | public T getFirst() { 36 | return first; 37 | } 38 | 39 | public T getSecond() { 40 | return second; 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /src/test/java/at/ac/univie/mminf/qskos4j/issues/InvalidCharactersTest.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues; 2 | 3 | import at.ac.univie.mminf.qskos4j.QSkos; 4 | import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; 5 | import junit.framework.Assert; 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | import org.eclipse.rdf4j.RDF4JException; 9 | 10 | import java.io.IOException; 11 | 12 | public class InvalidCharactersTest { 13 | private QSkos qSkosInvalidCharacters; 14 | 15 | @Before 16 | public void setUp() throws RDF4JException, IOException { 17 | qSkosInvalidCharacters = new QSkos(); 18 | qSkosInvalidCharacters.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("invalidCharacters.rdf").getConnection()); 19 | } 20 | 21 | @Test 22 | public void testAllIssues() throws RDF4JException { 23 | // all issues must run without exception 24 | try { 25 | for (Issue issue : qSkosInvalidCharacters.getAllIssues()) { 26 | issue.getResult(); 27 | } 28 | } 29 | catch (Exception e) { 30 | Assert.fail(e.toString()); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/progress/StreamProgressMonitor.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.progress; 2 | 3 | public class StreamProgressMonitor implements IProgressMonitor { 4 | 5 | private int prevPercentage = 0, prevTenPercentage = 0; 6 | 7 | @Override 8 | public void onUpdateProgress(float progress) { 9 | int percentage = Math.round(progress * 100); 10 | int tenPercentage = (int) Math.floor(progress * 10); 11 | if (percentage > prevPercentage) { 12 | if (tenPercentage > prevTenPercentage) { 13 | System.out.print(tenPercentage * 10 + "%"); 14 | prevTenPercentage = tenPercentage; 15 | } 16 | else { 17 | System.out.print("."); 18 | } 19 | prevPercentage = percentage; 20 | } 21 | } 22 | 23 | @Override 24 | public void setTaskDescription(String description) { 25 | System.out.println(description); 26 | } 27 | 28 | @Override 29 | public void reset() { 30 | prevPercentage = 0; 31 | } 32 | 33 | @Override 34 | public void onFinish() { 35 | System.out.println(); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/at/ac/univie/mminf/qskos4j/issues/LexicalRelationsTest.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.concepts.InvolvedConcepts; 4 | import at.ac.univie.mminf.qskos4j.issues.labels.LexicalRelations; 5 | import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; 6 | import junit.framework.Assert; 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | import org.eclipse.rdf4j.RDF4JException; 10 | 11 | import java.io.IOException; 12 | 13 | /** 14 | * Created by christian 15 | * Date: 26.01.13 16 | * Time: 14:18 17 | */ 18 | public class LexicalRelationsTest { 19 | 20 | private LexicalRelations lexicalRelations; 21 | 22 | @Before 23 | public void setUp() throws RDF4JException, IOException 24 | { 25 | lexicalRelations = new LexicalRelations(new InvolvedConcepts()); 26 | lexicalRelations.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("components_1.rdf").getConnection()); 27 | } 28 | 29 | @Test 30 | public void testLexicalRelationsCount() throws RDF4JException { 31 | Assert.assertEquals(29, lexicalRelations.getResult().getData().longValue()); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/AmbiguousNotationMultipleResources.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues.labels.util; 2 | 3 | 4 | import org.eclipse.rdf4j.model.Literal; 5 | import org.eclipse.rdf4j.model.Resource; 6 | 7 | import java.util.Collection; 8 | import java.util.Iterator; 9 | 10 | /** 11 | * Created by christian on 26.09.14. 12 | */ 13 | public class AmbiguousNotationMultipleResources extends AmbiguousNotation { 14 | 15 | private Literal notation; 16 | private Collection conflictingResources; 17 | 18 | public AmbiguousNotationMultipleResources(Literal notation, Collection conflictingResources) { 19 | this.notation = notation; 20 | this.conflictingResources = conflictingResources; 21 | } 22 | 23 | @Override 24 | public String toString() { 25 | String result = "Notation: " +notation.stringValue()+ ", conflicting resources: "; 26 | Iterator resourceIt = conflictingResources.iterator(); 27 | while (resourceIt.hasNext()) { 28 | result += resourceIt.next().stringValue() + (resourceIt.hasNext() ? ", " : ""); 29 | } 30 | return result; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/AmbiguousNotationWithinOneResource.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues.labels.util; 2 | 3 | import org.eclipse.rdf4j.model.Literal; 4 | import org.eclipse.rdf4j.model.Resource; 5 | 6 | import java.util.Collection; 7 | import java.util.Iterator; 8 | 9 | /** 10 | * Created by christian on 26.09.14. 11 | */ 12 | public class AmbiguousNotationWithinOneResource extends AmbiguousNotation { 13 | 14 | private Resource authConcept; 15 | private Collection notationsForConcept; 16 | 17 | public AmbiguousNotationWithinOneResource(Resource authConcept, Collection notationsForConcept) { 18 | this.authConcept = authConcept; 19 | this.notationsForConcept = notationsForConcept; 20 | } 21 | 22 | @Override 23 | public String toString() { 24 | String ret = "Resource: " +authConcept.stringValue()+ ", Notations: "; 25 | 26 | Iterator notationsIt = notationsForConcept.iterator(); 27 | while (notationsIt.hasNext()) { 28 | ret += notationsIt.next().stringValue() + (notationsIt.hasNext() ? ", " : ""); 29 | } 30 | 31 | return ret; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/issues/cycles/HierarchicalCyclesResult.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues.cycles; 2 | 3 | import at.ac.univie.mminf.qskos4j.result.ResourceCollectionsResult; 4 | import at.ac.univie.mminf.qskos4j.util.graph.GraphExporter; 5 | import at.ac.univie.mminf.qskos4j.util.graph.NamedEdge; 6 | import org.jgrapht.DirectedGraph; 7 | import org.eclipse.rdf4j.model.Resource; 8 | 9 | import java.io.BufferedWriter; 10 | import java.io.IOException; 11 | import java.util.Collection; 12 | 13 | public class HierarchicalCyclesResult extends ResourceCollectionsResult { 14 | 15 | private DirectedGraph graph; 16 | 17 | public HierarchicalCyclesResult( 18 | Collection> data, 19 | DirectedGraph graph) 20 | { 21 | super(data, "Cycle"); 22 | 23 | this.graph = graph; 24 | } 25 | 26 | @Override 27 | public void generateDotReport(BufferedWriter writer) throws IOException { 28 | for (String hierarchyCycleDot : new GraphExporter(graph).exportDotGraphs(getData())) { 29 | writer.write(hierarchyCycleDot); 30 | writer.newLine(); 31 | } 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/test/resources/nocommonlanguage.rdf: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | conceptA 10 | 11 | 12 | 13 | 14 | konzeptB 15 | 16 | 17 | 18 | 19 | conceptC 20 | 21 | 22 | 23 | 24 | conceptD 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/util/RandomSubSet.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.util; 2 | 3 | import java.util.*; 4 | 5 | public class RandomSubSet extends AbstractSet{ 6 | 7 | private Collection subset; 8 | private List origElements; 9 | private int subsetElementCount; 10 | 11 | public RandomSubSet(Collection origSet, float randomSubsetSize_percent) 12 | { 13 | origElements = new ArrayList(origSet); 14 | subsetElementCount = (int) ((origSet.size() * randomSubsetSize_percent) / (float) 100); 15 | subset = new HashSet(subsetElementCount); 16 | 17 | pickRandomElements(); 18 | } 19 | 20 | private void pickRandomElements() 21 | { 22 | Random randomGenerator = new Random(); 23 | 24 | for (int i = 0; i < subsetElementCount; i++) { 25 | T randomElement; 26 | do { 27 | int origUriIndex = randomGenerator.nextInt(origElements.size()); 28 | randomElement = origElements.get(origUriIndex); 29 | } 30 | while (subset.contains(randomElement)); 31 | subset.add(randomElement); 32 | } 33 | } 34 | 35 | @Override 36 | public Iterator iterator() { 37 | return subset.iterator(); 38 | } 39 | 40 | @Override 41 | public int size() { 42 | return subset.size(); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/issues/clusters/ClustersResult.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues.clusters; 2 | 3 | import at.ac.univie.mminf.qskos4j.result.ResourceCollectionsResult; 4 | import at.ac.univie.mminf.qskos4j.util.graph.GraphExporter; 5 | import at.ac.univie.mminf.qskos4j.util.graph.NamedEdge; 6 | import org.jgrapht.DirectedGraph; 7 | import org.eclipse.rdf4j.model.Resource; 8 | 9 | import java.io.BufferedWriter; 10 | import java.io.IOException; 11 | import java.util.Collection; 12 | 13 | public class ClustersResult extends ResourceCollectionsResult 14 | { 15 | private DirectedGraph graph; 16 | 17 | ClustersResult(Collection> data, DirectedGraph graph) { 18 | super(data, "Cluster"); 19 | 20 | // one disconnected cluster is not an error, so no need to report 21 | if (data.size() == 1) data.clear(); 22 | 23 | this.graph = graph; 24 | } 25 | 26 | @Override 27 | public void generateDotReport(BufferedWriter writer) throws IOException { 28 | for (String dotGraph : new GraphExporter(graph).exportDotGraphs(getData())) { 29 | writer.write(dotGraph); 30 | writer.newLine(); 31 | } 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/test/resources/overlappingLabels.rdf: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | Concept Label 9 | 10 | 11 | 12 | 13 | concept label 14 | 15 | 16 | 17 | 18 | 19 | Another Label 20 | 21 | 22 | 23 | 24 | another label 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/test/resources/commonlanguage_en.rdf: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | conceptB 10 | konzeptB 11 | 12 | 13 | 14 | 15 | conceptA 16 | 17 | 18 | 19 | 20 | conceptC 21 | 22 | 23 | 24 | 25 | conceptD 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/result/CollectionResult.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.result; 2 | 3 | import java.io.BufferedWriter; 4 | import java.io.IOException; 5 | import java.util.Collection; 6 | import java.util.Iterator; 7 | 8 | public class CollectionResult extends Result> { 9 | 10 | public CollectionResult(Collection data) { 11 | super(data); 12 | } 13 | 14 | @Override 15 | protected void generateTextReport(BufferedWriter osw, ReportStyle style) throws IOException 16 | { 17 | switch (style) { 18 | case SHORT: 19 | osw.write("count: " + getData().size()); 20 | break; 21 | 22 | case EXTENSIVE: 23 | osw.write(generateExtensiveTextReport()); 24 | break; 25 | } 26 | } 27 | 28 | @Override 29 | public long occurrenceCount() { 30 | return getData().size(); 31 | } 32 | 33 | public String generateExtensiveTextReport() { 34 | StringBuilder report = new StringBuilder(); 35 | Iterator dataIt = getData().iterator(); 36 | while (dataIt.hasNext()) { 37 | report.append(dataIt.next().toString()).append(dataIt.hasNext() ? "\n" : ""); 38 | } 39 | 40 | return report.toString(); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/at/ac/univie/mminf/qskos4j/issues/BrokenLinksTest.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.outlinks.BrokenLinks; 4 | import at.ac.univie.mminf.qskos4j.issues.outlinks.HttpURIs; 5 | import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; 6 | import junit.framework.Assert; 7 | import org.junit.Before; 8 | import org.junit.Ignore; 9 | import org.junit.Test; 10 | import org.eclipse.rdf4j.RDF4JException; 11 | 12 | import java.io.IOException; 13 | import java.net.URL; 14 | import java.util.Collection; 15 | 16 | /** 17 | * Created by christian 18 | * Date: 26.01.13 19 | * Time: 16:44 20 | */ 21 | public class BrokenLinksTest { 22 | 23 | private BrokenLinks brokenLinks; 24 | 25 | @Before 26 | public void setUp() throws RDF4JException, IOException { 27 | brokenLinks = new BrokenLinks(new HttpURIs()); 28 | brokenLinks.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("resources.rdf").getConnection()); 29 | brokenLinks.setExtAccessDelayMillis(0); 30 | } 31 | 32 | @Ignore 33 | @Test 34 | public void testBrokenLinks() throws RDF4JException { 35 | Collection brokenLinkURLs = brokenLinks.getResult().getData(); 36 | Assert.assertEquals(1, brokenLinkURLs.size()); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/at/ac/univie/mminf/qskos4j/issues/ValuelessAssociativeRelationsTest.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.relations.ValuelessAssociativeRelations; 4 | import at.ac.univie.mminf.qskos4j.util.Tuple; 5 | import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; 6 | import junit.framework.Assert; 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | import org.eclipse.rdf4j.RDF4JException; 10 | import org.eclipse.rdf4j.model.IRI; 11 | 12 | import java.io.IOException; 13 | import java.util.Collection; 14 | 15 | public class ValuelessAssociativeRelationsTest { 16 | 17 | private ValuelessAssociativeRelations valuelessAssociativeRelations; 18 | 19 | @Before 20 | public void setUp() throws RDF4JException, IOException { 21 | valuelessAssociativeRelations = new ValuelessAssociativeRelations(); 22 | valuelessAssociativeRelations.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("redundantAssociativeRelations.rdf").getConnection()); 23 | } 24 | 25 | @Test 26 | public void testRedundantAssociativeRelationsCount() throws RDF4JException { 27 | Collection> redAssRels = valuelessAssociativeRelations.getResult().getData(); 28 | Assert.assertEquals(6, redAssRels.size()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/at/ac/univie/mminf/qskos4j/issues/ReflexivelyRelatedConceptsTest.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.concepts.AuthoritativeConcepts; 4 | import at.ac.univie.mminf.qskos4j.issues.concepts.InvolvedConcepts; 5 | import at.ac.univie.mminf.qskos4j.issues.relations.ReflexivelyRelatedConcepts; 6 | import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; 7 | import junit.framework.Assert; 8 | import org.junit.Before; 9 | import org.junit.Test; 10 | import org.eclipse.rdf4j.RDF4JException; 11 | 12 | import java.io.IOException; 13 | 14 | public class ReflexivelyRelatedConceptsTest { 15 | 16 | private ReflexivelyRelatedConcepts reflexivelyRelatedConcepts; 17 | 18 | @Before 19 | public void setUp() throws IOException, RDF4JException 20 | { 21 | reflexivelyRelatedConcepts = new ReflexivelyRelatedConcepts(new AuthoritativeConcepts(new InvolvedConcepts())); 22 | reflexivelyRelatedConcepts.setRepositoryConnection( 23 | new RepositoryBuilder().setUpFromTestResource("reflexivelyRelatedConcepts.rdf").getConnection()); 24 | } 25 | 26 | @Test 27 | public void mappingRelationsMisuseCount() throws RDF4JException { 28 | Assert.assertEquals(2, reflexivelyRelatedConcepts.getResult().getData().size()); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/EmptyLabelsResult.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues.labels.util; 2 | 3 | import at.ac.univie.mminf.qskos4j.result.Result; 4 | import org.eclipse.rdf4j.model.Resource; 5 | 6 | import java.io.BufferedWriter; 7 | import java.io.IOException; 8 | import java.util.Collection; 9 | import java.util.Map; 10 | 11 | public class EmptyLabelsResult extends Result>> { 12 | 13 | public EmptyLabelsResult(Map> data) { 14 | super(data); 15 | } 16 | 17 | @Override 18 | public void generateTextReport(BufferedWriter writer, ReportStyle style) throws IOException { 19 | if (style == ReportStyle.SHORT) { 20 | writer.write("count: " +occurrenceCount()+ "\n"); 21 | } 22 | else if (style == ReportStyle.EXTENSIVE) { 23 | generateExtensiveTextReport(writer); 24 | } 25 | } 26 | 27 | @Override 28 | public long occurrenceCount() { 29 | return getData().keySet().size(); 30 | } 31 | 32 | private void generateExtensiveTextReport(BufferedWriter writer) throws IOException { 33 | for (Resource resource : getData().keySet()) { 34 | writer.write(resource.stringValue() +": "+ getData().get(resource).toString() +"\n"); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/at/ac/univie/mminf/qskos4j/issues/UndocumentedConceptsTest.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.concepts.AuthoritativeConcepts; 4 | import at.ac.univie.mminf.qskos4j.issues.concepts.InvolvedConcepts; 5 | import at.ac.univie.mminf.qskos4j.issues.concepts.UndocumentedConcepts; 6 | import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; 7 | import junit.framework.Assert; 8 | import org.junit.Before; 9 | import org.junit.Test; 10 | import org.eclipse.rdf4j.RDF4JException; 11 | import org.eclipse.rdf4j.repository.RepositoryConnection; 12 | 13 | import java.io.IOException; 14 | 15 | 16 | public class UndocumentedConceptsTest { 17 | 18 | private UndocumentedConcepts undocumentedConcepts; 19 | private RepositoryConnection repCon; 20 | 21 | @Before 22 | public void setUp() throws RDF4JException, IOException { 23 | repCon = new RepositoryBuilder().setUpFromTestResource("documentedConcepts.rdf").getConnection(); 24 | undocumentedConcepts = new UndocumentedConcepts(new AuthoritativeConcepts(new InvolvedConcepts())); 25 | undocumentedConcepts.setRepositoryConnection(repCon); 26 | } 27 | 28 | @Test 29 | public void testAverageDocumentationCoverageRatio() throws RDF4JException { 30 | Assert.assertEquals(1, undocumentedConcepts.getResult().getData().size()); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/at/ac/univie/mminf/qskos4j/issues/HttpURIsTest.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.outlinks.HttpURIs; 4 | import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; 5 | import junit.framework.Assert; 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | import org.eclipse.rdf4j.RDF4JException; 9 | 10 | import java.io.IOException; 11 | 12 | /** 13 | * Created by christian 14 | * Date: 26.01.13 15 | * Time: 15:33 16 | */ 17 | public class HttpURIsTest { 18 | 19 | private HttpURIs httpURIs1, httpURIs2; 20 | 21 | @Before 22 | public void setUp() throws RDF4JException, IOException { 23 | httpURIs1 = new HttpURIs(); 24 | httpURIs1.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("concepts.rdf").getConnection()); 25 | 26 | httpURIs2 = new HttpURIs(); 27 | httpURIs2.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("resources.rdf").getConnection()); 28 | } 29 | 30 | @Test 31 | public void testConceptsHttpUriCount() throws RDF4JException { 32 | Assert.assertEquals(21, httpURIs1.getResult().getData().size()); 33 | } 34 | 35 | @Test 36 | public void testResourcesHttpUriCount() throws RDF4JException { 37 | Assert.assertEquals(8, httpURIs2.getResult().getData().size()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/result/ExtrapolatedCollectionResult.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.result; 2 | 3 | import java.io.BufferedWriter; 4 | import java.io.IOException; 5 | import java.util.Collection; 6 | 7 | public class ExtrapolatedCollectionResult extends CollectionResult { 8 | 9 | private Float subsetSize_percent; 10 | private Collection data; 11 | 12 | public ExtrapolatedCollectionResult(Collection data, Float subsetSize_percent) 13 | { 14 | super(data); 15 | this.data = data; 16 | this.subsetSize_percent = subsetSize_percent; 17 | } 18 | 19 | @Override 20 | protected void generateTextReport(BufferedWriter osw, ReportStyle style) throws IOException { 21 | switch (style) { 22 | case SHORT: 23 | osw.write(getShortReport()); 24 | break; 25 | 26 | case EXTENSIVE: 27 | super.generateTextReport(osw, style); 28 | break; 29 | } 30 | } 31 | 32 | private String getShortReport() { 33 | long elementCount = data.size(); 34 | 35 | StringBuilder report = new StringBuilder("count: "+elementCount); 36 | 37 | if (subsetSize_percent != null) { 38 | elementCount *= 100 / subsetSize_percent; 39 | report.append(", extrapolated: ").append(elementCount); 40 | } 41 | 42 | return report.toString(); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/at/ac/univie/mminf/qskos4j/issues/AmbiguousNotationReferencesTest.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.concepts.AuthoritativeConcepts; 4 | import at.ac.univie.mminf.qskos4j.issues.concepts.InvolvedConcepts; 5 | import at.ac.univie.mminf.qskos4j.issues.conceptscheme.AmbiguousNotationReferences; 6 | import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; 7 | import junit.framework.Assert; 8 | import org.eclipse.rdf4j.RDF4JException; 9 | import org.junit.Before; 10 | import org.junit.Test; 11 | 12 | import java.io.IOException; 13 | 14 | /** 15 | * Created by christian on 25.09.14. 16 | */ 17 | public class AmbiguousNotationReferencesTest { 18 | 19 | private AmbiguousNotationReferences ambiguousNotationReferences; 20 | 21 | @Before 22 | public void setUp() throws IOException, RDF4JException 23 | { 24 | ambiguousNotationReferences = new AmbiguousNotationReferences(new AuthoritativeConcepts(new InvolvedConcepts())); 25 | ambiguousNotationReferences.setRepositoryConnection( 26 | new RepositoryBuilder().setUpFromTestResource("ambiguousNotationReferences.rdf").getConnection()); 27 | } 28 | 29 | @Test 30 | public void mappingRelationsMisuseCount() throws RDF4JException { 31 | Assert.assertEquals(8, ambiguousNotationReferences.getResult().getData().size()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/issues/language/util/NoCommonLanguagesResult.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues.language.util; 2 | 3 | import at.ac.univie.mminf.qskos4j.result.Result; 4 | 5 | import java.io.BufferedWriter; 6 | import java.io.IOException; 7 | import java.util.Collection; 8 | 9 | public class NoCommonLanguagesResult extends Result> { 10 | 11 | public NoCommonLanguagesResult(Collection data) { 12 | super(data); 13 | } 14 | 15 | @Override 16 | protected void generateTextReport(BufferedWriter osw, ReportStyle style) throws IOException 17 | { 18 | switch (style) { 19 | case SHORT: 20 | if (getData().isEmpty()) { 21 | osw.write("Concepts are not described in a common language"); 22 | } 23 | else { 24 | osw.write("At least one common language for text literals of all concepts has been found"); 25 | } 26 | break; 27 | 28 | case EXTENSIVE: 29 | if (!getData().isEmpty()) { 30 | osw.write("Common language(s) for all concepts: " +getData().toString()); 31 | } 32 | break; 33 | } 34 | } 35 | 36 | @Override 37 | public boolean isProblematic() { 38 | return getData().isEmpty(); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/LabeledConcept.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues.labels.util; 2 | 3 | import org.eclipse.rdf4j.model.Literal; 4 | import org.eclipse.rdf4j.model.Resource; 5 | 6 | public class LabeledConcept { 7 | 8 | private Literal literal; 9 | private LabelType labelType; 10 | private Resource concept; 11 | 12 | public LabeledConcept(Resource concept, Literal literal, LabelType labelType) 13 | { 14 | this.concept = concept; 15 | this.literal = literal; 16 | this.labelType = labelType; 17 | } 18 | 19 | public Literal getLiteral() { 20 | return literal; 21 | } 22 | 23 | public Resource getConcept() { 24 | return concept; 25 | } 26 | 27 | public LabelType getLabelType() { 28 | return labelType; 29 | } 30 | 31 | @Override 32 | public String toString() { 33 | return concept +" ("+ literal +", "+ labelType +")"; 34 | } 35 | 36 | @Override 37 | public int hashCode() { 38 | return concept.hashCode() + literal.hashCode(); 39 | } 40 | 41 | @Override 42 | public boolean equals(Object obj) { 43 | if (!(obj instanceof LabeledConcept)) { 44 | return false; 45 | } 46 | 47 | LabeledConcept other = (LabeledConcept) obj; 48 | return concept.equals(other.concept) && literal.equals(other.literal) && labelType.equals(other.labelType); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/LabelConflict.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues.labels.util; 2 | 3 | import org.eclipse.rdf4j.model.Resource; 4 | 5 | import java.util.HashSet; 6 | import java.util.Set; 7 | 8 | 9 | public class LabelConflict { 10 | 11 | private Set conflicts; 12 | 13 | public LabelConflict() { 14 | conflicts = new HashSet(); 15 | } 16 | 17 | public LabelConflict(Set conflicts) 18 | { 19 | this.conflicts = conflicts; 20 | } 21 | 22 | public Set getAffectedResources() { 23 | Set affectedResources = new HashSet(); 24 | 25 | for (LabeledConcept labeledConcept : conflicts) { 26 | affectedResources.add(labeledConcept.getConcept()); 27 | } 28 | return affectedResources; 29 | } 30 | 31 | public void add(LabeledConcept labeledResource) { 32 | conflicts.add(labeledResource); 33 | } 34 | 35 | public Set getConflicts() { 36 | return conflicts; 37 | } 38 | 39 | @Override 40 | public String toString() { 41 | return conflicts.toString(); 42 | } 43 | 44 | @Override 45 | public int hashCode() { 46 | return conflicts.hashCode(); 47 | } 48 | 49 | @Override 50 | public boolean equals(Object obj) { 51 | return obj instanceof LabeledConcept && conflicts.equals(obj); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/at/ac/univie/mminf/qskos4j/issues/AuthoritativeConceptsTest.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.concepts.AuthoritativeConcepts; 4 | import at.ac.univie.mminf.qskos4j.issues.concepts.InvolvedConcepts; 5 | import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; 6 | import junit.framework.Assert; 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | import org.eclipse.rdf4j.RDF4JException; 10 | import org.eclipse.rdf4j.model.Resource; 11 | 12 | import java.io.IOException; 13 | import java.util.Collection; 14 | 15 | /** 16 | * Created by christian 17 | * Date: 26.01.13 18 | * Time: 12:57 19 | */ 20 | public class AuthoritativeConceptsTest { 21 | 22 | private AuthoritativeConcepts authoritativeConcepts; 23 | 24 | @Before 25 | public void setUp() throws RDF4JException, IOException { 26 | authoritativeConcepts = new AuthoritativeConcepts(new InvolvedConcepts()); 27 | authoritativeConcepts.setAuthResourceIdentifier("zbw.eu"); 28 | authoritativeConcepts.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("concepts.rdf").getConnection()); 29 | } 30 | 31 | @Test 32 | public void testAuthoritativeConceptsCount() throws RDF4JException 33 | { 34 | Collection authoritativeConceptValues = authoritativeConcepts.getResult().getData(); 35 | Assert.assertEquals(9, authoritativeConceptValues.size()); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/resources/missingTopConcepts.rdf: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /src/test/java/at/ac/univie/mminf/qskos4j/issues/NoCommonLanguagesTest.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.concepts.InvolvedConcepts; 4 | import at.ac.univie.mminf.qskos4j.issues.language.NoCommonLanguages; 5 | import at.ac.univie.mminf.qskos4j.issues.language.util.LanguageCoverage; 6 | import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; 7 | import junit.framework.Assert; 8 | import org.junit.Before; 9 | import org.junit.Test; 10 | import org.eclipse.rdf4j.RDF4JException; 11 | 12 | import java.io.IOException; 13 | 14 | public class NoCommonLanguagesTest { 15 | 16 | private NoCommonLanguages noCommonLanguages; 17 | 18 | @Before 19 | public void setUp() throws RDF4JException, IOException { 20 | noCommonLanguages = new NoCommonLanguages(new LanguageCoverage(new InvolvedConcepts())); 21 | } 22 | 23 | @Test 24 | public void oneCommonLang() throws RDF4JException, IOException { 25 | noCommonLanguages.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("commonlanguage_en.rdf").getConnection()); 26 | Assert.assertEquals(1, noCommonLanguages.getResult().getData().size()); 27 | } 28 | 29 | @Test 30 | public void noCommonLang() throws RDF4JException, IOException { 31 | noCommonLanguages.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("nocommonlanguage.rdf").getConnection()); 32 | Assert.assertEquals(0, noCommonLanguages.getResult().getData().size()); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/at/ac/univie/mminf/qskos4j/issues/UnidirectionallyRelatedConceptsTest.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.concepts.AuthoritativeConcepts; 4 | import at.ac.univie.mminf.qskos4j.issues.concepts.InvolvedConcepts; 5 | import at.ac.univie.mminf.qskos4j.issues.relations.UnidirectionallyRelatedConcepts; 6 | import at.ac.univie.mminf.qskos4j.util.Tuple; 7 | import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; 8 | import junit.framework.Assert; 9 | import org.junit.Before; 10 | import org.junit.Test; 11 | import org.eclipse.rdf4j.RDF4JException; 12 | import org.eclipse.rdf4j.model.Resource; 13 | 14 | import java.io.IOException; 15 | import java.util.Map; 16 | 17 | public class UnidirectionallyRelatedConceptsTest { 18 | 19 | private UnidirectionallyRelatedConcepts unidirectionallyRelatedConcepts; 20 | 21 | @Before 22 | public void setUp() throws RDF4JException, IOException { 23 | unidirectionallyRelatedConcepts = new UnidirectionallyRelatedConcepts(new AuthoritativeConcepts(new InvolvedConcepts())); 24 | unidirectionallyRelatedConcepts.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("omittedInverseRelations.rdf").getConnection()); 25 | } 26 | 27 | @Test 28 | public void testMissingInverseRelationsCount() throws RDF4JException { 29 | Map, String> missingRelations = unidirectionallyRelatedConcepts.getResult().getData(); 30 | Assert.assertEquals(8, missingRelations.size()); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/at/ac/univie/mminf/qskos4j/issues/UnprintableCharactersInLabelsTest.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.concepts.AuthoritativeConcepts; 4 | import at.ac.univie.mminf.qskos4j.issues.concepts.InvolvedConcepts; 5 | import at.ac.univie.mminf.qskos4j.issues.labels.UnprintableCharactersInLabels; 6 | import at.ac.univie.mminf.qskos4j.issues.labels.util.LabeledConcept; 7 | import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; 8 | import junit.framework.Assert; 9 | import org.eclipse.rdf4j.RDF4JException; 10 | import org.junit.Before; 11 | import org.junit.Test; 12 | 13 | import java.io.IOException; 14 | import java.util.Collection; 15 | 16 | public class UnprintableCharactersInLabelsTest { 17 | 18 | private UnprintableCharactersInLabels unprintableCharactersInLabels; 19 | 20 | @Before 21 | public void setUp() throws RDF4JException, IOException { 22 | unprintableCharactersInLabels = new UnprintableCharactersInLabels(new AuthoritativeConcepts(new InvolvedConcepts())); 23 | unprintableCharactersInLabels.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource( 24 | "labelsWithUnprintableCharacters.rdf").getConnection()); 25 | } 26 | 27 | @Test 28 | public void labelsWithUnprintableCharacters_count() throws RDF4JException { 29 | Collection invalidLabels = unprintableCharactersInLabels.getResult().getData(); 30 | 31 | Assert.assertEquals(2, invalidLabels.size()); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/progress/MonitoredIterator.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.progress; 2 | 3 | import java.util.Collection; 4 | import java.util.Iterator; 5 | 6 | public class MonitoredIterator implements Iterator { 7 | 8 | private Iterator delegate; 9 | private int totalSteps, currentStep; 10 | private IProgressMonitor progressMonitor; 11 | 12 | public MonitoredIterator( 13 | Collection iteratorProvider, 14 | IProgressMonitor progressMonitor) 15 | { 16 | this.delegate = iteratorProvider.iterator(); 17 | this.totalSteps = iteratorProvider.size(); 18 | this.progressMonitor = progressMonitor; 19 | 20 | currentStep = 0; 21 | progressMonitor.reset(); 22 | } 23 | 24 | public MonitoredIterator( 25 | Collection iteratorProvider, 26 | IProgressMonitor progressMonitor, 27 | String taskDescription) 28 | { 29 | this(iteratorProvider, progressMonitor); 30 | progressMonitor.setTaskDescription(taskDescription); 31 | } 32 | 33 | @Override 34 | public boolean hasNext() { 35 | boolean hasNext = delegate.hasNext(); 36 | 37 | if (!hasNext) { 38 | progressMonitor.onFinish(); 39 | } 40 | 41 | return hasNext; 42 | } 43 | 44 | @Override 45 | public T next() { 46 | if (progressMonitor != null) { 47 | progressMonitor.onUpdateProgress((float) currentStep / totalSteps); 48 | currentStep++; 49 | } 50 | 51 | return delegate.next(); 52 | } 53 | 54 | @Override 55 | public void remove() { 56 | delegate.remove(); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/progress/ConsoleProgressMonitor.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.progress; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | public class ConsoleProgressMonitor implements IProgressMonitor { 7 | 8 | private final Logger logger = LoggerFactory.getLogger(ConsoleProgressMonitor.class); 9 | private final int PROG_BAR_WIDTH = 50; 10 | 11 | private float prevProgressValue; 12 | 13 | @Override 14 | public void onUpdateProgress(float progress) { 15 | if (progress - prevProgressValue > .01) { 16 | int percentage = Math.round(progress * 100); 17 | System.out.print("|" +createBar(percentage)+ "|" +percentage+ "%\r"); 18 | 19 | prevProgressValue = progress; 20 | } 21 | } 22 | 23 | @Override 24 | public void onFinish() { 25 | System.out.print(produceBlanks(PROG_BAR_WIDTH + 10) + "\r"); 26 | } 27 | 28 | private String createBar(int percentage) { 29 | int numSegments = (int) Math.round((double) (PROG_BAR_WIDTH * percentage) / (double) 100); 30 | 31 | String bar = ""; 32 | for (int i = 0; i < numSegments; i++) { 33 | bar += "="; 34 | } 35 | bar += produceBlanks(PROG_BAR_WIDTH - numSegments); 36 | 37 | return bar; 38 | } 39 | 40 | private String produceBlanks(int numBlanks) { 41 | return new String(new char[numBlanks]).replace('\0', ' '); 42 | } 43 | 44 | @Override 45 | public void setTaskDescription(String description) { 46 | logger.info(description); 47 | } 48 | 49 | @Override 50 | public void reset() { 51 | prevProgressValue = 0; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/issues/count/Collections.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues.count; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.Issue; 4 | import at.ac.univie.mminf.qskos4j.result.NumberResult; 5 | import at.ac.univie.mminf.qskos4j.util.IssueDescriptor; 6 | import at.ac.univie.mminf.qskos4j.util.vocab.SkosOntology; 7 | import org.eclipse.rdf4j.RDF4JException; 8 | import org.eclipse.rdf4j.model.Statement; 9 | import org.eclipse.rdf4j.model.vocabulary.RDF; 10 | import org.eclipse.rdf4j.repository.RepositoryResult; 11 | 12 | /** 13 | * Created by christian 14 | * Date: 26.01.13 15 | * Time: 14:23 16 | * 17 | * Finds the number of SKOS Collections. 18 | */ 19 | public class Collections extends Issue> { 20 | 21 | public Collections() { 22 | super(new IssueDescriptor.Builder("cc", 23 | "Collection Count", 24 | "Counts the involved Collections", 25 | IssueDescriptor.IssueType.STATISTICAL).build() 26 | ); 27 | } 28 | 29 | @Override 30 | protected NumberResult invoke() throws RDF4JException { 31 | RepositoryResult result = repCon.getStatements(null, RDF.TYPE, SkosOntology.getInstance().getUri("Collection"), true); 32 | 33 | long collectionCount = 0; 34 | while (result.hasNext()) { 35 | result.next(); 36 | collectionCount++; 37 | } 38 | result.close(); 39 | 40 | return new NumberResult<>(collectionCount); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/at/ac/univie/mminf/qskos4j/issues/HierarchicalCyclesTest.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.cycles.HierarchicalCycles; 4 | import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; 5 | import junit.framework.Assert; 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | import org.eclipse.rdf4j.RDF4JException; 9 | 10 | import java.io.IOException; 11 | 12 | /** 13 | * Created by christian 14 | * Date: 27.01.13 15 | * Time: 00:20 16 | */ 17 | public class HierarchicalCyclesTest { 18 | 19 | private HierarchicalCycles hierarchicalCycles, hierarchicalCyclesForComponents; 20 | 21 | @Before 22 | public void setUp() throws RDF4JException, IOException { 23 | hierarchicalCycles = new HierarchicalCycles(new HierarchyGraphBuilder()); 24 | hierarchicalCycles.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("cycles.rdf").getConnection()); 25 | 26 | hierarchicalCyclesForComponents = new HierarchicalCycles(new HierarchyGraphBuilder()); 27 | hierarchicalCyclesForComponents.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("components_1.rdf").getConnection()); 28 | } 29 | 30 | @Test 31 | public void testCycleCount() throws RDF4JException { 32 | Assert.assertEquals(3, hierarchicalCycles.getResult().getData().size()); 33 | } 34 | 35 | @Test 36 | public void testComponentsCycleCount() throws RDF4JException { 37 | Assert.assertEquals(3, hierarchicalCyclesForComponents.getResult().getData().size()); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/test/resources/topConceptsHavingBroaderConcept.rdf: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /src/test/resources/labelMatch.rdf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | ABC 13 | 14 | 15 | 16 | 17 | AB 18 | 19 | 20 | 21 | 22 | AB 23 | 24 | 25 | 26 | 27 | AB 28 | 29 | 30 | 31 | 32 | 33 | ABC 34 | AB 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/util/Tuple.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.util; 2 | 3 | import java.util.*; 4 | 5 | public class Tuple { 6 | 7 | private List elements; 8 | 9 | public Tuple(List initElements) { 10 | elements = new ArrayList<>(); 11 | elements.addAll(initElements); 12 | } 13 | 14 | @Override 15 | public boolean equals(Object obj) { 16 | if (!(obj instanceof Tuple)) return false; 17 | 18 | Tuple other = (Tuple) obj; 19 | if (other.elements.size() != elements.size()) return false; 20 | 21 | for (T element : elements) { 22 | if (!other.elements.contains(element)) return false; 23 | } 24 | 25 | return true; 26 | } 27 | 28 | public int hashCode() { 29 | int hashCode = 0; 30 | for (T element : elements) { 31 | hashCode += element.hashCode(); 32 | } 33 | return hashCode; 34 | } 35 | 36 | @Override 37 | public String toString() { 38 | String ret = "("; 39 | 40 | Iterator it = elements.iterator(); 41 | while (it.hasNext()) { 42 | ret += it.next().toString() + (it.hasNext() ? ", " : ""); 43 | } 44 | 45 | ret += ")"; 46 | return ret; 47 | } 48 | 49 | public T get(int index) { 50 | return elements.get(index); 51 | } 52 | 53 | public T getFirst() { 54 | return elements.get(0); 55 | } 56 | 57 | public T getSecond() { 58 | return elements.get(1); 59 | } 60 | 61 | public List getElements() { 62 | return elements; 63 | } 64 | 65 | } -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/issues/conceptscheme/ConceptSchemeUtil.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues.conceptscheme; 2 | 3 | import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; 4 | import org.eclipse.rdf4j.RDF4JException; 5 | import org.eclipse.rdf4j.model.Resource; 6 | import org.eclipse.rdf4j.query.QueryLanguage; 7 | import org.eclipse.rdf4j.repository.RepositoryConnection; 8 | 9 | /** 10 | * Created by christian on 26.09.14. 11 | */ 12 | class ConceptSchemeUtil { 13 | 14 | public static boolean inSameConceptScheme(Resource concept, Resource otherConcept, RepositoryConnection repCon) 15 | throws RDF4JException 16 | { 17 | return repCon.prepareBooleanQuery(QueryLanguage.SPARQL, createInSchemeQuery(concept, otherConcept)).evaluate(); 18 | } 19 | 20 | private static String createInSchemeQuery(Resource... concepts) { 21 | String query = SparqlPrefix.SKOS + "ASK {"; 22 | 23 | for (Resource concept : concepts) { 24 | query += "<" +concept.stringValue()+ "> skos:inScheme ?conceptScheme ."; 25 | } 26 | 27 | return query + "}"; 28 | } 29 | 30 | public static boolean inNoConceptScheme(Resource concept, Resource otherConcept, RepositoryConnection repCon) 31 | throws RDF4JException 32 | { 33 | boolean conceptInScheme = repCon.prepareBooleanQuery(QueryLanguage.SPARQL, createInSchemeQuery(concept)).evaluate(); 34 | boolean otherConceptInScheme = repCon.prepareBooleanQuery(QueryLanguage.SPARQL, createInSchemeQuery(otherConcept)).evaluate(); 35 | 36 | return !conceptInScheme || !otherConceptInScheme; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/test/resources/documentedConcepts.rdf: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | note 11 | 12 | 13 | 14 | 15 | note 16 | changeNote 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | scopenote 27 | 28 | 29 | 30 | 31 | 32 | scopenote 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /src/test/java/at/ac/univie/mminf/qskos4j/issues/NonHttpResourcesTest.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.outlinks.HttpUriSchemeViolations; 4 | import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; 5 | import junit.framework.Assert; 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | import org.eclipse.rdf4j.RDF4JException; 9 | 10 | import java.io.IOException; 11 | 12 | /** 13 | * Created by christian 14 | * Date: 26.01.13 15 | * Time: 17:15 16 | */ 17 | public class NonHttpResourcesTest { 18 | 19 | private HttpUriSchemeViolations httpUriSchemeViolationsForConcepts, httpResourcesForUriSchemeViolations; 20 | 21 | @Before 22 | public void setUp() throws RDF4JException, IOException { 23 | httpUriSchemeViolationsForConcepts = new HttpUriSchemeViolations(); 24 | httpUriSchemeViolationsForConcepts.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("concepts.rdf").getConnection()); 25 | 26 | httpResourcesForUriSchemeViolations = new HttpUriSchemeViolations(); 27 | httpResourcesForUriSchemeViolations.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("resources.rdf").getConnection()); 28 | } 29 | 30 | 31 | @Test 32 | public void testConceptsNonHttpUriCount() throws RDF4JException { 33 | Assert.assertEquals(1, httpUriSchemeViolationsForConcepts.getResult().getData().size()); 34 | } 35 | 36 | @Test 37 | public void testResourcesNonHttpUriCount() throws RDF4JException { 38 | Assert.assertEquals(4, httpResourcesForUriSchemeViolations.getResult().getData().size()); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/issues/count/SemanticRelations.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues.count; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.Issue; 4 | import at.ac.univie.mminf.qskos4j.result.NumberResult; 5 | import at.ac.univie.mminf.qskos4j.util.IssueDescriptor; 6 | import at.ac.univie.mminf.qskos4j.util.vocab.SkosOntology; 7 | import org.eclipse.rdf4j.RDF4JException; 8 | import org.eclipse.rdf4j.model.Statement; 9 | import org.eclipse.rdf4j.repository.RepositoryResult; 10 | 11 | /** 12 | * Created by christian 13 | * Date: 26.01.13 14 | * Time: 14:01 15 | * 16 | * Finds the number of triples involving (subproperties of) skos:semanticRelation. 17 | */ 18 | public class SemanticRelations extends Issue> { 19 | 20 | public SemanticRelations() { 21 | super(new IssueDescriptor.Builder("sr", 22 | "Semantic Relations Count", 23 | "Counts the number of relations between concepts (skos:semanticRelation and subproperties thereof)", 24 | IssueDescriptor.IssueType.STATISTICAL).build() 25 | ); 26 | } 27 | 28 | @Override 29 | protected NumberResult invoke() throws RDF4JException { 30 | RepositoryResult result = repCon.getStatements( 31 | null, 32 | SkosOntology.getInstance().getUri("semanticRelation"), 33 | null, 34 | true); 35 | 36 | long semanticRelationsCount = 0; 37 | while (result.hasNext()) { 38 | result.next(); 39 | semanticRelationsCount++; 40 | } 41 | return new NumberResult(semanticRelationsCount); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/LabelConflictsResult.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues.labels.util; 2 | 3 | import at.ac.univie.mminf.qskos4j.result.CollectionResult; 4 | import org.eclipse.rdf4j.model.Resource; 5 | 6 | import java.io.BufferedWriter; 7 | import java.io.IOException; 8 | import java.util.Collection; 9 | import java.util.HashSet; 10 | 11 | public class LabelConflictsResult extends CollectionResult { 12 | 13 | public LabelConflictsResult(Collection data) { 14 | super(data); 15 | } 16 | 17 | @Override 18 | public void generateTextReport(BufferedWriter writer, ReportStyle style) throws IOException { 19 | if (style == ReportStyle.SHORT) { 20 | writer.write("count: " +getDistinctConcepts().size()+ "\n"); 21 | } 22 | else if (style == ReportStyle.EXTENSIVE) { 23 | generateExtensiveTextReport(writer); 24 | } 25 | } 26 | 27 | private Collection getDistinctConcepts() { 28 | Collection distinctConcepts = new HashSet(); 29 | 30 | for (LabelConflict labelConflict : getData()) { 31 | for (Resource labeledConcept : labelConflict.getAffectedResources()) { 32 | distinctConcepts.add(labeledConcept); 33 | } 34 | } 35 | 36 | return distinctConcepts; 37 | } 38 | 39 | private void generateExtensiveTextReport(BufferedWriter writer) throws IOException { 40 | for (LabelConflict labelConflict : getData()) { 41 | writer.write(labelConflict.toString()); 42 | writer.write("\n"); 43 | } 44 | } 45 | 46 | } -------------------------------------------------------------------------------- /src/test/resources/exactVsAssociativeMappingClashes.rdf: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /src/test/java/at/ac/univie/mminf/qskos4j/issues/InvolvedConceptsTest.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.concepts.InvolvedConcepts; 4 | import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; 5 | import junit.framework.Assert; 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | import org.eclipse.rdf4j.RDF4JException; 9 | import org.eclipse.rdf4j.model.Resource; 10 | 11 | import java.io.IOException; 12 | import java.util.Collection; 13 | 14 | public class InvolvedConceptsTest { 15 | 16 | private InvolvedConcepts involvedConceptsForConcepts, involvedConceptsForComponents; 17 | 18 | @Before 19 | public void setUp() throws RDF4JException, IOException { 20 | involvedConceptsForConcepts = new InvolvedConcepts(); 21 | involvedConceptsForConcepts.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("concepts.rdf").getConnection()); 22 | 23 | involvedConceptsForComponents = new InvolvedConcepts(); 24 | involvedConceptsForComponents.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("components_1.rdf").getConnection()); 25 | } 26 | 27 | @Test 28 | public void testConceptCount_1() throws RDF4JException 29 | { 30 | Collection involvedConceptValues = involvedConceptsForConcepts.getResult().getData(); 31 | Assert.assertEquals(10, involvedConceptValues.size()); 32 | } 33 | 34 | @Test 35 | public void testConceptCount_2() throws RDF4JException 36 | { 37 | Collection involvedConceptValues = involvedConceptsForComponents.getResult().getData(); 38 | Assert.assertEquals(21, involvedConceptValues.size()); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/result/ResourceCollectionsResult.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.result; 2 | 3 | import org.eclipse.rdf4j.model.Resource; 4 | import org.eclipse.rdf4j.model.Value; 5 | 6 | import java.io.BufferedWriter; 7 | import java.io.IOException; 8 | import java.util.Collection; 9 | import java.util.Iterator; 10 | 11 | public class ResourceCollectionsResult extends CollectionResult> { 12 | 13 | private String valueSetName; 14 | 15 | public ResourceCollectionsResult(Collection> data, String valueSetName) { 16 | super(data); 17 | this.valueSetName = valueSetName; 18 | } 19 | 20 | @Override 21 | public void generateTextReport(BufferedWriter osw, ReportStyle style) throws IOException { 22 | StringBuilder report = new StringBuilder(); 23 | long compCount = 1; 24 | 25 | if (style == ReportStyle.SHORT) { 26 | report.append("count: ").append(getData().size()).append("\n"); 27 | } 28 | 29 | Iterator> componentIt = getData().iterator(); 30 | while (componentIt.hasNext()) { 31 | Collection component = componentIt.next(); 32 | 33 | report.append(valueSetName +" ").append(compCount).append(", size: ").append(component.size()); 34 | if (style == ReportStyle.EXTENSIVE) { 35 | for (Value value : component) { 36 | report.append("\n\t").append(value.toString()); 37 | } 38 | } 39 | compCount++; 40 | 41 | if (componentIt.hasNext()) report.append("\n"); 42 | } 43 | 44 | osw.write(report.toString()); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/issues/relations/UnidirectionallyRelatedConceptsResult.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues.relations; 2 | 3 | import at.ac.univie.mminf.qskos4j.result.CollectionResult; 4 | import at.ac.univie.mminf.qskos4j.result.Result; 5 | import at.ac.univie.mminf.qskos4j.util.Tuple; 6 | import org.eclipse.rdf4j.model.Resource; 7 | 8 | import java.io.BufferedWriter; 9 | import java.io.IOException; 10 | import java.util.Map; 11 | 12 | public class UnidirectionallyRelatedConceptsResult extends Result, String>> { 13 | 14 | protected UnidirectionallyRelatedConceptsResult(Map, String> data) { 15 | super(data); 16 | } 17 | 18 | @Override 19 | protected void generateTextReport(BufferedWriter writer, ReportStyle style) throws IOException 20 | { 21 | switch (style) { 22 | case SHORT: 23 | new CollectionResult>(getData().keySet()).generateReport(writer, ReportFormat.TXT, ReportStyle.SHORT); 24 | break; 25 | 26 | case EXTENSIVE: 27 | writer.write(generateExtensiveReport()); 28 | break; 29 | } 30 | } 31 | 32 | private String generateExtensiveReport() 33 | { 34 | StringBuilder extensiveReport = new StringBuilder(); 35 | 36 | for (Tuple concepts : getData().keySet()) { 37 | extensiveReport.append("concepts: ").append(concepts.toString()).append(", related by: '").append(getData().get(concepts)).append("'\n"); 38 | } 39 | 40 | return extensiveReport.toString(); 41 | } 42 | 43 | @Override 44 | public long occurrenceCount() { 45 | return getData().size(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/at/ac/univie/mminf/qskos4j/cmd/IssueInvocationTest.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.cmd; 2 | 3 | import java.io.File; 4 | import java.net.URL; 5 | import java.nio.file.Files; 6 | 7 | import junit.framework.Assert; 8 | 9 | import org.junit.Test; 10 | 11 | import at.ac.univie.mminf.qskos4j.util.IssueDescriptor; 12 | 13 | public class IssueInvocationTest { 14 | 15 | @Test 16 | public void testAllIssuesInvocation() { 17 | for (final IssueDescriptor.IssueType issueType : IssueDescriptor.IssueType 18 | .values()) { 19 | invokeOnCmdLine(issueType); 20 | } 21 | } 22 | 23 | private void invokeOnCmdLine(final IssueDescriptor.IssueType issueType) { 24 | final String command = findCommand(issueType); 25 | final String testFileName = getTestFileName(); 26 | try { 27 | final File outputDirectory = Files.createTempFile("temp", "bla") 28 | .toFile(); 29 | outputDirectory.setExecutable(true, true); 30 | outputDirectory.setWritable(true, true); 31 | outputDirectory.setReadable(true, true); 32 | new VocEvaluate(new String[] { command, "-o", 33 | outputDirectory.getCanonicalPath(), testFileName }); 34 | } catch (final Exception e) { 35 | Assert.fail(e.getMessage() + ", command: " + command); 36 | } 37 | } 38 | 39 | private String findCommand(final IssueDescriptor.IssueType type) { 40 | switch (type) { 41 | case ANALYTICAL: 42 | return VocEvaluate.CMD_NAME_ANALYZE; 43 | 44 | case STATISTICAL: 45 | return VocEvaluate.CMD_NAME_SUMMARIZE; 46 | } 47 | 48 | throw new IllegalStateException("unknown measure type"); 49 | } 50 | 51 | private String getTestFileName() { 52 | final URL conceptsUrl = getClass().getResource("/nocontent.rdf"); 53 | return conceptsUrl.getFile(); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/test/resources/resources.rdf: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | test 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /src/test/java/at/ac/univie/mminf/qskos4j/issues/UndefinedSkosResourcesTest.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.skosintegrity.UndefinedSkosResources; 4 | import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; 5 | import junit.framework.Assert; 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | import org.eclipse.rdf4j.RDF4JException; 9 | import org.eclipse.rdf4j.model.IRI; 10 | 11 | import java.io.IOException; 12 | import java.util.Collection; 13 | 14 | 15 | public class UndefinedSkosResourcesTest { 16 | 17 | private UndefinedSkosResources undefinedSkosResourcesInConcepts, undefinedSkosResourcesInDeprecatedAndIllegal; 18 | 19 | @Before 20 | public void setUp() throws RDF4JException, IOException { 21 | undefinedSkosResourcesInConcepts = new UndefinedSkosResources(); 22 | undefinedSkosResourcesInConcepts.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("concepts.rdf").getConnection()); 23 | undefinedSkosResourcesInDeprecatedAndIllegal = new UndefinedSkosResources(); 24 | undefinedSkosResourcesInDeprecatedAndIllegal.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("deprecatedAndIllegalTerms.rdf").getConnection()); 25 | } 26 | 27 | @Test 28 | public void testUndefinedSkosResourcesCount_1() throws RDF4JException { 29 | Collection undefRes = undefinedSkosResourcesInConcepts.getResult().getData(); 30 | Assert.assertEquals(3, undefRes.size()); 31 | } 32 | 33 | @Test 34 | public void testUndefinedSkosResourcesCount_2() throws RDF4JException { 35 | Collection undefRes = undefinedSkosResourcesInDeprecatedAndIllegal.getResult().getData(); 36 | Assert.assertEquals(12, undefRes.size()); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/issues/concepts/InvolvedConcepts.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues.concepts; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.Issue; 4 | import at.ac.univie.mminf.qskos4j.result.CollectionResult; 5 | import at.ac.univie.mminf.qskos4j.util.IssueDescriptor; 6 | import at.ac.univie.mminf.qskos4j.util.vocab.SkosOntology; 7 | import org.eclipse.rdf4j.RDF4JException; 8 | import org.eclipse.rdf4j.model.Resource; 9 | import org.eclipse.rdf4j.model.Statement; 10 | import org.eclipse.rdf4j.model.vocabulary.RDF; 11 | import org.eclipse.rdf4j.repository.RepositoryResult; 12 | 13 | import java.util.ArrayList; 14 | import java.util.Collection; 15 | 16 | /** 17 | * Finds all SKOS Concepts involved in the vocabulary. 18 | */ 19 | public class InvolvedConcepts extends Issue> { 20 | 21 | public InvolvedConcepts() { 22 | super(new IssueDescriptor.Builder("c", 23 | "All Concepts", 24 | "Finds all SKOS concepts involved in the vocabulary", 25 | IssueDescriptor.IssueType.STATISTICAL).build() 26 | ); 27 | } 28 | 29 | @Override 30 | protected CollectionResult invoke() throws RDF4JException { 31 | RepositoryResult result = repCon.getStatements( 32 | null, 33 | RDF.TYPE, 34 | SkosOntology.getInstance().getUri("Concept"), 35 | true); 36 | 37 | Collection involvedConcepts = new ArrayList(); 38 | while (result.hasNext()) { 39 | involvedConcepts.add(result.next().getSubject()); 40 | } 41 | 42 | return new CollectionResult<>(involvedConcepts); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/test/resources/aggregations.rdf: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /src/test/resources/cycles.rdf: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /src/test/resources/skosxl.rdf: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | ; 9 | ; 10 | ; 11 | 12 | adoration 13 | 14 | 15 | 16 | 17 | love 18 | 19 | 20 | 21 | 22 | adoration 23 | 24 | 25 | 26 | 27 | luv 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | anderes Konzept 38 | 39 | 40 | 41 | luv 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /src/test/java/at/ac/univie/mminf/qskos4j/issues/DisjointLabelsViolationsTest.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.labels.DisjointLabelsViolations; 4 | import at.ac.univie.mminf.qskos4j.issues.labels.util.LabelConflict; 5 | import at.ac.univie.mminf.qskos4j.issues.labels.util.ResourceLabelsCollector; 6 | import at.ac.univie.mminf.qskos4j.issues.labels.util.UriSuffixFinder; 7 | import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; 8 | import org.junit.Assert; 9 | import org.junit.Before; 10 | import org.junit.Test; 11 | import org.eclipse.rdf4j.RDF4JException; 12 | 13 | import java.io.IOException; 14 | import java.util.Collection; 15 | 16 | public class DisjointLabelsViolationsTest { 17 | 18 | private DisjointLabelsViolations disjointLabelsViolations; 19 | 20 | @Before 21 | public void setUp() throws RDF4JException, IOException { 22 | disjointLabelsViolations = new DisjointLabelsViolations(new ResourceLabelsCollector()); 23 | disjointLabelsViolations.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("ambiguousLabels.rdf").getConnection()); 24 | } 25 | 26 | @Test 27 | public void testDisjointLabels() throws RDF4JException { 28 | Collection ambiguousResources = disjointLabelsViolations.getResult().getData(); 29 | 30 | Assert.assertTrue(UriSuffixFinder.isPartOfConflict(ambiguousResources, "conceptD")); 31 | Assert.assertTrue(UriSuffixFinder.isPartOfConflict(ambiguousResources, "conceptF")); 32 | 33 | Assert.assertFalse(UriSuffixFinder.isPartOfConflict(ambiguousResources, "conceptE")); 34 | Assert.assertFalse(UriSuffixFinder.isPartOfConflict(ambiguousResources, "conceptG")); 35 | Assert.assertFalse(UriSuffixFinder.isPartOfConflict(ambiguousResources, "conceptI")); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/at/ac/univie/mminf/qskos4j/issues/OrphanConceptsTest.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.concepts.InvolvedConcepts; 4 | import at.ac.univie.mminf.qskos4j.issues.concepts.OrphanConcepts; 5 | import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; 6 | import junit.framework.Assert; 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | import org.eclipse.rdf4j.RDF4JException; 10 | import org.eclipse.rdf4j.model.Resource; 11 | 12 | import java.io.IOException; 13 | import java.util.Collection; 14 | 15 | /** 16 | * Created by christian 17 | * Date: 26.01.13 18 | * Time: 13:48 19 | */ 20 | public class OrphanConceptsTest { 21 | 22 | private OrphanConcepts orphanConceptsForConcepts, orphanConceptsForComponents; 23 | 24 | @Before 25 | public void setUp() throws RDF4JException, IOException { 26 | orphanConceptsForConcepts = new OrphanConcepts(new InvolvedConcepts()); 27 | orphanConceptsForConcepts.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("concepts.rdf").getConnection()); 28 | 29 | orphanConceptsForComponents = new OrphanConcepts(new InvolvedConcepts()); 30 | orphanConceptsForComponents.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("components_1.rdf").getConnection()); 31 | } 32 | 33 | @Test 34 | public void testConceptsLooseConceptCount() throws RDF4JException { 35 | Collection orphanConceptValues = orphanConceptsForConcepts.getResult().getData(); 36 | Assert.assertEquals(7, orphanConceptValues.size()); 37 | } 38 | 39 | @Test 40 | public void testComponentsLooseConceptCount() throws RDF4JException { 41 | Collection orphanConceptValues = orphanConceptsForComponents.getResult().getData(); 42 | Assert.assertEquals(2, orphanConceptValues.size()); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/issues/count/AggregationRelations.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues.count; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.Issue; 4 | import at.ac.univie.mminf.qskos4j.result.NumberResult; 5 | import at.ac.univie.mminf.qskos4j.util.IssueDescriptor; 6 | import at.ac.univie.mminf.qskos4j.util.TupleQueryResultUtil; 7 | import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; 8 | import org.eclipse.rdf4j.RDF4JException; 9 | import org.eclipse.rdf4j.query.QueryLanguage; 10 | import org.eclipse.rdf4j.query.TupleQuery; 11 | 12 | /** 13 | * Created by christian 14 | * Date: 26.01.13 15 | * Time: 14:23 16 | * 17 | * Finds the number of triples that assign concepts to concept schemes or lists. 18 | */ 19 | public class AggregationRelations extends Issue> { 20 | 21 | private final String AGGREGATION_RELATIONS = 22 | "skos:topConceptOf, skos:hasTopConcept, skos:inScheme, skos:member, skos:memberList"; 23 | 24 | public AggregationRelations() { 25 | super(new IssueDescriptor.Builder("ar", 26 | "Aggregation Relations Count", 27 | "Counts the statements relating resources to ConceptSchemes or Collections", 28 | IssueDescriptor.IssueType.STATISTICAL).build() 29 | ); 30 | } 31 | 32 | @Override 33 | protected NumberResult invoke() throws RDF4JException { 34 | TupleQuery query = repCon.prepareTupleQuery(QueryLanguage.SPARQL, createAggregationRelationsQuery()); 35 | return new NumberResult<>(TupleQueryResultUtil.countResults(query.evaluate())); 36 | } 37 | 38 | private String createAggregationRelationsQuery() { 39 | return SparqlPrefix.SKOS +" "+ SparqlPrefix.RDFS + 40 | "SELECT * WHERE {" + 41 | "{" + 42 | "?res1 ?aggregationRelation ?res2 ." + 43 | "}" + 44 | "FILTER (?aggregationRelation IN ("+ AGGREGATION_RELATIONS+ "))" + 45 | "}"; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/at/ac/univie/mminf/qskos4j/issues/InconsistentPrefLabelsTest.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.labels.InconsistentPrefLabels; 4 | import at.ac.univie.mminf.qskos4j.issues.labels.util.LabelConflict; 5 | import at.ac.univie.mminf.qskos4j.issues.labels.util.ResourceLabelsCollector; 6 | import at.ac.univie.mminf.qskos4j.issues.labels.util.UriSuffixFinder; 7 | import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; 8 | import org.junit.Assert; 9 | import org.junit.Before; 10 | import org.junit.Test; 11 | import org.eclipse.rdf4j.RDF4JException; 12 | 13 | import java.io.IOException; 14 | import java.util.Collection; 15 | 16 | public class InconsistentPrefLabelsTest { 17 | 18 | private InconsistentPrefLabels inconsistentPrefLabels; 19 | 20 | @Before 21 | public void setUp() throws RDF4JException, IOException { 22 | inconsistentPrefLabels = new InconsistentPrefLabels(new ResourceLabelsCollector()); 23 | inconsistentPrefLabels.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("ambiguousLabels.rdf").getConnection()); 24 | } 25 | 26 | @Test 27 | public void testUniquePrefLabels() throws RDF4JException { 28 | Collection ambiguousResources = inconsistentPrefLabels.getResult().getData(); 29 | 30 | Assert.assertTrue(UriSuffixFinder.isPartOfConflict(ambiguousResources, "conceptA")); 31 | Assert.assertTrue(UriSuffixFinder.isPartOfConflict(ambiguousResources, "conceptA2")); 32 | Assert.assertTrue(UriSuffixFinder.isPartOfConflict(ambiguousResources, "conceptA3")); 33 | Assert.assertTrue(UriSuffixFinder.isPartOfConflict(ambiguousResources, "conceptA4")); 34 | Assert.assertFalse(UriSuffixFinder.isPartOfConflict(ambiguousResources, "conceptB")); 35 | Assert.assertFalse(UriSuffixFinder.isPartOfConflict(ambiguousResources, "conceptC")); 36 | Assert.assertFalse(UriSuffixFinder.isPartOfConflict(ambiguousResources, "conceptG")); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/at/ac/univie/mminf/qskos4j/issues/MissingOutLinksTest.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.concepts.AuthoritativeConcepts; 4 | import at.ac.univie.mminf.qskos4j.issues.concepts.InvolvedConcepts; 5 | import at.ac.univie.mminf.qskos4j.issues.outlinks.MissingOutLinks; 6 | import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; 7 | import junit.framework.Assert; 8 | import org.junit.Before; 9 | import org.junit.Test; 10 | import org.eclipse.rdf4j.RDF4JException; 11 | 12 | import java.io.IOException; 13 | 14 | /** 15 | * Created by christian 16 | * Date: 26.01.13 17 | * Time: 16:16 18 | */ 19 | public class MissingOutLinksTest { 20 | 21 | private InvolvedConcepts involvedConceptsForComponents; 22 | private MissingOutLinks missingOutLinksForComponents, missingOutLinksForConcepts; 23 | 24 | @Before 25 | public void setUp() throws RDF4JException, IOException { 26 | involvedConceptsForComponents = new InvolvedConcepts(); 27 | missingOutLinksForComponents = new MissingOutLinks(new AuthoritativeConcepts(involvedConceptsForComponents)); 28 | missingOutLinksForComponents.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("components_1.rdf").getConnection()); 29 | 30 | missingOutLinksForConcepts = new MissingOutLinks(new AuthoritativeConcepts(new InvolvedConcepts())); 31 | missingOutLinksForConcepts.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("concepts.rdf").getConnection()); 32 | } 33 | 34 | @Test 35 | public void testComponentsMissingOutLinkCount() throws RDF4JException { 36 | Assert.assertEquals(involvedConceptsForComponents.getResult().getData().size(), 37 | missingOutLinksForComponents.getResult().getData().size()); 38 | } 39 | 40 | @Test 41 | public void testConceptsMissingOutLinkCount() throws RDF4JException { 42 | Assert.assertEquals(7, missingOutLinksForConcepts.getResult().getData().size()); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/util/graph/GraphExporter.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.util.graph; 2 | 3 | import org.jgrapht.DirectedGraph; 4 | import org.jgrapht.Graph; 5 | import org.jgrapht.ext.DOTExporter; 6 | import org.jgrapht.ext.IntegerNameProvider; 7 | import org.jgrapht.ext.StringEdgeNameProvider; 8 | import org.jgrapht.ext.VertexNameProvider; 9 | import org.jgrapht.graph.DirectedSubgraph; 10 | import org.eclipse.rdf4j.model.Resource; 11 | 12 | import java.io.StringWriter; 13 | import java.util.Collection; 14 | import java.util.HashSet; 15 | import java.util.Set; 16 | 17 | public class GraphExporter { 18 | 19 | private DirectedGraph graph; 20 | 21 | public GraphExporter(DirectedGraph graph) { 22 | this.graph = graph; 23 | } 24 | 25 | public Collection exportDotGraphs(Collection> vertexSubSets) { 26 | Set dotGraphs = new HashSet(); 27 | 28 | for (Collection component : vertexSubSets) { 29 | Graph componentGraph = getGraphForComponent(component); 30 | dotGraphs.add(exportGraph(componentGraph)); 31 | } 32 | 33 | return dotGraphs; 34 | } 35 | 36 | private Graph getGraphForComponent(Collection component) 37 | { 38 | return new DirectedSubgraph(graph, new HashSet(component), null); 39 | } 40 | 41 | private String exportGraph(Graph componentGraph) { 42 | StringWriter outputWriter = new StringWriter(); 43 | 44 | new DOTExporter( 45 | new IntegerNameProvider(), 46 | new IRIVertexNameProvider(), 47 | new StringEdgeNameProvider() 48 | ).export(outputWriter, componentGraph); 49 | 50 | return outputWriter.toString(); 51 | } 52 | 53 | private class IRIVertexNameProvider implements VertexNameProvider 54 | { 55 | @Override 56 | public String getVertexName(Resource vertex) { 57 | return vertex.stringValue(); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/issues/language/IncompleteLangCovResult.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues.language; 2 | 3 | import at.ac.univie.mminf.qskos4j.result.CollectionResult; 4 | import at.ac.univie.mminf.qskos4j.result.Result; 5 | import org.eclipse.rdf4j.model.Resource; 6 | 7 | import java.io.BufferedWriter; 8 | import java.io.IOException; 9 | import java.util.Collection; 10 | import java.util.Iterator; 11 | import java.util.Map; 12 | import java.util.Map.Entry; 13 | 14 | public class IncompleteLangCovResult extends Result>> { 15 | 16 | IncompleteLangCovResult(Map> data) { 17 | super(data); 18 | } 19 | 20 | @Override 21 | protected void generateTextReport(BufferedWriter writer, ReportStyle style) throws IOException 22 | { 23 | switch (style) { 24 | case SHORT: 25 | new CollectionResult(getData().keySet()).generateReport(writer, ReportFormat.TXT, ReportStyle.SHORT); 26 | break; 27 | 28 | case EXTENSIVE: 29 | writer.write(generateExtensiveTextReport()); 30 | break; 31 | } 32 | 33 | } 34 | 35 | private String generateExtensiveTextReport() { 36 | StringBuilder extensiveReport = new StringBuilder(); 37 | 38 | Iterator>> entryIt = getData().entrySet().iterator(); 39 | while (entryIt.hasNext()) { 40 | Entry> entry = entryIt.next(); 41 | extensiveReport.append("concept: '") 42 | .append(entry.getKey().stringValue()) 43 | .append("', not covered languages: ") 44 | .append(entry.getValue().toString()) 45 | .append(entryIt.hasNext() ? "\n" : ""); 46 | } 47 | 48 | return extensiveReport.toString(); 49 | } 50 | 51 | @Override 52 | public long occurrenceCount() { 53 | return getData().size(); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/issues/language/NoCommonLanguages.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues.language; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.Issue; 4 | import at.ac.univie.mminf.qskos4j.issues.language.util.NoCommonLanguagesResult; 5 | import at.ac.univie.mminf.qskos4j.issues.language.util.LanguageCoverage; 6 | import at.ac.univie.mminf.qskos4j.util.IssueDescriptor; 7 | import org.eclipse.rdf4j.RDF4JException; 8 | import org.eclipse.rdf4j.model.Resource; 9 | 10 | import java.util.Collection; 11 | import java.util.HashSet; 12 | import java.util.Map; 13 | import java.util.Set; 14 | 15 | public class NoCommonLanguages extends Issue { 16 | 17 | private LanguageCoverage languageCoverage; 18 | private Set commonLanguages; 19 | 20 | public NoCommonLanguages(LanguageCoverage languageCoverage) { 21 | super(new IssueDescriptor.Builder( 22 | "ncl", 23 | "No Common Languages", 24 | "Checks for common languages in all concept literals", 25 | IssueDescriptor.IssueType.ANALYTICAL) 26 | .dependentIssue(languageCoverage) 27 | .build()); 28 | 29 | this.languageCoverage = languageCoverage; 30 | } 31 | 32 | @Override 33 | protected NoCommonLanguagesResult invoke() throws RDF4JException { 34 | Map> langCovData = languageCoverage.getResult().getData(); 35 | commonLanguages = new HashSet<>(); 36 | 37 | if (!langCovData.isEmpty()) { 38 | for (Collection languages : langCovData.values()) { 39 | commonLanguages.addAll(languages); 40 | } 41 | 42 | findCommonLanguages(); 43 | } 44 | 45 | return new NoCommonLanguagesResult(commonLanguages); 46 | } 47 | 48 | private void findCommonLanguages() throws RDF4JException { 49 | for (Map.Entry> entry : languageCoverage.getResult().getData().entrySet()) { 50 | commonLanguages.retainAll(entry.getValue()); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/issues/language/OmittedOrInvalidLanguageTagsResult.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues.language; 2 | 3 | import at.ac.univie.mminf.qskos4j.result.CollectionResult; 4 | import at.ac.univie.mminf.qskos4j.result.Result; 5 | import org.eclipse.rdf4j.model.Literal; 6 | import org.eclipse.rdf4j.model.Resource; 7 | 8 | import java.io.BufferedWriter; 9 | import java.io.IOException; 10 | import java.util.Collection; 11 | import java.util.Iterator; 12 | import java.util.Map; 13 | 14 | public class OmittedOrInvalidLanguageTagsResult extends Result>> { 15 | 16 | OmittedOrInvalidLanguageTagsResult(Map> data) { 17 | super(data); 18 | } 19 | 20 | @Override 21 | protected void generateTextReport(BufferedWriter writer, ReportStyle style) throws IOException 22 | { 23 | switch (style) { 24 | case SHORT: 25 | new CollectionResult(getData().keySet()).generateReport(writer, ReportFormat.TXT, ReportStyle.SHORT); 26 | break; 27 | 28 | case EXTENSIVE: 29 | writer.write(generateExtensiveTextReport()); 30 | break; 31 | } 32 | 33 | } 34 | 35 | private String generateExtensiveTextReport() { 36 | StringBuilder extensiveReport = new StringBuilder(); 37 | 38 | Iterator>> entryIt = getData().entrySet().iterator(); 39 | while (entryIt.hasNext()) { 40 | Map.Entry> entry = entryIt.next(); 41 | extensiveReport.append("concept: '") 42 | .append(entry.getKey().stringValue()) 43 | .append("', literals with no or invalid language tags: ") 44 | .append(entry.getValue().toString()) 45 | .append(entryIt.hasNext() ? "\n" : ""); 46 | } 47 | 48 | return extensiveReport.toString(); 49 | } 50 | 51 | @Override 52 | public long occurrenceCount() { 53 | return getData().size(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/at/ac/univie/mminf/qskos4j/issues/DisconnectedConceptClustersTest.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.clusters.DisconnectedConceptClusters; 4 | import at.ac.univie.mminf.qskos4j.issues.concepts.InvolvedConcepts; 5 | import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; 6 | import junit.framework.Assert; 7 | import org.junit.Test; 8 | import org.eclipse.rdf4j.RDF4JException; 9 | import org.eclipse.rdf4j.model.Resource; 10 | 11 | import java.io.IOException; 12 | import java.util.Collection; 13 | 14 | public class DisconnectedConceptClustersTest { 15 | 16 | private InvolvedConcepts involvedConcepts; 17 | private DisconnectedConceptClusters disconnectedConceptClusters; 18 | 19 | @Test 20 | public void testComponentCount() throws RDF4JException, IOException { 21 | setUp("components_1.rdf"); 22 | 23 | long conceptCount = involvedConcepts.getResult().getData().size(); 24 | Collection> components = disconnectedConceptClusters.getResult().getData(); 25 | 26 | Assert.assertEquals(7, components.size()); 27 | Assert.assertTrue(getVertexCount(components) <= conceptCount); 28 | } 29 | 30 | private void setUp(String filename) throws IOException, RDF4JException { 31 | involvedConcepts = new InvolvedConcepts(); 32 | disconnectedConceptClusters = new DisconnectedConceptClusters(involvedConcepts); 33 | disconnectedConceptClusters.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource(filename).getConnection()); 34 | } 35 | 36 | private long getVertexCount(Collection> components) { 37 | long ret = 0; 38 | 39 | for (Collection component : components) { 40 | ret += component.size(); 41 | } 42 | 43 | return ret; 44 | } 45 | 46 | @Test 47 | public void testComponents_ok() throws RDF4JException, IOException { 48 | setUp("components_2.rdf"); 49 | Assert.assertFalse(disconnectedConceptClusters.getResult().isProblematic()); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/test/resources/solitaryTransitiveRelations.rdf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/LabelType.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues.labels.util; 2 | 3 | import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; 4 | import org.eclipse.rdf4j.model.IRI; 5 | 6 | import java.util.ArrayList; 7 | import java.util.Collection; 8 | 9 | public enum LabelType { 10 | 11 | PREF_LABEL(SparqlPrefix.SKOS.getNameSpace() + "prefLabel", true, "skos:prefLabel"), 12 | ALT_LABEL(SparqlPrefix.SKOS.getNameSpace() + "altLabel", true, "skos:altLabel"), 13 | HIDDEN_LABEL(SparqlPrefix.SKOS.getNameSpace() + "hiddenLabel", true, "skos:hiddenLabel"), 14 | DCTERMS_TITLE(SparqlPrefix.DCTERMS.getNameSpace() + "title", false, "dcterms:title"), 15 | DC_TITLE(SparqlPrefix.DC.getNameSpace() + "title", false, "dc:title"), 16 | LABEL(SparqlPrefix.RDFS.getNameSpace() + "label", false, "rdfs:label"), 17 | UNKNOWN(null, false, "null"); 18 | 19 | private String predicate; 20 | private boolean definedInSkos; 21 | private String usualPrefixedDisplayUri; 22 | 23 | private LabelType(String predicate, boolean definedInSkos, String usualPrefixedDisplayUri) { 24 | this.predicate = predicate; 25 | this.definedInSkos = definedInSkos; 26 | this.usualPrefixedDisplayUri = usualPrefixedDisplayUri; 27 | } 28 | 29 | public String getPredicate() { 30 | return predicate; 31 | } 32 | 33 | public boolean isDefinedInSkos() { 34 | return definedInSkos; 35 | } 36 | 37 | public String getUsualPrefixedDisplayUri() { 38 | return usualPrefixedDisplayUri; 39 | } 40 | 41 | public static LabelType getFromUri(IRI uri) { 42 | for (LabelType labelType : values()) { 43 | if (uri.stringValue().contains(labelType.predicate)) return labelType; 44 | } 45 | return UNKNOWN; 46 | } 47 | 48 | public static Collection getSkosLabels() { 49 | Collection skosLabels = new ArrayList(); 50 | 51 | for (LabelType labelType : values()) { 52 | if (labelType.definedInSkos) skosLabels.add(labelType); 53 | } 54 | 55 | return skosLabels; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/test/resources/labelsWithUnprintableCharacters.rdf: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | not 10 | valid 11 | non 12 | valido 13 | 14 | 15 | 16 | 17 | 18 | valid 19 | 20 | 21 | 22 | 23 | 24 | also valid 25 | 26 | 27 | 28 | 29 | 30 | Ümlaut 31 | 32 | 33 | 34 | 35 | 36 | partnerschap overheid — particuliere sector 37 | 38 | 39 | 40 | 41 | 42 | ∆ΓΛΠ 43 | manuale operativo per la gestione dell’emergenza 44 | 阿特拉津(莠去津) 45 | al·luvió 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/issues/Issue.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues; 2 | 3 | import at.ac.univie.mminf.qskos4j.progress.IProgressMonitor; 4 | import at.ac.univie.mminf.qskos4j.progress.StubProgressMonitor; 5 | import at.ac.univie.mminf.qskos4j.result.Result; 6 | import at.ac.univie.mminf.qskos4j.util.IssueDescriptor; 7 | import org.eclipse.rdf4j.RDF4JException; 8 | import org.eclipse.rdf4j.repository.RepositoryConnection; 9 | 10 | public abstract class Issue> { 11 | 12 | private IssueDescriptor issueDescriptor; 13 | protected RepositoryConnection repCon; 14 | protected IProgressMonitor progressMonitor = new StubProgressMonitor(); 15 | private T result; 16 | 17 | public Issue(IssueDescriptor issueDescriptor) { 18 | this.issueDescriptor = issueDescriptor; 19 | } 20 | 21 | protected abstract T invoke() throws RDF4JException; 22 | 23 | public final T getResult() throws RDF4JException { 24 | if (result == null) { 25 | result = invoke(); 26 | } 27 | return result; 28 | } 29 | 30 | protected final void reset() { 31 | result = null; 32 | if (progressMonitor != null) { 33 | progressMonitor.reset(); 34 | } 35 | } 36 | 37 | public void setProgressMonitor(IProgressMonitor progressMonitor) { 38 | this.progressMonitor = progressMonitor; 39 | } 40 | 41 | public void setRepositoryConnection(RepositoryConnection repCon) { 42 | if (issueDescriptor.getDependentIssue() != null) { 43 | issueDescriptor.getDependentIssue().setRepositoryConnection(repCon); 44 | } 45 | 46 | this.repCon = repCon; 47 | reset(); 48 | } 49 | 50 | public IssueDescriptor getIssueDescriptor() { 51 | return issueDescriptor; 52 | } 53 | 54 | @Override 55 | public String toString() { 56 | return "Issue{" + 57 | "id='" + issueDescriptor.getId() + '\'' + 58 | ", name='" + issueDescriptor.getName() + '\'' + 59 | ", description='" + issueDescriptor.getDescription() + '\'' + 60 | ", type=" + issueDescriptor.getType() + 61 | '}'; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/test/resources/noBroaderAndNotTopConcepts.rdf: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/result/Result.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.result; 2 | 3 | import java.io.BufferedWriter; 4 | import java.io.IOException; 5 | import java.io.StringWriter; 6 | 7 | public abstract class Result { 8 | 9 | public enum ReportFormat {TXT, DOT} 10 | public enum ReportStyle {SHORT, EXTENSIVE} 11 | 12 | private T data; 13 | 14 | protected Result(T data) { 15 | this.data = data; 16 | } 17 | 18 | public T getData() { 19 | return data; 20 | } 21 | 22 | public final void generateReport(BufferedWriter writer, ReportFormat format) throws IOException 23 | { 24 | generateReport(writer, format, ReportStyle.SHORT); 25 | } 26 | 27 | public final void generateReport(BufferedWriter writer, ReportFormat format, ReportStyle style) throws IOException 28 | { 29 | switch (format) { 30 | case TXT: 31 | generateTextReport(writer, style); 32 | break; 33 | 34 | case DOT: 35 | generateDotReport(writer); 36 | break; 37 | 38 | default: 39 | throw new UnsupportedReportFormatException(format); 40 | } 41 | } 42 | 43 | protected void generateTextReport(BufferedWriter writer, ReportStyle style) throws IOException { 44 | throw new UnsupportedOperationException(); 45 | } 46 | 47 | public void generateDotReport(BufferedWriter writer) throws IOException { 48 | throw new UnsupportedOperationException(); 49 | } 50 | 51 | @Override 52 | public String toString() { 53 | try { 54 | BufferedWriter textReportStringWriter = new BufferedWriter(new StringWriter()); 55 | generateTextReport(textReportStringWriter, ReportStyle.SHORT); 56 | textReportStringWriter.close(); 57 | return textReportStringWriter.toString(); 58 | } 59 | catch (IOException e) { 60 | return "Could not create short text report (" +e.getMessage()+ ")"; 61 | } 62 | } 63 | 64 | public long occurrenceCount() { 65 | throw new UnsupportedOperationException(); 66 | } 67 | 68 | public boolean isProblematic() { 69 | return occurrenceCount() != 0; 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/test/resources/deprecatedAndIllegalTerms.rdf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | symbol 7 | prefSymbol 8 | altSymbol 9 | CollectableProperty 10 | 11 | 12 | 13 | 14 | subjectIndicator 15 | 16 | 17 | 18 | References a non existing resource in the SKOS namespace 19 | 20 | 21 | 22 | 23 | This property would be nice 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 1.2.3 32 | 123 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | test scopenote 41 | 42 | 43 | 44 | 45 | 1.2.3 46 | 47 | 48 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/issues/outlinks/HttpUriSchemeViolations.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues.outlinks; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.Issue; 4 | import at.ac.univie.mminf.qskos4j.result.CollectionResult; 5 | import at.ac.univie.mminf.qskos4j.util.IssueDescriptor; 6 | import org.eclipse.rdf4j.RDF4JException; 7 | import org.eclipse.rdf4j.model.Resource; 8 | import org.eclipse.rdf4j.model.Statement; 9 | import org.eclipse.rdf4j.model.IRI; 10 | import org.eclipse.rdf4j.repository.RepositoryResult; 11 | 12 | import java.util.HashSet; 13 | import java.util.Set; 14 | 15 | /** 16 | * Created by christian 17 | * Date: 26.01.13 18 | * Time: 16:30 19 | * 20 | * Finds resources not within the HTTP IRI scheme (HTTP IRI Scheme Violation. 21 | */ 22 | public class HttpUriSchemeViolations extends Issue> { 23 | 24 | public HttpUriSchemeViolations() { 25 | super(new IssueDescriptor.Builder("husv", 26 | "HTTP IRI Scheme Violation", 27 | "Finds triple subjects that are no HTTP IRIs", 28 | IssueDescriptor.IssueType.ANALYTICAL) 29 | .weblink("https://github.com/cmader/qSKOS/wiki/Quality-Issues#http-uri-scheme-violation") 30 | .build() 31 | ); 32 | } 33 | 34 | @Override 35 | protected CollectionResult invoke() throws RDF4JException { 36 | Set nonHttpIRIs = new HashSet(); 37 | 38 | RepositoryResult allStatements = repCon.getStatements(null, null, null, false); 39 | while (allStatements.hasNext()) { 40 | Statement statement = allStatements.next(); 41 | if (isNonHttpIRI(statement.getSubject())) { 42 | nonHttpIRIs.add(statement.getSubject().stringValue()); 43 | } 44 | } 45 | 46 | return new CollectionResult(nonHttpIRIs); 47 | } 48 | 49 | private boolean isNonHttpIRI(Resource resource) { 50 | if (resource instanceof IRI) { 51 | String uri = resource.stringValue().toLowerCase(); 52 | if (!uri.contains("http://") && !uri.contains("https://")) { 53 | return true; 54 | } 55 | } 56 | return false; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/test/java/at/ac/univie/mminf/qskos4j/issues/MappingRelationsMisuseTest.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.concepts.AuthoritativeConcepts; 4 | import at.ac.univie.mminf.qskos4j.issues.concepts.InvolvedConcepts; 5 | import at.ac.univie.mminf.qskos4j.issues.conceptscheme.MappingRelationsMisuse; 6 | import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; 7 | import junit.framework.Assert; 8 | import org.junit.Before; 9 | import org.junit.Test; 10 | import org.eclipse.rdf4j.RDF4JException; 11 | import org.eclipse.rdf4j.model.Statement; 12 | 13 | import java.io.IOException; 14 | import java.util.Collection; 15 | 16 | public class MappingRelationsMisuseTest { 17 | 18 | private MappingRelationsMisuse mappingRelationsMisuse; 19 | 20 | @Before 21 | public void setUp() throws IOException, RDF4JException 22 | { 23 | mappingRelationsMisuse = new MappingRelationsMisuse(new AuthoritativeConcepts(new InvolvedConcepts())); 24 | mappingRelationsMisuse.setRepositoryConnection( 25 | new RepositoryBuilder().setUpFromTestResource("mappingRelationsMisuse.rdf").getConnection()); 26 | } 27 | 28 | @Test 29 | public void mappingRelationsMisuseCount() throws RDF4JException { 30 | Assert.assertEquals(5, mappingRelationsMisuse.getResult().getData().size()); 31 | } 32 | 33 | @Test 34 | public void affectedConcepts() throws RDF4JException { 35 | Collection result = mappingRelationsMisuse.getResult().getData(); 36 | 37 | Assert.assertTrue(isAffected("conceptA", "conceptB", result)); 38 | Assert.assertTrue(isAffected("conceptC", "conceptD", result)); 39 | Assert.assertTrue(isAffected("conceptI", "conceptJ", result)); 40 | Assert.assertTrue(isAffected("conceptM", "conceptN", result)); 41 | Assert.assertTrue(isAffected("conceptK", "conceptL", result)); 42 | } 43 | 44 | private boolean isAffected(String subjUriSuffix, String objUriSuffix, Collection statements) { 45 | for (Statement statement : statements) { 46 | if (statement.getSubject().stringValue().endsWith(subjUriSuffix) && 47 | statement.getObject().stringValue().endsWith(objUriSuffix)) 48 | { 49 | return true; 50 | } 51 | } 52 | return false; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/util/TupleQueryResultUtil.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.util; 2 | 3 | import org.eclipse.rdf4j.RDF4JException; 4 | import org.eclipse.rdf4j.model.Resource; 5 | import org.eclipse.rdf4j.model.Value; 6 | import org.eclipse.rdf4j.query.BindingSet; 7 | import org.eclipse.rdf4j.query.QueryEvaluationException; 8 | import org.eclipse.rdf4j.query.TupleQueryResult; 9 | 10 | import java.util.*; 11 | 12 | public class TupleQueryResultUtil { 13 | 14 | public static Set getValuesForBindingName(TupleQueryResult result, String bindingName) 15 | throws QueryEvaluationException 16 | { 17 | Set ret = new HashSet<>(); 18 | 19 | while (result.hasNext()) { 20 | ret.add(result.next().getValue(bindingName)); 21 | } 22 | 23 | return ret; 24 | } 25 | 26 | public static String getFilterForBindingName(TupleQueryResult result, String bindingName, boolean exclusive) 27 | throws QueryEvaluationException 28 | { 29 | String filterExpression = "FILTER (?" +bindingName+ (exclusive ? " NOT" : "") +" IN ("; 30 | Iterator subPropIt = getValuesForBindingName(result, bindingName).iterator(); 31 | while (subPropIt.hasNext()) { 32 | filterExpression += "<"+ subPropIt.next().stringValue() +">"+ (subPropIt.hasNext() ? "," : "))"); 33 | } 34 | return filterExpression; 35 | } 36 | 37 | public static long countResults(TupleQueryResult result) throws QueryEvaluationException { 38 | long count = 0; 39 | 40 | while (result.hasNext()) { 41 | count++; 42 | result.next(); 43 | } 44 | 45 | return count; 46 | } 47 | 48 | public static Collection> createCollectionOfResourcePairs(TupleQueryResult result, String value1, String value2) 49 | throws RDF4JException 50 | { 51 | Collection> resultCollection = new ArrayList<>(); 52 | 53 | while (result.hasNext()) { 54 | BindingSet queryResult = result.next(); 55 | Resource concept1 = (Resource) queryResult.getValue(value1); 56 | Resource concept2 = (Resource) queryResult.getValue(value2); 57 | 58 | resultCollection.add(new Tuple<>(Arrays.asList(concept1, concept2))); 59 | } 60 | 61 | return resultCollection; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/util/vocab/SkosOntology.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.util.vocab; 2 | 3 | import org.eclipse.rdf4j.RDF4JException; 4 | import org.eclipse.rdf4j.model.Resource; 5 | import org.eclipse.rdf4j.model.IRI; 6 | import org.eclipse.rdf4j.model.ValueFactory; 7 | import org.eclipse.rdf4j.model.impl.SimpleValueFactory; 8 | import org.eclipse.rdf4j.repository.Repository; 9 | import org.eclipse.rdf4j.repository.RepositoryConnection; 10 | import org.eclipse.rdf4j.repository.sail.SailRepository; 11 | import org.eclipse.rdf4j.rio.RDFFormat; 12 | import org.eclipse.rdf4j.sail.memory.MemoryStore; 13 | import org.slf4j.Logger; 14 | import org.slf4j.LoggerFactory; 15 | 16 | import java.io.IOException; 17 | import java.net.URL; 18 | 19 | public class SkosOntology { 20 | 21 | private final static Logger logger = LoggerFactory.getLogger(SkosOntology.class); 22 | 23 | public final static String SKOS_BASE_IRI = "https://www.w3.org/2004/02/skos/core"; 24 | public final static String SKOS_ONTO_IRI = "https://www.w3.org/2009/08/skos-reference/skos.rdf"; 25 | 26 | private final static SkosOntology ourInstance = new SkosOntology(); 27 | private static Repository skosRepo; 28 | 29 | public static SkosOntology getInstance() { 30 | if (skosRepo == null) { 31 | try { 32 | ourInstance.createSkosRepo(); 33 | } 34 | catch (Exception e) { 35 | logger.error("Error creating SKOS repository", e); 36 | } 37 | } 38 | return ourInstance; 39 | } 40 | 41 | private void createSkosRepo() throws RDF4JException, IOException { 42 | skosRepo = new SailRepository(new MemoryStore()); 43 | skosRepo.initialize(); 44 | 45 | try (RepositoryConnection repCon = skosRepo.getConnection()) { 46 | repCon.add(new URL(SKOS_ONTO_IRI), SKOS_BASE_IRI, RDFFormat.RDFXML); 47 | } 48 | } 49 | 50 | private SkosOntology() { 51 | } 52 | 53 | public IRI getUri(String element) { 54 | ValueFactory factory = SimpleValueFactory.getInstance(); 55 | return factory.createIRI(SKOS_BASE_IRI +"#"+ element); 56 | } 57 | 58 | public Repository getRepository() { 59 | return skosRepo; 60 | } 61 | 62 | public boolean isSkosResource(Resource resource) { 63 | return resource.stringValue().startsWith(SparqlPrefix.SKOS.getNameSpace()); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/issues/skosintegrity/MappingClashes.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues.skosintegrity; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.Issue; 4 | import at.ac.univie.mminf.qskos4j.result.CollectionResult; 5 | import at.ac.univie.mminf.qskos4j.util.IssueDescriptor; 6 | import at.ac.univie.mminf.qskos4j.util.Tuple; 7 | import at.ac.univie.mminf.qskos4j.util.TupleQueryResultUtil; 8 | import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; 9 | import org.eclipse.rdf4j.RDF4JException; 10 | import org.eclipse.rdf4j.model.Resource; 11 | import org.eclipse.rdf4j.query.QueryLanguage; 12 | import org.eclipse.rdf4j.query.TupleQuery; 13 | 14 | import java.util.Collection; 15 | import java.util.HashSet; 16 | 17 | /** 18 | * Finds Exact vs. Associative and Hierarchical Mapping Clashes. 19 | */ 20 | public class MappingClashes extends Issue>> { 21 | 22 | public MappingClashes() { 23 | super(new IssueDescriptor.Builder("mc", 24 | "Mapping Clashes", 25 | "Covers condition S46 from the SKOS reference document (Exact vs. Associative and Hierarchical Mapping Clashes)", 26 | IssueDescriptor.IssueType.ANALYTICAL) 27 | .weblink("https://github.com/cmader/qSKOS/wiki/Quality-Issues#mapping-clashes") 28 | .build() 29 | ); 30 | } 31 | 32 | @Override 33 | protected CollectionResult> invoke() throws RDF4JException { 34 | TupleQuery query = repCon.prepareTupleQuery(QueryLanguage.SPARQL, createExVsAssMappingQuery()); 35 | 36 | Collection> valuePairs = TupleQueryResultUtil.createCollectionOfResourcePairs( 37 | query.evaluate(), 38 | "concept1", "concept2"); 39 | Collection> distinctPairs = new HashSet>(); 40 | distinctPairs.addAll(valuePairs); 41 | 42 | return new CollectionResult>(distinctPairs); 43 | } 44 | 45 | private String createExVsAssMappingQuery() { 46 | return SparqlPrefix.SKOS + 47 | "SELECT ?concept1 ?concept2 WHERE {" + 48 | "?concept1 (skos:exactMatch|^skos:exactMatch)+ ?concept2 ."+ 49 | "?concept1 skos:broadMatch|skos:narrowMatch|skos:relatedMatch ?concept2 ." + 50 | "}"; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/at/ac/univie/mminf/qskos4j/qskos/IssueIdTest.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.qskos; 2 | 3 | import at.ac.univie.mminf.qskos4j.QSkos; 4 | import at.ac.univie.mminf.qskos4j.UnknownIssueIdException; 5 | import at.ac.univie.mminf.qskos4j.issues.Issue; 6 | import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; 7 | import junit.framework.Assert; 8 | import org.junit.Before; 9 | import org.junit.Test; 10 | import org.eclipse.rdf4j.RDF4JException; 11 | 12 | import java.io.IOException; 13 | import java.util.*; 14 | 15 | public class IssueIdTest { 16 | 17 | private QSkos qskos; 18 | 19 | @Before 20 | public void setUp() throws IOException, RDF4JException 21 | { 22 | qskos = new QSkos(); 23 | qskos.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("nocontent.rdf").getConnection()); 24 | } 25 | 26 | @Test 27 | public void getAllIssuesByIdList() { 28 | String idList = getAllIdsAsCommaSeparatedList(); 29 | 30 | try { 31 | qskos.getIssues(idList); 32 | } 33 | catch (UnknownIssueIdException e) { 34 | Assert.fail(e.getMessage()); 35 | } 36 | } 37 | 38 | @Test(expected = UnknownIssueIdException.class) 39 | public void unknownIssueIdInListTest() { 40 | String idList = getAllIdsAsCommaSeparatedList() + ",bla"; 41 | qskos.getIssues(idList); 42 | } 43 | 44 | @Test 45 | public void whiteSpacesInIssueIdListTest() { 46 | Iterator issueIt = qskos.getAllIssues().iterator(); 47 | String idList = issueIt.next().getIssueDescriptor().getId() +", "+ issueIt.next().getIssueDescriptor().getId(); 48 | Collection issues = qskos.getIssues(idList); 49 | Assert.assertEquals(2, issues.size()); 50 | } 51 | 52 | @Test 53 | public void ensureUniqueIssueIdsTest() { 54 | List allIssues = qskos.getAllIssues(); 55 | Set uniqueIssueIds = new HashSet(); 56 | for (Issue issue : allIssues) { 57 | uniqueIssueIds.add(issue.getIssueDescriptor().getId()); 58 | } 59 | Assert.assertEquals(allIssues.size(), uniqueIssueIds.size()); 60 | } 61 | 62 | private String getAllIdsAsCommaSeparatedList() { 63 | String idList = ""; 64 | 65 | Iterator issueIt = qskos.getAllIssues().iterator(); 66 | while (issueIt.hasNext()) { 67 | idList += issueIt.next().getIssueDescriptor().getId() + (issueIt.hasNext() ? "," : ""); 68 | } 69 | 70 | return idList; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/test/java/at/ac/univie/mminf/qskos4j/issues/MissingInLinksTest.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.concepts.AuthoritativeConcepts; 4 | import at.ac.univie.mminf.qskos4j.issues.concepts.InvolvedConcepts; 5 | import at.ac.univie.mminf.qskos4j.issues.inlinks.MissingInLinks; 6 | import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; 7 | import junit.framework.Assert; 8 | import org.junit.Before; 9 | import org.junit.Test; 10 | import org.eclipse.rdf4j.RDF4JException; 11 | import org.eclipse.rdf4j.model.Resource; 12 | 13 | import java.io.IOException; 14 | import java.util.Collection; 15 | 16 | public class MissingInLinksTest { 17 | 18 | private MissingInLinks missingInLinks; 19 | private AuthoritativeConcepts authoritativeConcepts; 20 | 21 | @Before 22 | public void setUp() throws RDF4JException, IOException { 23 | authoritativeConcepts = new AuthoritativeConcepts(new InvolvedConcepts()); 24 | 25 | missingInLinks = new MissingInLinks(authoritativeConcepts); 26 | missingInLinks.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("rankConcepts.rdf").getConnection()); 27 | missingInLinks.addRepositoryLoopback(); 28 | } 29 | 30 | @Test 31 | public void testInLinksAsDbPedia() throws RDF4JException { 32 | authoritativeConcepts.setAuthResourceIdentifier("dbpedia.org"); 33 | 34 | Collection conceptsMissingInLinks = missingInLinks.getResult().getData(); 35 | Assert.assertTrue(conceptsMissingInLinks.isEmpty()); 36 | } 37 | 38 | @Test 39 | public void testInLinksAsSTW() throws RDF4JException { 40 | authoritativeConcepts.setAuthResourceIdentifier("zbw.eu"); 41 | 42 | Collection conceptsMissingInLinks = missingInLinks.getResult().getData(); 43 | Assert.assertEquals(2, conceptsMissingInLinks.size()); 44 | } 45 | 46 | @Test 47 | public void testInLinksAsBnf() throws RDF4JException { 48 | authoritativeConcepts.setAuthResourceIdentifier("data.bnf.fr"); 49 | 50 | Collection conceptsMissingInLinks = missingInLinks.getResult().getData(); 51 | Assert.assertEquals(1, conceptsMissingInLinks.size()); 52 | } 53 | 54 | 55 | @Test 56 | public void testInLinksAsLocal() throws RDF4JException { 57 | authoritativeConcepts.setAuthResourceIdentifier("myvocab.org"); 58 | 59 | Collection conceptsMissingInLinks = missingInLinks.getResult().getData(); 60 | Assert.assertEquals(1, conceptsMissingInLinks.size()); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/at/ac/univie/mminf/qskos4j/issues/OmittedOrInvalidLanguageTagsTest.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.language.OmittedOrInvalidLanguageTags; 4 | import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; 5 | import junit.framework.Assert; 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | import org.eclipse.rdf4j.RDF4JException; 9 | import org.eclipse.rdf4j.model.Literal; 10 | import org.eclipse.rdf4j.model.Resource; 11 | 12 | import java.io.IOException; 13 | import java.util.Collection; 14 | import java.util.Map; 15 | 16 | /** 17 | * Created by christian 18 | * Date: 27.01.13 19 | * Time: 00:42 20 | */ 21 | public class OmittedOrInvalidLanguageTagsTest { 22 | 23 | private OmittedOrInvalidLanguageTags oiltComponents, oiltDeprecatedAndIllegal, oiltLangTags; 24 | 25 | @Before 26 | public void setUp() throws RDF4JException, IOException { 27 | oiltComponents = new OmittedOrInvalidLanguageTags(); 28 | oiltComponents.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("components_1.rdf").getConnection()); 29 | 30 | oiltDeprecatedAndIllegal = new OmittedOrInvalidLanguageTags(); 31 | oiltDeprecatedAndIllegal.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("deprecatedAndIllegalTerms.rdf").getConnection()); 32 | 33 | oiltLangTags = new OmittedOrInvalidLanguageTags(); 34 | oiltLangTags.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("languageTags.rdf").getConnection()); 35 | } 36 | 37 | @Test 38 | public void testMissingLangTagCount_1() throws RDF4JException { 39 | Assert.assertEquals(3, oiltComponents.getResult().getData().size()); 40 | } 41 | 42 | @Test 43 | public void testMissingLangTagCount_2() throws RDF4JException { 44 | Map> missingLangTags = oiltDeprecatedAndIllegal.getResult().getData(); 45 | 46 | Assert.assertEquals(1, missingLangTags.keySet().size()); 47 | Assert.assertEquals(2, countEntries(missingLangTags.values())); 48 | } 49 | 50 | private int countEntries(Collection> allLiterals) { 51 | int literalCount = 0; 52 | for (Collection literals : allLiterals) { 53 | literalCount += literals.size(); 54 | } 55 | return literalCount; 56 | } 57 | 58 | @Test 59 | public void testMissingLangTagCount_3() throws RDF4JException { 60 | Assert.assertEquals(2, oiltLangTags.getResult().getData().size()); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/issues/conceptscheme/OmittedTopConcepts.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues.conceptscheme; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.Issue; 4 | import at.ac.univie.mminf.qskos4j.result.CollectionResult; 5 | import at.ac.univie.mminf.qskos4j.util.IssueDescriptor; 6 | import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; 7 | import org.eclipse.rdf4j.RDF4JException; 8 | import org.eclipse.rdf4j.model.Resource; 9 | import org.eclipse.rdf4j.model.Value; 10 | import org.eclipse.rdf4j.query.BooleanQuery; 11 | import org.eclipse.rdf4j.query.QueryLanguage; 12 | 13 | import java.util.Collection; 14 | import java.util.HashSet; 15 | 16 | /** 17 | * Finds concept schemes without top concepts ( 18 | * Omitted Top Concepts 19 | * ). 20 | */ 21 | public class OmittedTopConcepts extends Issue> { 22 | 23 | private ConceptSchemes conceptSchemes; 24 | 25 | public OmittedTopConcepts(ConceptSchemes conceptSchemes) { 26 | super(new IssueDescriptor.Builder( 27 | "otc", 28 | "Omitted Top Concepts", 29 | "Finds skos:ConceptSchemes that don't have top concepts defined", 30 | IssueDescriptor.IssueType.ANALYTICAL) 31 | .weblink("https://github.com/cmader/qSKOS/wiki/Quality-Issues#omitted-top-concepts") 32 | .dependentIssue(conceptSchemes) 33 | .build()); 34 | 35 | this.conceptSchemes = conceptSchemes; 36 | } 37 | 38 | @Override 39 | protected CollectionResult invoke() throws RDF4JException { 40 | Collection csWithOmittedTopConcepts = new HashSet<>(); 41 | 42 | for (Resource conceptScheme : conceptSchemes.getResult().getData()) { 43 | 44 | BooleanQuery hasTopConceptQuery = repCon.prepareBooleanQuery( 45 | QueryLanguage.SPARQL, 46 | createConceptSchemeWithoutTopConceptQuery(conceptScheme)); 47 | 48 | if (!hasTopConceptQuery.evaluate()) { 49 | csWithOmittedTopConcepts.add(conceptScheme); 50 | } 51 | } 52 | 53 | return new CollectionResult<>(csWithOmittedTopConcepts); 54 | } 55 | 56 | private String createConceptSchemeWithoutTopConceptQuery(Value conceptScheme) { 57 | return SparqlPrefix.SKOS+ 58 | "ASK {" + 59 | "<"+conceptScheme.stringValue()+"> (skos:hasTopConcept|^skos:topConceptOf)+ ?topConcept"+ 60 | "}"; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/issues/outlinks/HttpURIs.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues.outlinks; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.Issue; 4 | import at.ac.univie.mminf.qskos4j.result.CollectionResult; 5 | import at.ac.univie.mminf.qskos4j.util.IssueDescriptor; 6 | import org.eclipse.rdf4j.RDF4JException; 7 | import org.eclipse.rdf4j.model.Resource; 8 | import org.eclipse.rdf4j.model.Statement; 9 | import org.eclipse.rdf4j.model.Value; 10 | import org.eclipse.rdf4j.repository.RepositoryResult; 11 | 12 | import java.net.URI; 13 | import java.net.URISyntaxException; 14 | import java.util.*; 15 | 16 | /** 17 | * Created by christian 18 | * Date: 26.01.13 19 | * Time: 15:23 20 | */ 21 | public class HttpURIs extends Issue> { 22 | 23 | private Set httpURIs = new HashSet<>(); 24 | private Set invalidResources = new HashSet<>(); 25 | 26 | public HttpURIs() { 27 | super(new IssueDescriptor.Builder("huc", 28 | "HTTP URI Count", 29 | "Counts the total number of HTTP URIs", 30 | IssueDescriptor.IssueType.STATISTICAL).build() 31 | ); 32 | } 33 | 34 | @Override 35 | protected CollectionResult invoke() throws RDF4JException { 36 | RepositoryResult result = repCon.getStatements(null, null, null, false, (Resource) null); 37 | while (result.hasNext()) { 38 | Statement st = result.next(); 39 | 40 | Collection tripleValues = new ArrayList<>(); 41 | tripleValues.addAll(Arrays.asList(st.getSubject(), st.getObject(), st.getPredicate())); 42 | 43 | for (Value value : tripleValues) { 44 | if (value instanceof org.eclipse.rdf4j.model.IRI) addToUrlList(value); 45 | } 46 | } 47 | 48 | return new CollectionResult<>(httpURIs); 49 | } 50 | 51 | private void addToUrlList(Value iri) { 52 | try { 53 | URI uri = new URI(iri.stringValue()); 54 | 55 | if (uri.getScheme().startsWith("http")) { 56 | httpURIs.add(pruneFragment(uri)); 57 | } 58 | } 59 | catch (URISyntaxException e) { 60 | invalidResources.add(iri.toString()); 61 | } 62 | } 63 | 64 | private URI pruneFragment(URI uri) throws URISyntaxException 65 | { 66 | if (uri.getFragment() != null) { 67 | int hashIndex = uri.toString().indexOf("#"); 68 | return new URI(uri.toString().substring(0, hashIndex)); 69 | } 70 | return uri; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/test/resources/hierarchicalRedundancy.rdf: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/issues/concepts/OrphanConcepts.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues.concepts; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.Issue; 4 | import at.ac.univie.mminf.qskos4j.result.CollectionResult; 5 | import at.ac.univie.mminf.qskos4j.util.IssueDescriptor; 6 | import at.ac.univie.mminf.qskos4j.util.TupleQueryResultUtil; 7 | import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; 8 | import org.eclipse.rdf4j.RDF4JException; 9 | import org.eclipse.rdf4j.model.Resource; 10 | import org.eclipse.rdf4j.model.Value; 11 | import org.eclipse.rdf4j.query.QueryLanguage; 12 | import org.eclipse.rdf4j.query.TupleQuery; 13 | 14 | import java.util.HashSet; 15 | import java.util.Set; 16 | 17 | /** 18 | * Finds all "orphan concepts". Further info on Orphan 19 | * Concepts. 20 | */ 21 | public class OrphanConcepts extends Issue> { 22 | 23 | private InvolvedConcepts involvedConcepts; 24 | 25 | public OrphanConcepts(InvolvedConcepts involvedConcepts) { 26 | super(new IssueDescriptor.Builder( 27 | "oc", 28 | "Orphan Concepts", 29 | "Finds all orphan concepts, i.e. those not having semantic relationships to other concepts", 30 | IssueDescriptor.IssueType.ANALYTICAL) 31 | .weblink("https://github.com/cmader/qSKOS/wiki/Quality-Issues#orphan-concepts") 32 | .dependentIssue(involvedConcepts) 33 | .build() 34 | ); 35 | 36 | this.involvedConcepts = involvedConcepts; 37 | } 38 | 39 | @Override 40 | protected CollectionResult invoke() throws RDF4JException { 41 | TupleQuery query = repCon.prepareTupleQuery(QueryLanguage.SPARQL, createOrphanConceptsQuery()); 42 | Set connectedConcepts = TupleQueryResultUtil.getValuesForBindingName(query.evaluate(), "concept"); 43 | 44 | Set orphanConcepts = new HashSet<>(involvedConcepts.getResult().getData()); 45 | orphanConcepts.removeAll(connectedConcepts); 46 | 47 | return new CollectionResult<>(orphanConcepts); 48 | } 49 | 50 | private String createOrphanConceptsQuery() { 51 | return SparqlPrefix.SKOS +" "+ SparqlPrefix.RDF +" "+ SparqlPrefix.RDFS + 52 | "SELECT DISTINCT ?concept WHERE " + 53 | "{" + 54 | "{?concept ?rel ?otherConcept} UNION " + 55 | "{?otherConcept ?rel ?concept}" + 56 | "?rel rdfs:subPropertyOf skos:semanticRelation" + 57 | "}"; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/test/resources/redundantAssociativeRelations.rdf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | some label 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /src/test/java/at/ac/univie/mminf/qskos4j/issues/OverlappingLabelsTest.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.concepts.InvolvedConcepts; 4 | import at.ac.univie.mminf.qskos4j.issues.labels.OverlappingLabels; 5 | import at.ac.univie.mminf.qskos4j.issues.labels.util.LabelConflict; 6 | import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; 7 | import junit.framework.Assert; 8 | import org.junit.Before; 9 | import org.junit.Test; 10 | import org.eclipse.rdf4j.RDF4JException; 11 | import org.eclipse.rdf4j.model.Value; 12 | 13 | import java.io.IOException; 14 | import java.util.Collection; 15 | import java.util.HashSet; 16 | import java.util.Set; 17 | 18 | public class OverlappingLabelsTest { 19 | 20 | private OverlappingLabels overlappingLabelsForComponents, overlappingLabelsForRelatedConcepts, overlappingLabels; 21 | 22 | @Before 23 | public void setUp() throws RDF4JException, IOException { 24 | overlappingLabelsForComponents = new OverlappingLabels(new InvolvedConcepts()); 25 | overlappingLabelsForComponents.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("components_1.rdf").getConnection()); 26 | 27 | overlappingLabelsForRelatedConcepts = new OverlappingLabels(new InvolvedConcepts()); 28 | overlappingLabelsForRelatedConcepts.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("relatedConcepts.rdf").getConnection()); 29 | 30 | overlappingLabels = new OverlappingLabels(new InvolvedConcepts()); 31 | overlappingLabels.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("overlappingLabels.rdf").getConnection()); 32 | } 33 | 34 | @Test 35 | public void testLabelConflictCount_1() throws RDF4JException { 36 | Collection allLabelConflicts = overlappingLabelsForComponents.getResult().getData(); 37 | 38 | Assert.assertEquals(2, allLabelConflicts.size()); 39 | Assert.assertEquals(4, getDifferentResources(allLabelConflicts).size()); 40 | } 41 | 42 | @Test 43 | public void testCaseInsensitive() throws RDF4JException { 44 | Assert.assertEquals(2, overlappingLabels.getResult().getData().size()); 45 | } 46 | 47 | private Collection getDifferentResources(Collection labelConflicts) 48 | { 49 | Set ret = new HashSet<>(); 50 | 51 | for (LabelConflict labelConflict : labelConflicts) { 52 | ret.addAll(labelConflict.getAffectedResources()); 53 | } 54 | 55 | return ret; 56 | } 57 | 58 | @Test 59 | public void testLabelConflictCount_2() throws RDF4JException { 60 | Assert.assertEquals(0, overlappingLabelsForRelatedConcepts.getResult().getData().size()); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/at/ac/univie/mminf/qskos4j/issues/SkosXlTest.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.concepts.InvolvedConcepts; 4 | import at.ac.univie.mminf.qskos4j.issues.labels.LexicalRelations; 5 | import at.ac.univie.mminf.qskos4j.issues.labels.OverlappingLabels; 6 | import at.ac.univie.mminf.qskos4j.issues.language.IncompleteLanguageCoverage; 7 | import at.ac.univie.mminf.qskos4j.issues.language.OmittedOrInvalidLanguageTags; 8 | import at.ac.univie.mminf.qskos4j.issues.language.util.LanguageCoverage; 9 | import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; 10 | import junit.framework.Assert; 11 | import org.junit.Before; 12 | import org.junit.Test; 13 | import org.eclipse.rdf4j.RDF4JException; 14 | import org.eclipse.rdf4j.repository.Repository; 15 | 16 | import java.io.IOException; 17 | 18 | public class SkosXlTest { 19 | 20 | private LexicalRelations lexicalRelations; 21 | private OmittedOrInvalidLanguageTags omittedOrInvalidLanguageTags; 22 | private IncompleteLanguageCoverage incompleteLanguageCoverage; 23 | private OverlappingLabels overlappingLabels; 24 | 25 | @Before 26 | public void setUp() throws RDF4JException, IOException { 27 | RepositoryBuilder repositoryBuilder = new RepositoryBuilder(); 28 | Repository repo = repositoryBuilder.setUpFromTestResource("skosxl.rdf"); 29 | repositoryBuilder.enableSkosXlSupport(); 30 | 31 | lexicalRelations = new LexicalRelations(new InvolvedConcepts()); 32 | lexicalRelations.setRepositoryConnection(repo.getConnection()); 33 | 34 | omittedOrInvalidLanguageTags = new OmittedOrInvalidLanguageTags(); 35 | omittedOrInvalidLanguageTags.setRepositoryConnection(repo.getConnection()); 36 | 37 | incompleteLanguageCoverage = new IncompleteLanguageCoverage(new LanguageCoverage(new InvolvedConcepts())); 38 | incompleteLanguageCoverage.setRepositoryConnection(repo.getConnection()); 39 | 40 | overlappingLabels = new OverlappingLabels(new InvolvedConcepts()); 41 | overlappingLabels.setRepositoryConnection(repo.getConnection()); 42 | } 43 | 44 | @Test 45 | public void lexicalRelationsCountTest() throws RDF4JException { 46 | Assert.assertEquals(5, lexicalRelations.getResult().getData().intValue()); 47 | } 48 | 49 | @Test 50 | public void omittedLangTagCount() throws RDF4JException { 51 | Assert.assertEquals(2, omittedOrInvalidLanguageTags.getResult().getData().size()); 52 | } 53 | 54 | @Test 55 | public void incompleteLangCovCount() throws RDF4JException { 56 | Assert.assertEquals(2, incompleteLanguageCoverage.getResult().getData().size()); 57 | } 58 | 59 | @Test 60 | public void labelConflictCount() throws RDF4JException { 61 | Assert.assertEquals(1, overlappingLabels.getResult().getData().size()); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/at/ac/univie/mminf/qskos4j/issues/IncompleteLanguageCoverageTest.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.concepts.InvolvedConcepts; 4 | import at.ac.univie.mminf.qskos4j.issues.language.IncompleteLanguageCoverage; 5 | import at.ac.univie.mminf.qskos4j.issues.language.util.LanguageCoverage; 6 | import at.ac.univie.mminf.qskos4j.util.vocab.RepositoryBuilder; 7 | import org.junit.Assert; 8 | import org.junit.Before; 9 | import org.junit.Test; 10 | import org.eclipse.rdf4j.RDF4JException; 11 | import org.eclipse.rdf4j.model.Resource; 12 | import org.eclipse.rdf4j.model.Value; 13 | 14 | import java.io.IOException; 15 | import java.util.ArrayList; 16 | import java.util.Collection; 17 | import java.util.List; 18 | import java.util.Map; 19 | 20 | public class IncompleteLanguageCoverageTest { 21 | 22 | private IncompleteLanguageCoverage incompleteLanguageCoverage; 23 | 24 | @Before 25 | public void setUp() throws RDF4JException, IOException { 26 | incompleteLanguageCoverage = new IncompleteLanguageCoverage(new LanguageCoverage(new InvolvedConcepts())); 27 | incompleteLanguageCoverage.setRepositoryConnection(new RepositoryBuilder().setUpFromTestResource("components_1.rdf").getConnection()); 28 | } 29 | 30 | @Test 31 | public void testIncompleteLanguageCoverageCount() throws RDF4JException 32 | { 33 | Map> incompleteLangCoverage = incompleteLanguageCoverage.getResult().getData(); 34 | Assert.assertEquals(13, incompleteLangCoverage.size()); 35 | } 36 | 37 | @Test 38 | public void testExistResourcesNotHavingEnglishLabels() 39 | throws RDF4JException 40 | { 41 | Map> incompleteLangCoverage = incompleteLanguageCoverage.getResult().getData(); 42 | 43 | boolean englishTagFound = false; 44 | for (Collection missingLanguages : incompleteLangCoverage.values()) { 45 | englishTagFound = missingLanguages.contains("en"); 46 | if (englishTagFound) break; 47 | } 48 | 49 | Assert.assertFalse(englishTagFound); 50 | } 51 | 52 | @Test 53 | public void testResourcesMissingOnlyFrenchLabelsCount() 54 | throws RDF4JException 55 | { 56 | Map> incompleteLangCoverage = incompleteLanguageCoverage.getResult().getData(); 57 | 58 | List foundResources = new ArrayList<>(); 59 | for (Value resource : incompleteLangCoverage.keySet()) { 60 | Collection missingLanguages = incompleteLangCoverage.get(resource); 61 | if (missingLanguages.size() == 1 && missingLanguages.contains("fr")) { 62 | foundResources.add(resource); 63 | } 64 | } 65 | 66 | Assert.assertEquals(2, foundResources.size()); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/util/ResourceLabelsCollector.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues.labels.util; 2 | 3 | import org.eclipse.rdf4j.RDF4JException; 4 | import org.eclipse.rdf4j.model.Literal; 5 | import org.eclipse.rdf4j.model.Resource; 6 | import org.eclipse.rdf4j.query.BindingSet; 7 | import org.eclipse.rdf4j.query.QueryEvaluationException; 8 | import org.eclipse.rdf4j.query.QueryLanguage; 9 | import org.eclipse.rdf4j.query.TupleQueryResult; 10 | import org.eclipse.rdf4j.repository.RepositoryConnection; 11 | import org.slf4j.Logger; 12 | import org.slf4j.LoggerFactory; 13 | 14 | import java.util.Collection; 15 | import java.util.HashSet; 16 | 17 | public class ResourceLabelsCollector { 18 | 19 | private final Logger logger = LoggerFactory.getLogger(ResourceLabelsCollector.class); 20 | 21 | private RepositoryConnection repCon; 22 | private Collection labeledResources; 23 | 24 | public Collection getLabeledConcepts() { 25 | labeledResources = new HashSet(); 26 | createLabeledResources(); 27 | return labeledResources; 28 | } 29 | 30 | private void createLabeledResources() { 31 | for (LabelType labelType : LabelType.getSkosLabels()) { 32 | String labelQuery = createLabelQuery(labelType); 33 | try { 34 | TupleQueryResult result = repCon.prepareTupleQuery(QueryLanguage.SPARQL, labelQuery).evaluate(); 35 | addResultToLabels(labelType, result); 36 | } 37 | catch (RDF4JException e) { 38 | logger.error("error querying repository: " +labelQuery); 39 | } 40 | } 41 | } 42 | 43 | private String createLabelQuery(LabelType labelType) { 44 | return "SELECT DISTINCT ?resource ?label"+ 45 | "{" + 46 | "?resource <"+labelType.getPredicate()+"> ?label ." + 47 | "}"; 48 | } 49 | 50 | private void addResultToLabels(LabelType labelType, TupleQueryResult result) throws QueryEvaluationException 51 | { 52 | while (result.hasNext()) { 53 | BindingSet queryResult = result.next(); 54 | Resource resource = (Resource) queryResult.getValue("resource"); 55 | 56 | try { 57 | Literal label = (Literal) queryResult.getValue("label"); 58 | 59 | if (label != null) { 60 | labeledResources.add(new LabeledConcept(resource, label, labelType)); 61 | } 62 | } 63 | catch (ClassCastException e) { 64 | logger.error("Literal label expected for resource " +resource.toString()+ ", " +e.toString()); 65 | } 66 | } 67 | } 68 | 69 | public void setRepositoryConnection(RepositoryConnection repCon) { 70 | this.repCon = repCon; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/util/IssueDescriptor.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.util; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.Issue; 4 | import at.ac.univie.mminf.qskos4j.issues.language.util.LanguageCoverage; 5 | import org.eclipse.rdf4j.model.IRI; 6 | import org.eclipse.rdf4j.model.ValueFactory; 7 | import org.eclipse.rdf4j.model.impl.SimpleValueFactory; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import java.net.MalformedURLException; 12 | import java.net.URL; 13 | 14 | /** 15 | * Created by christian on 24.06.17. 16 | */ 17 | public class IssueDescriptor { 18 | private final static Logger logger = LoggerFactory.getLogger(IssueDescriptor.Builder.class); 19 | 20 | public enum IssueType {STATISTICAL, ANALYTICAL} 21 | 22 | private String id, name, description; 23 | private IssueType type; 24 | private URL weblink; 25 | private Issue dependentIssue; 26 | 27 | public static class Builder { 28 | // required 29 | private String id, name, description; 30 | private IssueType type; 31 | 32 | // optional 33 | private URL weblink; 34 | private Issue dependentIssue; 35 | 36 | public Builder(String id, String name, String description, IssueType type) { 37 | this.id = id; 38 | this.name = name; 39 | this.description = description; 40 | this.type = type; 41 | } 42 | 43 | public Builder weblink(String weblink) { 44 | try { 45 | this.weblink = new URL(weblink); 46 | } 47 | catch (MalformedURLException e) { 48 | logger.warn("The provided URL for issue '" +name+ "' is not valid: '" +weblink+ "'"); 49 | } 50 | return this; 51 | } 52 | 53 | public Builder dependentIssue(Issue dependentIssue) { 54 | this.dependentIssue = dependentIssue; 55 | return this; 56 | } 57 | 58 | public IssueDescriptor build() { 59 | return new IssueDescriptor(this); 60 | } 61 | } 62 | 63 | private IssueDescriptor(Builder builder) { 64 | this.id = builder.id; 65 | this.name = builder.name; 66 | this.description = builder.description; 67 | this.type = builder.type; 68 | this.weblink = builder.weblink; 69 | this.dependentIssue = builder.dependentIssue; 70 | } 71 | 72 | public String getId() { 73 | return id; 74 | } 75 | 76 | public String getName() { 77 | return name; 78 | } 79 | 80 | public String getDescription() { 81 | return description; 82 | } 83 | 84 | public IssueType getType() { 85 | return type; 86 | } 87 | 88 | public Issue getDependentIssue() { 89 | return dependentIssue; 90 | } 91 | 92 | public URL getWeblink() { 93 | return weblink; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/EmptyLabeledResources.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues.labels; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.Issue; 4 | import at.ac.univie.mminf.qskos4j.issues.labels.util.EmptyLabelsResult; 5 | import at.ac.univie.mminf.qskos4j.issues.labels.util.LabelType; 6 | import at.ac.univie.mminf.qskos4j.util.IssueDescriptor; 7 | import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; 8 | import org.eclipse.rdf4j.RDF4JException; 9 | import org.eclipse.rdf4j.model.Resource; 10 | import org.eclipse.rdf4j.model.IRI; 11 | import org.eclipse.rdf4j.model.Value; 12 | import org.eclipse.rdf4j.query.BindingSet; 13 | import org.eclipse.rdf4j.query.QueryLanguage; 14 | import org.eclipse.rdf4j.query.TupleQueryResult; 15 | 16 | import java.util.*; 17 | 18 | public class EmptyLabeledResources extends Issue { 19 | 20 | private Map> result; 21 | 22 | public EmptyLabeledResources() { 23 | super(new IssueDescriptor.Builder("el", 24 | "Empty Labels", 25 | "Finds empty labels or labels containing only whitespaces", 26 | IssueDescriptor.IssueType.ANALYTICAL).build()); 27 | } 28 | 29 | @Override 30 | protected EmptyLabelsResult invoke() throws RDF4JException { 31 | result = new HashMap<>(); 32 | 33 | TupleQueryResult result = repCon.prepareTupleQuery( 34 | QueryLanguage.SPARQL, 35 | createLexicalLabelQuery() 36 | ).evaluate(); 37 | 38 | while (result.hasNext()) { 39 | BindingSet bs = result.next(); 40 | Resource resource = (Resource) bs.getBinding("resource").getValue(); 41 | IRI labelType = (IRI) bs.getBinding("labelType").getValue(); 42 | Value literal = bs.getBinding("literal").getValue(); 43 | 44 | if (literal.stringValue().trim().isEmpty()) { 45 | addToResults(resource, LabelType.getFromUri(labelType)); 46 | } 47 | } 48 | 49 | return new EmptyLabelsResult(this.result); 50 | } 51 | 52 | private String createLexicalLabelQuery() { 53 | return SparqlPrefix.SKOS +" "+ SparqlPrefix.DCTERMS +" "+ SparqlPrefix.RDFS +" "+ SparqlPrefix.DC+ 54 | "SELECT ?resource ?labelType ?literal WHERE " + 55 | "{" + 56 | "?resource ?labelType ?literal ." + 57 | "FILTER (?labelType IN (rdfs:label, dc:title, dcterms:title, skos:prefLabel, skos:altLabel, skos:hiddenLabel))" + 58 | "}"; 59 | } 60 | 61 | private void addToResults(Resource resource, LabelType labelType) { 62 | Collection values = result.get(resource); 63 | if (values == null) { 64 | values = new HashSet<>(); 65 | result.put(resource, values); 66 | } 67 | values.add(labelType); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/issues/skosintegrity/HierarchicalRedundancy.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues.skosintegrity; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.HierarchyGraphBuilder; 4 | import at.ac.univie.mminf.qskos4j.issues.Issue; 5 | import at.ac.univie.mminf.qskos4j.progress.MonitoredIterator; 6 | import at.ac.univie.mminf.qskos4j.result.CollectionResult; 7 | import at.ac.univie.mminf.qskos4j.util.IssueDescriptor; 8 | import at.ac.univie.mminf.qskos4j.util.Pair; 9 | import at.ac.univie.mminf.qskos4j.util.graph.NamedEdge; 10 | import org.eclipse.rdf4j.RDF4JException; 11 | import org.eclipse.rdf4j.model.Resource; 12 | import org.eclipse.rdf4j.repository.RepositoryConnection; 13 | import org.jgrapht.DirectedGraph; 14 | import org.jgrapht.alg.DijkstraShortestPath; 15 | 16 | import java.util.*; 17 | 18 | public class HierarchicalRedundancy extends Issue>> { 19 | 20 | private Collection> hierarchicalRedundancies; 21 | private HierarchyGraphBuilder hierarchyGraphBuilder; 22 | private DirectedGraph hierarchyGraph; 23 | 24 | public HierarchicalRedundancy(HierarchyGraphBuilder hierarchyGraphBuilder) { 25 | super(new IssueDescriptor.Builder("hr", 26 | "Hierarchical Redundancy", 27 | "Finds broader/narrower relations over multiple hierarchy levels", 28 | IssueDescriptor.IssueType.ANALYTICAL) 29 | .weblink("https://github.com/cmader/qSKOS/wiki/Quality-Issues#hierarchical-redundancy") 30 | .build()); 31 | this.hierarchyGraphBuilder = hierarchyGraphBuilder; 32 | } 33 | 34 | @Override 35 | protected CollectionResult> invoke() throws RDF4JException { 36 | hierarchicalRedundancies = new HashSet<>(); 37 | hierarchyGraph = hierarchyGraphBuilder.createGraph(); 38 | 39 | Set allEdges = new HashSet<>(hierarchyGraph.edgeSet()); 40 | Iterator it = new MonitoredIterator<>(allEdges, progressMonitor); 41 | 42 | while (it.hasNext()) { 43 | NamedEdge edge = it.next(); 44 | Resource source = hierarchyGraph.getEdgeSource(edge); 45 | Resource target = hierarchyGraph.getEdgeTarget(edge); 46 | 47 | hierarchyGraph.removeEdge(edge); 48 | List path = new DijkstraShortestPath<>(hierarchyGraph, source, target).getPathEdgeList(); 49 | if (path != null && !path.isEmpty()) { 50 | hierarchicalRedundancies.add(new Pair<>(source, target)); 51 | } 52 | hierarchyGraph.addEdge(source, target); 53 | } 54 | 55 | return new CollectionResult<>(hierarchicalRedundancies); 56 | } 57 | 58 | @Override 59 | public void setRepositoryConnection(RepositoryConnection repCon) { 60 | hierarchyGraphBuilder.setRepositoryConnection(repCon); 61 | super.setRepositoryConnection(repCon); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/util/url/UrlDereferencer.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.util.url; 2 | 3 | import java.io.IOException; 4 | import java.net.URISyntaxException; 5 | import java.net.URL; 6 | 7 | import org.apache.http.Header; 8 | import org.apache.http.HttpResponse; 9 | import org.apache.http.client.config.CookieSpecs; 10 | import org.apache.http.client.config.RequestConfig; 11 | import org.apache.http.client.methods.HttpUriRequest; 12 | import org.apache.http.client.methods.RequestBuilder; 13 | import org.apache.http.impl.client.CloseableHttpClient; 14 | import org.apache.http.impl.client.HttpClientBuilder; 15 | import org.slf4j.Logger; 16 | import org.slf4j.LoggerFactory; 17 | 18 | public class UrlDereferencer { 19 | 20 | private final Logger logger = LoggerFactory 21 | .getLogger(UrlDereferencer.class); 22 | private final int HTTP_GET_TIMOUT_MILLIS = 60000; 23 | 24 | public String getContentType(final URL url) 25 | throws UrlNotDereferencableException { 26 | try { 27 | final HttpResponse response = sendRequest(url); 28 | 29 | if (isValidResponse(response)) { 30 | final Header contentType = response 31 | .getFirstHeader("Content-Type"); 32 | if (contentType == null || contentType.getValue().isEmpty()) { 33 | throw new NoContentTypeProvidedException(); 34 | } 35 | 36 | return contentType.getValue(); 37 | } 38 | } catch (final Exception e) { 39 | // fall through 40 | } 41 | throw new UrlNotDereferencableException(url); 42 | } 43 | 44 | private HttpResponse sendRequest(final URL url) throws URISyntaxException, 45 | IOException { 46 | this.logger.debug("dereferencing: " + url.toString()); 47 | 48 | final HttpUriRequest request = RequestBuilder 49 | .get(url.toURI()) 50 | .setConfig( 51 | RequestConfig 52 | .custom() 53 | .setConnectionRequestTimeout( 54 | this.HTTP_GET_TIMOUT_MILLIS) 55 | .setConnectTimeout(this.HTTP_GET_TIMOUT_MILLIS) 56 | .setSocketTimeout(this.HTTP_GET_TIMOUT_MILLIS) 57 | .setCookieSpec(CookieSpecs.STANDARD).build()) 58 | 59 | .setHeader("Accept", 60 | "text/html,application/xhtml+xml,application/xml,text/plain,*/*;q=0.5") 61 | .build(); 62 | 63 | final CloseableHttpClient httpClient = HttpClientBuilder.create() 64 | .build(); 65 | final HttpResponse response = httpClient.execute(request); 66 | httpClient.close(); 67 | 68 | return response; 69 | } 70 | 71 | private boolean isValidResponse(final HttpResponse response) { 72 | final int statusCode = response.getStatusLine().getStatusCode(); 73 | this.logger.debug("response status: " + statusCode); 74 | 75 | if (Integer.toString(statusCode).startsWith("4") 76 | || Integer.toString(statusCode).startsWith("5")) { 77 | return false; 78 | } else { 79 | switch (statusCode) { 80 | case 200: 81 | return true; 82 | default: 83 | throw new UnhandledHTTPResponseException(statusCode); 84 | } 85 | } 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/issues/labels/LexicalRelations.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues.labels; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.Issue; 4 | import at.ac.univie.mminf.qskos4j.issues.concepts.InvolvedConcepts; 5 | import at.ac.univie.mminf.qskos4j.result.NumberResult; 6 | import at.ac.univie.mminf.qskos4j.util.IssueDescriptor; 7 | import at.ac.univie.mminf.qskos4j.util.TupleQueryResultUtil; 8 | import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; 9 | import org.eclipse.rdf4j.RDF4JException; 10 | import org.eclipse.rdf4j.model.Value; 11 | import org.eclipse.rdf4j.query.QueryLanguage; 12 | import org.eclipse.rdf4j.query.TupleQueryResult; 13 | import org.slf4j.Logger; 14 | import org.slf4j.LoggerFactory; 15 | 16 | /** 17 | * Created by christian 18 | * Date: 26.01.13 19 | * Time: 13:58 20 | * 21 | * Finds the number of relations involving SKOS lexical labels (prefLabel, altLabel, hiddenLabel). 22 | * 23 | */ 24 | public class LexicalRelations extends Issue> { 25 | 26 | private final Logger logger = LoggerFactory.getLogger(LexicalRelations.class); 27 | 28 | private InvolvedConcepts involvedConcepts; 29 | 30 | public LexicalRelations(InvolvedConcepts involvedConcepts) { 31 | super(new IssueDescriptor.Builder( 32 | "clb", 33 | "Concept Labels", 34 | "Counts the number of relations between all concepts and lexical labels (prefLabel, altLabel, hiddenLabel and subproperties thereof)", 35 | IssueDescriptor.IssueType.STATISTICAL) 36 | .dependentIssue(involvedConcepts) 37 | .build() 38 | ); 39 | 40 | this.involvedConcepts = involvedConcepts; 41 | } 42 | 43 | @Override 44 | protected NumberResult invoke() throws RDF4JException { 45 | long relationsCount = 0; 46 | 47 | for (Value concept : involvedConcepts.getResult().getData()) { 48 | try { 49 | TupleQueryResult result = repCon.prepareTupleQuery( 50 | QueryLanguage.SPARQL, 51 | createLexicalLabelQuery(concept) 52 | ).evaluate(); 53 | 54 | relationsCount += TupleQueryResultUtil.countResults(result); 55 | } 56 | catch (RDF4JException e) { 57 | logger.error("Error finding labels for concept '" +concept+ "'", e); 58 | } 59 | } 60 | 61 | return new NumberResult<>(relationsCount); 62 | } 63 | 64 | private String createLexicalLabelQuery(Value concept) { 65 | return SparqlPrefix.SKOS +" "+ SparqlPrefix.SKOSXL +" "+ SparqlPrefix.RDFS + 66 | "SELECT DISTINCT ?skosLabelType ?literal WHERE " + 67 | "{" + 68 | "{<" +concept.stringValue()+ "> ?skosLabelType ?literal} " + 69 | "FILTER (?skosLabelType IN (skos:prefLabel, skos:altLabel, skos:hiddenLabel))" + 70 | "}"; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/issues/language/IncompleteLanguageCoverage.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues.language; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.Issue; 4 | import at.ac.univie.mminf.qskos4j.issues.language.util.LanguageCoverage; 5 | import at.ac.univie.mminf.qskos4j.util.IssueDescriptor; 6 | import org.eclipse.rdf4j.RDF4JException; 7 | import org.eclipse.rdf4j.model.Resource; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import java.util.*; 12 | 13 | /** 14 | * Finds all concepts with incomplete language coverage (Incomplete Language Coverage 15 | */ 16 | public class IncompleteLanguageCoverage extends Issue { 17 | 18 | private Map> incompleteLanguageCoverage; 19 | private LanguageCoverage languageCoverage; 20 | private Set distinctLanguages; 21 | 22 | public IncompleteLanguageCoverage(LanguageCoverage languageCoverage) { 23 | super(new IssueDescriptor.Builder( 24 | "ilc", 25 | "Incomplete Language Coverage", 26 | "Finds concepts lacking description in languages that are present for other concepts", 27 | IssueDescriptor.IssueType.ANALYTICAL) 28 | .weblink("https://github.com/cmader/qSKOS/wiki/Quality-Issues#incomplete-language-coverage") 29 | .dependentIssue(languageCoverage) 30 | .build() 31 | ); 32 | 33 | this.languageCoverage = languageCoverage; 34 | } 35 | 36 | @Override 37 | protected IncompleteLangCovResult invoke() throws RDF4JException { 38 | incompleteLanguageCoverage = new HashMap<>(); 39 | 40 | findDistinctLanguages(); 41 | generateIncompleteLanguageCoverageMap(); 42 | 43 | return new IncompleteLangCovResult(incompleteLanguageCoverage); 44 | } 45 | 46 | private void findDistinctLanguages() throws RDF4JException { 47 | distinctLanguages = new HashSet<>(); 48 | for (Collection languages : languageCoverage.getResult().getData().values()) { 49 | distinctLanguages.addAll(languages); 50 | } 51 | } 52 | 53 | private void generateIncompleteLanguageCoverageMap() throws RDF4JException { 54 | incompleteLanguageCoverage = new HashMap<>(); 55 | 56 | Map> langCovData = languageCoverage.getResult().getData(); 57 | 58 | for (Resource resource : langCovData.keySet()) { 59 | Collection coveredLanguages = langCovData.get(resource); 60 | Collection notCoveredLanguages = getNotCoveredLanguages(coveredLanguages); 61 | if (!notCoveredLanguages.isEmpty()) { 62 | incompleteLanguageCoverage.put(resource, notCoveredLanguages); 63 | } 64 | } 65 | } 66 | 67 | private Collection getNotCoveredLanguages(Collection coveredLanguages) { 68 | Set ret = new HashSet(distinctLanguages); 69 | ret.removeAll(coveredLanguages); 70 | return ret; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/issues/conceptscheme/MappingRelationsMisuse.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues.conceptscheme; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.Issue; 4 | import at.ac.univie.mminf.qskos4j.issues.concepts.AuthoritativeConcepts; 5 | import at.ac.univie.mminf.qskos4j.result.CollectionResult; 6 | import at.ac.univie.mminf.qskos4j.util.IssueDescriptor; 7 | import at.ac.univie.mminf.qskos4j.util.vocab.SkosOntology; 8 | import org.eclipse.rdf4j.RDF4JException; 9 | import org.eclipse.rdf4j.model.Resource; 10 | import org.eclipse.rdf4j.model.Statement; 11 | import org.eclipse.rdf4j.repository.RepositoryResult; 12 | 13 | import java.util.ArrayList; 14 | import java.util.Collection; 15 | 16 | public class MappingRelationsMisuse extends Issue> { 17 | 18 | private AuthoritativeConcepts authoritativeConcepts; 19 | 20 | public MappingRelationsMisuse(AuthoritativeConcepts authoritativeConcepts) { 21 | super(new IssueDescriptor.Builder( 22 | "mri", 23 | "Mapping Relations Misuse", 24 | "Finds concepts within the same concept scheme that are related by a mapping relation", 25 | IssueDescriptor.IssueType.ANALYTICAL) 26 | .weblink("https://github.com/cmader/qSKOS/wiki/Quality-Issues#mapping-relations-misuse") 27 | .dependentIssue(authoritativeConcepts) 28 | .build()); 29 | 30 | this.authoritativeConcepts = authoritativeConcepts; 31 | } 32 | 33 | @Override 34 | protected CollectionResult invoke() throws RDF4JException { 35 | Collection problematicRelations = new ArrayList<>(); 36 | 37 | RepositoryResult result = repCon.getStatements( 38 | null, 39 | SkosOntology.getInstance().getUri("mappingRelation"), 40 | null, 41 | true); 42 | while (result.hasNext()) { 43 | Statement st = result.next(); 44 | Resource concept = st.getSubject(); 45 | Resource otherConcept = (Resource) st.getObject(); 46 | 47 | if (areAuthoritativeConcepts(concept, otherConcept) && 48 | (ConceptSchemeUtil.inSameConceptScheme(concept, otherConcept, repCon) || 49 | ConceptSchemeUtil.inNoConceptScheme(concept, otherConcept, repCon))) 50 | { 51 | problematicRelations.add(st); 52 | } 53 | } 54 | 55 | return new CollectionResult<>(problematicRelations); 56 | } 57 | 58 | private boolean areAuthoritativeConcepts(Resource... concepts) throws RDF4JException { 59 | for (Resource concept : concepts) { 60 | boolean isAuthoritativeConcept = false; 61 | for (Resource authoritativeConcept : authoritativeConcepts.getResult().getData()) { 62 | if (concept.equals(authoritativeConcept)) isAuthoritativeConcept = true; 63 | } 64 | if (!isAuthoritativeConcept) return false; 65 | } 66 | 67 | return true; 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/test/resources/concepts.rdf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | deprecated 41 | 42 | 43 | 44 | 45 | 46 | 47 | editorial Note 48 | blubb 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | Expert Approval needed 57 | Expertenfreigabe erforderlich 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/issues/conceptscheme/TopConceptsHavingBroaderConcepts.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues.conceptscheme; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.Issue; 4 | import at.ac.univie.mminf.qskos4j.result.CollectionResult; 5 | import at.ac.univie.mminf.qskos4j.util.IssueDescriptor; 6 | import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; 7 | import org.eclipse.rdf4j.RDF4JException; 8 | import org.eclipse.rdf4j.model.IRI; 9 | import org.eclipse.rdf4j.model.Value; 10 | import org.eclipse.rdf4j.model.ValueFactory; 11 | import org.eclipse.rdf4j.model.impl.SimpleValueFactory; 12 | import org.eclipse.rdf4j.query.BindingSet; 13 | import org.eclipse.rdf4j.query.QueryLanguage; 14 | import org.eclipse.rdf4j.query.TupleQuery; 15 | import org.eclipse.rdf4j.query.TupleQueryResult; 16 | 17 | import java.net.URL; 18 | import java.util.ArrayList; 19 | import java.util.Collection; 20 | import java.util.List; 21 | 22 | /** 23 | * Finds top concepts that have broader concepts ( 24 | * Top Concepts Having Broader Concepts 25 | */ 26 | public class TopConceptsHavingBroaderConcepts extends Issue> { 27 | 28 | private ValueFactory factory = SimpleValueFactory.getInstance(); 29 | 30 | public TopConceptsHavingBroaderConcepts() { 31 | super(new IssueDescriptor.Builder("tchbc", 32 | "Top Concepts Having Broader Concepts", 33 | "Finds top concepts internal to the vocabulary hierarchy tree", 34 | IssueDescriptor.IssueType.ANALYTICAL) 35 | .weblink("https://github.com/cmader/qSKOS/wiki/Quality-Issues#top-concepts-having-broader-concepts") 36 | .build()); 37 | } 38 | 39 | @Override 40 | protected CollectionResult invoke() throws RDF4JException { 41 | TupleQuery query = repCon.prepareTupleQuery(QueryLanguage.SPARQL, createTopConceptsHavingBroaderConceptQuery()); 42 | return new CollectionResult<>(createUriResultList(query.evaluate())); 43 | } 44 | 45 | private String createTopConceptsHavingBroaderConceptQuery() { 46 | return SparqlPrefix.SKOS + 47 | "SELECT DISTINCT ?topConcept WHERE " + 48 | "{" + 49 | "{?topConcept skos:topConceptOf ?conceptScheme1}" + 50 | "UNION" + 51 | "{?conceptScheme2 skos:hasTopConcept ?topConcept}" + 52 | "?topConcept skos:broader|skos:broaderTransitive|^skos:narrower|^skos:narrowerTransitive ?broaderConcept ." + 53 | "}"; 54 | } 55 | 56 | private Collection createUriResultList(TupleQueryResult result) throws RDF4JException 57 | { 58 | List resultList = new ArrayList<>(); 59 | 60 | while (result.hasNext()) { 61 | BindingSet queryResult = result.next(); 62 | IRI resource = (IRI) queryResult.getValue("topConcept"); 63 | resultList.add(resource); 64 | } 65 | 66 | return resultList; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/at/ac/univie/mminf/qskos4j/issues/conceptscheme/ConceptSchemes.java: -------------------------------------------------------------------------------- 1 | package at.ac.univie.mminf.qskos4j.issues.conceptscheme; 2 | 3 | import at.ac.univie.mminf.qskos4j.issues.Issue; 4 | import at.ac.univie.mminf.qskos4j.result.CollectionResult; 5 | import at.ac.univie.mminf.qskos4j.util.IssueDescriptor; 6 | import at.ac.univie.mminf.qskos4j.util.vocab.SparqlPrefix; 7 | import org.eclipse.rdf4j.RDF4JException; 8 | import org.eclipse.rdf4j.model.Resource; 9 | import org.eclipse.rdf4j.model.Value; 10 | import org.eclipse.rdf4j.query.QueryEvaluationException; 11 | import org.eclipse.rdf4j.query.QueryLanguage; 12 | import org.eclipse.rdf4j.query.TupleQueryResult; 13 | import org.slf4j.Logger; 14 | import org.slf4j.LoggerFactory; 15 | 16 | import java.util.Collection; 17 | import java.util.HashSet; 18 | 19 | /** 20 | * Created by christian 21 | * Date: 26.01.13 22 | * Time: 14:23 23 | * 24 | * Finds the number of SKOS ConceptSchemes. 25 | */ 26 | public class ConceptSchemes extends Issue> { 27 | 28 | private final Logger logger = LoggerFactory.getLogger(ConceptSchemes.class); 29 | 30 | public ConceptSchemes() { 31 | super(new IssueDescriptor.Builder("cs", 32 | "Concept Schemes", 33 | "Finds the involved ConceptSchemes", 34 | IssueDescriptor.IssueType.STATISTICAL).build()); 35 | } 36 | 37 | @Override 38 | protected CollectionResult invoke() throws RDF4JException { 39 | TupleQueryResult result = repCon.prepareTupleQuery(QueryLanguage.SPARQL, createConceptSchemeQuery()).evaluate(); 40 | return new CollectionResult<>(identifyResources(result)); 41 | } 42 | 43 | private String createConceptSchemeQuery() { 44 | return SparqlPrefix.SKOS +" "+ SparqlPrefix.RDFS +" "+ SparqlPrefix.RDF + 45 | "SELECT DISTINCT ?resource WHERE {" + 46 | "{?resource rdf:type skos:ConceptScheme}" + 47 | "UNION" + 48 | "{?resource ?hasTopConcept ?concept . ?hasTopConcept rdfs:subPropertyOf skos:hasTopConcept}" + 49 | "UNION" + 50 | "{?concept ?topConceptOf ?resource . ?topConceptOf rdfs:subPropertyOf skos:topConceptOf}" + 51 | "UNION" + 52 | "{?concept ?inScheme ?resource . ?inScheme rdfs:subPropertyOf skos:inScheme}"+ 53 | "}"; 54 | } 55 | 56 | private Collection identifyResources(TupleQueryResult result) throws QueryEvaluationException 57 | { 58 | Collection allResources = new HashSet(); 59 | 60 | while (result.hasNext()) { 61 | Value conceptScheme = result.next().getValue("resource"); 62 | 63 | try { 64 | allResources.add((Resource) conceptScheme); 65 | } 66 | catch (ClassCastException e) { 67 | logger.error("Resource expected for conceptscheme " +conceptScheme.toString()+ ", " +e.toString()); 68 | } 69 | } 70 | 71 | return allResources; 72 | } 73 | } 74 | --------------------------------------------------------------------------------