You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commonsrdf.apache.org by st...@apache.org on 2016/09/05 15:53:45 UTC
[01/19] incubator-commonsrdf git commit: Add Quad and TripleOrQuad
Repository: incubator-commonsrdf
Updated Branches:
refs/heads/master 6c673b719 -> fc70462eb
Add Quad and TripleOrQuad
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/7639fd7c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/7639fd7c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/7639fd7c
Branch: refs/heads/master
Commit: 7639fd7c9de649361a7eaeeb3c9d8b620dc54afc
Parents: 73994db
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Apr 8 14:24:11 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Apr 8 14:24:11 2016 +0100
----------------------------------------------------------------------
.../java/org/apache/commons/rdf/api/Quad.java | 209 +++++++++++++++++++
.../java/org/apache/commons/rdf/api/Triple.java | 2 +-
.../apache/commons/rdf/api/TripleOrQuad.java | 64 ++++++
3 files changed, 274 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/7639fd7c/api/src/main/java/org/apache/commons/rdf/api/Quad.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Quad.java b/api/src/main/java/org/apache/commons/rdf/api/Quad.java
new file mode 100644
index 0000000..088533b
--- /dev/null
+++ b/api/src/main/java/org/apache/commons/rdf/api/Quad.java
@@ -0,0 +1,209 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.rdf.api;
+
+import java.util.Objects;
+import java.util.Optional;
+
+/**
+ * A Quad is a statement in a
+ * <a href= "http://www.w3.org/TR/rdf11-concepts/#section-dataset" >RDF-1.1
+ * Dataset</a>, as defined by
+ * <a href= "https://www.w3.org/TR/2014/NOTE-rdf11-datasets-20140225/" >RDF-1.1
+ * Concepts and Abstract Syntax</a>, a W3C Working Group Note published on 25
+ * February 2014.
+ *
+ * @see <a href="http://www.w3.org/TR/2014/NOTE-rdf11-datasets-20140225/">RDF
+ * 1.1: On Semantics of RDF Datasets</a>
+ * @see <a href="http://www.w3.org/TR/rdf11-concepts/#section-dataset"> </a>
+ */
+public interface Quad extends TripleOrQuad {
+
+ /**
+ * 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 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.
+ *
+ * @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>
+ */
+ 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>
+ */
+ BlankNodeOrIRI getSubject();
+
+ /**
+ * The predicate {@link IRI} of this triple.
+ *
+ * @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>
+ */
+ IRI getPredicate();
+
+ /**
+ * The object of this triple, 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 triple.
+ * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-object">RDF-1.1
+ * Triple object</a>
+ */
+ RDFTerm getObject();
+
+ /**
+ * Convert this {@link Quad} to a {@link Triple}.
+ * <p>
+ * The returned {@link Triple} will have equivalent values returned from the
+ * methods {@link TripleOrQuad#getSubject()},
+ * {@link TripleOrQuad#getPredicate()} and {@link TripleOrQuad#getObject()}
+ * (their values MUST be {@link RDFTerm#equals(Object)}) - however the
+ * property values MAY be different instances.
+ * <p>
+ * The returned {@link Triple} MUST NOT be {@link #equals(Object)} to this
+ * {@link Quad}, even if this quad has a default graph
+ * {@link #getGraphName()} value of {@link Optional#empty()}, but MUST
+ * follow the {@link Triple#equals(Object)) semantics. This means that the
+ * following MUST be true:
+ *
+ * <pre>
+ * Quad q1, q2;
+ * if (q1.equals(q2)) {
+ * assert(q1.asTriple().equals(q2.asTriple()));
+ * } else if (q1.asTriple().equals(q2.asTriple())) {
+ * assert(q1.getSubject().equals(q2.getSubject()));
+ * assert(q1.getPredicate().equals(q2.getPredicate()));
+ * assert(q1.getObject().equals(q2.getObject()));
+ * assert(! q1.getGraphName().equals(q2.getGraphName()));
+ * }
+ * </pre>
+ *
+ * The <code>default</code> implementation of this method return a proxy
+ * {@link Triple} instance that keeps a reference to this {@link Quad} to
+ * calls the underlying {@link TripleOrQuad} methods, but supplies a
+ * {@link Triple} compatible implementation of {@link Triple#equals(Object)}
+ * and {@link Triple#hashCode()}. Implementations may override this method,
+ * e.g. for a more efficient solution.
+ *
+ * @return A {@link Triple} that contains the same {@link TripleOrQuad}
+ * properties as this Quad.
+ */
+ 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(Object obj) {
+ if (!(obj instanceof Triple)) {
+ return false;
+ }
+ Triple other = (Triple) obj;
+ return Objects.equals(getSubject(), other.getSubject())
+ && Objects.equals(getPredicate(), other.getPredicate())
+ && Objects.equals(getObject(), other.getObject());
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(getSubject(), getPredicate(), getObject());
+ }
+ };
+ }
+
+ /**
+ * Check it this Quad is equal to another Quad.
+ * <p>
+ * Two Triples are equal if and only if their {@link #getGraphName()},
+ * {@link #getSubject()}, {@link #getPredicate()} and
+ * {@link #getObject()} are equal.
+ * </p>
+ * <p>
+ * Implementations MUST also override {@link #hashCode()} so that two equal
+ * Quads produce the same hash code.
+ * </p>
+ * <p>
+ * Note that a {@link Quad} MUST NOT be equal to a
+ * {@link Triple}, even if this Quad's {@link #getGraphName()}
+ * is {@link Optional#empty()}. To test triple-like equivalence,
+ * callers can use:
+ * </p>
+ * <pre>
+ * Quad q1;
+ * Triple t2;
+ * q1.asTriple().equals(t2));
+ * </pre>
+ *
+ * @param other
+ * Another object
+ * @return true if other is a Quad and is equal to this
+ * @see Object#equals(Object)
+ */
+ @Override
+ public boolean equals(Object other);
+
+ /**
+ * Calculate a hash code for this Quad.
+ * <p>
+ * The returned hash code MUST be equal to the result of
+ * {@link Objects#hash(Object...)} with the arguments {@link #getSubject()},
+ * {@link #getPredicate()}, {@link #getObject(), #getGraphName()}.
+ * <p>
+ * This method MUST be implemented in conjunction with
+ * {@link #equals(Object)} so that two equal {@link Quad}s produce the same
+ * hash code.
+ *
+ * @return a hash code value for this Quad.
+ * @see Object#hashCode()
+ * @see Objects#hash(Object...)
+ */
+ @Override
+ public int hashCode();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/7639fd7c/api/src/main/java/org/apache/commons/rdf/api/Triple.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Triple.java b/api/src/main/java/org/apache/commons/rdf/api/Triple.java
index b52a51d..0725913 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/Triple.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/Triple.java
@@ -28,7 +28,7 @@ import java.util.Objects;
* @see <a href= "http://www.w3.org/TR/rdf11-concepts/#dfn-rdf-triple" >RDF-1.1
* Triple</a>
*/
-public interface Triple {
+public interface Triple extends TripleOrQuad {
/**
* The subject of this triple, which may be either a {@link BlankNode} or an
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/7639fd7c/api/src/main/java/org/apache/commons/rdf/api/TripleOrQuad.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/TripleOrQuad.java b/api/src/main/java/org/apache/commons/rdf/api/TripleOrQuad.java
new file mode 100644
index 0000000..755bb99
--- /dev/null
+++ b/api/src/main/java/org/apache/commons/rdf/api/TripleOrQuad.java
@@ -0,0 +1,64 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.rdf.api;
+
+/**
+ * Common "triple-like" interface for {@link Triple} and {@link Quad}
+ * <p>
+ * A TripleOrQuad has at least a
+ * {@link #getSubject()}, {@link #getPredicate()} and
+ * {@link #getObject()}, but unlike a {@link Triple} does not have a
+ * formalized {@link Triple#equals(Object)} semantics, and does not
+ * neccesarily have a {@link Quad#getGraphLabel()}
+ * <p>
+ * Implementations of this interface SHOULD also implement {@link Triple}
+ * or {@link Quad}, but MUST NOT implement both interfaces.
+ */
+public interface TripleOrQuad {
+
+ /**
+ * The subject of this triple/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 triple/quad.
+ * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-subject">RDF-1.1
+ * Triple subject</a>
+ */
+ BlankNodeOrIRI getSubject();
+
+ /**
+ * The predicate {@link IRI} of this triple/quad.
+ *
+ * @return The predicate {@link IRI} of this triple/quad.
+ * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-predicate">RDF-1.1
+ * Triple predicate</a>
+ */
+ IRI getPredicate();
+
+ /**
+ * The object of this triple/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 triple/quad.
+ * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-object">RDF-1.1
+ * Triple object</a>
+ */
+ RDFTerm getObject();
+}
[10/19] incubator-commonsrdf git commit: add getGraph(),
getGraph(graphName), getGraphNames()
Posted by st...@apache.org.
add getGraph(), getGraph(graphName), getGraphNames()
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/839a6425
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/839a6425
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/839a6425
Branch: refs/heads/master
Commit: 839a6425fdb4985ef1594af87c6e12dcef8ec519
Parents: bfa15b8
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Apr 13 02:11:36 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Apr 13 02:11:36 2016 +0100
----------------------------------------------------------------------
.../org/apache/commons/rdf/api/Dataset.java | 65 ++++++++++++++++++++
.../apache/commons/rdf/simple/DatasetImpl.java | 30 +++++++++
2 files changed, 95 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/839a6425/api/src/main/java/org/apache/commons/rdf/api/Dataset.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Dataset.java b/api/src/main/java/org/apache/commons/rdf/api/Dataset.java
index 3d24022..706366c 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/Dataset.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/Dataset.java
@@ -99,6 +99,71 @@ public interface Dataset extends AutoCloseable {
}
/**
+ * Get the default graph of this dataset.
+ * <p>
+ * The {@link Triple}s of the default graph are equivalent to the
+ * {@link Quad}s in this Dataset which has the {@link Quad#getGraphName()}
+ * set to {@link Optional#empty()}.
+ * <p>
+ * It is unspecified if modifications to the returned Graph are reflected in
+ * this Dataset.
+ * <p>
+ * The returned graph MAY be empty.
+ *
+ * @see #getGraph(BlankNodeOrIRI)
+ * @return The default graph of this Dataset
+ */
+ Graph getGraph();
+
+ /**
+ * Get a named graph in this dataset.
+ * <p>
+ * The {@link Triple}s of the named graph are equivalent to the
+ * the Quads of this Dataset which has the
+ * {@link Quad#getGraphName()} equal to the provided <code>graphName</code>, or
+ * equal to {@link Optional#empty()} if the provided <code>graphName</code> is
+ * <code>null</code>.
+ * <p>
+ * It is unspecified if modifications to the returned Graph are reflected in
+ * this Dataset.
+ * <p>
+ * It is unspecified if requesting an unknown or empty graph will return
+ * {@link Optional#empty()} or create a new empty {@link Graph}.
+ *
+ * @see #getGraph()
+ * @see #getGraphNames()
+ * @param graphName
+ * The name of the graph, or <code>null</code> for the default
+ * graph.
+ * @return The named Graph, or {@link Optional#empty()} if the dataset do
+ * not contain the named graph.
+ */
+ Optional<Graph> getGraph(BlankNodeOrIRI graphName);
+
+ /**
+ * Get the graph names in this Dataset.
+ * <p>
+ * The set of returned graph names is equivalent to the set of unique
+ * {@link Quad#getGraphName()} of all the {@link #getQuads()} of this
+ * dataset (excluding the default graph).
+ * <p>
+ * The returned {@link Stream} SHOULD NOT contain duplicate graph names.
+ * <p>
+ * The graph names can be used with {@link #getGraph(BlankNodeOrIRI)} to
+ * retrieve the corresponding {@link Graph}, however callers should be aware
+ * of any concurrent modifications to the Dataset may cause such calls to
+ * return {@link Optional#empty()}.
+ * <p>
+ * Note that a Dataset always contains a <strong>default graph</strong>
+ * which is not named, and thus is not represented in the returned Stream.
+ * The default graph is accessible via {@link #getGraph()} or by using
+ * {@link Optional#empty()} in the Quad access methods).
+ *
+ * @return A {@link Stream} of the graph names of this Dataset.
+ */
+ Stream<BlankNodeOrIRI> getGraphNames();
+
+ /**
* Remove a concrete quad from the dataset.
*
* @param quad
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/839a6425/simple/src/main/java/org/apache/commons/rdf/simple/DatasetImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/DatasetImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/DatasetImpl.java
index 63d4025..af9b01d 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/DatasetImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/DatasetImpl.java
@@ -28,6 +28,7 @@ import java.util.stream.Stream;
import org.apache.commons.rdf.api.BlankNode;
import org.apache.commons.rdf.api.BlankNodeOrIRI;
import org.apache.commons.rdf.api.Dataset;
+import org.apache.commons.rdf.api.Graph;
import org.apache.commons.rdf.api.IRI;
import org.apache.commons.rdf.api.Literal;
import org.apache.commons.rdf.api.Quad;
@@ -192,5 +193,34 @@ final class DatasetImpl implements Dataset {
}
}
+ @Override
+ public void close() {
+ }
+
+ @Override
+ public Graph getGraph() {
+ return getGraph(null).get();
+ }
+
+ @Override
+ public Optional<Graph> getGraph(BlankNodeOrIRI graphName) {
+ // NOTE: Always returns a new copy
+ Graph g = new GraphImpl(factory);
+ getQuads(Optional.ofNullable(graphName), null, null, null)
+ .map(Quad::asTriple)
+ .sequential()
+ .forEach(g::add);
+ return Optional.of(g);
+ }
+
+ @Override
+ public Stream<BlankNodeOrIRI> getGraphNames() {
+ // Not very efficient..
+ return getQuads()
+ .map(Quad::getGraphName)
+ .filter(Optional::isPresent).map(Optional::get)
+ .distinct();
+ }
+
}
[16/19] incubator-commonsrdf git commit: Added DatasetGraphView
Posted by st...@apache.org.
Added DatasetGraphView
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/580484c9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/580484c9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/580484c9
Branch: refs/heads/master
Commit: 580484c9d7d02d34b64e5276744c1f644dbbd2f2
Parents: 14e505e
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Tue Jun 14 16:44:24 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Tue Jun 14 16:44:24 2016 +0100
----------------------------------------------------------------------
.../commons/rdf/simple/DatasetGraphView.java | 138 +++++++++++++++++++
.../apache/commons/rdf/simple/DatasetImpl.java | 8 +-
2 files changed, 139 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/580484c9/simple/src/main/java/org/apache/commons/rdf/simple/DatasetGraphView.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/DatasetGraphView.java b/simple/src/main/java/org/apache/commons/rdf/simple/DatasetGraphView.java
new file mode 100644
index 0000000..a347c3e
--- /dev/null
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/DatasetGraphView.java
@@ -0,0 +1,138 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.rdf.simple;
+
+import java.util.Optional;
+import java.util.stream.Stream;
+
+import org.apache.commons.rdf.api.BlankNode;
+import org.apache.commons.rdf.api.BlankNodeOrIRI;
+import org.apache.commons.rdf.api.Dataset;
+import org.apache.commons.rdf.api.Graph;
+import org.apache.commons.rdf.api.IRI;
+import org.apache.commons.rdf.api.Quad;
+import org.apache.commons.rdf.api.RDFTerm;
+import org.apache.commons.rdf.api.Triple;
+
+/**
+ * A {@link Graph} view on a {@link Dataset}.
+ * <p>
+ * This view is backed by a {@link Dataset}, and can be constructed in two ways:
+ *
+ * <dl>
+ * <dt>{@link #DatasetGraphView(Dataset)}</dt>
+ * <dd>Expose a <em>union graph</em> view of the Dataset, where all the
+ * {@link Quad}s of the Dataset is represented as a {@link Triple}. Adding
+ * triples will add them to the <em>default graph</em>, while removing triples
+ * will remove from all graphs.</dd>
+*
+ * <dt>{@link #DatasetGraphView(Dataset, IRI)}</dt>
+ * <dd>Expose a particular graph of the Dataset, either named by an {@link IRI}, a
+ * {@link BlankNode}, or <code>null</code> for the <em>default graph</em>.</dd>
+ * </dl>
+ * <p>
+ * Changes in the Graph are reflected directly in the Dataset and vice versa.
+ * This class is thread-safe is the underlying Dataset is thread-safe.
+ */
+public class DatasetGraphView implements Graph {
+
+ private final boolean unionGraph;
+ private final BlankNodeOrIRI namedGraph;
+ private final Dataset dataset;
+
+ public DatasetGraphView(Dataset dataset) {
+ this.dataset = dataset;
+ this.namedGraph = null;
+ this.unionGraph = true;
+ }
+
+ public DatasetGraphView(Dataset dataset, BlankNodeOrIRI namedGraph) {
+ this.dataset = dataset;
+ this.namedGraph = namedGraph;
+ this.unionGraph = false;
+ }
+
+ @Override
+ public void close() throws Exception {
+ dataset.close();
+
+ }
+
+ @Override
+ public void add(Triple triple) {
+ dataset.add(namedGraph, triple.getSubject(), triple.getPredicate(), triple.getObject());
+ }
+
+ @Override
+ public void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ dataset.add(namedGraph, subject, predicate, object);
+ }
+
+ @Override
+ public boolean contains(Triple triple) {
+ return dataset.contains(unionOrNamedGraph(), triple.getSubject(), triple.getPredicate(), triple.getObject());
+ }
+
+ private Optional<BlankNodeOrIRI> unionOrNamedGraph() {
+ if (unionGraph) {
+ return null;
+ }
+ return Optional.ofNullable(namedGraph);
+ }
+
+ @Override
+ public boolean contains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ return dataset.contains(unionOrNamedGraph(), subject, predicate, object);
+ }
+
+ @Override
+ public void remove(Triple triple) {
+ dataset.remove(unionOrNamedGraph(), triple.getSubject(), triple.getPredicate(), triple.getObject());
+ }
+
+ @Override
+ public void remove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ dataset.remove(unionOrNamedGraph(), subject, predicate, object);
+ }
+
+ @Override
+ public void clear() {
+ dataset.remove(unionOrNamedGraph(), null, null, null);
+ }
+
+ @Override
+ public long size() {
+ return stream().count();
+ }
+
+ @Override
+ public Stream<? extends Triple> stream() {
+ return stream(null, null, null);
+ }
+
+ @Override
+ public Stream<? extends Triple> stream(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ Stream<Triple> stream = dataset.stream(unionOrNamedGraph(), subject, predicate, object).map(Quad::asTriple);
+ if (unionGraph) {
+ // remove duplicates
+ return stream.distinct();
+ }
+ return stream;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/580484c9/simple/src/main/java/org/apache/commons/rdf/simple/DatasetImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/DatasetImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/DatasetImpl.java
index 9de358f..c372012 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/DatasetImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/DatasetImpl.java
@@ -204,13 +204,7 @@ final class DatasetImpl implements Dataset {
@Override
public Optional<Graph> getGraph(BlankNodeOrIRI graphName) {
- // NOTE: Always returns a new copy
- Graph g = new GraphImpl(factory);
- stream(Optional.ofNullable(graphName), null, null, null)
- .map(Quad::asTriple)
- .sequential()
- .forEach(g::add);
- return Optional.of(g);
+ return Optional.of(new DatasetGraphView(this, graphName));
}
@Override
[08/19] incubator-commonsrdf git commit: Dataset does not do
Triple-stuff
Posted by st...@apache.org.
Dataset does not do Triple-stuff
.. to avoid making assumptions about the default graph
See https://github.com/apache/incubator-commonsrdf/pull/19#issuecomment-208365206
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/084a4ade
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/084a4ade
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/084a4ade
Branch: refs/heads/master
Commit: 084a4adee2f286f1babec035382fae36812ec3c9
Parents: 683a2bb
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Mon Apr 11 15:17:11 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Mon Apr 11 15:17:11 2016 +0100
----------------------------------------------------------------------
.../org/apache/commons/rdf/api/Dataset.java | 49 +------
.../apache/commons/rdf/api/GraphOrDataset.java | 135 +------------------
.../apache/commons/rdf/simple/DatasetImpl.java | 47 ++-----
3 files changed, 14 insertions(+), 217 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/084a4ade/api/src/main/java/org/apache/commons/rdf/api/Dataset.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Dataset.java b/api/src/main/java/org/apache/commons/rdf/api/Dataset.java
index fca9810..04d0030 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/Dataset.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/Dataset.java
@@ -40,23 +40,6 @@ public interface Dataset extends AutoCloseable, GraphOrDataset<Quad> {
void add(Quad quad);
/**
- * Add a triple to the default graph of this dataset, possibly mapping any
- * of the components to those supported by this dataset.
- * <p>
- * This method is equivalent to
- * {@link #add(BlankNodeOrIRI, BlankNodeOrIRI, IRI, RDFTerm)} with
- * <code>graphName</code> set as <code>null</code>.
- *
- * @param subject
- * The quad subject
- * @param predicate
- * The quad predicate
- * @param object
- * The quad object
- */
- void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
-
- /**
* Add a quad to the dataset, possibly mapping any of the components to
* those supported by this dataset.
*
@@ -82,24 +65,6 @@ public interface Dataset extends AutoCloseable, GraphOrDataset<Quad> {
boolean contains(Quad quad);
/**
- * Check if the default graph in the dataset contains a triple pattern.
- * <p>
- * This method is equivalent to
- * {@link #contains(Optional, BlankNodeOrIRI, IRI, RDFTerm)} with a
- * <code>graphName</code> set to <code>null</code>
- *
- * @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 True if the default graph in the dataset contains any quads that
- * match the given pattern.
- */
- boolean contains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
-
- /**
* Check if dataset contains a pattern of quads.
*
* @param graphName
@@ -144,18 +109,6 @@ public interface Dataset extends AutoCloseable, GraphOrDataset<Quad> {
/**
* Remove a concrete pattern of quads from the default graph of the dataset.
*
- * @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(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
-
- /**
- * 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
@@ -315,6 +268,6 @@ public interface Dataset extends AutoCloseable, GraphOrDataset<Quad> {
@SuppressWarnings("unchecked")
default Iterable<Quad> iterate(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate,
RDFTerm object) throws ConcurrentModificationException, IllegalStateException {
- return ((Stream<Quad>) getQuads(null, subject, predicate, object))::iterator;
+ return ((Stream<Quad>) getQuads(graphName, subject, predicate, object))::iterator;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/084a4ade/api/src/main/java/org/apache/commons/rdf/api/GraphOrDataset.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/GraphOrDataset.java b/api/src/main/java/org/apache/commons/rdf/api/GraphOrDataset.java
index f41463a..87a1137 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/GraphOrDataset.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/GraphOrDataset.java
@@ -19,7 +19,6 @@ package org.apache.commons.rdf.api;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
-import java.util.stream.Stream;
/**
* Common interface for {@link Graph} and {@link Dataset}
@@ -37,17 +36,6 @@ public interface GraphOrDataset<T extends TripleOrQuad> extends AutoCloseable {
void add(T tripleOrQuad);
/**
- * Add a triple to the Graph, (or the default graph of a Dataset),
- * possibly mapping any of the components to
- * those supported by this graph/dataset.
- *
- * @param subject The triple subject
- * @param predicate The triple predicate
- * @param object The triple object
- */
- void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
-
- /**
* Check if graph/dataset contains triple/quad.
*
* @param tripleOrQuad The triple/quad to check.
@@ -56,21 +44,6 @@ public interface GraphOrDataset<T extends TripleOrQuad> extends AutoCloseable {
boolean contains(T tripleOrQuad);
/**
- * Check if graph/dataset contains a pattern of triples or quads in the
- * default graph of a dataset.
- *
- * @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 this graph/dataset contains any triples/quads
- * that match the given pattern.
- */
- boolean contains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
-
- /**
* Close the graph/dataset, relinquishing any underlying resources.
* <p>
* For example, this would close any open file and network streams and free
@@ -94,16 +67,6 @@ public interface GraphOrDataset<T extends TripleOrQuad> extends AutoCloseable {
void remove(T tripleOrQuad);
/**
- * Remove a concrete pattern of triples from the graph, or
- * quads from the default graph of a dataset.
- *
- * @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);
-
- /**
* Clear the graph/dataset, removing all triples/quads.
*/
void clear();
@@ -116,49 +79,7 @@ public interface GraphOrDataset<T extends TripleOrQuad> extends AutoCloseable {
long size();
/**
- * Get all triples contained by the graph, or
- * the equivalent of {@link Quad#asTriple()}
- * for all quads of the default graph of a dataset.
- * <p>
- * The iteration does not contain any duplicate triples, as determined by
- * the {@link Triple#equals(Object)} method for each {@link Triple}.
- * <p>
- * The behaviour of the {@link Stream} is not specified if {@link #add(TripleOrQuad)},
- * {@link #remove(TripleOrQuad)} or {@link #clear()} are called on the
- * {@link GraphOrDataset} 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 triples in the graph
- */
- Stream<? extends Triple> getTriples();
-
- /**
- * Get all triples contained by the graph matched with the pattern, or
- * the equivalent of {@link Quad#asTriple()}
- * for all quads of the default graph of a dataset that match 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>
- * The behaviour of the {@link Stream} is not specified if {@link #add(TripleOrQuad)},
- * {@link #remove(TripleOrQuad)} or {@link #clear()} are called on the
- * {@link GraphOrDataset} before it terminates.
- * <p>
- * Implementations may throw {@link ConcurrentModificationException} from Stream
- * methods if they detect a conflict while the Stream is active.
- *
- * @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> getTriples(BlankNodeOrIRI subject, IRI predicate,
- RDFTerm object);
-
- /**
- * Get an Iterable for iterating over all triples in the graph.
+ * Get an Iterable for iterating over all triples/quads in the graph/dataset.
* <p>
* This method is meant to be used with a Java for-each loop, e.g.:
* <pre>
@@ -187,57 +108,7 @@ public interface GraphOrDataset<T extends TripleOrQuad> extends AutoCloseable {
* if a concurrency conflict occurs while the Iterator is
* active.
*/
- @SuppressWarnings("unchecked")
- default Iterable<T> iterate()
- throws ConcurrentModificationException, IllegalStateException {
- return ((Stream<T>)getTriples())::iterator;
- }
+ Iterable<T> iterate()
+ throws ConcurrentModificationException, IllegalStateException;
- /**
- * Get an Iterable for iterating over the triples in the graph
- * or quads in the default graph of a dataset that
- * match the pattern.
- * <p>
- * This method is meant to be used with a Java for-each loop, e.g.:
- * <pre>
- * IRI alice = factory.createIRI("http://example.com/alice");
- * IRI knows = factory.createIRI("http://xmlns.com/foaf/0.1/");
- * for (Triple t : graphOrDataset.iterate(alice, knows, null)) {
- * System.out.println(t.getObject());
- * }
- * </pre>
- * <p>
- * The behaviour of the iterator is not specified if
- * {@link #add(TripleOrQuad)}, {@link #remove(TripleOrQuad)} or {@link #clear()}, are
- * called on the {@link GraphOrDataset} before it terminates. It is undefined if the
- * returned {@link Iterator} supports the {@link Iterator#remove()} method.
- * <p>
- * Implementations may throw {@link ConcurrentModificationException} from
- * Iterator methods if they detect a concurrency conflict while the Iterator
- * is active.
- * <p>
- * The {@link Iterable#iterator()} must only be called once, that is the
- * Iterable must only be iterated over once. A {@link IllegalStateException}
- * may be thrown on attempt to reuse the Iterable.
- *
- * @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 Iterable} that returns {@link Iterator} over the
- * matching triples in the graph
- * @throws IllegalStateException
- * if the {@link Iterable} has been reused
- * @throws ConcurrentModificationException
- * if a concurrency conflict occurs while the Iterator is
- * active.
- */
- @SuppressWarnings("unchecked")
- default Iterable<T> iterate(
- BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
- throws ConcurrentModificationException, IllegalStateException {
- return ((Stream<T>) getTriples(subject, predicate, object))::iterator;
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/084a4ade/simple/src/main/java/org/apache/commons/rdf/simple/DatasetImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/DatasetImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/DatasetImpl.java
index 64cf57d..63d4025 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/DatasetImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/DatasetImpl.java
@@ -17,9 +17,6 @@
*/
package org.apache.commons.rdf.simple;
-import org.apache.commons.rdf.api.*;
-import org.apache.commons.rdf.simple.SimpleRDFTermFactory.SimpleRDFTerm;
-
import java.util.HashSet;
import java.util.Objects;
import java.util.Optional;
@@ -28,6 +25,15 @@ import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import org.apache.commons.rdf.api.BlankNode;
+import org.apache.commons.rdf.api.BlankNodeOrIRI;
+import org.apache.commons.rdf.api.Dataset;
+import org.apache.commons.rdf.api.IRI;
+import org.apache.commons.rdf.api.Literal;
+import org.apache.commons.rdf.api.Quad;
+import org.apache.commons.rdf.api.RDFTerm;
+import org.apache.commons.rdf.simple.SimpleRDFTermFactory.SimpleRDFTerm;
+
/**
* A simple, memory-based implementation of Dataset.
* <p>
@@ -44,12 +50,6 @@ final class DatasetImpl implements Dataset {
DatasetImpl(SimpleRDFTermFactory simpleRDFTermFactory) {
this.factory = simpleRDFTermFactory;
}
-
- @Override
- public void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- // TODO: Should this method be promoted as a default method in Dataset?
- add(null, subject, predicate, object);
- }
@Override
public void add(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
@@ -117,13 +117,6 @@ final class DatasetImpl implements Dataset {
quads.clear();
}
- @Override
- public boolean contains(BlankNodeOrIRI subject, IRI predicate,
- RDFTerm object) {
- // TODO: Should this method be promoted as a default method in Dataset?
- return getQuads(Optional.empty(), subject, predicate, object).findAny().isPresent();
- }
-
@Override
public boolean contains(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
return getQuads(graphName, subject, predicate, object).findAny().isPresent();
@@ -165,29 +158,10 @@ final class DatasetImpl implements Dataset {
});
}
- @Override
- public Stream<Triple> getTriples() {
- // TODO: Should this method be promoted as a default method in Dataset?
- return getQuads(Optional.empty(), null, null, null).map(Quad::asTriple);
- }
-
- @Override
- public Stream<Triple> getTriples(final BlankNodeOrIRI subject,
- final IRI predicate, final RDFTerm object) {
- // TODO: Should this method be promoted as a default method in Dataset?
- return getQuads(Optional.empty(), subject, predicate, object).map(Quad::asTriple);
- }
-
private Stream<Quad> getQuads(final Predicate<Quad> filter) {
return getQuads().filter(filter);
}
- @Override
- public void remove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- // TODO: Should this method be promoted as a default method in Dataset?
- remove(Optional.empty(), subject, predicate, object);
- }
-
@Override
public void remove(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
Stream<Quad> toRemove = getQuads(graphName, subject, predicate, object);
@@ -197,7 +171,6 @@ final class DatasetImpl implements Dataset {
}
}
-
@Override
public void remove(Quad quad) {
quads.remove(Objects.requireNonNull(quad));
@@ -210,7 +183,7 @@ final class DatasetImpl implements Dataset {
@Override
public String toString() {
- String s = getTriples().limit(TO_STRING_MAX).map(Object::toString)
+ String s = getQuads().limit(TO_STRING_MAX).map(Object::toString)
.collect(Collectors.joining("\n"));
if (size() > TO_STRING_MAX) {
return s + "\n# ... +" + (size() - TO_STRING_MAX) + " more";
[02/19] incubator-commonsrdf git commit: GraphOrDataset superinterface
Posted by st...@apache.org.
GraphOrDataset superinterface
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/93f99826
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/93f99826
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/93f99826
Branch: refs/heads/master
Commit: 93f99826ac704d7804e78fe3e2dcbd7604614ace
Parents: 7639fd7
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Apr 8 14:25:09 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Apr 8 14:25:09 2016 +0100
----------------------------------------------------------------------
.../java/org/apache/commons/rdf/api/Graph.java | 2 +-
.../apache/commons/rdf/api/GraphOrDataset.java | 236 +++++++++++++++++++
2 files changed, 237 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/93f99826/api/src/main/java/org/apache/commons/rdf/api/Graph.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Graph.java b/api/src/main/java/org/apache/commons/rdf/api/Graph.java
index c421226..019a713 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/Graph.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/Graph.java
@@ -27,7 +27,7 @@ import java.util.stream.Stream;
* href="http://www.w3.org/TR/rdf11-concepts/" >RDF-1.1 Concepts and Abstract
* Syntax</a>, a W3C Recommendation published on 25 February 2014.
*/
-public interface Graph extends AutoCloseable {
+public interface Graph extends AutoCloseable, GraphOrDataset<Triple> {
/**
* Add a triple to the graph, possibly mapping any of the components of the
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/93f99826/api/src/main/java/org/apache/commons/rdf/api/GraphOrDataset.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/GraphOrDataset.java b/api/src/main/java/org/apache/commons/rdf/api/GraphOrDataset.java
new file mode 100644
index 0000000..35017fb
--- /dev/null
+++ b/api/src/main/java/org/apache/commons/rdf/api/GraphOrDataset.java
@@ -0,0 +1,236 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.rdf.api;
+
+import java.util.ConcurrentModificationException;
+import java.util.Iterator;
+import java.util.stream.Stream;
+
+/**
+ * An <a href="http://www.w3.org/TR/rdf11-concepts/#section-rdf-graph"> RDF 1.1
+ * Graph</a>, a set of RDF triples, as defined by <a
+ * href="http://www.w3.org/TR/rdf11-concepts/" >RDF-1.1 Concepts and Abstract
+ * Syntax</a>, a W3C Recommendation published on 25 February 2014.
+ */
+public interface GraphOrDataset<T extends TripleOrQuad> extends AutoCloseable {
+
+ /**
+ * Add a triple to the graph, possibly mapping any of the components of the
+ * Triple to those supported by this Graph.
+ *
+ * @param triple The triple or quad to add
+ */
+ void add(T triple);
+
+ /**
+ * Add a triple to the graph, possibly mapping any of the components to
+ * those supported by this Graph.
+ *
+ * @param subject The triple subject
+ * @param predicate The triple predicate
+ * @param object The triple object
+ */
+ void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
+
+ /**
+ * Check if graph contains triple.
+ *
+ * @param triple The triple to check.
+ * @return True if the Graph contains the given Triple.
+ */
+ boolean contains(T triple);
+
+ /**
+ * Check 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.
+ */
+ boolean contains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
+
+ /**
+ * Close the graph, relinquishing any underlying resources.
+ * <p>
+ * For example, this would close any open file and network streams and free
+ * database locks held by the Graph implementation.
+ * <p>
+ * The behaviour of the other Graph methods are undefined after closing the
+ * graph.
+ * <p>
+ * Implementations might not need {@link #close()}, hence the default
+ * implementation does nothing.
+ */
+ @Override
+ default void close() throws Exception {
+ }
+
+ /**
+ * Remove a concrete triple from the graph.
+ *
+ * @param triple triple to remove
+ */
+ void remove(T triple);
+
+ /**
+ * Remove 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);
+
+ /**
+ * Clear the graph, removing all triples.
+ */
+ void clear();
+
+ /**
+ * Number of triples contained by the graph.
+ * <p>
+ * The count of a set does not include duplicates, consistent with the
+ * {@link T#equals(Object)} equals method for each {@link T}.
+ *
+ * @return The number of triples in the graph
+ */
+ long size();
+
+ /**
+ * Get all triples contained by the graph.<br>
+ * <p>
+ * The iteration does not contain any duplicate triples, as determined by
+ * the {@link T#equals(Object)} method for each {@link T}.
+ * <p>
+ * The behaviour of the {@link Stream} is not specified if {@link #add(T)},
+ * {@link #remove(T)} or {@link #clear()} are called on the
+ * {@link GraphOrDataset} 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 triples in the graph
+ */
+ Stream<? extends T> getTriples();
+
+ /**
+ * Get all triples contained by the graph matched with the pattern.
+ * <p>
+ * The iteration does not contain any duplicate triples, as determined by
+ * the {@link T#equals(Object)} method for each {@link T}.
+ * <p>
+ * The behaviour of the {@link Stream} is not specified if {@link #add(T)},
+ * {@link #remove(T)} or {@link #clear()} are called on the
+ * {@link GraphOrDataset} before it terminates.
+ * <p>
+ * Implementations may throw {@link ConcurrentModificationException} from Stream
+ * methods if they detect a conflict while the Stream is active.
+ *
+ * @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 T> getTriples(BlankNodeOrIRI subject, IRI predicate,
+ RDFTerm object);
+
+ /**
+ * Get an Iterable for iterating over all triples in the graph.
+ * <p>
+ * This method is meant to be used with a Java for-each loop, e.g.:
+ * <pre>
+ * for (Triple t : graph.iterate()) {
+ * System.out.println(t);
+ * }
+ * </pre>
+ * The behaviour of the iterator is not specified if {@link #add(T)},
+ * {@link #remove(T)} or {@link #clear()}, are called on the
+ * {@link GraphOrDataset} before it terminates. It is undefined if the returned
+ * {@link Iterator} supports the {@link Iterator#remove()} method.
+ * <p>
+ * Implementations may throw {@link ConcurrentModificationException} from
+ * Iterator methods if they detect a concurrency conflict while the Iterator
+ * is active.
+ * <p>
+ * The {@link Iterable#iterator()} must only be called once, that is the
+ * Iterable must only be iterated over once. A {@link IllegalStateException}
+ * may be thrown on attempt to reuse the Iterable.
+ *
+ * @return A {@link Iterable} that returns {@link Iterator} over all of the
+ * triples in the graph
+ * @throws IllegalStateException
+ * if the {@link Iterable} has been reused
+ * @throws ConcurrentModificationException
+ * if a concurrency conflict occurs while the Iterator is
+ * active.
+ */
+ @SuppressWarnings("unchecked")
+ default Iterable<T> iterate()
+ throws ConcurrentModificationException, IllegalStateException {
+ return ((Stream<T>)getTriples())::iterator;
+ }
+
+ /**
+ * Get an Iterable for iterating over the triples in the graph that match
+ * the pattern.
+ * <p>
+ * This method is meant to be used with a Java for-each loop, e.g.:
+ * <pre>
+ * IRI alice = factory.createIRI("http://example.com/alice");
+ * IRI knows = factory.createIRI("http://xmlns.com/foaf/0.1/");
+ * for (Triple t : graph.iterate(alice, knows, null)) {
+ * System.out.println(t.getObject());
+ * }
+ * </pre>
+ * <p>
+ * The behaviour of the iterator is not specified if
+ * {@link #add(T)}, {@link #remove(T)} or {@link #clear()}, are
+ * called on the {@link GraphOrDataset} before it terminates. It is undefined if the
+ * returned {@link Iterator} supports the {@link Iterator#remove()} method.
+ * <p>
+ * Implementations may throw {@link ConcurrentModificationException} from
+ * Iterator methods if they detect a concurrency conflict while the Iterator
+ * is active.
+ * <p>
+ * The {@link Iterable#iterator()} must only be called once, that is the
+ * Iterable must only be iterated over once. A {@link IllegalStateException}
+ * may be thrown on attempt to reuse the Iterable.
+ *
+ * @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 Iterable} that returns {@link Iterator} over the
+ * matching triples in the graph
+ * @throws IllegalStateException
+ * if the {@link Iterable} has been reused
+ * @throws ConcurrentModificationException
+ * if a concurrency conflict occurs while the Iterator is
+ * active.
+ */
+ @SuppressWarnings("unchecked")
+ default Iterable<T> iterate(
+ BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
+ throws ConcurrentModificationException, IllegalStateException {
+ return ((Stream<T>) getTriples(subject, predicate, object))::iterator;
+ }
+}
[04/19] incubator-commonsrdf git commit: added createDataset() and
createQuad()
Posted by st...@apache.org.
added createDataset() and createQuad()
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/5e952b5f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/5e952b5f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/5e952b5f
Branch: refs/heads/master
Commit: 5e952b5f6e1b9fdf95fb0f4ae2e83470e4169f0d
Parents: 63745d3
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Apr 8 14:52:44 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Apr 8 14:52:44 2016 +0100
----------------------------------------------------------------------
.../apache/commons/rdf/api/RDFTermFactory.java | 40 ++++++++++++++++++++
1 file changed, 40 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/5e952b5f/api/src/main/java/org/apache/commons/rdf/api/RDFTermFactory.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/RDFTermFactory.java b/api/src/main/java/org/apache/commons/rdf/api/RDFTermFactory.java
index 41a7b94..f2a6f95 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/RDFTermFactory.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/RDFTermFactory.java
@@ -99,6 +99,19 @@ public interface RDFTermFactory {
}
/**
+ * Create a new dataset.
+ *
+ * It is undefined if the dataset will be persisted by any underlying storage
+ * mechanism.
+ *
+ * @return A new Dataset
+ * @throws UnsupportedOperationException If the operation is not supported.
+ */
+ default Dataset createDataset() throws UnsupportedOperationException {
+ throw new UnsupportedOperationException("createDataset() not supported");
+ }
+
+ /**
* Create an IRI from a (possibly escaped) String.
*
* The provided iri string MUST be valid according to the <a
@@ -234,4 +247,31 @@ public interface RDFTermFactory {
"createTriple(BlankNodeOrIRI,IRI,RDFTerm) not supported");
}
+ /**
+ * Create a quad.
+ * <p>
+ * The returned Quad SHOULD have a
+ * {@link Quad#getGraphName()} that is equal to the provided graphName, a
+ * {@link Quad#getSubject()} that is
+ * equal to the provided subject, a {@link Quad#getPredicate()} that is
+ * equal to the provided predicate, and a {@link Quad#getObject()} that is
+ * equal to the provided object.
+ *
+ * @param graphName The IRI or BlankNode that this quad belongs to, or <code>null</code> for the default graph
+ * @param subject The IRI or BlankNode that is the subject of the quad
+ * @param predicate The IRI that is the predicate of the quad
+ * @param object The IRI, BlankNode or Literal that is the object of the quad
+ * @return The created Quad
+ * @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.
+ * @throws UnsupportedOperationException If the operation is not supported.
+ */
+ default Quad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate,
+ RDFTerm object) throws IllegalArgumentException,
+ UnsupportedOperationException {
+ throw new UnsupportedOperationException(
+ "createTriple(BlankNodeOrIRI,IRI,RDFTerm) not supported");
+ }
+
}
[09/19] incubator-commonsrdf git commit: Remove GraphOrDataset
Posted by st...@apache.org.
Remove GraphOrDataset
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/bfa15b89
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/bfa15b89
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/bfa15b89
Branch: refs/heads/master
Commit: bfa15b89dad8ea6b9db3d4fbd942966b971ebd96
Parents: 084a4ad
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Apr 13 01:07:15 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Apr 13 01:07:15 2016 +0100
----------------------------------------------------------------------
.../org/apache/commons/rdf/api/Dataset.java | 2 +-
.../java/org/apache/commons/rdf/api/Graph.java | 2 +-
.../apache/commons/rdf/api/GraphOrDataset.java | 114 -------------------
3 files changed, 2 insertions(+), 116 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/bfa15b89/api/src/main/java/org/apache/commons/rdf/api/Dataset.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Dataset.java b/api/src/main/java/org/apache/commons/rdf/api/Dataset.java
index 04d0030..3d24022 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/Dataset.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/Dataset.java
@@ -28,7 +28,7 @@ import java.util.stream.Stream;
* <a href="http://www.w3.org/TR/rdf11-concepts/" >RDF-1.1 Concepts and Abstract
* Syntax</a>, a W3C Recommendation published on 25 February 2014.
*/
-public interface Dataset extends AutoCloseable, GraphOrDataset<Quad> {
+public interface Dataset extends AutoCloseable {
/**
* Add a quad to the dataset, possibly mapping any of the components of the
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/bfa15b89/api/src/main/java/org/apache/commons/rdf/api/Graph.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Graph.java b/api/src/main/java/org/apache/commons/rdf/api/Graph.java
index 019a713..c421226 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/Graph.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/Graph.java
@@ -27,7 +27,7 @@ import java.util.stream.Stream;
* href="http://www.w3.org/TR/rdf11-concepts/" >RDF-1.1 Concepts and Abstract
* Syntax</a>, a W3C Recommendation published on 25 February 2014.
*/
-public interface Graph extends AutoCloseable, GraphOrDataset<Triple> {
+public interface Graph extends AutoCloseable {
/**
* Add a triple to the graph, possibly mapping any of the components of the
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/bfa15b89/api/src/main/java/org/apache/commons/rdf/api/GraphOrDataset.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/GraphOrDataset.java b/api/src/main/java/org/apache/commons/rdf/api/GraphOrDataset.java
deleted file mode 100644
index 87a1137..0000000
--- a/api/src/main/java/org/apache/commons/rdf/api/GraphOrDataset.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.rdf.api;
-
-import java.util.ConcurrentModificationException;
-import java.util.Iterator;
-
-/**
- * Common interface for {@link Graph} and {@link Dataset}
- * <p>
- *
- */
-public interface GraphOrDataset<T extends TripleOrQuad> extends AutoCloseable {
-
- /**
- * Add a triple/quad to the graph, possibly mapping any of the components of the
- * TripleOrQuad to those supported by this Graph.
- *
- * @param tripleOrQuad The triple or quad to add
- */
- void add(T tripleOrQuad);
-
- /**
- * Check if graph/dataset contains triple/quad.
- *
- * @param tripleOrQuad The triple/quad to check.
- * @return True if this graph/dataset contains the given Triple.
- */
- boolean contains(T tripleOrQuad);
-
- /**
- * Close the graph/dataset, relinquishing any underlying resources.
- * <p>
- * For example, this would close any open file and network streams and free
- * database locks held by the Graph implementation.
- * <p>
- * The behaviour of the other Graph methods are undefined after closing the
- * graph.
- * <p>
- * Implementations might not need {@link #close()}, hence the default
- * implementation does nothing.
- */
- @Override
- default void close() throws Exception {
- }
-
- /**
- * Remove a concrete triple/quad from the graph.
- *
- * @param tripleOrQuad triple/quad to remove
- */
- void remove(T tripleOrQuad);
-
- /**
- * Clear the graph/dataset, removing all triples/quads.
- */
- void clear();
-
- /**
- * Number of triples/quads contained by the graph/dataset.
- *
- * @return The number of triples/quads in the graph/dataset
- */
- long size();
-
- /**
- * Get an Iterable for iterating over all triples/quads in the graph/dataset.
- * <p>
- * This method is meant to be used with a Java for-each loop, e.g.:
- * <pre>
- * for (TripleOrQuad t : graphOrDataset.iterate()) {
- * System.out.println(t);
- * }
- * </pre>
- * The behaviour of the iterator is not specified if {@link #add(TripleOrQuad)},
- * {@link #remove(TripleOrQuad)} or {@link #clear()}, are called on the
- * {@link GraphOrDataset} before it terminates. It is undefined if the returned
- * {@link Iterator} supports the {@link Iterator#remove()} method.
- * <p>
- * Implementations may throw {@link ConcurrentModificationException} from
- * Iterator methods if they detect a concurrency conflict while the Iterator
- * is active.
- * <p>
- * The {@link Iterable#iterator()} must only be called once, that is the
- * Iterable must only be iterated over once. A {@link IllegalStateException}
- * may be thrown on attempt to reuse the Iterable.
- *
- * @return A {@link Iterable} that returns {@link Iterator} over all of the
- * triples in the graph
- * @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;
-
-}
[18/19] incubator-commonsrdf git commit: COMMONSRDF-37: Improve Quad
javadoc
Posted by st...@apache.org.
COMMONSRDF-37: Improve Quad javadoc
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/a1d65546
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/a1d65546
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/a1d65546
Branch: refs/heads/master
Commit: a1d65546388f3d9acf56456d08d923aae3beaa41
Parents: 53ef228
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Thu Jul 7 10:47:06 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Thu Jul 7 10:47:06 2016 +0100
----------------------------------------------------------------------
.../org/apache/commons/rdf/api/GraphLike.java | 21 +++++++++++++++---
.../java/org/apache/commons/rdf/api/Quad.java | 23 +++++++++++---------
.../org/apache/commons/rdf/api/QuadLike.java | 18 +++++++++++----
.../org/apache/commons/rdf/api/TripleLike.java | 14 +++++++++---
.../commons/rdf/simple/DatasetGraphView.java | 2 +-
5 files changed, 57 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/a1d65546/api/src/main/java/org/apache/commons/rdf/api/GraphLike.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/GraphLike.java b/api/src/main/java/org/apache/commons/rdf/api/GraphLike.java
index c68278e..bd37510 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/GraphLike.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/GraphLike.java
@@ -30,7 +30,23 @@ import java.util.stream.Stream;
* generalised {@link TripleLike} or {@link QuadLike} statements, and does not
* include semantics like {@link #size()} or the requirement of mapping
* {@link RDFTerm} instances from different implementations.
+ * <p>
+ * As {@link TripleLike} do not have a specific {@link Object#equals(Object)}
+ * semantics, the behaviour of methods like {@link #contains(TripleLike)} and
+ * {@link #remove(TripleLike)} is undefined for arguments that are not object
+ * identical to previously added or returned {@link TripleLike} statements.
*
+ * @param <T>
+ * A {@link TripleLike} type used by the graph methods, typically
+ * {@link Triple} or {@link Quad}
+ * @param <S>
+ * The type of subjects in the statements, typically
+ * {@link BlankNodeOrIRI}
+ * @param <P>
+ * The type of predicates in the statements, typically {@link IRI}
+ * @param <O>
+ * The type of objects in the statements, typically {@link RDFTerm}
+ *
* @since 0.3.0-incubating
* @see Graph
* @see Dataset
@@ -50,7 +66,7 @@ public interface GraphLike<T extends TripleLike<S, P, O>, S extends RDFTerm, P e
* Check if statement is contained.
*
* @param statement
- * The {@link TripleLike} statement to chec
+ * The {@link TripleLike} statement to check
* @return True if the statement is contained
*/
boolean contains(T statement);
@@ -71,7 +87,7 @@ public interface GraphLike<T extends TripleLike<S, P, O>, S extends RDFTerm, P e
/**
* Number of statements.
*
- * @return
+ * @return Number of statements
*/
long size();
@@ -86,7 +102,6 @@ public interface GraphLike<T extends TripleLike<S, P, O>, S extends RDFTerm, P e
* Iterate over contained statements.
*
* @return An {@link Iterable} of {@link TripleLike} statements.
- *
* @throws IllegalStateException
* if the {@link Iterable} has been reused
* @throws ConcurrentModificationException
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/a1d65546/api/src/main/java/org/apache/commons/rdf/api/Quad.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Quad.java b/api/src/main/java/org/apache/commons/rdf/api/Quad.java
index 5a67571..679000b 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/Quad.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/Quad.java
@@ -67,31 +67,31 @@ public interface Quad extends QuadLike<BlankNodeOrIRI,IRI,RDFTerm,BlankNodeOrIRI
BlankNodeOrIRI getSubject();
/**
- * The predicate {@link IRI} of this triple.
+ * The predicate {@link IRI} of this quad.
*
- * @return The predicate {@link IRI} of this triple.
+ * @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>
*/
IRI getPredicate();
/**
- * The object of this triple, which may be either a {@link BlankNode}, an
+ * 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 triple.
+ * @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>
*/
RDFTerm getObject();
/**
- * Convert this Quad to a Triple.
+ * Adapt this Quad to a Triple.
* <p>
* The returned {@link Triple} will have equivalent values returned from the
- * methods {@link TripleOrQuad#getSubject()},
- * {@link TripleOrQuad#getPredicate()} and {@link TripleOrQuad#getObject()}.
+ * methods {@link TripleLike#getSubject()},
+ * {@link TripleLike#getPredicate()} and {@link TripleLike#getObject()}.
* <p>
* The returned {@link Triple} MUST NOT be {@link #equals(Object)} to this
* {@link Quad}, even if this quad has a default graph
@@ -113,12 +113,12 @@ public interface Quad extends QuadLike<BlankNodeOrIRI,IRI,RDFTerm,BlankNodeOrIRI
*
* The <code>default</code> implementation of this method return a proxy
* {@link Triple} instance that keeps a reference to this {@link Quad} to
- * calls the underlying {@link TripleOrQuad} methods, but supplies a
+ * call the underlying {@link TripleLike} methods, but supplies a
* {@link Triple} compatible implementation of {@link Triple#equals(Object)}
* and {@link Triple#hashCode()}. Implementations may override this method,
* e.g. for a more efficient solution.
*
- * @return A {@link Triple} that contains the same {@link TripleOrQuad}
+ * @return A {@link Triple} that contains the same {@link TripleLike}
* properties as this Quad.
*/
default Triple asTriple() {
@@ -140,6 +140,9 @@ public interface Quad extends QuadLike<BlankNodeOrIRI,IRI,RDFTerm,BlankNodeOrIRI
@Override
public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
if (!(obj instanceof Triple)) {
return false;
}
@@ -159,7 +162,7 @@ public interface Quad extends QuadLike<BlankNodeOrIRI,IRI,RDFTerm,BlankNodeOrIRI
/**
* Check it this Quad is equal to another Quad.
* <p>
- * Two Triples are equal if and only if their {@link #getGraphName()},
+ * Two Quads are equal if and only if their {@link #getGraphName()},
* {@link #getSubject()}, {@link #getPredicate()} and
* {@link #getObject()} are equal.
* </p>
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/a1d65546/api/src/main/java/org/apache/commons/rdf/api/QuadLike.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/QuadLike.java b/api/src/main/java/org/apache/commons/rdf/api/QuadLike.java
index 9c42465..3f85862 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/QuadLike.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/QuadLike.java
@@ -28,10 +28,20 @@ import java.util.Optional;
* {@link Quad#equals(Object)} semantics, and can allow generalised quads (e.g.
* a {@link BlankNode} as predicate).
* <p>
- * Implementations should specialise which {@link RDFTerm} subclasses they
- * return for subject {@link S}, predicate {@link P}, object {@link O} and graph
- * name {@link G}.
- * <p>
+ * Implementations should specialise which specific {@link RDFTerm} types they
+ * return for {@link #getSubject()}, {@link #getPredicate()},
+ * {@link #getObject()} and {@link #getGraphName()}.
+ *
+ * @param <S>
+ * The type of subjects in the statements, typically
+ * {@link BlankNodeOrIRI}
+ * @param <P>
+ * The type of predicates in the statements, typically {@link IRI}
+ * @param <O>
+ * The type of objects in the statements, typically {@link RDFTerm}
+ * @param <G>
+ * The type of graph names in the statements, typically
+ * {@link BlankNodeOrIRI}
*
* @since 0.3.0-incubating
* @see Quad
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/a1d65546/api/src/main/java/org/apache/commons/rdf/api/TripleLike.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/TripleLike.java b/api/src/main/java/org/apache/commons/rdf/api/TripleLike.java
index 2fbeb11..9bead97 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/TripleLike.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/TripleLike.java
@@ -26,14 +26,22 @@ package org.apache.commons.rdf.api;
* does not have a formalised {@link Triple#equals(Object)} semantics, and can
* allow generalised triples (e.g. a {@link BlankNode} as predicate).
* <p>
- * Implementations should specialise which {@link RDFTerm} subclasses they
- * return for subject {@link S}, predicate {@link P} and object {@link O}.
+ * Implementations should specialise which specific {@link RDFTerm} types they
+ * return for {@link #getSubject()}, {@link #getPredicate()} and
+ * {@link #getObject()}.
+ *
+ * @param <S>
+ * The type of subjects in the statements, typically
+ * {@link BlankNodeOrIRI}
+ * @param <P>
+ * The type of predicates in the statements, typically {@link IRI}
+ * @param <O>
+ * The type of objects in the statements, typically {@link RDFTerm}
*
* @since 0.3.0-incubating
* @see Triple
* @see Quad
* @see QuadLike
- *
*/
public interface TripleLike<S extends RDFTerm, P extends RDFTerm, O extends RDFTerm> {
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/a1d65546/simple/src/main/java/org/apache/commons/rdf/simple/DatasetGraphView.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/DatasetGraphView.java b/simple/src/main/java/org/apache/commons/rdf/simple/DatasetGraphView.java
index a347c3e..d578a40 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/DatasetGraphView.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/DatasetGraphView.java
@@ -41,7 +41,7 @@ import org.apache.commons.rdf.api.Triple;
* triples will add them to the <em>default graph</em>, while removing triples
* will remove from all graphs.</dd>
*
- * <dt>{@link #DatasetGraphView(Dataset, IRI)}</dt>
+ * <dt>{@link #DatasetGraphView(Dataset, BlankNodeOrIRI)}</dt>
* <dd>Expose a particular graph of the Dataset, either named by an {@link IRI}, a
* {@link BlankNode}, or <code>null</code> for the <em>default graph</em>.</dd>
* </dl>
[15/19] incubator-commonsrdf git commit: Include @Deprecated
getTriples()
Posted by st...@apache.org.
Include @Deprecated getTriples()
The default implementation calls .stream()
.. and @since for new Quad features
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/14e505e3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/14e505e3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/14e505e3
Branch: refs/heads/master
Commit: 14e505e33d10b72fc22efd5c7952ad63f16f2393
Parents: 14f246e
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Thu Jun 2 17:30:50 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Thu Jun 2 17:31:05 2016 +0100
----------------------------------------------------------------------
.../java/org/apache/commons/rdf/api/Graph.java | 30 ++++++++++++++++++--
.../org/apache/commons/rdf/api/GraphLike.java | 1 +
.../java/org/apache/commons/rdf/api/Quad.java | 1 +
.../org/apache/commons/rdf/api/QuadLike.java | 1 +
.../org/apache/commons/rdf/api/TripleLike.java | 1 +
.../commons/rdf/api/AbstractGraphTest.java | 4 +--
6 files changed, 33 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/14e505e3/api/src/main/java/org/apache/commons/rdf/api/Graph.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Graph.java b/api/src/main/java/org/apache/commons/rdf/api/Graph.java
index 42ced98..6106bab 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/Graph.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/Graph.java
@@ -125,11 +125,12 @@ public interface Graph extends AutoCloseable,GraphLike<Triple, BlankNodeOrIRI, I
* <p>
* Implementations may throw {@link ConcurrentModificationException} from Stream
* methods if they detect a conflict while the Stream is active.
- *
+ *
+ * @since 0.3.0-incubating
* @return A {@link Stream} over all of the triples in the graph
*/
Stream<? extends Triple> stream();
-
+
/**
* Get all triples contained by the graph matched with the pattern.
* <p>
@@ -142,7 +143,9 @@ public interface Graph extends AutoCloseable,GraphLike<Triple, BlankNodeOrIRI, I
* <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)
@@ -152,6 +155,27 @@ public interface Graph extends AutoCloseable,GraphLike<Triple, BlankNodeOrIRI, I
RDFTerm object);
/**
+ * This method is deprecated, use the equivalent method
+ * {@link #stream()} instead.
+ *
+ */
+ @Deprecated
+ default Stream<? extends Triple> getTriples() {
+ return stream();
+ }
+
+ /**
+ * This method is deprecated, use the equivalent method
+ * {@link #stream(BlankNodeOrIRI, IRI, RDFTerm)} instead.
+ *
+ */
+ @Deprecated
+ default Stream<? extends Triple> getTriples(BlankNodeOrIRI subject, IRI predicate,
+ RDFTerm object) {
+ return stream(subject, predicate, object);
+ }
+
+ /**
* Get an Iterable for iterating over all triples in the graph.
* <p>
* This method is meant to be used with a Java for-each loop, e.g.:
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/14e505e3/api/src/main/java/org/apache/commons/rdf/api/GraphLike.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/GraphLike.java b/api/src/main/java/org/apache/commons/rdf/api/GraphLike.java
index 28c2f10..c68278e 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/GraphLike.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/GraphLike.java
@@ -31,6 +31,7 @@ import java.util.stream.Stream;
* include semantics like {@link #size()} or the requirement of mapping
* {@link RDFTerm} instances from different implementations.
*
+ * @since 0.3.0-incubating
* @see Graph
* @see Dataset
* @see TripleLike
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/14e505e3/api/src/main/java/org/apache/commons/rdf/api/Quad.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Quad.java b/api/src/main/java/org/apache/commons/rdf/api/Quad.java
index 348595b..5a67571 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/Quad.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/Quad.java
@@ -28,6 +28,7 @@ import java.util.Optional;
* Concepts and Abstract Syntax</a>, a W3C Working Group Note published on 25
* February 2014.
*
+ * @since 0.3.0-incubating
* @see <a href="http://www.w3.org/TR/2014/NOTE-rdf11-datasets-20140225/">RDF
* 1.1: On Semantics of RDF Datasets</a>
* @see <a href="http://www.w3.org/TR/rdf11-concepts/#section-dataset"> </a>
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/14e505e3/api/src/main/java/org/apache/commons/rdf/api/QuadLike.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/QuadLike.java b/api/src/main/java/org/apache/commons/rdf/api/QuadLike.java
index 7ed7255..9c42465 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/QuadLike.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/QuadLike.java
@@ -33,6 +33,7 @@ import java.util.Optional;
* name {@link G}.
* <p>
*
+ * @since 0.3.0-incubating
* @see Quad
*/
public interface QuadLike<S extends RDFTerm, P extends RDFTerm, O extends RDFTerm, G extends RDFTerm>
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/14e505e3/api/src/main/java/org/apache/commons/rdf/api/TripleLike.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/TripleLike.java b/api/src/main/java/org/apache/commons/rdf/api/TripleLike.java
index c061cc7..2fbeb11 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/TripleLike.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/TripleLike.java
@@ -29,6 +29,7 @@ package org.apache.commons.rdf.api;
* Implementations should specialise which {@link RDFTerm} subclasses they
* return for subject {@link S}, predicate {@link P} and object {@link O}.
*
+ * @since 0.3.0-incubating
* @see Triple
* @see Quad
* @see QuadLike
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/14e505e3/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java b/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
index 27b9ff4..67191de 100644
--- a/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
+++ b/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
@@ -296,7 +296,7 @@ public abstract class AbstractGraphTest {
// look up BlankNodes by name
IRI name = factory.createIRI("http://xmlns.com/foaf/0.1/name");
- g3.getTriples(null, name, null).parallel().forEach( t ->
+ g3.stream(null, name, null).parallel().forEach( t ->
whoIsWho.put( t.getObject().ntriplesString(), t.getSubject()));
assertEquals(4, whoIsWho.size());
@@ -361,7 +361,7 @@ public abstract class AbstractGraphTest {
// unordered() as we don't need to preserve triple order
// sequential() as we don't (currently) require target Graph to be thread-safe
- source.getTriples().unordered().sequential().forEach(t -> target.add(t));
+ source.stream().unordered().sequential().forEach(t -> target.add(t));
}
/**
[03/19] incubator-commonsrdf git commit: Added Dataset (copy-paste of
Graph)
Posted by st...@apache.org.
Added Dataset (copy-paste of Graph)
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/63745d33
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/63745d33
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/63745d33
Branch: refs/heads/master
Commit: 63745d33b66d0ff28ab54e0c8edf65d76dbab931
Parents: 93f9982
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Apr 8 14:25:49 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Apr 8 14:50:57 2016 +0100
----------------------------------------------------------------------
.../org/apache/commons/rdf/api/Dataset.java | 322 +++++++++++++++++++
1 file changed, 322 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/63745d33/api/src/main/java/org/apache/commons/rdf/api/Dataset.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Dataset.java b/api/src/main/java/org/apache/commons/rdf/api/Dataset.java
new file mode 100644
index 0000000..70d5bff
--- /dev/null
+++ b/api/src/main/java/org/apache/commons/rdf/api/Dataset.java
@@ -0,0 +1,322 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.rdf.api;
+
+import java.util.ConcurrentModificationException;
+import java.util.Iterator;
+import java.util.Optional;
+import java.util.stream.Stream;
+
+/**
+ * An <a href="http://www.w3.org/TR/rdf11-concepts/#section-rdf-dataset"> RDF
+ * 1.1 dataset</a>, a set of RDF quads, as defined by
+ * <a href="http://www.w3.org/TR/rdf11-concepts/" >RDF-1.1 Concepts and Abstract
+ * Syntax</a>, a W3C Recommendation published on 25 February 2014.
+ */
+public interface Dataset extends AutoCloseable, GraphOrDataset<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
+ */
+ void add(Quad quad);
+
+ /**
+ * Add a triple to the default graph of this dataset, possibly mapping any
+ * of the components to those supported by this dataset.
+ * <p>
+ * This method is equivalent to
+ * {@link #add(BlankNodeOrIRI, BlankNodeOrIRI, IRI, RDFTerm)} with
+ * <code>graphName</code> set as <code>null</code>.
+ *
+ * @param subject
+ * The quad subject
+ * @param predicate
+ * The quad predicate
+ * @param object
+ * The quad object
+ */
+ void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
+
+ /**
+ * Add a quad to the dataset, possibly mapping any of the components to
+ * those supported by this dataset.
+ *
+ * @param graphName
+ * The graph the quad belongs to, or <code>null</code> for the
+ * default graph
+ * @param subject
+ * The quad subject
+ * @param predicate
+ * The quad predicate
+ * @param object
+ * The quad object
+ */
+ void add(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
+
+ /**
+ * Check if dataset contains quad.
+ *
+ * @param quad
+ * The quad to check.
+ * @return True if the dataset contains the given Quad.
+ */
+ boolean contains(Quad quad);
+
+ /**
+ * Check if the default graph in the dataset contains a triple pattern.
+ * <p>
+ * This method is equivalent to
+ * {@link #contains(Optional, BlankNodeOrIRI, IRI, RDFTerm)} with a
+ * <code>graphName</code> set to <code>null</code>
+ *
+ * @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 True if the default graph in the dataset contains any quads that
+ * match the given pattern.
+ */
+ boolean contains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
+
+ /**
+ * Check if dataset contains a pattern of quads.
+ *
+ * @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 True if the dataset contains any quads that match the given
+ * pattern.
+ */
+ 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 behaviour 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 {
+ }
+
+ /**
+ * Remove a concrete quad from the dataset.
+ *
+ * @param quad
+ * quad to remove
+ */
+ 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
+ * @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(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
+
+ /**
+ * 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.
+ */
+ 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
+ */
+ long size();
+
+ /**
+ * Get 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 behaviour 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
+ */
+ Stream<? extends Quad> getQuads();
+
+ /**
+ * Get 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 behaviour 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> getQuads(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate,
+ RDFTerm object);
+
+ /**
+ * Get an Iterable for iterating over all quads in the dataset.
+ * <p>
+ * This method is meant to be used with a Java for-each loop, e.g.:
+ *
+ * <pre>
+ * for (Quad t : dataset.iterate()) {
+ * System.out.println(t);
+ * }
+ * </pre>
+ *
+ * The behaviour of the iterator is not specified if {@link #add(Quad)},
+ * {@link #remove(Quad)} or {@link #clear()}, are called on the
+ * {@link Dataset} before it terminates. It is undefined if the returned
+ * {@link Iterator} supports the {@link Iterator#remove()} method.
+ * <p>
+ * Implementations may throw {@link ConcurrentModificationException} from
+ * Iterator methods if they detect a concurrency conflict while the Iterator
+ * is active.
+ * <p>
+ * The {@link Iterable#iterator()} must only be called once, that is the
+ * Iterable must only be iterated over once. A {@link IllegalStateException}
+ * may be thrown on attempt to reuse the Iterable.
+ *
+ * @return A {@link Iterable} that returns {@link Iterator} over all of the
+ * quads in the dataset
+ * @throws IllegalStateException
+ * if the {@link Iterable} has been reused
+ * @throws ConcurrentModificationException
+ * if a concurrency conflict occurs while the Iterator is
+ * active.
+ */
+ @SuppressWarnings("unchecked")
+ default Iterable<Quad> iterate() throws ConcurrentModificationException, IllegalStateException {
+ return ((Stream<Quad>) getQuads())::iterator;
+ }
+
+ /**
+ * Get an Iterable for iterating over the quads in the dataset that match
+ * the pattern.
+ * <p>
+ * This method is meant to be used with a Java for-each loop, e.g.:
+ *
+ * <pre>
+ * IRI alice = factory.createIRI("http://example.com/alice");
+ * IRI knows = factory.createIRI("http://xmlns.com/foaf/0.1/");
+ * for (Quad t : dataset.iterate(null, alice, knows, null)) {
+ * System.out.println(t.getGraphName());
+ * System.out.println(t.getObject());
+ * }
+ * </pre>
+ * <p>
+ * The behaviour of the iterator is not specified if {@link #add(Quad)},
+ * {@link #remove(Quad)} or {@link #clear()}, are called on the
+ * {@link Dataset} before it terminates. It is undefined if the returned
+ * {@link Iterator} supports the {@link Iterator#remove()} method.
+ * <p>
+ * Implementations may throw {@link ConcurrentModificationException} from
+ * Iterator methods if they detect a concurrency conflict while the Iterator
+ * is active.
+ * <p>
+ * The {@link Iterable#iterator()} must only be called once, that is the
+ * Iterable must only be iterated over once. A {@link IllegalStateException}
+ * may be thrown on attempt to reuse the Iterable.
+ *
+ * @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 Iterable} that returns {@link Iterator} over the
+ * matching quads in the dataset
+ * @throws IllegalStateException
+ * if the {@link Iterable} has been reused
+ * @throws ConcurrentModificationException
+ * if a concurrency conflict occurs while the Iterator is
+ * active.
+ */
+ @SuppressWarnings("unchecked")
+ default Iterable<Quad> iterate(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate,
+ RDFTerm object) throws ConcurrentModificationException, IllegalStateException {
+ return ((Stream<Quad>) getQuads(null, subject, predicate, object))::iterator;
+ }
+}
[12/19] incubator-commonsrdf git commit: Added GraphLike and renamed
getTriples() -> stream()
Posted by st...@apache.org.
Added GraphLike and renamed getTriples() -> stream()
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/b25af136
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/b25af136
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/b25af136
Branch: refs/heads/master
Commit: b25af1363bac61ad0c088f92479ff6f44b821f82
Parents: bc639bb
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Thu Jun 2 12:10:13 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Thu Jun 2 12:10:13 2016 +0100
----------------------------------------------------------------------
.../org/apache/commons/rdf/api/Dataset.java | 12 +--
.../java/org/apache/commons/rdf/api/Graph.java | 10 +-
.../org/apache/commons/rdf/api/GraphLike.java | 97 ++++++++++++++++++++
.../commons/rdf/api/AbstractGraphTest.java | 20 ++--
.../apache/commons/rdf/simple/DatasetImpl.java | 17 ++--
.../apache/commons/rdf/simple/GraphImpl.java | 12 +--
.../commons/rdf/simple/TestWritingGraph.java | 8 +-
7 files changed, 137 insertions(+), 39 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/b25af136/api/src/main/java/org/apache/commons/rdf/api/Dataset.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Dataset.java b/api/src/main/java/org/apache/commons/rdf/api/Dataset.java
index 706366c..c809bc9 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/Dataset.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/Dataset.java
@@ -28,7 +28,7 @@ import java.util.stream.Stream;
* <a href="http://www.w3.org/TR/rdf11-concepts/" >RDF-1.1 Concepts and Abstract
* Syntax</a>, a W3C Recommendation published on 25 February 2014.
*/
-public interface Dataset extends AutoCloseable {
+public interface Dataset extends AutoCloseable, GraphLike<Quad, BlankNodeOrIRI, IRI, RDFTerm> {
/**
* Add a quad to the dataset, possibly mapping any of the components of the
@@ -144,7 +144,7 @@ public interface Dataset extends AutoCloseable {
* Get the graph names in this Dataset.
* <p>
* The set of returned graph names is equivalent to the set of unique
- * {@link Quad#getGraphName()} of all the {@link #getQuads()} of this
+ * {@link Quad#getGraphName()} of all the {@link #stream()} of this
* dataset (excluding the default graph).
* <p>
* The returned {@link Stream} SHOULD NOT contain duplicate graph names.
@@ -217,7 +217,7 @@ public interface Dataset extends AutoCloseable {
*
* @return A {@link Stream} over all of the quads in the dataset
*/
- Stream<? extends Quad> getQuads();
+ Stream<? extends Quad> stream();
/**
* Get all quads contained by the dataset matched with the pattern.
@@ -244,7 +244,7 @@ public interface Dataset extends AutoCloseable {
* The quad object (<code>null</code> is a wildcard)
* @return A {@link Stream} over the matched quads.
*/
- Stream<? extends Quad> getQuads(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate,
+ Stream<? extends Quad> stream(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate,
RDFTerm object);
/**
@@ -281,7 +281,7 @@ public interface Dataset extends AutoCloseable {
*/
@SuppressWarnings("unchecked")
default Iterable<Quad> iterate() throws ConcurrentModificationException, IllegalStateException {
- return ((Stream<Quad>) getQuads())::iterator;
+ return ((Stream<Quad>) stream())::iterator;
}
/**
@@ -333,6 +333,6 @@ public interface Dataset extends AutoCloseable {
@SuppressWarnings("unchecked")
default Iterable<Quad> iterate(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate,
RDFTerm object) throws ConcurrentModificationException, IllegalStateException {
- return ((Stream<Quad>) getQuads(graphName, subject, predicate, object))::iterator;
+ return ((Stream<Quad>) stream(graphName, subject, predicate, object))::iterator;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/b25af136/api/src/main/java/org/apache/commons/rdf/api/Graph.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Graph.java b/api/src/main/java/org/apache/commons/rdf/api/Graph.java
index c421226..42ced98 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/Graph.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/Graph.java
@@ -27,7 +27,7 @@ import java.util.stream.Stream;
* href="http://www.w3.org/TR/rdf11-concepts/" >RDF-1.1 Concepts and Abstract
* Syntax</a>, a W3C Recommendation published on 25 February 2014.
*/
-public interface Graph extends AutoCloseable {
+public interface Graph extends AutoCloseable,GraphLike<Triple, BlankNodeOrIRI, IRI, RDFTerm> {
/**
* Add a triple to the graph, possibly mapping any of the components of the
@@ -128,7 +128,7 @@ public interface Graph extends AutoCloseable {
*
* @return A {@link Stream} over all of the triples in the graph
*/
- Stream<? extends Triple> getTriples();
+ Stream<? extends Triple> stream();
/**
* Get all triples contained by the graph matched with the pattern.
@@ -148,7 +148,7 @@ public interface Graph extends AutoCloseable {
* @param object The triple object (null is a wildcard)
* @return A {@link Stream} over the matched triples.
*/
- Stream<? extends Triple> getTriples(BlankNodeOrIRI subject, IRI predicate,
+ Stream<? extends Triple> stream(BlankNodeOrIRI subject, IRI predicate,
RDFTerm object);
/**
@@ -184,7 +184,7 @@ public interface Graph extends AutoCloseable {
@SuppressWarnings("unchecked")
default Iterable<Triple> iterate()
throws ConcurrentModificationException, IllegalStateException {
- return ((Stream<Triple>)getTriples())::iterator;
+ return ((Stream<Triple>)stream())::iterator;
}
/**
@@ -231,6 +231,6 @@ public interface Graph extends AutoCloseable {
default Iterable<Triple> iterate(
BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
throws ConcurrentModificationException, IllegalStateException {
- return ((Stream<Triple>) getTriples(subject, predicate, object))::iterator;
+ return ((Stream<Triple>) stream(subject, predicate, object))::iterator;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/b25af136/api/src/main/java/org/apache/commons/rdf/api/GraphLike.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/GraphLike.java b/api/src/main/java/org/apache/commons/rdf/api/GraphLike.java
new file mode 100644
index 0000000..57b55cb
--- /dev/null
+++ b/api/src/main/java/org/apache/commons/rdf/api/GraphLike.java
@@ -0,0 +1,97 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.rdf.api;
+
+import java.util.ConcurrentModificationException;
+import java.util.stream.Stream;
+
+/**
+ * A "graph-like" interface that contains {@link TripleLike} statements.
+ * <p>
+ * Extended by {@link Graph} (for {@link Triple}) and {@link Dataset} (for
+ * {@link Quad}).
+ * <p>
+ * Unlike {@link Graph} and {@link Dataset}, this interface can support
+ * with generalised {@link TripleLike} or {@link QuadLike} statements, and
+ * does not include semantics like {@link #size()} or the requirement of
+ * mapping {@link RDFTerm} instances from different implementations.
+ *
+ * @see Graph
+ * @see Dataset
+ * @see TripleLike
+ */
+public interface GraphLike<T extends TripleLike<S, P, O>, S extends RDFTerm, P extends RDFTerm, O extends RDFTerm> {
+
+ /**
+ * Add a statement.
+ *
+ * @param statement
+ * The TripleLike statement to add
+ */
+ void add(T statement);
+
+ /**
+ * Check if statement is contained.
+ *
+ * @param statement
+ * The {@link TripleLike} statement to chec
+ * @return True if the statement is contained
+ */
+ boolean contains(T statement);
+
+ /**
+ * Add a statement.
+ *
+ * @param statement
+ * The TripleLike statement to add
+ */
+ void remove(T statement);
+
+ /**
+ * Remove all statements.
+ */
+ void clear();
+
+ /**
+ * Number of statements.
+ *
+ * @return
+ */
+ long size();
+
+ /**
+ * Return a Stream of contained statements.
+ *
+ * @return A {@link Stream} of {@link TripleLike} statements.
+ */
+ 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;
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/b25af136/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java b/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
index 9029cc4..15773df 100644
--- a/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
+++ b/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
@@ -177,7 +177,7 @@ public abstract class AbstractGraphTest {
assertTrue(graph.contains(alice, knows, bob));
- Optional<? extends Triple> first = graph.getTriples().skip(4)
+ Optional<? extends Triple> first = graph.stream().skip(4)
.findFirst();
Assume.assumeTrue(first.isPresent());
Triple existingTriple = first.get();
@@ -218,7 +218,7 @@ public abstract class AbstractGraphTest {
graph.remove(alice, knows, bob);
assertEquals(shrunkSize, graph.size());
- Optional<? extends Triple> anyTriple = graph.getTriples().findAny();
+ Optional<? extends Triple> anyTriple = graph.stream().findAny();
Assume.assumeTrue(anyTriple.isPresent());
Triple otherTriple = anyTriple.get();
@@ -242,9 +242,9 @@ public abstract class AbstractGraphTest {
@Test
public void getTriples() throws Exception {
- long tripleCount = graph.getTriples().count();
+ long tripleCount = graph.stream().count();
assertTrue(tripleCount > 0);
- assertTrue(graph.getTriples().allMatch(t -> graph.contains(t)));
+ assertTrue(graph.stream().allMatch(t -> graph.contains(t)));
// Check exact count
Assume.assumeNotNull(bnode1, bnode2, aliceName, bobName, secretClubName,
companyName, bobNameTriple);
@@ -254,15 +254,15 @@ public abstract class AbstractGraphTest {
@Test
public void getTriplesQuery() throws Exception {
- long aliceCount = graph.getTriples(alice, null, null).count();
+ long aliceCount = graph.stream(alice, null, null).count();
assertTrue(aliceCount > 0);
Assume.assumeNotNull(aliceName);
assertEquals(3, aliceCount);
Assume.assumeNotNull(bnode1, bnode2, bobName, companyName, secretClubName);
- assertEquals(4, graph.getTriples(null, name, null).count());
+ assertEquals(4, graph.stream(null, name, null).count());
Assume.assumeNotNull(bnode1);
- assertEquals(3, graph.getTriples(null, member, null).count());
+ assertEquals(3, graph.stream(null, member, null).count());
}
/**
@@ -287,14 +287,14 @@ public abstract class AbstractGraphTest {
// Find a secret organizations
assertEquals(
"\"The Secret Club\"",
- graph.getTriples(null, knows, null)
+ graph.stream(null, knows, null)
// Find One-way "knows"
.filter(t -> !graph.contains(
(BlankNodeOrIRI) t.getObject(), knows,
t.getSubject()))
.map(knowsTriple -> graph
// and those they know, what are they member of?
- .getTriples(
+ .stream(
(BlankNodeOrIRI) knowsTriple
.getObject(), member, null)
// keep those which first-guy is a member of
@@ -305,7 +305,7 @@ public abstract class AbstractGraphTest {
.get().getObject())
// then look up the name of that org
.map(org -> graph
- .getTriples((BlankNodeOrIRI) org, name, null)
+ .stream((BlankNodeOrIRI) org, name, null)
.findFirst().get().getObject().ntriplesString())
.findFirst().get());
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/b25af136/simple/src/main/java/org/apache/commons/rdf/simple/DatasetImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/DatasetImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/DatasetImpl.java
index af9b01d..9de358f 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/DatasetImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/DatasetImpl.java
@@ -120,7 +120,7 @@ final class DatasetImpl implements Dataset {
@Override
public boolean contains(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- return getQuads(graphName, subject, predicate, object).findAny().isPresent();
+ return stream(graphName, subject, predicate, object).findAny().isPresent();
}
@Override
@@ -129,12 +129,12 @@ final class DatasetImpl implements Dataset {
}
@Override
- public Stream<Quad> getQuads() {
+ public Stream<Quad> stream() {
return quads.parallelStream().unordered();
}
@Override
- public Stream<Quad> getQuads(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate,
+ public Stream<Quad> stream(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate,
RDFTerm object) {
final Optional<BlankNodeOrIRI> newGraphName = graphName.map(g -> (BlankNodeOrIRI)internallyMap(g));
final BlankNodeOrIRI newSubject = (BlankNodeOrIRI) internallyMap(subject);
@@ -160,12 +160,12 @@ final class DatasetImpl implements Dataset {
}
private Stream<Quad> getQuads(final Predicate<Quad> filter) {
- return getQuads().filter(filter);
+ return stream().filter(filter);
}
@Override
public void remove(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- Stream<Quad> toRemove = getQuads(graphName, subject, predicate, object);
+ Stream<Quad> toRemove = stream(graphName, subject, predicate, object);
for (Quad t : toRemove.collect(Collectors.toList())) {
// Avoid ConcurrentModificationException in ArrayList
remove(t);
@@ -184,7 +184,7 @@ final class DatasetImpl implements Dataset {
@Override
public String toString() {
- String s = getQuads().limit(TO_STRING_MAX).map(Object::toString)
+ String s = stream().limit(TO_STRING_MAX).map(Object::toString)
.collect(Collectors.joining("\n"));
if (size() > TO_STRING_MAX) {
return s + "\n# ... +" + (size() - TO_STRING_MAX) + " more";
@@ -206,7 +206,7 @@ final class DatasetImpl implements Dataset {
public Optional<Graph> getGraph(BlankNodeOrIRI graphName) {
// NOTE: Always returns a new copy
Graph g = new GraphImpl(factory);
- getQuads(Optional.ofNullable(graphName), null, null, null)
+ stream(Optional.ofNullable(graphName), null, null, null)
.map(Quad::asTriple)
.sequential()
.forEach(g::add);
@@ -216,11 +216,12 @@ final class DatasetImpl implements Dataset {
@Override
public Stream<BlankNodeOrIRI> getGraphNames() {
// Not very efficient..
- return getQuads()
+ return stream()
.map(Quad::getGraphName)
.filter(Optional::isPresent).map(Optional::get)
.distinct();
}
+
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/b25af136/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
index 024da21..1f19d57 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
@@ -111,7 +111,7 @@ final class GraphImpl implements Graph {
@Override
public boolean contains(BlankNodeOrIRI subject, IRI predicate,
RDFTerm object) {
- return getTriples(subject, predicate, object).findFirst().isPresent();
+ return stream(subject, predicate, object).findFirst().isPresent();
}
@Override
@@ -120,12 +120,12 @@ final class GraphImpl implements Graph {
}
@Override
- public Stream<Triple> getTriples() {
+ public Stream<Triple> stream() {
return triples.parallelStream().unordered();
}
@Override
- public Stream<Triple> getTriples(final BlankNodeOrIRI subject,
+ public Stream<Triple> stream(final BlankNodeOrIRI subject,
final IRI predicate, final RDFTerm object) {
final BlankNodeOrIRI newSubject = (BlankNodeOrIRI) internallyMap(subject);
final IRI newPredicate = (IRI) internallyMap(predicate);
@@ -148,12 +148,12 @@ final class GraphImpl implements Graph {
}
private Stream<Triple> getTriples(final Predicate<Triple> filter) {
- return getTriples().filter(filter);
+ return stream().filter(filter);
}
@Override
public void remove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- Stream<Triple> toRemove = getTriples(subject, predicate, object);
+ Stream<Triple> toRemove = stream(subject, predicate, object);
for (Triple t : toRemove.collect(Collectors.toList())) {
// Avoid ConcurrentModificationException in ArrayList
remove(t);
@@ -172,7 +172,7 @@ final class GraphImpl implements Graph {
@Override
public String toString() {
- String s = getTriples().limit(TO_STRING_MAX).map(Object::toString)
+ String s = stream().limit(TO_STRING_MAX).map(Object::toString)
.collect(Collectors.joining("\n"));
if (size() > TO_STRING_MAX) {
return s + "\n# ... +" + (size() - TO_STRING_MAX) + " more";
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/b25af136/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java b/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java
index 9862770..6cd8f52 100644
--- a/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java
@@ -102,7 +102,7 @@ public class TestWritingGraph {
public void countQuery() {
IRI subject = factory.createIRI("subj");
IRI predicate = factory.createIRI("pred");
- long count = graph.getTriples(subject, predicate, null).unordered()
+ long count = graph.stream(subject, predicate, null).unordered()
.parallel().count();
//System.out.println("Counted - " + count);
assertEquals(count, TRIPLES);
@@ -123,7 +123,7 @@ public class TestWritingGraph {
graphFile.toFile().deleteOnExit();
}
- Stream<CharSequence> stream = graph.getTriples().map(TestWritingGraph::tripleAsString);
+ Stream<CharSequence> stream = graph.stream().map(TestWritingGraph::tripleAsString);
Files.write(graphFile, stream::iterator, StandardCharsets.UTF_8);
}
@@ -139,7 +139,7 @@ public class TestWritingGraph {
IRI subject = factory.createIRI("subj");
IRI predicate = factory.createIRI("pred");
Stream<CharSequence> stream = graph
- .getTriples(subject, predicate, null).map(TestWritingGraph::tripleAsString);
+ .stream(subject, predicate, null).map(TestWritingGraph::tripleAsString);
Files.write(graphFile, stream::iterator, StandardCharsets.UTF_8);
}
@@ -156,7 +156,7 @@ public class TestWritingGraph {
IRI subject = factory.createIRI("nonexistent");
IRI predicate = factory.createIRI("pred");
Stream<CharSequence> stream = graph
- .getTriples(subject, predicate, null).map(Object::toString);
+ .stream(subject, predicate, null).map(Object::toString);
Files.write(graphFile, stream::iterator, StandardCharsets.UTF_8);
}
[13/19] incubator-commonsrdf git commit: GraphLike javadoc tweaks
Posted by st...@apache.org.
GraphLike javadoc tweaks
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/c7e1a5bd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/c7e1a5bd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/c7e1a5bd
Branch: refs/heads/master
Commit: c7e1a5bde5e3b8209cb15099a7ceaef6ced57e7f
Parents: b25af13
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Thu Jun 2 12:18:03 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Thu Jun 2 12:18:03 2016 +0100
----------------------------------------------------------------------
.../org/apache/commons/rdf/api/GraphLike.java | 20 +++----
.../java/org/apache/commons/rdf/api/Quad.java | 4 +-
.../org/apache/commons/rdf/api/QuadLike.java | 51 +++++++---------
.../org/apache/commons/rdf/api/TripleLike.java | 63 +++++++++-----------
4 files changed, 63 insertions(+), 75 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/c7e1a5bd/api/src/main/java/org/apache/commons/rdf/api/GraphLike.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/GraphLike.java b/api/src/main/java/org/apache/commons/rdf/api/GraphLike.java
index 57b55cb..28c2f10 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/GraphLike.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/GraphLike.java
@@ -26,10 +26,10 @@ import java.util.stream.Stream;
* Extended by {@link Graph} (for {@link Triple}) and {@link Dataset} (for
* {@link Quad}).
* <p>
- * Unlike {@link Graph} and {@link Dataset}, this interface can support
- * with generalised {@link TripleLike} or {@link QuadLike} statements, and
- * does not include semantics like {@link #size()} or the requirement of
- * mapping {@link RDFTerm} instances from different implementations.
+ * Unlike {@link Graph} and {@link Dataset}, this interface can support with
+ * generalised {@link TripleLike} or {@link QuadLike} statements, and does not
+ * include semantics like {@link #size()} or the requirement of mapping
+ * {@link RDFTerm} instances from different implementations.
*
* @see Graph
* @see Dataset
@@ -83,14 +83,14 @@ public interface GraphLike<T extends TripleLike<S, P, O>, S extends RDFTerm, P e
/**
* 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.
+ * @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;
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/c7e1a5bd/api/src/main/java/org/apache/commons/rdf/api/Quad.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Quad.java b/api/src/main/java/org/apache/commons/rdf/api/Quad.java
index fa9298e..348595b 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/Quad.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/Quad.java
@@ -40,8 +40,8 @@ public interface Quad extends QuadLike<BlankNodeOrIRI,IRI,RDFTerm,BlankNodeOrIRI
* 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 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
+ * name 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.
*
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/c7e1a5bd/api/src/main/java/org/apache/commons/rdf/api/QuadLike.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/QuadLike.java b/api/src/main/java/org/apache/commons/rdf/api/QuadLike.java
index a47e32b..7ed7255 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/QuadLike.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/QuadLike.java
@@ -22,42 +22,35 @@ import java.util.Optional;
/**
* A generalised "quad-like" interface, extended by {@link Quad}.
* <p>
- * A QuadLike has at least a
- * {@link #getSubject()}, {@link #getPredicate()} and
- * {@link #getObject()}, and a {@link #getGraphName()},
- * but unlike a {@link Quad} does not have a
- * formalised {@link Quad#equals(Object)} semantics, and allow
- * generalised quads (e.g. a BlankNode as predicate).
+ * A QuadLike statement has at least a {@link #getSubject()},
+ * {@link #getPredicate()}, {@link #getObject()} and {@link #getGraphName()},
+ * but unlike a {@link Quad} does not have a formalised
+ * {@link Quad#equals(Object)} semantics, and can allow generalised quads (e.g.
+ * a {@link BlankNode} as predicate).
* <p>
- * Implementations should specialise which RDFTerm
- * subclasses they return for subject {@link S},
- * predicate {@link P}, object {@link O} and graph name {@link G}.
+ * Implementations should specialise which {@link RDFTerm} subclasses they
+ * return for subject {@link S}, predicate {@link P}, object {@link O} and graph
+ * name {@link G}.
* <p>
+ *
* @see Quad
*/
-public interface QuadLike <S extends RDFTerm, P extends RDFTerm, O extends RDFTerm, G extends RDFTerm>
- extends TripleLike<S,P,O> {
-
+public interface QuadLike<S extends RDFTerm, P extends RDFTerm, O extends RDFTerm, G extends RDFTerm>
+ extends TripleLike<S, P, O> {
/**
- * The graph name (graph label) of this quad, if present.
- *
- * If {@link Optional#isPresent()}, then the {@link Optional#get()}
- * indicate the
- * <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-named-graph">graph
- * name 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.
+ * The graph name (graph label) of this statement, if present.
+ * <p>
+ * If {@link Optional#isPresent()}, then the {@link Optional#get()} indicate
+ * the graph name of this statement. If the graph name is not present,e.g.
+ * the value is {@link Optional#empty()}, it indicates that this Quad is in
+ * the default graph.
*
- * @return If {@link Optional#isPresent()}, the graph name
- * of this quad, otherwise. The graph name is typically an
- * {@link IRI} or {@link BlankNode}.
- * {@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>
+ * @return If {@link Optional#isPresent()}, the graph name of this quad,
+ * otherwise {@link Optional#empty()}, indicating the default
+ * graph. The graph name is typically an {@link IRI} or
+ * {@link BlankNode}.
*/
Optional<G> getGraphName();
-
+
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/c7e1a5bd/api/src/main/java/org/apache/commons/rdf/api/TripleLike.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/TripleLike.java b/api/src/main/java/org/apache/commons/rdf/api/TripleLike.java
index 1ed75d0..c061cc7 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/TripleLike.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/TripleLike.java
@@ -18,48 +18,43 @@
package org.apache.commons.rdf.api;
/**
- * A generalised "triple-like" interface, extended by {@link Triple} and {@link Quad}.
+ * A generalised "triple-like" interface, extended by {@link Triple} and
+ * {@link Quad}.
* <p>
- * A TripleLike has at least a
- * {@link #getSubject()}, {@link #getPredicate()} and
- * {@link #getObject()}, but unlike a {@link Triple} does not have a
- * formalised {@link Triple#equals(Object)} semantics, and allow
- * generalised triples (e.g. a BlankNode as predicate).
- * <p>
- * Implementations should specialise which RDFTerms subclasses
- * they return for subject, predicate and object.
+ * A TripleLike statement has at least a {@link #getSubject()},
+ * {@link #getPredicate()} and {@link #getObject()}, but unlike a {@link Triple}
+ * does not have a formalised {@link Triple#equals(Object)} semantics, and can
+ * allow generalised triples (e.g. a {@link BlankNode} as predicate).
* <p>
+ * Implementations should specialise which {@link RDFTerm} subclasses they
+ * return for subject {@link S}, predicate {@link P} and object {@link O}.
+ *
* @see Triple
* @see Quad
* @see QuadLike
*
*/
-public interface TripleLike <S extends RDFTerm, P extends RDFTerm, O extends RDFTerm> {
+public interface TripleLike<S extends RDFTerm, P extends RDFTerm, O extends RDFTerm> {
- /**
- * The subject of this statement.
- *
- * @return The subject, typically an {@link IRI} or {@link BlankNode}.
- * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-subject">RDF-1.1
- * Triple subject</a>
- */
- S getSubject();
+ /**
+ * The subject of this statement.
+ *
+ * @return The subject, typically an {@link IRI} or {@link BlankNode}.
+ */
+ S getSubject();
- /**
- * The predicate of this statement.
- *
- * @return The predicate, typically an {@link IRI}.
- * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-predicate">RDF-1.1
- * Triple predicate</a>
- */
- P getPredicate();
+ /**
+ * The predicate of this statement.
+ *
+ * @return The predicate, typically an {@link IRI}.
+ */
+ P getPredicate();
- /**
- * The object of this statement.
- *
- * @return The object, typically an {@link IRI}, {@link BlankNode} or {@link Literal}.
- * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-object">RDF-1.1
- * Triple object</a>
- */
- O getObject();
+ /**
+ * The object of this statement.
+ *
+ * @return The object, typically an {@link IRI}, {@link BlankNode} or
+ * {@link Literal}.
+ */
+ O getObject();
}
[14/19] incubator-commonsrdf git commit: Merge branch 'master' into
quad
Posted by st...@apache.org.
Merge branch 'master' into quad
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/14f246e7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/14f246e7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/14f246e7
Branch: refs/heads/master
Commit: 14f246e74cf89ca37efad1360b2bcd142cb60759
Parents: c7e1a5b 058f781
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Thu Jun 2 17:24:33 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Thu Jun 2 17:24:33 2016 +0100
----------------------------------------------------------------------
RELEASE-NOTES.txt | 39 +++++
RELEASE-PROCESS.md | 16 ++
api/pom.xml | 2 +-
.../commons/rdf/api/AbstractGraphTest.java | 172 +++++++++++++++++++
.../rdf/api/AbstractRDFTermFactoryTest.java | 29 ++++
examples/pom.xml | 4 +-
examples/src/example/UserGuideTest.java | 1 +
pom.xml | 95 +++++-----
simple/pom.xml | 3 +-
src/assembly/src.xml | 45 +++++
src/main/assembly/src.xml | 44 -----
src/site/markdown/download.md | 34 ++--
src/site/markdown/userguide.md | 60 +++++--
13 files changed, 414 insertions(+), 130 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/14f246e7/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
----------------------------------------------------------------------
diff --cc api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
index 15773df,5986958..27b9ff4
--- a/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
+++ b/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
@@@ -260,11 -266,177 +266,177 @@@ public abstract class AbstractGraphTes
assertEquals(3, aliceCount);
Assume.assumeNotNull(bnode1, bnode2, bobName, companyName, secretClubName);
- assertEquals(4, graph.getTriples(null, name, null).count());
+ assertEquals(4, graph.stream(null, name, null).count());
Assume.assumeNotNull(bnode1);
- assertEquals(3, graph.getTriples(null, member, null).count());
+ assertEquals(3, graph.stream(null, member, null).count());
}
+ @Test
+ public void addBlankNodesFromMultipleGraphs() {
+
+ try {
+ // Create two separate Graph instances
+ Graph g1 = createGraph1();
+ Graph g2 = createGraph2();
+
+ // and add them to a new Graph g3
+ Graph g3 = factory.createGraph();
+ addAllTriples(g1, g3);
+ addAllTriples(g2, g3);
+
+
+ // Let's make a map to find all those blank nodes after insertion
+ // (The Graph implementation is not currently required to
+ // keep supporting those BlankNodes with contains() - see COMMONSRDF-15)
+
+ final Map<String, BlankNodeOrIRI> whoIsWho = new ConcurrentHashMap<>();
+ // ConcurrentHashMap as we will try parallel forEach below,
+ // which should not give inconsistent results (it does with a
+ // HashMap!)
+
+ // look up BlankNodes by name
+ IRI name = factory.createIRI("http://xmlns.com/foaf/0.1/name");
+ g3.getTriples(null, name, null).parallel().forEach( t ->
+ whoIsWho.put( t.getObject().ntriplesString(), t.getSubject()));
+
+ assertEquals(4, whoIsWho.size());
+ // and contains 4 unique values
+ assertEquals(4, new HashSet<BlankNodeOrIRI>(whoIsWho.values()).size());
+
+ BlankNodeOrIRI b1Alice = whoIsWho.get("\"Alice\"");
+ assertNotNull(b1Alice);
+ BlankNodeOrIRI b2Bob = whoIsWho.get("\"Bob\"");
+ assertNotNull(b2Bob);
+ BlankNodeOrIRI b1Charlie = whoIsWho.get("\"Charlie\"");
+ assertNotNull(b1Charlie);
+ BlankNodeOrIRI b2Dave = whoIsWho.get("\"Dave\"");
+ assertNotNull(b2Dave);
+
+ // All blank nodes should differ
+ notEquals(b1Alice, b2Bob);
+ notEquals(b1Alice, b1Charlie);
+ notEquals(b1Alice, b2Dave);
+ notEquals(b2Bob, b1Charlie);
+ notEquals(b2Bob, b2Dave);
+ notEquals(b1Charlie, b2Dave);
+
+ // And we should be able to query with them again
+ // as we got them back from g3
+ IRI hasChild = factory.createIRI("http://example.com/hasChild");
+ assertTrue(g3.contains(b1Alice, hasChild, b2Bob));
+ assertTrue(g3.contains(b2Dave, hasChild, b1Charlie));
+ // But not
+ assertFalse(g3.contains(b1Alice, hasChild, b1Alice));
+ assertFalse(g3.contains(b1Alice, hasChild, b1Charlie));
+ assertFalse(g3.contains(b1Alice, hasChild, b2Dave));
+ // nor
+ assertFalse(g3.contains(b2Dave, hasChild, b1Alice));
+ assertFalse(g3.contains(b2Dave, hasChild, b1Alice));
+
+ // and these don't have any children (as far as we know)
+ assertFalse(g3.contains(b2Bob, hasChild, null));
+ assertFalse(g3.contains(b1Charlie, hasChild, null));
+ } catch (UnsupportedOperationException ex) {
+ Assume.assumeNoException(ex);
+ }
+ }
+
+ private void notEquals(BlankNodeOrIRI node1, BlankNodeOrIRI node2) {
+ assertFalse(node1.equals(node2));
+ // in which case we should be able to assume
+ // (as they are in the same graph)
+ assertFalse(node1.ntriplesString().equals(node2.ntriplesString()));
+ }
+
+ /**
+ * Add all triples from the source to the target.
+ * <p>
+ * The triples may be copied in any order.
+ * No special conversion or adaptation of {@link BlankNode}s are performed.
+ *
+ * @param source Source Graph to copy triples from
+ * @param target Target Graph where triples will be added
+ */
+ private void addAllTriples(Graph source, Graph target) {
+
+ // unordered() as we don't need to preserve triple order
+ // sequential() as we don't (currently) require target Graph to be thread-safe
+ source.getTriples().unordered().sequential().forEach(t -> target.add(t));
+ }
+
+ /**
+ * Make a new graph with two BlankNodes - each with a different uniqueReference
+ */
+ private Graph createGraph1() {
+ RDFTermFactory factory1 = createFactory();
+
+ IRI name = factory1.createIRI("http://xmlns.com/foaf/0.1/name");
+ Graph g1 = factory1.createGraph();
+ BlankNode b1 = createOwnBlankNode("b1", "0240eaaa-d33e-4fc0-a4f1-169d6ced3680");
+ g1.add(b1, name, factory1.createLiteral("Alice"));
+
+
+ BlankNode b2 = createOwnBlankNode("b2", "9de7db45-0ce7-4b0f-a1ce-c9680ffcfd9f");
+ g1.add(b2, name, factory1.createLiteral("Bob"));
+
+ IRI hasChild = factory1.createIRI("http://example.com/hasChild");
+ g1.add(b1, hasChild, b2);
+
+ return g1;
+ }
+
+ /**
+ * Create a different implementation of BlankNode to be tested with
+ * graph.add(a,b,c);
+ * (the implementation may or may not then choose to translate such to
+ * its own instances)
+ *
+ * @param name
+ * @return
+ */
+ private BlankNode createOwnBlankNode(String name, String uuid) {
+ return new BlankNode() {
+ @Override
+ public String ntriplesString() {
+ return "_: " + name;
+ }
+ @Override
+ public String uniqueReference() {
+ return uuid;
+ }
+ @Override
+ public int hashCode() {
+ return uuid.hashCode();
+ }
+ @Override
+ public boolean equals(Object obj) {
+ if (!( obj instanceof BlankNode)) {
+ return false;
+ }
+ BlankNode other = (BlankNode)obj;
+ return uuid.equals(other.uniqueReference());
+ }
+ };
+ }
+
+ private Graph createGraph2() {
+ RDFTermFactory factory2 = createFactory();
+ IRI name = factory2.createIRI("http://xmlns.com/foaf/0.1/name");
+
+ Graph g2 = factory2.createGraph();
+
+ BlankNode b1 = createOwnBlankNode("b1", "bc8d3e45-a08f-421d-85b3-c25b373abf87");
+ g2.add(b1, name, factory2.createLiteral("Charlie"));
+
+ BlankNode b2 = createOwnBlankNode("b2", "2209097a-5078-4b03-801a-6a2d2f50d739");
+ g2.add(b2, name, factory2.createLiteral("Dave"));
+
+ IRI hasChild = factory2.createIRI("http://example.com/hasChild");
+ // NOTE: Opposite direction of loadGraph1
+ g2.add(b2, hasChild, b1);
+ return g2;
+ }
+
/**
* An attempt to use the Java 8 streams to look up a more complicated query.
* <p>
[19/19] incubator-commonsrdf git commit: COMMONSRDF-37 Add Quad,
Dataset, TripleLike
Posted by st...@apache.org.
COMMONSRDF-37 Add Quad, Dataset, TripleLike
Also adds QuadLike, GraphLike
simple adds DatasetGraphView, DatsetImple, QuadImpl
TODO: Dataset tests
This closes #19
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/fc70462e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/fc70462e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/fc70462e
Branch: refs/heads/master
Commit: fc70462ebf3462233a42f10a80c13040c6bb5a43
Parents: 6c673b7 a1d6554
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Mon Sep 5 16:39:35 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Mon Sep 5 16:39:56 2016 +0100
----------------------------------------------------------------------
.../org/apache/commons/rdf/api/Dataset.java | 338 +++++++++++++++++++
.../java/org/apache/commons/rdf/api/Graph.java | 40 ++-
.../org/apache/commons/rdf/api/GraphLike.java | 113 +++++++
.../java/org/apache/commons/rdf/api/Quad.java | 211 ++++++++++++
.../org/apache/commons/rdf/api/QuadLike.java | 67 ++++
.../apache/commons/rdf/api/RDFTermFactory.java | 40 +++
.../java/org/apache/commons/rdf/api/Triple.java | 2 +-
.../org/apache/commons/rdf/api/TripleLike.java | 69 ++++
.../commons/rdf/api/AbstractGraphTest.java | 24 +-
.../commons/rdf/simple/DatasetGraphView.java | 138 ++++++++
.../apache/commons/rdf/simple/DatasetImpl.java | 221 ++++++++++++
.../apache/commons/rdf/simple/GraphImpl.java | 12 +-
.../org/apache/commons/rdf/simple/QuadImpl.java | 109 ++++++
.../rdf/simple/SimpleRDFTermFactory.java | 13 +
.../commons/rdf/simple/TestWritingGraph.java | 8 +-
15 files changed, 1374 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
[17/19] incubator-commonsrdf git commit: quad: fixed typo in error
message
Posted by st...@apache.org.
quad: fixed typo in error message
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/53ef2282
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/53ef2282
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/53ef2282
Branch: refs/heads/master
Commit: 53ef22820e750200b888d0ae93de438bfb4037d6
Parents: 580484c
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Mon Jun 20 18:18:46 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Mon Jun 20 18:18:46 2016 +0100
----------------------------------------------------------------------
api/src/main/java/org/apache/commons/rdf/api/RDFTermFactory.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/53ef2282/api/src/main/java/org/apache/commons/rdf/api/RDFTermFactory.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/RDFTermFactory.java b/api/src/main/java/org/apache/commons/rdf/api/RDFTermFactory.java
index f2a6f95..48605e7 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/RDFTermFactory.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/RDFTermFactory.java
@@ -271,7 +271,7 @@ public interface RDFTermFactory {
RDFTerm object) throws IllegalArgumentException,
UnsupportedOperationException {
throw new UnsupportedOperationException(
- "createTriple(BlankNodeOrIRI,IRI,RDFTerm) not supported");
+ "createQuad(BlankNodeOrIRI,BlankNodeOrIRI,IRI,RDFTerm) not supported");
}
}
[05/19] incubator-commonsrdf git commit: javadoc typos
Posted by st...@apache.org.
javadoc typos
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/220f75f1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/220f75f1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/220f75f1
Branch: refs/heads/master
Commit: 220f75f19f3dfb730a9626292ac25e11807f4f31
Parents: 5e952b5
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Apr 8 15:13:16 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Apr 8 15:16:42 2016 +0100
----------------------------------------------------------------------
.../org/apache/commons/rdf/api/Dataset.java | 2 -
.../apache/commons/rdf/api/GraphOrDataset.java | 107 ++++++++++---------
.../java/org/apache/commons/rdf/api/Quad.java | 12 +--
.../apache/commons/rdf/api/TripleOrQuad.java | 4 +-
4 files changed, 64 insertions(+), 61 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/220f75f1/api/src/main/java/org/apache/commons/rdf/api/Dataset.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Dataset.java b/api/src/main/java/org/apache/commons/rdf/api/Dataset.java
index 70d5bff..fca9810 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/Dataset.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/Dataset.java
@@ -144,8 +144,6 @@ public interface Dataset extends AutoCloseable, GraphOrDataset<Quad> {
/**
* Remove a concrete pattern of quads from the default graph of the dataset.
*
- * @param graphName
- * The graph the quad belongs to
* @param subject
* The quad subject (<code>null</code> is a wildcard)
* @param predicate
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/220f75f1/api/src/main/java/org/apache/commons/rdf/api/GraphOrDataset.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/GraphOrDataset.java b/api/src/main/java/org/apache/commons/rdf/api/GraphOrDataset.java
index 35017fb..f41463a 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/GraphOrDataset.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/GraphOrDataset.java
@@ -22,24 +22,24 @@ import java.util.Iterator;
import java.util.stream.Stream;
/**
- * An <a href="http://www.w3.org/TR/rdf11-concepts/#section-rdf-graph"> RDF 1.1
- * Graph</a>, a set of RDF triples, as defined by <a
- * href="http://www.w3.org/TR/rdf11-concepts/" >RDF-1.1 Concepts and Abstract
- * Syntax</a>, a W3C Recommendation published on 25 February 2014.
+ * Common interface for {@link Graph} and {@link Dataset}
+ * <p>
+ *
*/
public interface GraphOrDataset<T extends TripleOrQuad> extends AutoCloseable {
/**
- * Add a triple to the graph, possibly mapping any of the components of the
- * Triple to those supported by this Graph.
+ * Add a triple/quad to the graph, possibly mapping any of the components of the
+ * TripleOrQuad to those supported by this Graph.
*
- * @param triple The triple or quad to add
+ * @param tripleOrQuad The triple or quad to add
*/
- void add(T triple);
+ void add(T tripleOrQuad);
/**
- * Add a triple to the graph, possibly mapping any of the components to
- * those supported by this Graph.
+ * Add a triple to the Graph, (or the default graph of a Dataset),
+ * possibly mapping any of the components to
+ * those supported by this graph/dataset.
*
* @param subject The triple subject
* @param predicate The triple predicate
@@ -48,26 +48,30 @@ public interface GraphOrDataset<T extends TripleOrQuad> extends AutoCloseable {
void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
/**
- * Check if graph contains triple.
+ * Check if graph/dataset contains triple/quad.
*
- * @param triple The triple to check.
- * @return True if the Graph contains the given Triple.
+ * @param tripleOrQuad The triple/quad to check.
+ * @return True if this graph/dataset contains the given Triple.
*/
- boolean contains(T triple);
+ boolean contains(T tripleOrQuad);
/**
- * Check 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.
- */
+ * Check if graph/dataset contains a pattern of triples or quads in the
+ * default graph of a dataset.
+ *
+ * @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 this graph/dataset contains any triples/quads
+ * that match the given pattern.
+ */
boolean contains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
/**
- * Close the graph, relinquishing any underlying resources.
+ * Close the graph/dataset, relinquishing any underlying resources.
* <p>
* For example, this would close any open file and network streams and free
* database locks held by the Graph implementation.
@@ -83,14 +87,15 @@ public interface GraphOrDataset<T extends TripleOrQuad> extends AutoCloseable {
}
/**
- * Remove a concrete triple from the graph.
+ * Remove a concrete triple/quad from the graph.
*
- * @param triple triple to remove
+ * @param tripleOrQuad triple/quad to remove
*/
- void remove(T triple);
+ void remove(T tripleOrQuad);
/**
- * Remove a concrete pattern of triples from the graph.
+ * Remove a concrete pattern of triples from the graph, or
+ * quads from the default graph of a dataset.
*
* @param subject The triple subject (null is a wildcard)
* @param predicate The triple predicate (null is a wildcard)
@@ -99,28 +104,27 @@ public interface GraphOrDataset<T extends TripleOrQuad> extends AutoCloseable {
void remove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
/**
- * Clear the graph, removing all triples.
+ * Clear the graph/dataset, removing all triples/quads.
*/
void clear();
/**
- * Number of triples contained by the graph.
- * <p>
- * The count of a set does not include duplicates, consistent with the
- * {@link T#equals(Object)} equals method for each {@link T}.
+ * Number of triples/quads contained by the graph/dataset.
*
- * @return The number of triples in the graph
+ * @return The number of triples/quads in the graph/dataset
*/
long size();
/**
- * Get all triples contained by the graph.<br>
+ * Get all triples contained by the graph, or
+ * the equivalent of {@link Quad#asTriple()}
+ * for all quads of the default graph of a dataset.
* <p>
* The iteration does not contain any duplicate triples, as determined by
- * the {@link T#equals(Object)} method for each {@link T}.
+ * the {@link Triple#equals(Object)} method for each {@link Triple}.
* <p>
- * The behaviour of the {@link Stream} is not specified if {@link #add(T)},
- * {@link #remove(T)} or {@link #clear()} are called on the
+ * The behaviour of the {@link Stream} is not specified if {@link #add(TripleOrQuad)},
+ * {@link #remove(TripleOrQuad)} or {@link #clear()} are called on the
* {@link GraphOrDataset} before it terminates.
* <p>
* Implementations may throw {@link ConcurrentModificationException} from Stream
@@ -128,16 +132,18 @@ public interface GraphOrDataset<T extends TripleOrQuad> extends AutoCloseable {
*
* @return A {@link Stream} over all of the triples in the graph
*/
- Stream<? extends T> getTriples();
+ Stream<? extends Triple> getTriples();
/**
- * Get all triples contained by the graph matched with the pattern.
+ * Get all triples contained by the graph matched with the pattern, or
+ * the equivalent of {@link Quad#asTriple()}
+ * for all quads of the default graph of a dataset that match the pattern.
* <p>
* The iteration does not contain any duplicate triples, as determined by
- * the {@link T#equals(Object)} method for each {@link T}.
+ * the {@link Triple#equals(Object)} method for each {@link Triple}.
* <p>
- * The behaviour of the {@link Stream} is not specified if {@link #add(T)},
- * {@link #remove(T)} or {@link #clear()} are called on the
+ * The behaviour of the {@link Stream} is not specified if {@link #add(TripleOrQuad)},
+ * {@link #remove(TripleOrQuad)} or {@link #clear()} are called on the
* {@link GraphOrDataset} before it terminates.
* <p>
* Implementations may throw {@link ConcurrentModificationException} from Stream
@@ -148,7 +154,7 @@ public interface GraphOrDataset<T extends TripleOrQuad> extends AutoCloseable {
* @param object The triple object (null is a wildcard)
* @return A {@link Stream} over the matched triples.
*/
- Stream<? extends T> getTriples(BlankNodeOrIRI subject, IRI predicate,
+ Stream<? extends Triple> getTriples(BlankNodeOrIRI subject, IRI predicate,
RDFTerm object);
/**
@@ -156,12 +162,12 @@ public interface GraphOrDataset<T extends TripleOrQuad> extends AutoCloseable {
* <p>
* This method is meant to be used with a Java for-each loop, e.g.:
* <pre>
- * for (Triple t : graph.iterate()) {
+ * for (TripleOrQuad t : graphOrDataset.iterate()) {
* System.out.println(t);
* }
* </pre>
- * The behaviour of the iterator is not specified if {@link #add(T)},
- * {@link #remove(T)} or {@link #clear()}, are called on the
+ * The behaviour of the iterator is not specified if {@link #add(TripleOrQuad)},
+ * {@link #remove(TripleOrQuad)} or {@link #clear()}, are called on the
* {@link GraphOrDataset} before it terminates. It is undefined if the returned
* {@link Iterator} supports the {@link Iterator#remove()} method.
* <p>
@@ -188,20 +194,21 @@ public interface GraphOrDataset<T extends TripleOrQuad> extends AutoCloseable {
}
/**
- * Get an Iterable for iterating over the triples in the graph that match
- * the pattern.
+ * Get an Iterable for iterating over the triples in the graph
+ * or quads in the default graph of a dataset that
+ * match the pattern.
* <p>
* This method is meant to be used with a Java for-each loop, e.g.:
* <pre>
* IRI alice = factory.createIRI("http://example.com/alice");
* IRI knows = factory.createIRI("http://xmlns.com/foaf/0.1/");
- * for (Triple t : graph.iterate(alice, knows, null)) {
+ * for (Triple t : graphOrDataset.iterate(alice, knows, null)) {
* System.out.println(t.getObject());
* }
* </pre>
* <p>
* The behaviour of the iterator is not specified if
- * {@link #add(T)}, {@link #remove(T)} or {@link #clear()}, are
+ * {@link #add(TripleOrQuad)}, {@link #remove(TripleOrQuad)} or {@link #clear()}, are
* called on the {@link GraphOrDataset} before it terminates. It is undefined if the
* returned {@link Iterator} supports the {@link Iterator#remove()} method.
* <p>
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/220f75f1/api/src/main/java/org/apache/commons/rdf/api/Quad.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Quad.java b/api/src/main/java/org/apache/commons/rdf/api/Quad.java
index 088533b..7ccd0d1 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/Quad.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/Quad.java
@@ -86,20 +86,18 @@ public interface Quad extends TripleOrQuad {
RDFTerm getObject();
/**
- * Convert this {@link Quad} to a {@link Triple}.
+ * Convert this Quad to a Triple.
* <p>
* The returned {@link Triple} will have equivalent values returned from the
* methods {@link TripleOrQuad#getSubject()},
- * {@link TripleOrQuad#getPredicate()} and {@link TripleOrQuad#getObject()}
- * (their values MUST be {@link RDFTerm#equals(Object)}) - however the
- * property values MAY be different instances.
+ * {@link TripleOrQuad#getPredicate()} and {@link TripleOrQuad#getObject()}.
* <p>
* The returned {@link Triple} MUST NOT be {@link #equals(Object)} to this
* {@link Quad}, even if this quad has a default graph
* {@link #getGraphName()} value of {@link Optional#empty()}, but MUST
- * follow the {@link Triple#equals(Object)) semantics. This means that the
+ * follow the {@link Triple#equals(Object)} semantics. This means that the
* following MUST be true:
- *
+ *
* <pre>
* Quad q1, q2;
* if (q1.equals(q2)) {
@@ -193,7 +191,7 @@ public interface Quad extends TripleOrQuad {
* <p>
* The returned hash code MUST be equal to the result of
* {@link Objects#hash(Object...)} with the arguments {@link #getSubject()},
- * {@link #getPredicate()}, {@link #getObject(), #getGraphName()}.
+ * {@link #getPredicate()}, {@link #getObject()}, {@link #getGraphName()}.
* <p>
* This method MUST be implemented in conjunction with
* {@link #equals(Object)} so that two equal {@link Quad}s produce the same
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/220f75f1/api/src/main/java/org/apache/commons/rdf/api/TripleOrQuad.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/TripleOrQuad.java b/api/src/main/java/org/apache/commons/rdf/api/TripleOrQuad.java
index 755bb99..6a86447 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/TripleOrQuad.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/TripleOrQuad.java
@@ -23,8 +23,8 @@ package org.apache.commons.rdf.api;
* A TripleOrQuad has at least a
* {@link #getSubject()}, {@link #getPredicate()} and
* {@link #getObject()}, but unlike a {@link Triple} does not have a
- * formalized {@link Triple#equals(Object)} semantics, and does not
- * neccesarily have a {@link Quad#getGraphLabel()}
+ * formalised {@link Triple#equals(Object)} semantics, and does not
+ * necessarily have a {@link Quad#getGraphName()}
* <p>
* Implementations of this interface SHOULD also implement {@link Triple}
* or {@link Quad}, but MUST NOT implement both interfaces.
[07/19] incubator-commonsrdf git commit: Added DatasetImpl, QuadImpl
Posted by st...@apache.org.
Added DatasetImpl, QuadImpl
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/683a2bbd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/683a2bbd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/683a2bbd
Branch: refs/heads/master
Commit: 683a2bbdf7539772950d4eaaa0018745eaf6cc2d
Parents: 8ee8e2c
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Apr 8 16:21:49 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Apr 8 16:21:49 2016 +0100
----------------------------------------------------------------------
.../apache/commons/rdf/simple/DatasetImpl.java | 223 +++++++++++++++++++
.../org/apache/commons/rdf/simple/QuadImpl.java | 109 +++++++++
.../rdf/simple/SimpleRDFTermFactory.java | 13 ++
3 files changed, 345 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/683a2bbd/simple/src/main/java/org/apache/commons/rdf/simple/DatasetImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/DatasetImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/DatasetImpl.java
new file mode 100644
index 0000000..64cf57d
--- /dev/null
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/DatasetImpl.java
@@ -0,0 +1,223 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.rdf.simple;
+
+import org.apache.commons.rdf.api.*;
+import org.apache.commons.rdf.simple.SimpleRDFTermFactory.SimpleRDFTerm;
+
+import java.util.HashSet;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+/**
+ * A simple, memory-based implementation of Dataset.
+ * <p>
+ * {@link Quad}s in the graph are kept in a {@link Set}.
+ * <p>
+ * All Stream operations are performed using parallel and unordered directives.
+ */
+final class DatasetImpl implements Dataset {
+
+ private static final int TO_STRING_MAX = 10;
+ private final Set<Quad> quads = new HashSet<Quad>();
+ private final SimpleRDFTermFactory factory;
+
+ DatasetImpl(SimpleRDFTermFactory simpleRDFTermFactory) {
+ this.factory = simpleRDFTermFactory;
+ }
+
+ @Override
+ public void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ // TODO: Should this method be promoted as a default method in Dataset?
+ add(null, subject, predicate, object);
+ }
+
+ @Override
+ public void add(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ BlankNodeOrIRI newGraphName = (BlankNodeOrIRI) internallyMap(graphName);
+ BlankNodeOrIRI newSubject = (BlankNodeOrIRI) internallyMap(subject);
+ IRI newPredicate = (IRI) internallyMap(predicate);
+ RDFTerm newObject = internallyMap(object);
+ Quad result = factory.createQuad(newGraphName, newSubject, newPredicate, newObject);
+ quads.add(result);
+ }
+
+ @Override
+ public void add(Quad quad) {
+ BlankNodeOrIRI newGraph = (BlankNodeOrIRI) internallyMap(quad.getGraphName().orElse(null));
+ BlankNodeOrIRI newSubject = (BlankNodeOrIRI) internallyMap(quad
+ .getSubject());
+ IRI newPredicate = (IRI) internallyMap(quad.getPredicate());
+ RDFTerm newObject = internallyMap(quad.getObject());
+ // Check if any of the object references changed during the mapping, to
+ // avoid creating a new Quad object if possible
+ if (newGraph == quad.getGraphName().orElse(null)
+ && newSubject == quad.getSubject()
+ && newPredicate == quad.getPredicate()
+ && newObject == quad.getObject()) {
+ quads.add(quad);
+ } else {
+ // Make a new Quad with our mapped instances
+ Quad result = factory.createQuad(newGraph, newSubject, newPredicate,
+ newObject);
+ quads.add(result);
+ }
+ }
+
+ private <T extends RDFTerm> RDFTerm internallyMap(T object) {
+ if (object == null || object instanceof SimpleRDFTerm) {
+ return object;
+ }
+ if (object instanceof BlankNode && !(object instanceof BlankNodeImpl)) {
+ BlankNode blankNode = (BlankNode) object;
+ // This guarantees that adding the same BlankNode multiple times to
+ // this graph will generate a local object that is mapped to an
+ // equivalent object, based on the code in the package private
+ // BlankNodeImpl class
+ return factory.createBlankNode(blankNode.uniqueReference());
+ } else if (object instanceof IRI && !(object instanceof IRIImpl)) {
+ IRI iri = (IRI) object;
+ return factory.createIRI(iri.getIRIString());
+ } else if (object instanceof Literal
+ && !(object instanceof LiteralImpl)) {
+ Literal literal = (Literal) object;
+ if (literal.getLanguageTag().isPresent()) {
+ return factory.createLiteral(literal.getLexicalForm(), literal
+ .getLanguageTag().get());
+ } else {
+ return factory.createLiteral(literal.getLexicalForm(),
+ (IRI) internallyMap(literal.getDatatype()));
+ }
+ } else {
+ throw new IllegalArgumentException("Not a BlankNode, IRI or Literal: " + object);
+ }
+ }
+
+ @Override
+ public void clear() {
+ quads.clear();
+ }
+
+ @Override
+ public boolean contains(BlankNodeOrIRI subject, IRI predicate,
+ RDFTerm object) {
+ // TODO: Should this method be promoted as a default method in Dataset?
+ return getQuads(Optional.empty(), subject, predicate, object).findAny().isPresent();
+ }
+
+ @Override
+ public boolean contains(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ return getQuads(graphName, subject, predicate, object).findAny().isPresent();
+ }
+
+ @Override
+ public boolean contains(Quad quad) {
+ return quads.contains(Objects.requireNonNull(quad));
+ }
+
+ @Override
+ public Stream<Quad> getQuads() {
+ return quads.parallelStream().unordered();
+ }
+
+ @Override
+ public Stream<Quad> getQuads(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate,
+ RDFTerm object) {
+ final Optional<BlankNodeOrIRI> newGraphName = graphName.map(g -> (BlankNodeOrIRI)internallyMap(g));
+ final BlankNodeOrIRI newSubject = (BlankNodeOrIRI) internallyMap(subject);
+ final IRI newPredicate = (IRI) internallyMap(predicate);
+ final RDFTerm newObject = internallyMap(object);
+
+ return getQuads(t -> {
+ if (newGraphName != null && !t.getGraphName().equals(newGraphName)) {
+ // This would check Optional.empty() == Optional.empty()
+ return false;
+ }
+ if (subject != null && !t.getSubject().equals(newSubject)) {
+ return false;
+ }
+ if (predicate != null && !t.getPredicate().equals(newPredicate)) {
+ return false;
+ }
+ if (object != null && !t.getObject().equals(newObject)) {
+ return false;
+ }
+ return true;
+ });
+ }
+
+ @Override
+ public Stream<Triple> getTriples() {
+ // TODO: Should this method be promoted as a default method in Dataset?
+ return getQuads(Optional.empty(), null, null, null).map(Quad::asTriple);
+ }
+
+ @Override
+ public Stream<Triple> getTriples(final BlankNodeOrIRI subject,
+ final IRI predicate, final RDFTerm object) {
+ // TODO: Should this method be promoted as a default method in Dataset?
+ return getQuads(Optional.empty(), subject, predicate, object).map(Quad::asTriple);
+ }
+
+ private Stream<Quad> getQuads(final Predicate<Quad> filter) {
+ return getQuads().filter(filter);
+ }
+
+ @Override
+ public void remove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ // TODO: Should this method be promoted as a default method in Dataset?
+ remove(Optional.empty(), subject, predicate, object);
+ }
+
+ @Override
+ public void remove(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ Stream<Quad> toRemove = getQuads(graphName, subject, predicate, object);
+ for (Quad t : toRemove.collect(Collectors.toList())) {
+ // Avoid ConcurrentModificationException in ArrayList
+ remove(t);
+ }
+ }
+
+
+ @Override
+ public void remove(Quad quad) {
+ quads.remove(Objects.requireNonNull(quad));
+ }
+
+ @Override
+ public long size() {
+ return quads.size();
+ }
+
+ @Override
+ public String toString() {
+ String s = getTriples().limit(TO_STRING_MAX).map(Object::toString)
+ .collect(Collectors.joining("\n"));
+ if (size() > TO_STRING_MAX) {
+ return s + "\n# ... +" + (size() - TO_STRING_MAX) + " more";
+ } else {
+ return s;
+ }
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/683a2bbd/simple/src/main/java/org/apache/commons/rdf/simple/QuadImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/QuadImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/QuadImpl.java
new file mode 100644
index 0000000..54921bb
--- /dev/null
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/QuadImpl.java
@@ -0,0 +1,109 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.rdf.simple;
+
+import org.apache.commons.rdf.api.BlankNodeOrIRI;
+import org.apache.commons.rdf.api.IRI;
+import org.apache.commons.rdf.api.Quad;
+import org.apache.commons.rdf.api.RDFTerm;
+import org.apache.commons.rdf.api.Triple;
+
+import java.util.Objects;
+import java.util.Optional;
+
+/**
+ * A simple implementation of Quad.
+ */
+final class QuadImpl implements Quad {
+
+ private final BlankNodeOrIRI graphName;
+ private final BlankNodeOrIRI subject;
+ private final IRI predicate;
+ private final RDFTerm object;
+
+ /**
+ * Construct Quad from its constituent parts.
+ * <p>
+ * The objects are not changed. All mapping of BNode objects is done in
+ * {@link SimpleRDFTermFactory#createQuad(BlankNodeOrIRI, BlankNodeOrIRI, IRI, RDFTerm)}.
+ *
+ * @param graphName graphName of triple
+ * @param subject subject of triple
+ * @param predicate predicate of triple
+ * @param object object of triple
+ */
+ public QuadImpl(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ this.graphName = graphName; // possibly null
+ this.subject = Objects.requireNonNull(subject);
+ this.predicate = Objects.requireNonNull(predicate);
+ this.object = Objects.requireNonNull(object);
+ }
+
+ @Override
+ public Optional<BlankNodeOrIRI> getGraphName() {
+ return Optional.ofNullable(graphName);
+ }
+
+ @Override
+ public BlankNodeOrIRI getSubject() {
+ return subject;
+ }
+
+ @Override
+ public IRI getPredicate() {
+ return predicate;
+ }
+
+ @Override
+ public RDFTerm getObject() {
+ return object;
+ }
+
+ @Override
+ public String toString() {
+ return
+ getSubject().ntriplesString() + " "
+ + getPredicate().ntriplesString() + " "
+ + getObject().ntriplesString() + " "
+ + getGraphName().map(g -> g.ntriplesString() + " ").orElse("")
+ + ".";
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(subject, predicate, object, graphName);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof Quad)) {
+ return false;
+ }
+ Quad other = (Quad) obj;
+ return getGraphName().equals(other.getGraphName())
+ && getSubject().equals(other.getSubject())
+ && getPredicate().equals(other.getPredicate())
+ && getObject().equals(other.getObject());
+ }
+
+ @Override
+ public Triple asTriple() {
+ return new TripleImpl(getSubject(), getPredicate(), getObject());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/683a2bbd/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java b/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java
index 36694bf..4f54d03 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java
@@ -21,9 +21,11 @@ import java.util.UUID;
import org.apache.commons.rdf.api.BlankNode;
import org.apache.commons.rdf.api.BlankNodeOrIRI;
+import org.apache.commons.rdf.api.Dataset;
import org.apache.commons.rdf.api.Graph;
import org.apache.commons.rdf.api.IRI;
import org.apache.commons.rdf.api.Literal;
+import org.apache.commons.rdf.api.Quad;
import org.apache.commons.rdf.api.RDFTerm;
import org.apache.commons.rdf.api.RDFTermFactory;
import org.apache.commons.rdf.api.Triple;
@@ -71,6 +73,11 @@ public class SimpleRDFTermFactory implements RDFTermFactory {
}
@Override
+ public Dataset createDataset() throws UnsupportedOperationException {
+ return new DatasetImpl(this);
+ }
+
+ @Override
public IRI createIRI(String iri) {
IRI result = new IRIImpl(iri);
// Reuse any IRI objects already created in Types
@@ -97,4 +104,10 @@ public class SimpleRDFTermFactory implements RDFTermFactory {
RDFTerm object) {
return new TripleImpl(subject, predicate, object);
}
+
+ @Override
+ public Quad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
+ throws IllegalArgumentException, UnsupportedOperationException {
+ return new QuadImpl(graphName, subject, predicate, object);
+ }
}
[11/19] incubator-commonsrdf git commit: TripleOrQuad -> TripleLike,
GraphLike
Posted by st...@apache.org.
TripleOrQuad -> TripleLike, GraphLike
TripleLike is a generalized Triple (e.g. as seen in Jena), supporting
any RDFTerm in any of the subject/predicate/object positions.
This can be useful for parsers, and also serves as a common
super-type for Quad and Triple.
Equivalently, QuadLike extends TripleLike as a generalized Quad, supporting
any RDFTerm as its graphName.
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/bc639bbd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/bc639bbd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/bc639bbd
Branch: refs/heads/master
Commit: bc639bbd3b65ed6802dfdac14a53c9f96162bf32
Parents: 839a642
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Thu Jun 2 11:41:04 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Thu Jun 2 11:41:04 2016 +0100
----------------------------------------------------------------------
.../java/org/apache/commons/rdf/api/Quad.java | 2 +-
.../org/apache/commons/rdf/api/QuadLike.java | 63 +++++++++++++++++++
.../java/org/apache/commons/rdf/api/Triple.java | 2 +-
.../org/apache/commons/rdf/api/TripleLike.java | 65 ++++++++++++++++++++
.../apache/commons/rdf/api/TripleOrQuad.java | 64 -------------------
5 files changed, 130 insertions(+), 66 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/bc639bbd/api/src/main/java/org/apache/commons/rdf/api/Quad.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Quad.java b/api/src/main/java/org/apache/commons/rdf/api/Quad.java
index 7ccd0d1..fa9298e 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/Quad.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/Quad.java
@@ -32,7 +32,7 @@ import java.util.Optional;
* 1.1: On Semantics of RDF Datasets</a>
* @see <a href="http://www.w3.org/TR/rdf11-concepts/#section-dataset"> </a>
*/
-public interface Quad extends TripleOrQuad {
+public interface Quad extends QuadLike<BlankNodeOrIRI,IRI,RDFTerm,BlankNodeOrIRI> {
/**
* The graph name (graph label) of this quad, if present.
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/bc639bbd/api/src/main/java/org/apache/commons/rdf/api/QuadLike.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/QuadLike.java b/api/src/main/java/org/apache/commons/rdf/api/QuadLike.java
new file mode 100644
index 0000000..a47e32b
--- /dev/null
+++ b/api/src/main/java/org/apache/commons/rdf/api/QuadLike.java
@@ -0,0 +1,63 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.rdf.api;
+
+import java.util.Optional;
+
+/**
+ * A generalised "quad-like" interface, extended by {@link Quad}.
+ * <p>
+ * A QuadLike has at least a
+ * {@link #getSubject()}, {@link #getPredicate()} and
+ * {@link #getObject()}, and a {@link #getGraphName()},
+ * but unlike a {@link Quad} does not have a
+ * formalised {@link Quad#equals(Object)} semantics, and allow
+ * generalised quads (e.g. a BlankNode as predicate).
+ * <p>
+ * Implementations should specialise which RDFTerm
+ * subclasses they return for subject {@link S},
+ * predicate {@link P}, object {@link O} and graph name {@link G}.
+ * <p>
+ * @see Quad
+ */
+public interface QuadLike <S extends RDFTerm, P extends RDFTerm, O extends RDFTerm, G extends RDFTerm>
+ extends TripleLike<S,P,O> {
+
+
+ /**
+ * The graph name (graph label) of this quad, if present.
+ *
+ * If {@link Optional#isPresent()}, then the {@link Optional#get()}
+ * indicate the
+ * <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-named-graph">graph
+ * name 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.
+ *
+ * @return If {@link Optional#isPresent()}, the graph name
+ * of this quad, otherwise. The graph name is typically an
+ * {@link IRI} or {@link BlankNode}.
+ * {@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>
+ */
+ Optional<G> getGraphName();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/bc639bbd/api/src/main/java/org/apache/commons/rdf/api/Triple.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Triple.java b/api/src/main/java/org/apache/commons/rdf/api/Triple.java
index 0725913..dcbb509 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/Triple.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/Triple.java
@@ -28,7 +28,7 @@ import java.util.Objects;
* @see <a href= "http://www.w3.org/TR/rdf11-concepts/#dfn-rdf-triple" >RDF-1.1
* Triple</a>
*/
-public interface Triple extends TripleOrQuad {
+public interface Triple extends TripleLike<BlankNodeOrIRI, IRI, RDFTerm> {
/**
* The subject of this triple, which may be either a {@link BlankNode} or an
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/bc639bbd/api/src/main/java/org/apache/commons/rdf/api/TripleLike.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/TripleLike.java b/api/src/main/java/org/apache/commons/rdf/api/TripleLike.java
new file mode 100644
index 0000000..1ed75d0
--- /dev/null
+++ b/api/src/main/java/org/apache/commons/rdf/api/TripleLike.java
@@ -0,0 +1,65 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.rdf.api;
+
+/**
+ * A generalised "triple-like" interface, extended by {@link Triple} and {@link Quad}.
+ * <p>
+ * A TripleLike has at least a
+ * {@link #getSubject()}, {@link #getPredicate()} and
+ * {@link #getObject()}, but unlike a {@link Triple} does not have a
+ * formalised {@link Triple#equals(Object)} semantics, and allow
+ * generalised triples (e.g. a BlankNode as predicate).
+ * <p>
+ * Implementations should specialise which RDFTerms subclasses
+ * they return for subject, predicate and object.
+ * <p>
+ * @see Triple
+ * @see Quad
+ * @see QuadLike
+ *
+ */
+public interface TripleLike <S extends RDFTerm, P extends RDFTerm, O extends RDFTerm> {
+
+ /**
+ * The subject of this statement.
+ *
+ * @return The subject, typically an {@link IRI} or {@link BlankNode}.
+ * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-subject">RDF-1.1
+ * Triple subject</a>
+ */
+ S getSubject();
+
+ /**
+ * The predicate of this statement.
+ *
+ * @return The predicate, typically an {@link IRI}.
+ * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-predicate">RDF-1.1
+ * Triple predicate</a>
+ */
+ P getPredicate();
+
+ /**
+ * The object of this statement.
+ *
+ * @return The object, typically an {@link IRI}, {@link BlankNode} or {@link Literal}.
+ * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-object">RDF-1.1
+ * Triple object</a>
+ */
+ O getObject();
+}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/bc639bbd/api/src/main/java/org/apache/commons/rdf/api/TripleOrQuad.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/TripleOrQuad.java b/api/src/main/java/org/apache/commons/rdf/api/TripleOrQuad.java
deleted file mode 100644
index 6a86447..0000000
--- a/api/src/main/java/org/apache/commons/rdf/api/TripleOrQuad.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.rdf.api;
-
-/**
- * Common "triple-like" interface for {@link Triple} and {@link Quad}
- * <p>
- * A TripleOrQuad has at least a
- * {@link #getSubject()}, {@link #getPredicate()} and
- * {@link #getObject()}, but unlike a {@link Triple} does not have a
- * formalised {@link Triple#equals(Object)} semantics, and does not
- * necessarily have a {@link Quad#getGraphName()}
- * <p>
- * Implementations of this interface SHOULD also implement {@link Triple}
- * or {@link Quad}, but MUST NOT implement both interfaces.
- */
-public interface TripleOrQuad {
-
- /**
- * The subject of this triple/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 triple/quad.
- * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-subject">RDF-1.1
- * Triple subject</a>
- */
- BlankNodeOrIRI getSubject();
-
- /**
- * The predicate {@link IRI} of this triple/quad.
- *
- * @return The predicate {@link IRI} of this triple/quad.
- * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-predicate">RDF-1.1
- * Triple predicate</a>
- */
- IRI getPredicate();
-
- /**
- * The object of this triple/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 triple/quad.
- * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-object">RDF-1.1
- * Triple object</a>
- */
- RDFTerm getObject();
-}
[06/19] incubator-commonsrdf git commit: Merge branch 'SimpleRDFTerm'
into quad
Posted by st...@apache.org.
Merge branch 'SimpleRDFTerm' into quad
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/8ee8e2c2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/8ee8e2c2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/8ee8e2c2
Branch: refs/heads/master
Commit: 8ee8e2c2ad4e6cb8250eb564c2e98e8a8fd38f85
Parents: 220f75f 0a148cb
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Apr 8 16:21:13 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Apr 8 16:21:13 2016 +0100
----------------------------------------------------------------------
.../apache/commons/rdf/simple/BlankNodeImpl.java | 3 ++-
.../org/apache/commons/rdf/simple/GraphImpl.java | 18 +++++++++++-------
.../org/apache/commons/rdf/simple/IRIImpl.java | 2 +-
.../apache/commons/rdf/simple/LiteralImpl.java | 2 +-
.../commons/rdf/simple/SimpleRDFTermFactory.java | 12 ++++++++++++
.../java/org/apache/commons/rdf/simple/Types.java | 2 +-
6 files changed, 28 insertions(+), 11 deletions(-)
----------------------------------------------------------------------