You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/11/03 15:45:58 UTC
(commons-rdf) 02/04: Sort main members
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-rdf.git
commit 5e2ba9f1459f64e57b180a25de7cb913e741ce13
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Nov 3 11:44:45 2023 -0400
Sort main members
---
.../java/org/apache/commons/rdf/api/BlankNode.java | 52 +--
.../java/org/apache/commons/rdf/api/Dataset.java | 228 +++++------
.../java/org/apache/commons/rdf/api/Graph.java | 196 +++++-----
.../java/org/apache/commons/rdf/api/GraphLike.java | 34 +-
.../main/java/org/apache/commons/rdf/api/IRI.java | 20 +-
.../java/org/apache/commons/rdf/api/Literal.java | 58 +--
.../main/java/org/apache/commons/rdf/api/Quad.java | 140 +++----
.../main/java/org/apache/commons/rdf/api/RDF.java | 64 ++--
.../java/org/apache/commons/rdf/api/RDFSyntax.java | 238 ++++++------
.../java/org/apache/commons/rdf/api/RDFTerm.java | 20 +-
.../java/org/apache/commons/rdf/api/Triple.java | 62 +--
.../org/apache/commons/rdf/api/TripleLike.java | 14 +-
.../org/apache/commons/rdf/api/W3CRDFSyntax.java | 94 ++---
.../apache/commons/rdf/experimental/RDFParser.java | 416 ++++++++++-----------
14 files changed, 818 insertions(+), 818 deletions(-)
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/BlankNode.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/BlankNode.java
index c1ff6285..f91fd4c5 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/BlankNode.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/BlankNode.java
@@ -58,32 +58,6 @@ import java.util.UUID;
*/
public interface BlankNode extends BlankNodeOrIRI {
- /**
- * Return a reference for uniquely identifying the blank node.
- * <p>
- * The reference string MUST universally and uniquely identify this blank
- * node. That is, different blank nodes created separately in different JVMs
- * or from different {@link RDF} instances MUST NOT have the same reference
- * string.
- * <p>
- * The {@link #uniqueReference()} of two <code>BlankNode</code> instances
- * MUST be equal if and only if the two blank nodes are equal according to
- * {@link #equals(Object)}.
- * <p>
- * Clients should not assume any particular structure of the reference
- * string, however it is recommended that the reference string contain a
- * UUID-derived string, e.g. as returned from {@link UUID#toString()}.
- * <p>
- * <strong>IMPORTANT:</strong> This is not a
- * <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-blank-node-identifier">
- * blank node identifier</a> nor a serialization/syntax label, and there are
- * no guarantees that it is a valid identifier in any concrete RDF syntax.
- * For an N-Triples compatible identifier, use {@link #ntriplesString()}.
- *
- * @return A universally unique reference to identify this {@link BlankNode}
- */
- String uniqueReference();
-
/**
* Check it this BlankNode is equal to another BlankNode. Two BlankNodes
* MUST be equal if, and only if, they have the same
@@ -117,4 +91,30 @@ public interface BlankNode extends BlankNodeOrIRI {
@Override
int hashCode();
+ /**
+ * Return a reference for uniquely identifying the blank node.
+ * <p>
+ * The reference string MUST universally and uniquely identify this blank
+ * node. That is, different blank nodes created separately in different JVMs
+ * or from different {@link RDF} instances MUST NOT have the same reference
+ * string.
+ * <p>
+ * The {@link #uniqueReference()} of two <code>BlankNode</code> instances
+ * MUST be equal if and only if the two blank nodes are equal according to
+ * {@link #equals(Object)}.
+ * <p>
+ * Clients should not assume any particular structure of the reference
+ * string, however it is recommended that the reference string contain a
+ * UUID-derived string, e.g. as returned from {@link UUID#toString()}.
+ * <p>
+ * <strong>IMPORTANT:</strong> This is not a
+ * <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-blank-node-identifier">
+ * blank node identifier</a> nor a serialization/syntax label, and there are
+ * no guarantees that it is a valid identifier in any concrete RDF syntax.
+ * For an N-Triples compatible identifier, use {@link #ntriplesString()}.
+ *
+ * @return A universally unique reference to identify this {@link BlankNode}
+ */
+ String uniqueReference();
+
}
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/Dataset.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/Dataset.java
index 761c3520..3441b105 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/Dataset.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/Dataset.java
@@ -33,16 +33,6 @@ import java.util.stream.Stream;
*/
public interface Dataset extends AutoCloseable, GraphLike<Quad> {
- /**
- * Add a quad to the dataset, possibly mapping any of the components of the
- * Quad to those supported by this dataset.
- *
- * @param quad
- * The quad to add
- */
- @Override
- void add(Quad quad);
-
/**
* Add a quad to the dataset, possibly mapping any of the components to
* those supported by this dataset.
@@ -60,14 +50,36 @@ public interface Dataset extends AutoCloseable, GraphLike<Quad> {
void add(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
/**
- * Check if dataset contains quad.
+ * Add a quad to the dataset, possibly mapping any of the components of the
+ * Quad to those supported by this dataset.
*
* @param quad
- * The quad to check.
- * @return True if the dataset contains the given Quad.
+ * The quad to add
*/
@Override
- boolean contains(Quad quad);
+ void add(Quad quad);
+
+ /**
+ * Clear the dataset, removing all quads.
+ */
+ @Override
+ void clear();
+
+ /**
+ * Close the dataset, relinquishing any underlying resources.
+ * <p>
+ * For example, this would close any open file and network streams and free
+ * database locks held by the dataset implementation.
+ * <p>
+ * The behavior of the other dataset methods are undefined after closing
+ * the dataset.
+ * <p>
+ * Implementations might not need {@link #close()}, hence the default
+ * implementation does nothing.
+ */
+ @Override
+ default void close() throws Exception {
+ }
/**
* Check if dataset contains a pattern of quads.
@@ -88,20 +100,14 @@ public interface Dataset extends AutoCloseable, GraphLike<Quad> {
boolean contains(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
/**
- * Close the dataset, relinquishing any underlying resources.
- * <p>
- * For example, this would close any open file and network streams and free
- * database locks held by the dataset implementation.
- * <p>
- * The behavior of the other dataset methods are undefined after closing
- * the dataset.
- * <p>
- * Implementations might not need {@link #close()}, hence the default
- * implementation does nothing.
+ * Check if dataset contains quad.
+ *
+ * @param quad
+ * The quad to check.
+ * @return True if the dataset contains the given Quad.
*/
@Override
- default void close() throws Exception {
- }
+ boolean contains(Quad quad);
/**
* Gets the default graph of this dataset.
@@ -176,94 +182,6 @@ public interface Dataset extends AutoCloseable, GraphLike<Quad> {
return size() == 0;
}
- /**
- * Remove a concrete quad from the dataset.
- *
- * @param quad
- * quad to remove
- */
- @Override
- void remove(Quad quad);
-
- /**
- * Remove a concrete pattern of quads from the default graph of the dataset.
- *
- * @param graphName
- * The graph the quad belongs to, wrapped as an {@link Optional}
- * (<code>null</code> is a wildcard, {@link Optional#empty()} is
- * the default graph)
- * @param subject
- * The quad subject (<code>null</code> is a wildcard)
- * @param predicate
- * The quad predicate (<code>null</code> is a wildcard)
- * @param object
- * The quad object (<code>null</code> is a wildcard)
- */
- void remove(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
-
- /**
- * Clear the dataset, removing all quads.
- */
- @Override
- void clear();
-
- /**
- * Number of quads contained by the dataset.
- * <p>
- * The count of a set does not include duplicates, consistent with the
- * {@link Quad#equals(Object)} equals method for each {@link Quad}.
- *
- * @return The number of quads in the dataset
- */
- @Override
- long size();
-
- /**
- * Gets all quads contained by the dataset.<br>
- * <p>
- * The iteration does not contain any duplicate quads, as determined by the
- * {@link Quad#equals(Object)} method for each {@link Quad}.
- * <p>
- * The behavior of the {@link Stream} is not specified if
- * {@link #add(Quad)}, {@link #remove(Quad)} or {@link #clear()} are called
- * on the {@link Dataset} before it terminates.
- * <p>
- * Implementations may throw {@link ConcurrentModificationException} from
- * Stream methods if they detect a conflict while the Stream is active.
- *
- * @return A {@link Stream} over all of the quads in the dataset
- */
- @Override
- Stream<? extends Quad> stream();
-
- /**
- * Gets all quads contained by the dataset matched with the pattern.
- * <p>
- * The iteration does not contain any duplicate quads, as determined by the
- * {@link Quad#equals(Object)} method for each {@link Quad}.
- * <p>
- * The behavior of the {@link Stream} is not specified if
- * {@link #add(Quad)}, {@link #remove(Quad)} or {@link #clear()} are called
- * on the {@link Dataset} before it terminates.
- * <p>
- * Implementations may throw {@link ConcurrentModificationException} from
- * Stream methods if they detect a conflict while the Stream is active.
- *
- * @param graphName
- * The graph the quad belongs to, wrapped as an {@link Optional}
- * (<code>null</code> is a wildcard, {@link Optional#empty()} is
- * the default graph)
- * @param subject
- * The quad subject (<code>null</code> is a wildcard)
- * @param predicate
- * The quad predicate (<code>null</code> is a wildcard)
- * @param object
- * The quad object (<code>null</code> is a wildcard)
- * @return A {@link Stream} over the matched quads.
- */
- Stream<? extends Quad> stream(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate,
- RDFTerm object);
-
/**
* Gets an Iterable for iterating over all quads in the dataset.
* <p>
@@ -361,4 +279,86 @@ public interface Dataset extends AutoCloseable, GraphLike<Quad> {
return ((Stream<Quad>) stream(graphName, subject, predicate, object))::iterator;
}
+ /**
+ * Remove a concrete pattern of quads from the default graph of the dataset.
+ *
+ * @param graphName
+ * The graph the quad belongs to, wrapped as an {@link Optional}
+ * (<code>null</code> is a wildcard, {@link Optional#empty()} is
+ * the default graph)
+ * @param subject
+ * The quad subject (<code>null</code> is a wildcard)
+ * @param predicate
+ * The quad predicate (<code>null</code> is a wildcard)
+ * @param object
+ * The quad object (<code>null</code> is a wildcard)
+ */
+ void remove(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
+
+ /**
+ * Remove a concrete quad from the dataset.
+ *
+ * @param quad
+ * quad to remove
+ */
+ @Override
+ void remove(Quad quad);
+
+ /**
+ * Number of quads contained by the dataset.
+ * <p>
+ * The count of a set does not include duplicates, consistent with the
+ * {@link Quad#equals(Object)} equals method for each {@link Quad}.
+ *
+ * @return The number of quads in the dataset
+ */
+ @Override
+ long size();
+
+ /**
+ * Gets all quads contained by the dataset.<br>
+ * <p>
+ * The iteration does not contain any duplicate quads, as determined by the
+ * {@link Quad#equals(Object)} method for each {@link Quad}.
+ * <p>
+ * The behavior of the {@link Stream} is not specified if
+ * {@link #add(Quad)}, {@link #remove(Quad)} or {@link #clear()} are called
+ * on the {@link Dataset} before it terminates.
+ * <p>
+ * Implementations may throw {@link ConcurrentModificationException} from
+ * Stream methods if they detect a conflict while the Stream is active.
+ *
+ * @return A {@link Stream} over all of the quads in the dataset
+ */
+ @Override
+ Stream<? extends Quad> stream();
+
+ /**
+ * Gets all quads contained by the dataset matched with the pattern.
+ * <p>
+ * The iteration does not contain any duplicate quads, as determined by the
+ * {@link Quad#equals(Object)} method for each {@link Quad}.
+ * <p>
+ * The behavior of the {@link Stream} is not specified if
+ * {@link #add(Quad)}, {@link #remove(Quad)} or {@link #clear()} are called
+ * on the {@link Dataset} before it terminates.
+ * <p>
+ * Implementations may throw {@link ConcurrentModificationException} from
+ * Stream methods if they detect a conflict while the Stream is active.
+ *
+ * @param graphName
+ * The graph the quad belongs to, wrapped as an {@link Optional}
+ * (<code>null</code> is a wildcard, {@link Optional#empty()} is
+ * the default graph)
+ * @param subject
+ * The quad subject (<code>null</code> is a wildcard)
+ * @param predicate
+ * The quad predicate (<code>null</code> is a wildcard)
+ * @param object
+ * The quad object (<code>null</code> is a wildcard)
+ * @return A {@link Stream} over the matched quads.
+ */
+ Stream<? extends Quad> stream(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate,
+ RDFTerm object);
+
}
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/Graph.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/Graph.java
index 9d3e6746..13f1ffde 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/Graph.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/Graph.java
@@ -31,16 +31,6 @@ import java.util.stream.Stream;
*/
public interface Graph extends AutoCloseable, GraphLike<Triple> {
- /**
- * Adds a triple to the graph, possibly mapping any of the components of the
- * Triple to those supported by this Graph.
- *
- * @param triple
- * The triple to add
- */
- @Override
- void add(Triple triple);
-
/**
* Adds a triple to the graph, possibly mapping any of the components to
* those supported by this Graph.
@@ -55,28 +45,20 @@ public interface Graph extends AutoCloseable, GraphLike<Triple> {
void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
/**
- * Checks if graph contains triple.
+ * Adds a triple to the graph, possibly mapping any of the components of the
+ * Triple to those supported by this Graph.
*
* @param triple
- * The triple to check.
- * @return True if the Graph contains the given Triple.
+ * The triple to add
*/
@Override
- boolean contains(Triple triple);
+ void add(Triple triple);
/**
- * Checks if graph contains a pattern of triples.
- *
- * @param subject
- * The triple subject (null is a wildcard)
- * @param predicate
- * The triple predicate (null is a wildcard)
- * @param object
- * The triple object (null is a wildcard)
- * @return True if the Graph contains any Triples that match the given
- * pattern.
+ * Clears the graph, removing all triples.
*/
- boolean contains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
+ @Override
+ void clear();
/**
* Closes the graph, relinquishing any underlying resources.
@@ -98,16 +80,7 @@ public interface Graph extends AutoCloseable, GraphLike<Triple> {
}
/**
- * Removes a concrete triple from the graph.
- *
- * @param triple
- * triple to remove
- */
- @Override
- void remove(Triple triple);
-
- /**
- * Removes a concrete pattern of triples from the graph.
+ * Checks if graph contains a pattern of triples.
*
* @param subject
* The triple subject (null is a wildcard)
@@ -115,75 +88,20 @@ public interface Graph extends AutoCloseable, GraphLike<Triple> {
* The triple predicate (null is a wildcard)
* @param object
* The triple object (null is a wildcard)
+ * @return True if the Graph contains any Triples that match the given
+ * pattern.
*/
- void remove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
-
- /**
- * Clears the graph, removing all triples.
- */
- @Override
- void clear();
-
- /**
- * Number of triples contained by the graph.
- * <p>
- * The count of a set does not include duplicates, consistent with the
- * {@link Triple#equals(Object)} equals method for each {@link Triple}.
- * </p>
- *
- * @return The number of triples in the graph
- */
- @Override
- long size();
+ boolean contains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
/**
- * Gets all triples contained by the graph.<br>
- * <p>
- * The iteration does not contain any duplicate triples, as determined by
- * the {@link Triple#equals(Object)} method for each {@link Triple}.
- * </p>
- * <p>
- * The behavior of the {@link Stream} is not specified if
- * {@link #add(Triple)}, {@link #remove(Triple)} or {@link #clear()} are
- * called on the {@link Graph} before it terminates.
- * </p>
- * <p>
- * Implementations may throw {@link ConcurrentModificationException} from
- * Stream methods if they detect a conflict while the Stream is active.
- * </p>
+ * Checks if graph contains triple.
*
- * @since 0.3.0-incubating
- * @return A {@link Stream} over all of the triples in the graph
+ * @param triple
+ * The triple to check.
+ * @return True if the Graph contains the given Triple.
*/
@Override
- Stream<? extends Triple> stream();
-
- /**
- * Gets all triples contained by the graph matched with the pattern.
- * <p>
- * The iteration does not contain any duplicate triples, as determined by
- * the {@link Triple#equals(Object)} method for each {@link Triple}.
- * </p>
- * <p>
- * The behavior of the {@link Stream} is not specified if
- * {@link #add(Triple)}, {@link #remove(Triple)} or {@link #clear()} are
- * called on the {@link Graph} before it terminates.
- * </p>
- * <p>
- * Implementations may throw {@link ConcurrentModificationException} from
- * Stream methods if they detect a conflict while the Stream is active.
- * </p>
- *
- * @since 0.3.0-incubating
- * @param subject
- * The triple subject (null is a wildcard)
- * @param predicate
- * The triple predicate (null is a wildcard)
- * @param object
- * The triple object (null is a wildcard)
- * @return A {@link Stream} over the matched triples.
- */
- Stream<? extends Triple> stream(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
+ boolean contains(Triple triple);
/**
* This method is deprecated, use the equivalent method {@link #stream()}
@@ -322,4 +240,86 @@ public interface Graph extends AutoCloseable, GraphLike<Triple> {
return ((Stream<Triple>) stream(subject, predicate, object))::iterator;
}
+ /**
+ * Removes a concrete pattern of triples from the graph.
+ *
+ * @param subject
+ * The triple subject (null is a wildcard)
+ * @param predicate
+ * The triple predicate (null is a wildcard)
+ * @param object
+ * The triple object (null is a wildcard)
+ */
+ void remove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
+
+ /**
+ * Removes a concrete triple from the graph.
+ *
+ * @param triple
+ * triple to remove
+ */
+ @Override
+ void remove(Triple triple);
+
+ /**
+ * Number of triples contained by the graph.
+ * <p>
+ * The count of a set does not include duplicates, consistent with the
+ * {@link Triple#equals(Object)} equals method for each {@link Triple}.
+ * </p>
+ *
+ * @return The number of triples in the graph
+ */
+ @Override
+ long size();
+
+ /**
+ * Gets all triples contained by the graph.<br>
+ * <p>
+ * The iteration does not contain any duplicate triples, as determined by
+ * the {@link Triple#equals(Object)} method for each {@link Triple}.
+ * </p>
+ * <p>
+ * The behavior of the {@link Stream} is not specified if
+ * {@link #add(Triple)}, {@link #remove(Triple)} or {@link #clear()} are
+ * called on the {@link Graph} before it terminates.
+ * </p>
+ * <p>
+ * Implementations may throw {@link ConcurrentModificationException} from
+ * Stream methods if they detect a conflict while the Stream is active.
+ * </p>
+ *
+ * @since 0.3.0-incubating
+ * @return A {@link Stream} over all of the triples in the graph
+ */
+ @Override
+ Stream<? extends Triple> stream();
+
+ /**
+ * Gets all triples contained by the graph matched with the pattern.
+ * <p>
+ * The iteration does not contain any duplicate triples, as determined by
+ * the {@link Triple#equals(Object)} method for each {@link Triple}.
+ * </p>
+ * <p>
+ * The behavior of the {@link Stream} is not specified if
+ * {@link #add(Triple)}, {@link #remove(Triple)} or {@link #clear()} are
+ * called on the {@link Graph} before it terminates.
+ * </p>
+ * <p>
+ * Implementations may throw {@link ConcurrentModificationException} from
+ * Stream methods if they detect a conflict while the Stream is active.
+ * </p>
+ *
+ * @since 0.3.0-incubating
+ * @param subject
+ * The triple subject (null is a wildcard)
+ * @param predicate
+ * The triple predicate (null is a wildcard)
+ * @param object
+ * The triple object (null is a wildcard)
+ * @return A {@link Stream} over the matched triples.
+ */
+ Stream<? extends Triple> stream(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
+
}
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/GraphLike.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/GraphLike.java
index 0a0a7033..f50423f8 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/GraphLike.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/GraphLike.java
@@ -55,6 +55,11 @@ public interface GraphLike<T extends TripleLike> {
*/
void add(T statement);
+ /**
+ * Remove all statements.
+ */
+ void clear();
+
/**
* Check if statement is contained.
*
@@ -64,6 +69,18 @@ public interface GraphLike<T extends TripleLike> {
*/
boolean contains(T statement);
+ /**
+ * Iterate over contained statements.
+ *
+ * @return An {@link Iterable} of {@link TripleLike} statements.
+ * @throws IllegalStateException
+ * if the {@link Iterable} has been reused
+ * @throws ConcurrentModificationException
+ * if a concurrency conflict occurs while the Iterator is
+ * active.
+ */
+ Iterable<T> iterate() throws ConcurrentModificationException, IllegalStateException;
+
/**
* Add a statement.
*
@@ -72,11 +89,6 @@ public interface GraphLike<T extends TripleLike> {
*/
void remove(T statement);
- /**
- * Remove all statements.
- */
- void clear();
-
/**
* Number of statements.
*
@@ -91,16 +103,4 @@ public interface GraphLike<T extends TripleLike> {
*/
Stream<? extends T> stream();
- /**
- * Iterate over contained statements.
- *
- * @return An {@link Iterable} of {@link TripleLike} statements.
- * @throws IllegalStateException
- * if the {@link Iterable} has been reused
- * @throws ConcurrentModificationException
- * if a concurrency conflict occurs while the Iterator is
- * active.
- */
- Iterable<T> iterate() throws ConcurrentModificationException, IllegalStateException;
-
}
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/IRI.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/IRI.java
index 75ec9941..e55f43b0 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/IRI.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/IRI.java
@@ -27,16 +27,6 @@ package org.apache.commons.rdf.api;
*/
public interface IRI extends BlankNodeOrIRI {
- /**
- * Return the IRI encoded as a native Unicode String.<br>
- *
- * The returned string must not include URL-encoding to escape non-ASCII
- * characters.
- *
- * @return The IRI encoded as a native Unicode String.
- */
- String getIRIString();
-
/**
* Check it this IRI is equal to another IRI. <blockquote>
* <a href="http://www.w3.org/TR/rdf11-concepts/#section-IRIs">IRI
@@ -59,6 +49,16 @@ public interface IRI extends BlankNodeOrIRI {
@Override
boolean equals(Object other);
+ /**
+ * Return the IRI encoded as a native Unicode String.<br>
+ *
+ * The returned string must not include URL-encoding to escape non-ASCII
+ * characters.
+ *
+ * @return The IRI encoded as a native Unicode String.
+ */
+ String getIRIString();
+
/**
* Calculate a hash code for this IRI.
* <p>
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/Literal.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/Literal.java
index 52d31fcb..96904f23 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/Literal.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/Literal.java
@@ -36,15 +36,30 @@ import java.util.Optional;
public interface Literal extends RDFTerm {
/**
- * The lexical form of this literal, represented by a
- * <a href="http://www.unicode.org/versions/latest/">Unicode string</a>.
+ * Check it this Literal is equal to another Literal.
+ * <blockquote>
+ * <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-literal-term">Literal
+ * term equality</a>:
+ * Two literals are term-equal (the same RDF literal) if
+ * and only if the two lexical forms, the two datatype IRIs, and the two
+ * language tags (if any) compare equal, character by character. Thus, two
+ * literals can have the same value without being the same RDF term.
+ * </blockquote>
+ * As the value space for language tags is lower-space, if they are present,
+ * they MUST be compared character by character
+ * using the equivalent of {@link String#toLowerCase(java.util.Locale)} with
+ * the locale {@link Locale#ROOT}.
+ * <p>
+ * Implementations MUST also override {@link #hashCode()} so that two equal
+ * Literals produce the same hash code.
*
- * @return The lexical form of this literal.
- * @see <a href=
- * "http://www.w3.org/TR/rdf11-concepts/#dfn-lexical-form">RDF-1.1
- * Literal lexical form</a>
+ * @param other
+ * Another object
+ * @return true if other is a Literal and is equal to this
+ * @see Object#equals(Object)
*/
- String getLexicalForm();
+ @Override
+ boolean equals(Object other);
/**
* The IRI identifying the datatype that determines how the lexical form
@@ -97,30 +112,15 @@ public interface Literal extends RDFTerm {
Optional<String> getLanguageTag();
/**
- * Check it this Literal is equal to another Literal.
- * <blockquote>
- * <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-literal-term">Literal
- * term equality</a>:
- * Two literals are term-equal (the same RDF literal) if
- * and only if the two lexical forms, the two datatype IRIs, and the two
- * language tags (if any) compare equal, character by character. Thus, two
- * literals can have the same value without being the same RDF term.
- * </blockquote>
- * As the value space for language tags is lower-space, if they are present,
- * they MUST be compared character by character
- * using the equivalent of {@link String#toLowerCase(java.util.Locale)} with
- * the locale {@link Locale#ROOT}.
- * <p>
- * Implementations MUST also override {@link #hashCode()} so that two equal
- * Literals produce the same hash code.
+ * The lexical form of this literal, represented by a
+ * <a href="http://www.unicode.org/versions/latest/">Unicode string</a>.
*
- * @param other
- * Another object
- * @return true if other is a Literal and is equal to this
- * @see Object#equals(Object)
+ * @return The lexical form of this literal.
+ * @see <a href=
+ * "http://www.w3.org/TR/rdf11-concepts/#dfn-lexical-form">RDF-1.1
+ * Literal lexical form</a>
*/
- @Override
- boolean equals(Object other);
+ String getLexicalForm();
/**
* Calculate a hash code for this Literal.
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/Quad.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/Quad.java
index 0df1d084..73f36268 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/Quad.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/Quad.java
@@ -60,61 +60,6 @@ import java.util.Optional;
*/
public interface Quad extends QuadLike<BlankNodeOrIRI> {
- /**
- * The graph name (graph label) of this quad, if present.
- *
- * If {@link Optional#isPresent()}, then the {@link Optional#get()} is
- * either a {@link BlankNode} or an {@link IRI}, indicating the
- * <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-named-graph">graph
- * name</a> of this Quad. If the graph name is not present, e.g. the value
- * is {@link Optional#empty()}, it indicates that this Quad is in the
- * <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-default-graph">default
- * graph</a>.
- *
- * @return If {@link Optional#isPresent()}, the graph name
- * {@link BlankNodeOrIRI} of this quad, otherwise
- * {@link Optional#empty()}, indicating the default graph.
- *
- * @see <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-dataset">RDF-
- * 1.1 Dataset</a>
- */
- @Override
- Optional<BlankNodeOrIRI> getGraphName();
-
- /**
- * The subject of this quad, which may be either a {@link BlankNode} or an
- * {@link IRI}, which are represented in Commons RDF by the interface
- * {@link BlankNodeOrIRI}.
- *
- * @return The subject {@link BlankNodeOrIRI} of this quad.
- * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-subject">RDF-1.1
- * Triple subject</a>
- */
- @Override
- BlankNodeOrIRI getSubject();
-
- /**
- * The predicate {@link IRI} of this quad.
- *
- * @return The predicate {@link IRI} of this quad.
- * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-predicate">RDF-1.1
- * Triple predicate</a>
- */
- @Override
- IRI getPredicate();
-
- /**
- * The object of this quad, which may be either a {@link BlankNode}, an
- * {@link IRI}, or a {@link Literal}, which are represented in Commons RDF
- * by the interface {@link RDFTerm}.
- *
- * @return The object {@link RDFTerm} of this quad.
- * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-object">RDF-1.1
- * Triple object</a>
- */
- @Override
- RDFTerm getObject();
-
/**
* Adapt this Quad to a Triple.
* <p>
@@ -152,21 +97,6 @@ public interface Quad extends QuadLike<BlankNodeOrIRI> {
*/
default Triple asTriple() {
return new Triple() {
- @Override
- public BlankNodeOrIRI getSubject() {
- return Quad.this.getSubject();
- }
-
- @Override
- public IRI getPredicate() {
- return Quad.this.getPredicate();
- }
-
- @Override
- public RDFTerm getObject() {
- return Quad.this.getObject();
- }
-
@Override
public boolean equals(final Object obj) {
if (obj == this) {
@@ -181,6 +111,21 @@ public interface Quad extends QuadLike<BlankNodeOrIRI> {
&& Objects.equals(getObject(), other.getObject());
}
+ @Override
+ public RDFTerm getObject() {
+ return Quad.this.getObject();
+ }
+
+ @Override
+ public IRI getPredicate() {
+ return Quad.this.getPredicate();
+ }
+
+ @Override
+ public BlankNodeOrIRI getSubject() {
+ return Quad.this.getSubject();
+ }
+
@Override
public int hashCode() {
return Objects.hash(getSubject(), getPredicate(), getObject());
@@ -219,6 +164,61 @@ public interface Quad extends QuadLike<BlankNodeOrIRI> {
@Override
boolean equals(Object other);
+ /**
+ * The graph name (graph label) of this quad, if present.
+ *
+ * If {@link Optional#isPresent()}, then the {@link Optional#get()} is
+ * either a {@link BlankNode} or an {@link IRI}, indicating the
+ * <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-named-graph">graph
+ * name</a> of this Quad. If the graph name is not present, e.g. the value
+ * is {@link Optional#empty()}, it indicates that this Quad is in the
+ * <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-default-graph">default
+ * graph</a>.
+ *
+ * @return If {@link Optional#isPresent()}, the graph name
+ * {@link BlankNodeOrIRI} of this quad, otherwise
+ * {@link Optional#empty()}, indicating the default graph.
+ *
+ * @see <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-dataset">RDF-
+ * 1.1 Dataset</a>
+ */
+ @Override
+ Optional<BlankNodeOrIRI> getGraphName();
+
+ /**
+ * The object of this quad, which may be either a {@link BlankNode}, an
+ * {@link IRI}, or a {@link Literal}, which are represented in Commons RDF
+ * by the interface {@link RDFTerm}.
+ *
+ * @return The object {@link RDFTerm} of this quad.
+ * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-object">RDF-1.1
+ * Triple object</a>
+ */
+ @Override
+ RDFTerm getObject();
+
+ /**
+ * The predicate {@link IRI} of this quad.
+ *
+ * @return The predicate {@link IRI} of this quad.
+ * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-predicate">RDF-1.1
+ * Triple predicate</a>
+ */
+ @Override
+ IRI getPredicate();
+
+ /**
+ * The subject of this quad, which may be either a {@link BlankNode} or an
+ * {@link IRI}, which are represented in Commons RDF by the interface
+ * {@link BlankNodeOrIRI}.
+ *
+ * @return The subject {@link BlankNodeOrIRI} of this quad.
+ * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-subject">RDF-1.1
+ * Triple subject</a>
+ */
+ @Override
+ BlankNodeOrIRI getSubject();
+
/**
* Calculate a hash code for this Quad.
* <p>
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/RDF.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/RDF.java
index 457ee90c..7ef1c541 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/RDF.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/RDF.java
@@ -83,16 +83,6 @@ public interface RDF {
*/
BlankNode createBlankNode(String name);
- /**
- * Create a new graph.
- *
- * It is undefined if the graph will be persisted by any underlying storage
- * mechanism.
- *
- * @return A new Graph
- */
- Graph createGraph();
-
/**
* Create a new dataset.
*
@@ -103,6 +93,16 @@ public interface RDF {
*/
Dataset createDataset();
+ /**
+ * Create a new graph.
+ *
+ * It is undefined if the graph will be persisted by any underlying storage
+ * mechanism.
+ *
+ * @return A new Graph
+ */
+ Graph createGraph();
+
/**
* Create an IRI from a (possibly escaped) String.
*
@@ -206,28 +206,6 @@ public interface RDF {
*/
Literal createLiteral(String lexicalForm, String languageTag) throws IllegalArgumentException;
- /**
- * Create a triple.
- *
- * The returned Triple SHOULD have a {@link Triple#getSubject()} that is
- * equal to the provided subject, a {@link Triple#getPredicate()} that is
- * equal to the provided predicate, and a {@link Triple#getObject()} that is
- * equal to the provided object.
- *
- * @param subject
- * The IRI or BlankNode that is the subject of the triple
- * @param predicate
- * The IRI that is the predicate of the triple
- * @param object
- * The IRI, BlankNode or Literal that is the object of the triple
- * @return The created Triple
- * @throws IllegalArgumentException
- * If any of the provided arguments are not acceptable, e.g.
- * because a Literal has a lexicalForm that is too large for an
- * underlying storage.
- */
- Triple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) throws IllegalArgumentException;
-
/**
* Create a quad.
* <p>
@@ -255,4 +233,26 @@ public interface RDF {
Quad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
throws IllegalArgumentException;
+ /**
+ * Create a triple.
+ *
+ * The returned Triple SHOULD have a {@link Triple#getSubject()} that is
+ * equal to the provided subject, a {@link Triple#getPredicate()} that is
+ * equal to the provided predicate, and a {@link Triple#getObject()} that is
+ * equal to the provided object.
+ *
+ * @param subject
+ * The IRI or BlankNode that is the subject of the triple
+ * @param predicate
+ * The IRI that is the predicate of the triple
+ * @param object
+ * The IRI, BlankNode or Literal that is the object of the triple
+ * @return The created Triple
+ * @throws IllegalArgumentException
+ * If any of the provided arguments are not acceptable, e.g.
+ * because a Literal has a lexicalForm that is too large for an
+ * underlying storage.
+ */
+ Triple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) throws IllegalArgumentException;
+
}
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java
index 947868bb..f3251f33 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java
@@ -98,55 +98,106 @@ public interface RDFSyntax {
RDFSyntax TRIG = W3CRDFSyntax.TRIG;
/**
- * A short name of the RDF Syntax e.g. <code>JSONLD</code>.
+ * Return the RDFSyntax with the specified file extension.
* <p>
- * The name is specific to Commons RDF and carries no particular meaning.
+ * The <code>fileExtension</code> is compared in lower case to all
+ * extensions supported, therefore it might not be equal to the
+ * {@link RDFSyntax#fileExtension} of the returned RDFSyntax.
+ * <p>
+ * This method support all syntaxes returned by {@link #w3cSyntaxes()}.
*
- * @return Short name for RDF syntax
+ * @param fileExtension
+ * The fileExtension to match, starting with <code>.</code>
+ * @return If {@link Optional#isPresent()}, the {@link RDFSyntax} which has
+ * a matching {@link RDFSyntax#fileExtension()}, otherwise
+ * {@link Optional#empty()} indicating that no matching file
+ * extension was found.
*/
- String name();
+ static Optional<RDFSyntax> byFileExtension(final String fileExtension) {
+ final String ext = fileExtension.toLowerCase(Locale.ROOT);
+ return w3cSyntaxes().stream().filter(t -> t.fileExtensions().contains(ext))
+ .findAny();
+ }
/**
- * The title of the RDF Syntax.
+ * Return the RDFSyntax with the specified media type.
* <p>
- * This is generally the title of the corresponding standard,
- * e.g. <em>RDF 1.1 Turtle</em>.
+ * The <code>mediaType</code> is compared in lower case to all media types
+ * supported, therefore it might not be equal to the
+ * {@link RDFSyntax#mediaType} of the returned RDFSyntax.
+ * <p>
+ * If the media type specifies parameters, e.g.
+ * <code>text/turtle; charset=ascii</code>, only the part of the string to
+ * before <code>;</code> is considered.
+ * <p>
+ * This method support all syntaxes returned by {@link #w3cSyntaxes()}.
*
- * @return Title of RDF Syntax
+ * @param mediaType
+ * The media type to match
+ * @return If {@link Optional#isPresent()}, the {@link RDFSyntax} which has
+ * a matching {@link RDFSyntax#mediaType()}, otherwise
+ * {@link Optional#empty()} indicating that no matching syntax was
+ * found.
*/
- String title();
+ static Optional<RDFSyntax> byMediaType(final String mediaType) {
+ final String type = mediaType.toLowerCase(Locale.ROOT).split("\\s*;", 2)[0];
+ return w3cSyntaxes().stream().filter(t -> t.mediaTypes().contains(type))
+ .findAny();
+ }
/**
- * The <a href="https://tools.ietf.org/html/rfc2046">IANA media type</a> for
- * the RDF syntax.
+ * Return the RDFSyntax with the specified {@link #name()}.
* <p>
- * The media type can be used as part of <code>Content-Type</code> and
- * <code>Accept</code> for <em>content negotiation</em> in the
- * <a href="https://tools.ietf.org/html/rfc7231#section-3.1.1.1">HTTP
- * protocol</a>.
+ * This method support all syntaxes returned by {@link #w3cSyntaxes()}.
*
- * @return The registered media type of the RDF Syntax
+ * @param name
+ * The name to match, , e.g. <code>"JSONLD"</code>
+ * @return If {@link Optional#isPresent()}, the {@link RDFSyntax} which has
+ * a matching {@link RDFSyntax#name()}, otherwise
+ * {@link Optional#empty()} indicating that no matching name was found.
*/
- String mediaType();
+ static Optional<RDFSyntax> byName(final String name) {
+ return w3cSyntaxes().stream().filter(t -> t.name().equals(name)).findAny();
+ }
/**
- * Sets of <a href="https://tools.ietf.org/html/rfc2046">IANA media types</a> that
- * covers this RDF syntax, including any non-official media types.
+ * Return the RDF 1.1 serialization syntaxes.
* <p>
- * The media type can be used as part of <code>Content-Type</code> and
- * <code>Accept</code> for <em>content negotiation</em> in the
- * <a href="https://tools.ietf.org/html/rfc7231#section-3.1.1.1">HTTP
- * protocol</a>.
+ * This lists the W3C standardized RDF 1.1 syntaxes like {@link #TURTLE} and
+ * {@link #JSONLD}. Note the existence of other RDF syntaxes that are not
+ * included here, e.g. <a href="http://www.w3.org/TeamSubmission/n3/">N3</a> and
+ * <a href="https://en.wikipedia.org/wiki/TriX_%28syntax%29">TriX</a>.
* <p>
- * The returned Set MUST include the value {@link #mediaType()}; this is the
- * behavior of the default implementation.
+ * The syntaxes returned only support the {@link #mediaType()}
+ * and {@link #fileExtension()} as defined in the corresponding
+ * W3C specification.
*
- * @return The media types corresponding to the RDF Syntax
+ * @return
+ * A set of the official RDF 1.1 {@link RDFSyntax}es.
+ *
+ * @see <a href="https://www.w3.org/TR/rdf11-primer/#section-graph-syntax">RDF
+ * 1.1 Primer</a>
+ * @see org.apache.commons.rdf.experimental.RDFParser
*/
- default Set<String> mediaTypes() {
- return Collections.singleton(mediaType());
+
+ static Set<RDFSyntax> w3cSyntaxes() {
+ return W3CRDFSyntax.syntaxes;
}
+ /**
+ * 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 the object with which to compare
+ * @return true if this object is the same as the obj argument; false otherwise
+ */
+ @Override
+ boolean equals(Object obj);
+
/**
* The <a href="https://tools.ietf.org/html/rfc2046">IANA-registered</a>
* file extension.
@@ -172,13 +223,15 @@ public interface RDFSyntax {
}
/**
- * Indicate if this RDF syntax supports
- * <a href="https://www.w3.org/TR/rdf11-concepts/#section-dataset">RDF
- * Datasets</a>.
+ * 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 true if this RDF Syntax supports datasets; false otherwise
+ * @return Hash code of RDFSyntax
*/
- boolean supportsDataset();
+ @Override
+ int hashCode();
/**
* Return the {@link IRI} that <em>identifies</em> the RDF syntax.
@@ -192,116 +245,63 @@ public interface RDFSyntax {
IRI iri();
/**
- * Compare this RDFSyntax with another object.
+ * The <a href="https://tools.ietf.org/html/rfc2046">IANA media type</a> for
+ * the RDF syntax.
* <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 the object with which to compare
- * @return true if this object is the same as the obj argument; false otherwise
- */
- @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}.
+ * The media type can be used as part of <code>Content-Type</code> and
+ * <code>Accept</code> for <em>content negotiation</em> in the
+ * <a href="https://tools.ietf.org/html/rfc7231#section-3.1.1.1">HTTP
+ * protocol</a>.
*
- * @return Hash code of RDFSyntax
+ * @return The registered media type of the RDF Syntax
*/
- @Override
- int hashCode();
+ String mediaType();
/**
- * Return the RDF 1.1 serialization syntaxes.
+ * Sets of <a href="https://tools.ietf.org/html/rfc2046">IANA media types</a> that
+ * covers this RDF syntax, including any non-official media types.
* <p>
- * This lists the W3C standardized RDF 1.1 syntaxes like {@link #TURTLE} and
- * {@link #JSONLD}. Note the existence of other RDF syntaxes that are not
- * included here, e.g. <a href="http://www.w3.org/TeamSubmission/n3/">N3</a> and
- * <a href="https://en.wikipedia.org/wiki/TriX_%28syntax%29">TriX</a>.
+ * The media type can be used as part of <code>Content-Type</code> and
+ * <code>Accept</code> for <em>content negotiation</em> in the
+ * <a href="https://tools.ietf.org/html/rfc7231#section-3.1.1.1">HTTP
+ * protocol</a>.
* <p>
- * The syntaxes returned only support the {@link #mediaType()}
- * and {@link #fileExtension()} as defined in the corresponding
- * W3C specification.
- *
- * @return
- * A set of the official RDF 1.1 {@link RDFSyntax}es.
+ * The returned Set MUST include the value {@link #mediaType()}; this is the
+ * behavior of the default implementation.
*
- * @see <a href="https://www.w3.org/TR/rdf11-primer/#section-graph-syntax">RDF
- * 1.1 Primer</a>
- * @see org.apache.commons.rdf.experimental.RDFParser
+ * @return The media types corresponding to the RDF Syntax
*/
-
- static Set<RDFSyntax> w3cSyntaxes() {
- return W3CRDFSyntax.syntaxes;
+ default Set<String> mediaTypes() {
+ return Collections.singleton(mediaType());
}
/**
- * Return the RDFSyntax with the specified media type.
- * <p>
- * The <code>mediaType</code> is compared in lower case to all media types
- * supported, therefore it might not be equal to the
- * {@link RDFSyntax#mediaType} of the returned RDFSyntax.
- * <p>
- * If the media type specifies parameters, e.g.
- * <code>text/turtle; charset=ascii</code>, only the part of the string to
- * before <code>;</code> is considered.
+ * A short name of the RDF Syntax e.g. <code>JSONLD</code>.
* <p>
- * This method support all syntaxes returned by {@link #w3cSyntaxes()}.
+ * The name is specific to Commons RDF and carries no particular meaning.
*
- * @param mediaType
- * The media type to match
- * @return If {@link Optional#isPresent()}, the {@link RDFSyntax} which has
- * a matching {@link RDFSyntax#mediaType()}, otherwise
- * {@link Optional#empty()} indicating that no matching syntax was
- * found.
+ * @return Short name for RDF syntax
*/
- static Optional<RDFSyntax> byMediaType(final String mediaType) {
- final String type = mediaType.toLowerCase(Locale.ROOT).split("\\s*;", 2)[0];
- return w3cSyntaxes().stream().filter(t -> t.mediaTypes().contains(type))
- .findAny();
- }
+ String name();
/**
- * Return the RDFSyntax with the specified file extension.
- * <p>
- * The <code>fileExtension</code> is compared in lower case to all
- * extensions supported, therefore it might not be equal to the
- * {@link RDFSyntax#fileExtension} of the returned RDFSyntax.
- * <p>
- * This method support all syntaxes returned by {@link #w3cSyntaxes()}.
+ * Indicate if this RDF syntax supports
+ * <a href="https://www.w3.org/TR/rdf11-concepts/#section-dataset">RDF
+ * Datasets</a>.
*
- * @param fileExtension
- * The fileExtension to match, starting with <code>.</code>
- * @return If {@link Optional#isPresent()}, the {@link RDFSyntax} which has
- * a matching {@link RDFSyntax#fileExtension()}, otherwise
- * {@link Optional#empty()} indicating that no matching file
- * extension was found.
+ * @return true if this RDF Syntax supports datasets; false otherwise
*/
- static Optional<RDFSyntax> byFileExtension(final String fileExtension) {
- final String ext = fileExtension.toLowerCase(Locale.ROOT);
- return w3cSyntaxes().stream().filter(t -> t.fileExtensions().contains(ext))
- .findAny();
- }
+ boolean supportsDataset();
/**
- * Return the RDFSyntax with the specified {@link #name()}.
+ * The title of the RDF Syntax.
* <p>
- * This method support all syntaxes returned by {@link #w3cSyntaxes()}.
+ * This is generally the title of the corresponding standard,
+ * e.g. <em>RDF 1.1 Turtle</em>.
*
- * @param name
- * The name to match, , e.g. <code>"JSONLD"</code>
- * @return If {@link Optional#isPresent()}, the {@link RDFSyntax} which has
- * a matching {@link RDFSyntax#name()}, otherwise
- * {@link Optional#empty()} indicating that no matching name was found.
+ * @return Title of RDF Syntax
*/
- static Optional<RDFSyntax> byName(final String name) {
- return w3cSyntaxes().stream().filter(t -> t.name().equals(name)).findAny();
- }
+ String title();
}
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java
index 56388981..2ab2f1f2 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java
@@ -53,16 +53,6 @@ package org.apache.commons.rdf.api;
public interface RDFTerm {
/**
- * Return the term serialised as specified by the RDF-1.1 N-Triples
- * Canonical form.
- *
- * @return The term serialised as RDF-1.1 N-Triples.
- * @see <a href="http://www.w3.org/TR/n-triples/#canonical-ntriples">
- * RDF-1.1 N-Triples Canonical form</a>
- */
- String ntriplesString();
-
- /**
* Check it this RDFTerm is equal to another RDFTerm.
* <p>
* If this object is an {@link IRI}, equality is checked using
@@ -104,4 +94,14 @@ public interface RDFTerm {
@Override
int hashCode();
+ /**
+ * Return the term serialised as specified by the RDF-1.1 N-Triples
+ * Canonical form.
+ *
+ * @return The term serialised as RDF-1.1 N-Triples.
+ * @see <a href="http://www.w3.org/TR/n-triples/#canonical-ntriples">
+ * RDF-1.1 N-Triples Canonical form</a>
+ */
+ String ntriplesString();
+
}
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/Triple.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/Triple.java
index 2c66d13b..f5603edb 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/Triple.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/Triple.java
@@ -56,26 +56,23 @@ import java.util.Objects;
public interface Triple extends TripleLike {
/**
- * The subject of this triple, which may be either a {@link BlankNode} or an
- * {@link IRI}, which are represented in Commons RDF by the interface
- * {@link BlankNodeOrIRI}.
- *
- * @return The subject {@link BlankNodeOrIRI} of this triple.
- * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-subject">RDF-1.1
- * Triple subject</a>
- */
- @Override
- BlankNodeOrIRI getSubject();
-
- /**
- * The predicate {@link IRI} of this triple.
+ * Check it this Triple is equal to another Triple.
+ * <p>
+ * Two Triples are equal if and only if their {@link #getSubject()},
+ * {@link #getPredicate()} and {@link #getObject()} are equal.
+ * </p>
+ * <p>
+ * Implementations MUST also override {@link #hashCode()} so that two equal
+ * Triples produce the same hash code.
+ * </p>
*
- * @return The predicate {@link IRI} of this triple.
- * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-predicate">RDF-1.1
- * Triple predicate</a>
+ * @param other
+ * Another object
+ * @return true if other is a Triple and is equal to this
+ * @see Object#equals(Object)
*/
@Override
- IRI getPredicate();
+ boolean equals(Object other);
/**
* The object of this triple, which may be either a {@link BlankNode}, an
@@ -90,23 +87,26 @@ public interface Triple extends TripleLike {
RDFTerm getObject();
/**
- * Check it this Triple is equal to another Triple.
- * <p>
- * Two Triples are equal if and only if their {@link #getSubject()},
- * {@link #getPredicate()} and {@link #getObject()} are equal.
- * </p>
- * <p>
- * Implementations MUST also override {@link #hashCode()} so that two equal
- * Triples produce the same hash code.
- * </p>
+ * The predicate {@link IRI} of this triple.
*
- * @param other
- * Another object
- * @return true if other is a Triple and is equal to this
- * @see Object#equals(Object)
+ * @return The predicate {@link IRI} of this triple.
+ * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-predicate">RDF-1.1
+ * Triple predicate</a>
*/
@Override
- boolean equals(Object other);
+ IRI getPredicate();
+
+ /**
+ * The subject of this triple, which may be either a {@link BlankNode} or an
+ * {@link IRI}, which are represented in Commons RDF by the interface
+ * {@link BlankNodeOrIRI}.
+ *
+ * @return The subject {@link BlankNodeOrIRI} of this triple.
+ * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-subject">RDF-1.1
+ * Triple subject</a>
+ */
+ @Override
+ BlankNodeOrIRI getSubject();
/**
* Calculate a hash code for this Triple.
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/TripleLike.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/TripleLike.java
index bf1f9c91..85260a83 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/TripleLike.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/TripleLike.java
@@ -41,11 +41,12 @@ package org.apache.commons.rdf.api;
public interface TripleLike {
/**
- * The subject of this statement.
+ * The object of this statement.
*
- * @return The subject, typically an {@link IRI} or {@link BlankNode}.
+ * @return The object, typically an {@link IRI}, {@link BlankNode} or
+ * {@link Literal}.
*/
- RDFTerm getSubject();
+ RDFTerm getObject();
/**
* The predicate of this statement.
@@ -55,10 +56,9 @@ public interface TripleLike {
RDFTerm getPredicate();
/**
- * The object of this statement.
+ * The subject of this statement.
*
- * @return The object, typically an {@link IRI}, {@link BlankNode} or
- * {@link Literal}.
+ * @return The subject, typically an {@link IRI} or {@link BlankNode}.
*/
- RDFTerm getObject();
+ RDFTerm getSubject();
}
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/W3CRDFSyntax.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/W3CRDFSyntax.java
index e2f012c8..abaa2c4f 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/W3CRDFSyntax.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/W3CRDFSyntax.java
@@ -53,21 +53,6 @@ class W3CRDFSyntax implements RDFSyntax {
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) {
@@ -80,10 +65,25 @@ class W3CRDFSyntax implements RDFSyntax {
return getIRIString().equals(other.getIRIString());
}
+ @Override
+ public String getIRIString() {
+ return BASE + format;
+ }
+
@Override
public int hashCode() {
return getIRIString().hashCode();
}
+
+ @Override
+ public String ntriplesString() {
+ return "<" + getIRIString() + ">";
+ }
+
+ @Override
+ public String toString() {
+ return ntriplesString();
+ }
}
@@ -104,13 +104,13 @@ class W3CRDFSyntax implements RDFSyntax {
private final Set<String> extensions = Collections.unmodifiableSet(new LinkedHashSet<>(
Arrays.asList(".html", ".xhtml")));
@Override
- public Set<String> mediaTypes() {
- return types;
- }
- @Override
public Set<String> fileExtensions() {
return extensions;
}
+ @Override
+ public Set<String> mediaTypes() {
+ return types;
+ }
};
syntaxes = Collections.unmodifiableSet(new LinkedHashSet<>(
Arrays.asList(JSONLD, NQUADS, NTRIPLES, RDFA, RDFXML, TRIG, TURTLE)));
@@ -137,16 +137,16 @@ class W3CRDFSyntax implements RDFSyntax {
this.iri = new FormatIRI(name);
}
- /**
- * {@inheritDoc}
- * <p>
- * {@link W3CRDFSyntax} always defines media type in lower case, so
- * {@link String#toLowerCase(Locale)} need not be called.
- *
- */
@Override
- public String mediaType() {
- return mediaType;
+ public boolean equals(final Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (!(obj instanceof RDFSyntax)) {
+ return false;
+ }
+ final RDFSyntax other = (RDFSyntax) obj;
+ return mediaType.equals(other.mediaType().toLowerCase(Locale.ROOT));
}
/**
@@ -162,40 +162,40 @@ class W3CRDFSyntax implements RDFSyntax {
}
@Override
- public boolean supportsDataset() {
- return supportsDataset;
+ public int hashCode() {
+ return mediaType.hashCode();
}
@Override
- public String title() {
- return title;
+ public IRI iri() {
+ return iri;
}
+ /**
+ * {@inheritDoc}
+ * <p>
+ * {@link W3CRDFSyntax} always defines media type in lower case, so
+ * {@link String#toLowerCase(Locale)} need not be called.
+ *
+ */
@Override
- public String name() {
- return name;
+ public String mediaType() {
+ return mediaType;
}
@Override
- public IRI iri() {
- return iri;
+ public String name() {
+ return name;
}
@Override
- public boolean equals(final Object obj) {
- if (obj == this) {
- return true;
- }
- if (!(obj instanceof RDFSyntax)) {
- return false;
- }
- final RDFSyntax other = (RDFSyntax) obj;
- return mediaType.equals(other.mediaType().toLowerCase(Locale.ROOT));
+ public boolean supportsDataset() {
+ return supportsDataset;
}
@Override
- public int hashCode() {
- return mediaType.hashCode();
+ public String title() {
+ return title;
}
@Override
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/experimental/RDFParser.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/experimental/RDFParser.java
index a0b80d3e..87e7633e 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/experimental/RDFParser.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/experimental/RDFParser.java
@@ -93,23 +93,48 @@ public interface RDFParser {
}
/**
- * Specify which {@link RDF} to use for generating {@link RDFTerm}s.
+ * Specify a base IRI to use for parsing any relative IRI references.
* <p>
- * This option may be used together with {@link #target(Graph)} to override
- * the implementation's default factory and graph.
+ * Setting this option will override any protocol-specific base IRI (e.g.
+ * <code>Content-Location</code> header) or the {@link #source(IRI)} IRI,
+ * but does not override any base IRIs set within the source document (e.g.
+ * <code>@base</code> in Turtle documents).
* <p>
- * <strong>Warning:</strong> Using the same {@link RDF} for multiple
- * {@link #parse()} calls may accidentally merge {@link BlankNode}s having
- * the same label, as the parser may use the
- * {@link RDF#createBlankNode(String)} method from the parsed blank node
- * labels.
+ * If the source is in a syntax that does not support relative IRI
+ * references (e.g. {@link RDFSyntax#NTRIPLES}), setting the
+ * <code>base</code> has no effect.
+ * <p>
+ * This method will override any base IRI set with {@link #base(String)}.
*
- * @see #target(Graph)
- * @param rdfTermFactory
- * {@link RDF} to use for generating RDFTerms.
- * @return An {@link RDFParser} that will use the specified rdfTermFactory
+ * @see #base(String)
+ * @param base
+ * An absolute IRI to use as a base.
+ * @return An {@link RDFParser} that will use the specified base IRI.
*/
- RDFParser rdfTermFactory(RDF rdfTermFactory);
+ RDFParser base(IRI base);
+
+ /**
+ * Specify a base IRI to use for parsing any relative IRI references.
+ * <p>
+ * Setting this option will override any protocol-specific base IRI (e.g.
+ * <code>Content-Location</code> header) or the {@link #source(IRI)} IRI,
+ * but does not override any base IRIs set within the source document (e.g.
+ * <code>@base</code> in Turtle documents).
+ * <p>
+ * If the source is in a syntax that does not support relative IRI
+ * references (e.g. {@link RDFSyntax#NTRIPLES}), setting the
+ * <code>base</code> has no effect.
+ * <p>
+ * This method will override any base IRI set with {@link #base(IRI)}.
+ *
+ * @see #base(IRI)
+ * @param base
+ * An absolute IRI to use as a base.
+ * @return An {@link RDFParser} that will use the specified base IRI.
+ * @throws IllegalArgumentException
+ * If the base is not a valid absolute IRI string
+ */
+ RDFParser base(String base) throws IllegalArgumentException;
/**
* Specify the content type of the RDF syntax to parse.
@@ -162,147 +187,75 @@ public interface RDFParser {
RDFParser contentType(String contentType) throws IllegalArgumentException;
/**
- * Specify a {@link Graph} to add parsed triples to.
- * <p>
- * If the source supports datasets (e.g. the {@link #contentType(RDFSyntax)}
- * set has {@link RDFSyntax#supportsDataset} is true)), then only quads in
- * the <em>default graph</em> will be added to the Graph as {@link Triple}s.
- * <p>
- * It is undefined if any triples are added to the specified {@link Graph}
- * if {@link #parse()} throws any exceptions. (However implementations are
- * free to prevent this using transaction mechanisms or similar). If
- * {@link Future#get()} does not indicate an exception, the parser
- * implementation SHOULD have inserted all parsed triples to the specified
- * graph.
- * <p>
- * Calling this method will override any earlier targets set with
- * {@link #target(Graph)}, {@link #target(Consumer)} or
- * {@link #target(Dataset)}.
- * <p>
- * The default implementation of this method calls {@link #target(Consumer)}
- * with a {@link Consumer} that does {@link Graph#add(Triple)} with
- * {@link Quad#asTriple()} if the quad is in the default graph.
- *
- * @param graph
- * The {@link Graph} to add triples to.
- * @return An {@link RDFParser} that will insert triples into the specified
- * graph.
- */
- default RDFParser target(final Graph graph) {
- return target(q -> {
- if (!q.getGraphName().isPresent()) {
- graph.add(q.asTriple());
- }
- });
- }
-
- /**
- * Specify a {@link Dataset} to add parsed quads to.
- * <p>
- * It is undefined if any quads are added to the specified {@link Dataset}
- * if {@link #parse()} throws any exceptions. (However implementations are
- * free to prevent this using transaction mechanisms or similar). On the
- * other hand, if {@link #parse()} does not indicate an exception, the
- * implementation SHOULD have inserted all parsed quads to the specified
- * dataset.
- * <p>
- * Calling this method will override any earlier targets set with
- * {@link #target(Graph)}, {@link #target(Consumer)} or
- * {@link #target(Dataset)}.
- * <p>
- * The default implementation of this method calls {@link #target(Consumer)}
- * with a {@link Consumer} that does {@link Dataset#add(Quad)}.
- *
- * @param dataset
- * The {@link Dataset} to add quads to.
- * @return An {@link RDFParser} that will insert triples into the specified
- * dataset.
- */
- default RDFParser target(final Dataset dataset) {
- return target(dataset::add);
- }
-
- /**
- * Specify a consumer for parsed quads.
- * <p>
- * The quads will include triples in all named graphs of the parsed source,
- * including any triples in the default graph. When parsing a source format
- * which do not support datasets, all quads delivered to the consumer will
- * be in the default graph (e.g. their {@link Quad#getGraphName()} will be
- * as {@link Optional#empty()}), while for a source
- * <p>
- * It is undefined if any quads are consumed if {@link #parse()} throws any
- * exceptions. On the other hand, if {@link #parse()} does not indicate an
- * exception, the implementation SHOULD have produced all parsed quads to
- * the specified consumer.
+ * Parse the specified source.
* <p>
- * Calling this method will override any earlier targets set with
- * {@link #target(Graph)}, {@link #target(Consumer)} or
- * {@link #target(Dataset)}.
+ * A source method (e.g. {@link #source(InputStream)}, {@link #source(IRI)},
+ * {@link #source(Path)}, {@link #source(String)} or an equivalent subclass
+ * method) MUST have been called before calling this method, otherwise an
+ * {@link IllegalStateException} will be thrown.
* <p>
- * The consumer is not assumed to be thread safe - only one
- * {@link Consumer#accept(Object)} is delivered at a time for a given
- * {@link RDFParser#parse()} call.
+ * A target method (e.g. {@link #target(Consumer)},
+ * {@link #target(Dataset)}, {@link #target(Graph)} or an equivalent
+ * subclass method) MUST have been called before calling parse(), otherwise
+ * an {@link IllegalStateException} will be thrown.
* <p>
- * This method is typically called with a functional consumer, for example:
- *
- * <pre>
- * {@code
- * List<Quad> quads = new ArrayList<Quad>;
- * parserBuilder.target(quads::add).parse();
- * }
- * </pre>
- *
- * @param consumer
- * A {@link Consumer} of {@link Quad}s
- * @return An {@link RDFParser} that will call the consumer for into the
- * specified dataset.
- */
- RDFParser target(Consumer<Quad> consumer);
-
- /**
- * Specify a base IRI to use for parsing any relative IRI references.
+ * It is undefined if this method is thread-safe, however the
+ * {@link RDFParser} may be reused (e.g. setting a different source) as soon
+ * as the {@link Future} has been returned from this method.
* <p>
- * Setting this option will override any protocol-specific base IRI (e.g.
- * <code>Content-Location</code> header) or the {@link #source(IRI)} IRI,
- * but does not override any base IRIs set within the source document (e.g.
- * <code>@base</code> in Turtle documents).
+ * The RDFParser SHOULD perform the parsing as an asynchronous operation,
+ * and return the {@link Future} as soon as preliminary checks (such as
+ * validity of the {@link #source(IRI)} and {@link #contentType(RDFSyntax)}
+ * settings) have finished. The future SHOULD not mark
+ * {@link Future#isDone()} before parsing is complete. A synchronous
+ * implementation MAY be blocking on the <code>parse()</code> call and
+ * return a Future that is already {@link Future#isDone()}.
* <p>
- * If the source is in a syntax that does not support relative IRI
- * references (e.g. {@link RDFSyntax#NTRIPLES}), setting the
- * <code>base</code> has no effect.
+ * The returned {@link Future} contains a {@link ParseResult}.
+ * Implementations may subclass this interface to provide any parser
+ * details, e.g. list of warnings. <code>null</code> is a possible return
+ * value if no details are available, but parsing succeeded.
* <p>
- * This method will override any base IRI set with {@link #base(String)}.
+ * If an exception occurs during parsing, (e.g. {@link IOException} or
+ * <code>org.apache.commons.rdf.simple.experimental.RDFParseException</code>),
+ * it should be indicated as the
+ * {@link java.util.concurrent.ExecutionException#getCause()} in the
+ * {@link java.util.concurrent.ExecutionException} thrown on
+ * {@link Future#get()}.
*
- * @see #base(String)
- * @param base
- * An absolute IRI to use as a base.
- * @return An {@link RDFParser} that will use the specified base IRI.
+ * @return A Future that will return the populated {@link Graph} when the
+ * parsing has finished.
+ * @throws IOException
+ * If an error occurred while starting to read the source (e.g.
+ * file not found, unsupported IRI protocol). Note that IO
+ * errors during parsing would instead be the
+ * {@link java.util.concurrent.ExecutionException#getCause()} of
+ * the {@link java.util.concurrent.ExecutionException} thrown on
+ * {@link Future#get()}.
+ * @throws IllegalStateException
+ * If the builder is in an invalid state, e.g. a
+ * <code>source</code> has not been set.
*/
- RDFParser base(IRI base);
+ Future<? extends ParseResult> parse() throws IOException, IllegalStateException;
/**
- * Specify a base IRI to use for parsing any relative IRI references.
- * <p>
- * Setting this option will override any protocol-specific base IRI (e.g.
- * <code>Content-Location</code> header) or the {@link #source(IRI)} IRI,
- * but does not override any base IRIs set within the source document (e.g.
- * <code>@base</code> in Turtle documents).
+ * Specify which {@link RDF} to use for generating {@link RDFTerm}s.
* <p>
- * If the source is in a syntax that does not support relative IRI
- * references (e.g. {@link RDFSyntax#NTRIPLES}), setting the
- * <code>base</code> has no effect.
+ * This option may be used together with {@link #target(Graph)} to override
+ * the implementation's default factory and graph.
* <p>
- * This method will override any base IRI set with {@link #base(IRI)}.
+ * <strong>Warning:</strong> Using the same {@link RDF} for multiple
+ * {@link #parse()} calls may accidentally merge {@link BlankNode}s having
+ * the same label, as the parser may use the
+ * {@link RDF#createBlankNode(String)} method from the parsed blank node
+ * labels.
*
- * @see #base(IRI)
- * @param base
- * An absolute IRI to use as a base.
- * @return An {@link RDFParser} that will use the specified base IRI.
- * @throws IllegalArgumentException
- * If the base is not a valid absolute IRI string
+ * @see #target(Graph)
+ * @param rdfTermFactory
+ * {@link RDF} to use for generating RDFTerms.
+ * @return An {@link RDFParser} that will use the specified rdfTermFactory
*/
- RDFParser base(String base) throws IllegalArgumentException;
+ RDFParser rdfTermFactory(RDF rdfTermFactory);
/**
* Specify a source {@link InputStream} to parse.
@@ -337,32 +290,6 @@ public interface RDFParser {
*/
RDFParser source(InputStream inputStream);
- /**
- * Specify a source file {@link Path} to parse.
- * <p>
- * The source set will not be read before the call to {@link #parse()}.
- * <p>
- * The {@link #contentType(RDFSyntax)} or {@link #contentType(String)}
- * SHOULD be set before calling {@link #parse()}.
- * <p>
- * The character set is assumed to be {@link StandardCharsets#UTF_8} unless
- * the {@link #contentType(String)} specifies otherwise or the document
- * declares its own charset (e.g. RDF/XML with a
- * <code><?xml encoding="iso-8859-1"></code> header).
- * <p>
- * The {@link #base(IRI)} or {@link #base(String)} MAY be set before calling
- * {@link #parse()}, otherwise {@link Path#toUri()} will be used as the base
- * IRI.
- * <p>
- * This method will override any source set with {@link #source(IRI)},
- * {@link #source(InputStream)} or {@link #source(String)}.
- *
- * @param file
- * A Path for a file to parse
- * @return An {@link RDFParser} that will use the specified source.
- */
- RDFParser source(Path file);
-
/**
* Specify an absolute source {@link IRI} to retrieve and parse.
* <p>
@@ -395,6 +322,32 @@ public interface RDFParser {
*/
RDFParser source(IRI iri);
+ /**
+ * Specify a source file {@link Path} to parse.
+ * <p>
+ * The source set will not be read before the call to {@link #parse()}.
+ * <p>
+ * The {@link #contentType(RDFSyntax)} or {@link #contentType(String)}
+ * SHOULD be set before calling {@link #parse()}.
+ * <p>
+ * The character set is assumed to be {@link StandardCharsets#UTF_8} unless
+ * the {@link #contentType(String)} specifies otherwise or the document
+ * declares its own charset (e.g. RDF/XML with a
+ * <code><?xml encoding="iso-8859-1"></code> header).
+ * <p>
+ * The {@link #base(IRI)} or {@link #base(String)} MAY be set before calling
+ * {@link #parse()}, otherwise {@link Path#toUri()} will be used as the base
+ * IRI.
+ * <p>
+ * This method will override any source set with {@link #source(IRI)},
+ * {@link #source(InputStream)} or {@link #source(String)}.
+ *
+ * @param file
+ * A Path for a file to parse
+ * @return An {@link RDFParser} that will use the specified source.
+ */
+ RDFParser source(Path file);
+
/**
* Specify an absolute source IRI to retrieve and parse.
* <p>
@@ -431,54 +384,101 @@ public interface RDFParser {
RDFParser source(String iri) throws IllegalArgumentException;
/**
- * Parse the specified source.
+ * Specify a consumer for parsed quads.
* <p>
- * A source method (e.g. {@link #source(InputStream)}, {@link #source(IRI)},
- * {@link #source(Path)}, {@link #source(String)} or an equivalent subclass
- * method) MUST have been called before calling this method, otherwise an
- * {@link IllegalStateException} will be thrown.
+ * The quads will include triples in all named graphs of the parsed source,
+ * including any triples in the default graph. When parsing a source format
+ * which do not support datasets, all quads delivered to the consumer will
+ * be in the default graph (e.g. their {@link Quad#getGraphName()} will be
+ * as {@link Optional#empty()}), while for a source
* <p>
- * A target method (e.g. {@link #target(Consumer)},
- * {@link #target(Dataset)}, {@link #target(Graph)} or an equivalent
- * subclass method) MUST have been called before calling parse(), otherwise
- * an {@link IllegalStateException} will be thrown.
+ * It is undefined if any quads are consumed if {@link #parse()} throws any
+ * exceptions. On the other hand, if {@link #parse()} does not indicate an
+ * exception, the implementation SHOULD have produced all parsed quads to
+ * the specified consumer.
* <p>
- * It is undefined if this method is thread-safe, however the
- * {@link RDFParser} may be reused (e.g. setting a different source) as soon
- * as the {@link Future} has been returned from this method.
+ * Calling this method will override any earlier targets set with
+ * {@link #target(Graph)}, {@link #target(Consumer)} or
+ * {@link #target(Dataset)}.
* <p>
- * The RDFParser SHOULD perform the parsing as an asynchronous operation,
- * and return the {@link Future} as soon as preliminary checks (such as
- * validity of the {@link #source(IRI)} and {@link #contentType(RDFSyntax)}
- * settings) have finished. The future SHOULD not mark
- * {@link Future#isDone()} before parsing is complete. A synchronous
- * implementation MAY be blocking on the <code>parse()</code> call and
- * return a Future that is already {@link Future#isDone()}.
+ * The consumer is not assumed to be thread safe - only one
+ * {@link Consumer#accept(Object)} is delivered at a time for a given
+ * {@link RDFParser#parse()} call.
* <p>
- * The returned {@link Future} contains a {@link ParseResult}.
- * Implementations may subclass this interface to provide any parser
- * details, e.g. list of warnings. <code>null</code> is a possible return
- * value if no details are available, but parsing succeeded.
+ * This method is typically called with a functional consumer, for example:
+ *
+ * <pre>
+ * {@code
+ * List<Quad> quads = new ArrayList<Quad>;
+ * parserBuilder.target(quads::add).parse();
+ * }
+ * </pre>
+ *
+ * @param consumer
+ * A {@link Consumer} of {@link Quad}s
+ * @return An {@link RDFParser} that will call the consumer for into the
+ * specified dataset.
+ */
+ RDFParser target(Consumer<Quad> consumer);
+
+ /**
+ * Specify a {@link Dataset} to add parsed quads to.
* <p>
- * If an exception occurs during parsing, (e.g. {@link IOException} or
- * <code>org.apache.commons.rdf.simple.experimental.RDFParseException</code>),
- * it should be indicated as the
- * {@link java.util.concurrent.ExecutionException#getCause()} in the
- * {@link java.util.concurrent.ExecutionException} thrown on
- * {@link Future#get()}.
+ * It is undefined if any quads are added to the specified {@link Dataset}
+ * if {@link #parse()} throws any exceptions. (However implementations are
+ * free to prevent this using transaction mechanisms or similar). On the
+ * other hand, if {@link #parse()} does not indicate an exception, the
+ * implementation SHOULD have inserted all parsed quads to the specified
+ * dataset.
+ * <p>
+ * Calling this method will override any earlier targets set with
+ * {@link #target(Graph)}, {@link #target(Consumer)} or
+ * {@link #target(Dataset)}.
+ * <p>
+ * The default implementation of this method calls {@link #target(Consumer)}
+ * with a {@link Consumer} that does {@link Dataset#add(Quad)}.
*
- * @return A Future that will return the populated {@link Graph} when the
- * parsing has finished.
- * @throws IOException
- * If an error occurred while starting to read the source (e.g.
- * file not found, unsupported IRI protocol). Note that IO
- * errors during parsing would instead be the
- * {@link java.util.concurrent.ExecutionException#getCause()} of
- * the {@link java.util.concurrent.ExecutionException} thrown on
- * {@link Future#get()}.
- * @throws IllegalStateException
- * If the builder is in an invalid state, e.g. a
- * <code>source</code> has not been set.
+ * @param dataset
+ * The {@link Dataset} to add quads to.
+ * @return An {@link RDFParser} that will insert triples into the specified
+ * dataset.
*/
- Future<? extends ParseResult> parse() throws IOException, IllegalStateException;
+ default RDFParser target(final Dataset dataset) {
+ return target(dataset::add);
+ }
+
+ /**
+ * Specify a {@link Graph} to add parsed triples to.
+ * <p>
+ * If the source supports datasets (e.g. the {@link #contentType(RDFSyntax)}
+ * set has {@link RDFSyntax#supportsDataset} is true)), then only quads in
+ * the <em>default graph</em> will be added to the Graph as {@link Triple}s.
+ * <p>
+ * It is undefined if any triples are added to the specified {@link Graph}
+ * if {@link #parse()} throws any exceptions. (However implementations are
+ * free to prevent this using transaction mechanisms or similar). If
+ * {@link Future#get()} does not indicate an exception, the parser
+ * implementation SHOULD have inserted all parsed triples to the specified
+ * graph.
+ * <p>
+ * Calling this method will override any earlier targets set with
+ * {@link #target(Graph)}, {@link #target(Consumer)} or
+ * {@link #target(Dataset)}.
+ * <p>
+ * The default implementation of this method calls {@link #target(Consumer)}
+ * with a {@link Consumer} that does {@link Graph#add(Triple)} with
+ * {@link Quad#asTriple()} if the quad is in the default graph.
+ *
+ * @param graph
+ * The {@link Graph} to add triples to.
+ * @return An {@link RDFParser} that will insert triples into the specified
+ * graph.
+ */
+ default RDFParser target(final Graph graph) {
+ return target(q -> {
+ if (!q.getGraphName().isPresent()) {
+ graph.add(q.asTriple());
+ }
+ });
+ }
}