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/06/14 17:02:28 UTC
[1/2] incubator-commonsrdf git commit: expose includeInferred
Repository: incubator-commonsrdf
Updated Branches:
refs/heads/rdf4j 81f195f31 -> ea6b992b0
expose includeInferred
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/ccb5c5fd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/ccb5c5fd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/ccb5c5fd
Branch: refs/heads/rdf4j
Commit: ccb5c5fd46ec268fb6400f35c85ee5265b387618
Parents: 81f195f
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Tue Jun 14 17:57:54 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Tue Jun 14 17:57:54 2016 +0100
----------------------------------------------------------------------
.../commons/rdf/rdf4j/RDF4JTermFactory.java | 34 +++++++++++++++++---
.../rdf/rdf4j/impl/RepositoryDatasetImpl.java | 17 +++++-----
.../rdf/rdf4j/impl/RepositoryGraphImpl.java | 15 ++++++---
3 files changed, 47 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ccb5c5fd/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTermFactory.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTermFactory.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTermFactory.java
index 9aa0fda..9326807 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTermFactory.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTermFactory.java
@@ -170,19 +170,43 @@ public class RDF4JTermFactory implements RDFTermFactory {
/**
* Adapt an RDF4J {@link Repository} as a Commons RDF {@link Graph}.
* <p>
+ * The graph will include triples in any contexts (e.g. the union graph).
+ * <p>
* Changes to the graph are reflected in the repository, and vice versa.
*
* @param model
* RDF4J {@link Repository} to connect to.
- * @return Adapted {@link Graph}.
+ * @return A {@link Graph} backed by the RDF4J repository.
*/
public RDF4JGraph asRDFTermGraph(Repository repository) {
- return new RepositoryGraphImpl(repository);
+ return new RepositoryGraphImpl(repository, false, true);
+ }
+
+ /**
+ * Adapt an RDF4J {@link Repository} as a Commons RDF {@link Graph}.
+ * <p>
+ * The graph will include triples in any contexts (e.g. the union graph).
+ * <p>
+ * Changes to the graph are reflected in the repository, and vice versa.
+ *
+ * @param repository
+ * RDF4J {@link Repository} to connect to.
+ * @param includeInferred
+ * If true, any inferred triples are included in the graph
+ * @param unionGraph
+ * If true, triples from any context is included in the graph,
+ * otherwise only triples in the default context
+ * <code>null</code>.
+ * @return A {@link Graph} backed by the RDF4J repository.
+ */
+ public RDF4JGraph asRDFTermGraph(Repository repository, boolean includeInferred, boolean unionGraph) {
+ return new RepositoryGraphImpl(repository, includeInferred, unionGraph);
}
public Statement asStatement(TripleLike<BlankNodeOrIRI, org.apache.commons.rdf.api.IRI, RDFTerm> tripleLike) {
if (tripleLike instanceof RDF4JTripleLike) {
- // Return original statement - this covers both RDF4JQuad and RDF4JTriple
+ // Return original statement - this covers both RDF4JQuad and
+ // RDF4JTriple
RDF4JTripleLike rdf4jTriple = (RDF4JTripleLike) tripleLike;
return rdf4jTriple.asStatement();
}
@@ -190,13 +214,13 @@ public class RDF4JTermFactory implements RDFTermFactory {
org.eclipse.rdf4j.model.Resource subject = (org.eclipse.rdf4j.model.Resource) asValue(tripleLike.getSubject());
org.eclipse.rdf4j.model.IRI predicate = (org.eclipse.rdf4j.model.IRI) asValue(tripleLike.getPredicate());
Value object = asValue(tripleLike.getObject());
-
+
org.eclipse.rdf4j.model.Resource context = null;
if (tripleLike instanceof Quad) {
Quad quad = (Quad) tripleLike;
context = (org.eclipse.rdf4j.model.Resource) asValue(quad.getGraphName().orElse(null));
}
-
+
return valueFactory.createStatement(subject, predicate, object, context);
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ccb5c5fd/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/RepositoryDatasetImpl.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/RepositoryDatasetImpl.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/RepositoryDatasetImpl.java
index 0fb8a78..fa989a1 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/RepositoryDatasetImpl.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/RepositoryDatasetImpl.java
@@ -17,7 +17,6 @@
*/
package org.apache.commons.rdf.rdf4j.impl;
-import java.util.ConcurrentModificationException;
import java.util.Optional;
import java.util.stream.Stream;
@@ -85,6 +84,11 @@ public class RepositoryDatasetImpl extends AbstractRepositoryGraphLike<Quad> imp
@Override
public long size() {
+ if (includeInferred) {
+ // We'll need to count them all
+ return stream().count();
+ }
+ // else: Ask directly
try (RepositoryConnection conn = getRepositoryConnection()) {
return conn.size();
}
@@ -165,19 +169,14 @@ public class RepositoryDatasetImpl extends AbstractRepositoryGraphLike<Quad> imp
}
@Override
- public Iterable<Quad> iterate() throws ConcurrentModificationException, IllegalStateException {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
public Graph getGraph() {
- // TODO: Specify default context only? (the below will give the union graph)
- return new RepositoryGraphImpl(repository, includeInferred);
+ // default context only
+ return new RepositoryGraphImpl(repository, includeInferred, (Resource)null);
}
@Override
public Optional<Graph> getGraph(BlankNodeOrIRI graphName) {
+ // NOTE: May be null to indicate default context
Resource context = (Resource) rdf4jTermFactory.asValue(graphName);
return Optional.of(new RepositoryGraphImpl(repository, includeInferred, context));
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ccb5c5fd/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/RepositoryGraphImpl.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/RepositoryGraphImpl.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/RepositoryGraphImpl.java
index 2950579..7c15d1d 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/RepositoryGraphImpl.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/RepositoryGraphImpl.java
@@ -36,11 +36,16 @@ import org.eclipse.rdf4j.repository.RepositoryResult;
public class RepositoryGraphImpl extends AbstractRepositoryGraphLike<Triple> implements Graph, RDF4JGraph {
- private Resource[] contextFilter;
+ private final Resource[] contextFilter;
- public RepositoryGraphImpl(Repository repository) {
- // All contexts (supplying null would mean default graph only)
- this(repository, false);
+ public RepositoryGraphImpl(Repository repository, boolean includeInferred, boolean unionGraph) {
+ super(repository, includeInferred);
+ if (unionGraph) {
+ this.contextFilter = null;
+ } else {
+ // default context: null
+ this.contextFilter = new Resource[] { null };
+ }
}
public RepositoryGraphImpl(Repository repository, boolean includeInferred, Resource... contextFilter) {
@@ -140,7 +145,7 @@ public class RepositoryGraphImpl extends AbstractRepositoryGraphLike<Triple> imp
Value obj = rdf4jTermFactory.asValue(object);
RepositoryConnection conn = getRepositoryConnection();
// FIXME: Is it OK that we don't close the connection?
- RepositoryResult<Statement> statements = conn.getStatements(subj, pred, obj, contextFilter);
+ RepositoryResult<Statement> statements = conn.getStatements(subj, pred, obj, includeInferred, contextFilter);
return Iterations.stream(statements).map(this::asTripleLike);
}
[2/2] incubator-commonsrdf git commit: add asRDFTermDataset
Posted by st...@apache.org.
add asRDFTermDataset
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/ea6b992b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/ea6b992b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/ea6b992b
Branch: refs/heads/rdf4j
Commit: ea6b992b02aa3b19d374de33922365572632838a
Parents: ccb5c5f
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Tue Jun 14 18:01:01 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Tue Jun 14 18:01:01 2016 +0100
----------------------------------------------------------------------
.../commons/rdf/rdf4j/RDF4JTermFactory.java | 32 +++++++++++++++++++-
1 file changed, 31 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ea6b992b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTermFactory.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTermFactory.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTermFactory.java
index 9326807..04b0030 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTermFactory.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTermFactory.java
@@ -24,6 +24,7 @@ import java.util.UUID;
// commons.rdf and openrdf.model (e.g. IRI)
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.Quad;
import org.apache.commons.rdf.api.RDFTerm;
@@ -35,6 +36,7 @@ import org.apache.commons.rdf.rdf4j.impl.IRIImpl;
import org.apache.commons.rdf.rdf4j.impl.LiteralImpl;
import org.apache.commons.rdf.rdf4j.impl.ModelGraphImpl;
import org.apache.commons.rdf.rdf4j.impl.QuadImpl;
+import org.apache.commons.rdf.rdf4j.impl.RepositoryDatasetImpl;
import org.apache.commons.rdf.rdf4j.impl.RepositoryGraphImpl;
import org.apache.commons.rdf.rdf4j.impl.TripleImpl;
import org.eclipse.rdf4j.model.BNode;
@@ -155,6 +157,34 @@ public class RDF4JTermFactory implements RDFTermFactory {
}
/**
+ * Adapt an RDF4J {@link Repository} as a Commons RDF {@link Dataset}.
+ * <p>
+ * Changes to the dataset are reflected in the repository, and vice versa.
+ *
+ * @param repository
+ * RDF4J {@link Repository} to connect to.
+ * @return A {@link Dataset} backed by the RDF4J repository.
+ */
+ public RDF4JDataset asRDFTermDataset(Repository repository) {
+ return new RepositoryDatasetImpl(repository);
+ }
+
+ /**
+ * Adapt an RDF4J {@link Repository} as a Commons RDF {@link Dataset}.
+ * <p>
+ * Changes to the dataset are reflected in the repository, and vice versa.
+ *
+ * @param repository
+ * RDF4J {@link Repository} to connect to.
+ * @param includeInferred
+ * If true, any inferred quads are included in the dataset
+ * @return A {@link Dataset} backed by the RDF4J repository.
+ */
+ public RDF4JDataset asRDFTermDataset(Repository repository, boolean includeInferred) {
+ return new RepositoryDatasetImpl(repository, includeInferred);
+ }
+
+ /**
* Adapt an RDF4J {@link Model} as a Commons RDF {@link Graph}.
* <p>
* Changes to the graph are reflected in the model, and vice versa.
@@ -174,7 +204,7 @@ public class RDF4JTermFactory implements RDFTermFactory {
* <p>
* Changes to the graph are reflected in the repository, and vice versa.
*
- * @param model
+ * @param repository
* RDF4J {@link Repository} to connect to.
* @return A {@link Graph} backed by the RDF4J repository.
*/