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/28 13:50:13 UTC

[01/18] incubator-commonsrdf git commit: COMMONSRDF-39 experimental RDFParser interface

Repository: incubator-commonsrdf
Updated Branches:
  refs/heads/jena-jsonld-rdf4j-integration 6c17d5ed1 -> 549872958


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/10d27cde/simple/src/main/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParser.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParser.java b/simple/src/main/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParser.java
new file mode 100644
index 0000000..8111f09
--- /dev/null
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParser.java
@@ -0,0 +1,542 @@
+/**
+ * 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.experimental;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.function.Consumer;
+
+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.RDFSyntax;
+import org.apache.commons.rdf.api.RDFTermFactory;
+import org.apache.commons.rdf.experimental.RDFParser;
+import org.apache.commons.rdf.simple.SimpleRDFTermFactory;
+
+/**
+ * Abstract RDFParser
+ * <p>
+ * This abstract class keeps the properties in protected fields like
+ * {@link #sourceFile} using {@link Optional}. Some basic checking like
+ * {@link #checkIsAbsolute(IRI)} is performed.
+ * <p>
+ * This class and its subclasses are {@link Cloneable}, immutable and
+ * (therefore) thread-safe - each call to option methods like
+ * {@link #contentType(String)} or {@link #source(IRI)} will return a cloned,
+ * mutated copy.
+ * <p>
+ * By default, parsing is done by the abstract method
+ * {@link #parseSynchronusly()} - which is executed in a cloned snapshot - hence
+ * multiple {@link #parse()} calls are thread-safe. The default {@link #parse()}
+ * uses a thread pool in {@link #threadGroup} - but implementations can override
+ * {@link #parse()} (e.g. because it has its own threading model or use
+ * asynchronous remote execution).
+ */
+public abstract class AbstractRDFParser<T extends AbstractRDFParser<T>> 
+	implements RDFParser, Cloneable {	
+	
+	public static final ThreadGroup threadGroup = new ThreadGroup("Commons RDF parsers");
+	private static final ExecutorService threadpool = Executors.newCachedThreadPool(r -> new Thread(threadGroup, r));
+
+	// Basically only used for creating IRIs
+	private static RDFTermFactory internalRdfTermFactory = new SimpleRDFTermFactory();
+
+	/**
+	 * Get the set {@link RDFTermFactory}, if any.
+	 */
+	public Optional<RDFTermFactory> getRdfTermFactory() {
+		return rdfTermFactory;
+	}
+
+	/**
+	 * Get the set content-type {@link RDFSyntax}, if any.
+	 * <p>
+	 * If this is {@link Optional#isPresent()}, then 
+	 * {@link #getContentType()} contains the 
+	 * value of {@link RDFSyntax#mediaType}. 
+	 */
+	public Optional<RDFSyntax> getContentTypeSyntax() {
+		return contentTypeSyntax;
+	}
+	
+	/**
+	 * Get the set content-type String, if any.
+	 * <p>
+	 * If this is {@link Optional#isPresent()} and 
+	 * is recognized by {@link RDFSyntax#byMediaType(String)}, then
+	 * the corresponding {@link RDFSyntax} is set on 
+	 * {@link #getContentType()}, otherwise that is
+	 * {@link Optional#empty()}. 
+	 */
+	public final Optional<String> getContentType() {
+		return contentType;
+	}
+
+	/**
+	 * Get the target to consume parsed Quads.
+	 * <p>
+	 * From the call to {@link #parseSynchronusly()}, this
+	 * method is always {@link Optional#isPresent()}.
+	 * 
+	 */	
+	public Consumer<Quad> getTarget() {
+		return target;
+	}
+
+	/**
+	 * Get the target dataset as set by {@link #target(Dataset)}.
+	 * <p>
+	 * The return value is {@link Optional#isPresent()} if and only if
+	 * {@link #target(Dataset)} has been set, meaning that the implementation
+	 * may choose to append parsed quads to the {@link Dataset} directly instead
+	 * of relying on the generated {@link #getTarget()} consumer.
+	 * <p>
+	 * If this value is present, then {@link #getTargetGraph()} MUST 
+	 * be {@link Optional#empty()}.
+	 * 
+	 * @return The target Dataset, or {@link Optional#empty()} if another kind of target has been set.
+	 */
+	public Optional<Dataset> getTargetDataset() {
+		return targetDataset;
+	}
+
+	/**
+	 * Get the target graph as set by {@link #target(Graph)}.
+	 * <p>
+	 * The return value is {@link Optional#isPresent()} if and only if
+	 * {@link #target(Graph)} has been set, meaning that the implementation
+	 * may choose to append parsed triples to the {@link Graph} directly instead
+	 * of relying on the generated {@link #getTarget()} consumer.
+	 * <p>
+	 * If this value is present, then {@link #getTargetDataset()} MUST 
+	 * be {@link Optional#empty()}.
+	 * 
+	 * @return The target Graph, or {@link Optional#empty()} if another kind of target has been set.
+	 */	
+	public Optional<Graph>  getTargetGraph() {
+		return targetGraph;
+	}
+	
+	/**
+	 * Get the set base {@link IRI}, if present.
+	 * <p>
+	 * 
+	 */	
+	public Optional<IRI> getBase() {
+		return base;
+	}
+
+	/**
+	 * Get the set source {@link InputStream}.
+	 * <p>
+	 * If this is {@link Optional#isPresent()}, then 
+	 * {@link #getSourceFile()} and {@link #getSourceIri()}
+	 * are {@link Optional#empty()}.
+	 */
+	public Optional<InputStream> getSourceInputStream() {
+		return sourceInputStream;
+	}
+
+	/**
+	 * Get the set source {@link Path}.
+	 * <p>
+	 * If this is {@link Optional#isPresent()}, then 
+	 * {@link #getSourceInputStream()} and {@link #getSourceIri()}
+	 * are {@link Optional#empty()}.
+	 */	
+	public Optional<Path> getSourceFile() {
+		return sourceFile;
+	}
+
+	/**
+	 * Get the set source {@link Path}.
+	 * <p>
+	 * If this is {@link Optional#isPresent()}, then 
+	 * {@link #getSourceInputStream()} and {@link #getSourceInputStream()()}
+	 * are {@link Optional#empty()}.
+	 */		
+	public Optional<IRI> getSourceIri() {
+		return sourceIri;
+	}
+
+
+	private Optional<RDFTermFactory> rdfTermFactory = Optional.empty();
+	private Optional<RDFSyntax> contentTypeSyntax = Optional.empty();
+	private Optional<String> contentType = Optional.empty();
+	private Optional<IRI> base = Optional.empty();
+	private Optional<InputStream> sourceInputStream = Optional.empty();
+	private Optional<Path> sourceFile = Optional.empty();
+	private Optional<IRI> sourceIri = Optional.empty();
+	private Consumer<Quad> target;
+	private Optional<Dataset> targetDataset;
+	private Optional<Graph> targetGraph;
+
+	@SuppressWarnings("unchecked")
+	@Override
+	public T clone() {
+		try {
+			return (T) super.clone();
+		} catch (CloneNotSupportedException e) {
+			throw new RuntimeException(e);
+		}
+	}
+
+	@SuppressWarnings("unchecked")
+	protected T asT() { 
+		return (T) this;
+	}
+	
+	@Override
+	public T rdfTermFactory(RDFTermFactory rdfTermFactory) {
+		AbstractRDFParser<T> c = clone();
+		c.rdfTermFactory = Optional.ofNullable(rdfTermFactory);
+		return c.asT();
+	}
+
+	@Override
+	public T contentType(RDFSyntax rdfSyntax) throws IllegalArgumentException {
+		AbstractRDFParser<T> c = clone();
+		c.contentTypeSyntax = Optional.ofNullable(rdfSyntax);
+		c.contentType = c.contentTypeSyntax.map(syntax -> syntax.mediaType);
+		return c.asT();
+	}
+
+	@Override
+	public T contentType(String contentType) throws IllegalArgumentException {
+		AbstractRDFParser<T> c = clone();
+		c.contentType = Optional.ofNullable(contentType);
+		c.contentTypeSyntax = c.contentType.flatMap(RDFSyntax::byMediaType);
+		return c.asT();
+	}
+
+	@Override
+	public T base(IRI base) {
+		AbstractRDFParser<T> c = clone();
+		c.base = Optional.ofNullable(base);
+		c.base.ifPresent(i -> checkIsAbsolute(i));
+		return c.asT();
+	}
+
+	@Override
+	public T base(String base) throws IllegalArgumentException {
+		return base(internalRdfTermFactory.createIRI(base));
+	}
+
+	@Override
+	public T source(InputStream inputStream) {
+		AbstractRDFParser<T> c = clone();
+		c.resetSource();
+		c.sourceInputStream = Optional.ofNullable(inputStream);
+		return c.asT();
+	}
+
+	@Override
+	public T source(Path file) {
+		AbstractRDFParser<T> c = clone();
+		c.resetSource();
+		c.sourceFile = Optional.ofNullable(file);
+		return c.asT();
+	}
+
+	@Override
+	public T source(IRI iri) {
+		AbstractRDFParser<T> c = clone();
+		c.resetSource();
+		c.sourceIri = Optional.ofNullable(iri);
+		c.sourceIri.ifPresent(i -> checkIsAbsolute(i));
+		return c.asT();
+	}
+
+	@Override
+	public T source(String iri) throws IllegalArgumentException {
+		AbstractRDFParser<T> c = clone();
+		c.resetSource();
+		c.sourceIri = Optional.ofNullable(iri).map(internalRdfTermFactory::createIRI);
+		c.sourceIri.ifPresent(i -> checkIsAbsolute(i));
+		return source(internalRdfTermFactory.createIRI(iri));
+	}
+
+	/**
+	 * Check if an iri is absolute.
+	 * <p>
+	 * Used by {@link #source(String)} and {@link #base(String)}
+	 * 
+	 * @param iri
+	 */
+	protected void checkIsAbsolute(IRI iri) {
+		if (!URI.create(iri.getIRIString()).isAbsolute()) {
+			throw new IllegalArgumentException("IRI is not absolute: " + iri);
+		}
+	}
+
+	/**
+	 * Check that one and only one source is present and valid.
+	 * <p>
+	 * Used by {@link #parse()}.
+	 * <p>
+	 * Subclasses might override this method, e.g. to support other
+	 * source combinations, or to check if the sourceIri is 
+	 * resolvable. 
+	 * 
+	 * @throws IOException If a source file can't be read
+	 */
+	protected void checkSource() throws IOException {
+		if (!sourceFile.isPresent() && !sourceInputStream.isPresent() && !sourceIri.isPresent()) {
+			throw new IllegalStateException("No source has been set");
+		}
+		if (sourceIri.isPresent() && sourceInputStream.isPresent()) {
+			throw new IllegalStateException("Both sourceIri and sourceInputStream have been set");
+		}
+		if (sourceIri.isPresent() && sourceFile.isPresent()) {
+			throw new IllegalStateException("Both sourceIri and sourceFile have been set");
+		}
+		if (sourceInputStream.isPresent() && sourceFile.isPresent()) {
+			throw new IllegalStateException("Both sourceInputStream and sourceFile have been set");
+		}
+		if (sourceFile.isPresent() && !sourceFile.filter(Files::isReadable).isPresent()) {
+			throw new IOException("Can't read file: " + sourceFile);
+		}
+	}
+
+	/**
+	 * Check if base is required.
+	 * 
+	 * @throws IllegalStateException if base is required, but not set.
+	 */
+	protected void checkBaseRequired() {
+		if (!base.isPresent() && sourceInputStream.isPresent()
+				&& !contentTypeSyntax.filter(t -> t == RDFSyntax.NQUADS || t == RDFSyntax.NTRIPLES).isPresent()) {
+			throw new IllegalStateException("base iri required for inputstream source");
+		}
+	}
+
+	/**
+	 * Reset all source* fields to Optional.empty()
+	 * <p>
+	 * Subclasses should override this and call <code>super.resetSource()</code>
+	 * if they need to reset any additional source* fields.
+	 * 
+	 */
+	protected void resetSource() {
+		sourceInputStream = Optional.empty();
+		sourceIri = Optional.empty();
+		sourceFile = Optional.empty();
+	}
+
+
+	/**
+	 * Reset all optional target* fields to Optional.empty()</code>
+	 * <p>
+	 * Note that the consumer set for {@link #getTarget()} is
+	 * NOT reset.
+	 * <p>
+	 * Subclasses should override this and call <code>super.resetTarget()</code>
+	 * if they need to reset any additional target* fields.
+	 * 
+	 */
+	protected void resetTarget() {
+		targetDataset = Optional.empty();
+		targetGraph = Optional.empty();
+	}	
+	
+	/**
+	 * Parse {@link #sourceInputStream}, {@link #sourceFile} or
+	 * {@link #sourceIri}.
+	 * <p>
+	 * One of the source fields MUST be present, as checked by {@link #checkSource()}.
+	 * <p>
+	 * {@link #checkBaseRequired()} is called to verify if {@link #getBase()} is required.
+	 * 
+	 * @throws IOException If the source could not be read 
+	 * @throws RDFParseException If the source could not be parsed (e.g. a .ttl file was not valid Turtle)
+	 */
+	protected abstract void parseSynchronusly() throws IOException, RDFParseException;
+
+	/**
+	 * Prepare a clone of this RDFParser which have been checked and
+	 * completed.
+	 * <p>
+	 * The returned clone will always have
+	 * {@link #getTarget()} and {@link #getRdfTermFactory()} present.
+	 * <p>
+	 * If the {@link #getSourceFile()} is present, but the 
+	 * {@link #getBase()} is not present, the base will be set to the
+	 * <code>file:///</code> IRI for the Path's real path (e.g. resolving any 
+	 * symbolic links).  
+	 *  
+	 * @return A completed and checked clone of this RDFParser
+	 * @throws IOException If the source was not accessible (e.g. a file was not found)
+	 * @throws IllegalStateException If the parser was not in a compatible setting (e.g. contentType was an invalid string) 
+	 */
+	protected T prepareForParsing() throws IOException, IllegalStateException {
+		checkSource();
+		checkBaseRequired();		
+		checkContentType();
+		checkTarget();
+
+		// We'll make a clone of our current state which will be passed to
+		// parseSynchronously()
+		AbstractRDFParser<T> c = clone();
+
+		// Use a fresh SimpleRDFTermFactory for each parse
+		if (!c.rdfTermFactory.isPresent()) {
+			c.rdfTermFactory = Optional.of(createRDFTermFactory());
+		}
+		// sourceFile, but no base? Let's follow any symlinks and use
+		// the file:/// URI
+		if (c.sourceFile.isPresent() && !c.base.isPresent()) {
+			URI baseUri = c.sourceFile.get().toRealPath().toUri();
+			c.base = Optional.of(internalRdfTermFactory.createIRI(baseUri.toString()));
+		}
+
+		return c.asT();
+	}
+	
+	/**
+	 * Subclasses can override this method to check the target is 
+	 * valid.
+	 * <p>
+	 * The default implementation throws an IllegalStateException if the 
+	 * target has not been set.
+	 */
+	protected void checkTarget() {
+		if (target == null) {
+			throw new IllegalStateException("target has not been set");
+		}
+		if (targetGraph.isPresent() && targetDataset.isPresent()) {
+			// This should not happen as each target(..) method resets the optionals
+			throw new IllegalStateException("targetGraph and targetDataset can't both be set");
+		}
+	}
+
+	/**
+	 * Subclasses can override this method to check compatibility with the
+	 * contentType setting.
+	 * 
+	 * @throws IllegalStateException
+	 *             if the {@link #getContentType()} or
+	 *             {@link #getContentTypeSyntax()} is not compatible or invalid
+	 */
+	protected void checkContentType() throws IllegalStateException {
+	}
+
+	/**
+	 * Guess RDFSyntax from a local file's extension.
+	 * <p>
+	 * This method can be used by subclasses if {@link #getContentType()} is not
+	 * present and {@link #getSourceFile()} is set.
+	 * 
+	 * @param path Path which extension should be checked
+	 * @return The {@link RDFSyntax} which has a matching {@link RDFSyntax#fileExtension}, 
+	 * 	otherwise {@link Optional#empty()}. 
+	 */
+	protected static Optional<RDFSyntax> guessRDFSyntax(Path path) {
+			return fileExtension(path).flatMap(RDFSyntax::byFileExtension);
+	}
+
+	/**
+	 * Return the file extension of a Path - if any.
+	 * <p>
+	 * The returned file extension includes the leading <code>.</code>
+	 * <p>
+	 * Note that this only returns the last extension, e.g. the 
+	 * file extension for <code>archive.tar.gz</code> would be <code>.gz</code>
+	 * 
+	 * @param path Path which filename might contain an extension
+	 * @return File extension (including the leading <code>.</code>, 
+	 * 	or {@link Optional#empty()} if the path has no extension
+	 */
+	private static Optional<String> fileExtension(Path path) {
+		Path fileName = path.getFileName();
+		if (fileName == null) { 
+			return Optional.empty();
+		}
+		String filenameStr = fileName.toString();
+		int last = filenameStr.lastIndexOf(".");
+		if (last > -1) { 
+			return Optional.of(filenameStr.substring(last));				
+		}
+		return Optional.empty();
+	}
+	
+
+	/**
+	 * Create a new {@link RDFTermFactory} for a parse session.
+	 * <p>
+	 * This is called by {@link #parse()} to set 
+	 * {@link #rdfTermFactory(RDFTermFactory)} if it is
+	 * {@link Optional#empty()}.
+	 * <p>
+	 * As parsed blank nodes might be made with 
+	 * {@link RDFTermFactory#createBlankNode(String)}, 
+	 * each call to this method SHOULD return 
+	 * a new RDFTermFactory instance.
+	 * 
+	 * @return A new {@link RDFTermFactory}
+	 */
+	protected RDFTermFactory createRDFTermFactory() {
+		return new SimpleRDFTermFactory();
+	}
+
+	@Override
+	public Future<ParseResult> parse() throws IOException, IllegalStateException {
+		final AbstractRDFParser<T> c = prepareForParsing();
+		return threadpool.submit(() -> {
+			c.parseSynchronusly();
+			return null;
+		});
+	}
+
+	@Override
+	public T target(Consumer<Quad> consumer) {
+		AbstractRDFParser<T> c = clone();
+		c.resetTarget();
+		c.target = consumer;
+		return c.asT();
+	}
+	
+	@Override
+	public T target(Dataset dataset) {
+		@SuppressWarnings({ "rawtypes", "unchecked" })
+		AbstractRDFParser<T> c = (AbstractRDFParser) RDFParser.super.target(dataset);
+		c.resetTarget();
+		c.targetDataset = Optional.of(dataset);
+		return c.asT();
+	}
+	
+	@Override
+	public T target(Graph graph) {
+		@SuppressWarnings({ "rawtypes", "unchecked" }) // super calls our .clone()
+		AbstractRDFParser<T> c = (AbstractRDFParser) RDFParser.super.target(graph);
+		c.resetTarget();
+		c.targetGraph = Optional.of(graph);
+		return c.asT();
+	}
+	
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/10d27cde/simple/src/main/java/org/apache/commons/rdf/simple/experimental/RDFParseException.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/RDFParseException.java b/simple/src/main/java/org/apache/commons/rdf/simple/experimental/RDFParseException.java
new file mode 100644
index 0000000..cb3ad82
--- /dev/null
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/experimental/RDFParseException.java
@@ -0,0 +1,50 @@
+/**
+ * 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.experimental;
+
+import org.apache.commons.rdf.experimental.RDFParser;
+
+public class RDFParseException extends Exception {
+	private static final long serialVersionUID = 5427752643780702976L;
+	private RDFParser builder;
+
+	public RDFParseException(RDFParser builder) {
+		super();
+		this.builder = builder;
+	}
+
+	public RDFParseException(RDFParser builder, String message, Throwable cause) {
+		super(message, cause);
+		this.builder = builder;
+	}
+
+	public RDFParseException(RDFParser builder, String message) {
+		super(message);
+		this.builder = builder;
+	}
+
+	public RDFParseException(RDFParser builder, Throwable cause) {
+		super(cause);
+		this.builder = builder;
+	}
+
+	public RDFParser getRDFParserBuilder() {
+		return builder;
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/10d27cde/simple/src/main/java/org/apache/commons/rdf/simple/experimental/package-info.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/package-info.java b/simple/src/main/java/org/apache/commons/rdf/simple/experimental/package-info.java
new file mode 100644
index 0000000..5196f42
--- /dev/null
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/experimental/package-info.java
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+/**
+ * Experimental Commons RDF Simple implementations.
+ * <p>
+ * Classes in this package should be considered <strong>at
+ * risk</strong>; they might change or be removed in the next minor update of
+ * Commons RDF.
+ * <p>
+ * When a class has stabilized, it will move to the
+ * {@link org.apache.commons.rdf.simple} package.
+ * <p>
+ * <ul>
+ * <li>{@link AbstractRDFParser} - an abstract helper class
+ * for implementations of 
+ * {@link org.apache.commons.rdf.api.experimental.RDFParser}.</li>
+ * </ul>
+ */
+package org.apache.commons.rdf.simple.experimental;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/10d27cde/simple/src/test/java/org/apache/commons/rdf/simple/AbstractRDFParserBuilderTest.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/AbstractRDFParserBuilderTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/AbstractRDFParserBuilderTest.java
deleted file mode 100644
index 439bacb..0000000
--- a/simple/src/test/java/org/apache/commons/rdf/simple/AbstractRDFParserBuilderTest.java
+++ /dev/null
@@ -1,253 +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.simple;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.concurrent.TimeUnit;
-
-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.RDFParserBuilder;
-import org.apache.commons.rdf.api.RDFSyntax;
-import org.apache.commons.rdf.api.RDFTerm;
-import org.apache.commons.rdf.api.RDFTermFactory;
-import org.apache.commons.rdf.api.Triple;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
-public class AbstractRDFParserBuilderTest {
-
-	private RDFTermFactory factory = new SimpleRDFTermFactory();
-	
-	private DummyRDFParserBuilder dummyParser = new DummyRDFParserBuilder();
-	private Path testNt;
-	private Path testTtl;
-	private Path testXml;
-
-	@Before
-	public void createTempFile() throws IOException {
-		testNt = Files.createTempFile("test", ".nt");
-		testTtl = Files.createTempFile("test", ".ttl");
-		testXml = Files.createTempFile("test", ".xml");
-
-		// No need to populate the files as the dummy parser
-		// doesn't actually read anything
-	}
-
-	@After
-	public void deleteTempFiles() throws IOException {
-		Files.deleteIfExists(testNt);
-		Files.deleteIfExists(testTtl);
-		Files.deleteIfExists(testXml);
-	}
-
-	@Test
-	public void guessRDFSyntax() throws Exception {
-		assertEquals(RDFSyntax.NTRIPLES, AbstractRDFParserBuilder.guessRDFSyntax(testNt).get());
-		assertEquals(RDFSyntax.TURTLE, AbstractRDFParserBuilder.guessRDFSyntax(testTtl).get());
-		assertFalse(AbstractRDFParserBuilder.guessRDFSyntax(testXml).isPresent());
-	}
-
-	private void checkGraph(Graph g) throws Exception {				
-		assertTrue(g.size() > 0);		
-		IRI greeting = factory.createIRI("http://example.com/greeting");	
-		// Should only have parsed once!
-		assertEquals(1, g.getTriples(null, greeting, null).count());
-		Triple triple = g.getTriples(null, greeting, null).findAny().get();
-		assertTrue(triple.getSubject() instanceof IRI);
-		IRI parsing = (IRI) triple.getSubject();
-		assertTrue(parsing.getIRIString().startsWith("urn:uuid:"));
-
-		assertEquals("http://example.com/greeting", triple.getPredicate().getIRIString());
-
-		assertTrue(triple.getObject() instanceof Literal);
-		Literal literal = (Literal) triple.getObject();
-		assertEquals("Hello world", literal.getLexicalForm());
-		assertFalse(literal.getLanguageTag().isPresent());
-		assertEquals(Types.XSD_STRING, literal.getDatatype());
-		
-		// Check uniqueness of properties that are always present
-		assertEquals(1, 
-				g.getTriples(null, factory.createIRI("http://example.com/source"), null).count());
-		
-		// Check optional properties that are unique
-		assertTrue(2 > g.getTriples(null, factory.createIRI("http://example.com/base"), null).count());
-		assertTrue(2 > g.getTriples(null, factory.createIRI("http://example.com/contentType"), null).count());
-		assertTrue(2 > g.getTriples(null, factory.createIRI("http://example.com/contentTypeSyntax"), null).count());
-	}
-	
-	@Test
-	public void parseFile() throws Exception {	
-		Graph g = factory.createGraph();
-		RDFParserBuilder parser = dummyParser.source(testNt).target(g);
-		parser.parse().get(5, TimeUnit.SECONDS);
-		checkGraph(g);
-		// FIXME: this could potentially break if the equivalent of /tmp includes
-		// international characters
-		assertEquals("<" + testNt.toUri().toString() + ">", firstPredicate(g, "source"));
-		// Should be set to the file path
-		assertEquals("<" + testNt.toUri().toString() + ">", firstPredicate(g, "base"));		
-
-		// Should NOT have guessed the content type
-		assertNull(firstPredicate(g, "contentType"));
-		assertNull(firstPredicate(g, "contentTypeSyntax"));
-	}
-
-
-	@Test
-	public void parseNoSource() throws Exception {
-		thrown.expect(IllegalStateException.class);
-		dummyParser.parse();		
-	}
-	
-	@Test
-	public void parseBaseAndContentTypeNoSource() throws Exception {
-		// Can set the other options, even without source()
-		IRI base = dummyParser.createRDFTermFactory().createIRI("http://www.example.org/test.rdf");
-		RDFParserBuilder parser = dummyParser.base(base).contentType(RDFSyntax.RDFXML);
-		thrown.expect(IllegalStateException.class);
-		thrown.expectMessage("No source has been set");
-		// but .parse() should fail
-		parser.parse();		
-	}
-	
-	@Test
-	public void parseFileMissing() throws Exception {
-		Files.delete(testNt);
-		// This should not fail yet
-		RDFParserBuilder parser = dummyParser.source(testNt);
-		// but here:
-		thrown.expect(IOException.class);
-		parser.parse();		
-	}
-
-	
-	@Test
-	public void parseFileContentType() throws Exception {
-		Graph g = factory.createGraph();
-		RDFParserBuilder parser = dummyParser
-				.source(testNt)
-				.contentType(RDFSyntax.NTRIPLES)
-				.target(g);
-		parser.parse().get(5, TimeUnit.SECONDS);
-		checkGraph(g);
-		// FIXME: this could potentially break if the equivalent of /tmp includes
-		// international characters
-		assertEquals("<" + testNt.toUri().toString() + ">", firstPredicate(g, "source"));
-		assertEquals("<" + testNt.toUri().toString() + ">", firstPredicate(g, "base"));		
-		assertEquals("\"NTRIPLES\"", firstPredicate(g, "contentTypeSyntax"));
-		assertEquals("\"application/n-triples\"", firstPredicate(g, "contentType"));
-	}
-
-	private String firstPredicate(Graph g, String pred) {
-		return g.getTriples(null, factory.createIRI("http://example.com/" + pred), null)
-				.map(Triple::getObject).map(RDFTerm::ntriplesString).findAny().orElse(null);
-	}
-
-
-	@Rule
-	public ExpectedException thrown = ExpectedException.none();
-	
-	@Test
-	public void parseInputStreamFailsIfBaseMissing() throws Exception {
-		InputStream inputStream = new ByteArrayInputStream(new byte[0]);
-		// Should not fail at this point
-		RDFParserBuilder parser = dummyParser.source(inputStream);
-		// but here:
-		thrown.expect(IllegalStateException.class);
-		thrown.expectMessage("base iri required for inputstream source");
-		parser.parse();
-	}
-
-	@Test
-	public void parseInputStreamWithBase() throws Exception {
-		InputStream inputStream = new ByteArrayInputStream(new byte[0]);
-		IRI base = dummyParser.createRDFTermFactory().createIRI("http://www.example.org/test.rdf");
-		Graph g = factory.createGraph();
-		RDFParserBuilder parser = dummyParser.source(inputStream).base(base).target(g);		
-		parser.parse().get(5, TimeUnit.SECONDS);
-		checkGraph(g);
-		assertEquals("<http://www.example.org/test.rdf>", firstPredicate(g, "base"));
-		// in our particular debug output, 
-		// bnode source indicates InputStream 
-		assertTrue(firstPredicate(g, "source").startsWith("_:"));
-		assertNull(firstPredicate(g, "contentType"));
-		assertNull(firstPredicate(g, "contentTypeSyntax"));
-	}
-	
-	@Test
-	public void parseInputStreamWithNQuads() throws Exception {
-		InputStream inputStream = new ByteArrayInputStream(new byte[0]);
-		Graph g = factory.createGraph();
-		RDFParserBuilder parser = dummyParser.source(inputStream).contentType(RDFSyntax.NQUADS).target(g);		
-		parser.parse().get(5, TimeUnit.SECONDS);
-		checkGraph(g);
-		assertNull(firstPredicate(g, "base"));
-		// in our particular debug output, 
-		// bnode source indicates InputStream 
-		assertTrue(firstPredicate(g, "source").startsWith("_:"));
-		assertEquals("\"application/n-quads\"", firstPredicate(g, "contentType"));
-		assertEquals("\"NQUADS\"", firstPredicate(g, "contentTypeSyntax"));
-	}	
-
-	@Test
-	public void parseIRI() throws Exception {
-		IRI iri = dummyParser.createRDFTermFactory().createIRI("http://www.example.net/test.ttl");
-		Graph g = factory.createGraph();
-		RDFParserBuilder parser = dummyParser.source(iri).target(g);		
-		parser.parse().get(5, TimeUnit.SECONDS);
-		checkGraph(g);
-		assertEquals("<http://www.example.net/test.ttl>", firstPredicate(g, "source"));
-		// No base - assuming the above IRI is always 
-		// the base would break server-supplied base from 
-		// any HTTP Location redirects and  Content-Location header
-		assertNull(firstPredicate(g, "base"));
-		// ".ttl" in IRI string does not imply any content type
-		assertNull(firstPredicate(g, "contentType"));
-		assertNull(firstPredicate(g, "contentTypeSyntax"));
-		
-	}
-	
-	@Test
-	public void parseIRIBaseContentType() throws Exception {
-		IRI iri = dummyParser.createRDFTermFactory().createIRI("http://www.example.net/test.ttl");
-		Graph g = factory.createGraph();
-		RDFParserBuilder parser = dummyParser.source(iri).base(iri).contentType(RDFSyntax.TURTLE).target(g);
-		parser.parse().get(5, TimeUnit.SECONDS);
-		checkGraph(g);
-		assertEquals("<http://www.example.net/test.ttl>", firstPredicate(g, "source"));
-		assertEquals("<http://www.example.net/test.ttl>", firstPredicate(g, "base"));
-		assertEquals("\"TURTLE\"", firstPredicate(g, "contentTypeSyntax"));
-		assertEquals("\"text/turtle\"", firstPredicate(g, "contentType"));
-	}
-
-	
-}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/10d27cde/simple/src/test/java/org/apache/commons/rdf/simple/DummyRDFParserBuilder.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/DummyRDFParserBuilder.java b/simple/src/test/java/org/apache/commons/rdf/simple/DummyRDFParserBuilder.java
index baf9768..683ef7b 100644
--- a/simple/src/test/java/org/apache/commons/rdf/simple/DummyRDFParserBuilder.java
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/DummyRDFParserBuilder.java
@@ -23,18 +23,20 @@ import java.util.function.Consumer;
 
 import org.apache.commons.rdf.api.IRI;
 import org.apache.commons.rdf.api.Quad;
-import org.apache.commons.rdf.api.RDFParserBuilder;
 import org.apache.commons.rdf.api.RDFTermFactory;
+import org.apache.commons.rdf.experimental.RDFParser;
+import org.apache.commons.rdf.simple.experimental.AbstractRDFParser;
+import org.apache.commons.rdf.simple.experimental.RDFParseException;
 
 /** 
- * For test purposes - a {@link RDFParserBuilder} that inserts information
+ * For test purposes - a {@link RDFParser} that inserts information
  * about what it has been asked to parse instead of actually parsing anything.
  * <p>
  * This always insert at least the triple equivalent to:
  * <pre>
  *    <urn:uuid:b7ac3fcc-4d86-4d28-8358-a1cd094974a6> <http://example.com/greeting> "Hello world" .
  * </pre>
- * Additional triples match the corresponding getter in AbstractRDFParserBuilder,
+ * Additional triples match the corresponding getter in AbstractRDFParser,
  * e.g.:
  * <pre>
  *   <urn:uuid:b7ac3fcc-4d86-4d28-8358-a1cd094974a6> <http://example.com/base> <http://www.example.org/> .
@@ -43,7 +45,7 @@ import org.apache.commons.rdf.api.RDFTermFactory;
  * 
  *
  */
-public class DummyRDFParserBuilder extends AbstractRDFParserBuilder<DummyRDFParserBuilder> {
+public class DummyRDFParserBuilder extends AbstractRDFParser<DummyRDFParserBuilder> {
 	
 	@Override
 	protected void parseSynchronusly() throws IOException, IllegalStateException, RDFParseException {		
@@ -57,7 +59,7 @@ public class DummyRDFParserBuilder extends AbstractRDFParserBuilder<DummyRDFPars
 		t.accept(factory.createQuad(null, parsing, factory.createIRI("http://example.com/greeting"), 
 				factory.createLiteral("Hello world")));
 		
-		// Now we'll expose the finalized AbstractRDFParserBuilder settings
+		// Now we'll expose the finalized AbstractRDFParser settings
 		// so they can be inspected by the junit test
 
 		if (getSourceIri().isPresent()) {

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/10d27cde/simple/src/test/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParserTest.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParserTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParserTest.java
new file mode 100644
index 0000000..f263029
--- /dev/null
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParserTest.java
@@ -0,0 +1,256 @@
+/**
+ * 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.experimental;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.concurrent.TimeUnit;
+
+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.RDFSyntax;
+import org.apache.commons.rdf.api.RDFTerm;
+import org.apache.commons.rdf.api.RDFTermFactory;
+import org.apache.commons.rdf.api.Triple;
+import org.apache.commons.rdf.experimental.RDFParser;
+import org.apache.commons.rdf.simple.DummyRDFParserBuilder;
+import org.apache.commons.rdf.simple.SimpleRDFTermFactory;
+import org.apache.commons.rdf.simple.Types;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+public class AbstractRDFParserTest {
+
+	private RDFTermFactory factory = new SimpleRDFTermFactory();
+	
+	private DummyRDFParserBuilder dummyParser = new DummyRDFParserBuilder();
+	private Path testNt;
+	private Path testTtl;
+	private Path testXml;
+
+	@Before
+	public void createTempFile() throws IOException {
+		testNt = Files.createTempFile("test", ".nt");
+		testTtl = Files.createTempFile("test", ".ttl");
+		testXml = Files.createTempFile("test", ".xml");
+
+		// No need to populate the files as the dummy parser
+		// doesn't actually read anything
+	}
+
+	@After
+	public void deleteTempFiles() throws IOException {
+		Files.deleteIfExists(testNt);
+		Files.deleteIfExists(testTtl);
+		Files.deleteIfExists(testXml);
+	}
+
+	@Test
+	public void guessRDFSyntax() throws Exception {
+		assertEquals(RDFSyntax.NTRIPLES, AbstractRDFParser.guessRDFSyntax(testNt).get());
+		assertEquals(RDFSyntax.TURTLE, AbstractRDFParser.guessRDFSyntax(testTtl).get());
+		assertFalse(AbstractRDFParser.guessRDFSyntax(testXml).isPresent());
+	}
+
+	private void checkGraph(Graph g) throws Exception {				
+		assertTrue(g.size() > 0);		
+		IRI greeting = factory.createIRI("http://example.com/greeting");	
+		// Should only have parsed once!
+		assertEquals(1, g.getTriples(null, greeting, null).count());
+		Triple triple = g.getTriples(null, greeting, null).findAny().get();
+		assertTrue(triple.getSubject() instanceof IRI);
+		IRI parsing = (IRI) triple.getSubject();
+		assertTrue(parsing.getIRIString().startsWith("urn:uuid:"));
+
+		assertEquals("http://example.com/greeting", triple.getPredicate().getIRIString());
+
+		assertTrue(triple.getObject() instanceof Literal);
+		Literal literal = (Literal) triple.getObject();
+		assertEquals("Hello world", literal.getLexicalForm());
+		assertFalse(literal.getLanguageTag().isPresent());
+		assertEquals(Types.XSD_STRING, literal.getDatatype());
+		
+		// Check uniqueness of properties that are always present
+		assertEquals(1, 
+				g.getTriples(null, factory.createIRI("http://example.com/source"), null).count());
+		
+		// Check optional properties that are unique
+		assertTrue(2 > g.getTriples(null, factory.createIRI("http://example.com/base"), null).count());
+		assertTrue(2 > g.getTriples(null, factory.createIRI("http://example.com/contentType"), null).count());
+		assertTrue(2 > g.getTriples(null, factory.createIRI("http://example.com/contentTypeSyntax"), null).count());
+	}
+	
+	@Test
+	public void parseFile() throws Exception {	
+		Graph g = factory.createGraph();
+		RDFParser parser = dummyParser.source(testNt).target(g);
+		parser.parse().get(5, TimeUnit.SECONDS);
+		checkGraph(g);
+		// FIXME: this could potentially break if the equivalent of /tmp includes
+		// international characters
+		assertEquals("<" + testNt.toUri().toString() + ">", firstPredicate(g, "source"));
+		// Should be set to the file path
+		assertEquals("<" + testNt.toUri().toString() + ">", firstPredicate(g, "base"));		
+
+		// Should NOT have guessed the content type
+		assertNull(firstPredicate(g, "contentType"));
+		assertNull(firstPredicate(g, "contentTypeSyntax"));
+	}
+
+
+	@Test
+	public void parseNoSource() throws Exception {
+		thrown.expect(IllegalStateException.class);
+		dummyParser.parse();		
+	}
+	
+	@Test
+	public void parseBaseAndContentTypeNoSource() throws Exception {
+		// Can set the other options, even without source()
+		IRI base = dummyParser.createRDFTermFactory().createIRI("http://www.example.org/test.rdf");
+		RDFParser parser = dummyParser.base(base).contentType(RDFSyntax.RDFXML);
+		thrown.expect(IllegalStateException.class);
+		thrown.expectMessage("No source has been set");
+		// but .parse() should fail
+		parser.parse();		
+	}
+	
+	@Test
+	public void parseFileMissing() throws Exception {
+		Files.delete(testNt);
+		// This should not fail yet
+		RDFParser parser = dummyParser.source(testNt);
+		// but here:
+		thrown.expect(IOException.class);
+		parser.parse();		
+	}
+
+	
+	@Test
+	public void parseFileContentType() throws Exception {
+		Graph g = factory.createGraph();
+		RDFParser parser = dummyParser
+				.source(testNt)
+				.contentType(RDFSyntax.NTRIPLES)
+				.target(g);
+		parser.parse().get(5, TimeUnit.SECONDS);
+		checkGraph(g);
+		// FIXME: this could potentially break if the equivalent of /tmp includes
+		// international characters
+		assertEquals("<" + testNt.toUri().toString() + ">", firstPredicate(g, "source"));
+		assertEquals("<" + testNt.toUri().toString() + ">", firstPredicate(g, "base"));		
+		assertEquals("\"NTRIPLES\"", firstPredicate(g, "contentTypeSyntax"));
+		assertEquals("\"application/n-triples\"", firstPredicate(g, "contentType"));
+	}
+
+	private String firstPredicate(Graph g, String pred) {
+		return g.getTriples(null, factory.createIRI("http://example.com/" + pred), null)
+				.map(Triple::getObject).map(RDFTerm::ntriplesString).findAny().orElse(null);
+	}
+
+
+	@Rule
+	public ExpectedException thrown = ExpectedException.none();
+	
+	@Test
+	public void parseInputStreamFailsIfBaseMissing() throws Exception {
+		InputStream inputStream = new ByteArrayInputStream(new byte[0]);
+		// Should not fail at this point
+		RDFParser parser = dummyParser.source(inputStream);
+		// but here:
+		thrown.expect(IllegalStateException.class);
+		thrown.expectMessage("base iri required for inputstream source");
+		parser.parse();
+	}
+
+	@Test
+	public void parseInputStreamWithBase() throws Exception {
+		InputStream inputStream = new ByteArrayInputStream(new byte[0]);
+		IRI base = dummyParser.createRDFTermFactory().createIRI("http://www.example.org/test.rdf");
+		Graph g = factory.createGraph();
+		RDFParser parser = dummyParser.source(inputStream).base(base).target(g);		
+		parser.parse().get(5, TimeUnit.SECONDS);
+		checkGraph(g);
+		assertEquals("<http://www.example.org/test.rdf>", firstPredicate(g, "base"));
+		// in our particular debug output, 
+		// bnode source indicates InputStream 
+		assertTrue(firstPredicate(g, "source").startsWith("_:"));
+		assertNull(firstPredicate(g, "contentType"));
+		assertNull(firstPredicate(g, "contentTypeSyntax"));
+	}
+	
+	@Test
+	public void parseInputStreamWithNQuads() throws Exception {
+		InputStream inputStream = new ByteArrayInputStream(new byte[0]);
+		Graph g = factory.createGraph();
+		RDFParser parser = dummyParser.source(inputStream).contentType(RDFSyntax.NQUADS).target(g);		
+		parser.parse().get(5, TimeUnit.SECONDS);
+		checkGraph(g);
+		assertNull(firstPredicate(g, "base"));
+		// in our particular debug output, 
+		// bnode source indicates InputStream 
+		assertTrue(firstPredicate(g, "source").startsWith("_:"));
+		assertEquals("\"application/n-quads\"", firstPredicate(g, "contentType"));
+		assertEquals("\"NQUADS\"", firstPredicate(g, "contentTypeSyntax"));
+	}	
+
+	@Test
+	public void parseIRI() throws Exception {
+		IRI iri = dummyParser.createRDFTermFactory().createIRI("http://www.example.net/test.ttl");
+		Graph g = factory.createGraph();
+		RDFParser parser = dummyParser.source(iri).target(g);		
+		parser.parse().get(5, TimeUnit.SECONDS);
+		checkGraph(g);
+		assertEquals("<http://www.example.net/test.ttl>", firstPredicate(g, "source"));
+		// No base - assuming the above IRI is always 
+		// the base would break server-supplied base from 
+		// any HTTP Location redirects and  Content-Location header
+		assertNull(firstPredicate(g, "base"));
+		// ".ttl" in IRI string does not imply any content type
+		assertNull(firstPredicate(g, "contentType"));
+		assertNull(firstPredicate(g, "contentTypeSyntax"));
+		
+	}
+	
+	@Test
+	public void parseIRIBaseContentType() throws Exception {
+		IRI iri = dummyParser.createRDFTermFactory().createIRI("http://www.example.net/test.ttl");
+		Graph g = factory.createGraph();
+		RDFParser parser = dummyParser.source(iri).base(iri).contentType(RDFSyntax.TURTLE).target(g);
+		parser.parse().get(5, TimeUnit.SECONDS);
+		checkGraph(g);
+		assertEquals("<http://www.example.net/test.ttl>", firstPredicate(g, "source"));
+		assertEquals("<http://www.example.net/test.ttl>", firstPredicate(g, "base"));
+		assertEquals("\"TURTLE\"", firstPredicate(g, "contentTypeSyntax"));
+		assertEquals("\"text/turtle\"", firstPredicate(g, "contentType"));
+	}
+
+	
+}



[06/18] incubator-commonsrdf git commit: COMMONSRDF-33 Rename implementations to Jena*Impl

Posted by st...@apache.org.
COMMONSRDF-33 Rename implementations to Jena*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/c52979ba
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/c52979ba
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/c52979ba

Branch: refs/heads/jena-jsonld-rdf4j-integration
Commit: c52979ba57ce5acda06151030040986b19b1792a
Parents: 4416acc
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Sep 28 14:25:47 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Sep 28 14:25:47 2016 +0100

----------------------------------------------------------------------
 .../commons/rdf/jena/JenaRDFTermFactory.java    |   2 +-
 .../rdf/jena/impl/AbstractJenaRDFTerm.java      |  47 +++++
 .../commons/rdf/jena/impl/AbstractRDFTerm.java  |  47 -----
 .../apache/commons/rdf/jena/impl/AnyImpl.java   |  54 ------
 .../commons/rdf/jena/impl/BlankNodeImpl.java    |  61 ------
 .../commons/rdf/jena/impl/DatasetImpl.java      | 187 -------------------
 .../rdf/jena/impl/GeneralizedQuadImpl.java      | 136 --------------
 .../apache/commons/rdf/jena/impl/GraphImpl.java | 154 ---------------
 .../apache/commons/rdf/jena/impl/IRIImpl.java   |  61 ------
 .../commons/rdf/jena/impl/JenaAnyImpl.java      |  54 ++++++
 .../rdf/jena/impl/JenaBlankNodeImpl.java        |  61 ++++++
 .../commons/rdf/jena/impl/JenaDatasetImpl.java  | 187 +++++++++++++++++++
 .../commons/rdf/jena/impl/JenaFactory.java      |  52 +++---
 .../rdf/jena/impl/JenaGeneralizedQuad.java      | 136 ++++++++++++++
 .../commons/rdf/jena/impl/JenaGraphImpl.java    | 154 +++++++++++++++
 .../commons/rdf/jena/impl/JenaIRIImpl.java      |  61 ++++++
 .../commons/rdf/jena/impl/JenaLiteralImpl.java  |  73 ++++++++
 .../commons/rdf/jena/impl/JenaQuadImpl.java     |  66 +++++++
 .../commons/rdf/jena/impl/JenaTripleImpl.java   |  67 +++++++
 .../commons/rdf/jena/impl/JenaVariableImpl.java |  64 +++++++
 .../commons/rdf/jena/impl/LiteralImpl.java      |  73 --------
 .../apache/commons/rdf/jena/impl/QuadImpl.java  |  66 -------
 .../commons/rdf/jena/impl/TripleImpl.java       |  67 -------
 .../commons/rdf/jena/impl/VariableImpl.java     |  64 -------
 .../commons/rdf/jena/TestRDFParserBuilder.java  |   5 +-
 25 files changed, 1000 insertions(+), 999 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/c52979ba/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFTermFactory.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFTermFactory.java b/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFTermFactory.java
index ec84c0a..7359acb 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFTermFactory.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFTermFactory.java
@@ -681,7 +681,7 @@ public final class JenaRDFTermFactory implements RDFTermFactory {
 			return null;
 		}
 		if (term instanceof JenaRDFTerm)
-			// TODO: What if it's a BlankNodeImpl with
+			// TODO: What if it's a JenaBlankNodeImpl with
 			// a different salt? Do we need to rewrite the
 			// jena blanknode identifier?
 			return ((JenaRDFTerm) term).asJenaNode();

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/c52979ba/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractJenaRDFTerm.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractJenaRDFTerm.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractJenaRDFTerm.java
new file mode 100644
index 0000000..9c0d7ec
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractJenaRDFTerm.java
@@ -0,0 +1,47 @@
+/**
+ * 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.jena.impl;
+
+import org.apache.commons.rdf.api.RDFTerm;
+import org.apache.commons.rdf.jena.JenaRDFTerm;
+import org.apache.jena.graph.Node;
+import org.apache.jena.riot.out.NodeFmtLib;
+
+class AbstractJenaRDFTerm implements JenaRDFTerm, RDFTerm {
+	private Node node;
+	// static private PrefixMapping empty = new PrefixMappingImpl() ;
+
+	protected AbstractJenaRDFTerm(Node node) {
+		this.node = node;
+	}
+
+	@Override
+	public Node asJenaNode() {
+		return node;
+	}
+
+	public String ntriplesString() {
+		return NodeFmtLib.str(node);
+	}
+
+	@Override
+	public String toString() {
+		return ntriplesString();
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/c52979ba/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractRDFTerm.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractRDFTerm.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractRDFTerm.java
deleted file mode 100644
index 5c828ef..0000000
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractRDFTerm.java
+++ /dev/null
@@ -1,47 +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.jena.impl;
-
-import org.apache.commons.rdf.api.RDFTerm;
-import org.apache.commons.rdf.jena.JenaRDFTerm;
-import org.apache.jena.graph.Node;
-import org.apache.jena.riot.out.NodeFmtLib;
-
-class AbstractRDFTerm implements JenaRDFTerm, RDFTerm {
-	private Node node;
-	// static private PrefixMapping empty = new PrefixMappingImpl() ;
-
-	protected AbstractRDFTerm(Node node) {
-		this.node = node;
-	}
-
-	@Override
-	public Node asJenaNode() {
-		return node;
-	}
-
-	public String ntriplesString() {
-		return NodeFmtLib.str(node);
-	}
-
-	@Override
-	public String toString() {
-		return ntriplesString();
-	}
-}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/c52979ba/jena/src/main/java/org/apache/commons/rdf/jena/impl/AnyImpl.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/AnyImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/AnyImpl.java
deleted file mode 100644
index e2d3809..0000000
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/AnyImpl.java
+++ /dev/null
@@ -1,54 +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.jena.impl;
-
-import org.apache.commons.rdf.jena.JenaAny;
-import org.apache.commons.rdf.jena.JenaRDFTerm;
-import org.apache.jena.graph.Node;
-
-public class AnyImpl implements JenaRDFTerm, JenaAny {
-
-	static class Singleton {
-		static AnyImpl instance = new AnyImpl();
-	}
-	
-	/**
-	 * Private constructor
-	 * 
-	 * @see {@link Singleton#instance}
-	 */
-	private AnyImpl() {
-	}
-	
-	@Override
-	public String ntriplesString() {
-		return "[]";
-	}
-
-	@Override
-	public Node asJenaNode() {
-		return Node.ANY;
-	}
-	
-	@Override
-	public boolean equals(Object obj) {
-		return obj == this || obj instanceof JenaAny;
-	}
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/c52979ba/jena/src/main/java/org/apache/commons/rdf/jena/impl/BlankNodeImpl.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/BlankNodeImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/BlankNodeImpl.java
deleted file mode 100644
index 2acb635..0000000
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/BlankNodeImpl.java
+++ /dev/null
@@ -1,61 +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.jena.impl;
-
-import java.util.UUID;
-
-import org.apache.commons.rdf.api.BlankNode;
-import org.apache.commons.rdf.jena.JenaBlankNode;
-import org.apache.jena.graph.Node;
-
-public class BlankNodeImpl extends AbstractRDFTerm implements JenaBlankNode {
-
-	private UUID salt;
-
-	/* package */ BlankNodeImpl(Node node, UUID salt) {
-		super(node);
-		if (! node.isBlank()) {
-			throw new IllegalArgumentException("Node is not a blank node: " + node);
-		}				
-		this.salt = salt;
-	}
-
-	@Override
-	public boolean equals(Object other) {
-		if (other == this)
-			return true;
-		if (other == null)
-			return false;
-		if (!(other instanceof BlankNode))
-			return false;
-		BlankNode bNode = (BlankNode) other;
-		return uniqueReference().equals(bNode.uniqueReference());
-	}
-
-	@Override
-	public int hashCode() {
-		return uniqueReference().hashCode();
-	}
-
-	@Override
-	public String uniqueReference() {
-		return salt + asJenaNode().getBlankNodeLabel();
-	}
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/c52979ba/jena/src/main/java/org/apache/commons/rdf/jena/impl/DatasetImpl.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/DatasetImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/DatasetImpl.java
deleted file mode 100644
index 4094efe..0000000
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/DatasetImpl.java
+++ /dev/null
@@ -1,187 +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.jena.impl;
-
-import static org.apache.jena.graph.Node.ANY;
-
-import java.io.StringWriter;
-import java.util.Optional;
-import java.util.UUID;
-import java.util.stream.Stream;
-
-import org.apache.commons.rdf.api.BlankNodeOrIRI;
-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.jena.JenaDataset;
-import org.apache.commons.rdf.jena.JenaRDFTermFactory;
-import org.apache.jena.atlas.iterator.Iter;
-import org.apache.jena.graph.Node;
-import org.apache.jena.riot.Lang;
-import org.apache.jena.riot.RDFDataMgr;
-import org.apache.jena.sparql.core.DatasetGraph;
-import org.apache.jena.sparql.core.GraphView;
-
-public class DatasetImpl implements JenaDataset {
-
-	private DatasetGraph graph;
-	private UUID salt;
-
-	/* package */ DatasetImpl(DatasetGraph graph, UUID salt) {
-		this.graph = graph;
-		this.salt = salt;
-	}
-
-	@Override
-	public void add(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
-		graph.add(				
-				org.apache.jena.sparql.core.Quad.create(
-				JenaRDFTermFactory.toJena(graphName),
-				JenaRDFTermFactory.toJena(subject),				
-				JenaRDFTermFactory.toJena(predicate), 
-				JenaRDFTermFactory.toJena(object)));
-	}
-
-	@Override
-	public void add(Quad quad) {
-		graph.add(JenaRDFTermFactory.toJena(quad));
-	}
-	
-	@Override
-	public DatasetGraph asJenaDatasetGraph() {		
-		return graph;
-	}
-
-	@Override
-	public void clear() {
-		graph.clear();
-	}
-
-	@Override
-	public void close() {
-		graph.close();
-	}
-
-
-	@Override
-	public boolean contains(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {		
-		return graph.contains(
-				toJenaPattern(graphName),
-				toJenaPattern(subject), 
-				toJenaPattern(predicate),
-				toJenaPattern(object));
-	}
-
-	private Node toJenaPattern(Optional<? extends RDFTerm> graphName) {
-		// In theory we could have done:
-		//   JenaRDFTermFactory.toJena(graphName.orElse(JenaFactory::createAnyVariable))
-		// but because of generics casting rules that doesn't work :(						
-
-		if (graphName == null) {
-			return ANY;
-		}
-		// null: default graph
-		return JenaRDFTermFactory.toJena(graphName.orElse(null));
-	}
-
-	private Node toJenaPattern(RDFTerm term) {
-		if (term == null)
-			return ANY;
-		return JenaRDFTermFactory.toJena(term);
-	}
-
-	@Override
-	public boolean contains(Quad quad) {
-		return graph.contains(JenaRDFTermFactory.toJena(quad));
-	}
-
-	@Override
-	public void remove(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
-		graph.delete(org.apache.jena.sparql.core.Quad.create(
-				toJenaPattern(graphName),
-				toJenaPattern(subject),
-				toJenaPattern(predicate), 
-				toJenaPattern(object)));
-	}
-
-	@Override
-	public void remove(Quad quad) {
-		graph.delete(JenaRDFTermFactory.toJena(quad));
-	}
-
-	@Override
-	public long size() {
-		return graph.size();
-	}
-
-	@Override
-	public Stream<? extends Quad> stream() {
-		JenaRDFTermFactory factory = new JenaRDFTermFactory(salt);
-		return Iter.asStream(graph.find(ANY, ANY, ANY, ANY), true)
-				.map(factory::fromJena);
-	}
-
-	@Override
-	public Stream<? extends Quad> stream(Optional<BlankNodeOrIRI> g, BlankNodeOrIRI s, IRI p, RDFTerm o) {
-		JenaRDFTermFactory factory = new JenaRDFTermFactory(salt);
-		return Iter.asStream(graph.find(toJenaPattern(g), toJenaPattern(s), toJenaPattern(p), toJenaPattern(o)), true)
-				.map(factory::fromJena);
-	}
-
-	@Override
-	public String toString() {
-		StringWriter sw = new StringWriter();
-		RDFDataMgr.write(sw, graph, Lang.NT);
-		return sw.toString();
-	}
-
-	@Override
-	public Graph getGraph() {
-		GraphView gv = GraphView.createDefaultGraph(graph);
-		return new GraphImpl(gv, salt);
-	}
-
-	@Override
-	public Graph getUnionGraph() {
-		GraphView gv = GraphView.createUnionGraph(graph);
-		return new GraphImpl(gv, salt);
-	}
-	
-	@Override
-	public Optional<Graph> getGraph(BlankNodeOrIRI graphName) {
-		GraphView gv = GraphView.createNamedGraph(graph, JenaRDFTermFactory.toJena(graphName));
-		return Optional.of(new GraphImpl(gv, salt));
-	}	
-
-	@Override
-	public Stream<BlankNodeOrIRI> getGraphNames() {
-		JenaRDFTermFactory factory = new JenaRDFTermFactory(salt);
-		return Iter.asStream(graph.listGraphNodes()).map(node -> 
-			(BlankNodeOrIRI) factory.fromJena(node));		
-	}
-
-	@Override
-	public Iterable<Quad> iterate() {
-		return Iter.asStream(graph.find(), false)
-				.map(q -> (Quad) JenaRDFTermFactory.fromJena(q, salt))
-				::iterator;
-	}
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/c52979ba/jena/src/main/java/org/apache/commons/rdf/jena/impl/GeneralizedQuadImpl.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/GeneralizedQuadImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/GeneralizedQuadImpl.java
deleted file mode 100644
index e772bd1..0000000
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/GeneralizedQuadImpl.java
+++ /dev/null
@@ -1,136 +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.jena.impl;
-
-import java.util.Objects;
-import java.util.Optional;
-import java.util.UUID;
-
-import org.apache.commons.rdf.api.QuadLike;
-import org.apache.commons.rdf.api.RDFTerm;
-import org.apache.commons.rdf.jena.JenaQuad;
-import org.apache.commons.rdf.jena.JenaQuadLike;
-import org.apache.commons.rdf.jena.JenaRDFTermFactory;
-import org.apache.commons.rdf.jena.JenaTriple;
-import org.apache.jena.graph.Triple;
-import org.apache.jena.sparql.core.Quad;
-
-/**
- * A generalized {@link QuadLike}, backed by a Jena {@link Quad} or {@link Triple}.
- * <p>
- * This class does not implement any particular {@link #equals(Object)} or
- * {@link #hashCode()} but can otherwise be used as a base class for both
- * a {@link JenaTriple} and a {@link JenaQuad}.
- * 
- * @see TripleImpl
- * @see QuadImpl
- * @see JenaFactory#createGeneralizedTriple(RDFTerm, RDFTerm, RDFTerm)
- * @see JenaFactory#createGeneralizedQuad(RDFTerm, RDFTerm, RDFTerm, RDFTerm)
- *
- */
-public class GeneralizedQuadImpl<S extends RDFTerm, P extends RDFTerm, O extends RDFTerm, G extends RDFTerm> implements JenaQuadLike<S,P,O,G> {
-
-	final Optional<G> graphName;
-	final S subject;
-	final P predicate;
-	final O object;
-	org.apache.jena.sparql.core.Quad quad = null;
-	org.apache.jena.graph.Triple triple = null;
-	
-	GeneralizedQuadImpl(S subject, P predicate, O object, Optional<G> graphName) {		
-		this.subject = Objects.requireNonNull(subject);
-		this.predicate = Objects.requireNonNull(predicate);
-		this.object = Objects.requireNonNull(object);
-		this.graphName = Objects.requireNonNull(graphName);
-	}
-
-	GeneralizedQuadImpl(S subject, P predicate, O object) {
-		this(subject, predicate, object, Optional.empty());
-	}
-	 
-	@SuppressWarnings("unchecked")
-	GeneralizedQuadImpl(org.apache.jena.sparql.core.Quad quad, UUID salt) {
-		this.quad = Objects.requireNonNull(quad);
-		this.subject = (S) JenaFactory.fromJena(quad.getSubject(), salt);
-		this.predicate = (P) JenaFactory.fromJena(quad.getPredicate(), salt);
-		this.object = (O)JenaFactory.fromJena(quad.getObject(), salt);
-		this.graphName = Optional.of((G) JenaFactory.fromJena(quad.getGraph(), salt));		
-	}
-
-	@SuppressWarnings("unchecked")
-	GeneralizedQuadImpl(org.apache.jena.graph.Triple triple, UUID salt) {
-		this.triple = Objects.requireNonNull(triple);		
-		this.subject = (S) JenaFactory.fromJena(triple.getSubject(), salt);
-		this.predicate = (P) JenaFactory.fromJena(triple.getPredicate(), salt);
-		this.object = (O)JenaFactory.fromJena(triple.getObject(), salt);
-		this.graphName = Optional.empty();
-	}
-
-	@Override
-	public org.apache.jena.sparql.core.Quad asJenaQuad() {
-		if (quad == null) {
-			quad = org.apache.jena.sparql.core.Quad.create(
-					JenaRDFTermFactory.toJena(graphName.orElse(null)),
-					JenaRDFTermFactory.toJena(subject), 
-					JenaRDFTermFactory.toJena(predicate),
-					JenaRDFTermFactory.toJena(object));
-		}
-		return quad;
-	}
-
-	@Override
-	public org.apache.jena.graph.Triple asJenaTriple() {
-		if (triple == null) {
-			triple = org.apache.jena.graph.Triple.create(JenaRDFTermFactory.toJena(subject), 
-				JenaRDFTermFactory.toJena(predicate),
-				JenaRDFTermFactory.toJena(object));
-		}
-		return triple;
-	}	
-	
-	@Override
-	public S getSubject() {
-		return subject;
-	}
-
-	@Override
-	public P getPredicate() {
-		return predicate;
-	}
-	
-	@Override
-	public O getObject() {
-		return object;
-	}
-
-	@Override
-	public Optional<G> getGraphName() {
-		return graphName;
-	}
-
-	@Override
-	public String toString() {
-		// kind of nquad syntax
-		return getSubject().ntriplesString() + " " + 
-				getPredicate().ntriplesString() + " "
-				+ getObject().ntriplesString() + " " + 
-				getGraphName().map(RDFTerm::ntriplesString).orElse("") + ".";
-	}
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/c52979ba/jena/src/main/java/org/apache/commons/rdf/jena/impl/GraphImpl.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/GraphImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/GraphImpl.java
deleted file mode 100644
index 3b74ee0..0000000
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/GraphImpl.java
+++ /dev/null
@@ -1,154 +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.jena.impl;
-
-import java.io.StringWriter;
-import java.util.UUID;
-import java.util.stream.Stream;
-
-import org.apache.commons.rdf.api.BlankNodeOrIRI;
-import org.apache.commons.rdf.api.IRI;
-import org.apache.commons.rdf.api.RDFTerm;
-import org.apache.commons.rdf.api.Triple;
-import org.apache.commons.rdf.jena.JenaGraph;
-import org.apache.commons.rdf.jena.JenaRDFTermFactory;
-import org.apache.jena.atlas.iterator.Iter;
-import org.apache.jena.graph.Node;
-import org.apache.jena.rdf.model.Model;
-import org.apache.jena.rdf.model.ModelFactory;
-import org.apache.jena.riot.Lang;
-import org.apache.jena.riot.RDFDataMgr;
-
-public class GraphImpl implements JenaGraph {
-
-	private org.apache.jena.graph.Graph graph;
-	private UUID salt;
-	private Model model;
-
-	GraphImpl(org.apache.jena.graph.Graph graph, UUID salt) {
-		this.graph = graph;
-		this.salt = salt;
-	}
-
-	GraphImpl(Model model, UUID salt) {
-		this.model = model;
-		this.graph = model.getGraph();
-		this.salt = salt;
-	}
-
-	@Override
-	public void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
-		graph.add(org.apache.jena.graph.Triple.create(
-				JenaRDFTermFactory.toJena(subject),
-				JenaRDFTermFactory.toJena(predicate), 
-				JenaRDFTermFactory.toJena(object)));
-	}
-
-	@Override
-	public void add(Triple triple) {
-		graph.add(JenaRDFTermFactory.toJena(triple));
-	}
-
-	@Override
-	public org.apache.jena.graph.Graph asJenaGraph() {
-		return graph;
-	}
-
-	@Override
-	public void clear() {
-		graph.clear();
-	}
-
-	@Override
-	public void close() {
-		graph.close();
-	}
-
-	@Override
-	public boolean contains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
-		return graph.contains(
-				JenaRDFTermFactory.toJena(subject), 
-				JenaRDFTermFactory.toJena(predicate),
-				JenaRDFTermFactory.toJena(object));
-	}
-
-	@Override
-	public boolean contains(Triple triple) {
-		return graph.contains(JenaRDFTermFactory.toJena(triple));
-	}
-
-	@Override
-	public void remove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
-		graph.delete(org.apache.jena.graph.Triple.create(
-				JenaRDFTermFactory.toJena(subject),
-				JenaRDFTermFactory.toJena(predicate), 
-				JenaRDFTermFactory.toJena(object)));
-	}
-
-	@Override
-	public void remove(Triple triple) {
-		graph.delete(JenaRDFTermFactory.toJena(triple));
-	}
-
-	@Override
-	public long size() {
-		return graph.size();
-	}
-
-	@Override
-	public Stream<? extends Triple> stream() {
-		JenaRDFTermFactory factory = new JenaRDFTermFactory(salt);
-		return Iter.asStream(graph.find(null, null, null), true).map(factory::fromJena);
-	}
-
-	@Override
-	public Stream<? extends Triple> stream(BlankNodeOrIRI s, IRI p, RDFTerm o) {
-		JenaRDFTermFactory factory = new JenaRDFTermFactory(salt);
-		return Iter.asStream(graph.find(toJenaAny(s), toJenaAny(p), toJenaAny(o)), true)
-				.map(factory::fromJena);
-	}
-
-	private Node toJenaAny(RDFTerm term) {
-		if (term == null)
-			return Node.ANY;
-		return JenaRDFTermFactory.toJena(term);
-	}
-
-	@Override
-	public String toString() {
-		StringWriter sw = new StringWriter();
-		RDFDataMgr.write(sw, graph, Lang.NT);
-		return sw.toString();
-	}
-
-	@Override
-	public Model asJenaModel() {
-		if (model == null) {
-			synchronized(this) {
-				// As Model can be used for locks, we should make sure we don't make
-				// more than one model
-				if (model == null) {
-					model = ModelFactory.createModelForGraph(graph);
-				}
-			}
-		}
-		return model;
-	}
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/c52979ba/jena/src/main/java/org/apache/commons/rdf/jena/impl/IRIImpl.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/IRIImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/IRIImpl.java
deleted file mode 100644
index e85c80f..0000000
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/IRIImpl.java
+++ /dev/null
@@ -1,61 +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.jena.impl;
-
-import org.apache.commons.rdf.api.IRI;
-import org.apache.commons.rdf.jena.JenaIRI;
-import org.apache.jena.graph.Node;
-import org.apache.jena.graph.NodeFactory;
-
-public class IRIImpl extends AbstractRDFTerm implements JenaIRI {
-
-	/* package */ IRIImpl(Node node) {
-		super(node);
-		if (! node.isURI()) {
-			throw new IllegalArgumentException("Node is not a blank node: " + node);
-		}				
-		
-	}
-
-	/* package */ IRIImpl(String iriStr) {
-		super(NodeFactory.createURI(iriStr));
-	}
-
-	@Override
-	public boolean equals(Object other) {
-		if (other == this)
-			return true;
-		if (other == null)
-			return false;
-		if (!(other instanceof IRI))
-			return false;
-		IRI iri = (IRI) other;
-		return getIRIString().equals(iri.getIRIString());
-	}
-
-	@Override
-	public String getIRIString() {
-		return asJenaNode().getURI();
-	}
-
-	@Override
-	public int hashCode() {
-		return getIRIString().hashCode();
-	}
-}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/c52979ba/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaAnyImpl.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaAnyImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaAnyImpl.java
new file mode 100644
index 0000000..068cbd8
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaAnyImpl.java
@@ -0,0 +1,54 @@
+/**
+ * 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.jena.impl;
+
+import org.apache.commons.rdf.jena.JenaAny;
+import org.apache.commons.rdf.jena.JenaRDFTerm;
+import org.apache.jena.graph.Node;
+
+public class JenaAnyImpl implements JenaRDFTerm, JenaAny {
+
+	static class Singleton {
+		static JenaAnyImpl instance = new JenaAnyImpl();
+	}
+	
+	/**
+	 * Private constructor
+	 * 
+	 * @see {@link Singleton#instance}
+	 */
+	private JenaAnyImpl() {
+	}
+	
+	@Override
+	public String ntriplesString() {
+		return "[]";
+	}
+
+	@Override
+	public Node asJenaNode() {
+		return Node.ANY;
+	}
+	
+	@Override
+	public boolean equals(Object obj) {
+		return obj == this || obj instanceof JenaAny;
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/c52979ba/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaBlankNodeImpl.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaBlankNodeImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaBlankNodeImpl.java
new file mode 100644
index 0000000..0cbd764
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaBlankNodeImpl.java
@@ -0,0 +1,61 @@
+/**
+ * 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.jena.impl;
+
+import java.util.UUID;
+
+import org.apache.commons.rdf.api.BlankNode;
+import org.apache.commons.rdf.jena.JenaBlankNode;
+import org.apache.jena.graph.Node;
+
+public class JenaBlankNodeImpl extends AbstractJenaRDFTerm implements JenaBlankNode {
+
+	private UUID salt;
+
+	/* package */ JenaBlankNodeImpl(Node node, UUID salt) {
+		super(node);
+		if (! node.isBlank()) {
+			throw new IllegalArgumentException("Node is not a blank node: " + node);
+		}				
+		this.salt = salt;
+	}
+
+	@Override
+	public boolean equals(Object other) {
+		if (other == this)
+			return true;
+		if (other == null)
+			return false;
+		if (!(other instanceof BlankNode))
+			return false;
+		BlankNode bNode = (BlankNode) other;
+		return uniqueReference().equals(bNode.uniqueReference());
+	}
+
+	@Override
+	public int hashCode() {
+		return uniqueReference().hashCode();
+	}
+
+	@Override
+	public String uniqueReference() {
+		return salt + asJenaNode().getBlankNodeLabel();
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/c52979ba/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaDatasetImpl.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaDatasetImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaDatasetImpl.java
new file mode 100644
index 0000000..b756526
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaDatasetImpl.java
@@ -0,0 +1,187 @@
+/**
+ * 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.jena.impl;
+
+import static org.apache.jena.graph.Node.ANY;
+
+import java.io.StringWriter;
+import java.util.Optional;
+import java.util.UUID;
+import java.util.stream.Stream;
+
+import org.apache.commons.rdf.api.BlankNodeOrIRI;
+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.jena.JenaDataset;
+import org.apache.commons.rdf.jena.JenaRDFTermFactory;
+import org.apache.jena.atlas.iterator.Iter;
+import org.apache.jena.graph.Node;
+import org.apache.jena.riot.Lang;
+import org.apache.jena.riot.RDFDataMgr;
+import org.apache.jena.sparql.core.DatasetGraph;
+import org.apache.jena.sparql.core.GraphView;
+
+public class JenaDatasetImpl implements JenaDataset {
+
+	private DatasetGraph graph;
+	private UUID salt;
+
+	/* package */ JenaDatasetImpl(DatasetGraph graph, UUID salt) {
+		this.graph = graph;
+		this.salt = salt;
+	}
+
+	@Override
+	public void add(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+		graph.add(				
+				org.apache.jena.sparql.core.Quad.create(
+				JenaRDFTermFactory.toJena(graphName),
+				JenaRDFTermFactory.toJena(subject),				
+				JenaRDFTermFactory.toJena(predicate), 
+				JenaRDFTermFactory.toJena(object)));
+	}
+
+	@Override
+	public void add(Quad quad) {
+		graph.add(JenaRDFTermFactory.toJena(quad));
+	}
+	
+	@Override
+	public DatasetGraph asJenaDatasetGraph() {		
+		return graph;
+	}
+
+	@Override
+	public void clear() {
+		graph.clear();
+	}
+
+	@Override
+	public void close() {
+		graph.close();
+	}
+
+
+	@Override
+	public boolean contains(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {		
+		return graph.contains(
+				toJenaPattern(graphName),
+				toJenaPattern(subject), 
+				toJenaPattern(predicate),
+				toJenaPattern(object));
+	}
+
+	private Node toJenaPattern(Optional<? extends RDFTerm> graphName) {
+		// In theory we could have done:
+		//   JenaRDFTermFactory.toJena(graphName.orElse(JenaFactory::createAnyVariable))
+		// but because of generics casting rules that doesn't work :(						
+
+		if (graphName == null) {
+			return ANY;
+		}
+		// null: default graph
+		return JenaRDFTermFactory.toJena(graphName.orElse(null));
+	}
+
+	private Node toJenaPattern(RDFTerm term) {
+		if (term == null)
+			return ANY;
+		return JenaRDFTermFactory.toJena(term);
+	}
+
+	@Override
+	public boolean contains(Quad quad) {
+		return graph.contains(JenaRDFTermFactory.toJena(quad));
+	}
+
+	@Override
+	public void remove(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+		graph.delete(org.apache.jena.sparql.core.Quad.create(
+				toJenaPattern(graphName),
+				toJenaPattern(subject),
+				toJenaPattern(predicate), 
+				toJenaPattern(object)));
+	}
+
+	@Override
+	public void remove(Quad quad) {
+		graph.delete(JenaRDFTermFactory.toJena(quad));
+	}
+
+	@Override
+	public long size() {
+		return graph.size();
+	}
+
+	@Override
+	public Stream<? extends Quad> stream() {
+		JenaRDFTermFactory factory = new JenaRDFTermFactory(salt);
+		return Iter.asStream(graph.find(ANY, ANY, ANY, ANY), true)
+				.map(factory::fromJena);
+	}
+
+	@Override
+	public Stream<? extends Quad> stream(Optional<BlankNodeOrIRI> g, BlankNodeOrIRI s, IRI p, RDFTerm o) {
+		JenaRDFTermFactory factory = new JenaRDFTermFactory(salt);
+		return Iter.asStream(graph.find(toJenaPattern(g), toJenaPattern(s), toJenaPattern(p), toJenaPattern(o)), true)
+				.map(factory::fromJena);
+	}
+
+	@Override
+	public String toString() {
+		StringWriter sw = new StringWriter();
+		RDFDataMgr.write(sw, graph, Lang.NT);
+		return sw.toString();
+	}
+
+	@Override
+	public Graph getGraph() {
+		GraphView gv = GraphView.createDefaultGraph(graph);
+		return new JenaGraphImpl(gv, salt);
+	}
+
+	@Override
+	public Graph getUnionGraph() {
+		GraphView gv = GraphView.createUnionGraph(graph);
+		return new JenaGraphImpl(gv, salt);
+	}
+	
+	@Override
+	public Optional<Graph> getGraph(BlankNodeOrIRI graphName) {
+		GraphView gv = GraphView.createNamedGraph(graph, JenaRDFTermFactory.toJena(graphName));
+		return Optional.of(new JenaGraphImpl(gv, salt));
+	}	
+
+	@Override
+	public Stream<BlankNodeOrIRI> getGraphNames() {
+		JenaRDFTermFactory factory = new JenaRDFTermFactory(salt);
+		return Iter.asStream(graph.listGraphNodes()).map(node -> 
+			(BlankNodeOrIRI) factory.fromJena(node));		
+	}
+
+	@Override
+	public Iterable<Quad> iterate() {
+		return Iter.asStream(graph.find(), false)
+				.map(q -> (Quad) JenaRDFTermFactory.fromJena(q, salt))
+				::iterator;
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/c52979ba/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaFactory.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaFactory.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaFactory.java
index 7a6a7ab..0551094 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaFactory.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaFactory.java
@@ -62,60 +62,60 @@ import org.apache.jena.sparql.graph.GraphFactory;
 public class JenaFactory {
 
 	public static JenaBlankNode createBlankNode(String id, UUID salt) {
-		return new BlankNodeImpl(NodeFactory.createBlankNode(id), salt);
+		return new JenaBlankNodeImpl(NodeFactory.createBlankNode(id), salt);
 	}
 
 	public static JenaBlankNode createBlankNode(UUID salt) {
-		return new BlankNodeImpl(NodeFactory.createBlankNode(), salt);
+		return new JenaBlankNodeImpl(NodeFactory.createBlankNode(), salt);
 	}
 	public static Dataset createDataset(UUID salt) {
 		DatasetGraph dg = DatasetGraphFactory.createGeneral();
 		// Or which createMethod() -- a bit confusing with lots of choice..
-		return new DatasetImpl(dg, salt);
+		return new JenaDatasetImpl(dg, salt);
 	}
 
 	public static JenaGraph createGraph(UUID salt) {
-		return new GraphImpl(GraphFactory.createDefaultGraph(), salt);
+		return new JenaGraphImpl(GraphFactory.createDefaultGraph(), salt);
 	}
 
 	public static JenaIRI createIRI(String iriStr) {
-		return new IRIImpl(iriStr);
+		return new JenaIRIImpl(iriStr);
 	}
 
 	public static JenaLiteral createLiteral(String lexStr) {
-		return new LiteralImpl(NodeFactory.createLiteral(lexStr));
+		return new JenaLiteralImpl(NodeFactory.createLiteral(lexStr));
 	}
 
 	public static JenaLiteral createLiteralDT(String lexStr, String datatypeIRI) {
-		return new LiteralImpl(NodeFactory.createLiteral(lexStr, NodeFactory.getType(datatypeIRI)));
+		return new JenaLiteralImpl(NodeFactory.createLiteral(lexStr, NodeFactory.getType(datatypeIRI)));
 	}
 
 	public static JenaLiteral createLiteralLang(String lexStr, String langTag) {
-		return new LiteralImpl(NodeFactory.createLiteral(lexStr, langTag));
+		return new JenaLiteralImpl(NodeFactory.createLiteral(lexStr, langTag));
 	}
 
 	public static JenaTriple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
-		return new TripleImpl(subject, predicate, object);
+		return new JenaTripleImpl(subject, predicate, object);
 	}
 
 	public static JenaQuad createQuad(BlankNodeOrIRI subject, IRI predicate, RDFTerm object, BlankNodeOrIRI graphName) {
-		return new QuadImpl(subject, predicate, object, Optional.ofNullable(graphName));
+		return new JenaQuadImpl(subject, predicate, object, Optional.ofNullable(graphName));
 	}
 	
 	public static JenaVariable createVariable(String name) {
-		return new VariableImpl(NodeFactory.createVariable(name));
+		return new JenaVariableImpl(NodeFactory.createVariable(name));
 	}
 	
 	public static JenaAny createAnyVariable() {
-		return AnyImpl.Singleton.instance;
+		return JenaAnyImpl.Singleton.instance;
 	}
 
 	public static JenaTripleLike<RDFTerm,RDFTerm,RDFTerm> createGeneralizedTriple(RDFTerm subject, RDFTerm predicate, RDFTerm object) {
-		return new GeneralizedQuadImpl<RDFTerm,RDFTerm,RDFTerm,RDFTerm>(subject, predicate, object);
+		return new JenaGeneralizedQuad<RDFTerm,RDFTerm,RDFTerm,RDFTerm>(subject, predicate, object);
 	}
 
 	public static JenaQuadLike<RDFTerm,RDFTerm,RDFTerm,RDFTerm> createGeneralizedQuad(RDFTerm subject, RDFTerm predicate, RDFTerm object, RDFTerm graphName) {
-		return new GeneralizedQuadImpl<RDFTerm,RDFTerm,RDFTerm,RDFTerm>(subject, predicate, object, Optional.ofNullable(graphName));
+		return new JenaGeneralizedQuad<RDFTerm,RDFTerm,RDFTerm,RDFTerm>(subject, predicate, object, Optional.ofNullable(graphName));
 	}
 	
 	public static JenaRDFTerm fromJena(Node node, UUID salt) throws ConversionException {
@@ -127,49 +127,49 @@ public class JenaFactory {
 
 	public static JenaRDFTerm fromJenaGeneralized(Node node, UUID salt) {
 		if (node.isURI()) {
-			return new IRIImpl(node);
+			return new JenaIRIImpl(node);
 		}
 		if (node.isLiteral()) {
-			return new LiteralImpl(node);
+			return new JenaLiteralImpl(node);
 		}
 		if (node.isBlank()) {
-			return new BlankNodeImpl(node, salt);
+			return new JenaBlankNodeImpl(node, salt);
 		}
 		if (node.equals(Node.ANY)) {
-			return AnyImpl.Singleton.instance;
+			return JenaAnyImpl.Singleton.instance;
 		}
 		if (node.isVariable()) {
-			return new VariableImpl(node);
+			return new JenaVariableImpl(node);
 		}
 		throw new IllegalArgumentException("Unrecognized node type: " + node);
 	}
 
 	public static JenaGraph fromJena(org.apache.jena.graph.Graph graph, UUID salt) {
-		return new GraphImpl(graph, salt);
+		return new JenaGraphImpl(graph, salt);
 	}
 
 	public static JenaGraph fromJena(Model model, UUID salt) {
-		return new GraphImpl(model, salt);
+		return new JenaGraphImpl(model, salt);
 	}
 
 	public static JenaDataset fromJena(DatasetGraph datasetGraph, UUID salt) {
-		return new DatasetImpl(datasetGraph, salt);
+		return new JenaDatasetImpl(datasetGraph, salt);
 	}
 	
 	public static JenaTriple fromJena(org.apache.jena.graph.Triple triple, UUID salt) {
-		return new TripleImpl(triple, salt);
+		return new JenaTripleImpl(triple, salt);
 	}
 
 	public static JenaTripleLike<RDFTerm, RDFTerm, RDFTerm> fromJenaGeneralized(org.apache.jena.graph.Triple triple, UUID salt) {
-		return new GeneralizedQuadImpl<RDFTerm,RDFTerm,RDFTerm,RDFTerm>(triple, salt);
+		return new JenaGeneralizedQuad<RDFTerm,RDFTerm,RDFTerm,RDFTerm>(triple, salt);
 	}
 
 	public static JenaQuadLike<RDFTerm,RDFTerm,RDFTerm,RDFTerm> fromJenaGeneralized(org.apache.jena.sparql.core.Quad quad, UUID salt) {
-		return new GeneralizedQuadImpl<RDFTerm,RDFTerm,RDFTerm,RDFTerm>(quad, salt);
+		return new JenaGeneralizedQuad<RDFTerm,RDFTerm,RDFTerm,RDFTerm>(quad, salt);
 	}
 	
 	public static Quad fromJena(org.apache.jena.sparql.core.Quad quad, UUID salt) {
-		return new QuadImpl(quad, salt);
+		return new JenaQuadImpl(quad, salt);
 	}
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/c52979ba/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGeneralizedQuad.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGeneralizedQuad.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGeneralizedQuad.java
new file mode 100644
index 0000000..5456ec9
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGeneralizedQuad.java
@@ -0,0 +1,136 @@
+/**
+ * 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.jena.impl;
+
+import java.util.Objects;
+import java.util.Optional;
+import java.util.UUID;
+
+import org.apache.commons.rdf.api.QuadLike;
+import org.apache.commons.rdf.api.RDFTerm;
+import org.apache.commons.rdf.jena.JenaQuad;
+import org.apache.commons.rdf.jena.JenaQuadLike;
+import org.apache.commons.rdf.jena.JenaRDFTermFactory;
+import org.apache.commons.rdf.jena.JenaTriple;
+import org.apache.jena.graph.Triple;
+import org.apache.jena.sparql.core.Quad;
+
+/**
+ * A generalized {@link QuadLike}, backed by a Jena {@link Quad} or {@link Triple}.
+ * <p>
+ * This class does not implement any particular {@link #equals(Object)} or
+ * {@link #hashCode()} but can otherwise be used as a base class for both
+ * a {@link JenaTriple} and a {@link JenaQuad}.
+ * 
+ * @see JenaTripleImpl
+ * @see JenaQuadImpl
+ * @see JenaFactory#createGeneralizedTriple(RDFTerm, RDFTerm, RDFTerm)
+ * @see JenaFactory#createGeneralizedQuad(RDFTerm, RDFTerm, RDFTerm, RDFTerm)
+ *
+ */
+public class JenaGeneralizedQuad<S extends RDFTerm, P extends RDFTerm, O extends RDFTerm, G extends RDFTerm> implements JenaQuadLike<S,P,O,G> {
+
+	final Optional<G> graphName;
+	final S subject;
+	final P predicate;
+	final O object;
+	org.apache.jena.sparql.core.Quad quad = null;
+	org.apache.jena.graph.Triple triple = null;
+	
+	JenaGeneralizedQuad(S subject, P predicate, O object, Optional<G> graphName) {		
+		this.subject = Objects.requireNonNull(subject);
+		this.predicate = Objects.requireNonNull(predicate);
+		this.object = Objects.requireNonNull(object);
+		this.graphName = Objects.requireNonNull(graphName);
+	}
+
+	JenaGeneralizedQuad(S subject, P predicate, O object) {
+		this(subject, predicate, object, Optional.empty());
+	}
+	 
+	@SuppressWarnings("unchecked")
+	JenaGeneralizedQuad(org.apache.jena.sparql.core.Quad quad, UUID salt) {
+		this.quad = Objects.requireNonNull(quad);
+		this.subject = (S) JenaFactory.fromJena(quad.getSubject(), salt);
+		this.predicate = (P) JenaFactory.fromJena(quad.getPredicate(), salt);
+		this.object = (O)JenaFactory.fromJena(quad.getObject(), salt);
+		this.graphName = Optional.of((G) JenaFactory.fromJena(quad.getGraph(), salt));		
+	}
+
+	@SuppressWarnings("unchecked")
+	JenaGeneralizedQuad(org.apache.jena.graph.Triple triple, UUID salt) {
+		this.triple = Objects.requireNonNull(triple);		
+		this.subject = (S) JenaFactory.fromJena(triple.getSubject(), salt);
+		this.predicate = (P) JenaFactory.fromJena(triple.getPredicate(), salt);
+		this.object = (O)JenaFactory.fromJena(triple.getObject(), salt);
+		this.graphName = Optional.empty();
+	}
+
+	@Override
+	public org.apache.jena.sparql.core.Quad asJenaQuad() {
+		if (quad == null) {
+			quad = org.apache.jena.sparql.core.Quad.create(
+					JenaRDFTermFactory.toJena(graphName.orElse(null)),
+					JenaRDFTermFactory.toJena(subject), 
+					JenaRDFTermFactory.toJena(predicate),
+					JenaRDFTermFactory.toJena(object));
+		}
+		return quad;
+	}
+
+	@Override
+	public org.apache.jena.graph.Triple asJenaTriple() {
+		if (triple == null) {
+			triple = org.apache.jena.graph.Triple.create(JenaRDFTermFactory.toJena(subject), 
+				JenaRDFTermFactory.toJena(predicate),
+				JenaRDFTermFactory.toJena(object));
+		}
+		return triple;
+	}	
+	
+	@Override
+	public S getSubject() {
+		return subject;
+	}
+
+	@Override
+	public P getPredicate() {
+		return predicate;
+	}
+	
+	@Override
+	public O getObject() {
+		return object;
+	}
+
+	@Override
+	public Optional<G> getGraphName() {
+		return graphName;
+	}
+
+	@Override
+	public String toString() {
+		// kind of nquad syntax
+		return getSubject().ntriplesString() + " " + 
+				getPredicate().ntriplesString() + " "
+				+ getObject().ntriplesString() + " " + 
+				getGraphName().map(RDFTerm::ntriplesString).orElse("") + ".";
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/c52979ba/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGraphImpl.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGraphImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGraphImpl.java
new file mode 100644
index 0000000..49a09ae
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGraphImpl.java
@@ -0,0 +1,154 @@
+/**
+ * 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.jena.impl;
+
+import java.io.StringWriter;
+import java.util.UUID;
+import java.util.stream.Stream;
+
+import org.apache.commons.rdf.api.BlankNodeOrIRI;
+import org.apache.commons.rdf.api.IRI;
+import org.apache.commons.rdf.api.RDFTerm;
+import org.apache.commons.rdf.api.Triple;
+import org.apache.commons.rdf.jena.JenaGraph;
+import org.apache.commons.rdf.jena.JenaRDFTermFactory;
+import org.apache.jena.atlas.iterator.Iter;
+import org.apache.jena.graph.Node;
+import org.apache.jena.rdf.model.Model;
+import org.apache.jena.rdf.model.ModelFactory;
+import org.apache.jena.riot.Lang;
+import org.apache.jena.riot.RDFDataMgr;
+
+public class JenaGraphImpl implements JenaGraph {
+
+	private org.apache.jena.graph.Graph graph;
+	private UUID salt;
+	private Model model;
+
+	JenaGraphImpl(org.apache.jena.graph.Graph graph, UUID salt) {
+		this.graph = graph;
+		this.salt = salt;
+	}
+
+	JenaGraphImpl(Model model, UUID salt) {
+		this.model = model;
+		this.graph = model.getGraph();
+		this.salt = salt;
+	}
+
+	@Override
+	public void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+		graph.add(org.apache.jena.graph.Triple.create(
+				JenaRDFTermFactory.toJena(subject),
+				JenaRDFTermFactory.toJena(predicate), 
+				JenaRDFTermFactory.toJena(object)));
+	}
+
+	@Override
+	public void add(Triple triple) {
+		graph.add(JenaRDFTermFactory.toJena(triple));
+	}
+
+	@Override
+	public org.apache.jena.graph.Graph asJenaGraph() {
+		return graph;
+	}
+
+	@Override
+	public void clear() {
+		graph.clear();
+	}
+
+	@Override
+	public void close() {
+		graph.close();
+	}
+
+	@Override
+	public boolean contains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+		return graph.contains(
+				JenaRDFTermFactory.toJena(subject), 
+				JenaRDFTermFactory.toJena(predicate),
+				JenaRDFTermFactory.toJena(object));
+	}
+
+	@Override
+	public boolean contains(Triple triple) {
+		return graph.contains(JenaRDFTermFactory.toJena(triple));
+	}
+
+	@Override
+	public void remove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+		graph.delete(org.apache.jena.graph.Triple.create(
+				JenaRDFTermFactory.toJena(subject),
+				JenaRDFTermFactory.toJena(predicate), 
+				JenaRDFTermFactory.toJena(object)));
+	}
+
+	@Override
+	public void remove(Triple triple) {
+		graph.delete(JenaRDFTermFactory.toJena(triple));
+	}
+
+	@Override
+	public long size() {
+		return graph.size();
+	}
+
+	@Override
+	public Stream<? extends Triple> stream() {
+		JenaRDFTermFactory factory = new JenaRDFTermFactory(salt);
+		return Iter.asStream(graph.find(null, null, null), true).map(factory::fromJena);
+	}
+
+	@Override
+	public Stream<? extends Triple> stream(BlankNodeOrIRI s, IRI p, RDFTerm o) {
+		JenaRDFTermFactory factory = new JenaRDFTermFactory(salt);
+		return Iter.asStream(graph.find(toJenaAny(s), toJenaAny(p), toJenaAny(o)), true)
+				.map(factory::fromJena);
+	}
+
+	private Node toJenaAny(RDFTerm term) {
+		if (term == null)
+			return Node.ANY;
+		return JenaRDFTermFactory.toJena(term);
+	}
+
+	@Override
+	public String toString() {
+		StringWriter sw = new StringWriter();
+		RDFDataMgr.write(sw, graph, Lang.NT);
+		return sw.toString();
+	}
+
+	@Override
+	public Model asJenaModel() {
+		if (model == null) {
+			synchronized(this) {
+				// As Model can be used for locks, we should make sure we don't make
+				// more than one model
+				if (model == null) {
+					model = ModelFactory.createModelForGraph(graph);
+				}
+			}
+		}
+		return model;
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/c52979ba/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaIRIImpl.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaIRIImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaIRIImpl.java
new file mode 100644
index 0000000..2aa170f
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaIRIImpl.java
@@ -0,0 +1,61 @@
+/**
+ * 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.jena.impl;
+
+import org.apache.commons.rdf.api.IRI;
+import org.apache.commons.rdf.jena.JenaIRI;
+import org.apache.jena.graph.Node;
+import org.apache.jena.graph.NodeFactory;
+
+public class JenaIRIImpl extends AbstractJenaRDFTerm implements JenaIRI {
+
+	/* package */ JenaIRIImpl(Node node) {
+		super(node);
+		if (! node.isURI()) {
+			throw new IllegalArgumentException("Node is not a blank node: " + node);
+		}				
+		
+	}
+
+	/* package */ JenaIRIImpl(String iriStr) {
+		super(NodeFactory.createURI(iriStr));
+	}
+
+	@Override
+	public boolean equals(Object other) {
+		if (other == this)
+			return true;
+		if (other == null)
+			return false;
+		if (!(other instanceof IRI))
+			return false;
+		IRI iri = (IRI) other;
+		return getIRIString().equals(iri.getIRIString());
+	}
+
+	@Override
+	public String getIRIString() {
+		return asJenaNode().getURI();
+	}
+
+	@Override
+	public int hashCode() {
+		return getIRIString().hashCode();
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/c52979ba/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaLiteralImpl.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaLiteralImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaLiteralImpl.java
new file mode 100644
index 0000000..5bbc166
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaLiteralImpl.java
@@ -0,0 +1,73 @@
+/**
+ * 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.jena.impl;
+
+import java.util.Objects;
+import java.util.Optional;
+
+import org.apache.commons.rdf.api.IRI;
+import org.apache.commons.rdf.api.Literal;
+import org.apache.commons.rdf.jena.JenaLiteral;
+import org.apache.jena.graph.Node;
+
+public class JenaLiteralImpl extends AbstractJenaRDFTerm implements JenaLiteral {
+
+	/* package */ JenaLiteralImpl(Node node) {
+		super(node);
+		if (! node.isLiteral()) {
+			throw new IllegalArgumentException("Node is not a literal: " + node);
+		}		
+	}
+
+	@Override
+	public boolean equals(Object other) {
+		if (other == this)
+			return true;
+		if (other == null)
+			return false;
+		if (!(other instanceof Literal))
+			return false;
+		Literal literal = (Literal) other;
+		return getLexicalForm().equals(literal.getLexicalForm()) && getLanguageTag().equals(literal.getLanguageTag())
+				&& getDatatype().equals(literal.getDatatype());
+	}
+
+	@Override
+	public IRI getDatatype() {
+		return JenaFactory.createIRI(asJenaNode().getLiteralDatatype().getURI());
+	}
+
+	@Override
+	public Optional<String> getLanguageTag() {
+		String x = asJenaNode().getLiteralLanguage();
+		if (x == null || x.isEmpty())
+			return Optional.empty();
+		return Optional.of(x);
+	}
+
+	@Override
+	public String getLexicalForm() {
+		return asJenaNode().getLiteralLexicalForm();
+	}
+
+	@Override
+	public int hashCode() {
+		return Objects.hash(getLexicalForm(), getDatatype(), getLanguageTag());
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/c52979ba/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaQuadImpl.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaQuadImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaQuadImpl.java
new file mode 100644
index 0000000..0f3e3e3
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaQuadImpl.java
@@ -0,0 +1,66 @@
+/**
+ * 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.jena.impl;
+
+import java.util.Objects;
+import java.util.Optional;
+import java.util.UUID;
+
+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.jena.ConversionException;
+import org.apache.commons.rdf.jena.JenaQuad;
+
+public class JenaQuadImpl	extends JenaGeneralizedQuad<BlankNodeOrIRI,IRI,RDFTerm,BlankNodeOrIRI>
+	implements JenaQuad {
+
+	JenaQuadImpl(BlankNodeOrIRI subject, IRI predicate, RDFTerm object, Optional<BlankNodeOrIRI> graphName) {
+		super(subject, predicate, object, graphName);
+	}
+
+	JenaQuadImpl(org.apache.jena.sparql.core.Quad quad, UUID salt) {
+		super(quad, salt);
+		// Check the conversion
+		if ((graphName.isPresent() && ! (graphName.get() instanceof BlankNodeOrIRI)) ||
+			! (subject instanceof BlankNodeOrIRI) ||
+			! (predicate instanceof IRI) ||
+			! (object instanceof RDFTerm)) {
+			throw new ConversionException("Can't adapt generalized quad: " + quad);	
+		}
+	}
+
+	@Override
+	public boolean equals(Object other) {
+		if (other == this)
+			return true;
+		if (!(other instanceof Quad))
+			return false;
+		Quad quad = (Quad) other;
+		return getGraphName().equals(quad.getGraphName()) && getSubject().equals(quad.getSubject())
+				&& getPredicate().equals(quad.getPredicate()) && getObject().equals(quad.getObject());
+	}
+
+	@Override
+	public int hashCode() {
+		return Objects.hash(getSubject(), getPredicate(), getObject(), getGraphName());
+	}
+	
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/c52979ba/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaTripleImpl.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaTripleImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaTripleImpl.java
new file mode 100644
index 0000000..4e497f2
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaTripleImpl.java
@@ -0,0 +1,67 @@
+/**
+ * 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.jena.impl;
+
+import java.util.Objects;
+import java.util.UUID;
+
+import org.apache.commons.rdf.api.BlankNodeOrIRI;
+import org.apache.commons.rdf.api.IRI;
+import org.apache.commons.rdf.api.RDFTerm;
+import org.apache.commons.rdf.api.Triple;
+import org.apache.commons.rdf.jena.ConversionException;
+import org.apache.commons.rdf.jena.JenaTriple;
+
+public class JenaTripleImpl extends JenaGeneralizedQuad<BlankNodeOrIRI, IRI, RDFTerm, RDFTerm>
+		implements JenaTriple {
+
+	JenaTripleImpl(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+		super(subject, predicate, object);
+	}
+
+	JenaTripleImpl(org.apache.jena.graph.Triple triple, UUID salt) throws ConversionException {
+		super(triple, salt);
+		// Check the conversion
+		if (! (subject instanceof BlankNodeOrIRI) ||
+			! (predicate instanceof IRI) ||
+			! (object instanceof RDFTerm)) {
+			throw new ConversionException("Can't adapt generalized triple: " + quad);	
+		}
+	}
+
+	@Override
+	public boolean equals(Object other) {
+		if (other == this)
+			return true;
+		if (other == null)
+			return false;
+		if (!(other instanceof Triple))
+			return false;
+		Triple triple = (Triple) other;
+		return getSubject().equals(triple.getSubject()) && getPredicate().equals(triple.getPredicate())
+				&& getObject().equals(triple.getObject());
+	}
+
+	@Override
+	public int hashCode() {
+		return Objects.hash(getSubject(), getPredicate(), getObject());
+	}
+
+	
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/c52979ba/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaVariableImpl.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaVariableImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaVariableImpl.java
new file mode 100644
index 0000000..8027cf2
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaVariableImpl.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.jena.impl;
+
+import java.util.Objects;
+
+import org.apache.commons.rdf.jena.JenaRDFTerm;
+import org.apache.commons.rdf.jena.JenaVariable;
+import org.apache.jena.graph.Node;
+
+public class JenaVariableImpl implements JenaRDFTerm, JenaVariable {
+
+	private Node node;
+
+	JenaVariableImpl(Node node) {	
+		if (! node.isVariable()) {
+			throw new IllegalArgumentException("Node is not a variable: " + node);
+		}
+		this.node = node;
+	}
+
+	@Override
+	public String ntriplesString() {
+		return "?" + getVariableName();
+	}
+
+	@Override
+	public String getVariableName() {
+		return node.getName();
+	}
+
+	@Override
+	public Node asJenaNode() {
+		return node;
+	}
+	
+	@Override
+	public boolean equals(Object obj) {
+		if (obj == this) { 
+			return true;
+		}
+		if (! (obj instanceof JenaVariable)) { 
+			return false;
+		}
+		return Objects.equals(getVariableName(), ((JenaVariable)obj).getVariableName());
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/c52979ba/jena/src/main/java/org/apache/commons/rdf/jena/impl/LiteralImpl.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/LiteralImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/LiteralImpl.java
deleted file mode 100644
index 2750198..0000000
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/LiteralImpl.java
+++ /dev/null
@@ -1,73 +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.jena.impl;
-
-import java.util.Objects;
-import java.util.Optional;
-
-import org.apache.commons.rdf.api.IRI;
-import org.apache.commons.rdf.api.Literal;
-import org.apache.commons.rdf.jena.JenaLiteral;
-import org.apache.jena.graph.Node;
-
-public class LiteralImpl extends AbstractRDFTerm implements JenaLiteral {
-
-	/* package */ LiteralImpl(Node node) {
-		super(node);
-		if (! node.isLiteral()) {
-			throw new IllegalArgumentException("Node is not a literal: " + node);
-		}		
-	}
-
-	@Override
-	public boolean equals(Object other) {
-		if (other == this)
-			return true;
-		if (other == null)
-			return false;
-		if (!(other instanceof Literal))
-			return false;
-		Literal literal = (Literal) other;
-		return getLexicalForm().equals(literal.getLexicalForm()) && getLanguageTag().equals(literal.getLanguageTag())
-				&& getDatatype().equals(literal.getDatatype());
-	}
-
-	@Override
-	public IRI getDatatype() {
-		return JenaFactory.createIRI(asJenaNode().getLiteralDatatype().getURI());
-	}
-
-	@Override
-	public Optional<String> getLanguageTag() {
-		String x = asJenaNode().getLiteralLanguage();
-		if (x == null || x.isEmpty())
-			return Optional.empty();
-		return Optional.of(x);
-	}
-
-	@Override
-	public String getLexicalForm() {
-		return asJenaNode().getLiteralLexicalForm();
-	}
-
-	@Override
-	public int hashCode() {
-		return Objects.hash(getLexicalForm(), getDatatype(), getLanguageTag());
-	}
-}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/c52979ba/jena/src/main/java/org/apache/commons/rdf/jena/impl/QuadImpl.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/QuadImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/QuadImpl.java
deleted file mode 100644
index d68fcaf..0000000
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/QuadImpl.java
+++ /dev/null
@@ -1,66 +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.jena.impl;
-
-import java.util.Objects;
-import java.util.Optional;
-import java.util.UUID;
-
-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.jena.ConversionException;
-import org.apache.commons.rdf.jena.JenaQuad;
-
-public class QuadImpl	extends GeneralizedQuadImpl<BlankNodeOrIRI,IRI,RDFTerm,BlankNodeOrIRI>
-	implements JenaQuad {
-
-	QuadImpl(BlankNodeOrIRI subject, IRI predicate, RDFTerm object, Optional<BlankNodeOrIRI> graphName) {
-		super(subject, predicate, object, graphName);
-	}
-
-	QuadImpl(org.apache.jena.sparql.core.Quad quad, UUID salt) {
-		super(quad, salt);
-		// Check the conversion
-		if ((graphName.isPresent() && ! (graphName.get() instanceof BlankNodeOrIRI)) ||
-			! (subject instanceof BlankNodeOrIRI) ||
-			! (predicate instanceof IRI) ||
-			! (object instanceof RDFTerm)) {
-			throw new ConversionException("Can't adapt generalized quad: " + quad);	
-		}
-	}
-
-	@Override
-	public boolean equals(Object other) {
-		if (other == this)
-			return true;
-		if (!(other instanceof Quad))
-			return false;
-		Quad quad = (Quad) other;
-		return getGraphName().equals(quad.getGraphName()) && getSubject().equals(quad.getSubject())
-				&& getPredicate().equals(quad.getPredicate()) && getObject().equals(quad.getObject());
-	}
-
-	@Override
-	public int hashCode() {
-		return Objects.hash(getSubject(), getPredicate(), getObject(), getGraphName());
-	}
-	
-}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/c52979ba/jena/src/main/java/org/apache/commons/rdf/jena/impl/TripleImpl.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/TripleImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/TripleImpl.java
deleted file mode 100644
index 9207b38..0000000
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/TripleImpl.java
+++ /dev/null
@@ -1,67 +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.jena.impl;
-
-import java.util.Objects;
-import java.util.UUID;
-
-import org.apache.commons.rdf.api.BlankNodeOrIRI;
-import org.apache.commons.rdf.api.IRI;
-import org.apache.commons.rdf.api.RDFTerm;
-import org.apache.commons.rdf.api.Triple;
-import org.apache.commons.rdf.jena.ConversionException;
-import org.apache.commons.rdf.jena.JenaTriple;
-
-public class TripleImpl extends GeneralizedQuadImpl<BlankNodeOrIRI, IRI, RDFTerm, RDFTerm>
-		implements JenaTriple {
-
-	TripleImpl(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
-		super(subject, predicate, object);
-	}
-
-	TripleImpl(org.apache.jena.graph.Triple triple, UUID salt) throws ConversionException {
-		super(triple, salt);
-		// Check the conversion
-		if (! (subject instanceof BlankNodeOrIRI) ||
-			! (predicate instanceof IRI) ||
-			! (object instanceof RDFTerm)) {
-			throw new ConversionException("Can't adapt generalized triple: " + quad);	
-		}
-	}
-
-	@Override
-	public boolean equals(Object other) {
-		if (other == this)
-			return true;
-		if (other == null)
-			return false;
-		if (!(other instanceof Triple))
-			return false;
-		Triple triple = (Triple) other;
-		return getSubject().equals(triple.getSubject()) && getPredicate().equals(triple.getPredicate())
-				&& getObject().equals(triple.getObject());
-	}
-
-	@Override
-	public int hashCode() {
-		return Objects.hash(getSubject(), getPredicate(), getObject());
-	}
-
-	
-}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/c52979ba/jena/src/main/java/org/apache/commons/rdf/jena/impl/VariableImpl.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/VariableImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/VariableImpl.java
deleted file mode 100644
index b72ecde..0000000
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/VariableImpl.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.jena.impl;
-
-import java.util.Objects;
-
-import org.apache.commons.rdf.jena.JenaRDFTerm;
-import org.apache.commons.rdf.jena.JenaVariable;
-import org.apache.jena.graph.Node;
-
-public class VariableImpl implements JenaRDFTerm, JenaVariable {
-
-	private Node node;
-
-	VariableImpl(Node node) {	
-		if (! node.isVariable()) {
-			throw new IllegalArgumentException("Node is not a variable: " + node);
-		}
-		this.node = node;
-	}
-
-	@Override
-	public String ntriplesString() {
-		return "?" + getVariableName();
-	}
-
-	@Override
-	public String getVariableName() {
-		return node.getName();
-	}
-
-	@Override
-	public Node asJenaNode() {
-		return node;
-	}
-	
-	@Override
-	public boolean equals(Object obj) {
-		if (obj == this) { 
-			return true;
-		}
-		if (! (obj instanceof JenaVariable)) { 
-			return false;
-		}
-		return Objects.equals(getVariableName(), ((JenaVariable)obj).getVariableName());
-	}
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/c52979ba/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFParserBuilder.java
----------------------------------------------------------------------
diff --git a/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFParserBuilder.java b/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFParserBuilder.java
index c689d0e..cd57a0e 100644
--- a/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFParserBuilder.java
+++ b/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFParserBuilder.java
@@ -28,8 +28,9 @@ import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.commons.rdf.api.Graph;
-import org.apache.commons.rdf.api.RDFParserBuilder.ParseResult;
 import org.apache.commons.rdf.api.RDFSyntax;
+import org.apache.commons.rdf.experimental.RDFParser.ParseResult;
+import org.apache.commons.rdf.jena.experimental.JenaRDFParser;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -54,7 +55,7 @@ public class TestRDFParserBuilder {
 	@Test
 	public void parseTurtle() throws Exception {
 		Graph g = new JenaRDFTermFactory().createGraph();
-		Future<ParseResult> gFuture = new JenaRDFParserBuilder().contentType(RDFSyntax.TURTLE).source(turtleFile)
+		Future<ParseResult> gFuture = new JenaRDFParser().contentType(RDFSyntax.TURTLE).source(turtleFile)
 				.target(g).parse();
 		gFuture.get(5, TimeUnit.SECONDS);
 		assertEquals(3, g.size());


[04/18] incubator-commonsrdf git commit: Merge branch 'master' into jena

Posted by st...@apache.org.
Merge branch 'master' into jena


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

Branch: refs/heads/jena-jsonld-rdf4j-integration
Commit: 2eb821d65e6512ed160a5b18c0054595a8a006d7
Parents: 5e78763 e0d3191
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Sep 28 14:24:33 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Sep 28 14:24:33 2016 +0100

----------------------------------------------------------------------
 .../commons/rdf/api/RDFParserBuilder.java       | 479 ----------------
 .../commons/rdf/experimental/RDFParser.java     | 495 +++++++++++++++++
 .../commons/rdf/experimental/package-info.java  |  34 ++
 .../test/resources/example-rdf/example.jsonld   |  25 +
 api/src/test/resources/example-rdf/example.nq   |   3 +
 api/src/test/resources/example-rdf/example.nt   |   2 +
 api/src/test/resources/example-rdf/example.rdf  |  23 +
 api/src/test/resources/example-rdf/example.trig |   3 +
 api/src/test/resources/example-rdf/example.ttl  |   2 +
 .../rdf/simple/AbstractRDFParserBuilder.java    | 541 ------------------
 .../apache/commons/rdf/simple/GraphImpl.java    |  39 +-
 .../commons/rdf/simple/RDFParseException.java   |  50 --
 .../simple/experimental/AbstractRDFParser.java  | 542 +++++++++++++++++++
 .../simple/experimental/RDFParseException.java  |  50 ++
 .../rdf/simple/experimental/package-info.java   |  34 ++
 .../simple/AbstractRDFParserBuilderTest.java    | 253 ---------
 .../rdf/simple/DummyRDFParserBuilder.java       |  12 +-
 .../experimental/AbstractRDFParserTest.java     | 256 +++++++++
 18 files changed, 1497 insertions(+), 1346 deletions(-)
----------------------------------------------------------------------



[07/18] incubator-commonsrdf git commit: Merge branch 'master' into rdf4j

Posted by st...@apache.org.
Merge branch 'master' into rdf4j


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

Branch: refs/heads/jena-jsonld-rdf4j-integration
Commit: cb2a81f91de43c59d6db6ad13fc56a67e9c3ceae
Parents: be220ea e0d3191
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Sep 28 14:27:25 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Sep 28 14:27:25 2016 +0100

----------------------------------------------------------------------
 .../commons/rdf/api/RDFParserBuilder.java       | 472 ----------------
 .../commons/rdf/experimental/RDFParser.java     | 495 +++++++++++++++++
 .../commons/rdf/experimental/package-info.java  |  34 ++
 .../rdf/simple/AbstractRDFParserBuilder.java    | 545 -------------------
 .../apache/commons/rdf/simple/GraphImpl.java    |  39 +-
 .../commons/rdf/simple/RDFParseException.java   |  50 --
 .../simple/experimental/AbstractRDFParser.java  | 542 ++++++++++++++++++
 .../simple/experimental/RDFParseException.java  |  50 ++
 .../rdf/simple/experimental/package-info.java   |  34 ++
 .../simple/AbstractRDFParserBuilderTest.java    | 253 ---------
 .../rdf/simple/DummyRDFParserBuilder.java       |  12 +-
 .../experimental/AbstractRDFParserTest.java     | 256 +++++++++
 12 files changed, 1439 insertions(+), 1343 deletions(-)
----------------------------------------------------------------------



[02/18] incubator-commonsrdf git commit: COMMONSRDF-39 experimental RDFParser interface

Posted by st...@apache.org.
COMMONSRDF-39 experimental RDFParser interface

moved to org.apache.commons.rdf.experimental for now


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

Branch: refs/heads/jena-jsonld-rdf4j-integration
Commit: 10d27cde2f7310a68274eacf550f201a3690dab8
Parents: bfcead4
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Sep 28 14:16:02 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Sep 28 14:16:02 2016 +0100

----------------------------------------------------------------------
 .../commons/rdf/api/RDFParserBuilder.java       | 479 ----------------
 .../commons/rdf/experimental/RDFParser.java     | 495 +++++++++++++++++
 .../commons/rdf/experimental/package-info.java  |  34 ++
 .../test/resources/example-rdf/example.jsonld   |  25 +
 api/src/test/resources/example-rdf/example.nq   |   3 +
 api/src/test/resources/example-rdf/example.nt   |   2 +
 api/src/test/resources/example-rdf/example.rdf  |  23 +
 api/src/test/resources/example-rdf/example.trig |   3 +
 api/src/test/resources/example-rdf/example.ttl  |   2 +
 .../rdf/simple/AbstractRDFParserBuilder.java    | 541 ------------------
 .../commons/rdf/simple/RDFParseException.java   |  50 --
 .../simple/experimental/AbstractRDFParser.java  | 542 +++++++++++++++++++
 .../simple/experimental/RDFParseException.java  |  50 ++
 .../rdf/simple/experimental/package-info.java   |  34 ++
 .../simple/AbstractRDFParserBuilderTest.java    | 253 ---------
 .../rdf/simple/DummyRDFParserBuilder.java       |  12 +-
 .../experimental/AbstractRDFParserTest.java     | 256 +++++++++
 17 files changed, 1476 insertions(+), 1328 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/10d27cde/api/src/main/java/org/apache/commons/rdf/api/RDFParserBuilder.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/RDFParserBuilder.java b/api/src/main/java/org/apache/commons/rdf/api/RDFParserBuilder.java
deleted file mode 100644
index dde92ac..0000000
--- a/api/src/main/java/org/apache/commons/rdf/api/RDFParserBuilder.java
+++ /dev/null
@@ -1,479 +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.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Path;
-import java.util.Optional;
-import java.util.concurrent.Future;
-import java.util.function.Consumer;
-
-/**
- * Builder for parsing an RDF source into a target (e.g. a Graph/Dataset).
- * <p>
- * This interface follows the
- * <a href="https://en.wikipedia.org/wiki/Builder_pattern">Builder pattern</a>,
- * allowing to set parser settings like {@link #contentType(RDFSyntax)} and
- * {@link #base(IRI)}. A caller MUST call one of the <code>source</code> methods
- * (e.g. {@link #source(IRI)}, {@link #source(Path)},
- * {@link #source(InputStream)}), and MUST call one of the <code>target</code>
- * methods (e.g. {@link #target(Consumer)}, {@link #target(Dataset)},
- * {@link #target(Graph)}) before calling {@link #parse()} on the returned
- * RDFParserBuilder - however methods can be called in any order.
- * <p>
- * The call to {@link #parse()} returns a {@link Future}, allowing asynchronous
- * parse operations. Callers are recommended to check {@link Future#get()} to
- * ensure parsing completed successfully, or catch exceptions thrown during
- * parsing.
- * <p>
- * Setting a method that has already been set will override any existing value
- * in the returned builder - regardless of the parameter type (e.g.
- * {@link #source(IRI)} will override a previous {@link #source(Path)}. Settings
- * can be unset by passing <code>null</code> - note that this may 
- * require casting, e.g. <code>contentType( (RDFSyntax) null )</code> 
- * to undo a previous call to {@link #contentType(RDFSyntax)}.
- * <p>
- * It is undefined if a RDFParserBuilder is mutable or thread-safe, so callers
- * should always use the returned modified RDFParserBuilder from the builder
- * methods. The builder may return itself after modification, 
- * or a cloned builder with the modified settings applied. 
- * Implementations are however encouraged to be immutable,
- * thread-safe and document this. As an example starting point, see
- * {@link org.apache.commons.rdf.simple.AbstractRDFParserBuilder}.
- * <p>
- * Example usage:
- * </p>
- * 
- * <pre>
- *   Graph g1 = rDFTermFactory.createGraph();
- *   new ExampleRDFParserBuilder()
- *    	.source(Paths.get("/tmp/graph.ttl"))
- *    	.contentType(RDFSyntax.TURTLE)
- *   	.target(g1)
- *   	.parse().get(30, TimeUnit.Seconds);
- * </pre>
- *
- */
-public interface RDFParserBuilder {
-
-	/** 
-	 * The result of {@link RDFParserBuilder#parse()} indicating
-	 * parsing completed.
-	 * <p>
-	 * This is a marker interface that may be subclassed to include
-	 * parser details, e.g. warning messages or triple counts.
-	 */
-	public interface ParseResult {		
-	}
-
-	/**
-	 * Specify which {@link RDFTermFactory} to use for generating
-	 * {@link RDFTerm}s.
-	 * <p>
-	 * This option may be used together with {@link #target(Graph)} to
-	 * override the implementation's default factory and graph.
-	 * <p>
-	 * <strong>Warning:</strong> Using the same {@link RDFTermFactory} for 
-	 * multiple {@link #parse()} calls  may accidentally merge 
-	 * {@link BlankNode}s having the same label, as the parser may 
-	 * use the {@link RDFTermFactory#createBlankNode(String)} method
-	 * from the parsed blank node labels.
-	 * 
-	 * @see #target(Graph)
-	 * @param rdfTermFactory
-	 *            {@link RDFTermFactory} to use for generating RDFTerms.
-	 * @return An {@link RDFParserBuilder} that will use the specified
-	 *         rdfTermFactory
-	 */
-	RDFParserBuilder rdfTermFactory(RDFTermFactory rdfTermFactory);
-
-	/**
-	 * Specify the content type of the RDF syntax to parse.
-	 * <p>
-	 * This option can be used to select the RDFSyntax of the source, overriding
-	 * any <code>Content-Type</code> headers or equivalent.
-	 * <p>
-	 * The character set of the RDFSyntax is assumed to be
-	 * {@link StandardCharsets#UTF_8} unless overridden within the document
-	 * (e.g. <?xml version="1.0" encoding="iso-8859-1"?></code> in
-	 * {@link RDFSyntax#RDFXML}).
-	 * <p>
-	 * This method will override any contentType set with
-	 * {@link #contentType(String)}.
-	 * 
-	 * @see #contentType(String)
-	 * @param rdfSyntax
-	 *            An {@link RDFSyntax} to parse the source according to, e.g.
-	 *            {@link RDFSyntax#TURTLE}.
-	 * @throws IllegalArgumentException
-	 *             If this RDFParserBuilder does not support the specified
-	 *             RDFSyntax.
-	 * @return An {@link RDFParserBuilder} that will use the specified content
-	 *         type.
-	 */
-	RDFParserBuilder contentType(RDFSyntax rdfSyntax) throws IllegalArgumentException;
-
-	/**
-	 * Specify the content type of the RDF syntax to parse.
-	 * <p>
-	 * This option can be used to select the RDFSyntax of the source, overriding
-	 * any <code>Content-Type</code> headers or equivalent.
-	 * <p>
-	 * The content type MAY include a <code>charset</code> parameter if the RDF
-	 * media types permit it; the default charset is
-	 * {@link StandardCharsets#UTF_8} unless overridden within the document.
-	 * <p>
-	 * This method will override any contentType set with
-	 * {@link #contentType(RDFSyntax)}.
-	 * 
-	 * @see #contentType(RDFSyntax)
-	 * @param contentType
-	 *            A content-type string, e.g. <code>application/ld+json</code>
-	 *            or <code>text/turtle;charset="UTF-8"</code> as specified by
-	 *            <a href="https://tools.ietf.org/html/rfc7231#section-3.1.1.1">
-	 *            RFC7231</a>.
-	 * @return An {@link RDFParserBuilder} that will use the specified content
-	 *         type.
-	 * @throws IllegalArgumentException
-	 *             If the contentType has an invalid syntax, or this
-	 *             RDFParserBuilder does not support the specified contentType.
-	 */
-	RDFParserBuilder contentType(String contentType) throws IllegalArgumentException;
-
-	/**
-	 * Specify a {@link Graph} to add parsed triples to.
-	 * <p>
-	 * If the source supports datasets (e.g. the {@link #contentType(RDFSyntax)}
-	 * set has {@link RDFSyntax#supportsDataset} is true)), then only quads in
-	 * the <em>default graph</em> will be added to the Graph as {@link Triple}s.
-	 * <p>
-	 * It is undefined if any triples are added to the specified {@link Graph}
-	 * if {@link #parse()} throws any exceptions. (However implementations are
-	 * free to prevent this using transaction mechanisms or similar). If
-	 * {@link Future#get()} does not indicate an exception, the parser
-	 * implementation SHOULD have inserted all parsed triples to the specified
-	 * graph.
-	 * <p>
-	 * Calling this method will override any earlier targets set with
-	 * {@link #target(Graph)}, {@link #target(Consumer)} or
-	 * {@link #target(Dataset)}.
-	 * <p>
-	 * The default implementation of this method calls {@link #target(Consumer)}
-	 * with a {@link Consumer} that does {@link Graph#add(Triple)} with
-	 * {@link Quad#asTriple()} if the quad is in the default graph.
-	 * 
-	 * @param graph
-	 *            The {@link Graph} to add triples to.
-	 * @return An {@link RDFParserBuilder} that will insert triples into the
-	 *         specified graph.
-	 */
-	default RDFParserBuilder target(Graph graph) {		
-		return target(q -> { 
-			if (! q.getGraphName().isPresent()) { 
-				graph.add(q.asTriple());
-			}
-		});
-	}
-
-	/**
-	 * Specify a {@link Dataset} to add parsed quads to.
-	 * <p>
-	 * It is undefined if any quads are added to the specified
-	 * {@link Dataset} if {@link #parse()} throws any exceptions. 
-	 * (However implementations are free to prevent this using transaction 
-	 * mechanisms or similar).  On the other hand, if {@link #parse()}
-	 * does not indicate an exception, the 
-	 * implementation SHOULD have inserted all parsed quads 
-	 * to the specified dataset.
-	 * <p>
-	 * Calling this method will override any earlier targets set with 
-	 * {@link #target(Graph)}, {@link #target(Consumer)} or {@link #target(Dataset)}.
-	 * <p>
-	 * The default implementation of this method calls {@link #target(Consumer)}
-	 * with a {@link Consumer} that does {@link Dataset#add(Quad)}.
-	 * 
-	 * @param dataset
-	 *            The {@link Dataset} to add quads to.
-	 * @return An {@link RDFParserBuilder} that will insert triples into the
-	 *         specified dataset.
-	 */
-	default RDFParserBuilder target(Dataset dataset) {
-		return target(dataset::add);
-	}
-
-	/**
-	 * Specify a consumer for parsed quads.
-	 * <p>
-	 * The quads will include triples in all named graphs of the parsed 
-	 * source, including any triples in the default graph. 
-	 * When parsing a source format which do not support datasets, all quads 
-	 * delivered to the consumer will be in the default graph 
-	 * (e.g. their {@link Quad#getGraphName()} will be
-	 * as {@link Optional#empty()}), while for a source   
-	 * <p>
-	 * It is undefined if any quads are consumed if {@link #parse()} throws any
-	 * exceptions. On the other hand, if {@link #parse()} does not indicate an
-	 * exception, the implementation SHOULD have produced all parsed quads to
-	 * the specified consumer.
-	 * <p>
-	 * Calling this method will override any earlier targets set with
-	 * {@link #target(Graph)}, {@link #target(Consumer)} or
-	 * {@link #target(Dataset)}.
-	 * <p>
-	 * The consumer is not assumed to be thread safe - only one
-	 * {@link Consumer#accept(Object)} is delivered at a time for a given
-	 * {@link RDFParserBuilder#parse()} call.
-	 * <p>
-	 * This method is typically called with a functional consumer, for example:
-	 * <pre>
-	 * List<Quad> quads = new ArrayList<Quad>;
-	 * parserBuilder.target(quads::add).parse();
-	 * </pre>
-	 * 
-	 * @param consumer
-	 *            A {@link Consumer} of {@link Quad}s
-	 * @return An {@link RDFParserBuilder} that will call the consumer for into
-	 *         the specified dataset.
-	 */
-	RDFParserBuilder target(Consumer<Quad> consumer);
-	
-	/**
-	 * Specify a base IRI to use for parsing any relative IRI references.
-	 * <p>
-	 * Setting this option will override any protocol-specific base IRI (e.g.
-	 * <code>Content-Location</code> header) or the {@link #source(IRI)} IRI,
-	 * but does not override any base IRIs set within the source document (e.g.
-	 * <code>@base</code> in Turtle documents).
-	 * <p>
-	 * If the source is in a syntax that does not support relative IRI
-	 * references (e.g. {@link RDFSyntax#NTRIPLES}), setting the
-	 * <code>base</code> has no effect.
-	 * <p>
-	 * This method will override any base IRI set with {@link #base(String)}.
-	 *
-	 * @see #base(String)
-	 * @param base
-	 *            An absolute IRI to use as a base.
-	 * @return An {@link RDFParserBuilder} that will use the specified base IRI.
-	 */
-	RDFParserBuilder base(IRI base);
-
-	/**
-	 * Specify a base IRI to use for parsing any relative IRI references.
-	 * <p>
-	 * Setting this option will override any protocol-specific base IRI (e.g.
-	 * <code>Content-Location</code> header) or the {@link #source(IRI)} IRI,
-	 * but does not override any base IRIs set within the source document (e.g.
-	 * <code>@base</code> in Turtle documents).
-	 * <p>
-	 * If the source is in a syntax that does not support relative IRI
-	 * references (e.g. {@link RDFSyntax#NTRIPLES}), setting the
-	 * <code>base</code> has no effect.
-	 * <p>
-	 * This method will override any base IRI set with {@link #base(IRI)}.
-	 *
-	 * @see #base(IRI)
-	 * @param base
-	 *            An absolute IRI to use as a base.
-	 * @return An {@link RDFParserBuilder} that will use the specified base IRI.
-	 * @throws IllegalArgumentException
-	 *             If the base is not a valid absolute IRI string
-	 */
-	RDFParserBuilder base(String base) throws IllegalArgumentException;
-
-	/**
-	 * Specify a source {@link InputStream} to parse.
-	 * <p>
-	 * The source set will not be read before the call to {@link #parse()}.
-	 * <p>
-	 * The InputStream will not be closed after parsing. The InputStream does
-	 * not need to support {@link InputStream#markSupported()}.
-	 * <p>
-	 * The parser might not consume the complete stream (e.g. an RDF/XML parser
-	 * may not read beyond the closing tag of
-	 * <code>&lt;/rdf:Description&gt;</code>).
-	 * <p>
-	 * The {@link #contentType(RDFSyntax)} or {@link #contentType(String)}
-	 * SHOULD be set before calling {@link #parse()}.
-	 * <p>
-	 * The character set is assumed to be {@link StandardCharsets#UTF_8} unless
-	 * the {@link #contentType(String)} specifies otherwise or the document
-	 * declares its own charset (e.g. RDF/XML with a
-	 * <code>&lt;?xml encoding="iso-8859-1"&gt;</code> header).
-	 * <p>
-	 * The {@link #base(IRI)} or {@link #base(String)} MUST be set before
-	 * calling {@link #parse()}, unless the RDF syntax does not permit relative
-	 * IRIs (e.g. {@link RDFSyntax#NTRIPLES}).
-	 * <p>
-	 * This method will override any source set with {@link #source(IRI)},
-	 * {@link #source(Path)} or {@link #source(String)}.
-	 * 
-	 * @param inputStream
-	 *            An InputStream to consume
-	 * @return An {@link RDFParserBuilder} that will use the specified source.
-	 */
-	RDFParserBuilder source(InputStream inputStream);
-
-	/**
-	 * Specify a source file {@link Path} to parse.
-	 * <p>
-	 * The source set will not be read before the call to {@link #parse()}.
-	 * <p>
-	 * The {@link #contentType(RDFSyntax)} or {@link #contentType(String)}
-	 * SHOULD be set before calling {@link #parse()}.
-	 * <p>
-	 * The character set is assumed to be {@link StandardCharsets#UTF_8} unless
-	 * the {@link #contentType(String)} specifies otherwise or the document
-	 * declares its own charset (e.g. RDF/XML with a
-	 * <code>&lt;?xml encoding="iso-8859-1"&gt;</code> header).
-	 * <p>
-	 * The {@link #base(IRI)} or {@link #base(String)} MAY be set before calling
-	 * {@link #parse()}, otherwise {@link Path#toUri()} will be used as the base
-	 * IRI.
-	 * <p>
-	 * This method will override any source set with {@link #source(IRI)},
-	 * {@link #source(InputStream)} or {@link #source(String)}.
-	 * 
-	 * @param file
-	 *            A Path for a file to parse
-	 * @return An {@link RDFParserBuilder} that will use the specified source.
-	 */
-	RDFParserBuilder source(Path file);
-
-	/**
-	 * Specify an absolute source {@link IRI} to retrieve and parse.
-	 * <p>
-	 * The source set will not be read before the call to {@link #parse()}.
-	 * <p>
-	 * If this builder does not support the given IRI protocol (e.g.
-	 * <code>urn:uuid:ce667463-c5ab-4c23-9b64-701d055c4890</code>), this method
-	 * should succeed, while the {@link #parse()} should throw an
-	 * {@link IOException}.
-	 * <p>
-	 * The {@link #contentType(RDFSyntax)} or {@link #contentType(String)} MAY
-	 * be set before calling {@link #parse()}, in which case that type MAY be
-	 * used for content negotiation (e.g. <code>Accept</code> header in HTTP),
-	 * and SHOULD be used for selecting the RDFSyntax.
-	 * <p>
-	 * The character set is assumed to be {@link StandardCharsets#UTF_8} unless
-	 * the protocol's equivalent of <code>Content-Type</code> specifies
-	 * otherwise or the document declares its own charset (e.g. RDF/XML with a
-	 * <code>&lt;?xml encoding="iso-8859-1"&gt;</code> header).
-	 * <p>
-	 * The {@link #base(IRI)} or {@link #base(String)} MAY be set before calling
-	 * {@link #parse()}, otherwise the source IRI will be used as the base IRI.
-	 * <p>
-	 * This method will override any source set with {@link #source(Path)},
-	 * {@link #source(InputStream)} or {@link #source(String)}.
-	 * 
-	 * @param iri
-	 *            An IRI to retrieve and parse
-	 * @return An {@link RDFParserBuilder} that will use the specified source.
-	 */
-	RDFParserBuilder source(IRI iri);
-
-	/**
-	 * Specify an absolute source IRI to retrieve and parse.
-	 * <p>
-	 * The source set will not be read before the call to {@link #parse()}.
-	 * <p>
-	 * If this builder does not support the given IRI (e.g.
-	 * <code>urn:uuid:ce667463-c5ab-4c23-9b64-701d055c4890</code>), this method
-	 * should succeed, while the {@link #parse()} should throw an
-	 * {@link IOException}.
-	 * <p>
-	 * The {@link #contentType(RDFSyntax)} or {@link #contentType(String)} MAY
-	 * be set before calling {@link #parse()}, in which case that type MAY be
-	 * used for content negotiation (e.g. <code>Accept</code> header in HTTP),
-	 * and SHOULD be used for selecting the RDFSyntax.
-	 * <p>
-	 * The character set is assumed to be {@link StandardCharsets#UTF_8} unless
-	 * the protocol's equivalent of <code>Content-Type</code> specifies
-	 * otherwise or the document declares its own charset (e.g. RDF/XML with a
-	 * <code>&lt;?xml encoding="iso-8859-1"&gt;</code> header).
-	 * <p>
-	 * The {@link #base(IRI)} or {@link #base(String)} MAY be set before calling
-	 * {@link #parse()}, otherwise the source IRI will be used as the base IRI.
-	 * <p>
-	 * This method will override any source set with {@link #source(Path)},
-	 * {@link #source(InputStream)} or {@link #source(IRI)}.
-	 * 
-	 * @param iri
-	 *            An IRI to retrieve and parse
-	 * @return An {@link RDFParserBuilder} that will use the specified source.
-	 * @throws IllegalArgumentException
-	 *             If the base is not a valid absolute IRI string
-	 * 
-	 */
-	RDFParserBuilder source(String iri) throws IllegalArgumentException;
-
-	/**
-	 * Parse the specified source.
-	 * <p>
-	 * A source method (e.g. {@link #source(InputStream)}, {@link #source(IRI)},
-	 * {@link #source(Path)}, {@link #source(String)} or an equivalent subclass
-	 * method) MUST have been called before calling this method, otherwise an
-	 * {@link IllegalStateException} will be thrown.
-	 * <p>
-	 * A target method (e.g. {@link #target(Consumer)}, {@link #target(Dataset)},
-	 * {@link #target(Graph)} or an equivalent subclass method) MUST have been
-	 * called before calling parse(), otherwise an
-	 * {@link IllegalStateException} will be thrown.
-	 * <p>
-	 * It is undefined if this method is thread-safe, however the
-	 * {@link RDFParserBuilder} may be reused (e.g. setting a different source)
-	 * as soon as the {@link Future} has been returned from this method.
-	 * <p>
-	 * The RDFParserBuilder SHOULD perform the parsing as an asynchronous
-	 * operation, and return the {@link Future} as soon as preliminary checks
-	 * (such as validity of the {@link #source(IRI)} and
-	 * {@link #contentType(RDFSyntax)} settings) have finished. The future
-	 * SHOULD not mark {@link Future#isDone()} before parsing is complete. A
-	 * synchronous implementation MAY be blocking on the <code>parse()</code>
-	 * call and return a Future that is already {@link Future#isDone()}.
-	 * <p>
-	 * The returned {@link Future} contains a {@link ParseResult}. 
-	 * Implementations may subclass this interface to provide any 
-	 * parser details, e.g. list of warnings. <code>null</code> is a
-	 * possible return value if no details are available, but 
-	 * parsing succeeded.
-	 * <p>
-	 * If an exception occurs during parsing, (e.g. {@link IOException} or
-	 * {@link org.apache.commons.rdf.simple.RDFParseException}), 
-	 * it should be indicated as the
-	 * {@link java.util.concurrent.ExecutionException#getCause()} in the
-	 * {@link java.util.concurrent.ExecutionException} thrown on
-	 * {@link Future#get()}.
-	 * 
-	 * @return A Future that will return the populated {@link Graph} when the
-	 *         parsing has finished.
-	 * @throws IOException
-	 *             If an error occurred while starting to read the source (e.g.
-	 *             file not found, unsupported IRI protocol). Note that IO
-	 *             errors during parsing would instead be the
-	 *             {@link java.util.concurrent.ExecutionException#getCause()} of
-	 *             the {@link java.util.concurrent.ExecutionException} thrown on
-	 *             {@link Future#get()}.
-	 * @throws IllegalStateException
-	 *             If the builder is in an invalid state, e.g. a
-	 *             <code>source</code> has not been set.
-	 */
-	Future<? extends ParseResult> parse() throws IOException, IllegalStateException;
-}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/10d27cde/api/src/main/java/org/apache/commons/rdf/experimental/RDFParser.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/experimental/RDFParser.java b/api/src/main/java/org/apache/commons/rdf/experimental/RDFParser.java
new file mode 100644
index 0000000..dd6bcf0
--- /dev/null
+++ b/api/src/main/java/org/apache/commons/rdf/experimental/RDFParser.java
@@ -0,0 +1,495 @@
+/**
+ * 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.experimental;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Path;
+import java.util.Optional;
+import java.util.concurrent.Future;
+import java.util.function.Consumer;
+
+import org.apache.commons.rdf.api.BlankNode;
+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.RDFSyntax;
+import org.apache.commons.rdf.api.RDFTerm;
+import org.apache.commons.rdf.api.RDFTermFactory;
+import org.apache.commons.rdf.api.Triple;
+
+/**
+ * Parse an RDF source into a target (e.g. a Graph/Dataset).
+ * <h2>Experimental</h2>
+ * This interface (and its implementations) should be considered <strong>at
+ * risk</strong>; they might change or be removed in the next minor update of
+ * Commons RDF. It may move to the the  {@link org.apache.commons.rdf.api}
+ * package when it has stabilized.
+ * <h2>Description</h2>
+ * <p>
+ * This interface follows the
+ * <a href="https://en.wikipedia.org/wiki/Builder_pattern">Builder pattern</a>,
+ * allowing to set parser settings like {@link #contentType(RDFSyntax)} and
+ * {@link #base(IRI)}. A caller MUST call one of the <code>source</code> methods
+ * (e.g. {@link #source(IRI)}, {@link #source(Path)},
+ * {@link #source(InputStream)}), and MUST call one of the <code>target</code>
+ * methods (e.g. {@link #target(Consumer)}, {@link #target(Dataset)},
+ * {@link #target(Graph)}) before calling {@link #parse()} on the returned
+ * RDFParser - however methods can be called in any order.
+ * <p>
+ * The call to {@link #parse()} returns a {@link Future}, allowing asynchronous
+ * parse operations. Callers are recommended to check {@link Future#get()} to
+ * ensure parsing completed successfully, or catch exceptions thrown during
+ * parsing.
+ * <p>
+ * Setting a method that has already been set will override any existing value
+ * in the returned builder - regardless of the parameter type (e.g.
+ * {@link #source(IRI)} will override a previous {@link #source(Path)}. Settings
+ * can be unset by passing <code>null</code> - note that this may 
+ * require casting, e.g. <code>contentType( (RDFSyntax) null )</code> 
+ * to undo a previous call to {@link #contentType(RDFSyntax)}.
+ * <p>
+ * It is undefined if a RDFParser is mutable or thread-safe, so callers
+ * should always use the returned modified RDFParser from the builder
+ * methods. The builder may return itself after modification, 
+ * or a cloned builder with the modified settings applied. 
+ * Implementations are however encouraged to be immutable,
+ * thread-safe and document this. As an example starting point, see
+ * {@link org.apache.commons.rdf.simple.AbstractRDFParserBuilder}.
+ * <p>
+ * Example usage:
+ * </p>
+ * 
+ * <pre>
+ *   Graph g1 = rDFTermFactory.createGraph();
+ *   new ExampleRDFParserBuilder()
+ *    	.source(Paths.get("/tmp/graph.ttl"))
+ *    	.contentType(RDFSyntax.TURTLE)
+ *   	.target(g1)
+ *   	.parse().get(30, TimeUnit.Seconds);
+ * </pre>
+ *
+ */
+public interface RDFParser {
+
+	/** 
+	 * The result of {@link RDFParser#parse()} indicating
+	 * parsing completed.
+	 * <p>
+	 * This is a marker interface that may be subclassed to include
+	 * parser details, e.g. warning messages or triple counts.
+	 */
+	public interface ParseResult {		
+	}
+
+	/**
+	 * Specify which {@link RDFTermFactory} to use for generating
+	 * {@link RDFTerm}s.
+	 * <p>
+	 * This option may be used together with {@link #target(Graph)} to
+	 * override the implementation's default factory and graph.
+	 * <p>
+	 * <strong>Warning:</strong> Using the same {@link RDFTermFactory} for 
+	 * multiple {@link #parse()} calls  may accidentally merge 
+	 * {@link BlankNode}s having the same label, as the parser may 
+	 * use the {@link RDFTermFactory#createBlankNode(String)} method
+	 * from the parsed blank node labels.
+	 * 
+	 * @see #target(Graph)
+	 * @param rdfTermFactory
+	 *            {@link RDFTermFactory} to use for generating RDFTerms.
+	 * @return An {@link RDFParser} that will use the specified
+	 *         rdfTermFactory
+	 */
+	RDFParser rdfTermFactory(RDFTermFactory rdfTermFactory);
+
+	/**
+	 * Specify the content type of the RDF syntax to parse.
+	 * <p>
+	 * This option can be used to select the RDFSyntax of the source, overriding
+	 * any <code>Content-Type</code> headers or equivalent.
+	 * <p>
+	 * The character set of the RDFSyntax is assumed to be
+	 * {@link StandardCharsets#UTF_8} unless overridden within the document
+	 * (e.g. <?xml version="1.0" encoding="iso-8859-1"?></code> in
+	 * {@link RDFSyntax#RDFXML}).
+	 * <p>
+	 * This method will override any contentType set with
+	 * {@link #contentType(String)}.
+	 * 
+	 * @see #contentType(String)
+	 * @param rdfSyntax
+	 *            An {@link RDFSyntax} to parse the source according to, e.g.
+	 *            {@link RDFSyntax#TURTLE}.
+	 * @throws IllegalArgumentException
+	 *             If this RDFParser does not support the specified
+	 *             RDFSyntax.
+	 * @return An {@link RDFParser} that will use the specified content
+	 *         type.
+	 */
+	RDFParser contentType(RDFSyntax rdfSyntax) throws IllegalArgumentException;
+
+	/**
+	 * Specify the content type of the RDF syntax to parse.
+	 * <p>
+	 * This option can be used to select the RDFSyntax of the source, overriding
+	 * any <code>Content-Type</code> headers or equivalent.
+	 * <p>
+	 * The content type MAY include a <code>charset</code> parameter if the RDF
+	 * media types permit it; the default charset is
+	 * {@link StandardCharsets#UTF_8} unless overridden within the document.
+	 * <p>
+	 * This method will override any contentType set with
+	 * {@link #contentType(RDFSyntax)}.
+	 * 
+	 * @see #contentType(RDFSyntax)
+	 * @param contentType
+	 *            A content-type string, e.g. <code>application/ld+json</code>
+	 *            or <code>text/turtle;charset="UTF-8"</code> as specified by
+	 *            <a href="https://tools.ietf.org/html/rfc7231#section-3.1.1.1">
+	 *            RFC7231</a>.
+	 * @return An {@link RDFParser} that will use the specified content
+	 *         type.
+	 * @throws IllegalArgumentException
+	 *             If the contentType has an invalid syntax, or this
+	 *             RDFParser does not support the specified contentType.
+	 */
+	RDFParser contentType(String contentType) throws IllegalArgumentException;
+
+	/**
+	 * Specify a {@link Graph} to add parsed triples to.
+	 * <p>
+	 * If the source supports datasets (e.g. the {@link #contentType(RDFSyntax)}
+	 * set has {@link RDFSyntax#supportsDataset} is true)), then only quads in
+	 * the <em>default graph</em> will be added to the Graph as {@link Triple}s.
+	 * <p>
+	 * It is undefined if any triples are added to the specified {@link Graph}
+	 * if {@link #parse()} throws any exceptions. (However implementations are
+	 * free to prevent this using transaction mechanisms or similar). If
+	 * {@link Future#get()} does not indicate an exception, the parser
+	 * implementation SHOULD have inserted all parsed triples to the specified
+	 * graph.
+	 * <p>
+	 * Calling this method will override any earlier targets set with
+	 * {@link #target(Graph)}, {@link #target(Consumer)} or
+	 * {@link #target(Dataset)}.
+	 * <p>
+	 * The default implementation of this method calls {@link #target(Consumer)}
+	 * with a {@link Consumer} that does {@link Graph#add(Triple)} with
+	 * {@link Quad#asTriple()} if the quad is in the default graph.
+	 * 
+	 * @param graph
+	 *            The {@link Graph} to add triples to.
+	 * @return An {@link RDFParser} that will insert triples into the
+	 *         specified graph.
+	 */
+	default RDFParser target(Graph graph) {		
+		return target(q -> { 
+			if (! q.getGraphName().isPresent()) { 
+				graph.add(q.asTriple());
+			}
+		});
+	}
+
+	/**
+	 * Specify a {@link Dataset} to add parsed quads to.
+	 * <p>
+	 * It is undefined if any quads are added to the specified
+	 * {@link Dataset} if {@link #parse()} throws any exceptions. 
+	 * (However implementations are free to prevent this using transaction 
+	 * mechanisms or similar).  On the other hand, if {@link #parse()}
+	 * does not indicate an exception, the 
+	 * implementation SHOULD have inserted all parsed quads 
+	 * to the specified dataset.
+	 * <p>
+	 * Calling this method will override any earlier targets set with 
+	 * {@link #target(Graph)}, {@link #target(Consumer)} or {@link #target(Dataset)}.
+	 * <p>
+	 * The default implementation of this method calls {@link #target(Consumer)}
+	 * with a {@link Consumer} that does {@link Dataset#add(Quad)}.
+	 * 
+	 * @param dataset
+	 *            The {@link Dataset} to add quads to.
+	 * @return An {@link RDFParser} that will insert triples into the
+	 *         specified dataset.
+	 */
+	default RDFParser target(Dataset dataset) {
+		return target(dataset::add);
+	}
+
+	/**
+	 * Specify a consumer for parsed quads.
+	 * <p>
+	 * The quads will include triples in all named graphs of the parsed 
+	 * source, including any triples in the default graph. 
+	 * When parsing a source format which do not support datasets, all quads 
+	 * delivered to the consumer will be in the default graph 
+	 * (e.g. their {@link Quad#getGraphName()} will be
+	 * as {@link Optional#empty()}), while for a source   
+	 * <p>
+	 * It is undefined if any quads are consumed if {@link #parse()} throws any
+	 * exceptions. On the other hand, if {@link #parse()} does not indicate an
+	 * exception, the implementation SHOULD have produced all parsed quads to
+	 * the specified consumer.
+	 * <p>
+	 * Calling this method will override any earlier targets set with
+	 * {@link #target(Graph)}, {@link #target(Consumer)} or
+	 * {@link #target(Dataset)}.
+	 * <p>
+	 * The consumer is not assumed to be thread safe - only one
+	 * {@link Consumer#accept(Object)} is delivered at a time for a given
+	 * {@link RDFParser#parse()} call.
+	 * <p>
+	 * This method is typically called with a functional consumer, for example:
+	 * <pre>
+	 * List<Quad> quads = new ArrayList<Quad>;
+	 * parserBuilder.target(quads::add).parse();
+	 * </pre>
+	 * 
+	 * @param consumer
+	 *            A {@link Consumer} of {@link Quad}s
+	 * @return An {@link RDFParser} that will call the consumer for into
+	 *         the specified dataset.
+	 */
+	RDFParser target(Consumer<Quad> consumer);
+	
+	/**
+	 * Specify a base IRI to use for parsing any relative IRI references.
+	 * <p>
+	 * Setting this option will override any protocol-specific base IRI (e.g.
+	 * <code>Content-Location</code> header) or the {@link #source(IRI)} IRI,
+	 * but does not override any base IRIs set within the source document (e.g.
+	 * <code>@base</code> in Turtle documents).
+	 * <p>
+	 * If the source is in a syntax that does not support relative IRI
+	 * references (e.g. {@link RDFSyntax#NTRIPLES}), setting the
+	 * <code>base</code> has no effect.
+	 * <p>
+	 * This method will override any base IRI set with {@link #base(String)}.
+	 *
+	 * @see #base(String)
+	 * @param base
+	 *            An absolute IRI to use as a base.
+	 * @return An {@link RDFParser} that will use the specified base IRI.
+	 */
+	RDFParser base(IRI base);
+
+	/**
+	 * Specify a base IRI to use for parsing any relative IRI references.
+	 * <p>
+	 * Setting this option will override any protocol-specific base IRI (e.g.
+	 * <code>Content-Location</code> header) or the {@link #source(IRI)} IRI,
+	 * but does not override any base IRIs set within the source document (e.g.
+	 * <code>@base</code> in Turtle documents).
+	 * <p>
+	 * If the source is in a syntax that does not support relative IRI
+	 * references (e.g. {@link RDFSyntax#NTRIPLES}), setting the
+	 * <code>base</code> has no effect.
+	 * <p>
+	 * This method will override any base IRI set with {@link #base(IRI)}.
+	 *
+	 * @see #base(IRI)
+	 * @param base
+	 *            An absolute IRI to use as a base.
+	 * @return An {@link RDFParser} that will use the specified base IRI.
+	 * @throws IllegalArgumentException
+	 *             If the base is not a valid absolute IRI string
+	 */
+	RDFParser base(String base) throws IllegalArgumentException;
+
+	/**
+	 * Specify a source {@link InputStream} to parse.
+	 * <p>
+	 * The source set will not be read before the call to {@link #parse()}.
+	 * <p>
+	 * The InputStream will not be closed after parsing. The InputStream does
+	 * not need to support {@link InputStream#markSupported()}.
+	 * <p>
+	 * The parser might not consume the complete stream (e.g. an RDF/XML parser
+	 * may not read beyond the closing tag of
+	 * <code>&lt;/rdf:Description&gt;</code>).
+	 * <p>
+	 * The {@link #contentType(RDFSyntax)} or {@link #contentType(String)}
+	 * SHOULD be set before calling {@link #parse()}.
+	 * <p>
+	 * The character set is assumed to be {@link StandardCharsets#UTF_8} unless
+	 * the {@link #contentType(String)} specifies otherwise or the document
+	 * declares its own charset (e.g. RDF/XML with a
+	 * <code>&lt;?xml encoding="iso-8859-1"&gt;</code> header).
+	 * <p>
+	 * The {@link #base(IRI)} or {@link #base(String)} MUST be set before
+	 * calling {@link #parse()}, unless the RDF syntax does not permit relative
+	 * IRIs (e.g. {@link RDFSyntax#NTRIPLES}).
+	 * <p>
+	 * This method will override any source set with {@link #source(IRI)},
+	 * {@link #source(Path)} or {@link #source(String)}.
+	 * 
+	 * @param inputStream
+	 *            An InputStream to consume
+	 * @return An {@link RDFParser} that will use the specified source.
+	 */
+	RDFParser source(InputStream inputStream);
+
+	/**
+	 * Specify a source file {@link Path} to parse.
+	 * <p>
+	 * The source set will not be read before the call to {@link #parse()}.
+	 * <p>
+	 * The {@link #contentType(RDFSyntax)} or {@link #contentType(String)}
+	 * SHOULD be set before calling {@link #parse()}.
+	 * <p>
+	 * The character set is assumed to be {@link StandardCharsets#UTF_8} unless
+	 * the {@link #contentType(String)} specifies otherwise or the document
+	 * declares its own charset (e.g. RDF/XML with a
+	 * <code>&lt;?xml encoding="iso-8859-1"&gt;</code> header).
+	 * <p>
+	 * The {@link #base(IRI)} or {@link #base(String)} MAY be set before calling
+	 * {@link #parse()}, otherwise {@link Path#toUri()} will be used as the base
+	 * IRI.
+	 * <p>
+	 * This method will override any source set with {@link #source(IRI)},
+	 * {@link #source(InputStream)} or {@link #source(String)}.
+	 * 
+	 * @param file
+	 *            A Path for a file to parse
+	 * @return An {@link RDFParser} that will use the specified source.
+	 */
+	RDFParser source(Path file);
+
+	/**
+	 * Specify an absolute source {@link IRI} to retrieve and parse.
+	 * <p>
+	 * The source set will not be read before the call to {@link #parse()}.
+	 * <p>
+	 * If this builder does not support the given IRI protocol (e.g.
+	 * <code>urn:uuid:ce667463-c5ab-4c23-9b64-701d055c4890</code>), this method
+	 * should succeed, while the {@link #parse()} should throw an
+	 * {@link IOException}.
+	 * <p>
+	 * The {@link #contentType(RDFSyntax)} or {@link #contentType(String)} MAY
+	 * be set before calling {@link #parse()}, in which case that type MAY be
+	 * used for content negotiation (e.g. <code>Accept</code> header in HTTP),
+	 * and SHOULD be used for selecting the RDFSyntax.
+	 * <p>
+	 * The character set is assumed to be {@link StandardCharsets#UTF_8} unless
+	 * the protocol's equivalent of <code>Content-Type</code> specifies
+	 * otherwise or the document declares its own charset (e.g. RDF/XML with a
+	 * <code>&lt;?xml encoding="iso-8859-1"&gt;</code> header).
+	 * <p>
+	 * The {@link #base(IRI)} or {@link #base(String)} MAY be set before calling
+	 * {@link #parse()}, otherwise the source IRI will be used as the base IRI.
+	 * <p>
+	 * This method will override any source set with {@link #source(Path)},
+	 * {@link #source(InputStream)} or {@link #source(String)}.
+	 * 
+	 * @param iri
+	 *            An IRI to retrieve and parse
+	 * @return An {@link RDFParser} that will use the specified source.
+	 */
+	RDFParser source(IRI iri);
+
+	/**
+	 * Specify an absolute source IRI to retrieve and parse.
+	 * <p>
+	 * The source set will not be read before the call to {@link #parse()}.
+	 * <p>
+	 * If this builder does not support the given IRI (e.g.
+	 * <code>urn:uuid:ce667463-c5ab-4c23-9b64-701d055c4890</code>), this method
+	 * should succeed, while the {@link #parse()} should throw an
+	 * {@link IOException}.
+	 * <p>
+	 * The {@link #contentType(RDFSyntax)} or {@link #contentType(String)} MAY
+	 * be set before calling {@link #parse()}, in which case that type MAY be
+	 * used for content negotiation (e.g. <code>Accept</code> header in HTTP),
+	 * and SHOULD be used for selecting the RDFSyntax.
+	 * <p>
+	 * The character set is assumed to be {@link StandardCharsets#UTF_8} unless
+	 * the protocol's equivalent of <code>Content-Type</code> specifies
+	 * otherwise or the document declares its own charset (e.g. RDF/XML with a
+	 * <code>&lt;?xml encoding="iso-8859-1"&gt;</code> header).
+	 * <p>
+	 * The {@link #base(IRI)} or {@link #base(String)} MAY be set before calling
+	 * {@link #parse()}, otherwise the source IRI will be used as the base IRI.
+	 * <p>
+	 * This method will override any source set with {@link #source(Path)},
+	 * {@link #source(InputStream)} or {@link #source(IRI)}.
+	 * 
+	 * @param iri
+	 *            An IRI to retrieve and parse
+	 * @return An {@link RDFParser} that will use the specified source.
+	 * @throws IllegalArgumentException
+	 *             If the base is not a valid absolute IRI string
+	 * 
+	 */
+	RDFParser source(String iri) throws IllegalArgumentException;
+
+	/**
+	 * Parse the specified source.
+	 * <p>
+	 * A source method (e.g. {@link #source(InputStream)}, {@link #source(IRI)},
+	 * {@link #source(Path)}, {@link #source(String)} or an equivalent subclass
+	 * method) MUST have been called before calling this method, otherwise an
+	 * {@link IllegalStateException} will be thrown.
+	 * <p>
+	 * A target method (e.g. {@link #target(Consumer)}, {@link #target(Dataset)},
+	 * {@link #target(Graph)} or an equivalent subclass method) MUST have been
+	 * called before calling parse(), otherwise an
+	 * {@link IllegalStateException} will be thrown.
+	 * <p>
+	 * It is undefined if this method is thread-safe, however the
+	 * {@link RDFParser} may be reused (e.g. setting a different source)
+	 * as soon as the {@link Future} has been returned from this method.
+	 * <p>
+	 * The RDFParser SHOULD perform the parsing as an asynchronous
+	 * operation, and return the {@link Future} as soon as preliminary checks
+	 * (such as validity of the {@link #source(IRI)} and
+	 * {@link #contentType(RDFSyntax)} settings) have finished. The future
+	 * SHOULD not mark {@link Future#isDone()} before parsing is complete. A
+	 * synchronous implementation MAY be blocking on the <code>parse()</code>
+	 * call and return a Future that is already {@link Future#isDone()}.
+	 * <p>
+	 * The returned {@link Future} contains a {@link ParseResult}. 
+	 * Implementations may subclass this interface to provide any 
+	 * parser details, e.g. list of warnings. <code>null</code> is a
+	 * possible return value if no details are available, but 
+	 * parsing succeeded.
+	 * <p>
+	 * If an exception occurs during parsing, (e.g. {@link IOException} or
+	 * {@link org.apache.commons.rdf.simple.RDFParseException}), 
+	 * it should be indicated as the
+	 * {@link java.util.concurrent.ExecutionException#getCause()} in the
+	 * {@link java.util.concurrent.ExecutionException} thrown on
+	 * {@link Future#get()}.
+	 * 
+	 * @return A Future that will return the populated {@link Graph} when the
+	 *         parsing has finished.
+	 * @throws IOException
+	 *             If an error occurred while starting to read the source (e.g.
+	 *             file not found, unsupported IRI protocol). Note that IO
+	 *             errors during parsing would instead be the
+	 *             {@link java.util.concurrent.ExecutionException#getCause()} of
+	 *             the {@link java.util.concurrent.ExecutionException} thrown on
+	 *             {@link Future#get()}.
+	 * @throws IllegalStateException
+	 *             If the builder is in an invalid state, e.g. a
+	 *             <code>source</code> has not been set.
+	 */
+	Future<? extends ParseResult> parse() throws IOException, IllegalStateException;
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/10d27cde/api/src/main/java/org/apache/commons/rdf/experimental/package-info.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/experimental/package-info.java b/api/src/main/java/org/apache/commons/rdf/experimental/package-info.java
new file mode 100644
index 0000000..5f24ddc
--- /dev/null
+++ b/api/src/main/java/org/apache/commons/rdf/experimental/package-info.java
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+/**
+ * Experimental Commons RDF features.
+ * <p>
+ * Interfaces/classes in this package should be considered <strong>at
+ * risk</strong>; they might change or be removed in the next minor update of
+ * Commons RDF.
+ * <p>
+ * When class/interface has stabilized, it will move to the
+ * {@link org.apache.commons.rdf.api} package.
+ * <p>
+ * <ul>
+ * <li>{@link RDFParser} - a builder-like interface for parsing RDF to a
+ * {@link org.apache.commons.rdf.api.Graph} or
+ * {@link org.apache.commons.rdf.api.Dataset}.</li>
+ * </ul>
+ */
+package org.apache.commons.rdf.experimental;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/10d27cde/api/src/test/resources/example-rdf/example.jsonld
----------------------------------------------------------------------
diff --git a/api/src/test/resources/example-rdf/example.jsonld b/api/src/test/resources/example-rdf/example.jsonld
new file mode 100644
index 0000000..d6fb670
--- /dev/null
+++ b/api/src/test/resources/example-rdf/example.jsonld
@@ -0,0 +1,25 @@
+{
+  "@graph" : [ {
+    "@id" : "_:b0",
+    "license" : "http://www.apache.org/licenses/LICENSE-2.0",
+    "rights" : {
+      "@language" : "en",
+      "@value" : "Licensed to the Apache Software Foundation (ASF) under one\n or more contributor license agreements. See the NOTICE file\n distributed with this work for additional information\n regarding copyright ownership. The ASF licenses this file\n to you under the Apache License, Version 2.0 (the\n \"License\"); you may not use this file except in compliance\n with the License.  You may obtain a copy of the License at\n \n http://www.apache.org/licenses/LICENSE-2.0\n \n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n"
+    }
+  }, {
+    "@graph" : [ {
+      "@id" : "_:b0",
+      "license" : "http://example.com/LICENSE"
+    } ],
+    "@id" : "http://example.com"
+  } ],
+  "@context" : {
+    "rights" : {
+      "@id" : "http://purl.org/dc/terms/rights"
+    },
+    "license" : {
+      "@id" : "http://purl.org/dc/terms/license",
+      "@type" : "@id"
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/10d27cde/api/src/test/resources/example-rdf/example.nq
----------------------------------------------------------------------
diff --git a/api/src/test/resources/example-rdf/example.nq b/api/src/test/resources/example-rdf/example.nq
new file mode 100644
index 0000000..9c5e749
--- /dev/null
+++ b/api/src/test/resources/example-rdf/example.nq
@@ -0,0 +1,3 @@
+_:b1 <http://purl.org/dc/terms/license> <http://www.apache.org/licenses/LICENSE-2.0> .
+_:b1 <http://purl.org/dc/terms/rights> "Licensed to the Apache Software Foundation (ASF) under one\n or more contributor license agreements. See the NOTICE file\n distributed with this work for additional information\n regarding copyright ownership. The ASF licenses this file\n to you under the Apache License, Version 2.0 (the\n \"License\"); you may not use this file except in compliance\n with the License.  You may obtain a copy of the License at\n \n http://www.apache.org/licenses/LICENSE-2.0\n \n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n"@en .
+_:b1 <http://purl.org/dc/terms/license> <http://example.com/LICENSE> <http://example.com> .

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/10d27cde/api/src/test/resources/example-rdf/example.nt
----------------------------------------------------------------------
diff --git a/api/src/test/resources/example-rdf/example.nt b/api/src/test/resources/example-rdf/example.nt
new file mode 100644
index 0000000..53d3f94
--- /dev/null
+++ b/api/src/test/resources/example-rdf/example.nt
@@ -0,0 +1,2 @@
+_:b1 <http://purl.org/dc/terms/license> <http://www.apache.org/licenses/LICENSE-2.0> .
+_:b1 <http://purl.org/dc/terms/rights> "Licensed to the Apache Software Foundation (ASF) under one\n or more contributor license agreements. See the NOTICE file\n distributed with this work for additional information\n regarding copyright ownership. The ASF licenses this file\n to you under the Apache License, Version 2.0 (the\n \"License\"); you may not use this file except in compliance\n with the License.  You may obtain a copy of the License at\n \n http://www.apache.org/licenses/LICENSE-2.0\n \n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n"@en .

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/10d27cde/api/src/test/resources/example-rdf/example.rdf
----------------------------------------------------------------------
diff --git a/api/src/test/resources/example-rdf/example.rdf b/api/src/test/resources/example-rdf/example.rdf
new file mode 100644
index 0000000..44adfbc
--- /dev/null
+++ b/api/src/test/resources/example-rdf/example.rdf
@@ -0,0 +1,23 @@
+<rdf:RDF
+    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+    xmlns:j.0="http://purl.org/dc/terms/">
+  <rdf:Description>
+    <j.0:rights xml:lang="en">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.
+</j.0:rights>
+    <j.0:license rdf:resource="http://www.apache.org/licenses/LICENSE-2.0"/>
+  </rdf:Description>
+</rdf:RDF>

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/10d27cde/api/src/test/resources/example-rdf/example.trig
----------------------------------------------------------------------
diff --git a/api/src/test/resources/example-rdf/example.trig b/api/src/test/resources/example-rdf/example.trig
new file mode 100644
index 0000000..9d433ce
--- /dev/null
+++ b/api/src/test/resources/example-rdf/example.trig
@@ -0,0 +1,3 @@
+{ _:b0    <http://purl.org/dc/terms/license>  <http://www.apache.org/licenses/LICENSE-2.0> ;
+          <http://purl.org/dc/terms/rights>  "Licensed to the Apache Software Foundation (ASF) under one\n or more contributor license agreements. See the NOTICE file\n distributed with this work for additional information\n regarding copyright ownership. The ASF licenses this file\n to you under the Apache License, Version 2.0 (the\n \"License\"); you may not use this file except in compliance\n with the License.  You may obtain a copy of the License at\n \n http://www.apache.org/licenses/LICENSE-2.0\n \n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n"@en .
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/10d27cde/api/src/test/resources/example-rdf/example.ttl
----------------------------------------------------------------------
diff --git a/api/src/test/resources/example-rdf/example.ttl b/api/src/test/resources/example-rdf/example.ttl
new file mode 100644
index 0000000..48b97af
--- /dev/null
+++ b/api/src/test/resources/example-rdf/example.ttl
@@ -0,0 +1,2 @@
+_:b0    <http://purl.org/dc/terms/license>  <http://www.apache.org/licenses/LICENSE-2.0> ;
+        <http://purl.org/dc/terms/rights>  "Licensed to the Apache Software Foundation (ASF) under one\n or more contributor license agreements. See the NOTICE file\n distributed with this work for additional information\n regarding copyright ownership. The ASF licenses this file\n to you under the Apache License, Version 2.0 (the\n \"License\"); you may not use this file except in compliance\n with the License.  You may obtain a copy of the License at\n \n http://www.apache.org/licenses/LICENSE-2.0\n \n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n"@en .

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/10d27cde/simple/src/main/java/org/apache/commons/rdf/simple/AbstractRDFParserBuilder.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/AbstractRDFParserBuilder.java b/simple/src/main/java/org/apache/commons/rdf/simple/AbstractRDFParserBuilder.java
deleted file mode 100644
index 9e97487..0000000
--- a/simple/src/main/java/org/apache/commons/rdf/simple/AbstractRDFParserBuilder.java
+++ /dev/null
@@ -1,541 +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.simple;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.Optional;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.function.Consumer;
-
-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.RDFParserBuilder;
-import org.apache.commons.rdf.api.RDFSyntax;
-import org.apache.commons.rdf.api.RDFTermFactory;
-
-/**
- * Abstract RDFParserBuilder
- * <p>
- * This abstract class keeps the builder properties in protected fields like
- * {@link #sourceFile} using {@link Optional}. Some basic checking like
- * {@link #checkIsAbsolute(IRI)} is performed.
- * <p>
- * This class and its subclasses are {@link Cloneable}, immutable and
- * (therefore) thread-safe - each call to option methods like
- * {@link #contentType(String)} or {@link #source(IRI)} will return a cloned,
- * mutated copy.
- * <p>
- * By default, parsing is done by the abstract method
- * {@link #parseSynchronusly()} - which is executed in a cloned snapshot - hence
- * multiple {@link #parse()} calls are thread-safe. The default {@link #parse()}
- * uses a thread pool in {@link #threadGroup} - but implementations can override
- * {@link #parse()} (e.g. because it has its own threading model or use
- * asynchronous remote execution).
- */
-public abstract class AbstractRDFParserBuilder<T extends AbstractRDFParserBuilder<T>> 
-	implements RDFParserBuilder, Cloneable {	
-	
-	public static final ThreadGroup threadGroup = new ThreadGroup("Commons RDF parsers");
-	private static final ExecutorService threadpool = Executors.newCachedThreadPool(r -> new Thread(threadGroup, r));
-
-	// Basically only used for creating IRIs
-	private static RDFTermFactory internalRdfTermFactory = new SimpleRDFTermFactory();
-
-	/**
-	 * Get the set {@link RDFTermFactory}, if any.
-	 */
-	public Optional<RDFTermFactory> getRdfTermFactory() {
-		return rdfTermFactory;
-	}
-
-	/**
-	 * Get the set content-type {@link RDFSyntax}, if any.
-	 * <p>
-	 * If this is {@link Optional#isPresent()}, then 
-	 * {@link #getContentType()} contains the 
-	 * value of {@link RDFSyntax#mediaType}. 
-	 */
-	public Optional<RDFSyntax> getContentTypeSyntax() {
-		return contentTypeSyntax;
-	}
-	
-	/**
-	 * Get the set content-type String, if any.
-	 * <p>
-	 * If this is {@link Optional#isPresent()} and 
-	 * is recognized by {@link RDFSyntax#byMediaType(String)}, then
-	 * the corresponding {@link RDFSyntax} is set on 
-	 * {@link #getContentType()}, otherwise that is
-	 * {@link Optional#empty()}. 
-	 */
-	public final Optional<String> getContentType() {
-		return contentType;
-	}
-
-	/**
-	 * Get the target to consume parsed Quads.
-	 * <p>
-	 * From the call to {@link #parseSynchronusly()}, this
-	 * method is always {@link Optional#isPresent()}.
-	 * 
-	 */	
-	public Consumer<Quad> getTarget() {
-		return target;
-	}
-
-	/**
-	 * Get the target dataset as set by {@link #target(Dataset)}.
-	 * <p>
-	 * The return value is {@link Optional#isPresent()} if and only if
-	 * {@link #target(Dataset)} has been set, meaning that the implementation
-	 * may choose to append parsed quads to the {@link Dataset} directly instead
-	 * of relying on the generated {@link #getTarget()} consumer.
-	 * <p>
-	 * If this value is present, then {@link #getTargetGraph()} MUST 
-	 * be {@link Optional#empty()}.
-	 * 
-	 * @return The target Dataset, or {@link Optional#empty()} if another kind of target has been set.
-	 */
-	public Optional<Dataset> getTargetDataset() {
-		return targetDataset;
-	}
-
-	/**
-	 * Get the target graph as set by {@link #target(Graph)}.
-	 * <p>
-	 * The return value is {@link Optional#isPresent()} if and only if
-	 * {@link #target(Graph)} has been set, meaning that the implementation
-	 * may choose to append parsed triples to the {@link Graph} directly instead
-	 * of relying on the generated {@link #getTarget()} consumer.
-	 * <p>
-	 * If this value is present, then {@link #getTargetDataset()} MUST 
-	 * be {@link Optional#empty()}.
-	 * 
-	 * @return The target Graph, or {@link Optional#empty()} if another kind of target has been set.
-	 */	
-	public Optional<Graph>  getTargetGraph() {
-		return targetGraph;
-	}
-	
-	/**
-	 * Get the set base {@link IRI}, if present.
-	 * <p>
-	 * 
-	 */	
-	public Optional<IRI> getBase() {
-		return base;
-	}
-
-	/**
-	 * Get the set source {@link InputStream}.
-	 * <p>
-	 * If this is {@link Optional#isPresent()}, then 
-	 * {@link #getSourceFile()} and {@link #getSourceIri()}
-	 * are {@link Optional#empty()}.
-	 */
-	public Optional<InputStream> getSourceInputStream() {
-		return sourceInputStream;
-	}
-
-	/**
-	 * Get the set source {@link Path}.
-	 * <p>
-	 * If this is {@link Optional#isPresent()}, then 
-	 * {@link #getSourceInputStream()} and {@link #getSourceIri()}
-	 * are {@link Optional#empty()}.
-	 */	
-	public Optional<Path> getSourceFile() {
-		return sourceFile;
-	}
-
-	/**
-	 * Get the set source {@link Path}.
-	 * <p>
-	 * If this is {@link Optional#isPresent()}, then 
-	 * {@link #getSourceInputStream()} and {@link #getSourceInputStream()()}
-	 * are {@link Optional#empty()}.
-	 */		
-	public Optional<IRI> getSourceIri() {
-		return sourceIri;
-	}
-
-
-	private Optional<RDFTermFactory> rdfTermFactory = Optional.empty();
-	private Optional<RDFSyntax> contentTypeSyntax = Optional.empty();
-	private Optional<String> contentType = Optional.empty();
-	private Optional<IRI> base = Optional.empty();
-	private Optional<InputStream> sourceInputStream = Optional.empty();
-	private Optional<Path> sourceFile = Optional.empty();
-	private Optional<IRI> sourceIri = Optional.empty();
-	private Consumer<Quad> target;
-	private Optional<Dataset> targetDataset;
-	private Optional<Graph> targetGraph;
-
-	@SuppressWarnings("unchecked")
-	@Override
-	public T clone() {
-		try {
-			return (T) super.clone();
-		} catch (CloneNotSupportedException e) {
-			throw new RuntimeException(e);
-		}
-	}
-
-	@SuppressWarnings("unchecked")
-	protected T asT() { 
-		return (T) this;
-	}
-	
-	@Override
-	public T rdfTermFactory(RDFTermFactory rdfTermFactory) {
-		AbstractRDFParserBuilder<T> c = clone();
-		c.rdfTermFactory = Optional.ofNullable(rdfTermFactory);
-		return c.asT();
-	}
-
-	@Override
-	public T contentType(RDFSyntax rdfSyntax) throws IllegalArgumentException {
-		AbstractRDFParserBuilder<T> c = clone();
-		c.contentTypeSyntax = Optional.ofNullable(rdfSyntax);
-		c.contentType = c.contentTypeSyntax.map(syntax -> syntax.mediaType);
-		return c.asT();
-	}
-
-	@Override
-	public T contentType(String contentType) throws IllegalArgumentException {
-		AbstractRDFParserBuilder<T> c = clone();
-		c.contentType = Optional.ofNullable(contentType);
-		c.contentTypeSyntax = c.contentType.flatMap(RDFSyntax::byMediaType);
-		return c.asT();
-	}
-
-	@Override
-	public T base(IRI base) {
-		AbstractRDFParserBuilder<T> c = clone();
-		c.base = Optional.ofNullable(base);
-		c.base.ifPresent(i -> checkIsAbsolute(i));
-		return c.asT();
-	}
-
-	@Override
-	public T base(String base) throws IllegalArgumentException {
-		return base(internalRdfTermFactory.createIRI(base));
-	}
-
-	@Override
-	public T source(InputStream inputStream) {
-		AbstractRDFParserBuilder<T> c = clone();
-		c.resetSource();
-		c.sourceInputStream = Optional.ofNullable(inputStream);
-		return c.asT();
-	}
-
-	@Override
-	public T source(Path file) {
-		AbstractRDFParserBuilder<T> c = clone();
-		c.resetSource();
-		c.sourceFile = Optional.ofNullable(file);
-		return c.asT();
-	}
-
-	@Override
-	public T source(IRI iri) {
-		AbstractRDFParserBuilder<T> c = clone();
-		c.resetSource();
-		c.sourceIri = Optional.ofNullable(iri);
-		c.sourceIri.ifPresent(i -> checkIsAbsolute(i));
-		return c.asT();
-	}
-
-	@Override
-	public T source(String iri) throws IllegalArgumentException {
-		AbstractRDFParserBuilder<T> c = clone();
-		c.resetSource();
-		c.sourceIri = Optional.ofNullable(iri).map(internalRdfTermFactory::createIRI);
-		c.sourceIri.ifPresent(i -> checkIsAbsolute(i));
-		return source(internalRdfTermFactory.createIRI(iri));
-	}
-
-	/**
-	 * Check if an iri is absolute.
-	 * <p>
-	 * Used by {@link #source(String)} and {@link #base(String)}
-	 * 
-	 * @param iri
-	 */
-	protected void checkIsAbsolute(IRI iri) {
-		if (!URI.create(iri.getIRIString()).isAbsolute()) {
-			throw new IllegalArgumentException("IRI is not absolute: " + iri);
-		}
-	}
-
-	/**
-	 * Check that one and only one source is present and valid.
-	 * <p>
-	 * Used by {@link #parse()}.
-	 * <p>
-	 * Subclasses might override this method, e.g. to support other
-	 * source combinations, or to check if the sourceIri is 
-	 * resolvable. 
-	 * 
-	 * @throws IOException If a source file can't be read
-	 */
-	protected void checkSource() throws IOException {
-		if (!sourceFile.isPresent() && !sourceInputStream.isPresent() && !sourceIri.isPresent()) {
-			throw new IllegalStateException("No source has been set");
-		}
-		if (sourceIri.isPresent() && sourceInputStream.isPresent()) {
-			throw new IllegalStateException("Both sourceIri and sourceInputStream have been set");
-		}
-		if (sourceIri.isPresent() && sourceFile.isPresent()) {
-			throw new IllegalStateException("Both sourceIri and sourceFile have been set");
-		}
-		if (sourceInputStream.isPresent() && sourceFile.isPresent()) {
-			throw new IllegalStateException("Both sourceInputStream and sourceFile have been set");
-		}
-		if (sourceFile.isPresent() && !sourceFile.filter(Files::isReadable).isPresent()) {
-			throw new IOException("Can't read file: " + sourceFile);
-		}
-	}
-
-	/**
-	 * Check if base is required.
-	 * 
-	 * @throws IllegalStateException if base is required, but not set.
-	 */
-	protected void checkBaseRequired() {
-		if (!base.isPresent() && sourceInputStream.isPresent()
-				&& !contentTypeSyntax.filter(t -> t == RDFSyntax.NQUADS || t == RDFSyntax.NTRIPLES).isPresent()) {
-			throw new IllegalStateException("base iri required for inputstream source");
-		}
-	}
-
-	/**
-	 * Reset all source* fields to Optional.empty()
-	 * <p>
-	 * Subclasses should override this and call <code>super.resetSource()</code>
-	 * if they need to reset any additional source* fields.
-	 * 
-	 */
-	protected void resetSource() {
-		sourceInputStream = Optional.empty();
-		sourceIri = Optional.empty();
-		sourceFile = Optional.empty();
-	}
-
-
-	/**
-	 * Reset all optional target* fields to Optional.empty()</code>
-	 * <p>
-	 * Note that the consumer set for {@link #getTarget()} is
-	 * NOT reset.
-	 * <p>
-	 * Subclasses should override this and call <code>super.resetTarget()</code>
-	 * if they need to reset any additional target* fields.
-	 * 
-	 */
-	protected void resetTarget() {
-		targetDataset = Optional.empty();
-		targetGraph = Optional.empty();
-	}	
-	
-	/**
-	 * Parse {@link #sourceInputStream}, {@link #sourceFile} or
-	 * {@link #sourceIri}.
-	 * <p>
-	 * One of the source fields MUST be present, as checked by {@link #checkSource()}.
-	 * <p>
-	 * {@link #checkBaseRequired()} is called to verify if {@link #getBase()} is required.
-	 * 
-	 * @throws IOException If the source could not be read 
-	 * @throws RDFParseException If the source could not be parsed (e.g. a .ttl file was not valid Turtle)
-	 */
-	protected abstract void parseSynchronusly() throws IOException, RDFParseException;
-
-	/**
-	 * Prepare a clone of this RDFParserBuilder which have been checked and
-	 * completed.
-	 * <p>
-	 * The returned clone will always have
-	 * {@link #getTarget()} and {@link #getRdfTermFactory()} present.
-	 * <p>
-	 * If the {@link #getSourceFile()} is present, but the 
-	 * {@link #getBase()} is not present, the base will be set to the
-	 * <code>file:///</code> IRI for the Path's real path (e.g. resolving any 
-	 * symbolic links).  
-	 *  
-	 * @return A completed and checked clone of this RDFParserBuilder
-	 * @throws IOException If the source was not accessible (e.g. a file was not found)
-	 * @throws IllegalStateException If the parser was not in a compatible setting (e.g. contentType was an invalid string) 
-	 */
-	protected T prepareForParsing() throws IOException, IllegalStateException {
-		checkSource();
-		checkBaseRequired();		
-		checkContentType();
-		checkTarget();
-
-		// We'll make a clone of our current state which will be passed to
-		// parseSynchronously()
-		AbstractRDFParserBuilder<T> c = clone();
-
-		// Use a fresh SimpleRDFTermFactory for each parse
-		if (!c.rdfTermFactory.isPresent()) {
-			c.rdfTermFactory = Optional.of(createRDFTermFactory());
-		}
-		// sourceFile, but no base? Let's follow any symlinks and use
-		// the file:/// URI
-		if (c.sourceFile.isPresent() && !c.base.isPresent()) {
-			URI baseUri = c.sourceFile.get().toRealPath().toUri();
-			c.base = Optional.of(internalRdfTermFactory.createIRI(baseUri.toString()));
-		}
-
-		return c.asT();
-	}
-	
-	/**
-	 * Subclasses can override this method to check the target is 
-	 * valid.
-	 * <p>
-	 * The default implementation throws an IllegalStateException if the 
-	 * target has not been set.
-	 */
-	protected void checkTarget() {
-		if (target == null) {
-			throw new IllegalStateException("target has not been set");
-		}
-		if (targetGraph.isPresent() && targetDataset.isPresent()) {
-			// This should not happen as each target(..) method resets the optionals
-			throw new IllegalStateException("targetGraph and targetDataset can't both be set");
-		}
-	}
-
-	/**
-	 * Subclasses can override this method to check compatibility with the
-	 * contentType setting.
-	 * 
-	 * @throws IllegalStateException
-	 *             if the {@link #getContentType()} or
-	 *             {@link #getContentTypeSyntax()} is not compatible or invalid
-	 */
-	protected void checkContentType() throws IllegalStateException {
-	}
-
-	/**
-	 * Guess RDFSyntax from a local file's extension.
-	 * <p>
-	 * This method can be used by subclasses if {@link #getContentType()} is not
-	 * present and {@link #getSourceFile()} is set.
-	 * 
-	 * @param path Path which extension should be checked
-	 * @return The {@link RDFSyntax} which has a matching {@link RDFSyntax#fileExtension}, 
-	 * 	otherwise {@link Optional#empty()}. 
-	 */
-	protected static Optional<RDFSyntax> guessRDFSyntax(Path path) {
-			return fileExtension(path).flatMap(RDFSyntax::byFileExtension);
-	}
-
-	/**
-	 * Return the file extension of a Path - if any.
-	 * <p>
-	 * The returned file extension includes the leading <code>.</code>
-	 * <p>
-	 * Note that this only returns the last extension, e.g. the 
-	 * file extension for <code>archive.tar.gz</code> would be <code>.gz</code>
-	 * 
-	 * @param path Path which filename might contain an extension
-	 * @return File extension (including the leading <code>.</code>, 
-	 * 	or {@link Optional#empty()} if the path has no extension
-	 */
-	private static Optional<String> fileExtension(Path path) {
-		Path fileName = path.getFileName();
-		if (fileName == null) { 
-			return Optional.empty();
-		}
-		String filenameStr = fileName.toString();
-		int last = filenameStr.lastIndexOf(".");
-		if (last > -1) { 
-			return Optional.of(filenameStr.substring(last));				
-		}
-		return Optional.empty();
-	}
-	
-
-	/**
-	 * Create a new {@link RDFTermFactory} for a parse session.
-	 * <p>
-	 * This is called by {@link #parse()} to set 
-	 * {@link #rdfTermFactory(RDFTermFactory)} if it is
-	 * {@link Optional#empty()}.
-	 * <p>
-	 * As parsed blank nodes might be made with 
-	 * {@link RDFTermFactory#createBlankNode(String)}, 
-	 * each call to this method SHOULD return 
-	 * a new RDFTermFactory instance.
-	 * 
-	 * @return A new {@link RDFTermFactory}
-	 */
-	protected RDFTermFactory createRDFTermFactory() {
-		return new SimpleRDFTermFactory();
-	}
-
-	@Override
-	public Future<ParseResult> parse() throws IOException, IllegalStateException {
-		final AbstractRDFParserBuilder<T> c = prepareForParsing();
-		return threadpool.submit(() -> {
-			c.parseSynchronusly();
-			return null;
-		});
-	}
-
-	@Override
-	public T target(Consumer<Quad> consumer) {
-		AbstractRDFParserBuilder<T> c = clone();
-		c.resetTarget();
-		c.target = consumer;
-		return c.asT();
-	}
-	
-	@Override
-	public T target(Dataset dataset) {
-		@SuppressWarnings({ "rawtypes", "unchecked" })
-		AbstractRDFParserBuilder<T> c = (AbstractRDFParserBuilder) RDFParserBuilder.super.target(dataset);
-		c.resetTarget();
-		c.targetDataset = Optional.of(dataset);
-		return c.asT();
-	}
-	
-	@Override
-	public T target(Graph graph) {
-		@SuppressWarnings({ "rawtypes", "unchecked" }) // super calls our .clone()
-		AbstractRDFParserBuilder<T> c = (AbstractRDFParserBuilder) RDFParserBuilder.super.target(graph);
-		c.resetTarget();
-		c.targetGraph = Optional.of(graph);
-		return c.asT();
-	}
-	
-
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/10d27cde/simple/src/main/java/org/apache/commons/rdf/simple/RDFParseException.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/RDFParseException.java b/simple/src/main/java/org/apache/commons/rdf/simple/RDFParseException.java
deleted file mode 100644
index ed16bb2..0000000
--- a/simple/src/main/java/org/apache/commons/rdf/simple/RDFParseException.java
+++ /dev/null
@@ -1,50 +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.simple;
-
-import org.apache.commons.rdf.api.RDFParserBuilder;
-
-public class RDFParseException extends Exception {
-	private static final long serialVersionUID = 5427752643780702976L;
-	private RDFParserBuilder builder;
-
-	public RDFParseException(RDFParserBuilder builder) {
-		super();
-		this.builder = builder;
-	}
-
-	public RDFParseException(RDFParserBuilder builder, String message, Throwable cause) {
-		super(message, cause);
-		this.builder = builder;
-	}
-
-	public RDFParseException(RDFParserBuilder builder, String message) {
-		super(message);
-		this.builder = builder;
-	}
-
-	public RDFParseException(RDFParserBuilder builder, Throwable cause) {
-		super(cause);
-		this.builder = builder;
-	}
-
-	public RDFParserBuilder getRDFParserBuilder() {
-		return builder;
-	}
-}
\ No newline at end of file


[13/18] incubator-commonsrdf git commit: COMMONSRDF-36 JsonLd* interfaces for Graph/Dataset

Posted by st...@apache.org.
COMMONSRDF-36 JsonLd* interfaces for Graph/Dataset


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

Branch: refs/heads/jena-jsonld-rdf4j-integration
Commit: 043a061a37c8107500943d092d5b4e2b19476d5b
Parents: 0e79b6f
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Sep 28 14:33:21 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Sep 28 14:42:05 2016 +0100

----------------------------------------------------------------------
 .../main/java/org/apache/commons/rdf/jsonldjava/JsonLdDataset.java | 2 +-
 .../main/java/org/apache/commons/rdf/jsonldjava/JsonLdGraph.java   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/043a061a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdDataset.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdDataset.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdDataset.java
index 1ab4b11..55b9f3c 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdDataset.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdDataset.java
@@ -32,7 +32,7 @@ import org.apache.commons.rdf.api.RDFTerm;
 
 import com.github.jsonldjava.core.RDFDataset;
 
-class JsonLdDataset extends JsonLdGraphLike<org.apache.commons.rdf.api.Quad> implements Dataset {
+public class JsonLdDataset extends JsonLdGraphLike<org.apache.commons.rdf.api.Quad> implements Dataset {
 
 	JsonLdDataset(RDFDataset rdfDataSet) {
 		super(rdfDataSet);

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/043a061a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdGraph.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdGraph.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdGraph.java
index 3b35c76..206c82a 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdGraph.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdGraph.java
@@ -34,7 +34,7 @@ import com.github.jsonldjava.core.RDFDataset;
  * A {@link Graph} view of a JsonLd {@link RDFDataset}.
  * 
  */
-class JsonLdGraph extends JsonLdGraphLike<org.apache.commons.rdf.api.Triple> implements Graph {
+public class JsonLdGraph extends JsonLdGraphLike<org.apache.commons.rdf.api.Triple> implements Graph {
 
 	private final Optional<BlankNodeOrIRI> graphName;
 


[16/18] incubator-commonsrdf git commit: Merge branch 'jena' into jena-jsonld-rdf4j-integration

Posted by st...@apache.org.
Merge branch 'jena' into jena-jsonld-rdf4j-integration


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

Branch: refs/heads/jena-jsonld-rdf4j-integration
Commit: 68438f41a34a8ee7c404304637a19b15245fe1c1
Parents: 6df7f1d c52979b
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Sep 28 14:49:27 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Sep 28 14:49:27 2016 +0100

----------------------------------------------------------------------

----------------------------------------------------------------------



[08/18] incubator-commonsrdf git commit: COMMONSRDF-39 RDF4JParser in experimental package

Posted by st...@apache.org.
COMMONSRDF-39 RDF4JParser in experimental package


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

Branch: refs/heads/jena-jsonld-rdf4j-integration
Commit: d90518985a6bc886dec31b9b2854367f1fe9ea3c
Parents: cb2a81f
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Sep 28 14:30:13 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Sep 28 14:30:13 2016 +0100

----------------------------------------------------------------------
 .../commons/rdf/rdf4j/RDF4JParserBuilder.java   | 194 ------------------
 .../rdf/rdf4j/experimental/RDF4JParser.java     | 197 +++++++++++++++++++
 .../rdf/rdf4j/experimental/package-info.java    |  34 ++++
 .../apache/commons/rdf/rdf4j/package-info.java  |   6 +-
 4 files changed, 234 insertions(+), 197 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/d9051898/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
deleted file mode 100644
index 732112b..0000000
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JParserBuilder.java
+++ /dev/null
@@ -1,194 +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;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.Optional;
-import java.util.function.Consumer;
-
-import org.apache.commons.rdf.api.IRI;
-import org.apache.commons.rdf.api.Quad;
-import org.apache.commons.rdf.api.RDFParserBuilder;
-import org.apache.commons.rdf.api.RDFSyntax;
-import org.apache.commons.rdf.simple.AbstractRDFParserBuilder;
-import org.eclipse.rdf4j.model.Model;
-import org.eclipse.rdf4j.repository.util.RDFInserter;
-import org.eclipse.rdf4j.repository.util.RDFLoader;
-import org.eclipse.rdf4j.rio.ParserConfig;
-import org.eclipse.rdf4j.rio.RDFFormat;
-import org.eclipse.rdf4j.rio.RDFHandler;
-import org.eclipse.rdf4j.rio.RDFHandlerException;
-import org.eclipse.rdf4j.rio.Rio;
-import org.eclipse.rdf4j.rio.helpers.AbstractRDFHandler;
-
-/**
- * RDF4J-based parser.
- * <p>
- * This can handle the RDF syntaxes {@link RDFSyntax#JSONLD},
- * {@link RDFSyntax#NQUADS}, {@link RDFSyntax#NTRIPLES},
- * {@link RDFSyntax#RDFXML}, {@link RDFSyntax#TRIG} and {@link RDFSyntax#TURTLE}
- * - additional syntaxes can be supported by including the corresponding
- * <em>rdf4j-rio-*</em> module on the classpath.
- *
- */
-public class RDF4JParserBuilder extends AbstractRDFParserBuilder<RDF4JParserBuilder> 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 RDF4JParserBuilder prepareForParsing() throws IOException, IllegalStateException {
-		RDF4JParserBuilder c = 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 {		
-		Optional<RDFFormat> formatByMimeType = getContentType().flatMap(Rio::getParserFormatForMIMEType);
-		String base = getBase().map(IRI::getIRIString).orElse(null);
-				
-		ParserConfig parserConfig = new ParserConfig();
-		// TODO: Should we need to set anything?
-		RDFLoader loader = new RDFLoader(parserConfig, rdf4jTermFactory.getValueFactory());
-		RDFHandler rdfHandler = makeRDFHandler();		
-		if (getSourceFile().isPresent()) {			
-			// NOTE: While we could have used  
-			// loader.load(sourcePath.toFile()
-			// if the path fs provider == FileSystems.getDefault(), 			
-			// that RDFLoader method does not use absolute path
-			// as the base URI, so to be consistent 
-			// we'll always do it with our own input stream
-			//
-			// That means we may have to guess format by extensions:			
-			Optional<RDFFormat> formatByFilename = getSourceFile().map(Path::getFileName).map(Path::toString)
-					.flatMap(Rio::getParserFormatForFileName);
-			// TODO: for the excited.. what about the extension after following symlinks? 
-			
-			RDFFormat format = formatByMimeType.orElse(formatByFilename.orElse(null));
-			try (InputStream in = Files.newInputStream(getSourceFile().get())) {
-				loader.load(in, base, format, rdfHandler);
-			}
-		} else if (getSourceIri().isPresent()) {
-			try {
-				// TODO: Handle international IRIs properly
-				// (Unicode support for for hostname, path and query)
-				URL url = new URL(getSourceIri().get().getIRIString());
-				// TODO: This probably does not support https:// -> http:// redirections
-				loader.load(url, base, formatByMimeType.orElse(null), makeRDFHandler());
-			} catch (MalformedURLException ex) {
-				throw new IOException("Can't handle source URL: " + getSourceIri().get(), ex);
-			}			
-		}
-		// must be getSourceInputStream then, this is guaranteed by super.checkSource(); 		
-		loader.load(getSourceInputStream().get(), base, formatByMimeType.orElse(null), rdfHandler);
-	}
-
-	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/d9051898/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/RDF4JParser.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/RDF4JParser.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/RDF4JParser.java
new file mode 100644
index 0000000..c185419
--- /dev/null
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/RDF4JParser.java
@@ -0,0 +1,197 @@
+/**
+ * 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.experimental;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Optional;
+import java.util.function.Consumer;
+
+import org.apache.commons.rdf.api.IRI;
+import org.apache.commons.rdf.api.Quad;
+import org.apache.commons.rdf.api.RDFSyntax;
+import org.apache.commons.rdf.experimental.RDFParser;
+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.experimental.AbstractRDFParser;
+import org.eclipse.rdf4j.model.Model;
+import org.eclipse.rdf4j.repository.util.RDFInserter;
+import org.eclipse.rdf4j.repository.util.RDFLoader;
+import org.eclipse.rdf4j.rio.ParserConfig;
+import org.eclipse.rdf4j.rio.RDFFormat;
+import org.eclipse.rdf4j.rio.RDFHandler;
+import org.eclipse.rdf4j.rio.RDFHandlerException;
+import org.eclipse.rdf4j.rio.Rio;
+import org.eclipse.rdf4j.rio.helpers.AbstractRDFHandler;
+
+/**
+ * RDF4J-based parser.
+ * <p>
+ * This can handle the RDF syntaxes {@link RDFSyntax#JSONLD},
+ * {@link RDFSyntax#NQUADS}, {@link RDFSyntax#NTRIPLES},
+ * {@link RDFSyntax#RDFXML}, {@link RDFSyntax#TRIG} and {@link RDFSyntax#TURTLE}
+ * - additional syntaxes can be supported by including the corresponding
+ * <em>rdf4j-rio-*</em> module on the classpath.
+ *
+ */
+public class RDF4JParser extends AbstractRDFParser<RDF4JParser> implements RDFParser {
+
+	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 RDF4JParser prepareForParsing() throws IOException, IllegalStateException {
+		RDF4JParser c = 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 {		
+		Optional<RDFFormat> formatByMimeType = getContentType().flatMap(Rio::getParserFormatForMIMEType);
+		String base = getBase().map(IRI::getIRIString).orElse(null);
+				
+		ParserConfig parserConfig = new ParserConfig();
+		// TODO: Should we need to set anything?
+		RDFLoader loader = new RDFLoader(parserConfig, rdf4jTermFactory.getValueFactory());
+		RDFHandler rdfHandler = makeRDFHandler();		
+		if (getSourceFile().isPresent()) {			
+			// NOTE: While we could have used  
+			// loader.load(sourcePath.toFile()
+			// if the path fs provider == FileSystems.getDefault(), 			
+			// that RDFLoader method does not use absolute path
+			// as the base URI, so to be consistent 
+			// we'll always do it with our own input stream
+			//
+			// That means we may have to guess format by extensions:			
+			Optional<RDFFormat> formatByFilename = getSourceFile().map(Path::getFileName).map(Path::toString)
+					.flatMap(Rio::getParserFormatForFileName);
+			// TODO: for the excited.. what about the extension after following symlinks? 
+			
+			RDFFormat format = formatByMimeType.orElse(formatByFilename.orElse(null));
+			try (InputStream in = Files.newInputStream(getSourceFile().get())) {
+				loader.load(in, base, format, rdfHandler);
+			}
+		} else if (getSourceIri().isPresent()) {
+			try {
+				// TODO: Handle international IRIs properly
+				// (Unicode support for for hostname, path and query)
+				URL url = new URL(getSourceIri().get().getIRIString());
+				// TODO: This probably does not support https:// -> http:// redirections
+				loader.load(url, base, formatByMimeType.orElse(null), makeRDFHandler());
+			} catch (MalformedURLException ex) {
+				throw new IOException("Can't handle source URL: " + getSourceIri().get(), ex);
+			}			
+		}
+		// must be getSourceInputStream then, this is guaranteed by super.checkSource(); 		
+		loader.load(getSourceInputStream().get(), base, formatByMimeType.orElse(null), rdfHandler);
+	}
+
+	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/d9051898/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/package-info.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/package-info.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/package-info.java
new file mode 100644
index 0000000..192a148
--- /dev/null
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/package-info.java
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+/**
+ * Experimental Commons RDF RDF4J implementations.
+ * <p>
+ * Classes in this package should be considered <strong>at
+ * risk</strong>; they might change or be removed in the next minor update of
+ * Commons RDF.
+ * <p>
+ * When a class has stabilized, it will move to the
+ * {@link org.apache.commons.rdf.rdf4j} package.
+ * <p>
+ * <ul>
+ * <li>{@link RDF4JParser} - an RDF4J-backed
+ * implementations of 
+ * {@link org.apache.commons.rdf.api.experimental.RDFParser}.</li>
+ * </ul>
+ */
+package org.apache.commons.rdf.rdf4j.experimental;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/d9051898/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 844da5a..e384f3d 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
@@ -41,11 +41,11 @@
  * {@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
+ * The {@link org.apache.commons.rdf.rdf4j.experimental.RDF4JParser} 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)}
+ * {@link org.apache.commons.rdf.rdf4j.experimental.RDF4JParser#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)}
+ * {@link org.apache.commons.rdf.rdf4j.experimental.RDF4JParser#target(org.apache.commons.rdf.api.Graph)}
  * and a an adapted {@link org.apache.commons.rdf.rdf4j.RDF4JGraph}
  * 
  *


[05/18] incubator-commonsrdf git commit: COMMONSRDF-39 JenaRDFParser moved to package ...jena.experimental

Posted by st...@apache.org.
COMMONSRDF-39 JenaRDFParser moved to package ...jena.experimental


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

Branch: refs/heads/jena-jsonld-rdf4j-integration
Commit: 4416acc1bdbcb8192475c93aeaec8dae73e6f1cc
Parents: 2eb821d
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Sep 28 14:25:07 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Sep 28 14:25:07 2016 +0100

----------------------------------------------------------------------
 .../commons/rdf/jena/JenaRDFParserBuilder.java  | 103 ------------------
 .../rdf/jena/experimental/JenaRDFParser.java    | 105 +++++++++++++++++++
 .../rdf/jena/experimental/package-info.java     |  34 ++++++
 3 files changed, 139 insertions(+), 103 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/4416acc1/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFParserBuilder.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFParserBuilder.java b/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFParserBuilder.java
deleted file mode 100644
index 2149932..0000000
--- a/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFParserBuilder.java
+++ /dev/null
@@ -1,103 +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.jena;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.file.Files;
-import java.util.function.Consumer;
-
-import org.apache.commons.rdf.api.IRI;
-import org.apache.commons.rdf.api.QuadLike;
-import org.apache.commons.rdf.api.RDFParserBuilder;
-import org.apache.commons.rdf.api.RDFTerm;
-import org.apache.commons.rdf.api.RDFTermFactory;
-import org.apache.commons.rdf.api.TripleLike;
-import org.apache.commons.rdf.simple.AbstractRDFParserBuilder;
-import org.apache.jena.graph.Graph;
-import org.apache.jena.riot.Lang;
-import org.apache.jena.riot.RDFDataMgr;
-import org.apache.jena.riot.system.StreamRDF;
-import org.apache.jena.riot.system.StreamRDFLib;
-
-public class JenaRDFParserBuilder extends AbstractRDFParserBuilder<JenaRDFParserBuilder> implements RDFParserBuilder {
-
-	private Consumer<TripleLike<RDFTerm, RDFTerm, RDFTerm>> generalizedConsumerTriple;
-	private Consumer<QuadLike<RDFTerm, RDFTerm, RDFTerm, RDFTerm>> generalizedConsumerQuad;
-
-	protected RDFTermFactory createRDFTermFactory() {
-		return new JenaRDFTermFactory();
-	}
-
-	public JenaRDFParserBuilder targetGeneralizedTriple(Consumer<TripleLike<RDFTerm,RDFTerm,RDFTerm>> consumer) {
-		JenaRDFParserBuilder c = this.clone();
-		c.resetTarget();		
-		c.generalizedConsumerTriple = consumer;
-		return c;
-	}
-
-	public JenaRDFParserBuilder targetGeneralizedQuad(Consumer<QuadLike<RDFTerm,RDFTerm,RDFTerm,RDFTerm>> consumer) {
-		JenaRDFParserBuilder c = this.clone();
-		c.resetTarget();		
-		c.generalizedConsumerQuad = consumer;
-		return c;
-	}
-	
-	@Override
-	protected void resetTarget() {		
-		super.resetTarget();
-		this.generalizedConsumerTriple = null;
-		this.generalizedConsumerQuad = null;
-	}
-	
-	@Override
-	protected void parseSynchronusly() throws IOException {
-		StreamRDF dest;
-		if (getTargetGraph().isPresent() && getTargetGraph().get() instanceof JenaGraph) {
-			Graph jenaGraph = ((JenaGraph) getTargetGraph().get()).asJenaGraph();
-			dest = StreamRDFLib.graph(jenaGraph);
-		} else if (generalizedConsumerQuad != null) {				
-			dest = getJenaFactory().streamJenaToGeneralizedQuad(generalizedConsumerQuad);			
-		} else if (generalizedConsumerTriple != null) {				
-			dest = getJenaFactory().streamJenaToGeneralizedTriple(generalizedConsumerTriple);			
-		} else {
-			dest = JenaRDFTermFactory.streamJenaToCommonsRDF(getRdfTermFactory().get(), getTarget());
-		}
-
-		Lang lang = getContentTypeSyntax().flatMap(JenaRDFTermFactory::rdfSyntaxToLang).orElse(null);
-		String baseStr = getBase().map(IRI::getIRIString).orElse(null);
-
-		if (getSourceIri().isPresent()) {
-			RDFDataMgr.parse(dest, getSourceIri().get().toString(), baseStr, lang, null);
-		} else if (getSourceFile().isPresent()) {
-			try (InputStream s = Files.newInputStream(getSourceFile().get())) {
-				RDFDataMgr.parse(dest, s, baseStr, lang, null);
-			}
-		} else {
-			RDFDataMgr.parse(dest, getSourceInputStream().get(), baseStr, lang, null);
-		}
-	}
-
-	private JenaRDFTermFactory getJenaFactory() {
-		return (JenaRDFTermFactory) getRdfTermFactory()
-				.filter(JenaRDFTermFactory.class::isInstance)
-				.orElseGet(this::createRDFTermFactory);		
-	}
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/4416acc1/jena/src/main/java/org/apache/commons/rdf/jena/experimental/JenaRDFParser.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/experimental/JenaRDFParser.java b/jena/src/main/java/org/apache/commons/rdf/jena/experimental/JenaRDFParser.java
new file mode 100644
index 0000000..873f1cf
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/experimental/JenaRDFParser.java
@@ -0,0 +1,105 @@
+/**
+ * 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.jena.experimental;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.util.function.Consumer;
+
+import org.apache.commons.rdf.api.IRI;
+import org.apache.commons.rdf.api.QuadLike;
+import org.apache.commons.rdf.api.RDFTerm;
+import org.apache.commons.rdf.api.RDFTermFactory;
+import org.apache.commons.rdf.api.TripleLike;
+import org.apache.commons.rdf.experimental.RDFParser;
+import org.apache.commons.rdf.jena.JenaGraph;
+import org.apache.commons.rdf.jena.JenaRDFTermFactory;
+import org.apache.commons.rdf.simple.experimental.AbstractRDFParser;
+import org.apache.jena.graph.Graph;
+import org.apache.jena.riot.Lang;
+import org.apache.jena.riot.RDFDataMgr;
+import org.apache.jena.riot.system.StreamRDF;
+import org.apache.jena.riot.system.StreamRDFLib;
+
+public class JenaRDFParser extends AbstractRDFParser<JenaRDFParser> implements RDFParser {
+
+	private Consumer<TripleLike<RDFTerm, RDFTerm, RDFTerm>> generalizedConsumerTriple;
+	private Consumer<QuadLike<RDFTerm, RDFTerm, RDFTerm, RDFTerm>> generalizedConsumerQuad;
+
+	protected RDFTermFactory createRDFTermFactory() {
+		return new JenaRDFTermFactory();
+	}
+
+	public JenaRDFParser targetGeneralizedTriple(Consumer<TripleLike<RDFTerm,RDFTerm,RDFTerm>> consumer) {
+		JenaRDFParser c = this.clone();
+		c.resetTarget();		
+		c.generalizedConsumerTriple = consumer;
+		return c;
+	}
+
+	public JenaRDFParser targetGeneralizedQuad(Consumer<QuadLike<RDFTerm,RDFTerm,RDFTerm,RDFTerm>> consumer) {
+		JenaRDFParser c = this.clone();
+		c.resetTarget();		
+		c.generalizedConsumerQuad = consumer;
+		return c;
+	}
+	
+	@Override
+	protected void resetTarget() {		
+		super.resetTarget();
+		this.generalizedConsumerTriple = null;
+		this.generalizedConsumerQuad = null;
+	}
+	
+	@Override
+	protected void parseSynchronusly() throws IOException {
+		StreamRDF dest;
+		if (getTargetGraph().isPresent() && getTargetGraph().get() instanceof JenaGraph) {
+			Graph jenaGraph = ((JenaGraph) getTargetGraph().get()).asJenaGraph();
+			dest = StreamRDFLib.graph(jenaGraph);
+		} else if (generalizedConsumerQuad != null) {				
+			dest = getJenaFactory().streamJenaToGeneralizedQuad(generalizedConsumerQuad);			
+		} else if (generalizedConsumerTriple != null) {				
+			dest = getJenaFactory().streamJenaToGeneralizedTriple(generalizedConsumerTriple);			
+		} else {
+			dest = JenaRDFTermFactory.streamJenaToCommonsRDF(getRdfTermFactory().get(), getTarget());
+		}
+
+		Lang lang = getContentTypeSyntax().flatMap(JenaRDFTermFactory::rdfSyntaxToLang).orElse(null);
+		String baseStr = getBase().map(IRI::getIRIString).orElse(null);
+
+		if (getSourceIri().isPresent()) {
+			RDFDataMgr.parse(dest, getSourceIri().get().toString(), baseStr, lang, null);
+		} else if (getSourceFile().isPresent()) {
+			try (InputStream s = Files.newInputStream(getSourceFile().get())) {
+				RDFDataMgr.parse(dest, s, baseStr, lang, null);
+			}
+		} else {
+			RDFDataMgr.parse(dest, getSourceInputStream().get(), baseStr, lang, null);
+		}
+	}
+
+	private JenaRDFTermFactory getJenaFactory() {
+		return (JenaRDFTermFactory) getRdfTermFactory()
+				.filter(JenaRDFTermFactory.class::isInstance)
+				.orElseGet(this::createRDFTermFactory);		
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/4416acc1/jena/src/main/java/org/apache/commons/rdf/jena/experimental/package-info.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/experimental/package-info.java b/jena/src/main/java/org/apache/commons/rdf/jena/experimental/package-info.java
new file mode 100644
index 0000000..9fe39f4
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/experimental/package-info.java
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+/**
+ * Experimental Commons RDF Jena implementations.
+ * <p>
+ * Classes in this package should be considered <strong>at
+ * risk</strong>; they might change or be removed in the next minor update of
+ * Commons RDF.
+ * <p>
+ * When a class has stabilized, it will move to the
+ * {@link org.apache.commons.rdf.jena} package.
+ * <p>
+ * <ul>
+ * <li>{@link JenaRDFParser} - a Jena-backed
+ * implementations of 
+ * {@link org.apache.commons.rdf.api.experimental.RDFParser}.</li>
+ * </ul>
+ */
+package org.apache.commons.rdf.jena.experimental;
\ No newline at end of file


[12/18] incubator-commonsrdf git commit: duplicate .gitignore removed

Posted by st...@apache.org.
duplicate .gitignore removed


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

Branch: refs/heads/jena-jsonld-rdf4j-integration
Commit: 0e79b6f3e047d71e4833d4e801813c485197f652
Parents: 1412edd
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Sep 28 14:33:02 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Sep 28 14:33:02 2016 +0100

----------------------------------------------------------------------
 jsonld-java/.gitignore | 1 -
 1 file changed, 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/0e79b6f3/jsonld-java/.gitignore
----------------------------------------------------------------------
diff --git a/jsonld-java/.gitignore b/jsonld-java/.gitignore
deleted file mode 100644
index b83d222..0000000
--- a/jsonld-java/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/target/


[11/18] incubator-commonsrdf git commit: COMMONSRDF-39 Moved JsonLdParser to experimental package

Posted by st...@apache.org.
COMMONSRDF-39 Moved JsonLdParser to experimental package


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

Branch: refs/heads/jena-jsonld-rdf4j-integration
Commit: 1412edd66f24401da13a45de6d06ef68c0e19fa7
Parents: 2510a07
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Sep 28 14:32:07 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Sep 28 14:32:07 2016 +0100

----------------------------------------------------------------------
 .../rdf/jsonldjava/JsonLdParserBuilder.java     | 157 ------------------
 .../jsonldjava/experimental/JsonLdParser.java   | 160 +++++++++++++++++++
 .../jsonldjava/experimental/package-info.java   |  34 ++++
 .../rdf/jsonldjava/JsonLdParserBuilderTest.java |   7 +-
 4 files changed, 198 insertions(+), 160 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/1412edd6/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdParserBuilder.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdParserBuilder.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdParserBuilder.java
deleted file mode 100644
index e38af2c..0000000
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdParserBuilder.java
+++ /dev/null
@@ -1,157 +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.jsonldjava;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.nio.file.Files;
-import java.util.function.Predicate;
-
-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.RDFSyntax;
-import org.apache.commons.rdf.simple.AbstractRDFParserBuilder;
-
-import com.github.jsonldjava.core.JsonLdError;
-import com.github.jsonldjava.core.JsonLdOptions;
-import com.github.jsonldjava.core.JsonLdProcessor;
-import com.github.jsonldjava.core.RDFDataset;
-import com.github.jsonldjava.utils.JsonUtils;
-
-public class JsonLdParserBuilder extends AbstractRDFParserBuilder<JsonLdParserBuilder> {
-
-	@Override
-	protected JsonLdRDFTermFactory createRDFTermFactory() {
-		return new JsonLdRDFTermFactory();
-	}
-
-	@Override
-	public JsonLdParserBuilder contentType(RDFSyntax rdfSyntax) throws IllegalArgumentException {
-		if (rdfSyntax != null && rdfSyntax != RDFSyntax.JSONLD) { 
-			throw new IllegalArgumentException("Unsupported contentType: " + rdfSyntax);
-		}
-		return super.contentType(rdfSyntax);
-	}
-	
-	@Override
-	public JsonLdParserBuilder contentType(String contentType) throws IllegalArgumentException {
-		JsonLdParserBuilder c = (JsonLdParserBuilder) super.contentType(contentType);
-		if (c.getContentType().filter(Predicate.isEqual(RDFSyntax.JSONLD).negate()).isPresent()) {
-			throw new IllegalArgumentException("Unsupported contentType: " + contentType);
-		}
-		return c;		
-	}
-
-	private static URL asURL(IRI iri) throws IllegalStateException {
-		try {
-			return new URI(iri.getIRIString()).toURL();
-		} catch (MalformedURLException | URISyntaxException e) {
-			throw new IllegalStateException("Invalid URL: " + iri.getIRIString());
-		}
-	}
-	
-	@Override
-	protected void checkSource() throws IOException {
-		super.checkSource();
-		// Might throw IllegalStateException if invalid
-		getSourceIri().map(JsonLdParserBuilder::asURL);
-	}
-	
-	@Override
-	protected void parseSynchronusly() throws IOException {		
-		Object json = readSource();
-		JsonLdOptions options = new JsonLdOptions();
-		getBase().map(IRI::getIRIString).ifPresent(options::setBase);
-		// TODO: base from readSource() (after redirection and Content-Location header) 
-		// should be forwarded		
-
-		// TODO: Modify JsonLdProcessor to accept the target RDFDataset
-		RDFDataset rdfDataset;
-		try {
-			rdfDataset = (RDFDataset) JsonLdProcessor.toRDF(json, options);
-		} catch (JsonLdError e) {
-			throw new IOException("Could not parse Json-LD", e);
-		}
-		if (getTargetGraph().isPresent()) {		
-			Graph intoGraph = getTargetGraph().get();
-			if (intoGraph instanceof JsonLdGraph && ! intoGraph.contains(null, null, null)) {
-				// Empty graph, we can just move over the map content directly:
-				JsonLdGraph jsonLdGraph = (JsonLdGraph) intoGraph;
-				jsonLdGraph.getRdfDataSet().putAll(rdfDataset);
-				return;
-				// otherwise we have to merge as normal
-			} 			
-			// TODO: Modify JsonLdProcessor to have an actual triple callback
-			Graph parsedGraph = getJsonLdRDFTermFactory().asGraph(rdfDataset);			
-			// sequential() as we don't know if destination is thread safe :-/
-			parsedGraph.stream().sequential().forEach(intoGraph::add);
-		} else if (getTargetDataset().isPresent()) {
-			Dataset intoDataset = getTargetDataset().get();
-			if (intoDataset instanceof JsonLdDataset && 
-					! intoDataset.contains(null, null, null, null)) {				
-				JsonLdDataset jsonLdDataset = (JsonLdDataset) intoDataset;
-				// Empty - we can just do a brave replace!
-				jsonLdDataset.getRdfDataSet().putAll(rdfDataset);
-				return;				
-				// otherwise we have to merge.. but also avoid duplicate triples, 
-				// map blank nodes etc, so we'll fall back to normal Dataset appending.
-			}	
-			Dataset fromDataset = getJsonLdRDFTermFactory().asDataset(rdfDataset);
-			// .sequential() as we don't know if destination is thread-safe :-/			
-			fromDataset.stream().sequential().forEach(intoDataset::add);
-		} else {	
-			Dataset fromDataset = getJsonLdRDFTermFactory().asDataset(rdfDataset);
-			// No need for .sequential() here
-			fromDataset.stream().forEach(getTarget());
-		}
-	}
-	
-	private JsonLdRDFTermFactory getJsonLdRDFTermFactory() {
-		if (getRdfTermFactory().isPresent() && getRdfTermFactory().get() instanceof JsonLdRDFTermFactory) {
-			return (JsonLdRDFTermFactory) getRdfTermFactory().get();
-		}
-		return createRDFTermFactory();		
-	}
-
-	private Object readSource() throws IOException {
-		// Due to checked IOException we can't easily 
-		// do this with .map and .orElseGet()
-		
-		if (getSourceInputStream().isPresent()) {
-			return JsonUtils.fromInputStream(getSourceInputStream().get());
-		}
-		if (getSourceIri().isPresent()) {
-			// TODO: propagate @base from content
-			return JsonUtils.fromURL(asURL(getSourceIri().get()), 
-					JsonUtils.getDefaultHttpClient());			
-		}
-		if (getSourceFile().isPresent()) {
-			try (InputStream inputStream = Files.newInputStream(getSourceFile().get())){
-				return JsonUtils.fromInputStream(inputStream);
-			} 			
-		}
-		throw new IllegalStateException("No known source found");
-	}
-
-}
-

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/1412edd6/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/experimental/JsonLdParser.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/experimental/JsonLdParser.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/experimental/JsonLdParser.java
new file mode 100644
index 0000000..102b2d4
--- /dev/null
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/experimental/JsonLdParser.java
@@ -0,0 +1,160 @@
+/**
+ * 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.jsonldjava.experimental;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.nio.file.Files;
+import java.util.function.Predicate;
+
+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.RDFSyntax;
+import org.apache.commons.rdf.jsonldjava.JsonLdDataset;
+import org.apache.commons.rdf.jsonldjava.JsonLdGraph;
+import org.apache.commons.rdf.jsonldjava.JsonLdRDFTermFactory;
+import org.apache.commons.rdf.simple.experimental.AbstractRDFParser;
+
+import com.github.jsonldjava.core.JsonLdError;
+import com.github.jsonldjava.core.JsonLdOptions;
+import com.github.jsonldjava.core.JsonLdProcessor;
+import com.github.jsonldjava.core.RDFDataset;
+import com.github.jsonldjava.utils.JsonUtils;
+
+public class JsonLdParser extends AbstractRDFParser<JsonLdParser> {
+
+	@Override
+	protected JsonLdRDFTermFactory createRDFTermFactory() {
+		return new JsonLdRDFTermFactory();
+	}
+
+	@Override
+	public JsonLdParser contentType(RDFSyntax rdfSyntax) throws IllegalArgumentException {
+		if (rdfSyntax != null && rdfSyntax != RDFSyntax.JSONLD) { 
+			throw new IllegalArgumentException("Unsupported contentType: " + rdfSyntax);
+		}
+		return super.contentType(rdfSyntax);
+	}
+	
+	@Override
+	public JsonLdParser contentType(String contentType) throws IllegalArgumentException {
+		JsonLdParser c = (JsonLdParser) super.contentType(contentType);
+		if (c.getContentType().filter(Predicate.isEqual(RDFSyntax.JSONLD).negate()).isPresent()) {
+			throw new IllegalArgumentException("Unsupported contentType: " + contentType);
+		}
+		return c;		
+	}
+
+	private static URL asURL(IRI iri) throws IllegalStateException {
+		try {
+			return new URI(iri.getIRIString()).toURL();
+		} catch (MalformedURLException | URISyntaxException e) {
+			throw new IllegalStateException("Invalid URL: " + iri.getIRIString());
+		}
+	}
+	
+	@Override
+	protected void checkSource() throws IOException {
+		super.checkSource();
+		// Might throw IllegalStateException if invalid
+		getSourceIri().map(JsonLdParser::asURL);
+	}
+	
+	@Override
+	protected void parseSynchronusly() throws IOException {		
+		Object json = readSource();
+		JsonLdOptions options = new JsonLdOptions();
+		getBase().map(IRI::getIRIString).ifPresent(options::setBase);
+		// TODO: base from readSource() (after redirection and Content-Location header) 
+		// should be forwarded		
+
+		// TODO: Modify JsonLdProcessor to accept the target RDFDataset
+		RDFDataset rdfDataset;
+		try {
+			rdfDataset = (RDFDataset) JsonLdProcessor.toRDF(json, options);
+		} catch (JsonLdError e) {
+			throw new IOException("Could not parse Json-LD", e);
+		}
+		if (getTargetGraph().isPresent()) {		
+			Graph intoGraph = getTargetGraph().get();
+			if (intoGraph instanceof JsonLdGraph && ! intoGraph.contains(null, null, null)) {
+				// Empty graph, we can just move over the map content directly:
+				JsonLdGraph jsonLdGraph = (JsonLdGraph) intoGraph;
+				jsonLdGraph.getRdfDataSet().putAll(rdfDataset);
+				return;
+				// otherwise we have to merge as normal
+			} 			
+			// TODO: Modify JsonLdProcessor to have an actual triple callback
+			Graph parsedGraph = getJsonLdRDFTermFactory().asGraph(rdfDataset);			
+			// sequential() as we don't know if destination is thread safe :-/
+			parsedGraph.stream().sequential().forEach(intoGraph::add);
+		} else if (getTargetDataset().isPresent()) {
+			Dataset intoDataset = getTargetDataset().get();
+			if (intoDataset instanceof JsonLdDataset && 
+					! intoDataset.contains(null, null, null, null)) {				
+				JsonLdDataset jsonLdDataset = (JsonLdDataset) intoDataset;
+				// Empty - we can just do a brave replace!
+				jsonLdDataset.getRdfDataSet().putAll(rdfDataset);
+				return;				
+				// otherwise we have to merge.. but also avoid duplicate triples, 
+				// map blank nodes etc, so we'll fall back to normal Dataset appending.
+			}	
+			Dataset fromDataset = getJsonLdRDFTermFactory().asDataset(rdfDataset);
+			// .sequential() as we don't know if destination is thread-safe :-/			
+			fromDataset.stream().sequential().forEach(intoDataset::add);
+		} else {	
+			Dataset fromDataset = getJsonLdRDFTermFactory().asDataset(rdfDataset);
+			// No need for .sequential() here
+			fromDataset.stream().forEach(getTarget());
+		}
+	}
+	
+	private JsonLdRDFTermFactory getJsonLdRDFTermFactory() {
+		if (getRdfTermFactory().isPresent() && getRdfTermFactory().get() instanceof JsonLdRDFTermFactory) {
+			return (JsonLdRDFTermFactory) getRdfTermFactory().get();
+		}
+		return createRDFTermFactory();		
+	}
+
+	private Object readSource() throws IOException {
+		// Due to checked IOException we can't easily 
+		// do this with .map and .orElseGet()
+		
+		if (getSourceInputStream().isPresent()) {
+			return JsonUtils.fromInputStream(getSourceInputStream().get());
+		}
+		if (getSourceIri().isPresent()) {
+			// TODO: propagate @base from content
+			return JsonUtils.fromURL(asURL(getSourceIri().get()), 
+					JsonUtils.getDefaultHttpClient());			
+		}
+		if (getSourceFile().isPresent()) {
+			try (InputStream inputStream = Files.newInputStream(getSourceFile().get())){
+				return JsonUtils.fromInputStream(inputStream);
+			} 			
+		}
+		throw new IllegalStateException("No known source found");
+	}
+
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/1412edd6/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/experimental/package-info.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/experimental/package-info.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/experimental/package-info.java
new file mode 100644
index 0000000..fbd595e
--- /dev/null
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/experimental/package-info.java
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+/**
+ * Experimental Commons RDF RDF4J implementations.
+ * <p>
+ * Classes in this package should be considered <strong>at
+ * risk</strong>; they might change or be removed in the next minor update of
+ * Commons RDF.
+ * <p>
+ * When a class has stabilized, it will move to the
+ * {@link org.apache.commons.rdf.rdf4j} package.
+ * <p>
+ * <ul>
+ * <li>{@link RDF4JParser} - an RDF4J-backed
+ * implementations of 
+ * {@link org.apache.commons.rdf.api.experimental.RDFParser}.</li>
+ * </ul>
+ */
+package org.apache.commons.rdf.jsonldjava.experimental;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/1412edd6/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdParserBuilderTest.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdParserBuilderTest.java b/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdParserBuilderTest.java
index 37fa560..4d846ee 100644
--- a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdParserBuilderTest.java
+++ b/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdParserBuilderTest.java
@@ -32,6 +32,7 @@ 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.RDFSyntax;
+import org.apache.commons.rdf.jsonldjava.experimental.JsonLdParser;
 import org.apache.commons.rdf.simple.Types;
 import org.junit.Test;
 
@@ -57,7 +58,7 @@ public class JsonLdParserBuilderTest {
 		assertNotNull("Test resource not found: " + TEST_JSONLD, url);
 		IRI iri = factory.createIRI(url.toString());
 		Graph g = factory.createGraph();
-		new JsonLdParserBuilder()
+		new JsonLdParser()
 				.contentType(RDFSyntax.JSONLD)
 				.source(iri)				
 				.target(g)
@@ -75,7 +76,7 @@ public class JsonLdParserBuilderTest {
 			Files.copy(is, path, StandardCopyOption.REPLACE_EXISTING);
 		}
 		Graph g = factory.createGraph();
-		new JsonLdParserBuilder()
+		new JsonLdParser()
 				.contentType(RDFSyntax.JSONLD)
 				.source(path)
 				.target(g)
@@ -89,7 +90,7 @@ public class JsonLdParserBuilderTest {
 		Graph g = factory.createGraph();
 		try (InputStream is = getClass().getResourceAsStream(TEST_JSONLD)) {
 			assertNotNull("Test resource not found: " + TEST_JSONLD, is);	
-			new JsonLdParserBuilder()
+			new JsonLdParser()
 					.base("http://example.com/base/")
 					.contentType(RDFSyntax.JSONLD).source(is)
 					.target(g)


[18/18] incubator-commonsrdf git commit: Merge branch 'rdf4j' into jena-jsonld-rdf4j-integration

Posted by st...@apache.org.
Merge branch 'rdf4j' into jena-jsonld-rdf4j-integration


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

Branch: refs/heads/jena-jsonld-rdf4j-integration
Commit: 549872958413218d854e4a21582eacd479dabca4
Parents: 0c11091 0a9c075
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Sep 28 14:49:56 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Sep 28 14:49:56 2016 +0100

----------------------------------------------------------------------

----------------------------------------------------------------------



[17/18] incubator-commonsrdf git commit: Merge branch 'jsonld-java' into jena-jsonld-rdf4j-integration

Posted by st...@apache.org.
Merge branch 'jsonld-java' into jena-jsonld-rdf4j-integration


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

Branch: refs/heads/jena-jsonld-rdf4j-integration
Commit: 0c110914fbbb737d6cfc141e2d284d9c6f9281ba
Parents: 68438f4 492ea23
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Sep 28 14:49:51 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Sep 28 14:49:51 2016 +0100

----------------------------------------------------------------------
 .../commons/rdf/jsonldjava/JsonLdBlankNode.java |  2 +-
 .../commons/rdf/jsonldjava/JsonLdDataset.java   | 15 ++++++-----
 .../commons/rdf/jsonldjava/JsonLdGraph.java     | 12 ++++++---
 .../commons/rdf/jsonldjava/JsonLdGraphLike.java | 22 +++++++++++----
 .../commons/rdf/jsonldjava/JsonLdIRI.java       |  3 +--
 .../commons/rdf/jsonldjava/JsonLdLiteral.java   |  3 +--
 .../commons/rdf/jsonldjava/JsonLdQuad.java      |  7 ++---
 .../commons/rdf/jsonldjava/JsonLdQuadLike.java  |  2 +-
 .../rdf/jsonldjava/JsonLdRDFTermFactory.java    | 28 +++++++++-----------
 .../commons/rdf/jsonldjava/JsonLdTerm.java      |  3 ++-
 .../commons/rdf/jsonldjava/JsonLdTriple.java    |  5 ++--
 .../rdf/jsonldjava/JsonLdUnionGraph.java        | 12 +++++----
 12 files changed, 65 insertions(+), 49 deletions(-)
----------------------------------------------------------------------



[14/18] incubator-commonsrdf git commit: COMMONSRDF-36 JsonLd*Impl made package protected

Posted by st...@apache.org.
COMMONSRDF-36 JsonLd*Impl made package protected


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

Branch: refs/heads/jena-jsonld-rdf4j-integration
Commit: 492ea2302fe8503a07fd2fbf1cf115234945e315
Parents: 043a061
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Sep 28 14:47:32 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Sep 28 14:47:32 2016 +0100

----------------------------------------------------------------------
 .../commons/rdf/jsonldjava/JsonLdBlankNode.java |  2 +-
 .../commons/rdf/jsonldjava/JsonLdDataset.java   | 15 ++++++-----
 .../commons/rdf/jsonldjava/JsonLdGraph.java     | 12 ++++++---
 .../commons/rdf/jsonldjava/JsonLdGraphLike.java | 22 +++++++++++----
 .../commons/rdf/jsonldjava/JsonLdIRI.java       |  3 +--
 .../commons/rdf/jsonldjava/JsonLdLiteral.java   |  3 +--
 .../commons/rdf/jsonldjava/JsonLdQuad.java      |  7 ++---
 .../commons/rdf/jsonldjava/JsonLdQuadLike.java  |  2 +-
 .../rdf/jsonldjava/JsonLdRDFTermFactory.java    | 28 +++++++++-----------
 .../commons/rdf/jsonldjava/JsonLdTerm.java      |  3 ++-
 .../commons/rdf/jsonldjava/JsonLdTriple.java    |  5 ++--
 .../rdf/jsonldjava/JsonLdUnionGraph.java        | 12 +++++----
 12 files changed, 65 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/492ea230/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdBlankNode.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdBlankNode.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdBlankNode.java
index e54c894..b079c14 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdBlankNode.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdBlankNode.java
@@ -22,6 +22,7 @@ import org.apache.commons.rdf.api.BlankNode;
 import com.github.jsonldjava.core.RDFDataset.Node;
 
 public interface JsonLdBlankNode extends JsonLdTerm, BlankNode {
+}	
 	
 	final class JsonLdBlankNodeImpl extends JsonLdTermImpl implements JsonLdBlankNode {
 		private String blankNodePrefix;
@@ -59,4 +60,3 @@ public interface JsonLdBlankNode extends JsonLdTerm, BlankNode {
 		}
 	}
 
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/492ea230/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdDataset.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdDataset.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdDataset.java
index 55b9f3c..8774cdc 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdDataset.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdDataset.java
@@ -32,17 +32,20 @@ import org.apache.commons.rdf.api.RDFTerm;
 
 import com.github.jsonldjava.core.RDFDataset;
 
-public class JsonLdDataset extends JsonLdGraphLike<org.apache.commons.rdf.api.Quad> implements Dataset {
+public interface JsonLdDataset extends JsonLdGraphLike<org.apache.commons.rdf.api.Quad>, Dataset {
+}
+
+class JsonLdDatasetImpl extends AbstractJsonLdGraphLike<org.apache.commons.rdf.api.Quad> implements JsonLdDataset {
 
-	JsonLdDataset(RDFDataset rdfDataSet) {
+	JsonLdDatasetImpl(RDFDataset rdfDataSet) {
 		super(rdfDataSet);
 	}
 
-	JsonLdDataset(RDFDataset rdfDataset, String bnodePrefix) {
+	JsonLdDatasetImpl(RDFDataset rdfDataset, String bnodePrefix) {
 		super(rdfDataset, bnodePrefix);
 	}
 
-	JsonLdDataset(String bnodePrefix) {
+	JsonLdDatasetImpl(String bnodePrefix) {
 		super(bnodePrefix);
 	}
 
@@ -58,7 +61,7 @@ public class JsonLdDataset extends JsonLdGraphLike<org.apache.commons.rdf.api.Qu
 	
 	@Override
 	public Graph getGraph() {
-		return new JsonLdGraph(rdfDataSet, Optional.empty(), bnodePrefix);
+		return new JsonLdGraphImpl(rdfDataSet, Optional.empty(), bnodePrefix);
 	}	
 
 	@Override
@@ -67,7 +70,7 @@ public class JsonLdDataset extends JsonLdGraphLike<org.apache.commons.rdf.api.Qu
 			return Optional.of(getGraph());
 		}
 		return getGraphNames()
-				.map(g -> (Graph)new JsonLdGraph(rdfDataSet, Optional.of(g), bnodePrefix))
+				.map(g -> (Graph)new JsonLdGraphImpl(rdfDataSet, Optional.of(g), bnodePrefix))
 				.findAny();
 	}
 

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/492ea230/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdGraph.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdGraph.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdGraph.java
index 206c82a..0a59cc3 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdGraph.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdGraph.java
@@ -34,21 +34,25 @@ import com.github.jsonldjava.core.RDFDataset;
  * A {@link Graph} view of a JsonLd {@link RDFDataset}.
  * 
  */
-public class JsonLdGraph extends JsonLdGraphLike<org.apache.commons.rdf.api.Triple> implements Graph {
+public interface JsonLdGraph extends JsonLdGraphLike<org.apache.commons.rdf.api.Triple>, Graph {
+}
+
+class JsonLdGraphImpl extends AbstractJsonLdGraphLike<org.apache.commons.rdf.api.Triple> 
+	implements JsonLdGraph {
 
 	private final Optional<BlankNodeOrIRI> graphName;
 
-	JsonLdGraph(RDFDataset rdfDataSet) {
+	JsonLdGraphImpl(RDFDataset rdfDataSet) {
 		super(rdfDataSet);
 		this.graphName = Optional.empty();
 	}
 	
-	JsonLdGraph(RDFDataset rdfDataSet, Optional<BlankNodeOrIRI> graphName, String bnodePrefix) {
+	JsonLdGraphImpl(RDFDataset rdfDataSet, Optional<BlankNodeOrIRI> graphName, String bnodePrefix) {
 		super(rdfDataSet, bnodePrefix);
 		this.graphName = Objects.requireNonNull(graphName);
 	}
 	
-	JsonLdGraph(String bnodePrefix) {
+	JsonLdGraphImpl(String bnodePrefix) {
 		super(bnodePrefix);
 		this.graphName = Optional.empty();
 	}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/492ea230/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdGraphLike.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdGraphLike.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdGraphLike.java
index cb8e568..dced9cc 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdGraphLike.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdGraphLike.java
@@ -43,8 +43,20 @@ import com.github.jsonldjava.core.RDFDataset.Node;
  *
  * @param <T> specialisation of {@link TripleLike}, e.g. {@link Triple} or {@link Quad}
  */
-abstract class JsonLdGraphLike<T extends TripleLike<BlankNodeOrIRI, IRI, RDFTerm>>
-	implements GraphLike<T, BlankNodeOrIRI, IRI, RDFTerm> {
+public interface JsonLdGraphLike <T extends TripleLike<BlankNodeOrIRI, IRI, RDFTerm>>
+	extends GraphLike<T, BlankNodeOrIRI, IRI, RDFTerm> {
+	/**
+	 * Return the underlying JSONLD-Java {@link RDFDataset}.
+	 * <p>
+	 * Changes in the JSONLD-Java dataset is reflected in this class and vice
+	 * versa.
+	 * 
+	 */
+	public RDFDataset getRdfDataSet();
+}
+
+abstract class AbstractJsonLdGraphLike<T extends TripleLike<BlankNodeOrIRI, IRI, RDFTerm>>
+	implements JsonLdGraphLike<T> {
 	
 	/** 
 	 * Used by {@link #bnodePrefix()} to get a unique UUID per JVM run
@@ -66,17 +78,17 @@ abstract class JsonLdGraphLike<T extends TripleLike<BlankNodeOrIRI, IRI, RDFTerm
 	 */
 	RDFDataset rdfDataSet;
 	
-	JsonLdGraphLike(RDFDataset rdfDataSet) {
+	AbstractJsonLdGraphLike(RDFDataset rdfDataSet) {
 		this(rdfDataSet, "urn:uuid:" + SALT + "#" +  "g"+ System.identityHashCode(rdfDataSet));
 	}
 
-	JsonLdGraphLike(RDFDataset rdfDataSet, String bnodePrefix) {
+	AbstractJsonLdGraphLike(RDFDataset rdfDataSet, String bnodePrefix) {
 		this.rdfDataSet = Objects.requireNonNull(rdfDataSet);
 		this.bnodePrefix = Objects.requireNonNull(bnodePrefix);
 		this.factory = new JsonLdRDFTermFactory(bnodePrefix);
 	}
 	
-	JsonLdGraphLike(String bnodePrefix) {
+	AbstractJsonLdGraphLike(String bnodePrefix) {
 		this(new RDFDataset(), bnodePrefix);
 	}
 	

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/492ea230/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdIRI.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdIRI.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdIRI.java
index aac13e6..dc94401 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdIRI.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdIRI.java
@@ -23,6 +23,7 @@ import com.github.jsonldjava.core.RDFDataset;
 import com.github.jsonldjava.core.RDFDataset.Node;
 
 public interface JsonLdIRI extends JsonLdTerm, IRI {
+}
 
 	final class JsonLdIRIImpl extends JsonLdTermImpl implements JsonLdIRI {
 	
@@ -61,5 +62,3 @@ public interface JsonLdIRI extends JsonLdTerm, IRI {
 			return node.getValue().equals(other.getIRIString());
 		}
 	}
-
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/492ea230/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdLiteral.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdLiteral.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdLiteral.java
index 8eba6e7..01dff6f 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdLiteral.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdLiteral.java
@@ -23,11 +23,11 @@ import java.util.Optional;
 import org.apache.commons.rdf.api.IRI;
 import org.apache.commons.rdf.api.Literal;
 import org.apache.commons.rdf.simple.Types;
-import org.apache.commons.rdf.jsonldjava.JsonLdIRI.JsonLdIRIImpl;
 
 import com.github.jsonldjava.core.RDFDataset.Node;
 
 public interface JsonLdLiteral extends JsonLdTerm, Literal {
+}	
 	
 	class JsonLdLiteralImpl extends JsonLdTermImpl implements JsonLdLiteral {
 	
@@ -97,4 +97,3 @@ public interface JsonLdLiteral extends JsonLdTerm, Literal {
 			
 		}	
 	}
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/492ea230/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdQuad.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdQuad.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdQuad.java
index 524f43c..d9a26b3 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdQuad.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdQuad.java
@@ -23,17 +23,19 @@ import org.apache.commons.rdf.api.BlankNodeOrIRI;
 import org.apache.commons.rdf.api.IRI;
 import org.apache.commons.rdf.api.RDFTerm;
 // Note: To avoid confusion - don't import either Quad
-import org.apache.commons.rdf.jsonldjava.JsonLdQuadLike.JsonLdQuadLikeImpl;
 
 public interface JsonLdQuad extends org.apache.commons.rdf.api.Quad {
 
+	
 	/**
 	 * Return the underlying JsonLD {@link com.github.jsonldjava.core.RDFDataset.Quad}
 	 * 
 	 * @return The JsonLD {@link com.github.jsonldjava.core.RDFDataset.Quad}
 	 */
 	public com.github.jsonldjava.core.RDFDataset.Quad asJsonLdQuad();
-	
+
+}
+
 	final class JsonLdQuadImpl extends JsonLdQuadLikeImpl<BlankNodeOrIRI,IRI,RDFTerm,BlankNodeOrIRI> 
 		implements JsonLdQuad {
 		
@@ -62,4 +64,3 @@ public interface JsonLdQuad extends org.apache.commons.rdf.api.Quad {
 		}	
 	}	
 		
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/492ea230/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdQuadLike.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdQuadLike.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdQuadLike.java
index 224dc30..12fb95d 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdQuadLike.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdQuadLike.java
@@ -27,6 +27,7 @@ import com.github.jsonldjava.core.RDFDataset.Quad;
 public interface JsonLdQuadLike<S extends RDFTerm, P extends RDFTerm, O extends RDFTerm, G extends RDFTerm> extends QuadLike<S,P,O,G> {
 	
 	public Quad asJsonLdQuad();
+}
 	
 	class JsonLdQuadLikeImpl<S extends RDFTerm, P extends RDFTerm, O extends RDFTerm, G extends RDFTerm> implements JsonLdQuadLike<S,P,O,G> {
 		
@@ -72,4 +73,3 @@ public interface JsonLdQuadLike<S extends RDFTerm, P extends RDFTerm, O extends
 		}
 	}
 
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/492ea230/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdRDFTermFactory.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdRDFTermFactory.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdRDFTermFactory.java
index 310fd24..2e586f9 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdRDFTermFactory.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdRDFTermFactory.java
@@ -30,10 +30,6 @@ import org.apache.commons.rdf.api.Literal;
 import org.apache.commons.rdf.api.RDFTerm;
 import org.apache.commons.rdf.api.RDFTermFactory;
 import org.apache.commons.rdf.api.Triple;
-import org.apache.commons.rdf.jsonldjava.JsonLdBlankNode.JsonLdBlankNodeImpl;
-import org.apache.commons.rdf.jsonldjava.JsonLdLiteral.JsonLdLiteralImpl;
-import org.apache.commons.rdf.jsonldjava.JsonLdQuad.JsonLdQuadImpl;
-import org.apache.commons.rdf.jsonldjava.JsonLdTriple.JsonLdTripleImpl;
 import org.apache.commons.rdf.simple.Types;
 
 import com.github.jsonldjava.core.RDFDataset;
@@ -62,8 +58,8 @@ public final class JsonLdRDFTermFactory implements RDFTermFactory {
 	 * @param rdfDataSet JsonLd {@link RDFDataset} to adapt
 	 * @return Adapted {@link Dataset}
 	 */
-	public Dataset asDataset(RDFDataset rdfDataSet) {
-		return new JsonLdDataset(rdfDataSet);
+	public JsonLdDataset asDataset(RDFDataset rdfDataSet) {
+		return new JsonLdDatasetImpl(rdfDataSet);
 	}
 
 	/**
@@ -81,8 +77,8 @@ public final class JsonLdRDFTermFactory implements RDFTermFactory {
 	 * @param rdfDataSet JsonLd {@link RDFDataset} to adapt
 	 * @return Adapted {@link Graph} covering the <em>default graph</em>
 	 */	
-	public Graph asGraph(RDFDataset rdfDataSet) {
-		return new JsonLdGraph(rdfDataSet);
+	public JsonLdGraph asGraph(RDFDataset rdfDataSet) {
+		return new JsonLdGraphImpl(rdfDataSet);
 	}
 
 	public Node asJsonLdNode(RDFTerm term) {
@@ -202,8 +198,8 @@ public final class JsonLdRDFTermFactory implements RDFTermFactory {
 	 * @param rdfDataSet JsonLd {@link RDFDataset} to adapt
 	 * @return Adapted {@link Dataset}
 	 */	
-	public Graph asUnionGraph(RDFDataset rdfDataSet) {
-		return new JsonLdUnionGraph(rdfDataSet);
+	public JsonLdUnionGraph asUnionGraph(RDFDataset rdfDataSet) {
+		return new JsonLdUnionGraphImpl(rdfDataSet);
 	}
 
 	@Override
@@ -220,18 +216,18 @@ public final class JsonLdRDFTermFactory implements RDFTermFactory {
 	}
 
 	@Override
-	public Dataset createDataset() {
-		return new JsonLdDataset(bnodePrefix);
+	public JsonLdDataset createDataset() {
+		return new JsonLdDatasetImpl(bnodePrefix);
 	}
 
 	@Override
-	public Graph createGraph() {
-		return new JsonLdGraph(bnodePrefix);
+	public JsonLdGraph createGraph() {
+		return new JsonLdGraphImpl(bnodePrefix);
 	}
 
 	@Override
 	public JsonLdIRI createIRI(String iri) {
-		return new JsonLdIRI.JsonLdIRIImpl(iri);
+		return new JsonLdIRIImpl(iri);
 	}
 
 	@Override
@@ -288,7 +284,7 @@ public final class JsonLdRDFTermFactory implements RDFTermFactory {
 			return null; // e.g. default graph
 		}
 		if (node.isIRI()) {
-			return new JsonLdIRI.JsonLdIRIImpl(node);
+			return new JsonLdIRIImpl(node);
 		} else if (node.isBlankNode()) {
 			return new JsonLdBlankNodeImpl(node, blankNodePrefix);
 		} else if (node.isLiteral()) {

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/492ea230/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdTerm.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdTerm.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdTerm.java
index 2f250b9..62138d2 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdTerm.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdTerm.java
@@ -29,6 +29,7 @@ public interface JsonLdTerm extends RDFTerm {
 	 * @return JsonLd {@link Node}
 	 */
 	Node asJsonLdNode();
+}
 	
 	abstract class JsonLdTermImpl implements JsonLdTerm {
 		final Node node;
@@ -40,4 +41,4 @@ public interface JsonLdTerm extends RDFTerm {
 		}
 	}
 	
-}
+

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/492ea230/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdTriple.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdTriple.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdTriple.java
index 18e271c..68fe9c0 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdTriple.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdTriple.java
@@ -23,7 +23,6 @@ import org.apache.commons.rdf.api.BlankNodeOrIRI;
 import org.apache.commons.rdf.api.IRI;
 import org.apache.commons.rdf.api.RDFTerm;
 import org.apache.commons.rdf.api.Triple;
-import org.apache.commons.rdf.jsonldjava.JsonLdQuadLike.JsonLdQuadLikeImpl;
 
 import com.github.jsonldjava.core.RDFDataset.Quad;
 
@@ -35,7 +34,8 @@ public interface JsonLdTriple extends Triple {
 	 * @return The JsonLD {@link com.github.jsonldjava.core.RDFDataset.Quad}
 	 */
 	public com.github.jsonldjava.core.RDFDataset.Quad asJsonLdQuad();
-
+}
+	
 	final class JsonLdTripleImpl extends JsonLdQuadLikeImpl<BlankNodeOrIRI, IRI, RDFTerm, RDFTerm>
 		implements JsonLdTriple {
 		
@@ -59,4 +59,3 @@ public interface JsonLdTriple extends Triple {
 			return Objects.hash(getSubject(), getPredicate(), getObject());
 		}
 	}
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/492ea230/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdUnionGraph.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdUnionGraph.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdUnionGraph.java
index 46598ed..81b669a 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdUnionGraph.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdUnionGraph.java
@@ -46,17 +46,20 @@ import com.github.jsonldjava.core.RDFDataset;
  * inefficient as they skip any duplicate triples from multiple
  * graphs.
  */
-class JsonLdUnionGraph extends JsonLdGraphLike<org.apache.commons.rdf.api.Triple> implements Graph {
+public interface JsonLdUnionGraph extends JsonLdGraphLike<org.apache.commons.rdf.api.Triple>, Graph {
+}
+
+class JsonLdUnionGraphImpl extends AbstractJsonLdGraphLike<org.apache.commons.rdf.api.Triple> implements JsonLdUnionGraph {
 
-	JsonLdUnionGraph(String bnodePrefix) {
+	JsonLdUnionGraphImpl(String bnodePrefix) {
 		super(bnodePrefix);
 	}
 	
-	JsonLdUnionGraph(RDFDataset rdfDataSet) {
+	JsonLdUnionGraphImpl(RDFDataset rdfDataSet) {
 		super(rdfDataSet);
 	}
 	
-	JsonLdUnionGraph(RDFDataset rdfDataSet, String bnodePrefix) {
+	JsonLdUnionGraphImpl(RDFDataset rdfDataSet, String bnodePrefix) {
 		super(rdfDataSet, bnodePrefix);
 	}
 
@@ -111,6 +114,5 @@ class JsonLdUnionGraph extends JsonLdGraphLike<org.apache.commons.rdf.api.Triple
 		// Note: Our specialized stream() already removes duplicates using .distinct()
 		return stream().count();
 	}
-
 }
 


[10/18] incubator-commonsrdf git commit: Merge branch 'master' into jsonld-java

Posted by st...@apache.org.
Merge branch 'master' into jsonld-java


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

Branch: refs/heads/jena-jsonld-rdf4j-integration
Commit: 2510a07aca0ec277a4d23e17f4eeef754d0348dd
Parents: be7bfc8 e0d3191
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Sep 28 14:31:00 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Sep 28 14:31:00 2016 +0100

----------------------------------------------------------------------
 .../commons/rdf/api/RDFParserBuilder.java       | 479 ----------------
 .../commons/rdf/experimental/RDFParser.java     | 495 +++++++++++++++++
 .../commons/rdf/experimental/package-info.java  |  34 ++
 .../test/resources/example-rdf/example.jsonld   |  25 +
 api/src/test/resources/example-rdf/example.nq   |   3 +
 api/src/test/resources/example-rdf/example.nt   |   2 +
 api/src/test/resources/example-rdf/example.rdf  |  23 +
 api/src/test/resources/example-rdf/example.trig |   3 +
 api/src/test/resources/example-rdf/example.ttl  |   2 +
 .../rdf/simple/AbstractRDFParserBuilder.java    | 541 ------------------
 .../apache/commons/rdf/simple/GraphImpl.java    |  39 +-
 .../commons/rdf/simple/RDFParseException.java   |  50 --
 .../simple/experimental/AbstractRDFParser.java  | 542 +++++++++++++++++++
 .../simple/experimental/RDFParseException.java  |  50 ++
 .../rdf/simple/experimental/package-info.java   |  34 ++
 .../simple/AbstractRDFParserBuilderTest.java    | 253 ---------
 .../rdf/simple/DummyRDFParserBuilder.java       |  12 +-
 .../experimental/AbstractRDFParserTest.java     | 256 +++++++++
 18 files changed, 1497 insertions(+), 1346 deletions(-)
----------------------------------------------------------------------



[15/18] incubator-commonsrdf git commit: Merge branch 'master' into jena-jsonld-rdf4j-integration

Posted by st...@apache.org.
Merge branch 'master' into jena-jsonld-rdf4j-integration


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

Branch: refs/heads/jena-jsonld-rdf4j-integration
Commit: 6df7f1db169ad134d32738e820278f1f763b70c9
Parents: 6c17d5e e0d3191
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Sep 28 14:49:19 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Sep 28 14:49:19 2016 +0100

----------------------------------------------------------------------
 .../commons/rdf/simple/RDFParseException.java   | 50 --------------------
 .../simple/experimental/AbstractRDFParser.java  |  1 -
 .../simple/experimental/RDFParseException.java  | 50 ++++++++++++++++++++
 .../rdf/simple/DummyRDFParserBuilder.java       |  1 +
 4 files changed, 51 insertions(+), 51 deletions(-)
----------------------------------------------------------------------



[09/18] incubator-commonsrdf git commit: COMMONSRDF-35 no need for - get from rdf4j bom

Posted by st...@apache.org.
COMMONSRDF-35 no need for <version> - get from rdf4j bom


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

Branch: refs/heads/jena-jsonld-rdf4j-integration
Commit: 0a9c075e9af59cf8ec2a735bb7af8281dd571e85
Parents: d905189
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Sep 28 14:30:18 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Sep 28 14:30:18 2016 +0100

----------------------------------------------------------------------
 rdf4j/pom.xml | 2 --
 1 file changed, 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/0a9c075e/rdf4j/pom.xml
----------------------------------------------------------------------
diff --git a/rdf4j/pom.xml b/rdf4j/pom.xml
index 26d7121..db51613 100644
--- a/rdf4j/pom.xml
+++ b/rdf4j/pom.xml
@@ -106,8 +106,6 @@
 		<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>
 		<!-- Languages notably missing, and why: 
 		


[03/18] incubator-commonsrdf git commit: COMMONSRDF-39: Add RDFParser interface

Posted by st...@apache.org.
COMMONSRDF-39: Add RDFParser interface

Merge branch 'parser-with-quads'

See also #21


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

Branch: refs/heads/jena-jsonld-rdf4j-integration
Commit: e0d319181ed8df721de6ee11f072622fb90e1c8a
Parents: de7fe8a 10d27cd
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Sep 28 14:22:43 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Sep 28 14:22:43 2016 +0100

----------------------------------------------------------------------
 .../commons/rdf/experimental/RDFParser.java     | 495 +++++++++++++++++
 .../commons/rdf/experimental/package-info.java  |  34 ++
 .../test/resources/example-rdf/example.jsonld   |  25 +
 api/src/test/resources/example-rdf/example.nq   |   3 +
 api/src/test/resources/example-rdf/example.nt   |   2 +
 api/src/test/resources/example-rdf/example.rdf  |  23 +
 api/src/test/resources/example-rdf/example.trig |   3 +
 api/src/test/resources/example-rdf/example.ttl  |   2 +
 .../simple/experimental/AbstractRDFParser.java  | 542 +++++++++++++++++++
 .../simple/experimental/RDFParseException.java  |  50 ++
 .../rdf/simple/experimental/package-info.java   |  34 ++
 .../rdf/simple/DummyRDFParserBuilder.java       |  98 ++++
 .../experimental/AbstractRDFParserTest.java     | 256 +++++++++
 13 files changed, 1567 insertions(+)
----------------------------------------------------------------------