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/20 11:29:37 UTC

[1/5] incubator-commonsrdf git commit: organized imports

Repository: incubator-commonsrdf
Updated Branches:
  refs/heads/rdf4j 88793ce65 -> 9c66ae083


organized imports


Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/9209b0c7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/9209b0c7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/9209b0c7

Branch: refs/heads/rdf4j
Commit: 9209b0c7c8daa3347027acb31ad3fbbf94e77177
Parents: 88793ce
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Mon Jun 20 10:07:53 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Mon Jun 20 10:07:53 2016 +0100

----------------------------------------------------------------------
 .../java/org/apache/commons/rdf/rdf4j/Rdf4JRDFTermFactoryTest.java  | 1 -
 1 file changed, 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/9209b0c7/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/Rdf4JRDFTermFactoryTest.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/Rdf4JRDFTermFactoryTest.java b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/Rdf4JRDFTermFactoryTest.java
index b08b966..bc06c62 100644
--- a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/Rdf4JRDFTermFactoryTest.java
+++ b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/Rdf4JRDFTermFactoryTest.java
@@ -20,7 +20,6 @@ package org.apache.commons.rdf.rdf4j;
 import org.apache.commons.rdf.api.AbstractRDFTermFactoryTest;
 import org.apache.commons.rdf.api.RDFTermFactory;
 import org.junit.Assume;
-import org.junit.Ignore;
 
 public class Rdf4JRDFTermFactoryTest extends AbstractRDFTermFactoryTest {
 


[3/5] incubator-commonsrdf git commit: Reduce rdf4j-dependencies

Posted by st...@apache.org.
Reduce rdf4j-dependencies


Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/01ae8d91
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/01ae8d91
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/01ae8d91

Branch: refs/heads/rdf4j
Commit: 01ae8d91fda0927bc989a5847d68da7b8154bfc4
Parents: 5709ab2
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Mon Jun 20 12:20:44 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Mon Jun 20 12:20:44 2016 +0100

----------------------------------------------------------------------
 rdf4j/pom.xml | 174 ++++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 132 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/01ae8d91/rdf4j/pom.xml
----------------------------------------------------------------------
diff --git a/rdf4j/pom.xml b/rdf4j/pom.xml
index 29aeb3f..08aaf7d 100644
--- a/rdf4j/pom.xml
+++ b/rdf4j/pom.xml
@@ -18,23 +18,43 @@
     limitations under the License.
 
 -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-    <modelVersion>4.0.0</modelVersion>
-
-    <parent>
-        <groupId>org.apache.commons</groupId>
-        <artifactId>commons-rdf-parent</artifactId>
-        <version>0.3.0-incubating-SNAPSHOT</version>
-    </parent>
-
-    <artifactId>commons-rdf-rdf4j</artifactId>
-    <packaging>jar</packaging>
-	<properties>	
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+
+	<parent>
+		<groupId>org.apache.commons</groupId>
+		<artifactId>commons-rdf-parent</artifactId>
+		<version>0.3.0-incubating-SNAPSHOT</version>
+	</parent>
+
+	<artifactId>commons-rdf-rdf4j</artifactId>
+	<packaging>jar</packaging>
+	<properties>
 		<rdf4j.version>2.0M2</rdf4j.version>
 	</properties>
 
-    <name>Commons RDF: Integration: RDF4j</name>
-    <description>Eclipse RDF4j implementation of Commons RDF API</description>
+	<name>Commons RDF: Integration: RDF4j</name>
+	<description>Eclipse RDF4j implementation of Commons RDF API</description>
+
+	<build>
+		<plugins>
+			<plugin>
+
+				<groupId>org.apache.felix</groupId>
+				<artifactId>maven-bundle-plugin</artifactId>
+				<configuration>
+					<instructions>
+						<!-- Not sure why this is needed, .impl and .internal is normally hidden 
+							by the Bundle Plugin.. -->
+
+						<Export-Package>org.apache.commons.rdf.rdf4j</Export-Package>
+						<Private-Package>org.apache.commons.rdf.rdf4j.impl</Private-Package>
+					</instructions>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
 
 	<dependencies>
 		<dependency>
@@ -47,37 +67,107 @@
 			<artifactId>commons-rdf-simple</artifactId>
 			<version>${project.version}</version>
 		</dependency>
+
+		<!-- Selected rdf4j dependencies We don't use rdf4j-runtime or rdf4j-runtime-osgi 
+			here, as they pull in various depenencies like lucene, which might not be 
+			needed. -->
+
+		<dependency>
+			<groupId>org.eclipse.rdf4j</groupId>
+			<artifactId>rdf4j-model</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.eclipse.rdf4j</groupId>
+			<artifactId>rdf4j-repository-api</artifactId>
+		</dependency>
+
+		<!-- For RDF4JParserBuilder, these are the RIO dependencies for the standard 
+			RDF 1.1 languages -->
+		<dependency>
+			<groupId>org.eclipse.rdf4j</groupId>
+			<artifactId>rdf4j-rio-turtle</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.eclipse.rdf4j</groupId>
+			<artifactId>rdf4j-rio-ntriples</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.eclipse.rdf4j</groupId>
+			<artifactId>rdf4j-rio-nquads</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.eclipse.rdf4j</groupId>
+			<artifactId>rdf4j-rio-rdfxml</artifactId>
+		</dependency>
 		<dependency>
 			<groupId>org.eclipse.rdf4j</groupId>
-			<artifactId>rdf4j-runtime</artifactId>
+			<artifactId>rdf4j-rio-trig</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.eclipse.rdf4j</groupId>
+			<artifactId>rdf4j-rio-jsonld</artifactId>
+			<!-- FIXME: version should be in rdf4j-bom https://github.com/eclipse/rdf4j/issues/189 -->
 			<version>${rdf4j.version}</version>
 		</dependency>
-        
-        <dependency>
-            <groupId>${project.parent.groupId}</groupId>
-            <artifactId>commons-rdf-api</artifactId>
-            <version>${project.version}</version>
-            <classifier>tests</classifier>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <scope>test</scope>
-        </dependency>
-    </dependencies>
-
-<!-- Ensure consistent rdf4j versions across the board -->
-<dependencyManagement>
-    <dependencies>
-        <dependency>
-            <groupId>org.eclipse.rdf4j</groupId>
-            <artifactId>rdf4j-bom</artifactId>
-            <version>${rdf4j.version}</version>
-            <type>pom</type>
-            <scope>import</scope>
-        </dependency>
-    </dependencies>
-</dependencyManagement>
+		<!-- Languages notably missing, and why: 
+		
+		rdf4j-rio-rdfjson: standard, but https://www.w3.org/TR/rdf-json/ says:
+			"The syntax defined in this document should not be used unless there is a specific reason to do so" 
+			
+		rdf4j-rio-binary: non-standard 
+		
+		rdf4j-rio-n3: unofficial standard, super-seeded by Turtle
+			
+		rdf4j-rio-trix: unofficial standard 
+		-->
+
+
+		<!-- There are multiple RDF4J sail/repository implementations, we use the 
+			below for testing. -->
+		<dependency>
+			<groupId>org.eclipse.rdf4j</groupId>
+			<artifactId>rdf4j-sail-memory</artifactId>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.eclipse.rdf4j</groupId>
+			<artifactId>rdf4j-sail-nativerdf</artifactId>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.eclipse.rdf4j</groupId>
+			<artifactId>rdf4j-repository-sail</artifactId>
+			<scope>test</scope>
+		</dependency>
+
+
+		<dependency>
+			<groupId>${project.parent.groupId}</groupId>
+			<artifactId>commons-rdf-api</artifactId>
+			<version>${project.version}</version>
+			<classifier>tests</classifier>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<scope>test</scope>
+		</dependency>
+	</dependencies>
+
+
+
+	<!-- Ensure consistent rdf4j versions across the board -->
+	<dependencyManagement>
+		<dependencies>
+			<dependency>
+				<groupId>org.eclipse.rdf4j</groupId>
+				<artifactId>rdf4j-bom</artifactId>
+				<version>${rdf4j.version}</version>
+				<type>pom</type>
+				<scope>import</scope>
+			</dependency>
+		</dependencies>
+	</dependencyManagement>
 
 </project>


[4/5] incubator-commonsrdf git commit: javadoc on rdf4j implementation

Posted by st...@apache.org.
javadoc on rdf4j implementation


Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/8ef35e6c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/8ef35e6c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/8ef35e6c

Branch: refs/heads/rdf4j
Commit: 8ef35e6c0bec86207de97707701ae5add7bd09ce
Parents: 01ae8d9
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Mon Jun 20 12:28:42 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Mon Jun 20 12:29:08 2016 +0100

----------------------------------------------------------------------
 .../apache/commons/rdf/rdf4j/package-info.java  | 31 ++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/8ef35e6c/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/package-info.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/package-info.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/package-info.java
index b8ad947..844da5a 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/package-info.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/package-info.java
@@ -18,9 +18,36 @@
 /**
  * Commons RDF integration with <a href="http://rdf4j.org/">RDF4J</a>.
  * <p>
+ * Use the {@link org.apache.commons.rdf.rdf4j.RDF4JTermFactory} to convert
+ * between Commons RDF and RDF4J types, for instance
+ * {@link org.apache.commons.rdf.rdf4j.RDF4JTermFactory#asQuad(org.eclipse.rdf4j.model.Statement)}
+ * converts a RDF4J {@link org.eclipse.rdf4j.model.Statement} to a
+ * {@link org.apache.commons.rdf.api.Quad}. Converted RDF terms implement the
+ * {@link org.apache.commons.rdf.rdf4j.RDF4JTerm} interface, and converted
+ * statements the {@link org.apache.commons.rdf.rdf4j.RDF4JTripleLike}
+ * interface, which provide convenience access to the underlying RDF4J
+ * implementations.
+ * <p>
+ * RDF4J {@link org.eclipse.rdf4j.model.Model}s and
+ * {@link org.eclipse.rdf4j.repository.Repository} instances can be adapted to
+ * Commons RDF {@link org.apache.commons.rdf.api.Graph} and
+ * {@link org.apache.commons.rdf.api.Dataset}, e.g. using
+ * {@link org.apache.commons.rdf.rdf4j.RDF4JTermFactory#asRDFTermGraph(org.eclipse.rdf4j.model.Model)}
+ * or
+ * {@link org.apache.commons.rdf.rdf4j.RDF4JTermFactory#asRDFTermDataset(org.eclipse.rdf4j.repository.Repository)}.
+ * The returned adapted graph/dataset is directly mapped, so changes are
+ * propagated both ways. For convenience, the marker interface
+ * {@link org.apache.commons.rdf.rdf4j.RDF4JGraph} and
+ * {@link org.apache.commons.rdf.rdf4j.RDF4JDataset} provide access to the
+ * underlying RDF4J implementations.
+ * <p>
+ * The {@link org.apache.commons.rdf.rdf4j.RDF4JParserBuilder} can be used to
+ * parse RDF files using RDF4j. It should be most efficient if used with
+ * {@link org.apache.commons.rdf.rdf4j.RDF4JParserBuilder#target(org.apache.commons.rdf.api.Dataset)}
+ * and an adapted {@link org.apache.commons.rdf.rdf4j.RDF4JDataset}, or
+ * {@link org.apache.commons.rdf.rdf4j.RDF4JParserBuilder#target(org.apache.commons.rdf.api.Graph)}
+ * and a an adapted {@link org.apache.commons.rdf.rdf4j.RDF4JGraph}
  * 
  *
  */
 package org.apache.commons.rdf.rdf4j;
-
-


[5/5] incubator-commonsrdf git commit: Move RDF4JParserBuilder up from rdfj.impl

Posted by st...@apache.org.
Move RDF4JParserBuilder up from rdfj.impl


Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/9c66ae08
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/9c66ae08
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/9c66ae08

Branch: refs/heads/rdf4j
Commit: 9c66ae0834c0908eed0035fa258f0ea38e060259
Parents: 8ef35e6
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Mon Jun 20 12:29:13 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Mon Jun 20 12:29:13 2016 +0100

----------------------------------------------------------------------
 .../commons/rdf/rdf4j/RDF4JParserBuilder.java   | 156 +++++++++++++++++++
 .../rdf/rdf4j/impl/RDF4JParserBuilder.java      | 156 -------------------
 2 files changed, 156 insertions(+), 156 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/9c66ae08/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JParserBuilder.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JParserBuilder.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JParserBuilder.java
new file mode 100644
index 0000000..0c1aa12
--- /dev/null
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JParserBuilder.java
@@ -0,0 +1,156 @@
+/**
+ * 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.rdf4j;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.Optional;
+import java.util.function.Consumer;
+
+import org.apache.commons.rdf.api.Quad;
+import org.apache.commons.rdf.api.RDFParserBuilder;
+import org.apache.commons.rdf.rdf4j.RDF4JDataset;
+import org.apache.commons.rdf.rdf4j.RDF4JGraph;
+import org.apache.commons.rdf.rdf4j.RDF4JTermFactory;
+import org.apache.commons.rdf.simple.AbstractRDFParserBuilder;
+import org.eclipse.rdf4j.model.Model;
+import org.eclipse.rdf4j.repository.util.RDFInserter;
+import org.eclipse.rdf4j.rio.RDFFormat;
+import org.eclipse.rdf4j.rio.RDFHandler;
+import org.eclipse.rdf4j.rio.RDFHandlerException;
+import org.eclipse.rdf4j.rio.RDFParser;
+import org.eclipse.rdf4j.rio.Rio;
+import org.eclipse.rdf4j.rio.helpers.AbstractRDFHandler;
+
+public class RDF4JParserBuilder extends AbstractRDFParserBuilder implements RDFParserBuilder {
+
+	private final class AddToQuadConsumer extends AbstractRDFHandler {
+		private final Consumer<Quad> quadTarget;
+
+		private AddToQuadConsumer(Consumer<Quad> quadTarget) {
+			this.quadTarget = quadTarget;
+		}
+
+		public void handleStatement(org.eclipse.rdf4j.model.Statement st)
+				throws org.eclipse.rdf4j.rio.RDFHandlerException {
+			// TODO: if getRdfTermFactory() is a non-rdf4j factory, should
+			// we use factory.createQuad() instead?
+			// Unsure what is the promise of setting getRdfTermFactory() --
+			// does it go all the way down to creating BlankNode, IRI and
+			// Literal?
+			quadTarget.accept(rdf4jTermFactory.asQuad(st));
+			// Performance note:
+			// Graph/Quad.add should pick up again our
+			// RDF4JGraphLike.asStatement()
+			// and avoid double conversion.
+			// Additionally the RDF4JQuad and RDF4JTriple implementations
+			// are lazily converting subj/obj/pred/graph.s
+		}
+	}
+
+	private final static class AddToModel extends AbstractRDFHandler {
+		private final Model model;
+
+		public AddToModel(Model model) {
+			this.model = model;
+		}
+
+		public void handleStatement(org.eclipse.rdf4j.model.Statement st)
+				throws org.eclipse.rdf4j.rio.RDFHandlerException {
+			model.add(st);
+		}
+		
+		@Override
+		public void handleNamespace(String prefix, String uri) throws RDFHandlerException {
+			model.setNamespace(prefix, uri);
+		}
+	}
+
+	private RDF4JTermFactory rdf4jTermFactory;
+
+	@Override
+	protected RDF4JTermFactory createRDFTermFactory() {
+		return new RDF4JTermFactory();
+	}
+
+	@Override
+	protected AbstractRDFParserBuilder prepareForParsing() throws IOException, IllegalStateException {
+		RDF4JParserBuilder c = (RDF4JParserBuilder) prepareForParsing();
+		// Ensure we have an RDF4JTermFactory for conversion.
+		// We'll make a new one if user has provided a non-RDF4J factory
+		c.rdf4jTermFactory = (RDF4JTermFactory) getRdfTermFactory().filter(RDF4JTermFactory.class::isInstance)
+				.orElseGet(c::createRDFTermFactory);
+		return c;
+	}
+
+	@Override
+	protected void parseSynchronusly() throws IOException, RDFParseException {
+		if (getContentType().isPresent()) {
+			Rio.getParserFormatForMIMEType(getContentType().get());
+		}
+
+		Optional<RDFFormat> formatByMimeType = getContentType().flatMap(Rio::getParserFormatForMIMEType);
+		Optional<RDFFormat> formatByFilename = getSourceFile().map(Path::getFileName).map(Path::toString)
+				.flatMap(Rio::getParserFormatForFileName);
+		RDFFormat format = formatByMimeType.orElse(
+				formatByFilename.orElseThrow(() -> new RDFParseException("Unrecognized or missing content type")));
+
+		RDFParser parser = Rio.createParser(format);
+
+		parser.setRDFHandler(makeRDFHandler());
+	}
+
+	protected RDFHandler makeRDFHandler() {
+
+		// TODO: Can we join the below DF4JDataset and RDF4JGraph cases
+		// using RDF4JGraphLike<TripleLike<BlankNodeOrIRI,IRI,RDFTerm>>
+		// or will that need tricky generics types?
+
+		if (getTargetDataset().filter(RDF4JDataset.class::isInstance).isPresent()) {
+			// One of us, we can add them as Statements directly
+			RDF4JDataset dataset = (RDF4JDataset) getTargetDataset().get();
+			if (dataset.asRepository().isPresent()) {				
+				return new RDFInserter(dataset.asRepository().get().getConnection());
+			}
+			if (dataset.asModel().isPresent()) {
+				Model model = dataset.asModel().get();
+				return new AddToModel(model);
+			}
+			// Not backed by Repository or Model?
+			// Third-party RDF4JDataset subclass, so we'll fall through to the
+			// getTarget() handling further down
+		} else if (getTargetGraph().filter(RDF4JGraph.class::isInstance).isPresent()) {
+			RDF4JGraph graph = (RDF4JGraph) getTargetGraph().get();
+
+			if (graph.asRepository().isPresent()) {
+				RDFInserter inserter = new RDFInserter(graph.asRepository().get().getConnection());
+				graph.getContextFilter().ifPresent(inserter::enforceContext);
+				return inserter;
+			}
+			if (graph.asModel().isPresent() && graph.getContextFilter().isPresent()) {
+				Model model = graph.asModel().get();
+				return new AddToModel(model);
+			}
+			// else - fall through
+		}
+
+		// Fall thorough: let target() consume our converted quads.
+		return new AddToQuadConsumer(getTarget());
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/9c66ae08/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/RDF4JParserBuilder.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/RDF4JParserBuilder.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/RDF4JParserBuilder.java
deleted file mode 100644
index da09be3..0000000
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/RDF4JParserBuilder.java
+++ /dev/null
@@ -1,156 +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.rdf4j.impl;
-
-import java.io.IOException;
-import java.nio.file.Path;
-import java.util.Optional;
-import java.util.function.Consumer;
-
-import org.apache.commons.rdf.api.Quad;
-import org.apache.commons.rdf.api.RDFParserBuilder;
-import org.apache.commons.rdf.rdf4j.RDF4JDataset;
-import org.apache.commons.rdf.rdf4j.RDF4JGraph;
-import org.apache.commons.rdf.rdf4j.RDF4JTermFactory;
-import org.apache.commons.rdf.simple.AbstractRDFParserBuilder;
-import org.eclipse.rdf4j.model.Model;
-import org.eclipse.rdf4j.repository.util.RDFInserter;
-import org.eclipse.rdf4j.rio.RDFFormat;
-import org.eclipse.rdf4j.rio.RDFHandler;
-import org.eclipse.rdf4j.rio.RDFHandlerException;
-import org.eclipse.rdf4j.rio.RDFParser;
-import org.eclipse.rdf4j.rio.Rio;
-import org.eclipse.rdf4j.rio.helpers.AbstractRDFHandler;
-
-public class RDF4JParserBuilder extends AbstractRDFParserBuilder implements RDFParserBuilder {
-
-	private final class AddToQuadConsumer extends AbstractRDFHandler {
-		private final Consumer<Quad> quadTarget;
-
-		private AddToQuadConsumer(Consumer<Quad> quadTarget) {
-			this.quadTarget = quadTarget;
-		}
-
-		public void handleStatement(org.eclipse.rdf4j.model.Statement st)
-				throws org.eclipse.rdf4j.rio.RDFHandlerException {
-			// TODO: if getRdfTermFactory() is a non-rdf4j factory, should
-			// we use factory.createQuad() instead?
-			// Unsure what is the promise of setting getRdfTermFactory() --
-			// does it go all the way down to creating BlankNode, IRI and
-			// Literal?
-			quadTarget.accept(rdf4jTermFactory.asQuad(st));
-			// Performance note:
-			// Graph/Quad.add should pick up again our
-			// RDF4JGraphLike.asStatement()
-			// and avoid double conversion.
-			// Additionally the RDF4JQuad and RDF4JTriple implementations
-			// are lazily converting subj/obj/pred/graph.s
-		}
-	}
-
-	private final static class AddToModel extends AbstractRDFHandler {
-		private final Model model;
-
-		public AddToModel(Model model) {
-			this.model = model;
-		}
-
-		public void handleStatement(org.eclipse.rdf4j.model.Statement st)
-				throws org.eclipse.rdf4j.rio.RDFHandlerException {
-			model.add(st);
-		}
-		
-		@Override
-		public void handleNamespace(String prefix, String uri) throws RDFHandlerException {
-			model.setNamespace(prefix, uri);
-		}
-	}
-
-	private RDF4JTermFactory rdf4jTermFactory;
-
-	@Override
-	protected RDF4JTermFactory createRDFTermFactory() {
-		return new RDF4JTermFactory();
-	}
-
-	@Override
-	protected AbstractRDFParserBuilder prepareForParsing() throws IOException, IllegalStateException {
-		RDF4JParserBuilder c = (RDF4JParserBuilder) prepareForParsing();
-		// Ensure we have an RDF4JTermFactory for conversion.
-		// We'll make a new one if user has provided a non-RDF4J factory
-		c.rdf4jTermFactory = (RDF4JTermFactory) getRdfTermFactory().filter(RDF4JTermFactory.class::isInstance)
-				.orElseGet(c::createRDFTermFactory);
-		return c;
-	}
-
-	@Override
-	protected void parseSynchronusly() throws IOException, RDFParseException {
-		if (getContentType().isPresent()) {
-			Rio.getParserFormatForMIMEType(getContentType().get());
-		}
-
-		Optional<RDFFormat> formatByMimeType = getContentType().flatMap(Rio::getParserFormatForMIMEType);
-		Optional<RDFFormat> formatByFilename = getSourceFile().map(Path::getFileName).map(Path::toString)
-				.flatMap(Rio::getParserFormatForFileName);
-		RDFFormat format = formatByMimeType.orElse(
-				formatByFilename.orElseThrow(() -> new RDFParseException("Unrecognized or missing content type")));
-
-		RDFParser parser = Rio.createParser(format);
-
-		parser.setRDFHandler(makeRDFHandler());
-	}
-
-	protected RDFHandler makeRDFHandler() {
-
-		// TODO: Can we join the below DF4JDataset and RDF4JGraph cases
-		// using RDF4JGraphLike<TripleLike<BlankNodeOrIRI,IRI,RDFTerm>>
-		// or will that need tricky generics types?
-
-		if (getTargetDataset().filter(RDF4JDataset.class::isInstance).isPresent()) {
-			// One of us, we can add them as Statements directly
-			RDF4JDataset dataset = (RDF4JDataset) getTargetDataset().get();
-			if (dataset.asRepository().isPresent()) {				
-				return new RDFInserter(dataset.asRepository().get().getConnection());
-			}
-			if (dataset.asModel().isPresent()) {
-				Model model = dataset.asModel().get();
-				return new AddToModel(model);
-			}
-			// Not backed by Repository or Model?
-			// Third-party RDF4JDataset subclass, so we'll fall through to the
-			// getTarget() handling further down
-		} else if (getTargetGraph().filter(RDF4JGraph.class::isInstance).isPresent()) {
-			RDF4JGraph graph = (RDF4JGraph) getTargetGraph().get();
-
-			if (graph.asRepository().isPresent()) {
-				RDFInserter inserter = new RDFInserter(graph.asRepository().get().getConnection());
-				graph.getContextFilter().ifPresent(inserter::enforceContext);
-				return inserter;
-			}
-			if (graph.asModel().isPresent() && graph.getContextFilter().isPresent()) {
-				Model model = graph.asModel().get();
-				return new AddToModel(model);
-			}
-			// else - fall through
-		}
-
-		// Fall thorough: let target() consume our converted quads.
-		return new AddToQuadConsumer(getTarget());
-	}
-
-}


[2/5] incubator-commonsrdf git commit: rdf4j javadoc improvements

Posted by st...@apache.org.
rdf4j javadoc improvements


Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/5709ab23
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/5709ab23
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/5709ab23

Branch: refs/heads/rdf4j
Commit: 5709ab23539b3542634a8ecfb2e63f9fe3a71966
Parents: 9209b0c
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Mon Jun 20 10:46:03 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Mon Jun 20 11:06:31 2016 +0100

----------------------------------------------------------------------
 .../apache/commons/rdf/rdf4j/RDF4JGraph.java    |  28 ++--
 .../org/apache/commons/rdf/rdf4j/RDF4JTerm.java |   5 +-
 .../commons/rdf/rdf4j/RDF4JTermFactory.java     | 144 ++++++++++++++++---
 .../apache/commons/rdf/rdf4j/package-info.java  |  26 ++++
 4 files changed, 175 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/5709ab23/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JGraph.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JGraph.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JGraph.java
index f328be1..396a39b 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JGraph.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JGraph.java
@@ -23,7 +23,9 @@ import org.apache.commons.rdf.api.Graph;
 import org.apache.commons.rdf.api.Triple;
 import org.apache.commons.rdf.rdf4j.impl.ModelGraphImpl;
 import org.apache.commons.rdf.rdf4j.impl.RepositoryGraphImpl;
+import org.eclipse.rdf4j.model.Model;
 import org.eclipse.rdf4j.model.Resource;
+import org.eclipse.rdf4j.repository.Repository;
 
 
 /**
@@ -37,23 +39,27 @@ public interface RDF4JGraph extends Graph, RDF4JGraphLike<Triple> {
 	/**
 	 * Return a copy of the context filter, if present.
 	 * <p>
-	 * If {@link Optional#isPresent()}, the filter determines which contexts
-	 * this graph reflect. Modifications to the graph (e.g. {@link #add(Triple)
-	 * will be performed for all the specified contexts, while retrieval (e.g.
-	 * {@link #contains(Triple)}) will succeed if the triple is in at least one
-	 * of the specified contexts.
+	 * If {@link Optional#isPresent()}, the filter determines which
+	 * <em>contexts</em> in the corresponding RDF4J {@link Model} or
+	 * {@link Repository} that this graph reflect. Modifications to the graph
+	 * (e.g. {@link #add(Triple)} will be performed for all the specified
+	 * contexts, while retrieval (e.g. {@link #contains(Triple)}) will succeed
+	 * if the triple is in at least one of the specified contexts.
 	 * <p>
 	 * The context filter array may contain <code>null</code>, indicating the
 	 * default context (the <em>default graph</em> in RDF datasets).
 	 * <p>
-	 * If the context filter is {@link Optional#empty()}, then this is a union
-	 * graph which triples reflecting statements in any contexts. Triples added
-	 * to the graph will be added in the default context <code>null</code>.
+	 * If the context filter is {@link Optional#empty()}, then this is a
+	 * <em>union graph</em> which triples reflecting statements in any contexts.
+	 * Triples added to the graph will be added in the default context
+	 * <code>null</code>.
 	 * <p>
-	 * The returned filter is a copy and thus any modifications are not
-	 * reflected in the RDF4JGraph.
+	 * The filter array is a copy, and thus any modifications are not reflected
+	 * in the RDF4JGraph.
 	 * 
-	 * @return
+	 * @return The context filter as an array of {@link Resource}s, or
+	 *         {@link Optional#empty()} indicating the union graph (any
+	 *         context).
 	 */
 	public Optional<Resource[]> getContextFilter();
 	

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/5709ab23/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTerm.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTerm.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTerm.java
index 3117eee..7128b48 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTerm.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTerm.java
@@ -18,6 +18,9 @@
 package org.apache.commons.rdf.rdf4j;
 
 import org.apache.commons.rdf.api.RDFTerm;
+import org.eclipse.rdf4j.model.BNode;
+import org.eclipse.rdf4j.model.IRI;
+import org.eclipse.rdf4j.model.Literal;
 import org.eclipse.rdf4j.model.Value;
 
 /**
@@ -29,7 +32,7 @@ public interface RDF4JTerm<T extends Value> extends RDFTerm {
 	/**
 	 * Return the RDF4J {@link Value} that this RDFTerm represents.
 	 * 
-	 * @return
+	 * @return The wrapped {@link Value} (e.g. a {@link Literal}, {@link IRI} or {@link BNode}.
 	 */
 	public T asValue();
 }

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/5709ab23/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 2cd64e7..55a8046 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
@@ -54,7 +54,7 @@ import org.eclipse.rdf4j.repository.Repository;
  * <p>
  * The {@link #RDF4JTermFactory()} constructor uses a {@link SimpleValueFactory}
  * to create corresponding RDF4J {@link Value} instances. Alternatively, this
- * factory can be constructed with a {@link ValueFactory} using
+ * factory can be constructed with a different {@link ValueFactory} using
  * {@link #RDF4JTermFactory(ValueFactory)}.
  * <p>
  * {@link #asRDFTerm(Value)} can be used to convert any RDF4J {@link Value} to
@@ -65,13 +65,37 @@ import org.eclipse.rdf4j.repository.Repository;
  * {@link #createGraph()} creates a new Graph backed by {@link LinkedHashModel}.
  * To use other models, see {@link #asRDFTermGraph(Model)}.
  * <p>
+ * To adapt a RDF4J {@link Repository} as a {@link Dataset} or {@link Graph},
+ * use {@link #asRDFTermDataset(Repository)} or
+ * {@link #asRDFTermGraph(Repository)}.
+ * <p>
  * {@link #asTriple(Statement)} can be used to convert a RDF4J {@link Statement}
- * to a Commons RDF {@link Triple}.
+ * to a Commons RDF {@link Triple}, and equivalent {@link #asQuad(Statement)} to
+ * convert a {@link Quad}.
+ * <p>
+ * To convert any {@link Triple} or {@link Quad} to to RDF4J {@link Statement},
+ * use {@link #asStatement(TripleLike)}. This recognises previously converted
+ * {@link RDF4JTriple}s and {@link RDF4JQuad}s without re-converting their
+ * {@link RDF4JTripleLike#asStatement()}.
+ * <p>
+ * Likewise, {@link #asValue(RDFTerm)} can be used to convert any Commons RDF
+ * {@link RDFTerm} to a corresponding RDF4J {@link Value}. This recognises
+ * previously converted {@link RDF4JTerm}s without re-converting their
+ * {@link RDF4JTerm#asValue()}.
  * <p>
- * {@link #asStatement(Triple)} can be used to convert any Commons RDF
- * {@link Triple} to a RDF4J {@link Statement}. <p {@link #asValue(RDFTerm)} can
- * be used to convert any Commons RDF {@link RDFTerm} to a corresponding RDF4J
- * {@link Value}.
+ * For the purpose of {@link BlankNode} equivalence, this factory contains an
+ * internal {@link UUID} salt that is used by adapter methods like
+ * {@link #asQuad(Statement)}, {@link #asTriple(Statement)},
+ * {@link #asRDFTerm(Value)} as well as {@link #createBlankNode(String)}. As
+ * RDF4J {@link BNode} instances from multiple repositories or models may have
+ * the same {@link BNode#getID()}, converting them with the above methods might
+ * cause accidental {@link BlankNode} equivalence. Note that the {@link Graph}
+ * and {@link Dataset} adapter methods like
+ * {@link #asRDFTermDataset(Repository)} and {@link #asRDFTermGraph(Model)}
+ * therefore uses a unique {@link RDF4JTermFactory} internally. An alternative
+ * is to use the static methods {@link #asRDFTerm(Value, UUID)},
+ * {@link #asQuad(Statement, UUID)} or {@link #asTriple(Statement, UUID)} with
+ * a provided {@link UUID} salt.
  * 
  */
 public class RDF4JTermFactory implements RDFTermFactory {
@@ -89,18 +113,26 @@ public class RDF4JTermFactory implements RDFTermFactory {
 	 * {@link org.eclipse.rdf4j.model.Literal}. is converted to a
 	 * {@link org.apache.commons.rdf.api.Literal}
 	 * 
-	 * @param value
-	 * @return
+	 * @param value The RDF4J {@link Value} to convert.
+	 * @param salt
+	 *            A {@link UUID} salt to use for uniquely mapping any
+	 *            {@link BNode}s. The salt should typically be the same for
+	 *            multiple statements in the same {@link Repository} or
+	 *            {@link Model} to ensure {@link BlankNode#equals(Object)} and
+	 *            {@link BlankNode#uniqueReference()} works as intended.
+	 * @return A {@link RDFTerm} that corresponds to the RDF4J value
+	 * @throws IllegalArgumentException if the value is not a BNode, Literal or IRI 
 	 */
-	public static RDF4JTerm<?> asRDFTerm(final org.eclipse.rdf4j.model.Value value, UUID salt) {
+	@SuppressWarnings("unchecked")
+	public static <T extends Value> RDF4JTerm<T> asRDFTerm(final T value, UUID salt) {
 		if (value instanceof BNode) {
-			return new BlankNodeImpl((BNode) value, salt);
+			return (RDF4JTerm<T>) new BlankNodeImpl((BNode) value, salt);
 		}
 		if (value instanceof org.eclipse.rdf4j.model.Literal) {
-			return new LiteralImpl((org.eclipse.rdf4j.model.Literal) value);
+			return (RDF4JTerm<T>) new LiteralImpl((org.eclipse.rdf4j.model.Literal) value);
 		}
 		if (value instanceof org.eclipse.rdf4j.model.IRI) {
-			return new IRIImpl((org.eclipse.rdf4j.model.IRI) value);
+			return (RDF4JTerm<T>) new IRIImpl((org.eclipse.rdf4j.model.IRI) value);
 		}
 		throw new IllegalArgumentException("Value is not a BNode, Literal or IRI: " + value.getClass());
 	}
@@ -109,7 +141,14 @@ public class RDF4JTermFactory implements RDFTermFactory {
 	 * Adapt a RDF4J {@link Statement} as a Commons RDF {@link Triple}.
 	 * 
 	 * @param statement
-	 * @return
+	 *            The statement to convert
+	 * @param salt
+	 *            A {@link UUID} salt to use for uniquely mapping any
+	 *            {@link BNode}s. The salt should typically be the same for
+	 *            multiple statements in the same {@link Repository} or
+	 *            {@link Model} to ensure {@link BlankNode#equals(Object)} and
+	 *            {@link BlankNode#uniqueReference()} works as intended.
+	 * @return A {@link Triple} that corresponds to the RDF4J statement
 	 */
 	public static RDF4JTriple asTriple(final Statement statement, UUID salt) {
 		return new TripleImpl(statement, salt);
@@ -129,8 +168,22 @@ public class RDF4JTermFactory implements RDFTermFactory {
 
 	/**
 	 * Adapt a RDF4J {@link Statement} as a Commons RDF {@link Quad}.
+	 * <p>
+	 * For the purpose of {@link BlankNode} equivalence, this 
+	 * method will use an internal salt UUID that is unique per instance of 
+	 * {@link RDF4JTermFactory}. 
+	 * <p>
+	 * <strong>NOTE:</strong> If combining RDF4J {@link Statement}s
+	 * multiple repositories or models, then their {@link BNode}s 
+	 * may have the same {@link BNode#getID()}, which with this method 
+	 * would become equivalent according to {@link BlankNode#equals(Object)} and
+	 * {@link BlankNode#uniqueReference()}, 
+	 * unless a separate {@link RDF4JTermFactory}
+	 * instance is used per RDF4J repository/model.  
 	 * 
+	 * @see #asQuad(Statement, UUID)
 	 * @param statement
+	 *            The statement to convert
 	 * @return A {@link RDF4JQuad} that is equivalent to the statement
 	 */
 	public RDF4JQuad asQuad(final Statement statement) {
@@ -138,6 +191,25 @@ public class RDF4JTermFactory implements RDFTermFactory {
 	}
 
 	/**
+	 * Adapt a RDF4J {@link Statement} as a Commons RDF {@link Quad}.
+	 *
+	 * @see #asQuad(Statement)
+	 * @param statement
+	 *            The statement to convert
+	 * @param salt
+	 *            A {@link UUID} salt to use for uniquely mapping any
+	 *            {@link BNode}s. The salt should typically be the same for
+	 *            multiple statements in the same {@link Repository} or
+	 *            {@link Model} to ensure {@link BlankNode#equals(Object)} and
+	 *            {@link BlankNode#uniqueReference()} works as intended.
+	 * @return A {@link RDF4JQuad} that is equivalent to the statement
+	 */
+	public static RDF4JQuad asQuad(final Statement statement, UUID salt) {
+		return new QuadImpl(statement, salt);
+	}
+
+	
+	/**
 	 * 
 	 * Adapt a RDF4J {@link Value} as a Commons RDF {@link RDFTerm}.
 	 * <p>
@@ -149,11 +221,24 @@ public class RDF4JTermFactory implements RDFTermFactory {
 	 * {@link org.apache.commons.rdf.api.IRI} and a
 	 * {@link org.eclipse.rdf4j.model.Literal}. is converted to a
 	 * {@link org.apache.commons.rdf.api.Literal}
+	 * <p>
+	 * For the purpose of {@link BlankNode} equivalence, this 
+	 * method will use an internal salt UUID that is unique per instance of 
+	 * {@link RDF4JTermFactory}. 
+	 * <p>
+	 * <strong>NOTE:</strong> If combining RDF4J values from
+	 * multiple repositories or models, then their {@link BNode}s 
+	 * may have the same {@link BNode#getID()}, which with this method 
+	 * would become equivalent according to {@link BlankNode#equals(Object)} and
+	 * {@link BlankNode#uniqueReference()}, 
+	 * unless a separate {@link RDF4JTermFactory}
+	 * instance is used per RDF4J repository/model.  
 	 * 
-	 * @param value
-	 * @return
+	 * @param value The RDF4J {@link Value} to convert.
+	 * @return A {@link RDFTerm} that corresponds to the RDF4J value
+	 * @throws IllegalArgumentException if the value is not a BNode, Literal or IRI 
 	 */
-	public RDF4JTerm<?> asRDFTerm(final org.eclipse.rdf4j.model.Value value) {
+	public <T extends Value> RDF4JTerm<T> asRDFTerm(T value) {
 		return asRDFTerm(value, salt);
 	}
 
@@ -234,6 +319,21 @@ public class RDF4JTermFactory implements RDFTermFactory {
 		return new RepositoryGraphImpl(repository, includeInferred, unionGraph);
 	}
 
+	/**
+	 * Adapt a Commons RDF {@link Triple} or {@link Quad} as a RDF4J
+	 * {@link Statement}.
+	 * <p>
+	 * If the <code>tripleLike</code> argument is an {@link RDF4JTriple} or
+	 * a {@link RDF4JQuad}, then its {@link RDF4JTripleLike#asStatement()} is
+	 * returned as-is. Note that this means that a {@link RDF4JTriple} would
+	 * preserve its {@link Statement#getContext()}, and that any 
+	 * {@link BlankNode}s would be deemed equivalent in RDF4J
+	 * if they have the same {@link BNode#getID()}.
+	 * 
+	 * @param tripleLike
+	 *            A {@link Triple} or {@link Quad} to adapt
+	 * @return A corresponding {@link Statement}
+	 */
 	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
@@ -257,6 +357,18 @@ public class RDF4JTermFactory implements RDFTermFactory {
 
 	/**
 	 * Adapt a RDF4J {@link Statement} as a Commons RDF {@link Triple}.
+	 * <p>
+	 * For the purpose of {@link BlankNode} equivalence, this 
+	 * method will use an internal salt UUID that is unique per instance of 
+	 * {@link RDF4JTermFactory}. 
+	 * <p>
+	 * <strong>NOTE:</strong> If combining RDF4J statements from
+	 * multiple repositories or models, then their {@link BNode}s 
+	 * may have the same {@link BNode#getID()}, which with this method 
+	 * would become equivalent according to {@link BlankNode#equals(Object)} and
+	 * {@link BlankNode#uniqueReference()}, 
+	 * unless a separate {@link RDF4JTermFactory}
+	 * instance is used per RDF4J repository/model.
 	 * 
 	 * @param statement
 	 * @return A {@link RDF4JTriple} that is equivalent to the statement

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/5709ab23/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/package-info.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/package-info.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/package-info.java
new file mode 100644
index 0000000..b8ad947
--- /dev/null
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/package-info.java
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+/**
+ * Commons RDF integration with <a href="http://rdf4j.org/">RDF4J</a>.
+ * <p>
+ * 
+ *
+ */
+package org.apache.commons.rdf.rdf4j;
+
+