From 3bbee4990d0b5837bf5341852f6db70924a8f0db Mon Sep 17 00:00:00 2001 From: Dimitris Kontokostas Date: Sat, 26 Sep 2015 12:31:00 +0100 Subject: [PATCH] LOV dependency #34 #39 --- .../org/aksw/rdfunit/prefix/LOVEndpoint.java | 35 ++++++++++++++++++ .../org/aksw/rdfunit/prefix/SchemaEntry.java | 36 ++++++++++--------- 2 files changed, 54 insertions(+), 17 deletions(-) diff --git a/rdfunit-core/src/main/java/org/aksw/rdfunit/prefix/LOVEndpoint.java b/rdfunit-core/src/main/java/org/aksw/rdfunit/prefix/LOVEndpoint.java index 64b2f7c19..fdeac85bf 100644 --- a/rdfunit-core/src/main/java/org/aksw/rdfunit/prefix/LOVEndpoint.java +++ b/rdfunit-core/src/main/java/org/aksw/rdfunit/prefix/LOVEndpoint.java @@ -8,7 +8,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.*; import java.util.Arrays; +import java.util.Collections; import java.util.LinkedList; import java.util.List; @@ -78,4 +80,37 @@ public List getAllLOVEntries() { return lovEntries; } + + public void writeAllLOVEntriesToFile(String filename) { + + List lovEntries = getAllLOVEntries(); + Collections.sort(lovEntries); + String header = + "#This file is auto-generated from the (amazing) LOV service" + + "# if you don't want to load this use the available CLI / code options " + + "# To override some of it's entries use the schemaDecl.csv"; + + + try (Writer out = new BufferedWriter(new OutputStreamWriter( + new FileOutputStream("outfilename"), "UTF-8")) ){ + + out.write(header); + out.write("\n"); + + for (SchemaEntry entry: lovEntries) { + out.write(entry.getPrefix()); + out.write(','); + out.write(entry.getVocabularyURI()); + if (!entry.getVocabularyDefinedBy().isEmpty()) { + out.write(','); + out.write(entry.getVocabularyDefinedBy()); + } + out.write('\n'); + } + } catch (UnsupportedEncodingException e) { + } catch (IOException e) { + } + + + } } diff --git a/rdfunit-core/src/main/java/org/aksw/rdfunit/prefix/SchemaEntry.java b/rdfunit-core/src/main/java/org/aksw/rdfunit/prefix/SchemaEntry.java index 93616be9e..ae43b3807 100644 --- a/rdfunit-core/src/main/java/org/aksw/rdfunit/prefix/SchemaEntry.java +++ b/rdfunit-core/src/main/java/org/aksw/rdfunit/prefix/SchemaEntry.java @@ -1,5 +1,7 @@ package org.aksw.rdfunit.prefix; +import com.google.common.base.Objects; + /** * Encapsulates an LOV Entry * @@ -76,33 +78,33 @@ public String getVocabularyDefinedBy() { return vocabularyDefinedBy; } - /** {@inheritDoc} */ @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - SchemaEntry lovEntry = (SchemaEntry) o; - - return prefix.equals(lovEntry.prefix); + public int hashCode() { + return Objects.hashCode(prefix, vocabularyURI, vocabularyNamespace, vocabularyDefinedBy); } - /** {@inheritDoc} */ @Override - public int hashCode() { - int result = prefix.hashCode(); - result = 31 * result + vocabularyURI.hashCode(); - result = 31 * result + vocabularyNamespace.hashCode(); - result = 31 * result + vocabularyDefinedBy.hashCode(); - return result; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + final SchemaEntry other = (SchemaEntry) obj; + return Objects.equal(this.prefix, other.prefix) + && Objects.equal(this.vocabularyURI, other.vocabularyURI) + && Objects.equal(this.vocabularyNamespace, other.vocabularyNamespace) + && Objects.equal(this.vocabularyDefinedBy, other.vocabularyDefinedBy); } - /** {@inheritDoc} */ @Override public String toString() { - return "LOVEntry{" + + return "SchemaEntry{" + "prefix='" + prefix + '\'' + ", vocabularyURI='" + vocabularyURI + '\'' + + ", vocabularyNamespace='" + vocabularyNamespace + '\'' + + ", vocabularyDefinedBy='" + vocabularyDefinedBy + '\'' + '}'; }