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/10/26 11:51:03 UTC
[01/50] [abbrv] incubator-commonsrdf git commit: Merge branch
'jsonld-java' into rdf4j-jena-compat
Repository: incubator-commonsrdf
Updated Branches:
refs/heads/COMMONSRDF-46 44b4b6808 -> d6306ad47
Merge branch 'jsonld-java' into rdf4j-jena-compat
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/3353f9a5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/3353f9a5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/3353f9a5
Branch: refs/heads/COMMONSRDF-46
Commit: 3353f9a550ccb78131a17a186a28b7412ce03a92
Parents: 5855fa4 3a8cb56
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Sep 9 16:31:35 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Sep 9 16:31:35 2016 +0100
----------------------------------------------------------------------
jsonld-java/.gitignore | 1 +
jsonld-java/pom.xml | 67 ++++
.../commons/rdf/jsonldjava/JsonLdBlankNode.java | 62 ++++
.../commons/rdf/jsonldjava/JsonLdDataset.java | 112 +++++++
.../commons/rdf/jsonldjava/JsonLdGraph.java | 114 +++++++
.../commons/rdf/jsonldjava/JsonLdGraphLike.java | 204 +++++++++++++
.../commons/rdf/jsonldjava/JsonLdIRI.java | 65 ++++
.../commons/rdf/jsonldjava/JsonLdLiteral.java | 100 ++++++
.../rdf/jsonldjava/JsonLdParserBuilder.java | 131 ++++++++
.../commons/rdf/jsonldjava/JsonLdQuad.java | 65 ++++
.../commons/rdf/jsonldjava/JsonLdQuadLike.java | 75 +++++
.../rdf/jsonldjava/JsonLdRDFTermFactory.java | 304 +++++++++++++++++++
.../commons/rdf/jsonldjava/JsonLdTerm.java | 43 +++
.../commons/rdf/jsonldjava/JsonLdTriple.java | 62 ++++
.../rdf/jsonldjava/JsonLdUnionGraph.java | 116 +++++++
.../commons/rdf/jsonldjava/package-info.java | 27 ++
.../org.apache.commons.rdf.api.RDFTermFactory | 1 +
jsonld-java/src/main/resources/test.jsonld | 26 ++
.../rdf/jsonldjava/JsonLdBlankNodeTest.java | 25 ++
.../commons/rdf/jsonldjava/JsonLdGraphTest.java | 31 ++
.../rdf/jsonldjava/JsonLdParserBuilderTest.java | 116 +++++++
.../jsonldjava/JsonLdRDFTermFactoryTest.java | 54 ++++
pom.xml | 14 +
23 files changed, 1815 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/3353f9a5/pom.xml
----------------------------------------------------------------------
diff --cc pom.xml
index 3e858d1,5669122..02d205a
--- a/pom.xml
+++ b/pom.xml
@@@ -218,9 -215,7 +218,10 @@@
<modules>
<module>api</module>
<module>simple</module>
+ <module>rdf4j</module>
+ <module>jena</module>
+ <module>jsonld-java</module>
+ <module>integration-tests</module>
</modules>
<dependencyManagement>
[03/50] [abbrv] 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/5a49f969
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/5a49f969
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/5a49f969
Branch: refs/heads/COMMONSRDF-46
Commit: 5a49f96949301dbce53bff650e5591342bb887e6
Parents: 888a2a4 be220ea
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Sep 9 16:41:13 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Sep 9 16:41:13 2016 +0100
----------------------------------------------------------------------
.../org/apache/commons/rdf/rdf4j/RDF4JParserBuilder.java | 10 +++++-----
.../commons/rdf/simple/AbstractRDFParserBuilder.java | 3 +--
2 files changed, 6 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
[11/50] [abbrv] 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/2b51794e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/2b51794e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/2b51794e
Branch: refs/heads/COMMONSRDF-46
Commit: 2b51794e84caf64831c131f4cd84f34d3976dfa2
Parents: 112505d de7fe8a
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Mon Sep 12 19:03:47 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Mon Sep 12 19:03:47 2016 +0100
----------------------------------------------------------------------
.../apache/commons/rdf/simple/GraphImpl.java | 39 +++++++++++---------
1 file changed, 21 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
[05/50] [abbrv] 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/e5e85bd3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/e5e85bd3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/e5e85bd3
Branch: refs/heads/COMMONSRDF-46
Commit: e5e85bd39ba700ac2072b142c867717b4a462baf
Parents: 5ed73ac 3d63a0e
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Sep 9 17:15:44 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Sep 9 17:15:44 2016 +0100
----------------------------------------------------------------------
.../rdf/jsonldjava/JsonLdParserBuilder.java | 66 ++++++++++++++------
.../rdf/jsonldjava/JsonLdRDFTermFactory.java | 2 +-
2 files changed, 47 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
[23/50] [abbrv] incubator-commonsrdf git commit: RDFParser moved to
org.apache.commons.rdf.experimental
Posted by st...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/a189f91e/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/a189f91e/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/a189f91e/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 036b54b..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.RDF4JParser} 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.RDF4JParser#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.RDF4JParser#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}
*
*
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/a189f91e/simple/src/main/java/org/apache/commons/rdf/simple/AbstractRDFParser.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/AbstractRDFParser.java b/simple/src/main/java/org/apache/commons/rdf/simple/AbstractRDFParser.java
deleted file mode 100644
index e58fced..0000000
--- a/simple/src/main/java/org/apache/commons/rdf/simple/AbstractRDFParser.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.RDFParser;
-import org.apache.commons.rdf.api.RDFSyntax;
-import org.apache.commons.rdf.api.RDFTermFactory;
-
-/**
- * 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/a189f91e/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
index d1cdd57..adb5b0e 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/RDFParseException.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/RDFParseException.java
@@ -18,7 +18,7 @@
package org.apache.commons.rdf.simple;
-import org.apache.commons.rdf.api.RDFParser;
+import org.apache.commons.rdf.experimental.RDFParser;
public class RDFParseException extends Exception {
private static final long serialVersionUID = 5427752643780702976L;
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/a189f91e/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..f675459
--- /dev/null
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParser.java
@@ -0,0 +1,543 @@
+/**
+ * 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.RDFParseException;
+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/a189f91e/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/a189f91e/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
index acb75b7..f115e94 100644
--- a/simple/src/test/java/org/apache/commons/rdf/simple/AbstractRDFParserBuilderTest.java
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/AbstractRDFParserBuilderTest.java
@@ -32,11 +32,12 @@ 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.RDFParser;
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.experimental.AbstractRDFParser;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/a189f91e/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 fe0b36e..99ed576 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,8 +23,9 @@ 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.RDFParser;
import org.apache.commons.rdf.api.RDFTermFactory;
+import org.apache.commons.rdf.experimental.RDFParser;
+import org.apache.commons.rdf.simple.experimental.AbstractRDFParser;
/**
* For test purposes - a {@link RDFParser} that inserts information
[48/50] [abbrv] incubator-commonsrdf git commit: fromJena/toJena ->
as* / asJena*
Posted by st...@apache.org.
fromJena/toJena -> as* / asJena*
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/5c190d21
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/5c190d21
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/5c190d21
Branch: refs/heads/COMMONSRDF-46
Commit: 5c190d2104db3b64bd87b7520f9d45859e5805d9
Parents: 6fdc990
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Oct 26 12:30:51 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Oct 26 12:30:51 2016 +0100
----------------------------------------------------------------------
.../apache/commons/rdf/jena/JenaFactory.java | 150 ++++++++++---------
.../rdf/jena/experimental/JenaRDFParser.java | 4 +-
.../commons/rdf/jena/impl/AbstractQuadLike.java | 28 ++--
.../rdf/jena/impl/InternalJenaFactory.java | 72 ++++-----
.../commons/rdf/jena/impl/JenaDatasetImpl.java | 28 ++--
.../commons/rdf/jena/impl/JenaGraphImpl.java | 30 ++--
.../jena/TestJenaGraphToCommonsRDFGraph.java | 2 +-
7 files changed, 164 insertions(+), 150 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/5c190d21/jena/src/main/java/org/apache/commons/rdf/jena/JenaFactory.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/JenaFactory.java b/jena/src/main/java/org/apache/commons/rdf/jena/JenaFactory.java
index 0d735c7..f2c65df 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/JenaFactory.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/JenaFactory.java
@@ -50,11 +50,25 @@ import org.apache.jena.sparql.graph.GraphFactory;
/**
* RDFTermFactory with Jena-backed objects.
* <p>
- * This factory can also convert existing objects from/to Jena with methods like
- * {@link #fromJena(org.apache.jena.graph.Graph)} and {@link #toJena(Graph)}.
+ * This factory can also convert existing objects from Jena with methods like
+ * {@link #asRDFTerm(Node)} and {@link #asGraph(org.apache.jena.graph.Graph)},
+ * and vice versa from any Commons RDF object to Jena with the
+ * <code>asJena*</code> methods like {@link #asJenaNode(RDFTerm)} and
+ * {@link #asJenaGraph(Graph)}.
* <p>
- * For the purpose of {@link BlankNode} identity, this factory will use an internal
- * {@link UUID} as a salt. See {@link BlankNode#uniqueReference()} for details.
+ * Note that Commons RDF objects created by this class implement the
+ * specializations interfaces like {@link JenaRDFTerm}, {@link JenaGraph} and
+ * {@link JenaTriple}, which provide access to the underlying Jena objects, e.g.
+ * with {@link JenaRDFTerm#asJenaNode()}.
+ * <p>
+ * For the purpose of {@link BlankNode} identity when using
+ * {@link #createBlankNode(String)} (see {@link BlankNode#equals(Object)} and
+ * {@link BlankNode#uniqueReference()}), each instance of this factory uses an
+ * internal random state. If for some reason consistent/reproducible BlankNode
+ * identity is desired, it is possible to retrieve the state as a UUID using
+ * {@link #salt} for subsequent use with {@link JenaFactory#JenaFactory(UUID)} -
+ * note that such consistency is only guaranteed within the same minor version
+ * of Commons RDF.
*
* @see RDFTermFactory
*/
@@ -68,7 +82,7 @@ public final class JenaFactory implements RDFTermFactory {
* Create a JenaFactory.
* <p>
* This constructor will use a randomly generated {@link UUID} as a salt
- * for the purposes of {@link BlankNode} identity, see {@link #getSalt()}.
+ * for the purposes of {@link BlankNode} identity, see {@link #salt()}.
*/
public JenaFactory() {
this.salt = UUID.randomUUID();
@@ -91,22 +105,22 @@ public final class JenaFactory implements RDFTermFactory {
@Override
public JenaBlankNode createBlankNode() {
- return internalJenaFactory.createBlankNode(getSalt());
+ return internalJenaFactory.createBlankNode(salt());
}
@Override
public JenaBlankNode createBlankNode(String name) {
- return internalJenaFactory.createBlankNode(name, getSalt());
+ return internalJenaFactory.createBlankNode(name, salt());
}
@Override
public JenaDataset createDataset() {
- return internalJenaFactory.createDataset(getSalt());
+ return internalJenaFactory.createDataset(salt());
}
@Override
public JenaGraph createGraph() {
- return internalJenaFactory.createGraph(getSalt());
+ return internalJenaFactory.createGraph(salt());
}
@Override
@@ -203,7 +217,7 @@ public final class JenaFactory implements RDFTermFactory {
* {@link Node#getBlankNodeId()} for the purpose of its
* {@link BlankNode#uniqueReference()}.
*
- * @see #fromJena(RDFTermFactory, Node)
+ * @see #asRDFTerm(RDFTermFactory, Node)
*
* @param node
* The Jena Node to adapt. It's {@link Node#isConcrete()} must be
@@ -212,8 +226,8 @@ public final class JenaFactory implements RDFTermFactory {
* @throws ConversionException If the {@link Node} can't be represented as an {@link RDFTerm}, e.g.
* if the node is not concrete or represents a variable in Jena.
*/
- public JenaRDFTerm fromJena(Node node) throws ConversionException {
- return internalJenaFactory.fromJena(node, getSalt());
+ public JenaRDFTerm asRDFTerm(Node node) throws ConversionException {
+ return internalJenaFactory.createRDFTerm(node, salt());
}
/**
@@ -224,7 +238,7 @@ public final class JenaFactory implements RDFTermFactory {
* that care should be taken if reusing an {@link RDFTermFactory} instance
* for multiple conversion sessions.
*
- * @see #fromJena(Node)
+ * @see #asRDFTerm(Node)
*
* @param factory {@link RDFTermFactory} to use for creating {@link RDFTerm}.
* @param node
@@ -234,13 +248,13 @@ public final class JenaFactory implements RDFTermFactory {
* @throws ConversionException If the {@link Node} can't be represented as an {@link RDFTerm}, e.g.
* if the node is not concrete or represents a variable in Jena.
*/
- public static RDFTerm fromJena(RDFTermFactory factory, Node node) {
+ public static RDFTerm asRDFTerm(RDFTermFactory factory, Node node) {
if (node == null) {
return null;
}
if (factory instanceof JenaFactory) {
// No need to convert, just wrap
- return ((JenaFactory) factory).fromJena(node);
+ return ((JenaFactory) factory).asRDFTerm(node);
}
if (node.isURI())
return factory.createIRI(node.getURI());
@@ -268,7 +282,7 @@ public final class JenaFactory implements RDFTermFactory {
* {@link Node#getBlankNodeId()} for the purpose of its
* {@link BlankNode#uniqueReference()}.
*
- * @see #fromJena(RDFTermFactory, org.apache.jena.graph.Triple)
+ * @see #asTriple(RDFTermFactory, org.apache.jena.graph.Triple)
*
* @param triple
* Jena {@link org.apache.jena.graph.Triple} to adapt
@@ -277,8 +291,8 @@ public final class JenaFactory implements RDFTermFactory {
* if any of the triple's nodes are not concrete or the triple
* is a generalized triple
*/
- public JenaTriple fromJena(org.apache.jena.graph.Triple triple) throws ConversionException {
- return internalJenaFactory.fromJena(triple, getSalt());
+ public JenaTriple asTriple(org.apache.jena.graph.Triple triple) throws ConversionException {
+ return internalJenaFactory.createTriple(triple, salt());
}
/**
@@ -293,7 +307,7 @@ public final class JenaFactory implements RDFTermFactory {
* {@link Node#getBlankNodeId()} for the purpose of its
* {@link BlankNode#uniqueReference()}.
*
- * @see #fromJena(RDFTermFactory, org.apache.jena.graph.Triple)
+ * @see #asTriple(RDFTermFactory, org.apache.jena.graph.Triple)
*
* @param triple
* Jena triple
@@ -303,8 +317,8 @@ public final class JenaFactory implements RDFTermFactory {
* @throws ConversionException
* if any of the triple's nodes are not concrete
*/
- public JenaTripleLike fromJenaGeneralized(org.apache.jena.graph.Triple triple) throws ConversionException {
- return internalJenaFactory.fromJenaGeneralized(triple, getSalt());
+ public JenaTripleLike asGeneralizedTriple(org.apache.jena.graph.Triple triple) throws ConversionException {
+ return internalJenaFactory.createGeneralizedTriple(triple, salt());
}
/**
@@ -322,8 +336,8 @@ public final class JenaFactory implements RDFTermFactory {
* {@link Node#getBlankNodeId()} for the purpose of its
* {@link BlankNode#uniqueReference()}.
*
- * @see #fromJena(org.apache.jena.sparql.core.Quad)
- * @see #fromJenaGeneralized(org.apache.jena.graph.Triple)
+ * @see #asQuad(org.apache.jena.sparql.core.Quad)
+ * @see #asGeneralizedTriple(org.apache.jena.graph.Triple)
*
* @param quad
* Jena quad
@@ -333,8 +347,8 @@ public final class JenaFactory implements RDFTermFactory {
* @throws ConversionException
* if any of the quad nodes are not concrete
*/
- public JenaQuadLike<RDFTerm> fromJenaGeneralized(org.apache.jena.sparql.core.Quad quad) throws ConversionException {
- return internalJenaFactory.fromJenaGeneralized(quad, getSalt());
+ public JenaQuadLike<RDFTerm> asGeneralizedQuad(org.apache.jena.sparql.core.Quad quad) throws ConversionException {
+ return internalJenaFactory.createGeneralizedQuad(quad, salt());
}
/**
@@ -346,7 +360,7 @@ public final class JenaFactory implements RDFTermFactory {
* that care should be taken if reusing an {@link RDFTermFactory} instance
* for multiple conversion sessions.
*
- * @see #fromJena(org.apache.jena.graph.Triple)
+ * @see #asTriple(org.apache.jena.graph.Triple)
*
* @param factory {@link RDFTermFactory} to use for creating the {@link Triple} and its
* {@link RDFTerm}s.
@@ -357,21 +371,21 @@ public final class JenaFactory implements RDFTermFactory {
* if any of the triple's nodes are not concrete or the triple
* is a generalized triple
*/
- public static Triple fromJena(RDFTermFactory factory, org.apache.jena.graph.Triple triple)
+ public static Triple asTriple(RDFTermFactory factory, org.apache.jena.graph.Triple triple)
throws ConversionException{
if (factory instanceof JenaFactory) {
// No need to convert, just wrap
- return ((JenaFactory) factory).fromJena(triple);
+ return ((JenaFactory) factory).asTriple(triple);
}
final BlankNodeOrIRI subject;
final IRI predicate;
try {
- subject = (BlankNodeOrIRI) fromJena(factory, triple.getSubject());
- predicate = (IRI) fromJena(factory, triple.getPredicate());
+ subject = (BlankNodeOrIRI) asRDFTerm(factory, triple.getSubject());
+ predicate = (IRI) asRDFTerm(factory, triple.getPredicate());
} catch (ClassCastException ex) {
throw new ConversionException("Can't convert generalized triple: " + triple, ex);
}
- RDFTerm object = fromJena(factory, triple.getObject());
+ RDFTerm object = asRDFTerm(factory, triple.getObject());
return factory.createTriple(subject, predicate, object);
}
@@ -388,8 +402,8 @@ public final class JenaFactory implements RDFTermFactory {
* Jena quad
* @return Adapted quad
*/
- public JenaQuad fromJena(org.apache.jena.sparql.core.Quad quad) {
- return internalJenaFactory.fromJena(quad, getSalt());
+ public JenaQuad asQuad(org.apache.jena.sparql.core.Quad quad) {
+ return internalJenaFactory.createQuad(quad, salt());
}
/**
@@ -410,8 +424,8 @@ public final class JenaFactory implements RDFTermFactory {
* Jena {@link org.apache.jena.graph.Graph} to adapt
* @return Adapted {@link JenaGraph}
*/
- public JenaGraph fromJena(org.apache.jena.graph.Graph graph) {
- return internalJenaFactory.fromJena(graph, getSalt());
+ public JenaGraph asGraph(org.apache.jena.graph.Graph graph) {
+ return internalJenaFactory.createGraph(graph, salt());
}
/**
@@ -429,8 +443,8 @@ public final class JenaFactory implements RDFTermFactory {
* Jena {@link org.apache.jena.rdf.model.Model} to adapt
* @return Adapted {@link JenaGraph}
*/
- public JenaGraph fromJena(org.apache.jena.rdf.model.Model model) {
- return internalJenaFactory.fromJena(model, getSalt());
+ public JenaGraph asGraph(org.apache.jena.rdf.model.Model model) {
+ return internalJenaFactory.createGraph(model, salt());
}
/**
@@ -449,8 +463,8 @@ public final class JenaFactory implements RDFTermFactory {
* @param datasetGraph Jena {@link DatasetGraph} to adapt
* @return Adapted {@link JenaDataset}
*/
- public JenaDataset fromJena(DatasetGraph datasetGraph) {
- return internalJenaFactory.fromJena(datasetGraph, getSalt());
+ public JenaDataset asDataset(DatasetGraph datasetGraph) {
+ return internalJenaFactory.createDataset(datasetGraph, salt());
}
/**
@@ -469,8 +483,8 @@ public final class JenaFactory implements RDFTermFactory {
* @param datasetGraph Jena {@link org.apache.jena.query.Dataset} to adapt
* @return Adapted {@link JenaDataset}
*/
- public JenaDataset fromJena(org.apache.jena.query.Dataset datasetGraph) {
- return internalJenaFactory.fromJena(datasetGraph.asDatasetGraph(), getSalt());
+ public JenaDataset asDataset(org.apache.jena.query.Dataset datasetGraph) {
+ return internalJenaFactory.createDataset(datasetGraph.asDatasetGraph(), salt());
}
/**
@@ -482,8 +496,8 @@ public final class JenaFactory implements RDFTermFactory {
* meaning that care should be taken if reusing an {@link RDFTermFactory}
* instance for multiple conversion sessions.
*
- * @see #fromJena(org.apache.jena.sparql.core.Quad)
- * @see #fromJenaGeneralized(org.apache.jena.sparql.core.Quad)
+ * @see #asQuad(org.apache.jena.sparql.core.Quad)
+ * @see #asGeneralizedQuad(org.apache.jena.sparql.core.Quad)
*
* @param factory
* {@link RDFTermFactory} to use for creating the {@link Triple}
@@ -495,15 +509,15 @@ public final class JenaFactory implements RDFTermFactory {
* if any of the quad's nodes are not concrete or the quad
* is a generalized quad
*/
- public static Quad fromJena(RDFTermFactory factory, org.apache.jena.sparql.core.Quad quad) {
+ public static Quad asQuad(RDFTermFactory factory, org.apache.jena.sparql.core.Quad quad) {
if (factory instanceof JenaFactory) {
// No need to convert, just wrap
- return ((JenaFactory) factory).fromJena(quad);
+ return ((JenaFactory) factory).asQuad(quad);
}
- BlankNodeOrIRI graphName = (BlankNodeOrIRI) (fromJena(factory, quad.getGraph()));
- BlankNodeOrIRI subject = (BlankNodeOrIRI) (fromJena(factory, quad.getSubject()));
- IRI predicate = (IRI) (fromJena(factory, quad.getPredicate()));
- RDFTerm object = fromJena(factory, quad.getObject());
+ BlankNodeOrIRI graphName = (BlankNodeOrIRI) (asRDFTerm(factory, quad.getGraph()));
+ BlankNodeOrIRI subject = (BlankNodeOrIRI) (asRDFTerm(factory, quad.getSubject()));
+ IRI predicate = (IRI) (asRDFTerm(factory, quad.getPredicate()));
+ RDFTerm object = asRDFTerm(factory, quad.getObject());
return factory.createQuad(graphName, subject, predicate, object);
}
@@ -513,7 +527,7 @@ public final class JenaFactory implements RDFTermFactory {
* @param lang {@link Lang} to convert
* @return Matched {@link RDFSyntax}, otherwise {@link Optional#empty()}
*/
- public Optional<RDFSyntax> langToRdfSyntax(Lang lang) {
+ public Optional<RDFSyntax> asRDFSyntax(Lang lang) {
return RDFSyntax.byMediaType(lang.getContentType().getContentType());
}
@@ -523,7 +537,7 @@ public final class JenaFactory implements RDFTermFactory {
* @param rdfSyntax {@link RDFSyntax} to convert
* @return Matched {@link Lang}, otherwise {@link Optional#empty()}
*/
- public Optional<Lang> rdfSyntaxToLang(RDFSyntax rdfSyntax) {
+ public Optional<Lang> asJenaLang(RDFSyntax rdfSyntax) {
return Optional.ofNullable(RDFLanguages.contentTypeToLang(rdfSyntax.mediaType));
}
@@ -542,11 +556,11 @@ public final class JenaFactory implements RDFTermFactory {
* @return A {@link StreamRDF} that will stream converted quads to the
* consumer
*/
- public static StreamRDF streamJenaToCommonsRDF(RDFTermFactory factory, Consumer<Quad> consumer) {
+ public static StreamRDF streamJenaToQuad(RDFTermFactory factory, Consumer<Quad> consumer) {
return new StreamRDFBase() {
@Override
public void quad(org.apache.jena.sparql.core.Quad quad) {
- consumer.accept(fromJena(factory, quad));
+ consumer.accept(asQuad(factory, quad));
}
};
}
@@ -571,7 +585,7 @@ public final class JenaFactory implements RDFTermFactory {
return new StreamRDFBase() {
@Override
public void triple(org.apache.jena.graph.Triple triple) {
- generalizedConsumer.accept(fromJenaGeneralized(triple));
+ generalizedConsumer.accept(asGeneralizedTriple(triple));
}
};
}
@@ -596,7 +610,7 @@ public final class JenaFactory implements RDFTermFactory {
return new StreamRDFBase() {
@Override
public void quad(org.apache.jena.sparql.core.Quad quad) {
- generalizedConsumer.accept(fromJenaGeneralized(quad));
+ generalizedConsumer.accept(asGeneralizedQuad(quad));
}
};
}
@@ -609,11 +623,11 @@ public final class JenaFactory implements RDFTermFactory {
* @param graph Commons RDF {@link Graph} to convert
* @return Converted Jena {@link org.apache.jena.graph.Graph}
*/
- public org.apache.jena.graph.Graph toJena(Graph graph) {
+ public org.apache.jena.graph.Graph asJenaGraph(Graph graph) {
if (graph instanceof JenaGraph)
return ((JenaGraph) graph).asJenaGraph();
org.apache.jena.graph.Graph g = GraphFactory.createGraphMem();
- graph.stream().forEach(t -> g.add(toJena(t)));
+ graph.stream().forEach(t -> g.add(asJenaTriple(t)));
return g;
}
@@ -625,7 +639,7 @@ public final class JenaFactory implements RDFTermFactory {
* @param term Commons RDF {@link RDFTerm} to convert
* @return Converted Jena {@link Node}
*/
- public Node toJena(RDFTerm term) {
+ public Node asJenaNode(RDFTerm term) {
if (term == null) {
return null;
}
@@ -662,13 +676,13 @@ public final class JenaFactory implements RDFTermFactory {
* @param triple Commons RDF {@link Triple} to convert
* @return Converted Jena {@link org.apache.jena.graph.Triple}
*/
- public org.apache.jena.graph.Triple toJena(Triple triple) {
+ public org.apache.jena.graph.Triple asJenaTriple(Triple triple) {
if (triple instanceof JenaTriple)
return ((JenaTriple) triple).asJenaTriple();
return org.apache.jena.graph.Triple.create(
- toJena(triple.getSubject()),
- toJena(triple.getPredicate()),
- toJena(triple.getObject()));
+ asJenaNode(triple.getSubject()),
+ asJenaNode(triple.getPredicate()),
+ asJenaNode(triple.getObject()));
}
@@ -682,15 +696,15 @@ public final class JenaFactory implements RDFTermFactory {
* @param quad Commons RDF {@link Quad} to convert
* @return Converted Jena {@link org.apache.jena.sparql.core.Quad}
*/
- public org.apache.jena.sparql.core.Quad toJena(Quad quad) {
+ public org.apache.jena.sparql.core.Quad asJenaQuad(Quad quad) {
if (quad instanceof JenaQuad) {
return ((JenaQuad) quad).asJenaQuad();
}
return org.apache.jena.sparql.core.Quad.create(
- toJena(quad.getGraphName().orElse(null)),
- toJena(quad.getSubject()),
- toJena(quad.getPredicate()),
- toJena(quad.getObject()));
+ asJenaNode(quad.getGraphName().orElse(null)),
+ asJenaNode(quad.getSubject()),
+ asJenaNode(quad.getPredicate()),
+ asJenaNode(quad.getObject()));
}
// Some simple validations - full IRI parsing is not cheap.
@@ -720,7 +734,7 @@ public final class JenaFactory implements RDFTermFactory {
*
* @return The {@link UUID} used as salt
*/
- public UUID getSalt() {
+ public UUID salt() {
return salt;
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/5c190d21/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
index 19a8a63..14d13d9 100644
--- 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
@@ -81,11 +81,11 @@ public class JenaRDFParser extends AbstractRDFParser<JenaRDFParser> implements R
} else if (generalizedConsumerTriple != null) {
dest = jenaFactory.streamJenaToGeneralizedTriple(generalizedConsumerTriple);
} else {
- dest = JenaFactory.streamJenaToCommonsRDF(getRdfTermFactory().get(), getTarget());
+ dest = JenaFactory.streamJenaToQuad(getRdfTermFactory().get(), getTarget());
}
}
- Lang lang = getContentTypeSyntax().flatMap(jenaFactory::rdfSyntaxToLang).orElse(null);
+ Lang lang = getContentTypeSyntax().flatMap(jenaFactory::asJenaLang).orElse(null);
String baseStr = getBase().map(IRI::getIRIString).orElse(null);
if (getSourceIri().isPresent()) {
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/5c190d21/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractQuadLike.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractQuadLike.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractQuadLike.java
index c66a1da..9166731 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractQuadLike.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractQuadLike.java
@@ -69,18 +69,18 @@ abstract class AbstractQuadLike<S extends RDFTerm, P extends RDFTerm, O extends
@SuppressWarnings("unchecked")
AbstractQuadLike(org.apache.jena.sparql.core.Quad quad, UUID salt) {
this.quad = Objects.requireNonNull(quad);
- this.subject = (S) internalJenaFactory.fromJena(quad.getSubject(), salt);
- this.predicate = (P) internalJenaFactory.fromJena(quad.getPredicate(), salt);
- this.object = (O)internalJenaFactory.fromJena(quad.getObject(), salt);
- this.graphName = Optional.of((G) internalJenaFactory.fromJena(quad.getGraph(), salt));
+ this.subject = (S) internalJenaFactory.createRDFTerm(quad.getSubject(), salt);
+ this.predicate = (P) internalJenaFactory.createRDFTerm(quad.getPredicate(), salt);
+ this.object = (O)internalJenaFactory.createRDFTerm(quad.getObject(), salt);
+ this.graphName = Optional.of((G) internalJenaFactory.createRDFTerm(quad.getGraph(), salt));
}
@SuppressWarnings("unchecked")
AbstractQuadLike(org.apache.jena.graph.Triple triple, UUID salt) {
this.triple = Objects.requireNonNull(triple);
- this.subject = (S) internalJenaFactory.fromJena(triple.getSubject(), salt);
- this.predicate = (P) internalJenaFactory.fromJena(triple.getPredicate(), salt);
- this.object = (O)internalJenaFactory.fromJena(triple.getObject(), salt);
+ this.subject = (S) internalJenaFactory.createRDFTerm(triple.getSubject(), salt);
+ this.predicate = (P) internalJenaFactory.createRDFTerm(triple.getPredicate(), salt);
+ this.object = (O)internalJenaFactory.createRDFTerm(triple.getObject(), salt);
this.graphName = Optional.empty();
}
@@ -89,10 +89,10 @@ abstract class AbstractQuadLike<S extends RDFTerm, P extends RDFTerm, O extends
JenaFactory factory = new JenaFactory();
if (quad == null) {
quad = org.apache.jena.sparql.core.Quad.create(
- factory.toJena(graphName.orElse(null)),
- factory.toJena(subject),
- factory.toJena(predicate),
- factory.toJena(object));
+ factory.asJenaNode(graphName.orElse(null)),
+ factory.asJenaNode(subject),
+ factory.asJenaNode(predicate),
+ factory.asJenaNode(object));
}
return quad;
}
@@ -102,9 +102,9 @@ abstract class AbstractQuadLike<S extends RDFTerm, P extends RDFTerm, O extends
JenaFactory factory = new JenaFactory();
if (triple == null) {
triple = org.apache.jena.graph.Triple.create(
- factory.toJena(subject),
- factory.toJena(predicate),
- factory.toJena(object));
+ factory.asJenaNode(subject),
+ factory.asJenaNode(predicate),
+ factory.asJenaNode(object));
}
return triple;
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/5c190d21/jena/src/main/java/org/apache/commons/rdf/jena/impl/InternalJenaFactory.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/InternalJenaFactory.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/InternalJenaFactory.java
index 67fccb7..03ef887 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/InternalJenaFactory.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/InternalJenaFactory.java
@@ -65,12 +65,40 @@ public abstract class InternalJenaFactory {
public JenaBlankNode createBlankNode(UUID salt) {
return new JenaBlankNodeImpl(NodeFactory.createBlankNode(), salt);
}
+ public JenaDataset createDataset(DatasetGraph datasetGraph, UUID salt) {
+ return new JenaDatasetImpl(datasetGraph, salt);
+ }
+
public JenaDataset createDataset(UUID salt) {
DatasetGraph dg = DatasetGraphFactory.createGeneral();
// Or which createMethod() -- a bit confusing with lots of choice..
return new JenaDatasetImpl(dg, salt);
}
+ public JenaGeneralizedQuadLike createGeneralizedQuad(org.apache.jena.sparql.core.Quad quad, UUID salt) {
+ return new JenaGeneralizedQuadLikeImpl(quad, salt);
+ }
+
+ public JenaGeneralizedQuadLike createGeneralizedQuad(RDFTerm subject, RDFTerm predicate, RDFTerm object, RDFTerm graphName) {
+ return new JenaGeneralizedQuadLikeImpl(subject, predicate, object, Optional.ofNullable(graphName));
+ }
+
+ public JenaGeneralizedTripleLike createGeneralizedTriple(org.apache.jena.graph.Triple triple, UUID salt) {
+ return new JenaGeneralizedTripleLikeImpl(triple, salt);
+ }
+
+ public JenaGeneralizedTripleLike createGeneralizedTriple(RDFTerm subject, RDFTerm predicate, RDFTerm object) {
+ return new JenaGeneralizedTripleLikeImpl(subject, predicate, object);
+ }
+
+ public JenaGraph createGraph(Model model, UUID salt) {
+ return new JenaGraphImpl(model, salt);
+ }
+
+ public JenaGraph createGraph(org.apache.jena.graph.Graph graph, UUID salt) {
+ return new JenaGraphImpl(graph, salt);
+ }
+
public JenaGraph createGraph(UUID salt) {
return new JenaGraphImpl(GraphFactory.createDefaultGraph(), salt);
}
@@ -78,7 +106,7 @@ public abstract class InternalJenaFactory {
public JenaIRI createIRI(String iriStr) {
return new JenaIRIImpl(iriStr);
}
-
+
public JenaLiteral createLiteral(String lexStr) {
return new JenaLiteralImpl(NodeFactory.createLiteral(lexStr));
}
@@ -91,23 +119,15 @@ public abstract class InternalJenaFactory {
return new JenaLiteralImpl(NodeFactory.createLiteral(lexStr, langTag));
}
- public JenaTriple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- return new JenaTripleImpl(subject, predicate, object);
- }
-
public JenaQuad createQuad(BlankNodeOrIRI subject, IRI predicate, RDFTerm object, BlankNodeOrIRI graphName) {
return new JenaQuadImpl(subject, predicate, object, Optional.ofNullable(graphName));
}
-
- public JenaGeneralizedTripleLike createGeneralizedTriple(RDFTerm subject, RDFTerm predicate, RDFTerm object) {
- return new JenaGeneralizedTripleLikeImpl(subject, predicate, object);
+
+ public JenaQuad createQuad(org.apache.jena.sparql.core.Quad quad, UUID salt) {
+ return new JenaQuadImpl(quad, salt);
}
- public JenaGeneralizedQuadLike createGeneralizedQuad(RDFTerm subject, RDFTerm predicate, RDFTerm object, RDFTerm graphName) {
- return new JenaGeneralizedQuadLikeImpl(subject, predicate, object, Optional.ofNullable(graphName));
- }
-
- public JenaRDFTerm fromJena(Node node, UUID salt) throws ConversionException {
+ public JenaRDFTerm createRDFTerm(Node node, UUID salt) throws ConversionException {
if (! node.isConcrete()) {
throw new ConversionException("Node is not a concrete RDF Term: " + node);
}
@@ -131,32 +151,12 @@ public abstract class InternalJenaFactory {
throw new ConversionException("Unrecognized node type: " + node);
}
- public JenaGraph fromJena(org.apache.jena.graph.Graph graph, UUID salt) {
- return new JenaGraphImpl(graph, salt);
- }
-
- public JenaGraph fromJena(Model model, UUID salt) {
- return new JenaGraphImpl(model, salt);
- }
-
- public JenaDataset fromJena(DatasetGraph datasetGraph, UUID salt) {
- return new JenaDatasetImpl(datasetGraph, salt);
+ public JenaTriple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ return new JenaTripleImpl(subject, predicate, object);
}
- public JenaTriple fromJena(org.apache.jena.graph.Triple triple, UUID salt) {
+ public JenaTriple createTriple(org.apache.jena.graph.Triple triple, UUID salt) {
return new JenaTripleImpl(triple, salt);
}
- public JenaGeneralizedTripleLike fromJenaGeneralized(org.apache.jena.graph.Triple triple, UUID salt) {
- return new JenaGeneralizedTripleLikeImpl(triple, salt);
- }
-
- public JenaGeneralizedQuadLike fromJenaGeneralized(org.apache.jena.sparql.core.Quad quad, UUID salt) {
- return new JenaGeneralizedQuadLikeImpl(quad, salt);
- }
-
- public JenaQuad fromJena(org.apache.jena.sparql.core.Quad quad, UUID salt) {
- return new JenaQuadImpl(quad, salt);
- }
-
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/5c190d21/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
index 67b2988..17e4e0b 100644
--- 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
@@ -56,15 +56,15 @@ class JenaDatasetImpl implements JenaDataset {
public void add(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
graph.add(
org.apache.jena.sparql.core.Quad.create(
- factory.toJena(graphName),
- factory.toJena(subject),
- factory.toJena(predicate),
- factory.toJena(object)));
+ factory.asJenaNode(graphName),
+ factory.asJenaNode(subject),
+ factory.asJenaNode(predicate),
+ factory.asJenaNode(object)));
}
@Override
public void add(Quad quad) {
- graph.add(factory.toJena(quad));
+ graph.add(factory.asJenaQuad(quad));
}
@Override
@@ -101,18 +101,18 @@ class JenaDatasetImpl implements JenaDataset {
return ANY;
}
// null: default graph
- return factory.toJena(graphName.orElse(null));
+ return factory.asJenaNode(graphName.orElse(null));
}
private Node toJenaPattern(RDFTerm term) {
if (term == null)
return ANY;
- return factory.toJena(term);
+ return factory.asJenaNode(term);
}
@Override
public boolean contains(Quad quad) {
- return graph.contains(factory.toJena(quad));
+ return graph.contains(factory.asJenaQuad(quad));
}
@Override
@@ -126,7 +126,7 @@ class JenaDatasetImpl implements JenaDataset {
@Override
public void remove(Quad quad) {
- graph.delete(factory.toJena(quad));
+ graph.delete(factory.asJenaQuad(quad));
}
@Override
@@ -138,14 +138,14 @@ class JenaDatasetImpl implements JenaDataset {
public Stream<? extends Quad> stream() {
JenaFactory factory = new JenaFactory(salt);
return Iter.asStream(graph.find(ANY, ANY, ANY, ANY), true)
- .map(factory::fromJena);
+ .map(factory::asQuad);
}
@Override
public Stream<? extends Quad> stream(Optional<BlankNodeOrIRI> g, BlankNodeOrIRI s, IRI p, RDFTerm o) {
JenaFactory factory = new JenaFactory(salt);
return Iter.asStream(graph.find(toJenaPattern(g), toJenaPattern(s), toJenaPattern(p), toJenaPattern(o)), true)
- .map(factory::fromJena);
+ .map(factory::asQuad);
}
@Override
@@ -169,7 +169,7 @@ class JenaDatasetImpl implements JenaDataset {
@Override
public Optional<Graph> getGraph(BlankNodeOrIRI graphName) {
- GraphView gv = GraphView.createNamedGraph(graph, factory.toJena(graphName));
+ GraphView gv = GraphView.createNamedGraph(graph, factory.asJenaNode(graphName));
return Optional.of(new JenaGraphImpl(gv, salt));
}
@@ -177,14 +177,14 @@ class JenaDatasetImpl implements JenaDataset {
public Stream<BlankNodeOrIRI> getGraphNames() {
JenaFactory factory = new JenaFactory(salt);
return Iter.asStream(graph.listGraphNodes()).map(node ->
- (BlankNodeOrIRI) factory.fromJena(node));
+ (BlankNodeOrIRI) factory.asRDFTerm(node));
}
@Override
public Iterable<Quad> iterate() {
final JenaFactory factory = new JenaFactory(salt);
return Iter.asStream(graph.find(), false)
- .map(q -> (Quad) factory.fromJena(q))
+ .map(q -> (Quad) factory.asQuad(q))
::iterator;
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/5c190d21/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
index bad996a..ab56505 100644
--- 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
@@ -58,14 +58,14 @@ class JenaGraphImpl implements JenaGraph {
@Override
public void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
graph.add(org.apache.jena.graph.Triple.create(
- factory.toJena(subject),
- factory.toJena(predicate),
- factory.toJena(object)));
+ factory.asJenaNode(subject),
+ factory.asJenaNode(predicate),
+ factory.asJenaNode(object)));
}
@Override
public void add(Triple triple) {
- graph.add(factory.toJena(triple));
+ graph.add(factory.asJenaTriple(triple));
}
@Override
@@ -86,27 +86,27 @@ class JenaGraphImpl implements JenaGraph {
@Override
public boolean contains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
return graph.contains(
- factory.toJena(subject),
- factory.toJena(predicate),
- factory.toJena(object));
+ factory.asJenaNode(subject),
+ factory.asJenaNode(predicate),
+ factory.asJenaNode(object));
}
@Override
public boolean contains(Triple triple) {
- return graph.contains(factory.toJena(triple));
+ return graph.contains(factory.asJenaTriple(triple));
}
@Override
public void remove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
graph.delete(org.apache.jena.graph.Triple.create(
- factory.toJena(subject),
- factory.toJena(predicate),
- factory.toJena(object)));
+ factory.asJenaNode(subject),
+ factory.asJenaNode(predicate),
+ factory.asJenaNode(object)));
}
@Override
public void remove(Triple triple) {
- graph.delete(factory.toJena(triple));
+ graph.delete(factory.asJenaTriple(triple));
}
@Override
@@ -117,20 +117,20 @@ class JenaGraphImpl implements JenaGraph {
@Override
public Stream<? extends Triple> stream() {
JenaFactory factory = new JenaFactory(salt);
- return Iter.asStream(graph.find(null, null, null), true).map(factory::fromJena);
+ return Iter.asStream(graph.find(null, null, null), true).map(factory::asTriple);
}
@Override
public Stream<? extends Triple> stream(BlankNodeOrIRI s, IRI p, RDFTerm o) {
JenaFactory factory = new JenaFactory(salt);
return Iter.asStream(graph.find(toJenaAny(s), toJenaAny(p), toJenaAny(o)), true)
- .map(factory::fromJena);
+ .map(factory::asTriple);
}
private Node toJenaAny(RDFTerm term) {
if (term == null)
return Node.ANY;
- return factory.toJena(term);
+ return factory.asJenaNode(term);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/5c190d21/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
----------------------------------------------------------------------
diff --git a/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java b/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
index 050de4e..393bc8f 100644
--- a/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
+++ b/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
@@ -67,7 +67,7 @@ public class TestJenaGraphToCommonsRDFGraph {
JenaFactory factory = new JenaFactory() ;
// "graph" is a CommonsRDF graph
- Graph graph = factory.fromJena(jGraph) ;
+ Graph graph = factory.asGraph(jGraph) ;
[07/50] [abbrv] incubator-commonsrdf git commit: correct jsonld
dependency
Posted by st...@apache.org.
correct jsonld dependency
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/97e3acd9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/97e3acd9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/97e3acd9
Branch: refs/heads/COMMONSRDF-46
Commit: 97e3acd9462ce7c66a787c5d45cd95d5f13a590d
Parents: 3f88d29
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Sep 9 17:26:26 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Sep 9 17:26:26 2016 +0100
----------------------------------------------------------------------
integration-tests/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/97e3acd9/integration-tests/pom.xml
----------------------------------------------------------------------
diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml
index 7ddab6b..57835e5 100644
--- a/integration-tests/pom.xml
+++ b/integration-tests/pom.xml
@@ -53,7 +53,7 @@
as both rdf4j and jena depend on jsonld -->
<dependency>
<groupId>${project.groupId}</groupId>
- <artifactId>commons-rdf-jsonld</artifactId>
+ <artifactId>commons-rdf-jsonld-java</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
[24/50] [abbrv] incubator-commonsrdf git commit: RDFParser moved to
org.apache.commons.rdf.experimental
Posted by st...@apache.org.
RDFParser moved to org.apache.commons.rdf.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/a189f91e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/a189f91e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/a189f91e
Branch: refs/heads/COMMONSRDF-46
Commit: a189f91efba570f0039c6187e612f7d42aeb2f8d
Parents: 313fbf7
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Tue Sep 27 17:29:28 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Tue Sep 27 18:42:28 2016 +0100
----------------------------------------------------------------------
.../org/apache/commons/rdf/api/RDFParser.java | 479 ----------------
.../commons/rdf/experimental/RDFParser.java | 489 +++++++++++++++++
.../commons/rdf/experimental/package-info.java | 34 ++
.../apache/commons/rdf/jena/JenaRDFParser.java | 103 ----
.../rdf/jena/experimental/JenaRDFParser.java | 105 ++++
.../rdf/jena/experimental/package-info.java | 34 ++
.../commons/rdf/jena/TestRDFParserBuilder.java | 3 +-
.../rdf/jsonldjava/JsonLdParserBuilder.java | 157 ------
.../jsonldjava/experimental/JsonLdParser.java | 160 ++++++
.../jsonldjava/experimental/package-info.java | 34 ++
.../rdf/jsonldjava/JsonLdParserBuilderTest.java | 7 +-
.../apache/commons/rdf/rdf4j/RDF4JParser.java | 194 -------
.../rdf/rdf4j/experimental/RDF4JParser.java | 197 +++++++
.../rdf/rdf4j/experimental/package-info.java | 34 ++
.../apache/commons/rdf/rdf4j/package-info.java | 6 +-
.../commons/rdf/simple/AbstractRDFParser.java | 541 ------------------
.../commons/rdf/simple/RDFParseException.java | 2 +-
.../simple/experimental/AbstractRDFParser.java | 543 +++++++++++++++++++
.../rdf/simple/experimental/package-info.java | 34 ++
.../simple/AbstractRDFParserBuilderTest.java | 3 +-
.../rdf/simple/DummyRDFParserBuilder.java | 3 +-
21 files changed, 1678 insertions(+), 1484 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/a189f91e/api/src/main/java/org/apache/commons/rdf/api/RDFParser.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/RDFParser.java b/api/src/main/java/org/apache/commons/rdf/api/RDFParser.java
deleted file mode 100644
index 72c7e61..0000000
--- a/api/src/main/java/org/apache/commons/rdf/api/RDFParser.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;
-
-/**
- * Parse 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
- * 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></rdf:Description></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><?xml encoding="iso-8859-1"></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><?xml encoding="iso-8859-1"></code> header).
- * <p>
- * The {@link #base(IRI)} or {@link #base(String)} MAY be set before calling
- * {@link #parse()}, otherwise {@link Path#toUri()} will be used as the base
- * IRI.
- * <p>
- * This method will override any source set with {@link #source(IRI)},
- * {@link #source(InputStream)} or {@link #source(String)}.
- *
- * @param file
- * A Path for a file to parse
- * @return An {@link RDFParser} that will use the specified source.
- */
- RDFParser source(Path file);
-
- /**
- * Specify an absolute source {@link IRI} to retrieve and parse.
- * <p>
- * 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><?xml encoding="iso-8859-1"></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><?xml encoding="iso-8859-1"></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/a189f91e/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..39b7253
--- /dev/null
+++ b/api/src/main/java/org/apache/commons/rdf/experimental/RDFParser.java
@@ -0,0 +1,489 @@
+/**
+ * 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).
+ * <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></rdf:Description></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><?xml encoding="iso-8859-1"></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><?xml encoding="iso-8859-1"></code> header).
+ * <p>
+ * The {@link #base(IRI)} or {@link #base(String)} MAY be set before calling
+ * {@link #parse()}, otherwise {@link Path#toUri()} will be used as the base
+ * IRI.
+ * <p>
+ * This method will override any source set with {@link #source(IRI)},
+ * {@link #source(InputStream)} or {@link #source(String)}.
+ *
+ * @param file
+ * A Path for a file to parse
+ * @return An {@link RDFParser} that will use the specified source.
+ */
+ RDFParser source(Path file);
+
+ /**
+ * Specify an absolute source {@link IRI} to retrieve and parse.
+ * <p>
+ * 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><?xml encoding="iso-8859-1"></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><?xml encoding="iso-8859-1"></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/a189f91e/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/a189f91e/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFParser.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFParser.java b/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFParser.java
deleted file mode 100644
index 9690811..0000000
--- a/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFParser.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.RDFParser;
-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.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/a189f91e/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/a189f91e/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
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/a189f91e/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 ead3e3a..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.RDFParser.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;
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/a189f91e/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 2219c74..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.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 JsonLdParserBuilder extends AbstractRDFParser<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/a189f91e/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/a189f91e/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/a189f91e/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)
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/a189f91e/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JParser.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JParser.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JParser.java
deleted file mode 100644
index dd82044..0000000
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JParser.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.RDFParser;
-import org.apache.commons.rdf.api.RDFSyntax;
-import org.apache.commons.rdf.simple.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());
- }
-
-}
[33/50] [abbrv] 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/27e80654
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/27e80654
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/27e80654
Branch: refs/heads/COMMONSRDF-46
Commit: 27e80654d917efc3d79c54f8596b20b6af3b8734
Parents: 5498729 5afd0bd
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Sep 28 23:27:27 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Sep 28 23:27:27 2016 +0100
----------------------------------------------------------------------
.../java/org/apache/commons/rdf/api/Graph.java | 5 ++
.../java/org/apache/commons/rdf/api/Quad.java | 4 +-
.../commons/rdf/experimental/RDFParser.java | 8 +--
.../commons/rdf/experimental/package-info.java | 1 -
pom.xml | 4 +-
.../simple/experimental/AbstractRDFParser.java | 54 +++++++++++++-------
.../rdf/simple/experimental/package-info.java | 11 ++--
7 files changed, 53 insertions(+), 34 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/27e80654/pom.xml
----------------------------------------------------------------------
[34/50] [abbrv] 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/9bfc39fc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/9bfc39fc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/9bfc39fc
Branch: refs/heads/COMMONSRDF-46
Commit: 9bfc39fce3dfd78d824c93c381b663efe43009f3
Parents: 27e8065 a423c41
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Sep 28 23:27:30 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Sep 28 23:27:30 2016 +0100
----------------------------------------------------------------------
jena/.settings/org.eclipse.core.resources.prefs | 6 ------
jena/.settings/org.eclipse.jdt.core.prefs | 5 -----
jena/.settings/org.eclipse.m2e.core.prefs | 4 ----
jena/src/test/resources/log4j.properties | 15 +++++++++++++++
4 files changed, 15 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
[47/50] [abbrv] incubator-commonsrdf git commit: more extensive Jena
tests
Posted by st...@apache.org.
more extensive Jena tests
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/6fdc9903
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/6fdc9903
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/6fdc9903
Branch: refs/heads/COMMONSRDF-46
Commit: 6fdc9903b70fe8c4cacd7c70c6ed012d93a7d8f9
Parents: 13464e2
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Oct 26 12:10:32 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Oct 26 12:10:32 2016 +0100
----------------------------------------------------------------------
.../jena/TestJenaGraphToCommonsRDFGraph.java | 93 +++++++++++++++++---
1 file changed, 80 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/6fdc9903/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
----------------------------------------------------------------------
diff --git a/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java b/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
index 13ee7e7..050de4e 100644
--- a/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
+++ b/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
@@ -18,14 +18,22 @@
package org.apache.commons.rdf.jena;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
+import org.apache.commons.rdf.api.BlankNode;
+import org.apache.commons.rdf.api.BlankNodeOrIRI;
import org.apache.commons.rdf.api.Graph ;
-import org.apache.commons.rdf.api.RDFTermFactory ;
-import org.apache.jena.riot.Lang ;
+import org.apache.commons.rdf.api.RDFTerm;
+import org.apache.commons.rdf.api.Triple;
+import org.apache.commons.rdf.simple.Types;
+import org.apache.jena.riot.Lang;
import org.apache.jena.riot.RDFDataMgr ;
import org.apache.jena.sparql.graph.GraphFactory ;
import org.junit.After;
@@ -34,7 +42,8 @@ import org.junit.Test;
/** Adapt a Jena Graph after parsing data into it */
public class TestJenaGraphToCommonsRDFGraph {
- private Path turtleFile;
+ private static final boolean DEBUG = false;
+ private Path turtleFile;
@Before
@@ -55,19 +64,77 @@ public class TestJenaGraphToCommonsRDFGraph {
org.apache.jena.graph.Graph jGraph = GraphFactory.createGraphMem() ;
RDFDataMgr.read(jGraph, turtleFile.toUri().toString()) ;
+ JenaFactory factory = new JenaFactory() ;
+
// "graph" is a CommonsRDF graph
- Graph graph = new JenaFactory().fromJena(jGraph) ;
+ Graph graph = factory.fromJena(jGraph) ;
+
+
+
+ // The below check expected statements from D.ttl
+
+ JenaIRI p = factory.createIRI("http://example.com/p");
+ JenaIRI s = factory.createIRI("http://example.com/s");
+ JenaLiteral literal123 = factory.createLiteral("123", Types.XSD_INTEGER);
+ assertTrue(graph.contains(s, p, literal123));
+
+ JenaIRI p1 = factory.createIRI("http://example.com/p1");
+ // Let's look up the BlankNode
+ BlankNodeOrIRI bnode1 = graph.stream(null, p1, null)
+ .findFirst().map(Triple::getSubject).get();
+ assertTrue(bnode1 instanceof BlankNode);
+
+ // Verify we can use BlankNode in query again
+ RDFTerm obj = graph.stream(bnode1, p1, null).findFirst().map(Triple::getObject).get();
+
+ // Let's look up also that nested blank node
+ assertTrue(obj instanceof BlankNode);
+ BlankNode bnode2 = (BlankNode)obj;
+
+
+ JenaIRI q = factory.createIRI("http://example.com/q");
+ JenaLiteral literalR = factory.createLiteral("r", "en");
+ assertTrue(graph.contains(bnode2, q, literalR));
+
+
+ // Can we add the same triple again as s/p/o
+ // without affecting graph size?
+ // Just to be evil we add a blanknode-iri-blanknode statement
+ assertEquals(3, graph.size());
+ graph.add(bnode1, p1, bnode2);
+ assertEquals(3, graph.size());
+
+ // Add the same Triple again
+ graph.stream(bnode2,null,null).findFirst().ifPresent(graph::add);
+ assertEquals(3, graph.size());
+
+
// Add to CommonsRDF Graph
- RDFTermFactory rft = new JenaFactory() ;
- graph.add(rft.createIRI("http://example/s2"),
- rft.createIRI("http://example/p2"),
- rft.createLiteral("foo")) ;
-// System.out.println("==== Write CommonsRDF graph\n") ;
-// graph.stream().forEach(System.out::println) ;
-// System.out.println("\n==== Write Jena graph directly\n") ;
- // And its in the Jena graph
- RDFDataMgr.write(System.out, jGraph, Lang.TTL) ;
+ JenaIRI s2 = factory.createIRI("http://example/s2");
+ JenaIRI p2 = factory.createIRI("http://example/p2");
+ JenaLiteral foo = factory.createLiteral("foo");
+ graph.add(s2,
+ p2,
+ foo) ;
+ assertEquals(4, graph.size());
+ assertTrue(graph.contains(s2,p2,foo));
+
+ // Verify the corresponding Jena Nodes are in Jena graph
+ assertTrue(jGraph.contains(s2.asJenaNode(), p2.asJenaNode(), foo.asJenaNode()));
+
+ if (DEBUG) {
+ System.out.println("==== Write CommonsRDF graph\n") ;
+ graph.stream().forEach(System.out::println) ;
+ // And its in the Jena graph
+ System.out.println("\n==== Write Jena graph directly\n") ;
+ RDFDataMgr.write(System.out, jGraph, Lang.TTL) ;
+ }
+
+ // Can stream modify the jGraph? Let's try to remove..
+ assertFalse(jGraph.isEmpty());
+ graph.stream().forEach(graph::remove);
+ assertTrue(jGraph.isEmpty());
}
}
[50/50] [abbrv] incubator-commonsrdf git commit: Merge branch
'master' into COMMONSRDF-46
Posted by st...@apache.org.
Merge branch 'master' into COMMONSRDF-46
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/d6306ad4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/d6306ad4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/d6306ad4
Branch: refs/heads/COMMONSRDF-46
Commit: d6306ad47b151b20bde77a9bff70532f614f9285
Parents: 44b4b68 2a5dbf9
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Oct 26 12:50:50 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Oct 26 12:50:50 2016 +0100
----------------------------------------------------------------------
api/pom.xml | 7 -
integration-tests/pom.xml | 60 +++++++
.../rdf/integrationtests/AllToAllTest.java | 178 +++++++++++++++++++
jena/pom.xml | 9 +-
.../org/apache/commons/rdf/jena/JenaRDF.java | 153 ++++++++--------
.../rdf/jena/experimental/JenaRDFParser.java | 4 +-
.../commons/rdf/jena/impl/AbstractQuadLike.java | 28 +--
.../rdf/jena/impl/InternalJenaFactory.java | 72 ++++----
.../commons/rdf/jena/impl/JenaDatasetImpl.java | 28 +--
.../commons/rdf/jena/impl/JenaGraphImpl.java | 30 ++--
.../services/org.apache.commons.rdf.api.RDF | 1 +
.../org.apache.commons.rdf.api.RDFFactory | 1 -
.../jena/TestJenaGraphToCommonsRDFGraph.java | 86 +++++++--
jena/src/test/resources/log4j.properties | 33 ----
jsonld-java/pom.xml | 7 +-
.../services/org.apache.commons.rdf.api.RDF | 1 +
.../org.apache.commons.rdf.api.RDFFactory | 1 -
pom.xml | 40 ++++-
rdf4j/pom.xml | 10 +-
.../services/org.apache.commons.rdf.api.RDF | 1 +
.../org.apache.commons.rdf.api.RDFFactory | 1 -
simple/pom.xml | 5 -
.../services/org.apache.commons.rdf.api.RDF | 1 +
.../org.apache.commons.rdf.api.RDFFactory | 1 -
.../commons/rdf/simple/SimpleGraphTest.java | 2 +-
25 files changed, 517 insertions(+), 243 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/d6306ad4/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
----------------------------------------------------------------------
diff --cc integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
index 0000000,1b32e35..e90ea47
mode 000000,100644..100644
--- a/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
+++ b/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
@@@ -1,0 -1,178 +1,178 @@@
+ /**
+ * 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.integrationtests;
+
+ import static org.junit.Assert.assertEquals;
+ import static org.junit.Assert.assertTrue;
+
+ import java.util.ArrayList;
+ import java.util.Arrays;
+ import java.util.Collection;
+ import java.util.List;
+
+ import org.apache.commons.rdf.api.BlankNode;
+ 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.RDF;
+ 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.jena.JenaFactory;
-import org.apache.commons.rdf.jsonldjava.JsonLdFactory;
-import org.apache.commons.rdf.rdf4j.RDF4JFactory;
-import org.apache.commons.rdf.simple.SimpleRDFTermFactory;
++import org.apache.commons.rdf.jena.JenaRDF;
++import org.apache.commons.rdf.jsonldjava.JsonLdRDF;
++import org.apache.commons.rdf.rdf4j.RDF4J;
++import org.apache.commons.rdf.simple.SimpleRDF;
+ import org.junit.Test;
+ import org.junit.runner.RunWith;
+ import org.junit.runners.Parameterized;
+ import org.junit.runners.Parameterized.Parameters;
+
+ @RunWith(Parameterized.class)
+ public class AllToAllTest {
+
- private RDFTermFactory nodeFactory;
- private RDFTermFactory graphFactory;
++ private RDF nodeFactory;
++ private RDF graphFactory;
+
+
+ public AllToAllTest(
- Class<? extends RDFTermFactory> from,
- Class<? extends RDFTermFactory> to) throws InstantiationException, IllegalAccessException {
++ Class<? extends RDF> from,
++ Class<? extends RDF> to) throws InstantiationException, IllegalAccessException {
+ this.nodeFactory = from.newInstance();
+ this.graphFactory = to.newInstance();
+ }
+
+ @SuppressWarnings("rawtypes")
+ @Parameters(name = "{index}: {0}->{1}")
+ public static Collection<Object[]> data() {
+ List<Class> factories = Arrays.asList(
- SimpleRDFTermFactory.class,
- JenaFactory.class,
- RDF4JFactory.class,
- JsonLdFactory.class);
++ SimpleRDF.class,
++ JenaRDF.class,
++ RDF4J.class,
++ JsonLdRDF.class);
+ Collection<Object[]> allToAll = new ArrayList<>();
+ for (Class from : factories) {
+ for (Class to : factories) {
+ // NOTE: we deliberately include self-to-self here
+ // to test two instances of the same implementation
+ allToAll.add(new Object[]{from, to});
+ }
+ }
+ return allToAll;
+ }
+
+ /**
+ * This test creates a {@link Graph} with the first
+ * {@link RDFTermFactory}, then inserts/queries with
+ * triples using {@link RDFTerm}s created with the second factory.
+ *
+ * @param nodeFactory Factory to create {@link RDFTerm} instances
+ * @param graphFactory Factory to create {@link Graph}
+ * @throws Exception
+ */
+ @Test
+ public void addTermsFromOtherFactory() throws Exception {
+ Graph g = graphFactory.createGraph();
+ BlankNode s = nodeFactory.createBlankNode();
+ IRI p = nodeFactory.createIRI("http://example.com/p");
+ Literal o = nodeFactory.createLiteral("Hello");
+
+ g.add(s, p, o);
+
+ // blankNode should still work with g.contains()
+ assertTrue(g.contains(s, p, o));
+ Triple t1 = g.stream().findAny().get();
+
+ // Can't make assumptions about BlankNode equality - it might
+ // have been mapped to a different BlankNode.uniqueReference()
+ // assertEquals(s, t.getSubject());
+
+ assertEquals(p, t1.getPredicate());
+ assertEquals(o, t1.getObject());
+
+ IRI s2 = nodeFactory.createIRI("http://example.com/s2");
+ g.add(s2, p, s);
+ assertTrue(g.contains(s2, p, s));
+
+ // This should be mapped to the same BlankNode
+ // (even if it has a different identifier), e.g.
+ // we should be able to do:
+
+ Triple t2 = g.stream(s2, p, null).findAny().get();
+
+ BlankNode bnode = (BlankNode) t2.getObject();
+ // And that (possibly adapted) BlankNode object should
+ // match the subject of t1 statement
+ assertEquals(bnode, t1.getSubject());
+ // And can be used as a key:
+ Triple t3 = g.stream(bnode, p, null).findAny().get();
+ assertEquals(t1, t3);
+ }
+
+
+ /**
+ * This is a variation of {@link #addTermsFromOtherFactory(RDFTermFactory, RDFTermFactory)},
+ * but here {@link Triple} is created in the "foreign" nodeFactory before adding to the graph.
+ *
+ * @param nodeFactory Factory to create {@link RDFTerm} and {@link Triple}s
+ * @param graphFactory Factory to create {@link Graph}
+ * @throws Exception
+ */
+ @Test
+ public void addTriplesFromOtherFactory() throws Exception {
+ Graph g = graphFactory.createGraph();
+ BlankNode s = nodeFactory.createBlankNode();
+ IRI p = nodeFactory.createIRI("http://example.com/p");
+ Literal o = nodeFactory.createLiteral("Hello");
+
+ Triple srcT1 = nodeFactory.createTriple(s, p, o);
+ // This should work even with BlankNode as they are from the same factory
+ assertEquals(s, srcT1.getSubject());
+ assertEquals(p, srcT1.getPredicate());
+ assertEquals(o, srcT1.getObject());
+ g.add(srcT1);
+
+ // what about the blankNode within?
+ assertTrue(g.contains(srcT1));
+ Triple t1 = g.stream().findAny().get();
+
+ // Can't make assumptions about BlankNode equality - it might
+ // have been mapped to a different BlankNode.uniqueReference()
+ //assertEquals(srcT1, t1);
+ //assertEquals(s, t1.getSubject());
+ assertEquals(p, t1.getPredicate());
+ assertEquals(o, t1.getObject());
+
+ IRI s2 = nodeFactory.createIRI("http://example.com/s2");
+ Triple srcT2 = nodeFactory.createTriple(s2, p, s);
+ g.add(srcT2);
+ assertTrue(g.contains(srcT2));
+
+ // This should be mapped to the same BlankNode
+ // (even if it has a different identifier), e.g.
+ // we should be able to do:
+
+ Triple t2 = g.stream(s2, p, null).findAny().get();
+
+ BlankNode bnode = (BlankNode) t2.getObject();
+ // And that (possibly adapted) BlankNode object should
+ // match the subject of t1 statement
+ assertEquals(bnode, t1.getSubject());
+ // And can be used as a key:
+ Triple t3 = g.stream(bnode, p, null).findAny().get();
+ assertEquals(t1, t3);
+ }
+ }
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/d6306ad4/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDF.java
----------------------------------------------------------------------
diff --cc jena/src/main/java/org/apache/commons/rdf/jena/JenaRDF.java
index 0a3f1b0,0000000..22db284
mode 100644,000000..100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDF.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDF.java
@@@ -1,729 -1,0 +1,742 @@@
+/**
+ * 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.util.Optional;
+import java.util.UUID;
+import java.util.function.Consumer;
+
+import org.apache.commons.rdf.api.BlankNode;
+import org.apache.commons.rdf.api.BlankNodeOrIRI;
+import org.apache.commons.rdf.api.Dataset;
+import org.apache.commons.rdf.api.Graph;
+import org.apache.commons.rdf.api.IRI;
+import org.apache.commons.rdf.api.Literal;
+import org.apache.commons.rdf.api.Quad;
+import org.apache.commons.rdf.api.QuadLike;
+import org.apache.commons.rdf.api.RDFSyntax;
+import org.apache.commons.rdf.api.RDFTerm;
+import org.apache.commons.rdf.api.RDF;
+import org.apache.commons.rdf.api.Triple;
+import org.apache.commons.rdf.api.TripleLike;
+import org.apache.commons.rdf.jena.impl.InternalJenaFactory;
+import org.apache.jena.datatypes.RDFDatatype;
+import org.apache.jena.datatypes.xsd.XSDDatatype;
+import org.apache.jena.graph.Node;
+import org.apache.jena.graph.NodeFactory;
+import org.apache.jena.riot.Lang;
+import org.apache.jena.riot.RDFDataMgr;
+import org.apache.jena.riot.RDFLanguages;
+import org.apache.jena.riot.system.StreamRDF;
+import org.apache.jena.riot.system.StreamRDFBase;
+import org.apache.jena.sparql.core.DatasetGraph;
+import org.apache.jena.sparql.graph.GraphFactory;
+
+/**
+ * Apache Jena RDF implementation.
+ * <p>
- * Instances of JenaRDF can also convert existing objects from/to
- * <code>org.apache.jena</code> types with methods like
- * {@link #fromJena(org.apache.jena.graph.Graph)} and {@link #toJena(Graph)}.
++ * Instances of JenaRDF can also
++ * convert existing objects from Jena with methods like
++ * {@link #asRDFTerm(Node)} and {@link #asGraph(org.apache.jena.graph.Graph)},
++ * and vice versa from any Commons RDF object to Jena with the
++ * <code>asJena*</code> methods like {@link #asJenaNode(RDFTerm)} and
++ * {@link #asJenaGraph(Graph)}.
+ * <p>
- * For the purpose of {@link BlankNode} identity, JenaRDF instances use an
- * internal {@link UUID} as a salt. See {@link BlankNode#uniqueReference()} for
- * details.
++ * Note that Commons RDF objects created by this class implement the
++ * specializations interfaces like {@link JenaRDFTerm}, {@link JenaGraph} and
++ * {@link JenaTriple}, which provide access to the underlying Jena objects, e.g.
++ * with {@link JenaRDFTerm#asJenaNode()}.
++ * <p>
++ * For the purpose of {@link BlankNode} identity when using
++ * {@link #createBlankNode(String)} (see {@link BlankNode#equals(Object)} and
++ * {@link BlankNode#uniqueReference()}), each instance of JenaRDF uses an
++ * internal random state. If for some reason consistent/reproducible BlankNode
++ * identity is desired, it is possible to retrieve the state as a UUID using
++ * {@link #salt} for subsequent use with {@link JenaFactory#JenaFactory(UUID)} -
++ * note that such consistency is only guaranteed within the same minor version
++ * of Commons RDF.
+ *
+ * @see RDF
+ */
+public final class JenaRDF implements RDF {
+
+ private static InternalJenaFactory internalJenaFactory = new InternalJenaFactory(){};
+
+ private final UUID salt;
+
+ /**
+ * Create a JenaRDF.
+ * <p>
+ * This constructor will use a randomly generated {@link UUID} as a salt
- * for the purposes of {@link BlankNode} identity, see {@link #getSalt()}.
++ * for the purposes of {@link BlankNode} identity, see {@link #salt()}.
+ */
+ public JenaRDF() {
+ this.salt = UUID.randomUUID();
+ }
+
+ /**
+ * Create a JenaRDF.
+ * <p>
+ * This constructor will use the specified {@link UUID} as a salt for
+ * the purposes of {@link BlankNode} identity, and should only be used in
+ * cases where predictable and consistent
+ * {@link BlankNode#uniqueReference()} are important.
+ *
+ * @param salt
+ * {@link UUID} to use as salt for {@link BlankNode} equality
+ */
+ public JenaRDF(UUID salt) {
+ this.salt = salt;
+ }
+
+ @Override
+ public JenaBlankNode createBlankNode() {
- return internalJenaFactory.createBlankNode(getSalt());
++ return internalJenaFactory.createBlankNode(salt());
+ }
+
+ @Override
+ public JenaBlankNode createBlankNode(String name) {
- return internalJenaFactory.createBlankNode(name, getSalt());
++ return internalJenaFactory.createBlankNode(name, salt());
+ }
+
+ @Override
+ public JenaDataset createDataset() {
- return internalJenaFactory.createDataset(getSalt());
++ return internalJenaFactory.createDataset(salt());
+ }
+
+ @Override
+ public JenaGraph createGraph() {
- return internalJenaFactory.createGraph(getSalt());
++ return internalJenaFactory.createGraph(salt());
+ }
+
+ @Override
+ public JenaIRI createIRI(String iri) {
+ validateIRI(iri);
+ return internalJenaFactory.createIRI(iri);
+ }
+
+ @Override
+ public JenaLiteral createLiteral(String lexicalForm) {
+ return internalJenaFactory.createLiteral(lexicalForm);
+ }
+
+ @Override
+ public JenaLiteral createLiteral(String lexicalForm, IRI dataType) {
+ return internalJenaFactory.createLiteralDT(lexicalForm, dataType.getIRIString());
+ }
+
+ @Override
+ public JenaLiteral createLiteral(String lexicalForm, String languageTag) {
+ validateLang(languageTag);
+ return internalJenaFactory.createLiteralLang(lexicalForm, languageTag);
+ }
+
+ @Override
+ public JenaTriple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ return internalJenaFactory.createTriple(subject, predicate, object);
+ }
+
+ @Override
+ public JenaQuad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
+ throws IllegalArgumentException, UnsupportedOperationException {
+ return internalJenaFactory.createQuad(subject, predicate, object, graphName);
+ }
+
+ /**
+ * Create a generalized Jena triple.
+ * <p>
+ * The <em>generalized triple</em> supports any {@link RDFTerm} as its
+ * {@link TripleLike#getSubject()} {@link TripleLike#getPredicate()} or
+ * {@link TripleLike#getObject()}.
+ *
+ * @see #createTriple(BlankNodeOrIRI, IRI, RDFTerm)
+ * @see #createGeneralizedQuad(RDFTerm, RDFTerm, RDFTerm, RDFTerm)
+ *
+ * @param subject
+ * The subject of the statement
+ * @param predicate
+ * The predicate of the statement
+ * @param object
+ * The object of the statement
+ * @return Generalized {@link TripleLike}. Note that the generalized triple
+ * does <strong>not</strong> implement {@link Triple#equals(Object)}
+ * or {@link Triple#hashCode()}.
+ */
+ public JenaGeneralizedTripleLike createGeneralizedTriple(
+ RDFTerm subject, RDFTerm predicate, RDFTerm object) {
+ return internalJenaFactory.createGeneralizedTriple(subject, predicate, object);
+ }
+
+ /**
+ * Create a generalized Jena quad.
+ * <p>
+ * The <em>generalized quad</em> supports any {@link RDFTerm} as its
+ * {@link QuadLike#getSubject()} {@link QuadLike#getPredicate()},
+ * {@link QuadLike#getObject()} or {@link QuadLike#getObject()}.
+ *
+ * @see #createQuad(BlankNodeOrIRI, BlankNodeOrIRI, IRI, RDFTerm)
+ * @see #createGeneralizedTriple(RDFTerm, RDFTerm, RDFTerm)
+ *
+ * @param subject
+ * The subject of the statement
+ * @param predicate
+ * The predicate of the statement
+ * @param object
+ * The object of the statement
+ * @param graphName
+ * The graph name of the statement
+ * @return Generalized {@link QuadLike}. Note that the generalized quad does
+ * <strong>not</strong> implement {@link Quad#equals(Object)} or
+ * {@link Quad#hashCode()}.
+ */
+ public JenaGeneralizedQuadLike createGeneralizedQuad(
+ RDFTerm subject, RDFTerm predicate, RDFTerm object, RDFTerm graphName) {
+ return internalJenaFactory.createGeneralizedQuad(subject, predicate, object, graphName);
+ }
+ /**
+ * Adapt an existing Jena Node to CommonsRDF {@link RDFTerm}.
+ * <p>
+ * If {@link Node#isLiteral()}, then the returned value is a {@link Literal}.
+ * If {@link Node#isURI()}, the returned value is a IRI. If {$@link Node#isBlank()},
+ * the returned value is a {@link BlankNode}, which will use a {@link UUID}
+ * salt from this {@link JenaRDF} instance in combination with
+ * {@link Node#getBlankNodeId()} for the purpose of its
+ * {@link BlankNode#uniqueReference()}.
+ *
- * @see #fromJena(RDF, Node)
++ * @see #asRDFTerm(RDF, Node)
+ *
+ * @param node
+ * The Jena Node to adapt. It's {@link Node#isConcrete()} must be
+ * <code>true</code>.
+ * @return Adapted {@link JenaRDFTerm}
+ * @throws ConversionException If the {@link Node} can't be represented as an {@link RDFTerm}, e.g.
+ * if the node is not concrete or represents a variable in Jena.
+ */
- public JenaRDFTerm fromJena(Node node) throws ConversionException {
- return internalJenaFactory.fromJena(node, getSalt());
++ public JenaRDFTerm asRDFTerm(Node node) throws ConversionException {
++ return internalJenaFactory.createRDFTerm(node, salt());
+ }
+
+ /**
+ * Convert from Jena {@link Node} to any Commons RDF implementation.
+ * <p>
+ * Note that if the {@link Node#isBlank()}, then the factory's
+ * {@link RDF#createBlankNode(String)} will be used, meaning
+ * that care should be taken if reusing an {@link RDF} instance
+ * for multiple conversion sessions.
+ *
- * @see #fromJena(Node)
++ * @see #asRDFTerm(Node)
+ *
+ * @param factory {@link RDF} to use for creating {@link RDFTerm}.
+ * @param node
+ * The Jena Node to adapt. It's {@link Node#isConcrete()} must be
+ * <code>true</code>.
+ * @return Adapted {@link RDFTerm}
+ * @throws ConversionException If the {@link Node} can't be represented as an {@link RDFTerm}, e.g.
+ * if the node is not concrete or represents a variable in Jena.
+ */
- public static RDFTerm fromJena(RDF factory, Node node) {
++ public static RDFTerm asRDFTerm(RDF factory, Node node) {
+ if (node == null) {
+ return null;
+ }
+ if (factory instanceof JenaRDF) {
+ // No need to convert, just wrap
- return ((JenaRDF) factory).fromJena(node);
++ return ((JenaRDF) factory).asRDFTerm(node);
+ }
+ if (node.isURI())
+ return factory.createIRI(node.getURI());
+ if (node.isLiteral()) {
+ String lang = node.getLiteralLanguage();
+ if (lang != null && !lang.isEmpty())
+ return factory.createLiteral(node.getLiteralLexicalForm(), lang);
+ if (node.getLiteralDatatype().equals(XSDDatatype.XSDstring))
+ return factory.createLiteral(node.getLiteralLexicalForm());
+ IRI dt = factory.createIRI(node.getLiteralDatatype().getURI());
+ return factory.createLiteral(node.getLiteralLexicalForm(), dt);
+ }
+ if (node.isBlank())
+ // The factory
+ return factory.createBlankNode(node.getBlankNodeLabel());
+ throw new ConversionException("Node is not a concrete RDF Term: " + node);
+ }
+
+ /**
+ * Adapt an existing Jena Triple to CommonsRDF {@link Triple}.
+ * <p>
+ * If the triple contains any {@link Node#isBlank()}, then any corresponding
+ * {@link BlankNode} will use a {@link UUID} salt from this
+ * {@link JenaRDF} instance in combination with
+ * {@link Node#getBlankNodeId()} for the purpose of its
+ * {@link BlankNode#uniqueReference()}.
+ *
- * @see #fromJena(RDF, org.apache.jena.graph.Triple)
++ * @see #asTriple(RDF, org.apache.jena.graph.Triple)
+ *
+ * @param triple
+ * Jena {@link org.apache.jena.graph.Triple} to adapt
+ * @return Adapted {@link JenaTriple}
+ * @throws ConversionException
+ * if any of the triple's nodes are not concrete or the triple
+ * is a generalized triple
+ */
- public JenaTriple fromJena(org.apache.jena.graph.Triple triple) throws ConversionException {
- return internalJenaFactory.fromJena(triple, getSalt());
++ public JenaTriple asTriple(org.apache.jena.graph.Triple triple) throws ConversionException {
++ return internalJenaFactory.createTriple(triple, salt());
+ }
+
+ /**
+ * Adapt a generalized Jena {@link org.apache.jena.graph.Triple} to a CommonsRDF {@link TripleLike}.
+ * <p>
+ * The generalized triple supports any {@link RDFTerm} as its {@link TripleLike#getSubject()}
+ * {@link TripleLike#getPredicate()} or {@link TripleLike#getObject()}.
+ * <p>
+ * If the Jena triple contains any {@link Node#isBlank()}, then any corresponding
+ * {@link BlankNode} will use a {@link UUID} salt from this
+ * {@link JenaRDF} instance in combination with
+ * {@link Node#getBlankNodeId()} for the purpose of its
+ * {@link BlankNode#uniqueReference()}.
+ *
- * @see #fromJena(RDF, org.apache.jena.graph.Triple)
++ * @see #asTriple(RDF, org.apache.jena.graph.Triple)
+ *
+ * @param triple
+ * Jena triple
+ * @return Adapted {@link TripleLike}. Note that the generalized triple does
+ * <strong>not</strong> implement {@link Triple#equals(Object)} or
+ * {@link Triple#hashCode()}.
+ * @throws ConversionException
+ * if any of the triple's nodes are not concrete
+ */
- public JenaTripleLike fromJenaGeneralized(org.apache.jena.graph.Triple triple) throws ConversionException {
- return internalJenaFactory.fromJenaGeneralized(triple, getSalt());
++ public JenaTripleLike asGeneralizedTriple(org.apache.jena.graph.Triple triple) throws ConversionException {
++ return internalJenaFactory.createGeneralizedTriple(triple, salt());
+ }
+
+ /**
+ * Adapt a generalized Jena {@link org.apache.jena.sparql.core.Quad} to a CommonsRDF {@link QuadLike}.
+ * <p>
+ * The generalized quad supports any {@link RDFTerm} as its
+ * {@link QuadLike#getGraphName()},
+ * {@link QuadLike#getSubject()}
+ * {@link QuadLike#getPredicate()} or
+ * {@link QuadLike#getObject()}.
+ * <p>
+ * If the Jena quad contains any {@link Node#isBlank()}, then any corresponding
+ * {@link BlankNode} will use a {@link UUID} salt from this
+ * {@link JenaRDF} instance in combination with
+ * {@link Node#getBlankNodeId()} for the purpose of its
+ * {@link BlankNode#uniqueReference()}.
+ *
- * @see #fromJena(org.apache.jena.sparql.core.Quad)
- * @see #fromJenaGeneralized(org.apache.jena.graph.Triple)
++ * @see #asQuad(org.apache.jena.sparql.core.Quad)
++ * @see #asGeneralizedTriple(org.apache.jena.graph.Triple)
+ *
+ * @param quad
+ * Jena quad
+ * @return Adapted {@link QuadLike}. Note that the generalized quad does
+ * <strong>not</strong> implement {@link Quad#equals(Object)} or
+ * {@link Quad#hashCode()}.
+ * @throws ConversionException
+ * if any of the quad nodes are not concrete
+ */
- public JenaQuadLike<RDFTerm> fromJenaGeneralized(org.apache.jena.sparql.core.Quad quad) throws ConversionException {
- return internalJenaFactory.fromJenaGeneralized(quad, getSalt());
++ public JenaQuadLike<RDFTerm> asGeneralizedQuad(org.apache.jena.sparql.core.Quad quad) throws ConversionException {
++ return internalJenaFactory.createGeneralizedQuad(quad, salt());
+ }
+
+ /**
+ * Convert from Jena {@link org.apache.jena.graph.Triple} to a Commons RDF
+ * {@link Triple}.
+ * <p>
+ * Note that if any of the triple's nodes {@link Node#isBlank()}, then the factory's
+ * {@link RDF#createBlankNode(String)} will be used, meaning
+ * that care should be taken if reusing an {@link RDF} instance
+ * for multiple conversion sessions.
+ *
- * @see #fromJena(org.apache.jena.graph.Triple)
++ * @see #asTriple(org.apache.jena.graph.Triple)
+ *
+ * @param factory {@link RDF} to use for creating the {@link Triple} and its
+ * {@link RDFTerm}s.
+ * @param triple
+ * Jena triple
+ * @return Converted triple
+ * @throws ConversionException
+ * if any of the triple's nodes are not concrete or the triple
+ * is a generalized triple
+ */
- public static Triple fromJena(RDF factory, org.apache.jena.graph.Triple triple)
++ public static Triple asTriple(RDF factory, org.apache.jena.graph.Triple triple)
+ throws ConversionException{
+ if (factory instanceof JenaRDF) {
+ // No need to convert, just wrap
- return ((JenaRDF) factory).fromJena(triple);
++ return ((JenaRDF) factory).asTriple(triple);
+ }
+ final BlankNodeOrIRI subject;
+ final IRI predicate;
+ try {
- subject = (BlankNodeOrIRI) fromJena(factory, triple.getSubject());
- predicate = (IRI) fromJena(factory, triple.getPredicate());
++ subject = (BlankNodeOrIRI) asRDFTerm(factory, triple.getSubject());
++ predicate = (IRI) asRDFTerm(factory, triple.getPredicate());
+ } catch (ClassCastException ex) {
+ throw new ConversionException("Can't convert generalized triple: " + triple, ex);
+ }
- RDFTerm object = fromJena(factory, triple.getObject());
++ RDFTerm object = asRDFTerm(factory, triple.getObject());
+ return factory.createTriple(subject, predicate, object);
+ }
+
+ /**
+ * Adapt an existing Jena {@link org.apache.jena.sparql.core.Quad} to CommonsRDF {@link Quad}.
+ * <p>
+ * If the quad contains any {@link Node#isBlank()}, then any corresponding
+ * {@link BlankNode} will use a {@link UUID} salt from this
+ * {@link JenaRDF} instance
+ * in combination with {@link Node#getBlankNodeId()}
+ * for the purpose of its {@link BlankNode#uniqueReference()}.
+ *
+ * @param quad
+ * Jena quad
+ * @return Adapted quad
+ */
- public JenaQuad fromJena(org.apache.jena.sparql.core.Quad quad) {
- return internalJenaFactory.fromJena(quad, getSalt());
++ public JenaQuad asQuad(org.apache.jena.sparql.core.Quad quad) {
++ return internalJenaFactory.createQuad(quad, salt());
+ }
+
+ /**
+ * Adapt an existing Jena {@link org.apache.jena.graph.Graph} to CommonsRDF
+ * {@link Graph}.
+ * <p>
+ * This does not take a copy, changes to the CommonsRDF Graph are reflected
+ * in the jena graph, which is accessible from
+ * {@link JenaGraph#asJenaGraph()}.
+ * <p>
+ * If the graph contains any {@link Node#isBlank()}, then any corresponding
+ * {@link BlankNode} will use a {@link UUID} salt from this
+ * {@link JenaRDF} instance in combination with
+ * {@link Node#getBlankNodeId()} for the purpose of its
+ * {@link BlankNode#uniqueReference()}.
+ *
+ * @param graph
+ * Jena {@link org.apache.jena.graph.Graph} to adapt
+ * @return Adapted {@link JenaGraph}
+ */
- public JenaGraph fromJena(org.apache.jena.graph.Graph graph) {
- return internalJenaFactory.fromJena(graph, getSalt());
++ public JenaGraph asGraph(org.apache.jena.graph.Graph graph) {
++ return internalJenaFactory.createGraph(graph, salt());
+ }
+
+ /**
+ * Adapt an existing Jena {@link org.apache.jena.rdf.model.Model} to CommonsRDF {@link Graph}.
+ * <p>
+ * This does not ake a copy, changes to the CommonsRDF Graph are reflected in the jena
+ * graph, which is accessible from {@link JenaGraph#asJenaGraph()}.
+ * <p>
+ * If the graph contains any {@link Node#isBlank()}, then any corresponding
+ * {@link BlankNode} will use a {@link UUID} salt from this
+ * {@link JenaRDF} instance
+ * in combination with {@link Node#getBlankNodeId()}
+ * for the purpose of its {@link BlankNode#uniqueReference()}.
+ * @param model
+ * Jena {@link org.apache.jena.rdf.model.Model} to adapt
+ * @return Adapted {@link JenaGraph}
+ */
- public JenaGraph fromJena(org.apache.jena.rdf.model.Model model) {
- return internalJenaFactory.fromJena(model, getSalt());
++ public JenaGraph asGraph(org.apache.jena.rdf.model.Model model) {
++ return internalJenaFactory.createGraph(model, salt());
+ }
+
+ /**
+ * Adapt an existing Jena {@link DatasetGraph} to CommonsRDF {@link Dataset}.
+ * <p>
+ * This does not
+ * take a copy, changes to the CommonsRDF Dataset are reflected in the jena
+ * dataset graph, which is accessible from {@link JenaDataset#asJenaDatasetGraph()}.
+ * <p>
+ * If the dataset contains any {@link Node#isBlank()}, then any corresponding
+ * {@link BlankNode} will use a {@link UUID} salt from this
+ * {@link JenaRDF} instance
+ * in combination with {@link Node#getBlankNodeId()}
+ * for the purpose of its {@link BlankNode#uniqueReference()}.
+ *
+ * @param datasetGraph Jena {@link DatasetGraph} to adapt
+ * @return Adapted {@link JenaDataset}
+ */
- public JenaDataset fromJena(DatasetGraph datasetGraph) {
- return internalJenaFactory.fromJena(datasetGraph, getSalt());
++ public JenaDataset asDataset(DatasetGraph datasetGraph) {
++ return internalJenaFactory.createDataset(datasetGraph, salt());
+ }
+
+ /**
+ * Adapt an existing Jena {@link org.apache.jena.query.Dataset} to CommonsRDF {@link Dataset}.
+ * <p>
+ * This does not
+ * take a copy, changes to the CommonsRDF Dataset are reflected in the jena
+ * dataset graph, which is accessible from {@link JenaDataset#asJenaDatasetGraph()}.
+ * <p>
+ * If the dataset contains any {@link Node#isBlank()}, then any corresponding
+ * {@link BlankNode} will use a {@link UUID} salt from this
+ * {@link JenaRDF} instance
+ * in combination with {@link Node#getBlankNodeId()}
+ * for the purpose of its {@link BlankNode#uniqueReference()}.
+ *
+ * @param datasetGraph Jena {@link org.apache.jena.query.Dataset} to adapt
+ * @return Adapted {@link JenaDataset}
+ */
- public JenaDataset fromJena(org.apache.jena.query.Dataset datasetGraph) {
- return internalJenaFactory.fromJena(datasetGraph.asDatasetGraph(), getSalt());
++ public JenaDataset asDataset(org.apache.jena.query.Dataset datasetGraph) {
++ return internalJenaFactory.createDataset(datasetGraph.asDatasetGraph(), salt());
+ }
+
+ /**
+ * Convert from Jena {@link org.apache.jena.sparql.core.Quad} to a Commons
+ * RDF {@link Quad}.
+ * <p>
+ * Note that if any of the quad's nodes {@link Node#isBlank()}, then the
+ * factory's {@link RDF#createBlankNode(String)} will be used,
+ * meaning that care should be taken if reusing an {@link RDF}
+ * instance for multiple conversion sessions.
+ *
- * @see #fromJena(org.apache.jena.sparql.core.Quad)
- * @see #fromJenaGeneralized(org.apache.jena.sparql.core.Quad)
++ * @see #asQuad(org.apache.jena.sparql.core.Quad)
++ * @see #asGeneralizedQuad(org.apache.jena.sparql.core.Quad)
+ *
+ * @param factory
+ * {@link RDF} to use for creating the {@link Triple}
+ * and its {@link RDFTerm}s.
+ * @param quad
+ * Jena {@link org.apache.jena.sparql.core.Quad} to adapt
+ * @return Converted {@link Quad}
+ * @throws ConversionException
+ * if any of the quad's nodes are not concrete or the quad
+ * is a generalized quad
+ */
- public static Quad fromJena(RDF factory, org.apache.jena.sparql.core.Quad quad) {
++ public static Quad asQuad(RDF factory, org.apache.jena.sparql.core.Quad quad) {
+ if (factory instanceof JenaRDF) {
+ // No need to convert, just wrap
- return ((JenaRDF) factory).fromJena(quad);
++ return ((JenaRDF) factory).asQuad(quad);
+ }
- BlankNodeOrIRI graphName = (BlankNodeOrIRI) (fromJena(factory, quad.getGraph()));
- BlankNodeOrIRI subject = (BlankNodeOrIRI) (fromJena(factory, quad.getSubject()));
- IRI predicate = (IRI) (fromJena(factory, quad.getPredicate()));
- RDFTerm object = fromJena(factory, quad.getObject());
++ BlankNodeOrIRI graphName = (BlankNodeOrIRI) (asRDFTerm(factory, quad.getGraph()));
++ BlankNodeOrIRI subject = (BlankNodeOrIRI) (asRDFTerm(factory, quad.getSubject()));
++ IRI predicate = (IRI) (asRDFTerm(factory, quad.getPredicate()));
++ RDFTerm object = asRDFTerm(factory, quad.getObject());
+ return factory.createQuad(graphName, subject, predicate, object);
+ }
+
+ /**
+ * Return {@link RDFSyntax} corresponding to a Jena {@link Lang}.
+ *
+ * @param lang {@link Lang} to convert
+ * @return Matched {@link RDFSyntax}, otherwise {@link Optional#empty()}
+ */
- public Optional<RDFSyntax> langToRdfSyntax(Lang lang) {
++ public Optional<RDFSyntax> asRDFSyntax(Lang lang) {
+ return RDFSyntax.byMediaType(lang.getContentType().getContentType());
+ }
+
+ /**
+ * Return Jena {@link Lang} corresponding to a {@link RDFSyntax}.
+ *
+ * @param rdfSyntax {@link RDFSyntax} to convert
+ * @return Matched {@link Lang}, otherwise {@link Optional#empty()}
+ */
- public Optional<Lang> rdfSyntaxToLang(RDFSyntax rdfSyntax) {
++ public Optional<Lang> asJenaLang(RDFSyntax rdfSyntax) {
+ return Optional.ofNullable(RDFLanguages.contentTypeToLang(rdfSyntax.mediaType));
+ }
+
+ /**
+ * Create a {@link StreamRDF} instance that inserts the converted
+ * {@link Quad}s. into a the provided {@link Consumer}.
+ * <p>
+ * The returned {@link StreamRDF} can be used for instance with Jena's
+ * {@link RDFDataMgr#parse(StreamRDF, String)}.
+ *
+ * @param factory
+ * {@link RDF} to use for creating {@link RDFTerm}s
+ * and {@link Quad}s.
+ * @param consumer
+ * A {@link Consumer} of {@link Quad}s
+ * @return A {@link StreamRDF} that will stream converted quads to the
+ * consumer
+ */
- public static StreamRDF streamJenaToCommonsRDF(RDF factory, Consumer<Quad> consumer) {
++ public static StreamRDF streamJenaToQuad(RDF factory, Consumer<Quad> consumer) {
+ return new StreamRDFBase() {
+ @Override
+ public void quad(org.apache.jena.sparql.core.Quad quad) {
- consumer.accept(fromJena(factory, quad));
++ consumer.accept(asQuad(factory, quad));
+ }
+ };
+ }
+
+ /**
+ * Create a {@link StreamRDF} instance that inserts generalized
+ * {@link TripleLike}s. into a the provided {@link Consumer}.
+ * <p>
+ * A generalized triple allows any {@link RDFTerm} for
+ * {@link TripleLike#getSubject()}, {@link TripleLike#getPredicate()} and
+ * {@link TripleLike#getObject()}.
+ * <p>
+ * The returned {@link StreamRDF} can be used for instance with Jena's
+ * {@link RDFDataMgr#parse(StreamRDF, String)}.
+ *
+ * @param generalizedConsumer
+ * A {@link Consumer} of generalized {@link TripleLike}s
+ * @return A {@link StreamRDF} that will stream generalized triples to the
+ * consumer
+ */
+ public StreamRDF streamJenaToGeneralizedTriple(Consumer<TripleLike> generalizedConsumer) {
+ return new StreamRDFBase() {
+ @Override
+ public void triple(org.apache.jena.graph.Triple triple) {
- generalizedConsumer.accept(fromJenaGeneralized(triple));
++ generalizedConsumer.accept(asGeneralizedTriple(triple));
+ }
+ };
+ }
+
+ /**
+ * Create a {@link StreamRDF} instance that inserts generalized
+ * {@link QuadLike}s. into a the provided {@link Consumer}.
+ * <p>
+ * A generalized quad allows any {@link RDFTerm} for
+ * {@link QuadLike#getSubject()}, {@link TripleLike#getPredicate()},
+ * {@link QuadLike#getObject()} and {@link QuadLike#getGraphName()} .
+ * <p>
+ * The returned {@link StreamRDF} can be used for instance with Jena's
+ * {@link RDFDataMgr#parse(StreamRDF, String)}.
+ *
+ * @param generalizedConsumer
+ * A {@link Consumer} of generalized {@link QuadLike}s
+ * @return A {@link StreamRDF} that will stream generalized quads to the
+ * consumer
+ */
+ public StreamRDF streamJenaToGeneralizedQuad(Consumer<QuadLike<RDFTerm>> generalizedConsumer) {
+ return new StreamRDFBase() {
+ @Override
+ public void quad(org.apache.jena.sparql.core.Quad quad) {
- generalizedConsumer.accept(fromJenaGeneralized(quad));
++ generalizedConsumer.accept(asGeneralizedQuad(quad));
+ }
+ };
+ }
+
+ /**
+ * Convert a CommonsRDF Graph to a Jena Graph. If the Graph was from Jena
+ * originally, return that original object else create a copy using Jena
+ * objects.
+ *
+ * @param graph Commons RDF {@link Graph} to convert
+ * @return Converted Jena {@link org.apache.jena.graph.Graph}
+ */
- public org.apache.jena.graph.Graph toJena(Graph graph) {
++ public org.apache.jena.graph.Graph asJenaGraph(Graph graph) {
+ if (graph instanceof JenaGraph)
+ return ((JenaGraph) graph).asJenaGraph();
+ org.apache.jena.graph.Graph g = GraphFactory.createGraphMem();
- graph.stream().forEach(t -> g.add(toJena(t)));
++ graph.stream().forEach(t -> g.add(asJenaTriple(t)));
+ return g;
+ }
+
+ /**
+ * Convert a CommonsRDF RDFTerm to a Jena Node. If the RDFTerm was from Jena
+ * originally, return that original object, else create a copy using Jena
+ * objects.
+ *
+ * @param term Commons RDF {@link RDFTerm} to convert
+ * @return Converted Jena {@link Node}
+ */
- public Node toJena(RDFTerm term) {
++ public Node asJenaNode(RDFTerm term) {
+ if (term == null) {
+ return null;
+ }
+ if (term instanceof JenaRDFTerm)
+ // TODO: What if it's a JenaBlankNodeImpl with
+ // a different salt? Do we need to rewrite the
+ // jena blanknode identifier?
+ return ((JenaRDFTerm) term).asJenaNode();
+
+ if (term instanceof IRI)
+ return NodeFactory.createURI(((IRI) term).getIRIString());
+
+ if (term instanceof Literal) {
+ Literal lit = (Literal) term;
+ RDFDatatype dt = NodeFactory.getType(lit.getDatatype().getIRIString());
+ String lang = lit.getLanguageTag().orElse("");
+ return NodeFactory.createLiteral(lit.getLexicalForm(), lang, dt);
+ }
+
+ if (term instanceof BlankNode) {
+ String id = ((BlankNode) term).uniqueReference();
+ return NodeFactory.createBlankNode(id);
+ }
+ throw new ConversionException("Not a concrete RDF Term: " + term);
+ }
+
+ /**
+ * Convert a CommonsRDF {@link Triple} to a Jena
+ * {@link org.apache.jena.graph.Triple}.
+ * <p>
+ * If the triple was from Jena originally, return that original object, else
+ * create a copy using Jena objects.
+ *
+ * @param triple Commons RDF {@link Triple} to convert
+ * @return Converted Jena {@link org.apache.jena.graph.Triple}
+ */
- public org.apache.jena.graph.Triple toJena(Triple triple) {
++ public org.apache.jena.graph.Triple asJenaTriple(Triple triple) {
+ if (triple instanceof JenaTriple)
+ return ((JenaTriple) triple).asJenaTriple();
+ return org.apache.jena.graph.Triple.create(
- toJena(triple.getSubject()),
- toJena(triple.getPredicate()),
- toJena(triple.getObject()));
++ asJenaNode(triple.getSubject()),
++ asJenaNode(triple.getPredicate()),
++ asJenaNode(triple.getObject()));
+ }
+
+
+ /**
+ * Convert a CommonsRDF {@link Quad} to a Jena
+ * {@link org.apache.jena.sparql.core.Quad}.
+ * <p>
+ * If the quad was from Jena originally, return that original object,
+ * otherwise create a copy using Jena objects.
+ *
+ * @param quad Commons RDF {@link Quad} to convert
+ * @return Converted Jena {@link org.apache.jena.sparql.core.Quad}
+ */
- public org.apache.jena.sparql.core.Quad toJena(Quad quad) {
++ public org.apache.jena.sparql.core.Quad asJenaQuad(Quad quad) {
+ if (quad instanceof JenaQuad) {
+ return ((JenaQuad) quad).asJenaQuad();
+ }
+ return org.apache.jena.sparql.core.Quad.create(
- toJena(quad.getGraphName().orElse(null)),
- toJena(quad.getSubject()),
- toJena(quad.getPredicate()),
- toJena(quad.getObject()));
++ asJenaNode(quad.getGraphName().orElse(null)),
++ asJenaNode(quad.getSubject()),
++ asJenaNode(quad.getPredicate()),
++ asJenaNode(quad.getObject()));
+ }
+
+ // Some simple validations - full IRI parsing is not cheap.
+ private void validateIRI(String iri) {
+ if (iri.contains(" "))
+ throw new IllegalArgumentException();
+ if (iri.contains("<"))
+ throw new IllegalArgumentException();
+ if (iri.contains(">"))
+ throw new IllegalArgumentException();
+ }
+
+ private static void validateLang(String languageTag) {
+ if (languageTag.contains(" "))
+ throw new IllegalArgumentException("Invalid language tag: " + languageTag);
+ }
+
+ /**
+ * Return the {@link UUID} salt used by this factory.
+ * <p>
+ * The salt is used for the purposes of {@link BlankNode} identity, see
+ * {@link BlankNode#uniqueReference()} for details.
+ * <p>
+ * This salt can be used with the constructor
+ * {@link JenaRDF#JenaRDF(UUID)}
+ * if consistent or reproducible {@link BlankNode}s are desirable.
+ *
+ * @return The {@link UUID} used as salt
+ */
- public UUID getSalt() {
++ public UUID salt() {
+ return salt;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/d6306ad4/jena/src/main/java/org/apache/commons/rdf/jena/experimental/JenaRDFParser.java
----------------------------------------------------------------------
diff --cc jena/src/main/java/org/apache/commons/rdf/jena/experimental/JenaRDFParser.java
index d78870c,14d13d9..81069f0
--- 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
@@@ -77,15 -77,15 +77,15 @@@ public class JenaRDFParser extends Abst
dest = StreamRDFLib.graph(jenaGraph);
} else {
if (generalizedConsumerQuad != null) {
- dest = jenaFactory.streamJenaToGeneralizedQuad(generalizedConsumerQuad);
+ dest = jenaRDF.streamJenaToGeneralizedQuad(generalizedConsumerQuad);
} else if (generalizedConsumerTriple != null) {
- dest = jenaFactory.streamJenaToGeneralizedTriple(generalizedConsumerTriple);
+ dest = jenaRDF.streamJenaToGeneralizedTriple(generalizedConsumerTriple);
} else {
- dest = JenaRDF.streamJenaToCommonsRDF(getRdfTermFactory().get(), getTarget());
- dest = JenaFactory.streamJenaToQuad(getRdfTermFactory().get(), getTarget());
++ dest = JenaRDF.streamJenaToQuad(getRdfTermFactory().get(), getTarget());
}
}
- Lang lang = getContentTypeSyntax().flatMap(jenaRDF::rdfSyntaxToLang).orElse(null);
- Lang lang = getContentTypeSyntax().flatMap(jenaFactory::asJenaLang).orElse(null);
++ Lang lang = getContentTypeSyntax().flatMap(jenaRDF::asJenaLang).orElse(null);
String baseStr = getBase().map(IRI::getIRIString).orElse(null);
if (getSourceIri().isPresent()) {
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/d6306ad4/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractQuadLike.java
----------------------------------------------------------------------
diff --cc jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractQuadLike.java
index d538076,9166731..10dc069
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractQuadLike.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractQuadLike.java
@@@ -86,25 -86,25 +86,25 @@@ abstract class AbstractQuadLike<S exten
@Override
public org.apache.jena.sparql.core.Quad asJenaQuad() {
- JenaFactory factory = new JenaFactory();
+ JenaRDF factory = new JenaRDF();
if (quad == null) {
quad = org.apache.jena.sparql.core.Quad.create(
- factory.toJena(graphName.orElse(null)),
- factory.toJena(subject),
- factory.toJena(predicate),
- factory.toJena(object));
+ factory.asJenaNode(graphName.orElse(null)),
+ factory.asJenaNode(subject),
+ factory.asJenaNode(predicate),
+ factory.asJenaNode(object));
}
return quad;
}
@Override
public org.apache.jena.graph.Triple asJenaTriple() {
- JenaFactory factory = new JenaFactory();
+ JenaRDF factory = new JenaRDF();
if (triple == null) {
triple = org.apache.jena.graph.Triple.create(
- factory.toJena(subject),
- factory.toJena(predicate),
- factory.toJena(object));
+ factory.asJenaNode(subject),
+ factory.asJenaNode(predicate),
+ factory.asJenaNode(object));
}
return triple;
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/d6306ad4/jena/src/main/java/org/apache/commons/rdf/jena/impl/InternalJenaFactory.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/d6306ad4/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaDatasetImpl.java
----------------------------------------------------------------------
diff --cc jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaDatasetImpl.java
index 81c9a07,17e4e0b..17cb641
--- 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
@@@ -136,16 -136,16 +136,16 @@@ class JenaDatasetImpl implements JenaDa
@Override
public Stream<? extends Quad> stream() {
- JenaFactory factory = new JenaFactory(salt);
+ JenaRDF factory = new JenaRDF(salt);
return Iter.asStream(graph.find(ANY, ANY, ANY, ANY), true)
- .map(factory::fromJena);
+ .map(factory::asQuad);
}
@Override
public Stream<? extends Quad> stream(Optional<BlankNodeOrIRI> g, BlankNodeOrIRI s, IRI p, RDFTerm o) {
- JenaFactory factory = new JenaFactory(salt);
+ JenaRDF factory = new JenaRDF(salt);
return Iter.asStream(graph.find(toJenaPattern(g), toJenaPattern(s), toJenaPattern(p), toJenaPattern(o)), true)
- .map(factory::fromJena);
+ .map(factory::asQuad);
}
@Override
@@@ -175,16 -175,16 +175,16 @@@
@Override
public Stream<BlankNodeOrIRI> getGraphNames() {
- JenaFactory factory = new JenaFactory(salt);
+ JenaRDF factory = new JenaRDF(salt);
return Iter.asStream(graph.listGraphNodes()).map(node ->
- (BlankNodeOrIRI) factory.fromJena(node));
+ (BlankNodeOrIRI) factory.asRDFTerm(node));
}
@Override
public Iterable<Quad> iterate() {
- final JenaFactory factory = new JenaFactory(salt);
+ final JenaRDF factory = new JenaRDF(salt);
return Iter.asStream(graph.find(), false)
- .map(q -> (Quad) factory.fromJena(q))
+ .map(q -> (Quad) factory.asQuad(q))
::iterator;
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/d6306ad4/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGraphImpl.java
----------------------------------------------------------------------
diff --cc jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGraphImpl.java
index eab4089,ab56505..fd2f6c4
--- 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
@@@ -116,15 -116,15 +116,15 @@@ class JenaGraphImpl implements JenaGrap
@Override
public Stream<? extends Triple> stream() {
- JenaFactory factory = new JenaFactory(salt);
+ JenaRDF factory = new JenaRDF(salt);
- return Iter.asStream(graph.find(null, null, null), true).map(factory::fromJena);
+ return Iter.asStream(graph.find(null, null, null), true).map(factory::asTriple);
}
@Override
public Stream<? extends Triple> stream(BlankNodeOrIRI s, IRI p, RDFTerm o) {
- JenaFactory factory = new JenaFactory(salt);
+ JenaRDF factory = new JenaRDF(salt);
return Iter.asStream(graph.find(toJenaAny(s), toJenaAny(p), toJenaAny(o)), true)
- .map(factory::fromJena);
+ .map(factory::asTriple);
}
private Node toJenaAny(RDFTerm term) {
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/d6306ad4/jena/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDF
----------------------------------------------------------------------
diff --cc jena/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDF
index 0000000,0000000..afe6af3
new file mode 100644
--- /dev/null
+++ b/jena/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDF
@@@ -1,0 -1,0 +1,1 @@@
++org.apache.commons.rdf.jena.JenaRDF
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/d6306ad4/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
----------------------------------------------------------------------
diff --cc jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
index 16e3e67,728bba2..51cfa4c
--- a/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
+++ b/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
@@@ -18,14 -18,22 +18,21 @@@
package org.apache.commons.rdf.jena;
+ import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
+ import static org.junit.Assert.assertTrue;
+
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
+ import org.apache.commons.rdf.api.BlankNode;
+ import org.apache.commons.rdf.api.BlankNodeOrIRI;
import org.apache.commons.rdf.api.Graph ;
- import org.apache.commons.rdf.api.RDF ;
+ import org.apache.commons.rdf.api.RDFTerm;
+ import org.apache.commons.rdf.api.Triple;
+ import org.apache.commons.rdf.simple.Types;
-import org.apache.jena.riot.Lang;
+import org.apache.jena.riot.Lang ;
import org.apache.jena.riot.RDFDataMgr ;
import org.apache.jena.sparql.graph.GraphFactory ;
import org.junit.After;
@@@ -55,20 -64,72 +63,72 @@@ public class TestJenaGraphToCommonsRDFG
org.apache.jena.graph.Graph jGraph = GraphFactory.createGraphMem() ;
RDFDataMgr.read(jGraph, turtleFile.toUri().toString()) ;
- JenaFactory factory = new JenaFactory() ;
++ JenaRDF factory = new JenaRDF() ;
+
// "graph" is a CommonsRDF graph
- Graph graph = new JenaRDF().fromJena(jGraph) ;
+ Graph graph = factory.asGraph(jGraph) ;
+
+
+
+ // The below check expected statements from D.ttl
+
+ JenaIRI p = factory.createIRI("http://example.com/p");
+ JenaIRI s = factory.createIRI("http://example.com/s");
+ JenaLiteral literal123 = factory.createLiteral("123", Types.XSD_INTEGER);
+ assertTrue(graph.contains(s, p, literal123));
+
+ JenaIRI p1 = factory.createIRI("http://example.com/p1");
+ // Let's look up the BlankNode
+ BlankNodeOrIRI bnode1 = graph.stream(null, p1, null)
+ .findFirst().map(Triple::getSubject).get();
+ assertTrue(bnode1 instanceof BlankNode);
+
+ // Verify we can use BlankNode in query again
+ RDFTerm obj = graph.stream(bnode1, p1, null).findFirst().map(Triple::getObject).get();
+ // Let's look up also that nested blank node
+ assertTrue(obj instanceof BlankNode);
+ BlankNode bnode2 = (BlankNode)obj;
+
+
+
+ JenaIRI q = factory.createIRI("http://example.com/q");
+ JenaLiteral literalR = factory.createLiteral("r", "en");
+ assertTrue(graph.contains(bnode2, q, literalR));
+
+
+ // Can we add the same triple again as s/p/o
+ // without affecting graph size?
+ // Just to be evil we add a blanknode-iri-blanknode statement
+ assertEquals(3, graph.size());
+ graph.add(bnode1, p1, bnode2);
+ assertEquals(3, graph.size());
+
+ // Add the same Triple again
+ graph.stream(bnode2,null,null).findFirst().ifPresent(graph::add);
+ assertEquals(3, graph.size());
+
+
// Add to CommonsRDF Graph
- RDF rft = new JenaRDF() ;
- graph.add(rft.createIRI("http://example/s2"),
- rft.createIRI("http://example/p2"),
- rft.createLiteral("foo")) ;
- System.out.println("==== Write CommonsRDF graph\n") ;
- graph.stream().forEach(System.out::println) ;
-
- System.out.println("\n==== Write Jena graph directly\n") ;
- // And its in the Jena graph
- RDFDataMgr.write(System.out, jGraph, Lang.TTL) ;
+ JenaIRI s2 = factory.createIRI("http://example/s2");
+ JenaIRI p2 = factory.createIRI("http://example/p2");
+ JenaLiteral foo = factory.createLiteral("foo");
+ graph.add(s2,
+ p2,
+ foo) ;
+ assertEquals(4, graph.size());
+ assertTrue(graph.contains(s2,p2,foo));
+
+ // Verify the corresponding Jena Nodes are in Jena graph
+ assertTrue(jGraph.contains(s2.asJenaNode(), p2.asJenaNode(), foo.asJenaNode()));
+
+ if (DEBUG) {
+ System.out.println("==== Write CommonsRDF graph\n") ;
+ graph.stream().forEach(System.out::println) ;
+ // And its in the Jena graph
+ System.out.println("\n==== Write Jena graph directly\n") ;
+ RDFDataMgr.write(System.out, jGraph, Lang.TTL) ;
+ }
}
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/d6306ad4/jsonld-java/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDF
----------------------------------------------------------------------
diff --cc jsonld-java/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDF
index 0000000,0000000..2c97ca5
new file mode 100644
--- /dev/null
+++ b/jsonld-java/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDF
@@@ -1,0 -1,0 +1,1 @@@
++org.apache.commons.rdf.jsonldjava.JsonLdRDF
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/d6306ad4/rdf4j/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDF
----------------------------------------------------------------------
diff --cc rdf4j/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDF
index 0000000,0000000..f8a94bb
new file mode 100644
--- /dev/null
+++ b/rdf4j/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDF
@@@ -1,0 -1,0 +1,1 @@@
++org.apache.commons.rdf.rdf4j.RDF4J
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/d6306ad4/simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDF
----------------------------------------------------------------------
diff --cc simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDF
index 0000000,0000000..4003034
new file mode 100644
--- /dev/null
+++ b/simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDF
@@@ -1,0 -1,0 +1,1 @@@
++org.apache.commons.rdf.simple.SimpleRDF
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/d6306ad4/simple/src/test/java/org/apache/commons/rdf/simple/SimpleGraphTest.java
----------------------------------------------------------------------
[30/50] [abbrv] 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/COMMONSRDF-46
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
----------------------------------------------------------------------
----------------------------------------------------------------------
[43/50] [abbrv] incubator-commonsrdf git commit: Integration test -
use *Factory instead of *RDFTermFactory
Posted by st...@apache.org.
Integration test - use *Factory instead of *RDFTermFactory
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/b51b7bc0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/b51b7bc0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/b51b7bc0
Branch: refs/heads/COMMONSRDF-46
Commit: b51b7bc05af83b7478884e94086557a7f5bcb760
Parents: 49601fe
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Oct 26 11:41:23 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Oct 26 11:41:23 2016 +0100
----------------------------------------------------------------------
.../commons/rdf/integrationtests/AllToAllTest.java | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/b51b7bc0/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
----------------------------------------------------------------------
diff --git a/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java b/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
index 24d3697..1b32e35 100644
--- a/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
+++ b/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
@@ -32,9 +32,9 @@ 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.jena.JenaRDFTermFactory;
-import org.apache.commons.rdf.jsonldjava.JsonLdRDFTermFactory;
-import org.apache.commons.rdf.rdf4j.RDF4JTermFactory;
+import org.apache.commons.rdf.jena.JenaFactory;
+import org.apache.commons.rdf.jsonldjava.JsonLdFactory;
+import org.apache.commons.rdf.rdf4j.RDF4JFactory;
import org.apache.commons.rdf.simple.SimpleRDFTermFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -60,9 +60,9 @@ public class AllToAllTest {
public static Collection<Object[]> data() {
List<Class> factories = Arrays.asList(
SimpleRDFTermFactory.class,
- JenaRDFTermFactory.class,
- RDF4JTermFactory.class,
- JsonLdRDFTermFactory.class);
+ JenaFactory.class,
+ RDF4JFactory.class,
+ JsonLdFactory.class);
Collection<Object[]> allToAll = new ArrayList<>();
for (Class from : factories) {
for (Class to : factories) {
[27/50] [abbrv] incubator-commonsrdf git commit: RDFParser is
experimental feature for now
Posted by st...@apache.org.
RDFParser is experimental feature 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/ef6a1af4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/ef6a1af4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/ef6a1af4
Branch: refs/heads/COMMONSRDF-46
Commit: ef6a1af4819cddacd317952a950bda4ae46c6f18
Parents: 74196bd
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Tue Sep 27 18:54:06 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Tue Sep 27 18:54:06 2016 +0100
----------------------------------------------------------------------
.../java/org/apache/commons/rdf/experimental/RDFParser.java | 6 ++++++
1 file changed, 6 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ef6a1af4/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
index 39b7253..dd6bcf0 100644
--- a/api/src/main/java/org/apache/commons/rdf/experimental/RDFParser.java
+++ b/api/src/main/java/org/apache/commons/rdf/experimental/RDFParser.java
@@ -37,6 +37,12 @@ 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>,
[18/50] [abbrv] 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/92eb91a6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/92eb91a6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/92eb91a6
Branch: refs/heads/COMMONSRDF-46
Commit: 92eb91a6d530964732d5d45b294ff214fea0f813
Parents: a7849c8 be7bfc8
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Sep 23 17:56:55 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Sep 23 17:56:55 2016 +0100
----------------------------------------------------------------------
.../commons/rdf/jsonldjava/JsonLdRDFTermFactory.java | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
[29/50] [abbrv] 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/COMMONSRDF-46
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(-)
----------------------------------------------------------------------
[21/50] [abbrv] incubator-commonsrdf git commit: RDFParserBuilder ->
RDFParser
Posted by st...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/313fbf75/simple/src/main/java/org/apache/commons/rdf/simple/AbstractRDFParser.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/AbstractRDFParser.java b/simple/src/main/java/org/apache/commons/rdf/simple/AbstractRDFParser.java
new file mode 100644
index 0000000..e58fced
--- /dev/null
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/AbstractRDFParser.java
@@ -0,0 +1,541 @@
+/**
+ * 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.RDFParser;
+import org.apache.commons.rdf.api.RDFSyntax;
+import org.apache.commons.rdf.api.RDFTermFactory;
+
+/**
+ * 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/313fbf75/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/313fbf75/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
index ed16bb2..d1cdd57 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/RDFParseException.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/RDFParseException.java
@@ -18,33 +18,33 @@
package org.apache.commons.rdf.simple;
-import org.apache.commons.rdf.api.RDFParserBuilder;
+import org.apache.commons.rdf.api.RDFParser;
public class RDFParseException extends Exception {
private static final long serialVersionUID = 5427752643780702976L;
- private RDFParserBuilder builder;
+ private RDFParser builder;
- public RDFParseException(RDFParserBuilder builder) {
+ public RDFParseException(RDFParser builder) {
super();
this.builder = builder;
}
- public RDFParseException(RDFParserBuilder builder, String message, Throwable cause) {
+ public RDFParseException(RDFParser builder, String message, Throwable cause) {
super(message, cause);
this.builder = builder;
}
- public RDFParseException(RDFParserBuilder builder, String message) {
+ public RDFParseException(RDFParser builder, String message) {
super(message);
this.builder = builder;
}
- public RDFParseException(RDFParserBuilder builder, Throwable cause) {
+ public RDFParseException(RDFParser builder, Throwable cause) {
super(cause);
this.builder = builder;
}
- public RDFParserBuilder getRDFParserBuilder() {
+ public RDFParser getRDFParserBuilder() {
return builder;
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/313fbf75/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
index 439bacb..acb75b7 100644
--- a/simple/src/test/java/org/apache/commons/rdf/simple/AbstractRDFParserBuilderTest.java
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/AbstractRDFParserBuilderTest.java
@@ -32,7 +32,7 @@ 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.RDFParser;
import org.apache.commons.rdf.api.RDFSyntax;
import org.apache.commons.rdf.api.RDFTerm;
import org.apache.commons.rdf.api.RDFTermFactory;
@@ -71,9 +71,9 @@ public class AbstractRDFParserBuilderTest {
@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());
+ 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 {
@@ -107,7 +107,7 @@ public class AbstractRDFParserBuilderTest {
@Test
public void parseFile() throws Exception {
Graph g = factory.createGraph();
- RDFParserBuilder parser = dummyParser.source(testNt).target(g);
+ 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
@@ -132,7 +132,7 @@ public class AbstractRDFParserBuilderTest {
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);
+ RDFParser parser = dummyParser.base(base).contentType(RDFSyntax.RDFXML);
thrown.expect(IllegalStateException.class);
thrown.expectMessage("No source has been set");
// but .parse() should fail
@@ -143,7 +143,7 @@ public class AbstractRDFParserBuilderTest {
public void parseFileMissing() throws Exception {
Files.delete(testNt);
// This should not fail yet
- RDFParserBuilder parser = dummyParser.source(testNt);
+ RDFParser parser = dummyParser.source(testNt);
// but here:
thrown.expect(IOException.class);
parser.parse();
@@ -153,7 +153,7 @@ public class AbstractRDFParserBuilderTest {
@Test
public void parseFileContentType() throws Exception {
Graph g = factory.createGraph();
- RDFParserBuilder parser = dummyParser
+ RDFParser parser = dummyParser
.source(testNt)
.contentType(RDFSyntax.NTRIPLES)
.target(g);
@@ -180,7 +180,7 @@ public class AbstractRDFParserBuilderTest {
public void parseInputStreamFailsIfBaseMissing() throws Exception {
InputStream inputStream = new ByteArrayInputStream(new byte[0]);
// Should not fail at this point
- RDFParserBuilder parser = dummyParser.source(inputStream);
+ RDFParser parser = dummyParser.source(inputStream);
// but here:
thrown.expect(IllegalStateException.class);
thrown.expectMessage("base iri required for inputstream source");
@@ -192,7 +192,7 @@ public class AbstractRDFParserBuilderTest {
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);
+ 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"));
@@ -207,7 +207,7 @@ public class AbstractRDFParserBuilderTest {
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);
+ RDFParser parser = dummyParser.source(inputStream).contentType(RDFSyntax.NQUADS).target(g);
parser.parse().get(5, TimeUnit.SECONDS);
checkGraph(g);
assertNull(firstPredicate(g, "base"));
@@ -222,7 +222,7 @@ public class AbstractRDFParserBuilderTest {
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);
+ 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"));
@@ -240,7 +240,7 @@ public class AbstractRDFParserBuilderTest {
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);
+ 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"));
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/313fbf75/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..fe0b36e 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,18 @@ 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.RDFParser;
import org.apache.commons.rdf.api.RDFTermFactory;
/**
- * 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 +43,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 +57,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()) {
[20/50] [abbrv] incubator-commonsrdf git commit: avoid rawtypes
warnings
Posted by st...@apache.org.
avoid rawtypes warnings
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/ed73c6f5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/ed73c6f5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/ed73c6f5
Branch: refs/heads/COMMONSRDF-46
Commit: ed73c6f5dbe454865cf4a8f49c407beeb9d7d835
Parents: 8a26fe8
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Sep 23 17:59:00 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Sep 23 17:59:00 2016 +0100
----------------------------------------------------------------------
.../java/org/apache/commons/rdf/integrationtests/AllToAllTest.java | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ed73c6f5/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
----------------------------------------------------------------------
diff --git a/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java b/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
index 3edf6e4..09c887c 100644
--- a/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
+++ b/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
@@ -38,6 +38,7 @@ public class AllToAllTest {
this.graphFactory = to.newInstance();
}
+ @SuppressWarnings("rawtypes")
@Parameters(name = "{index}: {0}->{1}")
public static Collection<Object[]> data() {
List<Class> factories = Arrays.asList(
[36/50] [abbrv] 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/b7dec9b0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/b7dec9b0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/b7dec9b0
Branch: refs/heads/COMMONSRDF-46
Commit: b7dec9b0237f529674b3bdbc36c10276bf56a5a3
Parents: 8296419 06711f9
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Sep 28 23:56:42 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Sep 28 23:56:42 2016 +0100
----------------------------------------------------------------------
.../commons/rdf/rdf4j/RDF4JTermFactory.java | 33 +++++++++++---------
.../rdf/rdf4j/experimental/package-info.java | 3 +-
2 files changed, 19 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
[02/50] [abbrv] incubator-commonsrdf git commit: pom title
Posted by st...@apache.org.
pom title
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/888a2a43
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/888a2a43
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/888a2a43
Branch: refs/heads/COMMONSRDF-46
Commit: 888a2a436f2ea7d8645386cf20485ea91e7c84cb
Parents: 3353f9a
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Sep 9 16:34:13 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Sep 9 16:34:13 2016 +0100
----------------------------------------------------------------------
integration-tests/pom.xml | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/888a2a43/integration-tests/pom.xml
----------------------------------------------------------------------
diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml
index 196f4d5..71fd66b 100644
--- a/integration-tests/pom.xml
+++ b/integration-tests/pom.xml
@@ -64,4 +64,5 @@
</dependencies>
+ <name>Commons RDF: Integration tests</name>
</project>
[08/50] [abbrv] incubator-commonsrdf git commit: AllToAllTest
Posted by st...@apache.org.
AllToAllTest
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/1828c2ab
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/1828c2ab
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/1828c2ab
Branch: refs/heads/COMMONSRDF-46
Commit: 1828c2abf584958bf25de48d0827c825fd3bb21a
Parents: 97e3acd
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Sep 9 17:36:32 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Sep 9 17:36:41 2016 +0100
----------------------------------------------------------------------
.../rdf/integrationtests/AllToAllTest.java | 99 ++++++++++++++++++++
.../rdf/integrationtests/JenaRDF4JTest.java | 78 ---------------
2 files changed, 99 insertions(+), 78 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/1828c2ab/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
----------------------------------------------------------------------
diff --git a/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java b/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
new file mode 100644
index 0000000..a8cd1cd
--- /dev/null
+++ b/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
@@ -0,0 +1,99 @@
+package org.apache.commons.rdf.integrationtests;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.commons.rdf.api.BlankNode;
+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.RDFTermFactory;
+import org.apache.commons.rdf.api.Triple;
+import org.apache.commons.rdf.jena.JenaRDFTermFactory;
+import org.apache.commons.rdf.jsonldjava.JsonLdRDFTermFactory;
+import org.apache.commons.rdf.rdf4j.RDF4JTermFactory;
+import org.apache.commons.rdf.simple.SimpleRDFTermFactory;
+import org.junit.Test;
+
+public class AllToAllTest {
+
+ private RDFTermFactory simpleFactory = new SimpleRDFTermFactory();
+ private RDFTermFactory jenaFactory = new JenaRDFTermFactory();
+ private RDFTermFactory rdf4jFactory = new RDF4JTermFactory();
+ private RDFTermFactory jsonldFactory = new JsonLdRDFTermFactory();
+
+ @Test
+ public void jenaToRdf4j() throws Exception {
+ nodesIntoOther(jenaFactory, rdf4jFactory);
+ }
+ @Test
+ public void jenaToJsonLd() throws Exception {
+ nodesIntoOther(jenaFactory, jsonldFactory);
+ }
+ @Test
+ public void jenaToSimple() throws Exception {
+ nodesIntoOther(jenaFactory, simpleFactory);
+ }
+
+ @Test
+ public void rdf4jToJena() throws Exception {
+ nodesIntoOther(rdf4jFactory, jenaFactory);
+ }
+ @Test
+ public void rdf4jToJsonLd() throws Exception {
+ nodesIntoOther(rdf4jFactory, jsonldFactory);
+ }
+ @Test
+ public void rdf4jToSimple() throws Exception {
+ nodesIntoOther(rdf4jFactory, simpleFactory);
+ }
+
+ @Test
+ public void simpletoJena() throws Exception {
+ nodesIntoOther(simpleFactory, jenaFactory);
+ }
+ @Test
+ public void simpleToJsonLd() throws Exception {
+ nodesIntoOther(simpleFactory, jsonldFactory);
+ }
+ @Test
+ public void simpleToRdf4j() throws Exception {
+ nodesIntoOther(simpleFactory, rdf4jFactory);
+ }
+
+ public void nodesIntoOther(RDFTermFactory fromFactory, RDFTermFactory toFactory) throws Exception {
+ Graph g = fromFactory.createGraph();
+ BlankNode s = toFactory.createBlankNode();
+ IRI p = toFactory.createIRI("http://example.com/p");
+ Literal o = toFactory.createLiteral("Hello");
+
+ g.add(s, p, o);
+
+ // blankNode should still work with g.contains()
+ assertTrue(g.contains(s, p, o));
+ Triple t1 = g.stream().findAny().get();
+
+ // Can't make assumptions about mappegetPredicated BlankNode equality
+ // assertEquals(s, t.getSubject());
+ assertEquals(p, t1.getPredicate());
+ assertEquals(o, t1.getObject());
+
+ IRI s2 = toFactory.createIRI("http://example.com/s2");
+ g.add(s2, p, s);
+ assertTrue(g.contains(s2, p, s));
+
+ // This should be mapped to the same BlankNode
+ // (even if it has a different identifier), e.g.
+ // we should be able to do:
+
+ Triple t2 = g.stream(s2, p, null).findAny().get();
+
+ BlankNode bnode = (BlankNode) t2.getObject();
+ // And that (possibly adapted) BlankNode object should
+ // match the subject of t1 statement
+ assertEquals(bnode, t1.getSubject());
+ // And can be used as a key:
+ Triple t3 = g.stream(bnode, p, null).findAny().get();
+ assertEquals(t1, t3);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/1828c2ab/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/JenaRDF4JTest.java
----------------------------------------------------------------------
diff --git a/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/JenaRDF4JTest.java b/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/JenaRDF4JTest.java
deleted file mode 100644
index 50b5c68..0000000
--- a/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/JenaRDF4JTest.java
+++ /dev/null
@@ -1,78 +0,0 @@
-package org.apache.commons.rdf.integrationtests;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import org.apache.commons.rdf.api.BlankNode;
-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.RDFTermFactory;
-import org.apache.commons.rdf.api.Triple;
-import org.apache.commons.rdf.jena.RDFTermFactoryJena;
-import org.apache.commons.rdf.rdf4j.RDF4JTermFactory;
-import org.apache.commons.rdf.simple.SimpleRDFTermFactory;
-import org.junit.Test;
-
-public class JenaRDF4JTest {
-
- private RDFTermFactory simpleFactory = new SimpleRDFTermFactory();
- private RDFTermFactory jenaFactory = new RDFTermFactoryJena();
- private RDFTermFactory rdf4jFactory = new RDF4JTermFactory();
-
- @Test
- public void jenaToRdf4j() throws Exception {
- nodesIntoOther(jenaFactory, rdf4jFactory);
- }
-
- @Test
- public void rdf4jToJena() throws Exception {
- nodesIntoOther(rdf4jFactory, jenaFactory);
- }
-
- @Test
- public void simpletoJena() throws Exception {
- nodesIntoOther(simpleFactory, jenaFactory);
- }
-
- @Test
- public void simpleToRdf4j() throws Exception {
- nodesIntoOther(simpleFactory, rdf4jFactory);
- }
-
- public void nodesIntoOther(RDFTermFactory fromFactory, RDFTermFactory toFactory) throws Exception {
- Graph g = fromFactory.createGraph();
- BlankNode s = toFactory.createBlankNode();
- IRI p = toFactory.createIRI("http://example.com/p");
- Literal o = toFactory.createLiteral("Hello");
-
- g.add(s, p, o);
-
- // blankNode should still work with g.contains()
- assertTrue(g.contains(s, p, o));
- Triple t1 = g.stream().findAny().get();
-
- // Can't make assumptions about mappegetPredicated BlankNode equality
- // assertEquals(s, t.getSubject());
- assertEquals(p, t1.getPredicate());
- assertEquals(o, t1.getObject());
-
- IRI s2 = toFactory.createIRI("http://example.com/s2");
- g.add(s2, p, s);
- assertTrue(g.contains(s2, p, s));
-
- // This should be mapped to the same BlankNode
- // (even if it has a different identifier), e.g.
- // we should be able to do:
-
- Triple t2 = g.stream(s2, p, null).findAny().get();
-
- BlankNode bnode = (BlankNode) t2.getObject();
- // And that (possibly adapted) BlankNode object should
- // match the subject of t1 statement
- assertEquals(bnode, t1.getSubject());
- // And can be used as a key:
- Triple t3 = g.stream(bnode, p, null).findAny().get();
- assertEquals(t1, t3);
- }
-}
[45/50] [abbrv] incubator-commonsrdf git commit: jena no longer need
log4j.properties
Posted by st...@apache.org.
jena no longer need log4j.properties
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/b54b5c68
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/b54b5c68
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/b54b5c68
Branch: refs/heads/COMMONSRDF-46
Commit: b54b5c6862b570a181390f32537310642fb88690
Parents: c34a85e
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Oct 26 11:45:13 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Oct 26 11:45:13 2016 +0100
----------------------------------------------------------------------
jena/src/test/resources/log4j.properties | 33 ---------------------------
1 file changed, 33 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/b54b5c68/jena/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/jena/src/test/resources/log4j.properties b/jena/src/test/resources/log4j.properties
deleted file mode 100644
index 794559f..0000000
--- a/jena/src/test/resources/log4j.properties
+++ /dev/null
@@ -1,33 +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.
-log4j.rootLogger=INFO, stdlog
-
-log4j.appender.stdlog=org.apache.log4j.ConsoleAppender
-## log4j.appender.stdlog.target=System.err
-log4j.appender.stdlog.layout=org.apache.log4j.PatternLayout
-log4j.appender.stdlog.layout.ConversionPattern=%d{HH:mm:ss} %-5p %-25c{1} :: %m%n
-
-# Execution logging
-log4j.logger.org.apache.jena.arq.info=INFO
-log4j.logger.org.apache.jena.arq.exec=INFO
-
-# Everything else in Jena
-log4j.logger.org.apache.jena=WARN
-log4j.logger.org.apache.jena.riot=INFO
-
-# Apache Commons HTTP
-# May be useful to turn up to DEBUG if debugging HTTP communication issues
-log4j.logger.org.apache.http=WARN
[13/50] [abbrv] 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/60864de7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/60864de7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/60864de7
Branch: refs/heads/COMMONSRDF-46
Commit: 60864de72d0f5ac38a765fcadaa9ce52d27b748e
Parents: ace02c0 47abae8
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Tue Sep 13 00:12:40 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Tue Sep 13 00:12:40 2016 +0100
----------------------------------------------------------------------
.../org/apache/commons/rdf/jena/JenaRDFTermFactory.java | 10 +++++-----
.../apache/commons/rdf/jena/impl/GeneralizedQuadImpl.java | 2 +-
2 files changed, 6 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
[25/50] [abbrv] incubator-commonsrdf git commit: JsonLdDataSet and
JsonLdGraph made public for JsonLdParser
Posted by st...@apache.org.
JsonLdDataSet and JsonLdGraph made public for JsonLdParser
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/c3c17192
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/c3c17192
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/c3c17192
Branch: refs/heads/COMMONSRDF-46
Commit: c3c17192ad049d2d86678f440e4a6d0f29f28dc4
Parents: a189f91
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Tue Sep 27 18:43:30 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Tue Sep 27 18:43:30 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/c3c17192/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/c3c17192/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;
[32/50] [abbrv] 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/COMMONSRDF-46
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
----------------------------------------------------------------------
----------------------------------------------------------------------
[42/50] [abbrv] incubator-commonsrdf git commit: Keep all dependency
versions in top pom.xml
Posted by st...@apache.org.
Keep all dependency versions in top pom.xml
.. as <properties>
Also slf4j-simple set as logging backend for Jena
and JSONLD-Java during tests.
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/49601fed
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/49601fed
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/49601fed
Branch: refs/heads/COMMONSRDF-46
Commit: 49601fed85787296d42b53fbdd074deded7f5e9b
Parents: 887c9e6
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Oct 26 11:40:27 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Oct 26 11:40:51 2016 +0100
----------------------------------------------------------------------
integration-tests/pom.xml | 15 ---------------
jena/pom.xml | 9 ++-------
jsonld-java/pom.xml | 7 +------
pom.xml | 37 +++++++++++++++++++++++++++++++------
rdf4j/pom.xml | 10 +---------
5 files changed, 35 insertions(+), 43 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/49601fed/integration-tests/pom.xml
----------------------------------------------------------------------
diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml
index 57835e5..8487ac9 100644
--- a/integration-tests/pom.xml
+++ b/integration-tests/pom.xml
@@ -56,20 +56,5 @@
<artifactId>commons-rdf-jsonld-java</artifactId>
<version>${project.version}</version>
</dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>commons-rdf-api</artifactId>
- <version>${project.version}</version>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
-
</dependencies>
-
-
</project>
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/49601fed/jena/pom.xml
----------------------------------------------------------------------
diff --git a/jena/pom.xml b/jena/pom.xml
index f8a2dc4..ab9ff8b 100644
--- a/jena/pom.xml
+++ b/jena/pom.xml
@@ -52,7 +52,7 @@
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>apache-jena-libs</artifactId>
- <version>${ver.jena}</version>
+ <version>${jena.version}</version>
<type>pom</type>
<scope>optional</scope>
</dependency>
@@ -62,7 +62,7 @@
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-osgi</artifactId>
- <version>${ver.jena}</version>
+ <version>${jena.version}</version>
</dependency>
<!-- Additional bundles needed by jena-osgi -->
@@ -85,11 +85,6 @@
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
</dependencies>
</project>
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/49601fed/jsonld-java/pom.xml
----------------------------------------------------------------------
diff --git a/jsonld-java/pom.xml b/jsonld-java/pom.xml
index 6a4826c..ad8645c 100644
--- a/jsonld-java/pom.xml
+++ b/jsonld-java/pom.xml
@@ -54,14 +54,9 @@
<dependency>
<groupId>com.github.jsonld-java</groupId>
<artifactId>jsonld-java</artifactId>
- <version>0.8.2</version>
+ <version>${jsonldjava.version}</version>
</dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
</dependencies>
</project>
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/49601fed/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 22c01c3..9ef400a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -52,11 +52,26 @@
<commons.scmPubUrl>https://svn.apache.org/repos/infra/websites/production/commonsrdf/content/</commons.scmPubUrl>
<commons.scmPubCheckoutDirectory>${project.build.directory}/site-content</commons.scmPubCheckoutDirectory>
<commons.javadoc.java.link>https://docs.oracle.com/javase/8/docs/api/</commons.javadoc.java.link>
- <!-- upgrade from 0.8.0 -->
- <commons.japicmp.version>0.9.1</commons.japicmp.version>
- <ver.jena>3.1.0</ver.jena>
+
+ <!-- upgrade from 0.8.0 for Java 8 support -->
+ <commons.japicmp.version>0.9.1</commons.japicmp.version>
+
+
+ <!-- NOTE: jsonldjava is also used by rdf4j and jena, check -->
+ <jsonldjava.version>0.8.2</jsonldjava.version>
+ <rdf4j.version>2.0</rdf4j.version>
+ <jena.version>3.1.0</jena.version>
+ <!-- NOTE: dexx and xerces versions should match
+ the versions marked as <optional> in jena-osgi pom
+ -->
<dexx.collection.version>0.6</dexx.collection.version>
<servicemix.xerces.version>2.11.0_1</servicemix.xerces.version>
+
+
+ <!-- Test dependencies -->
+ <slf4j.version>1.7.20</slf4j.version>
+ <junit.version>4.12</junit.version>
+
</properties>
<scm>
@@ -224,16 +239,26 @@
<module>integration-tests</module>
</modules>
- <dependencyManagement>
+ <!--
+ Common dependencies across modules.
+ Keep this list small and only <scope>test</scope> !
+ -->
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>4.12</version>
+ <version>${junit.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <!-- System.err logging for Jena, JSONLD-Java, RDF4J
+ -->
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>${slf4j.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
- </dependencyManagement>
<build>
<plugins>
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/49601fed/rdf4j/pom.xml
----------------------------------------------------------------------
diff --git a/rdf4j/pom.xml b/rdf4j/pom.xml
index 0c6cb28..f833b67 100644
--- a/rdf4j/pom.xml
+++ b/rdf4j/pom.xml
@@ -30,9 +30,6 @@
<artifactId>commons-rdf-rdf4j</artifactId>
<packaging>jar</packaging>
- <properties>
- <rdf4j.version>2.0</rdf4j.version>
- </properties>
<name>Commons RDF: Integration: RDF4j</name>
<description>Eclipse RDF4j implementation of Commons RDF API</description>
@@ -81,7 +78,7 @@
<artifactId>rdf4j-repository-api</artifactId>
</dependency>
- <!-- For RDF4JParserBuilder, these are the RIO dependencies for the standard
+ <!-- For RDF4JParser, these are the RIO dependencies for the standard
RDF 1.1 languages -->
<dependency>
<groupId>org.eclipse.rdf4j</groupId>
@@ -145,11 +142,6 @@
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
</dependencies>
[44/50] [abbrv] incubator-commonsrdf git commit: Avoid System.out
Posted by st...@apache.org.
Avoid System.out
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/c34a85e1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/c34a85e1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/c34a85e1
Branch: refs/heads/COMMONSRDF-46
Commit: c34a85e14994831825f966a6a9bdb65c59711436
Parents: b51b7bc
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Oct 26 11:41:41 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Oct 26 11:41:49 2016 +0100
----------------------------------------------------------------------
.../commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java | 7 +++----
.../java/org/apache/commons/rdf/simple/SimpleGraphTest.java | 2 +-
2 files changed, 4 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/c34a85e1/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
----------------------------------------------------------------------
diff --git a/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java b/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
index 1a7b4e0..13ee7e7 100644
--- a/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
+++ b/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
@@ -63,10 +63,9 @@ public class TestJenaGraphToCommonsRDFGraph {
graph.add(rft.createIRI("http://example/s2"),
rft.createIRI("http://example/p2"),
rft.createLiteral("foo")) ;
- System.out.println("==== Write CommonsRDF graph\n") ;
- graph.stream().forEach(System.out::println) ;
-
- System.out.println("\n==== Write Jena graph directly\n") ;
+// System.out.println("==== Write CommonsRDF graph\n") ;
+// graph.stream().forEach(System.out::println) ;
+// System.out.println("\n==== Write Jena graph directly\n") ;
// And its in the Jena graph
RDFDataMgr.write(System.out, jGraph, Lang.TTL) ;
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/c34a85e1/simple/src/test/java/org/apache/commons/rdf/simple/SimpleGraphTest.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleGraphTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleGraphTest.java
index 14f14a6..90015c9 100644
--- a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleGraphTest.java
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleGraphTest.java
@@ -37,7 +37,7 @@ public class SimpleGraphTest extends AbstractGraphTest {
@Test
public void graphToString() {
Assume.assumeNotNull(aliceName, companyName);
- System.out.println(graph);
+ //System.out.println(graph);
assertTrue(graph
.toString()
.contains(
[12/50] [abbrv] incubator-commonsrdf git commit: Merge branch
'parser-with-quads' into jena-jsonld-rdf4j-integration
Posted by st...@apache.org.
Merge branch 'parser-with-quads' 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/ace02c0c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/ace02c0c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/ace02c0c
Branch: refs/heads/COMMONSRDF-46
Commit: ace02c0c179f490d1e563d35e23dffbd6d951ef6
Parents: 2b51794 bfcead4
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Tue Sep 13 00:12:35 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Tue Sep 13 00:12:35 2016 +0100
----------------------------------------------------------------------
.../commons/rdf/api/RDFParserBuilder.java | 21 +++++++++++++-------
.../rdf/simple/AbstractRDFParserBuilder.java | 6 +-----
2 files changed, 15 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
[41/50] [abbrv] incubator-commonsrdf git commit: Add integration test
Posted by st...@apache.org.
Add integration test
Merge branch '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/887c9e68
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/887c9e68
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/887c9e68
Branch: refs/heads/COMMONSRDF-46
Commit: 887c9e68a37106f17b5c609a149af718c3e679c4
Parents: 5f6bcff c991d05
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Oct 26 11:15:06 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Oct 26 11:17:16 2016 +0100
----------------------------------------------------------------------
integration-tests/pom.xml | 75 ++++++++
.../rdf/integrationtests/AllToAllTest.java | 178 +++++++++++++++++++
pom.xml | 1 +
3 files changed, 254 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/887c9e68/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
----------------------------------------------------------------------
diff --cc integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
index 0000000,09c887c..24d3697
mode 000000,100644..100644
--- a/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
+++ b/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
@@@ -1,0 -1,161 +1,178 @@@
++/**
++ * 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.integrationtests;
+
+ import static org.junit.Assert.assertEquals;
+ import static org.junit.Assert.assertTrue;
+
+ import java.util.ArrayList;
+ import java.util.Arrays;
+ import java.util.Collection;
+ import java.util.List;
+
+ import org.apache.commons.rdf.api.BlankNode;
+ 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.RDFTerm;
+ import org.apache.commons.rdf.api.RDFTermFactory;
+ import org.apache.commons.rdf.api.Triple;
+ import org.apache.commons.rdf.jena.JenaRDFTermFactory;
+ import org.apache.commons.rdf.jsonldjava.JsonLdRDFTermFactory;
+ import org.apache.commons.rdf.rdf4j.RDF4JTermFactory;
+ import org.apache.commons.rdf.simple.SimpleRDFTermFactory;
+ import org.junit.Test;
+ import org.junit.runner.RunWith;
+ import org.junit.runners.Parameterized;
+ import org.junit.runners.Parameterized.Parameters;
+
+ @RunWith(Parameterized.class)
+ public class AllToAllTest {
+
+ private RDFTermFactory nodeFactory;
+ private RDFTermFactory graphFactory;
+
+
+ public AllToAllTest(
- Class<? extends RDFTermFactory> from,
++ Class<? extends RDFTermFactory> from,
+ Class<? extends RDFTermFactory> to) throws InstantiationException, IllegalAccessException {
+ this.nodeFactory = from.newInstance();
- this.graphFactory = to.newInstance();
++ this.graphFactory = to.newInstance();
+ }
-
++
+ @SuppressWarnings("rawtypes")
+ @Parameters(name = "{index}: {0}->{1}")
- public static Collection<Object[]> data() {
++ public static Collection<Object[]> data() {
+ List<Class> factories = Arrays.asList(
- SimpleRDFTermFactory.class,
- JenaRDFTermFactory.class,
++ SimpleRDFTermFactory.class,
++ JenaRDFTermFactory.class,
+ RDF4JTermFactory.class,
+ JsonLdRDFTermFactory.class);
+ Collection<Object[]> allToAll = new ArrayList<>();
+ for (Class from : factories) {
+ for (Class to : factories) {
+ // NOTE: we deliberately include self-to-self here
+ // to test two instances of the same implementation
+ allToAll.add(new Object[]{from, to});
+ }
+ }
+ return allToAll;
+ }
-
++
+ /**
+ * This test creates a {@link Graph} with the first
+ * {@link RDFTermFactory}, then inserts/queries with
+ * triples using {@link RDFTerm}s created with the second factory.
- *
++ *
+ * @param nodeFactory Factory to create {@link RDFTerm} instances
+ * @param graphFactory Factory to create {@link Graph}
+ * @throws Exception
+ */
+ @Test
+ public void addTermsFromOtherFactory() throws Exception {
+ Graph g = graphFactory.createGraph();
+ BlankNode s = nodeFactory.createBlankNode();
+ IRI p = nodeFactory.createIRI("http://example.com/p");
+ Literal o = nodeFactory.createLiteral("Hello");
+
+ g.add(s, p, o);
+
+ // blankNode should still work with g.contains()
+ assertTrue(g.contains(s, p, o));
+ Triple t1 = g.stream().findAny().get();
+
+ // Can't make assumptions about BlankNode equality - it might
+ // have been mapped to a different BlankNode.uniqueReference()
+ // assertEquals(s, t.getSubject());
-
++
+ assertEquals(p, t1.getPredicate());
+ assertEquals(o, t1.getObject());
+
+ IRI s2 = nodeFactory.createIRI("http://example.com/s2");
+ g.add(s2, p, s);
+ assertTrue(g.contains(s2, p, s));
+
+ // This should be mapped to the same BlankNode
+ // (even if it has a different identifier), e.g.
+ // we should be able to do:
+
+ Triple t2 = g.stream(s2, p, null).findAny().get();
+
+ BlankNode bnode = (BlankNode) t2.getObject();
+ // And that (possibly adapted) BlankNode object should
+ // match the subject of t1 statement
+ assertEquals(bnode, t1.getSubject());
+ // And can be used as a key:
+ Triple t3 = g.stream(bnode, p, null).findAny().get();
- assertEquals(t1, t3);
++ assertEquals(t1, t3);
+ }
-
++
+
+ /**
- * This is a variation of {@link #addTermsFromOtherFactory(RDFTermFactory, RDFTermFactory)},
++ * This is a variation of {@link #addTermsFromOtherFactory(RDFTermFactory, RDFTermFactory)},
+ * but here {@link Triple} is created in the "foreign" nodeFactory before adding to the graph.
- *
++ *
+ * @param nodeFactory Factory to create {@link RDFTerm} and {@link Triple}s
+ * @param graphFactory Factory to create {@link Graph}
+ * @throws Exception
+ */
+ @Test
+ public void addTriplesFromOtherFactory() throws Exception {
+ Graph g = graphFactory.createGraph();
+ BlankNode s = nodeFactory.createBlankNode();
+ IRI p = nodeFactory.createIRI("http://example.com/p");
+ Literal o = nodeFactory.createLiteral("Hello");
-
++
+ Triple srcT1 = nodeFactory.createTriple(s, p, o);
+ // This should work even with BlankNode as they are from the same factory
+ assertEquals(s, srcT1.getSubject());
+ assertEquals(p, srcT1.getPredicate());
+ assertEquals(o, srcT1.getObject());
+ g.add(srcT1);
-
++
+ // what about the blankNode within?
+ assertTrue(g.contains(srcT1));
+ Triple t1 = g.stream().findAny().get();
+
+ // Can't make assumptions about BlankNode equality - it might
+ // have been mapped to a different BlankNode.uniqueReference()
+ //assertEquals(srcT1, t1);
+ //assertEquals(s, t1.getSubject());
+ assertEquals(p, t1.getPredicate());
+ assertEquals(o, t1.getObject());
+
+ IRI s2 = nodeFactory.createIRI("http://example.com/s2");
+ Triple srcT2 = nodeFactory.createTriple(s2, p, s);
+ g.add(srcT2);
+ assertTrue(g.contains(srcT2));
+
+ // This should be mapped to the same BlankNode
+ // (even if it has a different identifier), e.g.
+ // we should be able to do:
+
+ Triple t2 = g.stream(s2, p, null).findAny().get();
+
+ BlankNode bnode = (BlankNode) t2.getObject();
+ // And that (possibly adapted) BlankNode object should
+ // match the subject of t1 statement
+ assertEquals(bnode, t1.getSubject());
+ // And can be used as a key:
+ Triple t3 = g.stream(bnode, p, null).findAny().get();
- assertEquals(t1, t3);
- }
++ assertEquals(t1, t3);
++ }
+ }
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/887c9e68/pom.xml
----------------------------------------------------------------------
[28/50] [abbrv] incubator-commonsrdf git commit: Jena*Impl prefixes
Posted by st...@apache.org.
Jena*Impl prefixes
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/6c17d5ed
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/6c17d5ed
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/6c17d5ed
Branch: refs/heads/COMMONSRDF-46
Commit: 6c17d5ed10400c840f749ac1f2d252a4010f8cad
Parents: ef6a1af
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Sep 28 01:18:19 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Sep 28 01:18:19 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 -------
24 files changed, 997 insertions(+), 997 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/6c17d5ed/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/6c17d5ed/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/6c17d5ed/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/6c17d5ed/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/6c17d5ed/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/6c17d5ed/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/6c17d5ed/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/6c17d5ed/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/6c17d5ed/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/6c17d5ed/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/6c17d5ed/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/6c17d5ed/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/6c17d5ed/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/6c17d5ed/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/6c17d5ed/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/6c17d5ed/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/6c17d5ed/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/6c17d5ed/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/6c17d5ed/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/6c17d5ed/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/6c17d5ed/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/6c17d5ed/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/6c17d5ed/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/6c17d5ed/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());
- }
-
-}
[37/50] [abbrv] 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/28e38cad
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/28e38cad
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/28e38cad
Branch: refs/heads/COMMONSRDF-46
Commit: 28e38cad831eb32da5d78582b534dfaf7e062564
Parents: b7dec9b b0c55bd
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Thu Sep 29 00:50:06 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Thu Sep 29 00:50:06 2016 +0100
----------------------------------------------------------------------
.../commons/rdf/jena/JenaRDFTermFactory.java | 202 ++++++++++++++-----
.../rdf/jena/experimental/package-info.java | 3 +-
2 files changed, 149 insertions(+), 56 deletions(-)
----------------------------------------------------------------------
[22/50] [abbrv] incubator-commonsrdf git commit: RDFParserBuilder ->
RDFParser
Posted by st...@apache.org.
RDFParserBuilder -> RDFParser
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/313fbf75
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/313fbf75
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/313fbf75
Branch: refs/heads/COMMONSRDF-46
Commit: 313fbf75d349cf194baf83cb2da399bd8ad34bb6
Parents: ed73c6f
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Tue Sep 27 17:13:16 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Tue Sep 27 17:16:34 2016 +0100
----------------------------------------------------------------------
.../org/apache/commons/rdf/api/RDFParser.java | 479 ++++++++++++++++
.../commons/rdf/api/RDFParserBuilder.java | 479 ----------------
.../apache/commons/rdf/jena/JenaRDFParser.java | 103 ++++
.../commons/rdf/jena/JenaRDFParserBuilder.java | 103 ----
.../commons/rdf/jena/TestRDFParserBuilder.java | 4 +-
.../rdf/jsonldjava/JsonLdParserBuilder.java | 4 +-
.../apache/commons/rdf/rdf4j/RDF4JParser.java | 194 +++++++
.../commons/rdf/rdf4j/RDF4JParserBuilder.java | 194 -------
.../apache/commons/rdf/rdf4j/package-info.java | 6 +-
.../commons/rdf/simple/AbstractRDFParser.java | 541 +++++++++++++++++++
.../rdf/simple/AbstractRDFParserBuilder.java | 541 -------------------
.../commons/rdf/simple/RDFParseException.java | 14 +-
.../simple/AbstractRDFParserBuilderTest.java | 26 +-
.../rdf/simple/DummyRDFParserBuilder.java | 10 +-
14 files changed, 1349 insertions(+), 1349 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/313fbf75/api/src/main/java/org/apache/commons/rdf/api/RDFParser.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/RDFParser.java b/api/src/main/java/org/apache/commons/rdf/api/RDFParser.java
new file mode 100644
index 0000000..72c7e61
--- /dev/null
+++ b/api/src/main/java/org/apache/commons/rdf/api/RDFParser.java
@@ -0,0 +1,479 @@
+/**
+ * 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;
+
+/**
+ * Parse 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
+ * 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></rdf:Description></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><?xml encoding="iso-8859-1"></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><?xml encoding="iso-8859-1"></code> header).
+ * <p>
+ * The {@link #base(IRI)} or {@link #base(String)} MAY be set before calling
+ * {@link #parse()}, otherwise {@link Path#toUri()} will be used as the base
+ * IRI.
+ * <p>
+ * This method will override any source set with {@link #source(IRI)},
+ * {@link #source(InputStream)} or {@link #source(String)}.
+ *
+ * @param file
+ * A Path for a file to parse
+ * @return An {@link RDFParser} that will use the specified source.
+ */
+ RDFParser source(Path file);
+
+ /**
+ * Specify an absolute source {@link IRI} to retrieve and parse.
+ * <p>
+ * 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><?xml encoding="iso-8859-1"></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><?xml encoding="iso-8859-1"></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/313fbf75/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></rdf:Description></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><?xml encoding="iso-8859-1"></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><?xml encoding="iso-8859-1"></code> header).
- * <p>
- * The {@link #base(IRI)} or {@link #base(String)} MAY be set before calling
- * {@link #parse()}, otherwise {@link Path#toUri()} will be used as the base
- * IRI.
- * <p>
- * This method will override any source set with {@link #source(IRI)},
- * {@link #source(InputStream)} or {@link #source(String)}.
- *
- * @param file
- * A Path for a file to parse
- * @return An {@link 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><?xml encoding="iso-8859-1"></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><?xml encoding="iso-8859-1"></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/313fbf75/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFParser.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFParser.java b/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFParser.java
new file mode 100644
index 0000000..9690811
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFParser.java
@@ -0,0 +1,103 @@
+/**
+ * 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.RDFParser;
+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.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/313fbf75/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/313fbf75/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..ead3e3a 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,7 +28,7 @@ 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.RDFParser.ParseResult;
import org.apache.commons.rdf.api.RDFSyntax;
import org.junit.After;
import org.junit.Before;
@@ -54,7 +54,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());
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/313fbf75/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
index e38af2c..2219c74 100644
--- 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
@@ -30,7 +30,7 @@ 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 org.apache.commons.rdf.simple.AbstractRDFParser;
import com.github.jsonldjava.core.JsonLdError;
import com.github.jsonldjava.core.JsonLdOptions;
@@ -38,7 +38,7 @@ import com.github.jsonldjava.core.JsonLdProcessor;
import com.github.jsonldjava.core.RDFDataset;
import com.github.jsonldjava.utils.JsonUtils;
-public class JsonLdParserBuilder extends AbstractRDFParserBuilder<JsonLdParserBuilder> {
+public class JsonLdParserBuilder extends AbstractRDFParser<JsonLdParserBuilder> {
@Override
protected JsonLdRDFTermFactory createRDFTermFactory() {
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/313fbf75/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JParser.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JParser.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JParser.java
new file mode 100644
index 0000000..dd82044
--- /dev/null
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JParser.java
@@ -0,0 +1,194 @@
+/**
+ * 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.RDFParser;
+import org.apache.commons.rdf.api.RDFSyntax;
+import org.apache.commons.rdf.simple.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/313fbf75/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/313fbf75/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..036b54b 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.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.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.RDF4JParser#target(org.apache.commons.rdf.api.Graph)}
* and a an adapted {@link org.apache.commons.rdf.rdf4j.RDF4JGraph}
*
*
[31/50] [abbrv] 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/COMMONSRDF-46
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(-)
----------------------------------------------------------------------
[16/50] [abbrv] 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/f5a1604c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/f5a1604c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/f5a1604c
Branch: refs/heads/COMMONSRDF-46
Commit: f5a1604c5cabc3eac92177825f4ad6cb9c09228b
Parents: 0c58bd8 5e78763
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Sep 23 17:30:20 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Sep 23 17:30:20 2016 +0100
----------------------------------------------------------------------
jena/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
[17/50] [abbrv] incubator-commonsrdf git commit: parameterized all to
all test
Posted by st...@apache.org.
parameterized all to all test
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/a7849c86
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/a7849c86
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/a7849c86
Branch: refs/heads/COMMONSRDF-46
Commit: a7849c8671cd3ad0ee9e1fc8f7b51bf7de4aa26f
Parents: f5a1604
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Sep 23 17:45:36 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Sep 23 17:45:36 2016 +0100
----------------------------------------------------------------------
.../rdf/integrationtests/AllToAllTest.java | 87 ++++++++------------
1 file changed, 36 insertions(+), 51 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/a7849c86/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
----------------------------------------------------------------------
diff --git a/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java b/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
index 0d65f05..b0b4f3b 100644
--- a/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
+++ b/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
@@ -3,6 +3,11 @@ package org.apache.commons.rdf.integrationtests;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
import org.apache.commons.rdf.api.BlankNode;
import org.apache.commons.rdf.api.Graph;
import org.apache.commons.rdf.api.IRI;
@@ -15,63 +20,41 @@ import org.apache.commons.rdf.jsonldjava.JsonLdRDFTermFactory;
import org.apache.commons.rdf.rdf4j.RDF4JTermFactory;
import org.apache.commons.rdf.simple.SimpleRDFTermFactory;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+@RunWith(Parameterized.class)
public class AllToAllTest {
- private RDFTermFactory simpleFactory = new SimpleRDFTermFactory();
- private RDFTermFactory jenaFactory = new JenaRDFTermFactory();
- private RDFTermFactory rdf4jFactory = new RDF4JTermFactory();
- private RDFTermFactory jsonldFactory = new JsonLdRDFTermFactory();
+ private RDFTermFactory nodeFactory;
+ private RDFTermFactory graphFactory;
- @Test
- public void jenaToRdf4j() throws Exception {
- addTermsFromOtherFactory(jenaFactory, rdf4jFactory);
- addTriplesFromOtherFactory(jenaFactory, rdf4jFactory);
- }
- @Test
- public void jenaToJsonLd() throws Exception {
- addTermsFromOtherFactory(jenaFactory, jsonldFactory);
- addTriplesFromOtherFactory( jenaFactory, jsonldFactory );
- }
- @Test
- public void jenaToSimple() throws Exception {
- addTermsFromOtherFactory(jenaFactory, simpleFactory);
- addTriplesFromOtherFactory( jenaFactory, simpleFactory );
- }
-
- @Test
- public void rdf4jToJena() throws Exception {
- addTermsFromOtherFactory(rdf4jFactory, jenaFactory);
- addTriplesFromOtherFactory( rdf4jFactory, jenaFactory );
- }
- @Test
- public void rdf4jToJsonLd() throws Exception {
- addTermsFromOtherFactory(rdf4jFactory, jsonldFactory);
- addTriplesFromOtherFactory( rdf4jFactory, jenaFactory );
- }
- @Test
- public void rdf4jToSimple() throws Exception {
- addTermsFromOtherFactory(rdf4jFactory, simpleFactory);
- addTriplesFromOtherFactory(rdf4jFactory, simpleFactory );
+
+ public AllToAllTest(
+ Class<? extends RDFTermFactory> from,
+ Class<? extends RDFTermFactory> to) throws InstantiationException, IllegalAccessException {
+ this.nodeFactory = from.newInstance();
+ this.graphFactory = to.newInstance();
}
- @Test
- public void simpletoJena() throws Exception {
- addTermsFromOtherFactory(simpleFactory, jenaFactory);
- addTriplesFromOtherFactory( simpleFactory, jenaFactory);
- }
- @Test
- public void simpleToJsonLd() throws Exception {
- addTermsFromOtherFactory(simpleFactory, jsonldFactory);
- addTriplesFromOtherFactory( simpleFactory, jsonldFactory );
- }
- @Test
- public void simpleToRdf4j() throws Exception {
- addTermsFromOtherFactory(simpleFactory, rdf4jFactory);
- addTriplesFromOtherFactory( simpleFactory, rdf4jFactory );
+ @Parameters(name = "{index}: {0}->{1}")
+ public static Collection<Object[]> data() {
+ List<Class> factories = Arrays.asList(
+ SimpleRDFTermFactory.class,
+ JenaRDFTermFactory.class,
+ RDF4JTermFactory.class,
+ JsonLdRDFTermFactory.class);
+ Collection<Object[]> allToAll = new ArrayList<>();
+ for (Class from : factories) {
+ for (Class to : factories) {
+ allToAll.add(new Object[]{from, to});
+ }
+ }
+ return allToAll;
}
- /**
+ /**
* This test creates a {@link Graph} with the first
* {@link RDFTermFactory}, then inserts/queries with
* triples using {@link RDFTerm}s created with the second factory.
@@ -80,7 +63,8 @@ public class AllToAllTest {
* @param graphFactory Factory to create {@link Graph}
* @throws Exception
*/
- public void addTermsFromOtherFactory(RDFTermFactory nodeFactory, RDFTermFactory graphFactory) throws Exception {
+ @Test
+ public void addTermsFromOtherFactory() throws Exception {
Graph g = graphFactory.createGraph();
BlankNode s = nodeFactory.createBlankNode();
IRI p = nodeFactory.createIRI("http://example.com/p");
@@ -127,7 +111,8 @@ public class AllToAllTest {
* @param graphFactory Factory to create {@link Graph}
* @throws Exception
*/
- public void addTriplesFromOtherFactory(RDFTermFactory nodeFactory, RDFTermFactory graphFactory) throws Exception {
+ @Test
+ public void addTriplesFromOtherFactory() throws Exception {
Graph g = graphFactory.createGraph();
BlankNode s = nodeFactory.createBlankNode();
IRI p = nodeFactory.createIRI("http://example.com/p");
[38/50] [abbrv] 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/489ed917
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/489ed917
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/489ed917
Branch: refs/heads/COMMONSRDF-46
Commit: 489ed91795a423453e6a2919728d976d4cdec9d2
Parents: 28e38ca eb391f8
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Thu Sep 29 01:10:31 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Thu Sep 29 01:10:31 2016 +0100
----------------------------------------------------------------------
.../commons/rdf/jena/JenaRDFTermFactory.java | 20 ++++++++++++++++----
.../commons/rdf/jena/impl/JenaFactory.java | 5 ++---
pom.xml | 6 ++++++
3 files changed, 24 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/489ed917/pom.xml
----------------------------------------------------------------------
[06/50] [abbrv] 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/3f88d29d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/3f88d29d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/3f88d29d
Branch: refs/heads/COMMONSRDF-46
Commit: 3f88d29dc5e63f6fdb7c7d18196bf486258c1857
Parents: e5e85bd fa5580c
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Sep 9 17:20:55 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Sep 9 17:20:55 2016 +0100
----------------------------------------------------------------------
.../rdf/jsonldjava/JsonLdParserBuilderTest.java | 40 ++++++++++++--------
1 file changed, 25 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
[14/50] [abbrv] 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/485a7eb5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/485a7eb5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/485a7eb5
Branch: refs/heads/COMMONSRDF-46
Commit: 485a7eb5e545b9163f362adca89841644c8d44e5
Parents: 60864de 0928ddb
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Tue Sep 13 00:12:44 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Tue Sep 13 00:12:44 2016 +0100
----------------------------------------------------------------------
.../rdf/jsonldjava/JsonLdRDFTermFactory.java | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
[09/50] [abbrv] incubator-commonsrdf git commit:
addTermsFromOtherFactory
Posted by st...@apache.org.
addTermsFromOtherFactory
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/b8ff697a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/b8ff697a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/b8ff697a
Branch: refs/heads/COMMONSRDF-46
Commit: b8ff697a9bab3804ac59d7764c26ab76fda4ba23
Parents: 1828c2a
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Sep 9 17:42:27 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Sep 9 17:44:30 2016 +0100
----------------------------------------------------------------------
.../rdf/integrationtests/AllToAllTest.java | 46 ++++++++++++--------
1 file changed, 29 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/b8ff697a/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
----------------------------------------------------------------------
diff --git a/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java b/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
index a8cd1cd..b9ea397 100644
--- a/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
+++ b/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
@@ -7,6 +7,7 @@ import org.apache.commons.rdf.api.BlankNode;
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.RDFTerm;
import org.apache.commons.rdf.api.RDFTermFactory;
import org.apache.commons.rdf.api.Triple;
import org.apache.commons.rdf.jena.JenaRDFTermFactory;
@@ -24,48 +25,57 @@ public class AllToAllTest {
@Test
public void jenaToRdf4j() throws Exception {
- nodesIntoOther(jenaFactory, rdf4jFactory);
+ addTermsFromOtherFactory(jenaFactory, rdf4jFactory);
}
@Test
public void jenaToJsonLd() throws Exception {
- nodesIntoOther(jenaFactory, jsonldFactory);
+ addTermsFromOtherFactory(jenaFactory, jsonldFactory);
}
@Test
public void jenaToSimple() throws Exception {
- nodesIntoOther(jenaFactory, simpleFactory);
+ addTermsFromOtherFactory(jenaFactory, simpleFactory);
}
@Test
public void rdf4jToJena() throws Exception {
- nodesIntoOther(rdf4jFactory, jenaFactory);
+ addTermsFromOtherFactory(rdf4jFactory, jenaFactory);
}
@Test
public void rdf4jToJsonLd() throws Exception {
- nodesIntoOther(rdf4jFactory, jsonldFactory);
+ addTermsFromOtherFactory(rdf4jFactory, jsonldFactory);
}
@Test
public void rdf4jToSimple() throws Exception {
- nodesIntoOther(rdf4jFactory, simpleFactory);
+ addTermsFromOtherFactory(rdf4jFactory, simpleFactory);
}
@Test
public void simpletoJena() throws Exception {
- nodesIntoOther(simpleFactory, jenaFactory);
+ addTermsFromOtherFactory(simpleFactory, jenaFactory);
}
@Test
public void simpleToJsonLd() throws Exception {
- nodesIntoOther(simpleFactory, jsonldFactory);
+ addTermsFromOtherFactory(simpleFactory, jsonldFactory);
}
@Test
public void simpleToRdf4j() throws Exception {
- nodesIntoOther(simpleFactory, rdf4jFactory);
+ addTermsFromOtherFactory(simpleFactory, rdf4jFactory);
}
- public void nodesIntoOther(RDFTermFactory fromFactory, RDFTermFactory toFactory) throws Exception {
- Graph g = fromFactory.createGraph();
- BlankNode s = toFactory.createBlankNode();
- IRI p = toFactory.createIRI("http://example.com/p");
- Literal o = toFactory.createLiteral("Hello");
+ /**
+ * This test creates a {@link Graph} with the first
+ * {@link RDFTermFactory}, then inserts/queries with
+ * triples using {@link RDFTerm}s created with the second factory.
+ *
+ * @param graphFactory Factory to create {@link Graph}
+ * @param nodeFactory
+ * @throws Exception
+ */
+ public void addTermsFromOtherFactory(RDFTermFactory nodeFactory, RDFTermFactory graphFactory) throws Exception {
+ Graph g = graphFactory.createGraph();
+ BlankNode s = nodeFactory.createBlankNode();
+ IRI p = nodeFactory.createIRI("http://example.com/p");
+ Literal o = nodeFactory.createLiteral("Hello");
g.add(s, p, o);
@@ -73,12 +83,14 @@ public class AllToAllTest {
assertTrue(g.contains(s, p, o));
Triple t1 = g.stream().findAny().get();
- // Can't make assumptions about mappegetPredicated BlankNode equality
+ // Can't make assumptions about BlankNode equality - it might
+ // have been mapped to a different BlankNode.uniqueReference()
// assertEquals(s, t.getSubject());
+
assertEquals(p, t1.getPredicate());
assertEquals(o, t1.getObject());
- IRI s2 = toFactory.createIRI("http://example.com/s2");
+ IRI s2 = nodeFactory.createIRI("http://example.com/s2");
g.add(s2, p, s);
assertTrue(g.contains(s2, p, s));
@@ -94,6 +106,6 @@ public class AllToAllTest {
assertEquals(bnode, t1.getSubject());
// And can be used as a key:
Triple t3 = g.stream(bnode, p, null).findAny().get();
- assertEquals(t1, t3);
+ assertEquals(t1, t3);
}
}
[04/50] [abbrv] incubator-commonsrdf git commit: also depend on
jsonld-java
Posted by st...@apache.org.
also depend on 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/5ed73ac6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/5ed73ac6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/5ed73ac6
Branch: refs/heads/COMMONSRDF-46
Commit: 5ed73ac6e8c18f7c319bfb73b598d75adb2d3332
Parents: 5a49f96
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Sep 9 16:43:43 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Sep 9 16:43:43 2016 +0100
----------------------------------------------------------------------
integration-tests/pom.xml | 79 +++++++++++++++++++++++-------------------
1 file changed, 43 insertions(+), 36 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/5ed73ac6/integration-tests/pom.xml
----------------------------------------------------------------------
diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml
index 71fd66b..7ddab6b 100644
--- a/integration-tests/pom.xml
+++ b/integration-tests/pom.xml
@@ -27,42 +27,49 @@
<version>0.3.0-incubating-SNAPSHOT</version>
</parent>
<artifactId>commons-rdf-integration-tests</artifactId>
+ <name>Commons RDF: Integration tests</name>
<dependencies>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>commons-rdf-api</artifactId>
- <version>${project.version}</version>
- </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>commons-rdf-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>commons-rdf-simple</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>commons-rdf-rdf4j</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>commons-rdf-jena</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <!-- NOTE: This might be quite version-sensitive (including transitives)
+ as both rdf4j and jena depend on jsonld -->
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>commons-rdf-jsonld</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>commons-rdf-api</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>commons-rdf-simple</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>commons-rdf-rdf4j</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>commons-rdf-jena</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>commons-rdf-api</artifactId>
- <version>${project.version}</version>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
-
-</dependencies>
-
- <name>Commons RDF: Integration tests</name>
</project>
[39/50] [abbrv] 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/c991d056
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/c991d056
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/c991d056
Branch: refs/heads/COMMONSRDF-46
Commit: c991d0562e21ecc49ddb607ec308f3a5b7e13bed
Parents: 489ed91 c763ffa
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Thu Sep 29 01:14:05 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Thu Sep 29 01:14:05 2016 +0100
----------------------------------------------------------------------
.../java/org/apache/commons/rdf/jena/JenaRDFTermFactory.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
[46/50] [abbrv] incubator-commonsrdf git commit: remove duplicate
junit dependency
Posted by st...@apache.org.
remove duplicate junit dependency
.. now in parent pom.xml
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/13464e28
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/13464e28
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/13464e28
Branch: refs/heads/COMMONSRDF-46
Commit: 13464e2858ac394d783d782a94449d478741bcd6
Parents: b54b5c6
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Oct 26 11:45:36 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Oct 26 11:45:36 2016 +0100
----------------------------------------------------------------------
api/pom.xml | 7 -------
simple/pom.xml | 5 -----
2 files changed, 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/13464e28/api/pom.xml
----------------------------------------------------------------------
diff --git a/api/pom.xml b/api/pom.xml
index 14278d6..f3090c7 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -33,13 +33,6 @@
<name>Commons RDF: API</name>
<description>Commons Java API for RDF 1.1</description>
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
<build>
<plugins>
<plugin>
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/13464e28/simple/pom.xml
----------------------------------------------------------------------
diff --git a/simple/pom.xml b/simple/pom.xml
index bc8a861..8e0ad57 100644
--- a/simple/pom.xml
+++ b/simple/pom.xml
@@ -46,10 +46,5 @@
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
</dependencies>
</project>
[26/50] [abbrv] incubator-commonsrdf git commit:
AbstractRDFParserTest moved to ...experimental
Posted by st...@apache.org.
AbstractRDFParserTest moved to ...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/74196bdd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/74196bdd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/74196bdd
Branch: refs/heads/COMMONSRDF-46
Commit: 74196bdd363983648860e98e59888ce552e95933
Parents: c3c1719
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Tue Sep 27 18:46:25 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Tue Sep 27 18:46:25 2016 +0100
----------------------------------------------------------------------
.../simple/AbstractRDFParserBuilderTest.java | 254 ------------------
.../experimental/AbstractRDFParserTest.java | 256 +++++++++++++++++++
2 files changed, 256 insertions(+), 254 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/74196bdd/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 f115e94..0000000
--- a/simple/src/test/java/org/apache/commons/rdf/simple/AbstractRDFParserBuilderTest.java
+++ /dev/null
@@ -1,254 +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.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.experimental.AbstractRDFParser;
-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, 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"));
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/74196bdd/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"));
+ }
+
+
+}
[49/50] [abbrv] incubator-commonsrdf git commit: Avoid
ConcurrentModification
Posted by st...@apache.org.
Avoid ConcurrentModification
(can't modify graph while streaming it)
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/2a5dbf9f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/2a5dbf9f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/2a5dbf9f
Branch: refs/heads/COMMONSRDF-46
Commit: 2a5dbf9ff0633f1f7f518ef1431d53e21831281f
Parents: 5c190d2
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Oct 26 12:35:00 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Oct 26 12:35:00 2016 +0100
----------------------------------------------------------------------
.../apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java | 5 -----
1 file changed, 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/2a5dbf9f/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
----------------------------------------------------------------------
diff --git a/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java b/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
index 393bc8f..728bba2 100644
--- a/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
+++ b/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
@@ -130,11 +130,6 @@ public class TestJenaGraphToCommonsRDFGraph {
System.out.println("\n==== Write Jena graph directly\n") ;
RDFDataMgr.write(System.out, jGraph, Lang.TTL) ;
}
-
- // Can stream modify the jGraph? Let's try to remove..
- assertFalse(jGraph.isEmpty());
- graph.stream().forEach(graph::remove);
- assertTrue(jGraph.isEmpty());
}
}
[40/50] [abbrv] incubator-commonsrdf git commit: only
needed for -Prelease
Posted by st...@apache.org.
<finalName> only needed for -Prelease
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/5f6bcff7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/5f6bcff7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/5f6bcff7
Branch: refs/heads/COMMONSRDF-46
Commit: 5f6bcff7f28d8936523fc98cbe26c4433194f39a
Parents: 351c296
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Sun Oct 23 03:19:04 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Sun Oct 23 03:19:04 2016 +0100
----------------------------------------------------------------------
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/5f6bcff7/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 72563be..1c5d354 100644
--- a/pom.xml
+++ b/pom.xml
@@ -235,7 +235,6 @@
</dependencyManagement>
<build>
- <finalName>apache-commonsrdf-${project.version}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@@ -562,6 +561,7 @@
<id>release</id>
<!-- extends the release profile from commons -->
<build>
+ <finalName>apache-commonsrdf-${project.version}</finalName>
<plugins>
<!-- Generate convenience *.md5 *.sha1 files for dist puropses -->
<plugin>
[35/50] [abbrv] 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/8296419a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/8296419a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/8296419a
Branch: refs/heads/COMMONSRDF-46
Commit: 8296419afd9705b23dbbf938d199ec927714c7bb
Parents: 9bfc39f 11a6a33
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Sep 28 23:33:23 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Sep 28 23:33:23 2016 +0100
----------------------------------------------------------------------
.../apache/commons/rdf/jsonldjava/JsonLdGraphLike.java | 8 ++++++--
.../apache/commons/rdf/jsonldjava/JsonLdUnionGraph.java | 2 +-
.../rdf/jsonldjava/experimental/package-info.java | 12 ++++++------
.../commons/rdf/jsonldjava/JsonLdBlankNodeTest.java | 1 -
4 files changed, 13 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
[10/50] [abbrv] incubator-commonsrdf git commit: Also test adding
Triple instances
Posted by st...@apache.org.
Also test adding Triple instances
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/112505df
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/112505df
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/112505df
Branch: refs/heads/COMMONSRDF-46
Commit: 112505dfe488889b1ad16dca1120bd6c59ae8075
Parents: b8ff697
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Mon Sep 12 18:59:33 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Mon Sep 12 18:59:33 2016 +0100
----------------------------------------------------------------------
.../rdf/integrationtests/AllToAllTest.java | 64 +++++++++++++++++++-
1 file changed, 63 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/112505df/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
----------------------------------------------------------------------
diff --git a/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java b/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
index b9ea397..0d65f05 100644
--- a/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
+++ b/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
@@ -26,40 +26,49 @@ public class AllToAllTest {
@Test
public void jenaToRdf4j() throws Exception {
addTermsFromOtherFactory(jenaFactory, rdf4jFactory);
+ addTriplesFromOtherFactory(jenaFactory, rdf4jFactory);
}
@Test
public void jenaToJsonLd() throws Exception {
addTermsFromOtherFactory(jenaFactory, jsonldFactory);
+ addTriplesFromOtherFactory( jenaFactory, jsonldFactory );
}
@Test
public void jenaToSimple() throws Exception {
addTermsFromOtherFactory(jenaFactory, simpleFactory);
+ addTriplesFromOtherFactory( jenaFactory, simpleFactory );
}
@Test
public void rdf4jToJena() throws Exception {
addTermsFromOtherFactory(rdf4jFactory, jenaFactory);
+ addTriplesFromOtherFactory( rdf4jFactory, jenaFactory );
}
@Test
public void rdf4jToJsonLd() throws Exception {
addTermsFromOtherFactory(rdf4jFactory, jsonldFactory);
+ addTriplesFromOtherFactory( rdf4jFactory, jenaFactory );
}
@Test
public void rdf4jToSimple() throws Exception {
addTermsFromOtherFactory(rdf4jFactory, simpleFactory);
+ addTriplesFromOtherFactory(rdf4jFactory, simpleFactory );
}
@Test
public void simpletoJena() throws Exception {
addTermsFromOtherFactory(simpleFactory, jenaFactory);
+ addTriplesFromOtherFactory( simpleFactory, jenaFactory);
}
@Test
public void simpleToJsonLd() throws Exception {
addTermsFromOtherFactory(simpleFactory, jsonldFactory);
+ addTriplesFromOtherFactory( simpleFactory, jsonldFactory );
}
@Test
public void simpleToRdf4j() throws Exception {
addTermsFromOtherFactory(simpleFactory, rdf4jFactory);
+ addTriplesFromOtherFactory( simpleFactory, rdf4jFactory );
}
/**
@@ -67,8 +76,8 @@ public class AllToAllTest {
* {@link RDFTermFactory}, then inserts/queries with
* triples using {@link RDFTerm}s created with the second factory.
*
+ * @param nodeFactory Factory to create {@link RDFTerm} instances
* @param graphFactory Factory to create {@link Graph}
- * @param nodeFactory
* @throws Exception
*/
public void addTermsFromOtherFactory(RDFTermFactory nodeFactory, RDFTermFactory graphFactory) throws Exception {
@@ -108,4 +117,57 @@ public class AllToAllTest {
Triple t3 = g.stream(bnode, p, null).findAny().get();
assertEquals(t1, t3);
}
+
+
+ /**
+ * This is a variation of {@link #addTermsFromOtherFactory(RDFTermFactory, RDFTermFactory)},
+ * but here {@link Triple} is created in the "foreign" nodeFactory before adding to the graph.
+ *
+ * @param nodeFactory Factory to create {@link RDFTerm} and {@link Triple}s
+ * @param graphFactory Factory to create {@link Graph}
+ * @throws Exception
+ */
+ public void addTriplesFromOtherFactory(RDFTermFactory nodeFactory, RDFTermFactory graphFactory) throws Exception {
+ Graph g = graphFactory.createGraph();
+ BlankNode s = nodeFactory.createBlankNode();
+ IRI p = nodeFactory.createIRI("http://example.com/p");
+ Literal o = nodeFactory.createLiteral("Hello");
+
+ Triple srcT1 = nodeFactory.createTriple(s, p, o);
+ // This should work even with BlankNode as they are from the same factory
+ assertEquals(s, srcT1.getSubject());
+ assertEquals(p, srcT1.getPredicate());
+ assertEquals(o, srcT1.getObject());
+ g.add(srcT1);
+
+ // what about the blankNode within?
+ assertTrue(g.contains(srcT1));
+ Triple t1 = g.stream().findAny().get();
+
+ // Can't make assumptions about BlankNode equality - it might
+ // have been mapped to a different BlankNode.uniqueReference()
+ //assertEquals(srcT1, t1);
+ //assertEquals(s, t1.getSubject());
+ assertEquals(p, t1.getPredicate());
+ assertEquals(o, t1.getObject());
+
+ IRI s2 = nodeFactory.createIRI("http://example.com/s2");
+ Triple srcT2 = nodeFactory.createTriple(s2, p, s);
+ g.add(srcT2);
+ assertTrue(g.contains(srcT2));
+
+ // This should be mapped to the same BlankNode
+ // (even if it has a different identifier), e.g.
+ // we should be able to do:
+
+ Triple t2 = g.stream(s2, p, null).findAny().get();
+
+ BlankNode bnode = (BlankNode) t2.getObject();
+ // And that (possibly adapted) BlankNode object should
+ // match the subject of t1 statement
+ assertEquals(bnode, t1.getSubject());
+ // And can be used as a key:
+ Triple t3 = g.stream(bnode, p, null).findAny().get();
+ assertEquals(t1, t3);
+ }
}
[19/50] [abbrv] incubator-commonsrdf git commit: comment on all to all
Posted by st...@apache.org.
comment on all to all
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/8a26fe8f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/8a26fe8f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/8a26fe8f
Branch: refs/heads/COMMONSRDF-46
Commit: 8a26fe8ff3e989ad0c808f95ad7670b9a2e91303
Parents: 92eb91a
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Sep 23 17:58:17 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Sep 23 17:58:17 2016 +0100
----------------------------------------------------------------------
.../java/org/apache/commons/rdf/integrationtests/AllToAllTest.java | 2 ++
1 file changed, 2 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/8a26fe8f/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
----------------------------------------------------------------------
diff --git a/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java b/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
index b0b4f3b..3edf6e4 100644
--- a/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
+++ b/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
@@ -48,6 +48,8 @@ public class AllToAllTest {
Collection<Object[]> allToAll = new ArrayList<>();
for (Class from : factories) {
for (Class to : factories) {
+ // NOTE: we deliberately include self-to-self here
+ // to test two instances of the same implementation
allToAll.add(new Object[]{from, to});
}
}
[15/50] [abbrv] incubator-commonsrdf git commit: No need for another
.gitignore
Posted by st...@apache.org.
No need for another .gitignore
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/0c58bd8e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/0c58bd8e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/0c58bd8e
Branch: refs/heads/COMMONSRDF-46
Commit: 0c58bd8e594d9ecebc5e9d3d71cad8cb96d68b92
Parents: 485a7eb
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Tue Sep 13 00:39:21 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Tue Sep 13 00:39:21 2016 +0100
----------------------------------------------------------------------
jsonld-java/.gitignore | 1 -
1 file changed, 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/0c58bd8e/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/