You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by st...@apache.org on 2018/02/28 23:54:55 UTC

[1/9] commons-rdf git commit: Remove experimental.RDFParser

Repository: commons-rdf
Updated Branches:
  refs/heads/fluent-parser-impl [created] d850d8f43


Remove experimental.RDFParser

dummy Jena parser


Project: http://git-wip-us.apache.org/repos/asf/commons-rdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rdf/commit/9be11eda
Tree: http://git-wip-us.apache.org/repos/asf/commons-rdf/tree/9be11eda
Diff: http://git-wip-us.apache.org/repos/asf/commons-rdf/diff/9be11eda

Branch: refs/heads/fluent-parser-impl
Commit: 9be11eda7bd669ca1a81758493fefd47a64de81b
Parents: 01e6c91
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Tue Feb 20 16:05:40 2018 +0000
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Tue Feb 27 16:33:00 2018 +0000

----------------------------------------------------------------------
 .../commons/rdf/experimental/RDFParser.java     | 485 -------------------
 .../commons/rdf/experimental/package-info.java  |  33 --
 .../apache/commons/rdf/jena/JenaRDFParser.java  |  69 +++
 3 files changed, 69 insertions(+), 518 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/9be11eda/commons-rdf-api/src/main/java/org/apache/commons/rdf/experimental/RDFParser.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/experimental/RDFParser.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/experimental/RDFParser.java
deleted file mode 100644
index d5da0d9..0000000
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/experimental/RDFParser.java
+++ /dev/null
@@ -1,485 +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.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.RDF;
-import org.apache.commons.rdf.api.Triple;
-
-/**
- * Parse an RDF source into a target (e.g. a Graph/Dataset).
- * <h2>Experimental</h2> This interface (and its implementations) should be
- * considered <strong>at risk</strong>; they might change or be removed in the
- * next minor update of Commons RDF. It may move to the the
- * {@link org.apache.commons.rdf.api} package when it has stabilized.
- * <h2>Description</h2>
- * <p>
- * This interface follows the
- * <a href="https://en.wikipedia.org/wiki/Builder_pattern">Builder pattern</a>,
- * allowing to set parser settings like {@link #contentType(RDFSyntax)} and
- * {@link #base(IRI)}. A caller MUST call one of the <code>source</code> methods
- * (e.g. {@link #source(IRI)}, {@link #source(Path)},
- * {@link #source(InputStream)}), and MUST call one of the <code>target</code>
- * methods (e.g. {@link #target(Consumer)}, {@link #target(Dataset)},
- * {@link #target(Graph)}) before calling {@link #parse()} on the returned
- * RDFParser - however methods can be called in any order.
- * <p>
- * The call to {@link #parse()} returns a {@link Future}, allowing asynchronous
- * parse operations. Callers are recommended to check {@link Future#get()} to
- * ensure parsing completed successfully, or catch exceptions thrown during
- * parsing.
- * <p>
- * Setting a method that has already been set will override any existing value
- * in the returned builder - regardless of the parameter type (e.g.
- * {@link #source(IRI)} will override a previous {@link #source(Path)}. Settings
- * can be unset by passing <code>null</code> - note that this may require
- * casting, e.g. <code>contentType( (RDFSyntax) null )</code> to undo a previous
- * call to {@link #contentType(RDFSyntax)}.
- * <p>
- * It is undefined if a RDFParser is mutable or thread-safe, so callers should
- * always use the returned modified RDFParser from the builder methods. The
- * builder may return itself after modification, or a cloned builder with the
- * modified settings applied. Implementations are however encouraged to be
- * immutable, thread-safe and document this. As an example starting point, see
- * <code>org.apache.commons.rdf.simple.AbstractRDFParser</code>.
- * <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.
-     */
-    interface ParseResult {
-    }
-
-    /**
-     * Specify which {@link RDF} 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 RDF} for multiple
-     * {@link #parse()} calls may accidentally merge {@link BlankNode}s having
-     * the same label, as the parser may use the
-     * {@link RDF#createBlankNode(String)} method from the parsed blank node
-     * labels.
-     *
-     * @see #target(Graph)
-     * @param rdfTermFactory
-     *            {@link RDF} to use for generating RDFTerms.
-     * @return An {@link RDFParser} that will use the specified rdfTermFactory
-     */
-    RDFParser rdfTermFactory(RDF 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. {@code <?xml version="1.0" encoding="iso-8859-1"?>} 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(final 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(final 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>
-     * {@code
-     * List<Quad> quads = new ArrayList<Quad>;
-     * parserBuilder.target(quads::add).parse();
-     * }
-     * </pre>
-     *
-     * @param consumer
-     *            A {@link Consumer} of {@link Quad}s
-     * @return An {@link RDFParser} that will call the consumer for into the
-     *         specified dataset.
-     */
-    RDFParser target(Consumer<Quad> consumer);
-
-    /**
-     * Specify a base IRI to use for parsing any relative IRI references.
-     * <p>
-     * Setting this option will override any protocol-specific base IRI (e.g.
-     * <code>Content-Location</code> header) or the {@link #source(IRI)} IRI,
-     * but does not override any base IRIs set within the source document (e.g.
-     * <code>@base</code> in Turtle documents).
-     * <p>
-     * If the source is in a syntax that does not support relative IRI
-     * references (e.g. {@link RDFSyntax#NTRIPLES}), setting the
-     * <code>base</code> has no effect.
-     * <p>
-     * This method will override any base IRI set with {@link #base(String)}.
-     *
-     * @see #base(String)
-     * @param base
-     *            An absolute IRI to use as a base.
-     * @return An {@link RDFParser} that will use the specified base IRI.
-     */
-    RDFParser base(IRI base);
-
-    /**
-     * Specify a base IRI to use for parsing any relative IRI references.
-     * <p>
-     * Setting this option will override any protocol-specific base IRI (e.g.
-     * <code>Content-Location</code> header) or the {@link #source(IRI)} IRI,
-     * but does not override any base IRIs set within the source document (e.g.
-     * <code>@base</code> in Turtle documents).
-     * <p>
-     * If the source is in a syntax that does not support relative IRI
-     * references (e.g. {@link RDFSyntax#NTRIPLES}), setting the
-     * <code>base</code> has no effect.
-     * <p>
-     * This method will override any base IRI set with {@link #base(IRI)}.
-     *
-     * @see #base(IRI)
-     * @param base
-     *            An absolute IRI to use as a base.
-     * @return An {@link RDFParser} that will use the specified base IRI.
-     * @throws IllegalArgumentException
-     *             If the base is not a valid absolute IRI string
-     */
-    RDFParser base(String base) throws IllegalArgumentException;
-
-    /**
-     * Specify a source {@link InputStream} to parse.
-     * <p>
-     * The source set will not be read before the call to {@link #parse()}.
-     * <p>
-     * The InputStream will not be closed after parsing. The InputStream does
-     * not need to support {@link InputStream#markSupported()}.
-     * <p>
-     * The parser might not consume the complete stream (e.g. an RDF/XML parser
-     * may not read beyond the closing tag of
-     * <code>&lt;/rdf:Description&gt;</code>).
-     * <p>
-     * The {@link #contentType(RDFSyntax)} or {@link #contentType(String)}
-     * SHOULD be set before calling {@link #parse()}.
-     * <p>
-     * The character set is assumed to be {@link StandardCharsets#UTF_8} unless
-     * the {@link #contentType(String)} specifies otherwise or the document
-     * declares its own charset (e.g. RDF/XML with a
-     * <code>&lt;?xml encoding="iso-8859-1"&gt;</code> header).
-     * <p>
-     * The {@link #base(IRI)} or {@link #base(String)} MUST be set before
-     * calling {@link #parse()}, unless the RDF syntax does not permit relative
-     * IRIs (e.g. {@link RDFSyntax#NTRIPLES}).
-     * <p>
-     * This method will override any source set with {@link #source(IRI)},
-     * {@link #source(Path)} or {@link #source(String)}.
-     *
-     * @param inputStream
-     *            An InputStream to consume
-     * @return An {@link RDFParser} that will use the specified source.
-     */
-    RDFParser source(InputStream inputStream);
-
-    /**
-     * Specify a source file {@link Path} to parse.
-     * <p>
-     * The source set will not be read before the call to {@link #parse()}.
-     * <p>
-     * The {@link #contentType(RDFSyntax)} or {@link #contentType(String)}
-     * SHOULD be set before calling {@link #parse()}.
-     * <p>
-     * The character set is assumed to be {@link StandardCharsets#UTF_8} unless
-     * the {@link #contentType(String)} specifies otherwise or the document
-     * declares its own charset (e.g. RDF/XML with a
-     * <code>&lt;?xml encoding="iso-8859-1"&gt;</code> header).
-     * <p>
-     * The {@link #base(IRI)} or {@link #base(String)} MAY be set before calling
-     * {@link #parse()}, otherwise {@link Path#toUri()} will be used as the base
-     * IRI.
-     * <p>
-     * This method will override any source set with {@link #source(IRI)},
-     * {@link #source(InputStream)} or {@link #source(String)}.
-     *
-     * @param file
-     *            A Path for a file to parse
-     * @return An {@link RDFParser} that will use the specified source.
-     */
-    RDFParser source(Path file);
-
-    /**
-     * Specify an absolute source {@link IRI} to retrieve and parse.
-     * <p>
-     * The source set will not be read before the call to {@link #parse()}.
-     * <p>
-     * If this builder does not support the given IRI protocol (e.g.
-     * <code>urn:uuid:ce667463-c5ab-4c23-9b64-701d055c4890</code>), this method
-     * should succeed, while the {@link #parse()} should throw an
-     * {@link IOException}.
-     * <p>
-     * The {@link #contentType(RDFSyntax)} or {@link #contentType(String)} MAY
-     * be set before calling {@link #parse()}, in which case that type MAY be
-     * used for content negotiation (e.g. <code>Accept</code> header in HTTP),
-     * and SHOULD be used for selecting the RDFSyntax.
-     * <p>
-     * The character set is assumed to be {@link StandardCharsets#UTF_8} unless
-     * the protocol's equivalent of <code>Content-Type</code> specifies
-     * otherwise or the document declares its own charset (e.g. RDF/XML with a
-     * <code>&lt;?xml encoding="iso-8859-1"&gt;</code> header).
-     * <p>
-     * The {@link #base(IRI)} or {@link #base(String)} MAY be set before calling
-     * {@link #parse()}, otherwise the source IRI will be used as the base IRI.
-     * <p>
-     * This method will override any source set with {@link #source(Path)},
-     * {@link #source(InputStream)} or {@link #source(String)}.
-     *
-     * @param iri
-     *            An IRI to retrieve and parse
-     * @return An {@link RDFParser} that will use the specified source.
-     */
-    RDFParser source(IRI iri);
-
-    /**
-     * Specify an absolute source IRI to retrieve and parse.
-     * <p>
-     * The source set will not be read before the call to {@link #parse()}.
-     * <p>
-     * If this builder does not support the given IRI (e.g.
-     * <code>urn:uuid:ce667463-c5ab-4c23-9b64-701d055c4890</code>), this method
-     * should succeed, while the {@link #parse()} should throw an
-     * {@link IOException}.
-     * <p>
-     * The {@link #contentType(RDFSyntax)} or {@link #contentType(String)} MAY
-     * be set before calling {@link #parse()}, in which case that type MAY be
-     * used for content negotiation (e.g. <code>Accept</code> header in HTTP),
-     * and SHOULD be used for selecting the RDFSyntax.
-     * <p>
-     * The character set is assumed to be {@link StandardCharsets#UTF_8} unless
-     * the protocol's equivalent of <code>Content-Type</code> specifies
-     * otherwise or the document declares its own charset (e.g. RDF/XML with a
-     * <code>&lt;?xml encoding="iso-8859-1"&gt;</code> header).
-     * <p>
-     * The {@link #base(IRI)} or {@link #base(String)} MAY be set before calling
-     * {@link #parse()}, otherwise the source IRI will be used as the base IRI.
-     * <p>
-     * This method will override any source set with {@link #source(Path)},
-     * {@link #source(InputStream)} or {@link #source(IRI)}.
-     *
-     * @param iri
-     *            An IRI to retrieve and parse
-     * @return An {@link RDFParser} that will use the specified source.
-     * @throws IllegalArgumentException
-     *             If the base is not a valid absolute IRI string
-     *
-     */
-    RDFParser source(String iri) throws IllegalArgumentException;
-
-    /**
-     * Parse the specified source.
-     * <p>
-     * A source method (e.g. {@link #source(InputStream)}, {@link #source(IRI)},
-     * {@link #source(Path)}, {@link #source(String)} or an equivalent subclass
-     * method) MUST have been called before calling this method, otherwise an
-     * {@link IllegalStateException} will be thrown.
-     * <p>
-     * A target method (e.g. {@link #target(Consumer)},
-     * {@link #target(Dataset)}, {@link #target(Graph)} or an equivalent
-     * subclass method) MUST have been called before calling parse(), otherwise
-     * an {@link IllegalStateException} will be thrown.
-     * <p>
-     * It is undefined if this method is thread-safe, however the
-     * {@link RDFParser} may be reused (e.g. setting a different source) as soon
-     * as the {@link Future} has been returned from this method.
-     * <p>
-     * The RDFParser SHOULD perform the parsing as an asynchronous operation,
-     * and return the {@link Future} as soon as preliminary checks (such as
-     * validity of the {@link #source(IRI)} and {@link #contentType(RDFSyntax)}
-     * settings) have finished. The future SHOULD not mark
-     * {@link Future#isDone()} before parsing is complete. A synchronous
-     * implementation MAY be blocking on the <code>parse()</code> call and
-     * return a Future that is already {@link Future#isDone()}.
-     * <p>
-     * The returned {@link Future} contains a {@link ParseResult}.
-     * Implementations may subclass this interface to provide any parser
-     * details, e.g. list of warnings. <code>null</code> is a possible return
-     * value if no details are available, but parsing succeeded.
-     * <p>
-     * If an exception occurs during parsing, (e.g. {@link IOException} or
-     * <code>org.apache.commons.rdf.simple.experimental.RDFParseException</code>),
-     * 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/commons-rdf/blob/9be11eda/commons-rdf-api/src/main/java/org/apache/commons/rdf/experimental/package-info.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/experimental/package-info.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/experimental/package-info.java
deleted file mode 100644
index 4d9edfd..0000000
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/experimental/package-info.java
+++ /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.
- */
-/**
- * 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.
- * <ul>
- * <li>{@link org.apache.commons.rdf.experimental.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/commons-rdf/blob/9be11eda/commons-rdf-jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFParser.java
----------------------------------------------------------------------
diff --git a/commons-rdf-jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFParser.java b/commons-rdf-jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFParser.java
new file mode 100644
index 0000000..f00e43e
--- /dev/null
+++ b/commons-rdf-jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFParser.java
@@ -0,0 +1,69 @@
+/*
+ * 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.function.Consumer;
+
+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.TripleLike;
+import org.apache.commons.rdf.api.io.Parsed;
+import org.apache.commons.rdf.api.io.Parser;
+import org.apache.commons.rdf.api.io.ParserConfig;
+
+public class JenaRDFParser implements Parser {
+
+    private Consumer<TripleLike> generalizedConsumerTriple;
+    private Consumer<QuadLike<RDFTerm>> generalizedConsumerQuad;
+
+	public JenaRDFParser() {
+	}
+
+	@Override
+	public Parsed parse(ParserConfig config) {
+		if (! config.source().isPresent()) {
+			throw new IllegalStateException("No source target configured");
+		}
+		if (! config.target().isPresent()) {
+			throw new IllegalStateException("No parse target configured");
+		}
+		if (! config.syntax().isPresent() && ! config.source().get().iri().isPresent()) {
+			throw new IllegalStateException("Can't guess syntax when source has no iri");			
+		}		
+		if (syntaxNeedsBase(config) && 
+				! config.base().isPresent() && 
+				! config.source().get().iri().isPresent()) {			
+			throw new IllegalStateException("Can't guess syntax when source has no iri");			
+		}
+		
+		
+		
+	}
+
+	private boolean syntaxNeedsBase(ParserConfig config) {
+		if (! config.syntax().isPresent()) {
+			// guessing without source iri already covered
+			return false;
+		}
+		RDFSyntax s = config.syntax().get();
+		// If it's not Ntriples or Nquads, then we need base URI
+		return ! (s.equals(RDFSyntax.NTRIPLES) || s.equals(RDFSyntax.NQUADS));
+	}
+
+}
+ 
\ No newline at end of file


[6/9] commons-rdf git commit: Return optional.empty() for unknown RDFSyntaxes

Posted by st...@apache.org.
Return optional.empty() for unknown RDFSyntaxes


Project: http://git-wip-us.apache.org/repos/asf/commons-rdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rdf/commit/a793fc29
Tree: http://git-wip-us.apache.org/repos/asf/commons-rdf/tree/a793fc29
Diff: http://git-wip-us.apache.org/repos/asf/commons-rdf/diff/a793fc29

Branch: refs/heads/fluent-parser-impl
Commit: a793fc2918dd4a6d476edd82e7987c9b8455261e
Parents: e87a831
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Feb 28 23:44:29 2018 +0000
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Feb 28 23:44:29 2018 +0000

----------------------------------------------------------------------
 .../src/main/java/org/apache/commons/rdf/jena/JenaRDF.java        | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/a793fc29/commons-rdf-jena/src/main/java/org/apache/commons/rdf/jena/JenaRDF.java
----------------------------------------------------------------------
diff --git a/commons-rdf-jena/src/main/java/org/apache/commons/rdf/jena/JenaRDF.java b/commons-rdf-jena/src/main/java/org/apache/commons/rdf/jena/JenaRDF.java
index 30ead8c..2f37789 100644
--- a/commons-rdf-jena/src/main/java/org/apache/commons/rdf/jena/JenaRDF.java
+++ b/commons-rdf-jena/src/main/java/org/apache/commons/rdf/jena/JenaRDF.java
@@ -835,6 +835,9 @@ public final class JenaRDF implements RDF {
     
     @Override
     public Optional<Parser> parser(RDFSyntax syntax) {
+    	if (syntax != null && ! asJenaLang(syntax).isPresent()) {
+    		return Optional.empty();
+    	}    	
     	return Optional.of(new JenaParser(syntax));
     }
 


[7/9] commons-rdf git commit: Avoid duplicate JenaRDFParser

Posted by st...@apache.org.
Avoid duplicate JenaRDFParser


Project: http://git-wip-us.apache.org/repos/asf/commons-rdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rdf/commit/d33b803b
Tree: http://git-wip-us.apache.org/repos/asf/commons-rdf/tree/d33b803b
Diff: http://git-wip-us.apache.org/repos/asf/commons-rdf/diff/d33b803b

Branch: refs/heads/fluent-parser-impl
Commit: d33b803bfe3dcb3a347b5aa5b2a522f90a9cd0cf
Parents: a793fc2
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Feb 28 23:44:47 2018 +0000
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Feb 28 23:44:47 2018 +0000

----------------------------------------------------------------------
 .../apache/commons/rdf/jena/JenaRDFParser.java  | 69 --------------------
 1 file changed, 69 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/d33b803b/commons-rdf-jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFParser.java
----------------------------------------------------------------------
diff --git a/commons-rdf-jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFParser.java b/commons-rdf-jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFParser.java
deleted file mode 100644
index f00e43e..0000000
--- a/commons-rdf-jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFParser.java
+++ /dev/null
@@ -1,69 +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.util.function.Consumer;
-
-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.TripleLike;
-import org.apache.commons.rdf.api.io.Parsed;
-import org.apache.commons.rdf.api.io.Parser;
-import org.apache.commons.rdf.api.io.ParserConfig;
-
-public class JenaRDFParser implements Parser {
-
-    private Consumer<TripleLike> generalizedConsumerTriple;
-    private Consumer<QuadLike<RDFTerm>> generalizedConsumerQuad;
-
-	public JenaRDFParser() {
-	}
-
-	@Override
-	public Parsed parse(ParserConfig config) {
-		if (! config.source().isPresent()) {
-			throw new IllegalStateException("No source target configured");
-		}
-		if (! config.target().isPresent()) {
-			throw new IllegalStateException("No parse target configured");
-		}
-		if (! config.syntax().isPresent() && ! config.source().get().iri().isPresent()) {
-			throw new IllegalStateException("Can't guess syntax when source has no iri");			
-		}		
-		if (syntaxNeedsBase(config) && 
-				! config.base().isPresent() && 
-				! config.source().get().iri().isPresent()) {			
-			throw new IllegalStateException("Can't guess syntax when source has no iri");			
-		}
-		
-		
-		
-	}
-
-	private boolean syntaxNeedsBase(ParserConfig config) {
-		if (! config.syntax().isPresent()) {
-			// guessing without source iri already covered
-			return false;
-		}
-		RDFSyntax s = config.syntax().get();
-		// If it's not Ntriples or Nquads, then we need base URI
-		return ! (s.equals(RDFSyntax.NTRIPLES) || s.equals(RDFSyntax.NQUADS));
-	}
-
-}
- 
\ No newline at end of file


[3/9] commons-rdf git commit: ImmutableParserConfig with* returns new ImmutableParserConfigs

Posted by st...@apache.org.
ImmutableParserConfig with* returns new ImmutableParserConfigs


Project: http://git-wip-us.apache.org/repos/asf/commons-rdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rdf/commit/db99ef1f
Tree: http://git-wip-us.apache.org/repos/asf/commons-rdf/tree/db99ef1f
Diff: http://git-wip-us.apache.org/repos/asf/commons-rdf/diff/db99ef1f

Branch: refs/heads/fluent-parser-impl
Commit: db99ef1fc9ae1621aa46245145d5618066f53665
Parents: 1125dd8
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Feb 28 23:39:10 2018 +0000
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Feb 28 23:39:10 2018 +0000

----------------------------------------------------------------------
 .../rdf/api/io/ImmutableParserConfigImpl.java       | 14 +++++++-------
 .../org/apache/commons/rdf/api/io/ParserConfig.java | 16 +++++++++++++++-
 2 files changed, 22 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/db99ef1f/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ImmutableParserConfigImpl.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ImmutableParserConfigImpl.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ImmutableParserConfigImpl.java
index 25be678..8f6561a 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ImmutableParserConfigImpl.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ImmutableParserConfigImpl.java
@@ -69,34 +69,34 @@ class ImmutableParserConfigImpl implements ImmutableParserConfig, Serializable {
 	}
 
 	@Override
-	public ParserConfig withSyntax(RDFSyntax syntax) {
+	public ImmutableParserConfig withSyntax(RDFSyntax syntax) {
 		return new WithSyntax(this, syntax);
 	}
 
 	@SuppressWarnings("rawtypes")
 	@Override
-	public ParserConfig withSource(ParserSource source) {
+	public ImmutableParserConfig withSource(ParserSource source) {
 		return new WithSource(this, source);
 	}
 
 	@SuppressWarnings("rawtypes")
 	@Override
-	public ParserConfig withTarget(ParserTarget target) {
+	public ImmutableParserConfig withTarget(ParserTarget target) {
 		return new WithTarget(this, target);
 	}
 
 	@Override
-	public ParserConfig withRDF(RDF rdf) {
+	public ImmutableParserConfig withRDF(RDF rdf) {
 		return new WithRDF(this, rdf);
 	}
 
 	@Override
-	public ParserConfig withBase(IRI base) {
+	public ImmutableParserConfig withBase(IRI base) {
 		return new WithBase(this, base);
 	}
 
 	@Override
-	public <V> ParserConfig withOption(Option<V> o, V v) {
+	public <V> ImmutableParserConfig withOption(Option<V> o, V v) {
 		return new WithOption(this, o, v);
 	}
 
@@ -115,7 +115,7 @@ class ImmutableParserConfigImpl implements ImmutableParserConfig, Serializable {
 		@Override
 		public Map<Option, Object> options() {
 			// Add to parent options
-			Map options = super.options();
+			Map<Option, Object> options = super.options();
 			if (v == null) {
 				options.remove(o);
 			} else {

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/db99ef1f/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserConfig.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserConfig.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserConfig.java
index 50aa0ae..ece4f48 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserConfig.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserConfig.java
@@ -70,6 +70,20 @@ public interface ParserConfig {
 		}
 	}
 	
-	interface ImmutableParserConfig extends ParserConfig, Serializable {} 
+	interface ImmutableParserConfig extends ParserConfig, Serializable {
+		ImmutableParserConfig withSyntax(RDFSyntax syntax);
+
+		ImmutableParserConfig withSource(ParserSource source);
+
+		ImmutableParserConfig withTarget(ParserTarget target);
+
+		ImmutableParserConfig withRDF(RDF rdf);
+
+		ImmutableParserConfig withBase(IRI base);
+
+		<V> ImmutableParserConfig withOption(Option<V> o, V v);	
+		
+		
+	} 
 
 }


[8/9] commons-rdf git commit: commons-rdf-simple now only needed for tests in jena

Posted by st...@apache.org.
commons-rdf-simple now only needed for tests in jena


Project: http://git-wip-us.apache.org/repos/asf/commons-rdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rdf/commit/3789bad5
Tree: http://git-wip-us.apache.org/repos/asf/commons-rdf/tree/3789bad5
Diff: http://git-wip-us.apache.org/repos/asf/commons-rdf/diff/3789bad5

Branch: refs/heads/fluent-parser-impl
Commit: 3789bad539aa630a8eccb99c1778ffffe0da65ea
Parents: d33b803
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Feb 28 23:54:17 2018 +0000
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Feb 28 23:54:17 2018 +0000

----------------------------------------------------------------------
 commons-rdf-jena/pom.xml | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/3789bad5/commons-rdf-jena/pom.xml
----------------------------------------------------------------------
diff --git a/commons-rdf-jena/pom.xml b/commons-rdf-jena/pom.xml
index bf7df56..e7dfdff 100644
--- a/commons-rdf-jena/pom.xml
+++ b/commons-rdf-jena/pom.xml
@@ -50,6 +50,7 @@
 			<groupId>${project.parent.groupId}</groupId>
 			<artifactId>commons-rdf-simple</artifactId>
 			<version>${project.version}</version>
+			<scope>test</scope>
 		</dependency>
 		<!-- Uncomment below and disable jena-osgi to access the regular non-osgi 
 			 Jena dependencies (e.g. for debugging) -->


[2/9] commons-rdf git commit: JenaParser implementation

Posted by st...@apache.org.
JenaParser implementation


Project: http://git-wip-us.apache.org/repos/asf/commons-rdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rdf/commit/1125dd8d
Tree: http://git-wip-us.apache.org/repos/asf/commons-rdf/tree/1125dd8d
Diff: http://git-wip-us.apache.org/repos/asf/commons-rdf/diff/1125dd8d

Branch: refs/heads/fluent-parser-impl
Commit: 1125dd8dda8c3de1cddfa6b0d8c85ef3d0dba4f6
Parents: 9be11ed
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Feb 28 23:38:19 2018 +0000
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Feb 28 23:38:19 2018 +0000

----------------------------------------------------------------------
 .../org/apache/commons/rdf/jena/JenaRDF.java    |   7 +
 .../rdf/jena/experimental/JenaRDFParser.java    | 106 ---------------
 .../rdf/jena/experimental/package-info.java     |  31 -----
 .../commons/rdf/jena/impl/JenaParser.java       | 135 +++++++++++++++++++
 4 files changed, 142 insertions(+), 137 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/1125dd8d/commons-rdf-jena/src/main/java/org/apache/commons/rdf/jena/JenaRDF.java
----------------------------------------------------------------------
diff --git a/commons-rdf-jena/src/main/java/org/apache/commons/rdf/jena/JenaRDF.java b/commons-rdf-jena/src/main/java/org/apache/commons/rdf/jena/JenaRDF.java
index 62327a8..30ead8c 100644
--- a/commons-rdf-jena/src/main/java/org/apache/commons/rdf/jena/JenaRDF.java
+++ b/commons-rdf-jena/src/main/java/org/apache/commons/rdf/jena/JenaRDF.java
@@ -34,7 +34,9 @@ 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.api.io.Parser;
 import org.apache.commons.rdf.jena.impl.InternalJenaFactory;
+import org.apache.commons.rdf.jena.impl.JenaParser;
 import org.apache.jena.datatypes.RDFDatatype;
 import org.apache.jena.datatypes.xsd.XSDDatatype;
 import org.apache.jena.graph.Node;
@@ -830,5 +832,10 @@ public final class JenaRDF implements RDF {
     public UUID salt() {
         return salt;
     }
+    
+    @Override
+    public Optional<Parser> parser(RDFSyntax syntax) {
+    	return Optional.of(new JenaParser(syntax));
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/1125dd8d/commons-rdf-jena/src/main/java/org/apache/commons/rdf/jena/experimental/JenaRDFParser.java
----------------------------------------------------------------------
diff --git a/commons-rdf-jena/src/main/java/org/apache/commons/rdf/jena/experimental/JenaRDFParser.java b/commons-rdf-jena/src/main/java/org/apache/commons/rdf/jena/experimental/JenaRDFParser.java
deleted file mode 100644
index 2513e82..0000000
--- a/commons-rdf-jena/src/main/java/org/apache/commons/rdf/jena/experimental/JenaRDFParser.java
+++ /dev/null
@@ -1,106 +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.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.RDF;
-import org.apache.commons.rdf.api.RDFTerm;
-import org.apache.commons.rdf.api.TripleLike;
-import org.apache.commons.rdf.jena.JenaGraph;
-import org.apache.commons.rdf.jena.JenaRDF;
-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.RDFParser;
-import org.apache.jena.riot.system.StreamRDF;
-import org.apache.jena.riot.system.StreamRDFLib;
-
-public class JenaRDFParser extends AbstractRDFParser<JenaRDFParser> {
-
-    private Consumer<TripleLike> generalizedConsumerTriple;
-    private Consumer<QuadLike<RDFTerm>> generalizedConsumerQuad;
-
-    @Override
-    protected RDF createRDFTermFactory() {
-        return new JenaRDF();
-    }
-
-    public JenaRDFParser targetGeneralizedTriple(final Consumer<TripleLike> consumer) {
-        final JenaRDFParser c = this.clone();
-        c.resetTarget();
-        c.generalizedConsumerTriple = consumer;
-        return c;
-    }
-
-    public JenaRDFParser targetGeneralizedQuad(final Consumer<QuadLike<RDFTerm>> consumer) {
-        final 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;
-        final JenaRDF jenaRDF = getJenaFactory();
-        if (getTargetGraph().isPresent() && getTargetGraph().get() instanceof JenaGraph) {
-            final Graph jenaGraph = ((JenaGraph) getTargetGraph().get()).asJenaGraph();
-            dest = StreamRDFLib.graph(jenaGraph);
-        } else {
-            if (generalizedConsumerQuad != null) {
-                dest = jenaRDF.streamJenaToGeneralizedQuad(generalizedConsumerQuad);
-            } else if (generalizedConsumerTriple != null) {
-                dest = jenaRDF.streamJenaToGeneralizedTriple(generalizedConsumerTriple);
-            } else {
-                dest = JenaRDF.streamJenaToQuad(getRdfTermFactory().get(), getTarget());
-            }
-        }
-
-        final Lang lang = getContentTypeSyntax().flatMap(jenaRDF::asJenaLang).orElse(null);
-        final String baseStr = getBase().map(IRI::getIRIString).orElse(null);
-
-        if (getSourceIri().isPresent()) {
-        	    RDFParser.source(getSourceIri().get().toString()).base(baseStr).lang(lang).parse(dest);
-        } else if (getSourceFile().isPresent()) {
-            try (InputStream s = Files.newInputStream(getSourceFile().get())) {
-            	    RDFParser.source(s).base(baseStr).lang(lang).parse(dest);
-            }
-        } else {
-            RDFParser.source(getSourceInputStream().get()).base(baseStr).lang(lang).parse(dest);
-        }
-    }
-
-    private JenaRDF getJenaFactory() {
-        return (JenaRDF) getRdfTermFactory().filter(JenaRDF.class::isInstance).orElseGet(this::createRDFTermFactory);
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/1125dd8d/commons-rdf-jena/src/main/java/org/apache/commons/rdf/jena/experimental/package-info.java
----------------------------------------------------------------------
diff --git a/commons-rdf-jena/src/main/java/org/apache/commons/rdf/jena/experimental/package-info.java b/commons-rdf-jena/src/main/java/org/apache/commons/rdf/jena/experimental/package-info.java
deleted file mode 100644
index 83252b0..0000000
--- a/commons-rdf-jena/src/main/java/org/apache/commons/rdf/jena/experimental/package-info.java
+++ /dev/null
@@ -1,31 +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.
- */
-/**
- * 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.
- * <ul>
- * <li>{@link org.apache.commons.rdf.jena.experimental.JenaRDFParser} - a Jena-backed implementations of
- * {@link org.apache.commons.rdf.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/commons-rdf/blob/1125dd8d/commons-rdf-jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaParser.java
----------------------------------------------------------------------
diff --git a/commons-rdf-jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaParser.java b/commons-rdf-jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaParser.java
new file mode 100644
index 0000000..6952083
--- /dev/null
+++ b/commons-rdf-jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaParser.java
@@ -0,0 +1,135 @@
+/*
+ * 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.IOException;
+import java.nio.file.Path;
+
+import org.apache.commons.rdf.api.Dataset;
+import org.apache.commons.rdf.api.IRI;
+import org.apache.commons.rdf.api.RDF;
+import org.apache.commons.rdf.api.RDFSyntax;
+import org.apache.commons.rdf.api.io.Parsed;
+import org.apache.commons.rdf.api.io.Parser;
+import org.apache.commons.rdf.api.io.ParserConfig;
+import org.apache.commons.rdf.api.io.ParserConfig.ImmutableParserConfig;
+import org.apache.commons.rdf.api.io.ParserSource;
+import org.apache.commons.rdf.api.io.ParserTarget;
+import org.apache.commons.rdf.jena.JenaDataset;
+import org.apache.commons.rdf.jena.JenaGraph;
+import org.apache.commons.rdf.jena.JenaRDF;
+import org.apache.jena.riot.RDFParser;
+import org.apache.jena.riot.RDFParserBuilder;
+
+public class JenaParser implements Parser {
+
+	private final RDFSyntax defaultSyntax;
+
+	public JenaParser() {
+		defaultSyntax = null; // unspecified/guess
+	}
+
+	public JenaParser(RDFSyntax syntax) {
+		this.defaultSyntax = syntax;
+	}
+
+	@SuppressWarnings("rawtypes")
+	@Override
+	public Parsed parse(ParserConfig config) throws IOException {
+		return parseImpl(completeConfig(config));
+	}
+
+	private ImmutableParserConfig completeConfig(ParserConfig config) {
+		ImmutableParserConfig completed = config.asImmutableConfig();
+		if (!completed.source().isPresent()) {
+			throw new IllegalStateException("source missing from ParserConfig");
+		}
+
+		if (!completed.syntax().isPresent()) {
+			// Might still be null
+			completed = completed.withSyntax(defaultSyntax);
+		}
+		if (!completed.rdf().isPresent()) {
+			completed = completed.withRDF(new JenaRDF());
+		}
+		RDF rdf = completed.rdf().get();
+		if (!completed.target().isPresent()) {
+			Dataset ds = rdf.createDataset();
+			completed = completed.withTarget(ParserTarget.toDataset(ds));
+		}
+		ParserSource<?> source = completed.source().get();
+		if (!completed.base().isPresent() && source.iri().isPresent()) {
+			// Use base from source.iri() - but only if it's from a source
+			// type Jena does not recognize
+			Object src = source.src();
+			if (!(src instanceof IRI) && !(src instanceof Path)) {
+				completed = completed.withBase(source.iri().get());
+			}
+		}
+		return completed;
+	}
+
+	@SuppressWarnings("rawtypes")
+	private Parsed parseImpl(ImmutableParserConfig config) throws IOException {
+		RDF rdf = config.rdf().get();
+		JenaRDF jenaRDF = jenaRDF(rdf);
+		ParserSource<?> source = config.source().get();
+		ParserTarget<?> target = config.target().get();
+		RDFParserBuilder jenaParser = RDFParser.create();
+
+		config.base().map(IRI::getIRIString).map(jenaParser::base);		
+		config.syntax().flatMap(jenaRDF::asJenaLang).map(jenaParser::lang);
+		
+		// Handle jena-supported sources first
+		if (source.src() instanceof Path) {
+			Path path = (Path) source.src();
+			jenaParser.source(path);
+		} else if (source.src() instanceof IRI) {
+			IRI iri = (IRI) source.src();
+			jenaParser.source(iri.getIRIString());
+		} else if (source.src() instanceof String) {
+			jenaParser.fromString(source.src().toString());
+		} else {
+			// This fallback should always work
+			jenaParser.source(source.inputStream());
+		}
+		
+		// Handle jena implementations firsts
+		if (target.dest() instanceof JenaDataset) {
+			JenaDataset jenaDataset = (JenaDataset) target.dest();
+			jenaParser.parse(jenaDataset.asJenaDatasetGraph());
+		} else if (target.dest() instanceof JenaGraph) { 
+			JenaGraph jenaGraph = (JenaGraph) target.dest();
+			jenaParser.parse(jenaGraph.asJenaGraph());
+		} else {
+			// General approach, stream to Quads
+			jenaParser.parse(JenaRDF.streamJenaToQuad(rdf, target));
+		}
+		
+		// Parsing finished
+		return Parsed.from(source, target);
+	}
+
+	private JenaRDF jenaRDF(RDF rdf) {
+		if (rdf instanceof JenaRDF) { 
+			return (JenaRDF) rdf;
+		} else {
+			return new JenaRDF();
+		}
+	}
+
+}


[5/9] commons-rdf git commit: parse() might throw IOException!

Posted by st...@apache.org.
parse() might throw IOException!


Project: http://git-wip-us.apache.org/repos/asf/commons-rdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rdf/commit/e87a831e
Tree: http://git-wip-us.apache.org/repos/asf/commons-rdf/tree/e87a831e
Diff: http://git-wip-us.apache.org/repos/asf/commons-rdf/diff/e87a831e

Branch: refs/heads/fluent-parser-impl
Commit: e87a831e0cd34d627781b90badb3e5603c1f35bd
Parents: 9124270
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Feb 28 23:40:06 2018 +0000
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Feb 28 23:40:51 2018 +0000

----------------------------------------------------------------------
 .../main/java/org/apache/commons/rdf/api/fluentparser/Sync.java | 4 +++-
 .../src/main/java/org/apache/commons/rdf/api/io/Parser.java     | 5 +++--
 .../java/org/apache/commons/rdf/api/io/ParserConfigBuilder.java | 3 ++-
 3 files changed, 8 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/e87a831e/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/Sync.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/Sync.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/Sync.java
index a5b4462..2ae36f3 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/Sync.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/fluentparser/Sync.java
@@ -17,6 +17,8 @@
  */
 package org.apache.commons.rdf.api.fluentparser;
 
+import java.io.IOException;
+
 import org.apache.commons.rdf.api.io.Option;
 import org.apache.commons.rdf.api.io.Parsed;
 
@@ -26,5 +28,5 @@ public interface Sync<T, S> extends Buildable {
 	<V> Sync<T, S> option(Option<V> option, V value);
 	
     Async<T, S> async();
-    Parsed<T, S> parse();
+    Parsed<T, S> parse() throws IOException;
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/e87a831e/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/Parser.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/Parser.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/Parser.java
index a1040f2..5a39dc0 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/Parser.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/Parser.java
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.rdf.api.io;
 
+import java.io.IOException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
@@ -23,7 +24,7 @@ import java.util.concurrent.Future;
 public interface Parser {
 
 	@SuppressWarnings("rawtypes")
-	Parsed parse(ParserConfig config);
+	Parsed parse(ParserConfig config) throws IOException;
 
 	@SuppressWarnings("rawtypes")
 	default Future<Parsed> parseAsync(ParserConfig config) {
@@ -43,7 +44,7 @@ public interface Parser {
 			this.config = config.asImmutableConfig();
 		}
 		
-		Parsed parse() {
+		Parsed parse() throws IOException {
 			return syncParser.parse(config);			
 		}
 

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/e87a831e/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserConfigBuilder.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserConfigBuilder.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserConfigBuilder.java
index 6f7ecf3..8a47986 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserConfigBuilder.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/ParserConfigBuilder.java
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.rdf.api.io;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.nio.file.Path;
 import java.util.Optional;
@@ -116,7 +117,7 @@ public final class ParserConfigBuilder implements ParserBuilder, NeedTargetOrRDF
 	}
 
 	@Override
-	public Parsed parse() {
+	public Parsed parse() throws IOException {
 		ImmutableParserConfig c = config.asImmutableConfig();
 		Parser parser = getParserOrFail(c);
 		return parser.parse(c);


[9/9] commons-rdf git commit: Update example to new fluent API

Posted by st...@apache.org.
Update example to new fluent API


Project: http://git-wip-us.apache.org/repos/asf/commons-rdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rdf/commit/d850d8f4
Tree: http://git-wip-us.apache.org/repos/asf/commons-rdf/tree/d850d8f4
Diff: http://git-wip-us.apache.org/repos/asf/commons-rdf/diff/d850d8f4

Branch: refs/heads/fluent-parser-impl
Commit: d850d8f43fe985e6f8e4ecaaabe0454753f7bee6
Parents: 3789bad
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Feb 28 23:54:33 2018 +0000
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Feb 28 23:54:33 2018 +0000

----------------------------------------------------------------------
 .../commons/rdf/jena/TestRDFParserBuilder.java     | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/d850d8f4/commons-rdf-jena/src/test/java/org/apache/commons/rdf/jena/TestRDFParserBuilder.java
----------------------------------------------------------------------
diff --git a/commons-rdf-jena/src/test/java/org/apache/commons/rdf/jena/TestRDFParserBuilder.java b/commons-rdf-jena/src/test/java/org/apache/commons/rdf/jena/TestRDFParserBuilder.java
index b0c552f..2b71d88 100644
--- a/commons-rdf-jena/src/test/java/org/apache/commons/rdf/jena/TestRDFParserBuilder.java
+++ b/commons-rdf-jena/src/test/java/org/apache/commons/rdf/jena/TestRDFParserBuilder.java
@@ -29,14 +29,15 @@ import java.util.concurrent.TimeUnit;
 
 import org.apache.commons.rdf.api.Graph;
 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.apache.commons.rdf.api.io.Parsed;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
 public class TestRDFParserBuilder {
 
+	JenaRDF jenaRDF = new JenaRDF();
+	
     private Path turtleFile;
 
     @Before
@@ -54,9 +55,15 @@ public class TestRDFParserBuilder {
 
     @Test
     public void parseTurtle() throws Exception {
-        try (final Graph g = new JenaRDF().createGraph()) {
-            final Future<ParseResult> gFuture = new JenaRDFParser().contentType(RDFSyntax.TURTLE).source(turtleFile)
-                    .target(g).parse();
+        
+		try (final Graph g = jenaRDF.createGraph()) {
+			Future<Parsed<Graph, Path>> gFuture = jenaRDF.parserBuilder()
+					.syntax(RDFSyntax.TURTLE)
+					.target(g)
+					.source(turtleFile)
+					.async()
+					.parseAsync();					
+					
             gFuture.get(5, TimeUnit.SECONDS);
             assertEquals(3, g.size());
         }


[4/9] commons-rdf git commit: Parsed() drops count()

Posted by st...@apache.org.
Parsed() drops count()

adds a bean implementation


Project: http://git-wip-us.apache.org/repos/asf/commons-rdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rdf/commit/91242705
Tree: http://git-wip-us.apache.org/repos/asf/commons-rdf/tree/91242705
Diff: http://git-wip-us.apache.org/repos/asf/commons-rdf/diff/91242705

Branch: refs/heads/fluent-parser-impl
Commit: 912427059e1932ae614ec9c6ffd5c4e18298c78c
Parents: db99ef1
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Feb 28 23:39:29 2018 +0000
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Feb 28 23:39:29 2018 +0000

----------------------------------------------------------------------
 .../org/apache/commons/rdf/api/io/Parsed.java   | 36 +++++++++++++++++---
 1 file changed, 31 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/91242705/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/Parsed.java
----------------------------------------------------------------------
diff --git a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/Parsed.java b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/Parsed.java
index b252e44..12640dc 100644
--- a/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/Parsed.java
+++ b/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/io/Parsed.java
@@ -17,10 +17,36 @@
  */
 package org.apache.commons.rdf.api.io;
 
-public interface Parsed<T, S> {
-    long count();
+public interface Parsed<S, T> {
 
-    ParserSource<S> from();
+	ParserSource<S> from();
 
-    ParserTarget<T> into();
-}
\ No newline at end of file
+	ParserTarget<T> into();
+
+	@SuppressWarnings({ "unchecked", "rawtypes" })
+	public static <S, T> Parsed<S, T> from(
+			final ParserSource<S> from, 
+			final ParserTarget<T> into) {
+		return new ParsedImpl(from, into);
+	}
+}
+
+class ParsedImpl<S, T> implements Parsed<S, T> {
+	private ParserSource<S> from;
+	private ParserTarget<T> into;
+
+	ParsedImpl(final ParserSource<S> from, final ParserTarget<T> into) {
+		this.from = from;
+		this.into = into;
+	}
+
+	@Override
+	public ParserSource<S> from() {
+		return from;
+	}
+
+	@Override
+	public ParserTarget<T> into() {
+		return into;
+	}
+}