You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by st...@apache.org on 2017/02/16 11:56:22 UTC
[07/12] commons-rdf git commit: COMMONSRDF-47: Add RDFSyntax.iri()
COMMONSRDF-47: Add RDFSyntax.iri()
as proposed by @ansell in
https://github.com/apache/commons-rdf/pull/27#discussion_r88350517
Project: http://git-wip-us.apache.org/repos/asf/commons-rdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rdf/commit/81d5b320
Tree: http://git-wip-us.apache.org/repos/asf/commons-rdf/tree/81d5b320
Diff: http://git-wip-us.apache.org/repos/asf/commons-rdf/diff/81d5b320
Branch: refs/heads/master
Commit: 81d5b320b62e7165b178e0a34c5157105f57e4af
Parents: db17f1a
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Thu Feb 9 01:35:43 2017 +0000
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Thu Feb 9 01:35:43 2017 +0000
----------------------------------------------------------------------
.../org/apache/commons/rdf/api/RDFSyntax.java | 67 ++++++++++--------
.../apache/commons/rdf/api/W3CRDFSyntax.java | 73 +++++++++++++++++---
2 files changed, 103 insertions(+), 37 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/81d5b320/api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java b/api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java
index 3bd1249..657fbc3 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java
@@ -106,8 +106,7 @@ public interface RDFSyntax {
/**
* A short name of the RDF Syntax e.g. <code>JSONLD</code>.
* <p>
- * The name is specific to Commons RDF and carries no particular meaning
- * except that it matches the constants like {@link #JSONLD}.
+ * The name is specific to Commons RDF and carries no particular meaning.
*
* @return Short name for RDF syntax
*/
@@ -148,7 +147,43 @@ public interface RDFSyntax {
* Datasets</a>.
*/
public boolean supportsDataset();
-
+
+ /**
+ * Return the {@link IRI} that <em>identifies</em> the RDF syntax.
+ * <p>
+ * Note that the identifying IRI is generally distinct from the IRI of the
+ * document that <em>specifies</em> the RDF syntax.
+ *
+ * @return Identifying IRI, e.g.
+ * <code>http://www.w3.org/ns/formats/JSON-LD</code>
+ */
+ public IRI iri();
+
+ /**
+ * Compare this RDFSyntax with another object.
+ * <p>
+ * Two {@link RDFSyntax}es are considered equal if their
+ * {@link #mediaType()}s are equal when compared as lower case strings
+ * according to {@link String#toLowerCase(Locale)} with the locale
+ * {@link Locale#ROOT}.
+ *
+ * @param obj
+ * @return
+ */
+ @Override
+ boolean equals(Object obj);
+
+ /**
+ * The hash code of an RDFSyntax is equivalent to the hash code
+ * of the {@link #mediaType()} in lower case according to
+ * {@link String#toLowerCase(Locale)} with the locale
+ * {@link Locale#ROOT}.
+ *
+ * @return Hash code of RDFSyntax
+ */
+ @Override
+ int hashCode();
+
/**
* Return the RDF 1.1 serialization syntaxes.
* <p>
@@ -235,30 +270,6 @@ public interface RDFSyntax {
public static Optional<RDFSyntax> byName(final String name) {
return w3cSyntaxes().stream().filter(t -> t.name().equals(name)).findAny();
}
-
- /**
- * Compare this RDFSyntax with another object.
- * <p>
- * Two {@link RDFSyntax}es are considered equal if their
- * {@link #mediaType()}s are equal when compared as lower case strings
- * according to {@link String#toLowerCase(Locale)} with the locale
- * {@link Locale#ROOT}.
- *
- * @param obj
- * @return
- */
- @Override
- boolean equals(Object obj);
-
- /**
- * The hash code of an RDFSyntax is equivalent to the hash code
- * of the {@link #mediaType()} in lower case according to
- * {@link String#toLowerCase(Locale)} with the locale
- * {@link Locale#ROOT}.
- *
- * @return Hash code of RDFSyntax
- */
- @Override
- int hashCode();
+
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/81d5b320/api/src/main/java/org/apache/commons/rdf/api/W3CRDFSyntax.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/W3CRDFSyntax.java b/api/src/main/java/org/apache/commons/rdf/api/W3CRDFSyntax.java
index 4ddc6c2..82b6692 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/W3CRDFSyntax.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/W3CRDFSyntax.java
@@ -41,19 +41,66 @@ import java.util.Set;
*/
final class W3CRDFSyntax implements RDFSyntax {
+
+ /**
+ * IRI representing a <a href="https://www.w3.org/ns/formats/">W3C RDF
+ * format</a>.
+ */
+ private final static class FormatIRI implements IRI {
+ private static String BASE = "http://www.w3.org/ns/formats/";
+ private final String format;
+
+ private FormatIRI(final String format) {
+ this.format = format;
+ }
+
+ @Override
+ public String getIRIString() {
+ return BASE + format;
+ }
+
+ @Override
+ public String ntriplesString() {
+ return "<" + getIRIString() + ">";
+ }
+
+ @Override
+ public String toString() {
+ return ntriplesString();
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || !(obj instanceof IRI)) {
+ return false;
+ }
+ final IRI other = (IRI) obj;
+ return getIRIString().equals(other.getIRIString());
+ }
+
+ @Override
+ public int hashCode() {
+ return getIRIString().hashCode();
+ }
+ }
+
+
static final RDFSyntax JSONLD, TURTLE, NQUADS, NTRIPLES, RDFA_HTML, RDFA_XHTML, RDFXML, TRIG;
static final Set<RDFSyntax> syntaxes;
static {
// Initialize within static block to avoid inserting nulls
- JSONLD = new W3CRDFSyntax("JSONLD", "JSON-LD 1.0", "application/ld+json", ".jsonld", true);
- TURTLE = new W3CRDFSyntax("TURTLE", "RDF 1.1 Turtle", "text/turtle", ".ttl", false);
- NQUADS = new W3CRDFSyntax("NQUADS", "RDF 1.1 N-Quads", "application/n-quads", ".nq", true);
- NTRIPLES = new W3CRDFSyntax("NTRIPLES", "RDF 1.1 N-Triples", "application/n-triples", ".nt", false);
- RDFA_HTML = new W3CRDFSyntax("RDFA_HTML", "HTML+RDFa 1.1", "text/html", ".html", false);
- RDFA_XHTML = new W3CRDFSyntax("RDFA_XHTML", "XHTML+RDFa 1.1", "application/xhtml+xml", ".xhtml", false);
- RDFXML = new W3CRDFSyntax("RDFXML", "RDF 1.1 XML Syntax", "application/rdf+xml", ".rdf", false);
- TRIG = new W3CRDFSyntax("TRIG", "RDF 1.1 TriG", "application/trig", ".trig", true);
+ JSONLD = new W3CRDFSyntax("JSON-LD", "JSON-LD 1.0", "application/ld+json", ".jsonld", true);
+ TURTLE = new W3CRDFSyntax("Turtle", "RDF 1.1 Turtle", "text/turtle", ".ttl", false);
+ NQUADS = new W3CRDFSyntax("N-Quads", "RDF 1.1 N-Quads", "application/n-quads", ".nq", true);
+ NTRIPLES = new W3CRDFSyntax("N-Triples", "RDF 1.1 N-Triples", "application/n-triples", ".nt", false);
+ RDFA_HTML = new W3CRDFSyntax("RDFa", "HTML+RDFa 1.1", "text/html", ".html", false);
+ RDFA_XHTML = new W3CRDFSyntax("RDFa", "XHTML+RDFa 1.1", "application/xhtml+xml", ".xhtml", false);
+ RDFXML = new W3CRDFSyntax("RDF_XML", "RDF 1.1 XML Syntax", "application/rdf+xml", ".rdf", false);
+ TRIG = new W3CRDFSyntax("TriG", "RDF 1.1 TriG", "application/trig", ".trig", true);
syntaxes = Collections.unmodifiableSet(new LinkedHashSet<>(
Arrays.asList(JSONLD, NQUADS, NTRIPLES, RDFA_HTML, RDFA_XHTML, RDFXML, TRIG, TURTLE)));
@@ -64,10 +111,12 @@ final class W3CRDFSyntax implements RDFSyntax {
private final String mediaType;
private final String fileExtension;
-
+
private final boolean supportsDataset;
private final String name;
+
+ private final IRI iri;
private W3CRDFSyntax(String name, String title, String mediaType, String fileExtension, boolean supportsDataset) {
this.name = name;
@@ -75,6 +124,7 @@ final class W3CRDFSyntax implements RDFSyntax {
this.mediaType = mediaType.toLowerCase(Locale.ROOT);
this.fileExtension = fileExtension.toLowerCase(Locale.ROOT);
this.supportsDataset = supportsDataset;
+ this.iri = new FormatIRI(name);
}
/**
@@ -115,6 +165,11 @@ final class W3CRDFSyntax implements RDFSyntax {
public String name() {
return name;
}
+
+ @Override
+ public IRI iri() {
+ return iri;
+ }
@Override
public boolean equals(Object obj) {