null
for the
* default graph
* @param subject
* The quad subject
* @param predicate
* The quad predicate
* @param object
* The quad object
*/
void add(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
/**
* Check if dataset contains quad.
*
* @param quad
* The quad to check.
* @return True if the dataset contains the given Quad.
*/
@Override
boolean contains(Quad quad);
/**
* Check if dataset contains a pattern of quads.
*
* @param graphName
* The graph the quad belongs to, wrapped as an {@link Optional}
* (null
is a wildcard, {@link Optional#empty()} is
* the default graph)
* @param subject
* The quad subject (null
is a wildcard)
* @param predicate
* The quad predicate (null
is a wildcard)
* @param object
* The quad object (null
is a wildcard)
* @return True if the dataset contains any quads that match the given
* pattern.
*/
boolean contains(Optional* For example, this would close any open file and network streams and free * database locks held by the dataset implementation. *
* The behaviour of the other dataset methods are undefined after closing * the dataset. *
* Implementations might not need {@link #close()}, hence the default * implementation does nothing. */ @Override default void close() throws Exception { } /** * Get the default graph of this dataset. *
* The {@link Triple}s of the default graph are equivalent to the * {@link Quad}s in this Dataset which has the {@link Quad#getGraphName()} * set to {@link Optional#empty()}. *
* It is unspecified if modifications to the returned Graph are reflected in * this Dataset. *
* The returned graph MAY be empty. * * @see #getGraph(BlankNodeOrIRI) * @return The default graph of this Dataset */ Graph getGraph(); /** * Get a named graph in this dataset. *
* The {@link Triple}s of the named graph are equivalent to the the Quads of
* this Dataset which has the {@link Quad#getGraphName()} equal to the
* provided graphName
, or equal to {@link Optional#empty()} if
* the provided graphName
is null
.
*
* It is unspecified if modifications to the returned Graph are reflected in * this Dataset. *
* It is unspecified if requesting an unknown or empty graph will return
* {@link Optional#empty()} or create a new empty {@link Graph}.
*
* @see #getGraph()
* @see #getGraphNames()
* @param graphName
* The name of the graph, or
* The set of returned graph names is equivalent to the set of unique
* {@link Quad#getGraphName()} of all the {@link #stream()} of this dataset
* (excluding the default graph).
*
* The returned {@link Stream} SHOULD NOT contain duplicate graph names.
*
* The graph names can be used with {@link #getGraph(BlankNodeOrIRI)} to
* retrieve the corresponding {@link Graph}, however callers should be aware
* of any concurrent modifications to the Dataset may cause such calls to
* return {@link Optional#empty()}.
*
* Note that a Dataset always contains a default graph
* which is not named, and thus is not represented in the returned Stream.
* The default graph is accessible via {@link #getGraph()} or by using
* {@link Optional#empty()} in the Quad access methods).
*
* @return A {@link Stream} of the graph names of this Dataset.
*/
Stream
* The count of a set does not include duplicates, consistent with the
* {@link Quad#equals(Object)} equals method for each {@link Quad}.
*
* @return The number of quads in the dataset
*/
@Override
long size();
/**
* Get all quads contained by the dataset.
* The iteration does not contain any duplicate quads, as determined by the
* {@link Quad#equals(Object)} method for each {@link Quad}.
*
* The behaviour of the {@link Stream} is not specified if
* {@link #add(Quad)}, {@link #remove(Quad)} or {@link #clear()} are called
* on the {@link Dataset} before it terminates.
*
* Implementations may throw {@link ConcurrentModificationException} from
* Stream methods if they detect a conflict while the Stream is active.
*
* @return A {@link Stream} over all of the quads in the dataset
*/
@Override
Stream extends Quad> stream();
/**
* Get all quads contained by the dataset matched with the pattern.
*
* The iteration does not contain any duplicate quads, as determined by the
* {@link Quad#equals(Object)} method for each {@link Quad}.
*
* The behaviour of the {@link Stream} is not specified if
* {@link #add(Quad)}, {@link #remove(Quad)} or {@link #clear()} are called
* on the {@link Dataset} before it terminates.
*
* Implementations may throw {@link ConcurrentModificationException} from
* Stream methods if they detect a conflict while the Stream is active.
*
* @param graphName
* The graph the quad belongs to, wrapped as an {@link Optional}
* (
* This method is meant to be used with a Java for-each loop, e.g.:
*
*
* Implementations may throw {@link ConcurrentModificationException} from
* Iterator methods if they detect a concurrency conflict while the Iterator
* is active.
*
* The {@link Iterable#iterator()} must only be called once, that is the
* Iterable must only be iterated over once. A {@link IllegalStateException}
* may be thrown on attempt to reuse the Iterable.
*
* The default implementation of this method will call {@link #stream()} to
* return its {@link Stream#iterator()}.
*
* @return A {@link Iterable} that returns {@link Iterator} over all of the
* quads in the dataset
* @throws IllegalStateException
* if the {@link Iterable} has been reused
* @throws ConcurrentModificationException
* if a concurrency conflict occurs while the Iterator is
* active.
*/
@Override
@SuppressWarnings("unchecked")
default Iterable
* This method is meant to be used with a Java for-each loop, e.g.:
*
*
* The behaviour of the iterator is not specified if {@link #add(Quad)},
* {@link #remove(Quad)} or {@link #clear()}, are called on the
* {@link Dataset} before it terminates. It is undefined if the returned
* {@link Iterator} supports the {@link Iterator#remove()} method.
*
* Implementations may throw {@link ConcurrentModificationException} from
* Iterator methods if they detect a concurrency conflict while the Iterator
* is active.
*
* The {@link Iterable#iterator()} must only be called once, that is the
* Iterable must only be iterated over once. A {@link IllegalStateException}
* may be thrown on attempt to reuse the Iterable.
*
* The default implementation of this method will call
* {@link #stream(Optional, BlankNodeOrIRI, IRI, RDFTerm)} to return its
* {@link Stream#iterator()}.
*
* @param graphName
* The graph the quad belongs to, wrapped as an {@link Optional}
* (
* The core RDF 1.1 concepts
* are represented by corresponding interfaces:
*
* A {@link org.apache.commons.rdf.api.Graph} is a collection of
* {@link org.apache.commons.rdf.api.Triple}s, which have a subject,
* predicate and object of
* {@link org.apache.commons.rdf.api.RDFTerm}s. The three types of RDF terms are
* {@link org.apache.commons.rdf.api.IRI},
* {@link org.apache.commons.rdf.api.Literal} and
* {@link org.apache.commons.rdf.api.BlankNode}.
*
* Implementations of this API should provide an
* {@link org.apache.commons.rdf.api.RDF} to facilitate creation of these
* objects.
*
* All the {@link org.apache.commons.rdf.api.RDFTerm} objects are immutable,
* while a {@link org.apache.commons.rdf.api.Graph} MAY be mutable (e.g. support
* methods like {@link org.apache.commons.rdf.api.Graph#add(Triple)}).
*
* {@link org.apache.commons.rdf.api.RDFSyntax} enumerates the W3C standard RDF
* 1.1 syntaxes and their media types.
*
* For further documentation and contact details, see the
* Commons RDF web site.
*
*/
package org.apache.commons.rdf.api;
apache-commons-rdf-0.5.0/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/QuadLike.java 0000644 0001750 0001750 00000004467 13175733174 032101 0 ustar andrius andrius /**
* 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.util.Optional;
/**
* A generalised "quad-like" interface, extended by {@link Quad}.
*
* A QuadLike statement has at least a {@link #getSubject()},
* {@link #getPredicate()}, {@link #getObject()} and {@link #getGraphName()},
* but unlike a {@link Quad} does not have a formalised
* {@link Quad#equals(Object)} or {@link Quad#hashCode()} semantics and is not
* required to be immutable or thread-safe. This interface can
* also be used for generalised quads (e.g. a {@link BlankNode} as
* predicate).
*
* Implementations should specialise which specific {@link RDFTerm} types they
* return by overriding {@link #getSubject()}, {@link #getPredicate()},
* {@link #getObject()} and {@link #getGraphName()}.
*
* @since 0.3.0-incubating
* @see Quad
*/
public interface QuadLike
* If {@link Optional#isPresent()}, then the {@link Optional#get()} indicate
* the graph name of this statement. If the graph name is not present,e.g.
* the value is {@link Optional#empty()}, it indicates that this Quad is in
* the default graph.
*
* @return If {@link Optional#isPresent()}, the graph name of this quad,
* otherwise {@link Optional#empty()}, indicating the default graph.
* The graph name is typically an {@link IRI} or {@link BlankNode}.
*/
Optional
* A
* Note that
*
*
* Any
* The returned {@link Triple} will have equivalent values returned from the
* methods {@link TripleLike#getSubject()},
* {@link TripleLike#getPredicate()} and {@link TripleLike#getObject()}.
*
* The returned {@link Triple} MUST NOT be {@link #equals(Object)} to this
* {@link Quad}, even if this quad has a default graph
* {@link #getGraphName()} value of {@link Optional#empty()}, but MUST
* follow the {@link Triple#equals(Object)} semantics. This means that the
* following MUST be true:
*
*
* Two Quads are equal if and only if their {@link #getGraphName()},
* {@link #getSubject()}, {@link #getPredicate()} and {@link #getObject()}
* are equal.
*
* Implementations MUST also override {@link #hashCode()} so that two equal
* Quads produce the same hash code.
*
* Note that a {@link Quad} MUST NOT be equal to a {@link Triple}, even if
* this Quad's {@link #getGraphName()} is {@link Optional#empty()}. To test
* triple-like equivalence, callers can use:
*
* The returned hash code MUST be equal to the result of
* {@link Objects#hash(Object...)} with the arguments {@link #getSubject()},
* {@link #getPredicate()}, {@link #getObject()}, {@link #getGraphName()}.
*
* This method MUST be implemented in conjunction with
* {@link #equals(Object)} so that two equal {@link Quad}s produce the same
* hash code.
*
* @return a hash code value for this Quad.
* @see Object#hashCode()
* @see Objects#hash(Object...)
*/
@Override
public int hashCode();
}
././@LongLink 0000644 0000000 0000000 00000000146 00000000000 011604 L ustar root root apache-commons-rdf-0.5.0/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/RDFTermFactory.java apache-commons-rdf-0.5.0/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/RDFTermFactory.jav0000644 0001750 0001750 00000005370 13175733174 033026 0 ustar andrius andrius /**
* 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;
/**
* Factory for creating RDFTerm instances..
*
* This interface is deprecated in favour of the richer
* {@link RDF}.
*
* @see RDF
*/
@Deprecated
public interface RDFTermFactory {
default BlankNode createBlankNode() throws UnsupportedOperationException {
throw new UnsupportedOperationException("createBlankNode() not supported");
}
default BlankNode createBlankNode(final String name) throws UnsupportedOperationException {
throw new UnsupportedOperationException("createBlankNode(String) not supported");
}
default Graph createGraph() throws UnsupportedOperationException {
throw new UnsupportedOperationException("createGraph() not supported");
}
default IRI createIRI(final String iri) throws IllegalArgumentException, UnsupportedOperationException {
throw new UnsupportedOperationException("createIRI(String) not supported");
}
default Literal createLiteral(final String lexicalForm) throws IllegalArgumentException, UnsupportedOperationException {
throw new UnsupportedOperationException("createLiteral(String) not supported");
}
default Literal createLiteral(final String lexicalForm, final IRI dataType)
throws IllegalArgumentException, UnsupportedOperationException {
throw new UnsupportedOperationException("createLiteral(String) not supported");
}
default Literal createLiteral(final String lexicalForm, final String languageTag)
throws IllegalArgumentException, UnsupportedOperationException {
throw new UnsupportedOperationException("createLiteral(String,String) not supported");
}
default Triple createTriple(final BlankNodeOrIRI subject, final IRI predicate, final RDFTerm object)
throws IllegalArgumentException, UnsupportedOperationException {
throw new UnsupportedOperationException("createTriple(BlankNodeOrIRI,IRI,RDFTerm) not supported");
}
}
apache-commons-rdf-0.5.0/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/RDF.java 0000644 0001750 0001750 00000024642 13175733174 031012 0 ustar andrius andrius /**
* 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.Serializable;
import java.util.Locale;
/**
* A RDF implementation.
*
* A
* A partial RDF implementation should be clearly documented as such,
* and may throw {@link UnsupportedOperationException} where applicable, e.g. if
* it does not support creating {@link Dataset}s or {@link Quad}s.
*
* Instances of
* If a factory method of a particular implementation does not allow or support
* a provided parameter, e.g. because an IRI is considered invalid, then it
* SHOULD throw {@link IllegalArgumentException}.
*
* @since 0.3.0-incubating
* @see RDFTerm
* @see Graph
* @see Quad
*/
public interface RDF {
/**
* Create a new blank node.
*
* The returned blank node MUST NOT be equal to any existing
* {@link BlankNode} instances according to
* {@link BlankNode#equals(Object)}.
*
* @return A new, unique {@link BlankNode}
*/
public BlankNode createBlankNode();
/**
* Create a blank node based on the given name.
*
* All {@link BlankNode}s created with the given
* The returned BlankNode MUST NOT be equal to
* The returned BlankNode SHOULD NOT be equivalent to any BlankNodes created
* on a different
* The returned Quad SHOULD have a {@link Quad#getGraphName()} that is equal
* to the provided graphName, a {@link Quad#getSubject()} that is equal to
* the provided subject, a {@link Quad#getPredicate()} that is equal to the
* provided predicate, and a {@link Quad#getObject()} that is equal to the
* provided object.
*
* @param graphName
* The IRI or BlankNode that this quad belongs to, or
*
* A
* Note that
*
*
* Any
* Two Triples are equal if and only if their {@link #getSubject()},
* {@link #getPredicate()} and {@link #getObject()} are equal.
*
* Implementations MUST also override {@link #hashCode()} so that two equal
* Triples produce the same hash code.
*
* The returned hash code MUST be equal to the result of
* {@link Objects#hash(Object...)} with the arguments {@link #getSubject()},
* {@link #getPredicate()}, {@link #getObject()}.
*
* This method MUST be implemented in conjunction with
* {@link #equals(Object)} so that two equal {@link Triple}s produce the
* same hash code.
*
* @return a hash code value for this Triple.
* @see Object#hashCode()
* @see Objects#hash(Object...)
*/
@Override
public int hashCode();
}
apache-commons-rdf-0.5.0/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/GraphLike.java 0000644 0001750 0001750 00000006401 13175733174 032236 0 ustar andrius andrius /**
* 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.util.ConcurrentModificationException;
import java.util.stream.Stream;
/**
* A "graph-like" interface that contains {@link TripleLike} statements.
*
* Extended by {@link Graph} (for {@link Triple}) and {@link Dataset} (for
* {@link Quad}).
*
* Unlike {@link Graph} and {@link Dataset}, this interface can support
* generalised {@link TripleLike} or {@link QuadLike} statements, but does not
* imply semantics like {@link #size()} or the requirement of mapping
* {@link RDFTerm} instances from different implementations.
*
* As {@link TripleLike} do not have a specific {@link Object#equals(Object)}
* semantics, the behaviour of methods like {@link #contains(TripleLike)} and
* {@link #remove(TripleLike)} is undefined for arguments that are not object
* identical to previously added or returned {@link TripleLike} statements.
*
* @param
* A TripleLike statement has at least a {@link #getSubject()},
* {@link #getPredicate()} and {@link #getObject()}, but unlike a {@link Triple}
* does not have a formalised {@link Triple#equals(Object)} or
* {@link Triple#hashCode()} semantics and is not required to be
* immutable or thread-safe. This interfaced can also be used
* for generalised triples (e.g. a {@link BlankNode} as predicate).
*
* Implementations should specialise which specific {@link RDFTerm} types they
* return by overriding {@link #getSubject()}, {@link #getPredicate()} and
* {@link #getObject()}.
*
*
* @since 0.3.0-incubating
* @see Triple
* @see Quad
* @see QuadLike
*/
public interface TripleLike {
/**
* The subject of this statement.
*
* @return The subject, typically an {@link IRI} or {@link BlankNode}.
*/
RDFTerm getSubject();
/**
* The predicate of this statement.
*
* @return The predicate, typically an {@link IRI}.
*/
RDFTerm getPredicate();
/**
* The object of this statement.
*
* @return The object, typically an {@link IRI}, {@link BlankNode} or
* {@link Literal}.
*/
RDFTerm getObject();
}
apache-commons-rdf-0.5.0/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/Literal.java 0000644 0001750 0001750 00000013334 13175733174 031767 0 ustar andrius andrius /**
* 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.Serializable;
import java.util.Locale;
import java.util.Objects;
import java.util.Optional;
/**
* An RDF-1.1 Literal, as defined by
* RDF-1.1 Concepts and Abstract Syntax, a W3C Recommendation published on
* 25 February 2014.
*
* @see RDF#createLiteral(String)
* @see RDF#createLiteral(String, IRI)
* @see RDF#createLiteral(String, String)
*/
public interface Literal extends RDFTerm {
/**
* The lexical form of this literal, represented by a
* Unicode string.
*
* @return The lexical form of this literal.
* @see RDF-1.1
* Literal lexical form
*/
String getLexicalForm();
/**
* The IRI identifying the datatype that determines how the lexical form
* maps to a literal value.
*
* If the datatype IRI is
* http://www.w3.org/1999/02/22-rdf-syntax-ns#langString,
* {@link #getLanguageTag()} must not return {@link Optional#empty()}, and
* it must return a valid
* BCP47 language tag.
*
* @return The datatype IRI for this literal.
* @see RDF-1.1
* Literal datatype IRI
*/
IRI getDatatype();
/**
* If and only if the datatype IRI is
* http://www.w3.org/1999/02/22-rdf-syntax-ns#langString, the language
* tag for this Literal is a non-empty language tag as defined by
* BCP47.
* The value space of language tags is always in lower case; although
* RDF implementations MAY convert all language tags to lower case,
* safe comparisons of language tags should be done using
* {@link String#toLowerCase(Locale)} with the locale
* {@link Locale#ROOT}.
*
* Implementation note: If your application requires {@link Serializable}
* objects, it is best not to store an {@link Optional} in a field. It is
* recommended to use {@link Optional#ofNullable(Object)} to create the
* return value for this method.
*
* @return The {@link Optional} language tag for this literal. If
* {@link Optional#isPresent()} returns true, the value returned by
* {@link Optional#get()} must be a non-empty language tag string
* conforming to BCP47.
* @see RDF-1.1
* Literal language tag
*/
Optional
* Implementations MUST also override {@link #hashCode()} so that two equal
* Literals produce the same hash code.
*
* @param other
* Another object
* @return true if other is a Literal and is equal to this
* @see Object#equals(Object)
*/
@Override
public boolean equals(Object other);
/**
* Calculate a hash code for this Literal.
*
* The returned hash code MUST be equal to the result of
* {@link Objects#hash(Object...)} with the arguments
* {@link #getLexicalForm()}, {@link #getDatatype()},
* {@link #getLanguageTag()}
* This method MUST be implemented in conjunction with
* {@link #equals(Object)} so that two equal Literals produce the same hash
* code.
*
* @return a hash code value for this Literal.
* @see Object#hashCode()
* @see Objects#hash(Object...)
*/
@Override
public int hashCode();
}
apache-commons-rdf-0.5.0/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/IRI.java 0000644 0001750 0001750 00000005342 13175733174 031016 0 ustar andrius andrius /**
* 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;
/**
* An RDF-1.1 IRI,
* as defined by RDF-1.1
* Concepts and Abstract Syntax, a W3C Recommendation published on 25
* February 2014.
*
* @see RDF#createIRI(String)
*/
public interface IRI extends BlankNodeOrIRI {
/**
* Return the IRI encoded as a native Unicode String.
* The returned hash code MUST be equal to the {@link String#hashCode()} of
* the {@link #getIRIString()}.
*
* This method MUST be implemented in conjunction with
* {@link #equals(Object)} so that two equal IRIs produce the same hash
* code.
*
* @return a hash code value for this IRI.
* @see Object#hashCode()
*/
@Override
public int hashCode();
}
apache-commons-rdf-0.5.0/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java 0000644 0001750 0001750 00000010105 13175733174 031627 0 ustar andrius andrius /**
* 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;
/**
* An RDF-1.1
* Term, as defined by
* RDF-1.1 Concepts and
* Abstract Syntax, a W3C Recommendation published on 25 February 2014.
*
* A {@link RDFTerm} object in Commons RDF is considered
* immutable, that is, over its life time it will have
* consistent behaviour for its {@link #equals(Object)} and {@link #hashCode()},
* and objects returned from its getter methods (e.g. {@link IRI#getIRIString()}
* and {@link Literal#getLanguageTag()}) will have consistent
* {@link #equals(Object)} behaviour.
*
* Note that methods in
* Methods in
*
* Any
* If this object is an {@link IRI}, equality is checked using
* {@link IRI#equals(Object)}, or if this object is a {@link BlankNode},
* equality is checked using {@link BlankNode#equals(Object)}, or if this
* object is a {@link Literal}, equality is checked using
* {@link Literal#equals(Object)}.
*
* Implementations MUST also override {@link #hashCode()} so that two equal
* Literals produce the same hash code.
*
* @see IRI#equals(Object)
* @see BlankNode#equals(Object)
* @see Literal#equals(Object)
*
* @param other
* Another object
* @return true if other is a RDFTerm and is equal to this
*/
@Override
public boolean equals(Object other);
/**
* Calculate a hash code for this RDFTerm.
*
* As an {@link RDFTerm} is immutable, this method will always
* return the same hashCode over the lifetime of this object.
*
* This method MUST be implemented in conjunction with
* {@link #equals(Object)} so that two equal RDFTerm produce the same hash
* code.
*
* @see IRI#hashCode()
* @see Literal#hashCode()
* @see BlankNode#hashCode()
*
* @return a hash code value for this RDFTerm.
*/
@Override
public int hashCode();
}
apache-commons-rdf-0.5.0/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/BlankNode.java 0000644 0001750 0001750 00000011746 13175733174 032235 0 ustar andrius andrius /**
* 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.util.UUID;
/**
* A RDF-1.1
* Blank Node, as defined by
* RDF-1.1
* Concepts and Abstract Syntax, a W3C Recommendation published on 25
* February 2014.
* The reference string MUST universally and uniquely identify this blank
* node. That is, different blank nodes created separately in different JVMs
* or from different {@link RDF} instances MUST NOT have the same reference
* string.
*
* The {@link #uniqueReference()} of two
* Clients should not assume any particular structure of the reference
* string, however it is recommended that the reference string contain a
* UUID-derived string, e.g. as returned from {@link UUID#toString()}.
*
* IMPORTANT: This is not a
*
* blank node identifier nor a serialization/syntax label, and there are
* no guarantees that it is a valid identifier in any concrete RDF syntax.
* For an N-Triples compatible identifier, use {@link #ntriplesString()}.
*
* @return A universally unique reference to identify this {@link BlankNode}
*/
String uniqueReference();
/**
* Check it this BlankNode is equal to another BlankNode. Two BlankNodes
* MUST be equal if, and only if, they have the same
* {@link #uniqueReference()}.
*
* Implementations MUST also override {@link #hashCode()} so that two equal
* Literals produce the same hash code.
*
* @param other
* Another object
* @return true if other is a BlankNode instance that represent the same
* blank node
* @see Object#equals(Object)
*/
@Override
public boolean equals(Object other);
/**
* Calculate a hash code for this BlankNode.
*
* The returned hash code MUST be equal to the {@link String#hashCode()} of
* the {@link #uniqueReference()}.
*
* This method MUST be implemented in conjunction with
* {@link #equals(Object)} so that two equal BlankNodes produce the same
* hash code.
*
* @return a hash code value for this BlankNode.
* @see Object#hashCode()
*/
@Override
public int hashCode();
}
././@LongLink 0000644 0000000 0000000 00000000146 00000000000 011604 L ustar root root apache-commons-rdf-0.5.0/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/BlankNodeOrIRI.java apache-commons-rdf-0.5.0/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/BlankNodeOrIRI.jav0000644 0001750 0001750 00000002221 13175733174 032725 0 ustar andrius andrius /**
* 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;
/**
* This interface represents the {@link RDFTerm}s that may be used in the
* subject position of an RDF-1.1 {@link Triple} as well as the graph name
* position of a {@link Quad}.
*
* Instances of BlankNodeOrIRI SHOULD be a {@link BlankNode} or an {@link IRI}.
*/
public interface BlankNodeOrIRI extends RDFTerm {
}
apache-commons-rdf-0.5.0/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java 0000644 0001750 0001750 00000025067 13175733174 032223 0 ustar andrius andrius /**
* 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.util.Collections;
import java.util.Locale;
import java.util.Optional;
import java.util.Set;
/**
* An RDF syntax, e.g. as used for parsing and writing RDF.
*
* An RDF syntax is uniquely identified by its {@link #mediaType()}, and has a
* suggested {@link #fileExtension()}.
*
* Some of the RDF syntaxes may {@link #supportsDataset()}, meaning they can
* represent {@link Quad}s.
*
* An enumeration of the official RDF 1.1 syntaxes is available in
* {@link W3CRDFSyntax} - for convenience they are also accessible
* as constants here, e.g.
* The name is specific to Commons RDF and carries no particular meaning.
*
* @return Short name for RDF syntax
*/
public String name();
/**
* The title of the RDF Syntax.
*
* This is generally the title of the corresponding standard,
* e.g. RDF 1.1 Turtle.
*
* @return Title of RDF Syntax
*/
public String title();
/**
* The IANA media type for
* the RDF syntax.
*
* The media type can be used as part of
* The media type can be used as part of
* The returned Set MUST include the value {@link #mediaType()}; this is the
* behaviour of the default implementation.
*
* @return The media types corresponding to the RDF Syntax
*/
default public Set
* The file extension includes the leading period, e.g.
* The file extension includes the leading period, e.g.
* The returned Set MUST include the value from {@link #fileExtension()}; this is
* the behaviour of the default implementation.
*
* @return The file extensions corresponding to the RDF Syntax
*/
default public Set
* Note that the identifying IRI is generally distinct from the IRI of the
* document that specifies the RDF syntax.
*
* @return Identifying IRI, e.g.
*
* Two {@link RDFSyntax}es are considered equal if their
* {@link #mediaType()}s are equal when compared as lower case strings
* according to {@link String#toLowerCase(Locale)} with the locale
* {@link Locale#ROOT}.
*
* @param obj the object with which to compare
* @return true if this object is the same as the obj argument; false otherwise
*/
@Override
boolean equals(Object obj);
/**
* The hash code of an RDFSyntax is equivalent to the hash code
* of the {@link #mediaType()} in lower case according to
* {@link String#toLowerCase(Locale)} with the locale
* {@link Locale#ROOT}.
*
* @return Hash code of RDFSyntax
*/
@Override
int hashCode();
/**
* Return the RDF 1.1 serialization syntaxes.
*
* This lists the W3C standardized RDF 1.1 syntaxes like {@link #TURTLE} and
* {@link #JSONLD}. Note the existence of other RDF syntaxes that are not
* included here, e.g. N3 and
* TriX.
*
* The syntaxes returned only support the {@link #mediaType()}
* and {@link #fileExtension()} as defined in the corresponding
* W3C specification.
*
* @return
* A set of the official RDF 1.1 {@link RDFSyntax}es.
*
* @see RDF
* 1.1 Primer
* @see org.apache.commons.rdf.experimental.RDFParser
*/
public static Set
* The
* If the media type specifies parameters, e.g.
*
* This method support all syntaxes returned by {@link #w3cSyntaxes()}.
*
* @param mediaType
* The media type to match
* @return If {@link Optional#isPresent()}, the {@link RDFSyntax} which has
* a matching {@link RDFSyntax#mediaType()}, otherwise
* {@link Optional#empty()} indicating that no matching syntax was
* found.
*/
public static Optional
* The
* This method support all syntaxes returned by {@link #w3cSyntaxes()}.
*
* @param fileExtension
* The fileExtension to match, starting with
* This method support all syntaxes returned by {@link #w3cSyntaxes()}.
*
* @param name
* The name to match, , e.g.
* For example, this would close any open file and network streams and free
* database locks held by the Graph implementation.
*
* The behaviour of the other Graph methods are undefined after closing the
* graph.
*
* Implementations might not need {@link #close()}, hence the default
* implementation does nothing.
*/
@Override
default void close() throws Exception {
}
/**
* Removes a concrete triple from the graph.
*
* @param triple
* triple to remove
*/
@Override
void remove(Triple triple);
/**
* Removes a concrete pattern of triples from the graph.
*
* @param subject
* The triple subject (null is a wildcard)
* @param predicate
* The triple predicate (null is a wildcard)
* @param object
* The triple object (null is a wildcard)
*/
void remove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
/**
* Clears the graph, removing all triples.
*/
@Override
void clear();
/**
* Number of triples contained by the graph.
*
* The count of a set does not include duplicates, consistent with the
* {@link Triple#equals(Object)} equals method for each {@link Triple}.
*
* @return The number of triples in the graph
*/
@Override
long size();
/**
* Gets all triples contained by the graph.
* The iteration does not contain any duplicate triples, as determined by
* the {@link Triple#equals(Object)} method for each {@link Triple}.
*
* The behaviour of the {@link Stream} is not specified if
* {@link #add(Triple)}, {@link #remove(Triple)} or {@link #clear()} are
* called on the {@link Graph} before it terminates.
*
* Implementations may throw {@link ConcurrentModificationException} from
* Stream methods if they detect a conflict while the Stream is active.
*
* @since 0.3.0-incubating
* @return A {@link Stream} over all of the triples in the graph
*/
@Override
Stream extends Triple> stream();
/**
* Gets all triples contained by the graph matched with the pattern.
*
* The iteration does not contain any duplicate triples, as determined by
* the {@link Triple#equals(Object)} method for each {@link Triple}.
*
* The behaviour of the {@link Stream} is not specified if
* {@link #add(Triple)}, {@link #remove(Triple)} or {@link #clear()} are
* called on the {@link Graph} before it terminates.
*
* Implementations may throw {@link ConcurrentModificationException} from
* Stream methods if they detect a conflict while the Stream is active.
*
*
* @since 0.3.0-incubating
* @param subject
* The triple subject (null is a wildcard)
* @param predicate
* The triple predicate (null is a wildcard)
* @param object
* The triple object (null is a wildcard)
* @return A {@link Stream} over the matched triples.
*/
Stream extends Triple> stream(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
/**
* This method is deprecated, use the equivalent method {@link #stream()}
* instead.
*
* @return A {@link Stream} over all triples.
*/
@Deprecated
default Stream extends Triple> getTriples() {
return stream();
}
/**
* This method is deprecated, use the equivalent method
* {@link #stream(BlankNodeOrIRI, IRI, RDFTerm)} instead.
*
* @param subject
* The triple subject (null is a wildcard)
* @param predicate
* The triple predicate (null is a wildcard)
* @param object
* The triple object (null is a wildcard)
* @return A {@link Stream} over the matched triples.
*/
@Deprecated
default Stream extends Triple> getTriples(final BlankNodeOrIRI subject, final IRI predicate, final RDFTerm object) {
return stream(subject, predicate, object);
}
/**
* Gets an Iterable for iterating over all triples in the graph.
*
* This method is meant to be used with a Java for-each loop, e.g.:
*
*
* Implementations may throw {@link ConcurrentModificationException} from
* Iterator methods if they detect a concurrency conflict while the Iterator
* is active.
*
* The {@link Iterable#iterator()} must only be called once, that is the
* Iterable must only be iterated over once. A {@link IllegalStateException}
* may be thrown on attempt to reuse the Iterable.
*
* The default implementation of this method will call {@link #stream()} to return
* its {@link Stream#iterator()}.
*
* @return A {@link Iterable} that returns {@link Iterator} over all of the
* triples in the graph
* @throws IllegalStateException
* if the {@link Iterable} has been reused
* @throws ConcurrentModificationException
* if a concurrency conflict occurs while the Iterator is
* active.
*/
@Override
@SuppressWarnings("unchecked")
default Iterable
* This method is meant to be used with a Java for-each loop, e.g.:
*
*
* The behaviour of the iterator is not specified if {@link #add(Triple)},
* {@link #remove(Triple)} or {@link #clear()}, are called on the
* {@link Graph} before it terminates. It is undefined if the returned
* {@link Iterator} supports the {@link Iterator#remove()} method.
*
* Implementations may throw {@link ConcurrentModificationException} from
* Iterator methods if they detect a concurrency conflict while the Iterator
* is active.
*
* The {@link Iterable#iterator()} must only be called once, that is the
* Iterable must only be iterated over once. A {@link IllegalStateException}
* may be thrown on attempt to reuse the Iterable.
*
* The default implementation of this method will call
* {@link #stream(BlankNodeOrIRI, IRI, RDFTerm)} to return its
* {@link Stream#iterator()}.
*
* @param subject
* The triple subject (null is a wildcard)
* @param predicate
* The triple predicate (null is a wildcard)
* @param object
* The triple object (null is a wildcard)
* @return A {@link Iterable} that returns {@link Iterator} over the
* matching triples in the graph
* @throws IllegalStateException
* if the {@link Iterable} has been reused
* @throws ConcurrentModificationException
* if a concurrency conflict occurs while the Iterator is
* active.
*/
@SuppressWarnings("unchecked")
default Iterable
* This defines the W3C standardized RDF 1.1 syntaxes like {@link #TURTLE} and
* {@link #JSONLD}. Note the existence of other RDF syntaxes that are not
* included here, e.g. N3 and
* TriX.
*
* This class is package-protected, its static constants are exposed through
* {@link RDFSyntax}.
*
* @see RDFSyntax#w3cSyntaxes()
* @see RDF
* 1.1 Primer
* @see org.apache.commons.rdf.experimental.RDFParser
*/
class W3CRDFSyntax implements RDFSyntax {
/**
* IRI representing a W3C RDF
* format.
*/
private final static class FormatIRI implements IRI {
private static String BASE = "http://www.w3.org/ns/formats/";
private final String format;
private FormatIRI(final String format) {
this.format = format;
}
@Override
public String getIRIString() {
return BASE + format;
}
@Override
public String ntriplesString() {
return "<" + getIRIString() + ">";
}
@Override
public String toString() {
return ntriplesString();
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null || !(obj instanceof IRI)) {
return false;
}
final IRI other = (IRI) obj;
return getIRIString().equals(other.getIRIString());
}
@Override
public int hashCode() {
return getIRIString().hashCode();
}
}
static final RDFSyntax JSONLD, TURTLE, NQUADS, NTRIPLES, RDFA, RDFXML, TRIG;
static final Set
* {@link W3CRDFSyntax} always defines media type in lower case, so
* {@link String#toLowerCase(Locale)} need not be called.
*
*/
@Override
public String mediaType() {
return mediaType;
}
/**
* {@inheritDoc}
*
* {@link W3CRDFSyntax} always defines file extensions in lower case, so
* {@link String#toLowerCase(Locale)} need not be called.
*
*/
@Override
public String fileExtension() {
return fileExtension;
}
@Override
public boolean supportsDataset() {
return supportsDataset;
}
@Override
public String title() {
return title;
}
@Override
public String name() {
return name;
}
@Override
public IRI iri() {
return iri;
}
@Override
public boolean equals(final Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof RDFSyntax)) {
return false;
}
final RDFSyntax other = (RDFSyntax) obj;
return mediaType.equals(other.mediaType().toLowerCase(Locale.ROOT));
}
@Override
public int hashCode() {
return mediaType.hashCode();
}
@Override
public String toString() {
return title;
}
} apache-commons-rdf-0.5.0/commons-rdf-api/src/main/java/org/apache/commons/rdf/experimental/ 0000755 0001750 0001750 00000000000 13175733174 031450 5 ustar andrius andrius ././@LongLink 0000644 0000000 0000000 00000000155 00000000000 011604 L ustar root root apache-commons-rdf-0.5.0/commons-rdf-api/src/main/java/org/apache/commons/rdf/experimental/package-info.java apache-commons-rdf-0.5.0/commons-rdf-api/src/main/java/org/apache/commons/rdf/experimental/package-i0000644 0001750 0001750 00000002574 13175733174 033224 0 ustar andrius andrius /*
* 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.
*
* Interfaces/classes in this package should be considered at
* risk; they might change or be removed in the next minor update of
* Commons RDF.
*
* When class/interface has stabilized, it will move to the
* {@link org.apache.commons.rdf.api} package.
*
* This interface follows the
* Builder pattern,
* allowing to set parser settings like {@link #contentType(RDFSyntax)} and
* {@link #base(IRI)}. A caller MUST call one of the
* 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.
*
* 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
* 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
*
* Example usage:
*
* 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 RDF} to use for generating {@link RDFTerm}s.
*
* This option may be used together with {@link #target(Graph)} to override
* the implementation's default factory and graph.
*
* Warning: 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.
*
* This option can be used to select the RDFSyntax of the source, overriding
* any
* The character set of the RDFSyntax is assumed to be
* {@link StandardCharsets#UTF_8} unless overridden within the document
* (e.g. {@code } in
* {@link RDFSyntax#RDFXML}).
*
* 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.
*
* This option can be used to select the RDFSyntax of the source, overriding
* any
* The content type MAY include a
* This method will override any contentType set with
* {@link #contentType(RDFSyntax)}.
*
* @see #contentType(RDFSyntax)
* @param contentType
* A content-type string, e.g.
* If the source supports datasets (e.g. the {@link #contentType(RDFSyntax)}
* set has {@link RDFSyntax#supportsDataset} is true)), then only quads in
* the default graph will be added to the Graph as {@link Triple}s.
*
* 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.
*
* Calling this method will override any earlier targets set with
* {@link #target(Graph)}, {@link #target(Consumer)} or
* {@link #target(Dataset)}.
*
* 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.
*
* 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.
*
* Calling this method will override any earlier targets set with
* {@link #target(Graph)}, {@link #target(Consumer)} or
* {@link #target(Dataset)}.
*
* 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.
*
* 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
*
* 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.
*
* Calling this method will override any earlier targets set with
* {@link #target(Graph)}, {@link #target(Consumer)} or
* {@link #target(Dataset)}.
*
* 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.
*
* This method is typically called with a functional consumer, for example:
*
*
* Setting this option will override any protocol-specific base IRI (e.g.
*
* If the source is in a syntax that does not support relative IRI
* references (e.g. {@link RDFSyntax#NTRIPLES}), setting the
*
* 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.
*
* Setting this option will override any protocol-specific base IRI (e.g.
*
* If the source is in a syntax that does not support relative IRI
* references (e.g. {@link RDFSyntax#NTRIPLES}), setting the
*
* 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.
*
* The source set will not be read before the call to {@link #parse()}.
*
* The InputStream will not be closed after parsing. The InputStream does
* not need to support {@link InputStream#markSupported()}.
*
* The parser might not consume the complete stream (e.g. an RDF/XML parser
* may not read beyond the closing tag of
*
* The {@link #contentType(RDFSyntax)} or {@link #contentType(String)}
* SHOULD be set before calling {@link #parse()}.
*
* 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
*
* 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}).
*
* 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.
*
* The source set will not be read before the call to {@link #parse()}.
*
* The {@link #contentType(RDFSyntax)} or {@link #contentType(String)}
* SHOULD be set before calling {@link #parse()}.
*
* 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
*
* 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.
*
* 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.
*
* The source set will not be read before the call to {@link #parse()}.
*
* If this builder does not support the given IRI protocol (e.g.
*
* 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.
* The character set is assumed to be {@link StandardCharsets#UTF_8} unless
* the protocol's equivalent of
* 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.
*
* 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.
*
* The source set will not be read before the call to {@link #parse()}.
*
* If this builder does not support the given IRI (e.g.
*
* 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.
* The character set is assumed to be {@link StandardCharsets#UTF_8} unless
* the protocol's equivalent of
* 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.
*
* 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.
*
* 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.
*
* 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.
*
* 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.
*
* 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
* The returned {@link Future} contains a {@link ParseResult}.
* Implementations may subclass this interface to provide any parser
* details, e.g. list of warnings.
* If an exception occurs during parsing, (e.g. {@link IOException} or
*
* Each call to this method must provide a new, unique BlankNode.
*
* @return {@link RDF} instance to be tested.
*/
protected abstract BlankNode getBlankNode();
/**
* Gets a new blank node object based on the given identifier.
*
* Subsequent calls to this method during a single test with the same
* identifier must return BlankNode objects that are equals and have the
* same hashCode. The objects returned from successive calls during a single
* test may be the same object, or they may be different objects.
*
* To add to your implementation's tests, create a subclass with a name ending
* in
* This test uses try-with-resources blocks for calls to {@link Dataset#stream()}
* and {@link Dataset#iterate()}.
*
* @see Dataset
* @see RDF
*/
public abstract class AbstractDatasetTest {
protected RDF factory;
protected Dataset dataset;
protected IRI alice;
protected IRI bob;
protected IRI name;
protected IRI knows;
protected IRI member;
protected BlankNode bnode1;
protected BlankNode bnode2;
protected Literal aliceName;
protected Literal bobName;
protected Literal secretClubName;
protected Literal companyName;
protected Quad bobNameQuad;
private IRI isPrimaryTopicOf;
private IRI graph1;
private BlankNode graph2;
/**
*
* This method must be overridden by the implementing test to provide a
* factory for the test to create {@link Dataset}, {@link IRI} etc.
*
* @return {@link RDF} instance to be tested.
*/
protected abstract RDF createFactory();
@Before
public void createDatasetAndAdd() {
factory = createFactory();
dataset = factory.createDataset();
assertEquals(0, dataset.size());
graph1 = factory.createIRI("http://example.com/graph1");
graph2 = factory.createBlankNode();
alice = factory.createIRI("http://example.com/alice");
bob = factory.createIRI("http://example.com/bob");
name = factory.createIRI("http://xmlns.com/foaf/0.1/name");
knows = factory.createIRI("http://xmlns.com/foaf/0.1/knows");
member = factory.createIRI("http://xmlns.com/foaf/0.1/member");
bnode1 = factory.createBlankNode("org1");
bnode2 = factory.createBlankNode("org2");
secretClubName = factory.createLiteral("The Secret Club");
companyName = factory.createLiteral("A company");
aliceName = factory.createLiteral("Alice");
bobName = factory.createLiteral("Bob", "en-US");
dataset.add(graph1, alice, name, aliceName);
dataset.add(graph1, alice, knows, bob);
dataset.add(graph1, alice, member, bnode1);
bobNameQuad = factory.createQuad(graph2, bob, name, bobName);
dataset.add(bobNameQuad);
dataset.add(factory.createQuad(graph2, bob, member, bnode1));
dataset.add(factory.createQuad(graph2, bob, member, bnode2));
// NOTE: bnode1 used in both graph1 and graph2
dataset.add(graph1, bnode1, name, secretClubName);
dataset.add(graph2, bnode2, name, companyName);
// default graph describes graph1 and graph2
isPrimaryTopicOf = factory.createIRI("http://xmlns.com/foaf/0.1/isPrimaryTopicOf");
dataset.add(null, alice, isPrimaryTopicOf, graph1);
dataset.add(null, bob, isPrimaryTopicOf, graph2);
}
@Test
public void size() throws Exception {
assertEquals(10, dataset.size());
}
@Test
public void iterate() throws Exception {
Assume.assumeTrue(dataset.size() > 0);
final List
* The quads may be copied in any order. No special conversion or
* adaptation of {@link BlankNode}s are performed.
*
* @param source
* Source Dataset to copy quads from
* @param target
* Target Dataset where quads will be added
*/
private void addAllQuads(final Dataset source, final Dataset target) {
// unordered() as we don't need to preserve quad order
// sequential() as we don't (currently) require target Dataset to be
// thread-safe
try (Stream extends Quad> stream = source.stream()) {
stream.unordered().sequential().forEach(t -> target.add(t));
}
}
/**
* Make a new dataset with two BlankNodes - each with a different
* uniqueReference
*/
private Dataset createDataset1() {
final RDF factory1 = createFactory();
final IRI name = factory1.createIRI("http://xmlns.com/foaf/0.1/name");
final Dataset g1 = factory1.createDataset();
final BlankNode b1 = createOwnBlankNode("b1", "0240eaaa-d33e-4fc0-a4f1-169d6ced3680");
g1.add(b1, b1, name, factory1.createLiteral("Alice"));
final BlankNode b2 = createOwnBlankNode("b2", "9de7db45-0ce7-4b0f-a1ce-c9680ffcfd9f");
g1.add(b2, b2, name, factory1.createLiteral("Bob"));
final IRI hasChild = factory1.createIRI("http://example.com/hasChild");
g1.add(null, b1, hasChild, b2);
return g1;
}
/**
* Create a different implementation of BlankNode to be tested with
* dataset.add(a,b,c); (the implementation may or may not then choose to
* translate such to its own instances)
*
* @param name
* @return
*/
private BlankNode createOwnBlankNode(final String name, final String uuid) {
return new BlankNode() {
@Override
public String ntriplesString() {
return "_: " + name;
}
@Override
public String uniqueReference() {
return uuid;
}
@Override
public int hashCode() {
return uuid.hashCode();
}
@Override
public boolean equals(final Object obj) {
if (!(obj instanceof BlankNode)) {
return false;
}
final BlankNode other = (BlankNode) obj;
return uuid.equals(other.uniqueReference());
}
};
}
private Dataset createDataset2() {
final RDF factory2 = createFactory();
final IRI name = factory2.createIRI("http://xmlns.com/foaf/0.1/name");
final Dataset g2 = factory2.createDataset();
final BlankNode b1 = createOwnBlankNode("b1", "bc8d3e45-a08f-421d-85b3-c25b373abf87");
g2.add(b1, b1, name, factory2.createLiteral("Charlie"));
final BlankNode b2 = createOwnBlankNode("b2", "2209097a-5078-4b03-801a-6a2d2f50d739");
g2.add(b2, b2, name, factory2.createLiteral("Dave"));
final IRI hasChild = factory2.createIRI("http://example.com/hasChild");
// NOTE: Opposite direction of loadDataset1
g2.add(b2, b2, hasChild, b1);
return g2;
}
/**
* Ensure {@link Dataset#getGraphNames()} contains our two graphs.
*
* @throws Exception
* If test fails
*/
@Test
public void getGraphNames() throws Exception {
final Set
* FYI, the equivalent SPARQL version (untested):
*
*
* To add to your implementation's tests, create a subclass with a name ending
* in
* This test uses try-with-resources blocks for calls to {@link Graph#stream()}
* and {@link Graph#iterate()}.
*
* @see Graph
* @see RDF
*/
public abstract class AbstractGraphTest {
protected RDF factory;
protected Graph graph;
protected IRI alice;
protected IRI bob;
protected IRI name;
protected IRI knows;
protected IRI member;
protected BlankNode bnode1;
protected BlankNode bnode2;
protected Literal aliceName;
protected Literal bobName;
protected Literal secretClubName;
protected Literal companyName;
protected Triple bobNameTriple;
/**
*
* This method must be overridden by the implementing test to provide a
* factory for the test to create {@link Graph}, {@link IRI} etc.
*
* @return {@link RDF} instance to be tested.
*/
protected abstract RDF createFactory();
@Before
public void createGraphAndAdd() {
factory = createFactory();
graph = factory.createGraph();
assertEquals(0, graph.size());
alice = factory.createIRI("http://example.com/alice");
bob = factory.createIRI("http://example.com/bob");
name = factory.createIRI("http://xmlns.com/foaf/0.1/name");
knows = factory.createIRI("http://xmlns.com/foaf/0.1/knows");
member = factory.createIRI("http://xmlns.com/foaf/0.1/member");
try {
bnode1 = factory.createBlankNode("org1");
bnode2 = factory.createBlankNode("org2");
} catch (final UnsupportedOperationException ex) {
// leave as null
}
try {
secretClubName = factory.createLiteral("The Secret Club");
companyName = factory.createLiteral("A company");
aliceName = factory.createLiteral("Alice");
bobName = factory.createLiteral("Bob", "en-US");
} catch (final UnsupportedOperationException ex) {
// leave as null
}
if (aliceName != null) {
graph.add(alice, name, aliceName);
}
graph.add(alice, knows, bob);
if (bnode1 != null) {
graph.add(alice, member, bnode1);
}
if (bobName != null) {
try {
bobNameTriple = factory.createTriple(bob, name, bobName);
} catch (final UnsupportedOperationException ex) {
// leave as null
}
if (bobNameTriple != null) {
graph.add(bobNameTriple);
}
}
if (bnode1 != null) {
graph.add(factory.createTriple(bob, member, bnode1));
graph.add(factory.createTriple(bob, member, bnode2));
if (secretClubName != null) {
graph.add(bnode1, name, secretClubName);
graph.add(bnode2, name, companyName);
}
}
}
@Test
public void size() throws Exception {
assertTrue(graph.size() > 0);
Assume.assumeNotNull(bnode1, bnode2, aliceName, bobName, secretClubName, companyName, bobNameTriple);
// Can only reliably predict size if we could create all triples
assertEquals(8, graph.size());
}
@Test
public void iterate() throws Exception {
Assume.assumeTrue(graph.size() > 0);
final List
* The triples may be copied in any order. No special conversion or
* adaptation of {@link BlankNode}s are performed.
*
* @param source
* Source Graph to copy triples from
* @param target
* Target Graph where triples will be added
*/
private void addAllTriples(final Graph source, final Graph target) {
// unordered() as we don't need to preserve triple order
// sequential() as we don't (currently) require target Graph to be
// thread-safe
try (Stream extends Triple> stream = source.stream()) {
stream.unordered().sequential().forEach(t -> target.add(t));
}
}
/**
* Make a new graph with two BlankNodes - each with a different
* uniqueReference
*/
private Graph createGraph1() {
final RDF factory1 = createFactory();
final IRI name = factory1.createIRI("http://xmlns.com/foaf/0.1/name");
final Graph g1 = factory1.createGraph();
final BlankNode b1 = createOwnBlankNode("b1", "0240eaaa-d33e-4fc0-a4f1-169d6ced3680");
g1.add(b1, name, factory1.createLiteral("Alice"));
final BlankNode b2 = createOwnBlankNode("b2", "9de7db45-0ce7-4b0f-a1ce-c9680ffcfd9f");
g1.add(b2, name, factory1.createLiteral("Bob"));
final IRI hasChild = factory1.createIRI("http://example.com/hasChild");
g1.add(b1, hasChild, b2);
return g1;
}
/**
* Create a different implementation of BlankNode to be tested with
* graph.add(a,b,c); (the implementation may or may not then choose to
* translate such to its own instances)
*
* @param name
* @return
*/
private BlankNode createOwnBlankNode(final String name, final String uuid) {
return new BlankNode() {
@Override
public String ntriplesString() {
return "_: " + name;
}
@Override
public String uniqueReference() {
return uuid;
}
@Override
public int hashCode() {
return uuid.hashCode();
}
@Override
public boolean equals(final Object obj) {
if (!(obj instanceof BlankNode)) {
return false;
}
final BlankNode other = (BlankNode) obj;
return uuid.equals(other.uniqueReference());
}
};
}
private Graph createGraph2() {
final RDF factory2 = createFactory();
final IRI name = factory2.createIRI("http://xmlns.com/foaf/0.1/name");
final Graph g2 = factory2.createGraph();
final BlankNode b1 = createOwnBlankNode("b1", "bc8d3e45-a08f-421d-85b3-c25b373abf87");
g2.add(b1, name, factory2.createLiteral("Charlie"));
final BlankNode b2 = createOwnBlankNode("b2", "2209097a-5078-4b03-801a-6a2d2f50d739");
g2.add(b2, name, factory2.createLiteral("Dave"));
final IRI hasChild = factory2.createIRI("http://example.com/hasChild");
// NOTE: Opposite direction of loadGraph1
g2.add(b2, hasChild, b1);
return g2;
}
/**
* An attempt to use the Java 8 streams to look up a more complicated query.
*
* FYI, the equivalent SPARQL version (untested):
*
*
* To add to your implementation's tests, create a subclass with a name ending
* in
* {@link Quad}s in the graph are kept in a {@link Set}.
*
* All Stream operations are performed using parallel and unordered directives.
*/
final class DatasetImpl implements Dataset {
private static final int TO_STRING_MAX = 10;
private final Set
* The objects are not changed. All mapping of BNode objects is done in
* {@link SimpleRDF#createTriple(BlankNodeOrIRI, IRI, RDFTerm)}.
*
* @param subject
* subject of triple
* @param predicate
* predicate of triple
* @param object
* object of triple
*/
public TripleImpl(final BlankNodeOrIRI subject, final IRI predicate, final RDFTerm object) {
this.subject = Objects.requireNonNull(subject);
this.predicate = Objects.requireNonNull(predicate);
this.object = Objects.requireNonNull(object);
}
@Override
public BlankNodeOrIRI getSubject() {
return subject;
}
@Override
public IRI getPredicate() {
return predicate;
}
@Override
public RDFTerm getObject() {
return object;
}
@Override
public String toString() {
return getSubject().ntriplesString() + " " + getPredicate().ntriplesString() + " "
+ getObject().ntriplesString() + " .";
}
@Override
public int hashCode() {
return Objects.hash(subject, predicate, object);
}
@Override
public boolean equals(final Object obj) {
if (!(obj instanceof Triple)) {
return false;
}
final Triple other = (Triple) obj;
return getSubject().equals(other.getSubject()) && getPredicate().equals(other.getPredicate())
&& getObject().equals(other.getObject());
}
}
././@LongLink 0000644 0000000 0000000 00000000152 00000000000 011601 L ustar root root apache-commons-rdf-0.5.0/commons-rdf-simple/src/main/java/org/apache/commons/rdf/simple/package-info.java apache-commons-rdf-0.5.0/commons-rdf-simple/src/main/java/org/apache/commons/rdf/simple/package-info0000644 0001750 0001750 00000003344 13175733174 033237 0 ustar andrius andrius /*
* 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.
*/
/**
* A simple in-memory implementation of the Commons RDF API.
*
* This package contains a simple (if not naive) implementation of
* {@link org.apache.commons.rdf.api} using in-memory POJO objects.
*
* Note that although this module fully implements the commons-rdf API, it
* should not be considered a reference implementation. It is
* not thread-safe nor scalable, but may be useful for testing
* and simple usage (e.g. prototyping).
*
* To use this implementation, create an instance of
* {@link org.apache.commons.rdf.simple.SimpleRDF} and use methods like
* {@link org.apache.commons.rdf.simple.SimpleRDF#createGraph} and
* {@link org.apache.commons.rdf.simple.SimpleRDF#createIRI(String)}.
*
* The {@link org.apache.commons.rdf.simple.Types} class provide constant
* {@link org.apache.commons.rdf.api.IRI}s of the common RDF XML datatypes.
*
*/
package org.apache.commons.rdf.simple;
././@LongLink 0000644 0000000 0000000 00000000146 00000000000 011604 L ustar root root apache-commons-rdf-0.5.0/commons-rdf-simple/src/main/java/org/apache/commons/rdf/simple/experimental/ apache-commons-rdf-0.5.0/commons-rdf-simple/src/main/java/org/apache/commons/rdf/simple/experimental0000755 0001750 0001750 00000000000 13175733174 033402 5 ustar andrius andrius ././@LongLink 0000644 0000000 0000000 00000000167 00000000000 011607 L ustar root root apache-commons-rdf-0.5.0/commons-rdf-simple/src/main/java/org/apache/commons/rdf/simple/experimental/package-info.java apache-commons-rdf-0.5.0/commons-rdf-simple/src/main/java/org/apache/commons/rdf/simple/experimental0000644 0001750 0001750 00000002553 13175733174 033411 0 ustar andrius andrius /*
* 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.
*
* Classes in this package should be considered at risk; they
* might change or be removed in the next minor update of Commons RDF.
*
* When a class has stabilized, it will move to the
* {@link org.apache.commons.rdf.simple} package.
*
* This abstract class keeps the properties in protected fields like
* {@link #sourceFile} using {@link Optional}. Some basic checking like
* {@link #checkIsAbsolute(IRI)} is performed.
*
* 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.
*
* 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
* If this is {@link Optional#isPresent()}, then {@link #getContentType()}
* contains the value of {@link RDFSyntax#mediaType}.
*
* @return The {@link RDFSyntax} of the content type, or
* {@link Optional#empty()} if it has not been set
*/
public Optional
* 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()}.
*
* @return The Content-Type IANA media type, e.g.
* From the call to {@link #parseSynchronusly()}, this will be a
* non-
* 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.
*
* 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
* 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.
*
* 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
* If this is {@link Optional#isPresent()}, then {@link #getSourceFile()}
* and {@link #getSourceIri()} are {@link Optional#empty()}.
*
* @return The source {@link InputStream}, or {@link Optional#empty()} if it
* has not been set
*/
public Optional
* If this is {@link Optional#isPresent()}, then
* {@link #getSourceInputStream()} and {@link #getSourceIri()} are
* {@link Optional#empty()}.
*
* @return The source {@link Path}, or {@link Optional#empty()} if it has
* not been set
*/
public Optional
* If this is {@link Optional#isPresent()}, then
* {@link #getSourceInputStream()} and {@link #getSourceInputStream()} are
* {@link Optional#empty()}.
*
* @return The source {@link IRI}, or {@link Optional#empty()} if it has not
* been set
*/
public Optional
* Used by {@link #source(String)} and {@link #base(String)}.
*
* @param iri
* IRI to check
* @throws IllegalArgumentException
* If the IRI is not absolute
*/
protected void checkIsAbsolute(final IRI iri) throws IllegalArgumentException {
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.
*
* Used by {@link #parse()}.
*
* 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() throws IllegalStateException {
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()
*
* Subclasses should override this and call
* Note that the consumer set for {@link #getTarget()} is
* note reset.
*
* Subclasses should override this and call
* One of the source fields MUST be present, as checked by
* {@link #checkSource()}.
*
* {@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.
*
* The returned clone will always have {@link #getTarget()} and
* {@link #getRdfTermFactory()} present.
*
* If the {@link #getSourceFile()} is present, but the {@link #getBase()} is
* not present, the base will be set to the
* 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.
*
* 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
* The returned file extension includes the leading
* Note that this only returns the last extension, e.g. the file extension
* for
* This is called by {@link #parse()} to set {@link #rdfTermFactory(RDF)} if
* it is {@link Optional#empty()}.
*
* As parsed blank nodes might be made with
* {@link RDF#createBlankNode(String)}, each call to this method SHOULD
* return a new RDF instance.
*
* @return A new {@link RDF}
*/
protected RDF createRDFTermFactory() {
return new SimpleRDF();
}
@Override
public Future
* The {@link RDFTerm}, {@link Triple}, {@link Quad}, {@link Graph} and
* {@link Dataset} instances created by SimpleRDF are simple in-memory
* Implementations that are not thread-safe or efficient, but which may be
* useful for testing and prototyping purposes.
*/
public class SimpleRDF implements RDF {
/**
* Marker interface to say that this RDFTerm is part of the Simple
* implementation. Used by {@link GraphImpl} to avoid double remapping.
*
* This method is package protected to avoid any third-party subclasses.
*
*/
static interface SimpleRDFTerm extends RDFTerm {
}
/**
* Unique salt per instance, for {@link #createBlankNode(String)}
*/
private final UUID SALT = UUID.randomUUID();
@Override
public BlankNode createBlankNode() {
return new BlankNodeImpl();
}
@Override
public BlankNode createBlankNode(final String name) {
return new BlankNodeImpl(SALT, name);
}
@Override
public Graph createGraph() {
// Creates a GraphImpl object using this object as the factory for
// delegating all object creation to
return new GraphImpl(this);
}
@Override
public Dataset createDataset() throws UnsupportedOperationException {
return new DatasetImpl(this);
}
@Override
public IRI createIRI(final String iri) {
final IRI result = new IRIImpl(iri);
// Reuse any IRI objects already created in Types
return Types.get(result).orElse(result);
}
@Override
public Literal createLiteral(final String literal) {
return new LiteralImpl(literal);
}
@Override
public Literal createLiteral(final String literal, final IRI dataType) {
return new LiteralImpl(literal, dataType);
}
@Override
public Literal createLiteral(final String literal, final String language) {
return new LiteralImpl(literal, language);
}
@Override
public Triple createTriple(final BlankNodeOrIRI subject, final IRI predicate, final RDFTerm object) {
return new TripleImpl(subject, predicate, object);
}
@Override
public Quad createQuad(final BlankNodeOrIRI graphName, final BlankNodeOrIRI subject, final IRI predicate, final RDFTerm object)
throws IllegalArgumentException {
return new QuadImpl(graphName, subject, predicate, object);
}
}
././@LongLink 0000644 0000000 0000000 00000000156 00000000000 011605 L ustar root root apache-commons-rdf-0.5.0/commons-rdf-simple/src/main/java/org/apache/commons/rdf/simple/DatasetGraphView.java apache-commons-rdf-0.5.0/commons-rdf-simple/src/main/java/org/apache/commons/rdf/simple/DatasetGraph0000644 0001750 0001750 00000011121 13175733174 033252 0 ustar andrius andrius /**
* 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.util.Optional;
import java.util.stream.Stream;
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.Quad;
import org.apache.commons.rdf.api.RDFTerm;
import org.apache.commons.rdf.api.Triple;
/**
* A {@link Graph} view on a {@link Dataset}.
*
* This view is backed by a {@link Dataset}, and can be constructed in two ways:
*
*
* Changes in the Graph are reflected directly in the Dataset and vice versa.
* This class is thread-safe is the underlying Dataset is thread-safe.
*/
public class DatasetGraphView implements Graph {
private final boolean unionGraph;
private final BlankNodeOrIRI namedGraph;
private final Dataset dataset;
public DatasetGraphView(final Dataset dataset) {
this.dataset = dataset;
this.namedGraph = null;
this.unionGraph = true;
}
public DatasetGraphView(final Dataset dataset, final BlankNodeOrIRI namedGraph) {
this.dataset = dataset;
this.namedGraph = namedGraph;
this.unionGraph = false;
}
@Override
public void close() throws Exception {
dataset.close();
}
@Override
public void add(final Triple triple) {
dataset.add(namedGraph, triple.getSubject(), triple.getPredicate(), triple.getObject());
}
@Override
public void add(final BlankNodeOrIRI subject, final IRI predicate, final RDFTerm object) {
dataset.add(namedGraph, subject, predicate, object);
}
@Override
public boolean contains(final Triple triple) {
return dataset.contains(unionOrNamedGraph(), triple.getSubject(), triple.getPredicate(), triple.getObject());
}
private Optional
* {@link Triple}s in the graph are kept in a {@link Set}.
*
* All Stream operations are performed using parallel and unordered directives.
*/
final class GraphImpl implements Graph {
private static final int TO_STRING_MAX = 10;
private final Set
* The objects are not changed. All mapping of BNode objects is done in
* {@link SimpleRDF#createQuad(BlankNodeOrIRI, BlankNodeOrIRI, IRI, RDFTerm)}.
*
* @param graphName
* graphName of triple
* @param subject
* subject of triple
* @param predicate
* predicate of triple
* @param object
* object of triple
*/
public QuadImpl(final BlankNodeOrIRI graphName, final BlankNodeOrIRI subject, final IRI predicate, final RDFTerm object) {
this.graphName = graphName; // possibly null
this.subject = Objects.requireNonNull(subject);
this.predicate = Objects.requireNonNull(predicate);
this.object = Objects.requireNonNull(object);
}
@Override
public Optional
* This class is deprecated, use instead {@link SimpleRDF}.
*/
@Deprecated
public class SimpleRDFTermFactory implements RDFTermFactory {
private final SimpleRDF factory = new SimpleRDF();
@Override
public BlankNode createBlankNode() {
return factory.createBlankNode();
}
@Override
public BlankNode createBlankNode(final String name) {
return factory.createBlankNode(name);
}
@Override
public Graph createGraph() {
return factory.createGraph();
}
@Override
public IRI createIRI(final String iri) {
return factory.createIRI(iri);
}
@Override
public Literal createLiteral(final String literal) {
return factory.createLiteral(literal);
}
@Override
public Literal createLiteral(final String literal, final IRI dataType) {
return factory.createLiteral(literal, dataType);
}
@Override
public Literal createLiteral(final String literal, final String language) {
return factory.createLiteral(literal, language);
}
@Override
public Triple createTriple(final BlankNodeOrIRI subject, final IRI predicate, final RDFTerm object) {
return factory.createTriple(subject, predicate, object);
}
}
apache-commons-rdf-0.5.0/commons-rdf-simple/src/main/resources/ 0000755 0001750 0001750 00000000000 13175733174 024326 5 ustar andrius andrius apache-commons-rdf-0.5.0/commons-rdf-simple/src/main/resources/META-INF/ 0000755 0001750 0001750 00000000000 13212356336 025457 5 ustar andrius andrius apache-commons-rdf-0.5.0/commons-rdf-simple/src/main/resources/META-INF/NOTICE 0000644 0001750 0001750 00000000254 13212356336 026364 0 ustar andrius andrius Apache Commons RDF
Copyright 2015-2017 The Apache Software Foundation
This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).
apache-commons-rdf-0.5.0/commons-rdf-simple/src/main/resources/META-INF/services/ 0000755 0001750 0001750 00000000000 13175733174 027311 5 ustar andrius andrius ././@LongLink 0000644 0000000 0000000 00000000173 00000000000 011604 L ustar root root apache-commons-rdf-0.5.0/commons-rdf-simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFTermFactory apache-commons-rdf-0.5.0/commons-rdf-simple/src/main/resources/META-INF/services/org.apache.commons.0000644 0001750 0001750 00000000063 13175733174 032772 0 ustar andrius andrius org.apache.commons.rdf.simple.SimpleRDFTermFactory
././@LongLink 0000644 0000000 0000000 00000000160 00000000000 011600 L ustar root root apache-commons-rdf-0.5.0/commons-rdf-simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDF apache-commons-rdf-0.5.0/commons-rdf-simple/src/main/resources/META-INF/services/org.apache.commons.0000644 0001750 0001750 00000000050 13175733174 032766 0 ustar andrius andrius org.apache.commons.rdf.simple.SimpleRDF
apache-commons-rdf-0.5.0/commons-rdf-simple/src/main/resources/META-INF/LICENSE 0000644 0001750 0001750 00000026136 13175733174 026503 0 ustar andrius andrius
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed 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.
apache-commons-rdf-0.5.0/commons-rdf-simple/src/site/ 0000755 0001750 0001750 00000000000 13175733174 022334 5 ustar andrius andrius apache-commons-rdf-0.5.0/commons-rdf-simple/src/site/resources/ 0000755 0001750 0001750 00000000000 13175733174 024346 5 ustar andrius andrius apache-commons-rdf-0.5.0/commons-rdf-simple/src/site/resources/profile.japicmp 0000644 0001750 0001750 00000000000 13175733174 027341 0 ustar andrius andrius apache-commons-rdf-0.5.0/commons-rdf-simple/src/site/resources/profile.jacoco 0000644 0001750 0001750 00000000000 13175733174 027154 0 ustar andrius andrius apache-commons-rdf-0.5.0/commons-rdf-simple/src/test/ 0000755 0001750 0001750 00000000000 13212356336 022340 5 ustar andrius andrius apache-commons-rdf-0.5.0/commons-rdf-simple/src/test/java/ 0000755 0001750 0001750 00000000000 13175733174 023270 5 ustar andrius andrius apache-commons-rdf-0.5.0/commons-rdf-simple/src/test/java/org/ 0000755 0001750 0001750 00000000000 13175733174 024057 5 ustar andrius andrius apache-commons-rdf-0.5.0/commons-rdf-simple/src/test/java/org/apache/ 0000755 0001750 0001750 00000000000 13175733174 025300 5 ustar andrius andrius apache-commons-rdf-0.5.0/commons-rdf-simple/src/test/java/org/apache/commons/ 0000755 0001750 0001750 00000000000 13175733174 026753 5 ustar andrius andrius apache-commons-rdf-0.5.0/commons-rdf-simple/src/test/java/org/apache/commons/rdf/ 0000755 0001750 0001750 00000000000 13175733174 027526 5 ustar andrius andrius apache-commons-rdf-0.5.0/commons-rdf-simple/src/test/java/org/apache/commons/rdf/simple/ 0000755 0001750 0001750 00000000000 13175733174 031017 5 ustar andrius andrius ././@LongLink 0000644 0000000 0000000 00000000153 00000000000 011602 L ustar root root apache-commons-rdf-0.5.0/commons-rdf-simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTest.java apache-commons-rdf-0.5.0/commons-rdf-simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTes0000644 0001750 0001750 00000002121 13175733174 033177 0 ustar andrius andrius /**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.rdf.simple;
import org.apache.commons.rdf.api.AbstractRDFTest;
import org.apache.commons.rdf.api.RDF;
/**
* Simple RDF Test
*/
public class SimpleRDFTest extends AbstractRDFTest {
@Override
public RDF createFactory() {
return new SimpleRDF();
}
}
././@LongLink 0000644 0000000 0000000 00000000156 00000000000 011605 L ustar root root apache-commons-rdf-0.5.0/commons-rdf-simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java apache-commons-rdf-0.5.0/commons-rdf-simple/src/test/java/org/apache/commons/rdf/simple/TestWritingG0000644 0001750 0001750 00000012530 13175733174 033335 0 ustar andrius andrius /**
* 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 java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Stream;
import org.apache.commons.rdf.api.Graph;
import org.apache.commons.rdf.api.IRI;
import org.apache.commons.rdf.api.RDF;
import org.apache.commons.rdf.api.Triple;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
/**
* Test writing graph
*/
public class TestWritingGraph {
/*
* 200k triples should do - about 7 MB on disk. Override with
* -Dtriples=20000000 to exercise your memory banks.
*/
private static final long TRIPLES = Long.getLong("triples", 200000L);
/**
* Run tests with -Dkeepfiles=true to inspect /tmp files *
*/
private static boolean KEEP_FILES = Boolean.getBoolean("keepfiles");
private static Graph graph;
private static RDF factory;
@BeforeClass
public static void createGraph() throws Exception {
factory = new SimpleRDF();
graph = factory.createGraph();
final IRI subject = factory.createIRI("subj");
final IRI predicate = factory.createIRI("pred");
final List
* This always insert at least the triple equivalent to:
*
*
Note:
RDF 1.0 had the datatype
null
for the default
* graph.
* @return The named Graph, or {@link Optional#empty()} if the dataset do
* not contain the named graph.
*/
Optionalnull
is a wildcard, {@link Optional#empty()} is
* the default graph)
* @param subject
* The quad subject (null
is a wildcard)
* @param predicate
* The quad predicate (null
is a wildcard)
* @param object
* The quad object (null
is a wildcard)
*/
void remove(Optional
* null
is a wildcard, {@link Optional#empty()} is
* the default graph)
* @param subject
* The quad subject (null
is a wildcard)
* @param predicate
* The quad predicate (null
is a wildcard)
* @param object
* The quad object (null
is a wildcard)
* @return A {@link Stream} over the matched quads.
*/
Stream extends Quad> stream(Optional
* for (Quad t : dataset.iterate()) {
* System.out.println(t);
* }
*
*
* The behaviour of the iterator is not specified if {@link #add(Quad)},
* {@link #remove(Quad)} or {@link #clear()}, are called on the
* {@link Dataset} before it terminates. It is undefined if the returned
* {@link Iterator} supports the {@link Iterator#remove()} method.
*
* IRI alice = factory.createIRI("http://example.com/alice");
* IRI knows = factory.createIRI("http://xmlns.com/foaf/0.1/");
* for (Quad t : dataset.iterate(null, alice, knows, null)) {
* System.out.println(t.getGraphName());
* System.out.println(t.getObject());
* }
*
* null
is a wildcard, {@link Optional#empty()} is
* the default graph)
* @param subject
* The quad subject (null
is a wildcard)
* @param predicate
* The quad predicate (null
is a wildcard)
* @param object
* The quad object (null
is a wildcard)
* @return A {@link Iterable} that returns {@link Iterator} over the
* matching quads in the dataset
* @throws IllegalStateException
* if the {@link Iterable} has been reused
* @throws ConcurrentModificationException
* if a concurrency conflict occurs while the Iterator is
* active.
*/
@SuppressWarnings("unchecked")
default IterableQuad
object in Commons RDF is considered
* immutable, that is, over its life time it will have
* consistent behaviour for its {@link #equals(Object)}, and the instances
* returned from {@link #getGraphName()}, {@link #getSubject()},
* {@link #getPredicate()}, {@link #getObject()} and {@link #asTriple()} will
* have consistent {@link Object#equals(Object)} behaviour.
* Quad
methods are not required to return object
* identical (==
) instances as long as they are equivalent
* according to {@link Object#equals(Object)}. Specialisations of
* Quad
may provide additional methods that are documented to be
* mutable.
* Quad
methods are thread-safe, however
* specialisations may provide additional methods that are documented to not be
* thread-safe.
* Quad
s can be safely used in hashing collections like
* {@link java.util.HashSet} and {@link java.util.HashMap}.
* Quad
can be used interchangeably across Commons RDF
* implementations.
*
* @since 0.3.0-incubating
* @see Dataset
* @see RDF#createQuad(BlankNodeOrIRI,BlankNodeOrIRI,IRI,RDFTerm)
* @see RDF
* 1.1: On Semantics of RDF Datasets
* @see
*/
public interface Quad extends QuadLike
* Quad q1, q2;
* if (q1.equals(q2)) {
* assert (q1.asTriple().equals(q2.asTriple()));
* } else if (q1.asTriple().equals(q2.asTriple())) {
* assert (q1.getSubject().equals(q2.getSubject()));
* assert (q1.getPredicate().equals(q2.getPredicate()));
* assert (q1.getObject().equals(q2.getObject()));
* assert (!q1.getGraphName().equals(q2.getGraphName()));
* }
*
*
* The default
implementation of this method return a proxy
* {@link Triple} instance that keeps a reference to this {@link Quad} to
* call the underlying {@link TripleLike} methods, but supplies a
* {@link Triple} compatible implementation of {@link Triple#equals(Object)}
* and {@link Triple#hashCode()}. Implementations may override this method,
* e.g. for a more efficient solution.
*
* @return A {@link Triple} that contains the same {@link TripleLike}
* properties as this Quad.
*/
default Triple asTriple() {
return new Triple() {
@Override
public BlankNodeOrIRI getSubject() {
return Quad.this.getSubject();
}
@Override
public IRI getPredicate() {
return Quad.this.getPredicate();
}
@Override
public RDFTerm getObject() {
return Quad.this.getObject();
}
@Override
public boolean equals(final Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof Triple)) {
return false;
}
final Triple other = (Triple) obj;
return Objects.equals(getSubject(), other.getSubject())
&& Objects.equals(getPredicate(), other.getPredicate())
&& Objects.equals(getObject(), other.getObject());
}
@Override
public int hashCode() {
return Objects.hash(getSubject(), getPredicate(), getObject());
}
};
}
/**
* Check it this Quad is equal to another Quad.
*
* Quad q1;
* Triple t2;
* q1.asTriple().equals(t2));
*
*
* @param other
* Another object
* @return true if other is a Quad and is equal to this
* @see Object#equals(Object)
*/
@Override
public boolean equals(Object other);
/**
* Calculate a hash code for this Quad.
* RDF
implementation can create instances of the {@link RDFTerm}
* types {@link IRI}, {@link BlankNode} and {@link Literal}, as well as creating
* instances of the types {@link Triple}, {@link Quad}, {@link Graph} or
* {@link Dataset}.
* RDF
work like a factory for creating Commons RDF
* instances. spezializations of this interface may also provide methods for
* conversions from/to their underlying RDF framework.
* name
on a
* particular instance of RDF
MUST be equivalent according
* to {@link BlankNode#equals(Object)},
* BlankNode
* instances returned for any other name
or those returned from
* {@link #createBlankNode()}.
* RDF
instance, e.g. different
* instances of RDF
should produce different blank nodes for
* the same name
unless they purposely are intending to create
* equivalent {@link BlankNode} instances (e.g. a reinstated
* {@link Serializable} factory).
*
* @param name
* A non-empty, non-null, String that is unique to this blank
* node in the context of this {@link RDF}.
* @return A BlankNode for the given name
*/
public BlankNode createBlankNode(String name);
/**
* Create a new graph.
*
* It is undefined if the graph will be persisted by any underlying storage
* mechanism.
*
* @return A new Graph
*/
public Graph createGraph();
/**
* Create a new dataset.
*
* It is undefined if the dataset will be persisted by any underlying
* storage mechanism.
*
* @return A new Dataset
*/
public Dataset createDataset();
/**
* Create an IRI from a (possibly escaped) String.
*
* The provided iri string MUST be valid according to the
* W3C RDF-1.1
* IRI definition.
*
* @param iri
* Internationalized Resource Identifier
* @return A new IRI
* @throws IllegalArgumentException
* If the provided string is not acceptable, e.g. does not
* conform to the RFC3987 syntax.
*/
public IRI createIRI(String iri) throws IllegalArgumentException;
/**
* Create a simple literal.
*
* The provided lexical form should not be escaped in any sense, e.g. should
* not include "quotes" unless those are part of the literal value.
*
* The returned Literal MUST have a {@link Literal#getLexicalForm()} that is
* equal to the provided lexical form, MUST NOT have a
* {@link Literal#getLanguageTag()} present, and SHOULD return a
* {@link Literal#getDatatype()} that is equal to the IRI
* http://www.w3.org/2001/XMLSchema#string
.
*
* @param lexicalForm
* The literal value in plain text
* @return The created Literal
* @throws IllegalArgumentException
* If the provided lexicalForm is not acceptable, e.g. because
* it is too large for an underlying storage.
*/
public Literal createLiteral(String lexicalForm) throws IllegalArgumentException;
/**
* Create a literal with the specified data type.
*
* The provided lexical form should not be escaped in any sense, e.g. should
* not include "quotes" unless those are part of the literal value.
*
* It is RECOMMENDED that the provided dataType is one of the RDF-compatible XSD
* types.
*
* The provided lexical form SHOULD be in the
* lexical
* space of the provided dataType.
*
* The returned Literal SHOULD have a {@link Literal#getLexicalForm()} that
* is equal to the provided lexicalForm, MUST NOT have a
* {@link Literal#getLanguageTag()} present, and MUST return a
* {@link Literal#getDatatype()} that is equivalent to the provided dataType
* IRI.
*
* @param lexicalForm
* The literal value
* @param dataType
* The data type IRI for the literal value, e.g.
* http://www.w3.org/2001/XMLSchema#integer
* @return The created Literal
* @throws IllegalArgumentException
* If any of the provided arguments are not acceptable, e.g.
* because the provided dataType is not permitted.
*/
public Literal createLiteral(String lexicalForm, IRI dataType) throws IllegalArgumentException;
/**
* Create a language-tagged literal.
*
* The provided lexical form should not be escaped in any sense, e.g. should
* not include "quotes" unless those are part of the literal value.
*
* The provided language tag MUST be valid according to
* BCP47, e.g.
* en
.
*
* The provided language tag
* MAY be converted to lower case.
*
* The returned Literal SHOULD have a {@link Literal#getLexicalForm()} which
* is equal to the provided lexicalForm, MUST return a
* {@link Literal#getDatatype()} that is equal to the IRI
* http://www.w3.org/1999/02/22-rdf-syntax-ns#langString
, and
* MUST have a {@link Literal#getLanguageTag()} present which SHOULD be
* equal to the provided language tag (compared as
* {@link String#toLowerCase(Locale)} using {@link Locale#ENGLISH}).
*
* @param lexicalForm
* The literal value
* @param languageTag
* The non-empty language tag as defined by
* BCP47
* @return The created Literal
* @throws IllegalArgumentException
* If the provided values are not acceptable, e.g. because the
* languageTag was syntactically invalid.
*/
public Literal createLiteral(String lexicalForm, String languageTag) throws IllegalArgumentException;
/**
* Create a triple.
*
* The returned Triple SHOULD have a {@link Triple#getSubject()} that is
* equal to the provided subject, a {@link Triple#getPredicate()} that is
* equal to the provided predicate, and a {@link Triple#getObject()} that is
* equal to the provided object.
*
* @param subject
* The IRI or BlankNode that is the subject of the triple
* @param predicate
* The IRI that is the predicate of the triple
* @param object
* The IRI, BlankNode or Literal that is the object of the triple
* @return The created Triple
* @throws IllegalArgumentException
* If any of the provided arguments are not acceptable, e.g.
* because a Literal has a lexicalForm that is too large for an
* underlying storage.
*/
public Triple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) throws IllegalArgumentException;
/**
* Create a quad.
* null
for the public graph
* @param subject
* The IRI or BlankNode that is the subject of the quad
* @param predicate
* The IRI that is the predicate of the quad
* @param object
* The IRI, BlankNode or Literal that is the object of the quad
* @return The created Quad
* @throws IllegalArgumentException
* If any of the provided arguments are not acceptable, e.g.
* because a Literal has a lexicalForm that is too large for an
* underlying storage.
*/
public Quad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
throws IllegalArgumentException;
}
apache-commons-rdf-0.5.0/commons-rdf-api/src/main/java/org/apache/commons/rdf/api/Triple.java 0000644 0001750 0001750 00000011325 13175733174 031630 0 ustar andrius andrius /**
* 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.util.Objects;
/**
* An RDF-1.1
* Triple, as defined by
* RDF-1.1 Concepts and
* Abstract Syntax, a W3C Recommendation published on 25 February 2014.
* Triple
object in Commons RDF is considered
* immutable, that is, over its life time it will have
* consistent behaviour for its {@link #equals(Object)}, and the {@link RDFTerm}
* instances returned from {@link #getSubject()}, {@link #getPredicate()} and
* {@link #getObject()} will have consistent {@link RDFTerm#equals(Object)}
* behaviour.
* Triple
methods are not required to return object
* identical (==
) instances as long as they are equivalent
* according to {@link RDFTerm#equals(Object)}. Specialisations of
* Triple
may provide additional methods that are documented to be
* mutable.
* Triple
methods are thread-safe, however
* specialisations may provide additional methods that are documented to not be
* thread-safe.
* Triple
s can be safely used in hashing collections like
* {@link java.util.HashSet} and {@link java.util.HashMap}.
* Triple
can be used interchangeably across Commons RDF
* implementations.
*
* @see Quad
* @see RDF#createTriple(BlankNodeOrIRI,IRI,RDFTerm)
* @see RDF-1.1
* Triple
*/
public interface Triple extends TripleLike {
/**
* The subject of this triple, which may be either a {@link BlankNode} or an
* {@link IRI}, which are represented in Commons RDF by the interface
* {@link BlankNodeOrIRI}.
*
* @return The subject {@link BlankNodeOrIRI} of this triple.
* @see RDF-1.1
* Triple subject
*/
@Override
BlankNodeOrIRI getSubject();
/**
* The predicate {@link IRI} of this triple.
*
* @return The predicate {@link IRI} of this triple.
* @see RDF-1.1
* Triple predicate
*/
@Override
IRI getPredicate();
/**
* The object of this triple, which may be either a {@link BlankNode}, an
* {@link IRI}, or a {@link Literal}, which are represented in Commons RDF
* by the interface {@link RDFTerm}.
*
* @return The object {@link RDFTerm} of this triple.
* @see RDF-1.1
* Triple object
*/
@Override
RDFTerm getObject();
/**
* Check it this Triple is equal to another Triple.
*
* If the datatype IRI is not
* http://www.w3.org/1999/02/22-rdf-syntax-ns#langString, this method
* must return {@link Optional#empty()}.
*
* Literal
* term equality:
* Two literals are term-equal (the same RDF literal) if
* and only if the two lexical forms, the two datatype IRIs, and the two
* language tags (if any) compare equal, character by character. Thus, two
* literals can have the same value without being the same RDF term.
*
* As the value space for language tags is lower-space, if they are present,
* they MUST be compared character by character
* using the equivalent of {@link String#toLowerCase(java.util.Locale)} with
* the locale {@link Locale#ROOT}.
* .map(s->s.toLowerString(Locale.ROOT))
.
*
*
* The returned string must not include URL-encoding to escape non-ASCII
* characters.
*
* @return The IRI encoded as a native Unicode String.
*/
String getIRIString();
/**
* Check it this IRI is equal to another IRI.
* IRI
* equality: Two IRIs are equal if and only if they are equivalent under
* Simple String Comparison according to section 5.1 of [RFC3987]. Further
* normalization MUST NOT be performed when comparing IRIs for equality.
*
*
* Two IRI instances are equal if and only if their {@link #getIRIString()}
* are equal.
*
* Implementations MUST also override {@link #hashCode()} so that two equal
* IRIs produce the same hash code.
*
* @param other
* Another object
* @return true if other is an IRI and is equal to this
* @see Object#equals(Object)
*/
@Override
public boolean equals(Object other);
/**
* Calculate a hash code for this IRI.
* RDFTerm
and its Commons RDF specialisations
* {@link IRI}, {@link BlankNode} and {@link Literal} are not required to return
* object identical (==
) instances as long as they are equivalent
* according to their {@link Object#equals(Object)}. Further specialisations may
* provide additional methods that are documented to be mutable.
* RDFTerm
and its Commons RDF specialisations
* {@link IRI}, {@link BlankNode} and {@link Literal} are
* thread-safe, however further specialisations may add
* additional methods that are documented to not be thread-safe.
* RDFTerm
s can be safely used in hashing collections like
* {@link java.util.HashSet} and {@link java.util.HashMap}.
* RDFTerm
can be used interchangeably across Commons RDF
* implementations.
*
* @see RDF-1.1
* Term
*/
public interface RDFTerm {
/**
* Return the term serialised as specified by the RDF-1.1 N-Triples
* Canonical form.
*
* @return The term serialised as RDF-1.1 N-Triples.
* @see
* RDF-1.1 N-Triples Canonical form
*/
String ntriplesString();
/**
* Check it this RDFTerm is equal to another RDFTerm.
*
*
* Note:
* Blank nodes
* are disjoint from IRIs and literals. Otherwise, the set of possible blank
* nodes is arbitrary. RDF makes no reference to any internal structure of blank
* nodes.
*
* Also note that: Blank node
* identifiers are local identifiers that are used in some concrete RDF
* syntaxes or RDF store implementations. They are always locally
* scoped to the file or RDF store, and are not persistent or
* portable identifiers for blank nodes. Blank node identifiers are not
* part of the RDF abstract syntax, but are entirely dependent on the concrete
* syntax or implementation. The syntactic restrictions on blank node
* identifiers, if any, therefore also depend on the concrete RDF syntax or
* implementation.
*
* Implementations that handle blank node identifiers in concrete syntaxes need
* to be careful not to create the same blank node from multiple occurrences of
* the same blank node identifier except in situations where this is supported
* by the syntax.
*
* A BlankNode SHOULD contain a {@link UUID}-derived string as part of its
* universally unique {@link #uniqueReference()}.
*
* @see RDF#createBlankNode()
* @see RDF#createBlankNode(String)
* @see RDF-1.1
* Blank Node
*/
public interface BlankNode extends BlankNodeOrIRI {
/**
* Return a reference for uniquely identifying the blank node.
* BlankNode
instances
* MUST be equal if and only if the two blank nodes are equal according to
* {@link #equals(Object)}.
* RDFSyntax.JSONLD
.
*
*/
public interface RDFSyntax {
/**
* JSON-LD 1.0
*
* @see https://www.w3.org/TR/json-ld/
*
*/
public static RDFSyntax JSONLD = W3CRDFSyntax.JSONLD;
/**
* RDF 1.1 Turtle
*
* @see https://www.w3.org/TR/turtle/
*
*/
public static RDFSyntax TURTLE = W3CRDFSyntax.TURTLE;
/**
* RDF 1.1 N-Quads
*
* @see https://www.w3.org/TR/n-quads/
*/
public static RDFSyntax NQUADS = W3CRDFSyntax.NQUADS;
/**
* RDF 1.1 N-Triples
*
* @see https://www.w3.org/TR/n-triples/
*/
public static RDFSyntax NTRIPLES = W3CRDFSyntax.NTRIPLES;
/**
* HTML+RDFa 1.1 and XHTML+RDFa 1.1
*
* @see https://www.w3.org/TR/html-rdfa/
* @see https://www.w3.org/TR/xhtml-rdfa/
*/
public static RDFSyntax RDFA = W3CRDFSyntax.RDFA;
/**
* RDF 1.1 XML Syntax
*
* @see https://www.w3.org/TR/rdf-syntax-grammar/
*/
public static RDFSyntax RDFXML = W3CRDFSyntax.RDFXML;
/**
* RDF 1.1 TriG
*
* @see https://www.w3.org/TR/trig/
*/
public static RDFSyntax TRIG = W3CRDFSyntax.TRIG;
/**
* A short name of the RDF Syntax e.g. JSONLD
.
* Content-Type
and
* Accept
for content negotiation in the
* HTTP
* protocol.
*
* @return The registered media type of the RDF Syntax
*/
public String mediaType();
/**
* Set of IANA media types that
* covers this RDF syntax, including any non-official media types.
* Content-Type
and
* Accept
for content negotiation in the
* HTTP
* protocol.
* .jsonld
*
* @return The registered file extension of the RDF Syntax
*/
public String fileExtension();
/**
* Set of file extensions for this RDF syntax, including any non-official extensions.
* .jsonld
* http://www.w3.org/ns/formats/JSON-LD
*/
public IRI iri();
/**
* Compare this RDFSyntax with another object.
* mediaType
is compared in lower case to all media types
* supported, therefore it might not be equal to the
* {@link RDFSyntax#mediaType} of the returned RDFSyntax.
* text/turtle; charset=ascii
, only the part of the string to
* before ;
is considered.
* fileExtension
is compared in lower case to all
* extensions supported, therefore it might not be equal to the
* {@link RDFSyntax#fileExtension} of the returned RDFSyntax.
* .
* @return If {@link Optional#isPresent()}, the {@link RDFSyntax} which has
* a matching {@link RDFSyntax#fileExtension()}, otherwise
* {@link Optional#empty()} indicating that no matching file
* extension was found.
*/
public static Optional"JSONLD"
* @return If {@link Optional#isPresent()}, the {@link RDFSyntax} which has
* a matching {@link RDFSyntax#name()}, otherwise
* {@link Optional#empty()} indicating that no matching name was found.
*/
public static Optional
*
* for (Triple t : graph.iterate()) {
* System.out.println(t);
* }
*
*
* The behaviour of the iterator is not specified if {@link #add(Triple)},
* {@link #remove(Triple)} or {@link #clear()}, are called on the
* {@link Graph} before it terminates. It is undefined if the returned
* {@link Iterator} supports the {@link Iterator#remove()} method.
*
* IRI alice = factory.createIRI("http://example.com/alice");
* IRI knows = factory.createIRI("http://xmlns.com/foaf/0.1/");
* for (Triple t : graph.iterate(alice, knows, null)) {
* System.out.println(t.getObject());
* }
*
*
*
*/
package org.apache.commons.rdf.experimental; ././@LongLink 0000644 0000000 0000000 00000000152 00000000000 011601 L ustar root root apache-commons-rdf-0.5.0/commons-rdf-api/src/main/java/org/apache/commons/rdf/experimental/RDFParser.java apache-commons-rdf-0.5.0/commons-rdf-api/src/main/java/org/apache/commons/rdf/experimental/RDFParser0000644 0001750 0001750 00000052633 13175733174 033174 0 ustar andrius andrius /**
* 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).
* Experimental
This interface (and its implementations) should be
* considered at risk; 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.
* Description
* source
methods
* (e.g. {@link #source(IRI)}, {@link #source(Path)},
* {@link #source(InputStream)}), and MUST call one of the target
* 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.
* null
- note that this may require
* casting, e.g. contentType( (RDFSyntax) null )
to undo a previous
* call to {@link #contentType(RDFSyntax)}.
* org.apache.commons.rdf.simple.AbstractRDFParser
.
*
* Graph g1 = rDFTermFactory.createGraph();
* new ExampleRDFParserBuilder().source(Paths.get("/tmp/graph.ttl")).contentType(RDFSyntax.TURTLE).target(g1).parse()
* .get(30, TimeUnit.Seconds);
*
*
*/
public interface RDFParser {
/**
* The result of {@link RDFParser#parse()} indicating parsing completed.
* Content-Type
headers or equivalent.
* Content-Type
headers or equivalent.
* charset
parameter if the RDF
* media types permit it; the default charset is
* {@link StandardCharsets#UTF_8} unless overridden within the document.
* application/ld+json
* or text/turtle;charset="UTF-8"
as specified by
*
* RFC7231.
* @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.
*
* {@code
* List
*
* @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(ConsumerContent-Location
header) or the {@link #source(IRI)} IRI,
* but does not override any base IRIs set within the source document (e.g.
* @base
in Turtle documents).
* base
has no effect.
* Content-Location
header) or the {@link #source(IRI)} IRI,
* but does not override any base IRIs set within the source document (e.g.
* @base
in Turtle documents).
* base
has no effect.
* </rdf:Description>
).
* <?xml encoding="iso-8859-1">
header).
* <?xml encoding="iso-8859-1">
header).
* urn:uuid:ce667463-c5ab-4c23-9b64-701d055c4890
), this method
* should succeed, while the {@link #parse()} should throw an
* {@link IOException}.
* Accept
header in HTTP),
* and SHOULD be used for selecting the RDFSyntax.
* Content-Type
specifies
* otherwise or the document declares its own charset (e.g. RDF/XML with a
* <?xml encoding="iso-8859-1">
header).
* urn:uuid:ce667463-c5ab-4c23-9b64-701d055c4890
), this method
* should succeed, while the {@link #parse()} should throw an
* {@link IOException}.
* Accept
header in HTTP),
* and SHOULD be used for selecting the RDFSyntax.
* Content-Type
specifies
* otherwise or the document declares its own charset (e.g. RDF/XML with a
* <?xml encoding="iso-8859-1">
header).
* parse()
call and
* return a Future that is already {@link Future#isDone()}.
* null
is a possible return
* value if no details are available, but parsing succeeded.
* org.apache.commons.rdf.simple.experimental.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
* source
has not been set.
*/
Future extends ParseResult> parse() throws IOException, IllegalStateException;
}
apache-commons-rdf-0.5.0/commons-rdf-api/src/main/resources/ 0000755 0001750 0001750 00000000000 13175733174 023606 5 ustar andrius andrius apache-commons-rdf-0.5.0/commons-rdf-api/src/main/resources/META-INF/ 0000755 0001750 0001750 00000000000 13212356336 024737 5 ustar andrius andrius apache-commons-rdf-0.5.0/commons-rdf-api/src/main/resources/META-INF/NOTICE 0000644 0001750 0001750 00000000254 13212356336 025644 0 ustar andrius andrius Apache Commons RDF
Copyright 2015-2017 The Apache Software Foundation
This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).
apache-commons-rdf-0.5.0/commons-rdf-api/src/main/resources/META-INF/LICENSE 0000644 0001750 0001750 00000026136 13175733174 025763 0 ustar andrius andrius
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed 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.
apache-commons-rdf-0.5.0/commons-rdf-api/src/site/ 0000755 0001750 0001750 00000000000 13175733174 021614 5 ustar andrius andrius apache-commons-rdf-0.5.0/commons-rdf-api/src/site/resources/ 0000755 0001750 0001750 00000000000 13175733174 023626 5 ustar andrius andrius apache-commons-rdf-0.5.0/commons-rdf-api/src/site/resources/profile.japicmp 0000644 0001750 0001750 00000000000 13175733174 026621 0 ustar andrius andrius apache-commons-rdf-0.5.0/commons-rdf-api/src/site/resources/profile.jacoco 0000644 0001750 0001750 00000000000 13175733174 026434 0 ustar andrius andrius apache-commons-rdf-0.5.0/commons-rdf-api/src/test/ 0000755 0001750 0001750 00000000000 14132221255 021611 5 ustar andrius andrius apache-commons-rdf-0.5.0/commons-rdf-api/src/test/java/ 0000755 0001750 0001750 00000000000 13175733174 022550 5 ustar andrius andrius apache-commons-rdf-0.5.0/commons-rdf-api/src/test/java/org/ 0000755 0001750 0001750 00000000000 14132221255 023321 5 ustar andrius andrius apache-commons-rdf-0.5.0/commons-rdf-api/src/test/java/org/apache/ 0000755 0001750 0001750 00000000000 13175733174 024560 5 ustar andrius andrius apache-commons-rdf-0.5.0/commons-rdf-api/src/test/java/org/apache/commons/ 0000755 0001750 0001750 00000000000 14132221255 026215 5 ustar andrius andrius apache-commons-rdf-0.5.0/commons-rdf-api/src/test/java/org/apache/commons/rdf/ 0000755 0001750 0001750 00000000000 13175733174 027006 5 ustar andrius andrius apache-commons-rdf-0.5.0/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/ 0000755 0001750 0001750 00000000000 13175733174 027557 5 ustar andrius andrius ././@LongLink 0000644 0000000 0000000 00000000155 00000000000 011604 L ustar root root apache-commons-rdf-0.5.0/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/AbstractBlankNodeTest.java apache-commons-rdf-0.5.0/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/AbstractBlankNodeT0000644 0001750 0001750 00000020663 13175733174 033156 0 ustar andrius andrius /**
* 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 org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
/**
* Abstract test class for the BlankNode interface.
*/
public abstract class AbstractBlankNodeTest {
/**
* This method must be overridden by the implementing test to create a
* {@link BlankNode} to be tested.
* Test
and provide {@link #createFactory()} which minimally
* must support {@link RDF#createDataset()} and {@link RDF#createIRI(String)}, but
* ideally support all operations.
*
* SELECT ?orgName WHERE {
* ?org foaf:name ?orgName .
* ?alice foaf:member ?org .
* ?bob foaf:member ?org .
* ?alice foaf:knows ?bob .
* FILTER NOT EXIST { ?bob foaf:knows ?alice }
* }
*
*
* @throws Exception If test fails
*/
@Test
public void whyJavaStreamsMightNotTakeOverFromSparql() throws Exception {
Assume.assumeNotNull(bnode1, bnode2, secretClubName);
// Find a secret organizations
try (Stream extends Quad> stream = dataset.stream(null, null, knows, null)) {
assertEquals("\"The Secret Club\"",
// Find One-way "knows"
stream.filter(t -> !dataset.contains(null, (BlankNodeOrIRI) t.getObject(), knows, t.getSubject()))
.map(knowsQuad -> {
try (Stream extends Quad> memberOf = dataset
// and those they know, what are they
// member of?
.stream(null, (BlankNodeOrIRI) knowsQuad.getObject(), member, null)) {
return memberOf
// keep those which first-guy is a
// member of
.filter(memberQuad -> dataset.contains(null, knowsQuad.getSubject(), member,
// First hit is good enough
memberQuad.getObject()))
.findFirst().get().getObject();
}
})
// then look up the name of that org
.map(org -> {
try (Stream extends Quad> orgName = dataset.stream(null, (BlankNodeOrIRI) org, name,
null)) {
return orgName.findFirst().get().getObject().ntriplesString();
}
}).findFirst().get());
}
}
}
apache-commons-rdf-0.5.0/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/DummyQuadTest.java0000644 0001750 0001750 00000003425 13175733174 033174 0 ustar andrius andrius /**
* 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 static org.junit.Assert.*;
import java.util.Objects;
import org.junit.Test;
public class DummyQuadTest {
Quad quad = new DummyQuad();
@Test
public void getGraphName() throws Exception {
assertFalse(quad.getGraphName().isPresent());
}
@Test
public void getSubject() throws Exception {
assertEquals(1, ((DummyIRI) quad.getSubject()).i);
}
@Test
public void getPredicate() throws Exception {
assertEquals(2, ((DummyIRI) quad.getPredicate()).i);
}
@Test
public void getObject() throws Exception {
assertEquals(3, ((DummyIRI) quad.getObject()).i);
}
@Test
public void equals() throws Exception {
assertEquals(quad, new DummyQuad());
}
@Test
public void testHashCode() {
final int expected = Objects.hash(quad.getSubject(), quad.getPredicate(), quad.getObject(), quad.getGraphName());
assertEquals(expected, quad.hashCode());
}
}
apache-commons-rdf-0.5.0/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/DummyIRITest.java 0000644 0001750 0001750 00000003245 13175733174 032725 0 ustar andrius andrius /**
* 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 static org.junit.Assert.*;
import org.junit.Test;
public class DummyIRITest {
DummyIRI iri = new DummyIRI(1337);
@Test
public void i() throws Exception {
assertEquals(1337, iri.i);
}
@Test
public void equals() throws Exception {
assertEquals(iri, new DummyIRI(1337));
}
@Test
public void notEquals() throws Exception {
assertNotEquals(iri, new DummyIRI(1));
}
@Test
public void ntriplesString() throws Exception {
assertEquals("Test
and provide {@link #createFactory()} which minimally
* must support {@link RDF#createGraph()} and {@link RDF#createIRI(String)}, but
* ideally support all operations.
*
* SELECT ?orgName WHERE {
* ?org foaf:name ?orgName .
* ?alice foaf:member ?org .
* ?bob foaf:member ?org .
* ?alice foaf:knows ?bob .
* FILTER NOT EXIST { ?bob foaf:knows ?alice }
* }
*
*
* @throws Exception If test fails
*/
@Test
public void whyJavaStreamsMightNotTakeOverFromSparql() throws Exception {
Assume.assumeNotNull(bnode1, bnode2, secretClubName);
// Find a secret organizations
try (Stream extends Triple> stream = graph.stream(null, knows, null)) {
assertEquals("\"The Secret Club\"",
// Find One-way "knows"
stream.filter(t -> !graph.contains((BlankNodeOrIRI) t.getObject(), knows, t.getSubject()))
.map(knowsTriple -> {
try (Stream extends Triple> memberOf = graph
// and those they know, what are they
// member of?
.stream((BlankNodeOrIRI) knowsTriple.getObject(), member, null)) {
return memberOf
// keep those which first-guy is a
// member of
.filter(memberTriple -> graph.contains(knowsTriple.getSubject(), member,
// First hit is good enough
memberTriple.getObject()))
.findFirst().get().getObject();
}
})
// then look up the name of that org
.map(org -> {
try (Stream extends Triple> orgName = graph.stream((BlankNodeOrIRI) org, name,
null)) {
return orgName.findFirst().get().getObject().ntriplesString();
}
}).findFirst().get());
}
}
}
././@LongLink 0000644 0000000 0000000 00000000147 00000000000 011605 L ustar root root apache-commons-rdf-0.5.0/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/DummyTripleTest.java apache-commons-rdf-0.5.0/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/DummyTripleTest.ja0000644 0001750 0001750 00000003241 13175733174 033206 0 ustar andrius andrius /**
* 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 static org.junit.Assert.*;
import java.util.Objects;
import org.junit.Test;
public class DummyTripleTest {
Triple triple = new DummyTriple();
@Test
public void getSubject() throws Exception {
assertEquals(1, ((DummyIRI) triple.getSubject()).i);
}
@Test
public void getPredicate() throws Exception {
assertEquals(2, ((DummyIRI) triple.getPredicate()).i);
}
@Test
public void getObject() throws Exception {
assertEquals(3, ((DummyIRI) triple.getObject()).i);
}
@Test
public void equals() throws Exception {
assertEquals(triple, new DummyTriple());
}
@Test
public void testHashCode() {
final int expected = Objects.hash(triple.getSubject(), triple.getPredicate(), triple.getObject());
assertEquals(expected, triple.hashCode());
}
}
././@LongLink 0000644 0000000 0000000 00000000150 00000000000 011577 L ustar root root apache-commons-rdf-0.5.0/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/DummyDatasetTest.java apache-commons-rdf-0.5.0/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/DummyDatasetTest.j0000644 0001750 0001750 00000006303 13175733174 033175 0 ustar andrius andrius /**
* 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 static org.junit.Assert.*;
import org.junit.Test;
public class DummyDatasetTest {
Dataset dataset = new DummyDataset();
@Test
public void add() throws Exception {
dataset.add(new DummyQuad());
}
@Test
public void addSPO() throws Exception {
dataset.add(null, new DummyIRI(1), new DummyIRI(2), new DummyIRI(3));
}
@Test
public void contains() throws Exception {
assertTrue(dataset.contains(new DummyQuad()));
}
@Test
public void containsSPO() throws Exception {
assertTrue(dataset.contains(null, null, null, null));
assertTrue(dataset.contains(null, new DummyIRI(1), new DummyIRI(2), new DummyIRI(3)));
assertFalse(dataset.contains(null, new DummyIRI(0), new DummyIRI(0), new DummyIRI(0)));
}
@Test(expected = IllegalStateException.class)
public void clearNotSupported() throws Exception {
dataset.clear();
}
@Test(expected = IllegalStateException.class)
public void remove() throws Exception {
dataset.remove(new DummyQuad());
}
@Test
public void removeSPO() throws Exception {
dataset.remove(null, new DummyIRI(0), new DummyIRI(0), new DummyIRI(0));
}
@Test
public void size() throws Exception {
assertEquals(1, dataset.size());
}
@Test
public void stream() throws Exception {
assertEquals(new DummyQuad(), dataset.stream().findAny().get());
}
@Test
public void streamFiltered() throws Exception {
assertEquals(new DummyQuad(), dataset.stream(null, null, null, null).findAny().get());
assertEquals(new DummyQuad(),
dataset.stream(null, new DummyIRI(1), new DummyIRI(2), new DummyIRI(3)).findAny().get());
assertFalse(dataset.stream(null, new DummyIRI(0), new DummyIRI(0), new DummyIRI(0)).findAny().isPresent());
}
@Test
public void getGraph() throws Exception {
assertTrue(dataset.getGraph() instanceof DummyGraph);
}
@Test
public void getGraphNull() throws Exception {
assertTrue(dataset.getGraph(null).get() instanceof DummyGraph);
}
@Test
public void getGraphNamed() throws Exception {
assertFalse(dataset.getGraph(new DummyIRI(0)).isPresent());
}
@Test
public void getGraphNames() throws Exception {
assertFalse(dataset.getGraphNames().findAny().isPresent());
}
}
././@LongLink 0000644 0000000 0000000 00000000150 00000000000 011577 L ustar root root apache-commons-rdf-0.5.0/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/DefaultGraphTest.java apache-commons-rdf-0.5.0/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/DefaultGraphTest.j0000644 0001750 0001750 00000005153 13175733174 033144 0 ustar andrius andrius /**
* 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 static org.junit.Assert.*;
import org.junit.Test;
public class DefaultGraphTest {
DummyGraph graph = new DummyGraph();
@Test
public void close() throws Exception {
graph.close(); // no-op
}
@SuppressWarnings("deprecation")
@Test
public void defaultGetTriples() throws Exception {
assertFalse(graph.streamCalled);
assertFalse(graph.filteredStreamCalled);
assertEquals(1L, graph.getTriples().count());
assertTrue(graph.streamCalled);
assertFalse(graph.filteredStreamCalled);
}
@SuppressWarnings("deprecation")
@Test
public void defaultGetTriplesFiltered() throws Exception {
assertFalse(graph.streamCalled);
assertFalse(graph.filteredStreamCalled);
assertEquals(1L, graph.getTriples(null,null,null).count());
assertFalse(graph.streamCalled);
assertTrue(graph.filteredStreamCalled);
// Ensure arguments are passed on to graph.stream(s,p,o);
assertEquals(0L, graph.getTriples(new DummyIRI(0),null,null).count());
}
@Test
public void defaultIterate() throws Exception {
assertFalse(graph.streamCalled);
assertFalse(graph.filteredStreamCalled);
for (final Triple t : graph.iterate()) {
assertEquals(t, new DummyTriple());
}
assertTrue(graph.streamCalled);
assertFalse(graph.filteredStreamCalled);
}
@Test
public void defaultFilteredIterate() throws Exception {
assertFalse(graph.streamCalled);
assertFalse(graph.filteredStreamCalled);
for (final Triple t : graph.iterate(null, new DummyIRI(2), null)) {
assertEquals(t, new DummyTriple());
}
assertTrue(graph.filteredStreamCalled);
assertFalse(graph.streamCalled);
}
}
apache-commons-rdf-0.5.0/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/DummyIRI.java 0000644 0001750 0001750 00000002656 13175733174 032072 0 ustar andrius andrius /**
* 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;
class DummyIRI implements IRI {
static final String EXAMPLE_COM = "http://example.com/";
final int i;
public DummyIRI(final int i) {
this.i = i;
}
@Override
public String ntriplesString() {
return "<" + EXAMPLE_COM + i + ">";
}
@Override
public String getIRIString() {
return EXAMPLE_COM + i;
}
@Override
public boolean equals(final Object obj) {
return (obj instanceof IRI) && ((IRI) obj).getIRIString().equals(EXAMPLE_COM + i);
}
@Override
public int hashCode() {
return getIRIString().hashCode();
}
} apache-commons-rdf-0.5.0/commons-rdf-api/src/test/java/org/apache/commons/rdf/api/DummyDataset.java 0000644 0001750 0001750 00000007172 13175733174 033032 0 ustar andrius andrius /**
* 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.util.Arrays;
import java.util.Optional;
import java.util.stream.Stream;
class DummyDataset implements Dataset {
boolean streamCalled = false;
boolean filteredStreamCalled;
@Override
public void add(final Quad Quad) {
if (! contains(Quad)) {
throw new IllegalStateException("DummyDataset can't be modified");
}
}
@Override
public void add(final BlankNodeOrIRI graphName, final BlankNodeOrIRI subject, final IRI predicate, final RDFTerm object) {
if (! contains(Optional.ofNullable(graphName), subject, predicate, object)) {
throw new IllegalStateException("DummyDataset can't be modified");
}
}
@Override
public boolean contains(final Quad Quad) {
return Quad.equals(new DummyQuad());
}
@Override
public boolean contains(final OptionalTest
and provide {@link #createFactory()} which minimally
* supports one of the operations, but ideally supports all operations.
*
* @see RDF
*/
public abstract class AbstractRDFTest {
private RDF factory;
/**
*
* This method must be overridden by the implementing test to provide a
* factory for the test to create {@link Literal}, {@link IRI} etc.
*
* @return {@link RDF} instance to be tested.
*/
protected abstract RDF createFactory();
@Before
public void setUp() {
factory = createFactory();
}
@Test
public void testCreateBlankNode() throws Exception {
final BlankNode bnode = factory.createBlankNode();
final BlankNode bnode2 = factory.createBlankNode();
assertNotEquals("Second blank node has not got a unique internal identifier", bnode.uniqueReference(),
bnode2.uniqueReference());
}
@Test
public void testCreateBlankNodeIdentifierEmpty() throws Exception {
try {
factory.createBlankNode("");
} catch (final IllegalArgumentException e) {
// Expected exception
}
}
@Test
public void testCreateBlankNodeIdentifier() throws Exception {
factory.createBlankNode("example1");
}
@Test
public void testCreateBlankNodeIdentifierTwice() throws Exception {
BlankNode bnode1, bnode2, bnode3;
bnode1 = factory.createBlankNode("example1");
bnode2 = factory.createBlankNode("example1");
bnode3 = factory.createBlankNode("differ");
// We don't know what the identifier is, but it MUST be the same
assertEquals(bnode1.uniqueReference(), bnode2.uniqueReference());
// We don't know what the ntriplesString is, but it MUST be the same
assertEquals(bnode1.ntriplesString(), bnode2.ntriplesString());
// and here it MUST differ
assertNotEquals(bnode1.uniqueReference(), bnode3.uniqueReference());
assertNotEquals(bnode1.ntriplesString(), bnode3.ntriplesString());
}
@Test
public void testCreateBlankNodeIdentifierTwiceDifferentFactories() throws Exception {
BlankNode bnode1, differentFactory;
bnode1 = factory.createBlankNode();
// it MUST differ from a second factory
differentFactory = createFactory().createBlankNode();
// NOTE: We can't make similar assumption if we provide a
// name to createBlankNode(String) as its documentation
// only says:
//
// * BlankNodes created using this method with the same parameter, for
// * different instances of RDFFactory, SHOULD NOT be equivalent.
//
// https://github.com/apache/incubator-commonsrdf/pull/7#issuecomment-92312779
assertNotEquals(bnode1, differentFactory);
assertNotEquals(bnode1.uniqueReference(), differentFactory.uniqueReference());
// but we can't require:
// assertNotEquals(bnode1.ntriplesString(),
// differentFactory.ntriplesString());
}
@Test
public void testCreateGraph() throws Exception {
try (final Graph graph = factory.createGraph(); final Graph graph2 = factory.createGraph()) {
assertEquals("Graph was not empty", 0, graph.size());
graph.add(factory.createBlankNode(), factory.createIRI("http://example.com/"), factory.createBlankNode());
assertNotSame(graph, graph2);
assertEquals("Graph was empty after adding", 1, graph.size());
assertEquals("New graph was not empty", 0, graph2.size());
}
}
@Test
public void testCreateIRI() throws Exception {
final IRI example = factory.createIRI("http://example.com/");
assertEquals("http://example.com/", example.getIRIString());
assertEquals("
*
*/
package org.apache.commons.rdf.simple.experimental; ././@LongLink 0000644 0000000 0000000 00000000174 00000000000 011605 L ustar root root apache-commons-rdf-0.5.0/commons-rdf-simple/src/main/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParser.java apache-commons-rdf-0.5.0/commons-rdf-simple/src/main/java/org/apache/commons/rdf/simple/experimental0000644 0001750 0001750 00000047634 13175733174 033422 0 ustar andrius andrius /**
* 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.RDF;
import org.apache.commons.rdf.experimental.RDFParser;
import org.apache.commons.rdf.simple.SimpleRDF;
/**
* Abstract RDFParser
* text/turtle
,
* or {@link Optional#empty()} if it has not been set
*/
public final Optionalnull
value (as a target is a required setting).
*
* @return The target consumer of {@link Quad}s, or null
if it
* has not yet been set.
*
*/
public Consumersuper.resetSource()
* 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 {@link Optional#empty()}.
* super.resetTarget()
* 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}.
* file:///
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()
final AbstractRDFParser.
* archive.tar.gz
would be .gz
*
* @param path
* Path which filename might contain an extension
* @return File extension (including the leading .
, or
* {@link Optional#empty()} if the path has no extension
*/
private static Optional
*
* null
for the default
* graph.
* <urn:uuid:b7ac3fcc-4d86-4d28-8358-a1cd094974a6> <http://example.com/greeting> "Hello world" .
*
*
* Additional triples match the corresponding getter in AbstractRDFParser, e.g.:
*
*
* <urn:uuid:b7ac3fcc-4d86-4d28-8358-a1cd094974a6> <http://example.com/base> <http://www.example.org/> .
* <urn:uuid:b7ac3fcc-4d86-4d28-8358-a1cd094974a6> <http://example.com/sourceFile> "/tmp/file.ttl" .
*
*
*
*/
public class DummyRDFParserBuilder extends AbstractRDFParserhttp://www.w3.org/1999/02/22-rdf-syntax-ns#PlainLiteral
to
indicate plain literals (untyped), which were distinct from
http://www.w3.org/2001/XMLSchema#string
(typed). Commons
RDF assumes RDF 1.1, which merges the two concepts as the second type, however
particular implementations might have explicit options for RDF 1.0 support, in
which case you might find Literal
instances with the deprecated
plain
literal data type.
> `
> `