You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commonsrdf.apache.org by an...@apache.org on 2015/03/30 03:09:55 UTC

[01/18] incubator-commonsrdf git commit: Map blank nodes to UUID's without storing local scope for each object

Repository: incubator-commonsrdf
Updated Branches:
  refs/heads/master cf5f5158d -> 20b0b000f


Map blank nodes to UUID's without storing local scope for each object


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

Branch: refs/heads/master
Commit: 9522337ba110a195c3adb4f80429f8cdaef7a2f3
Parents: a6d0a03
Author: Peter Ansell <p_...@yahoo.com>
Authored: Sat Mar 28 19:04:41 2015 +1100
Committer: Peter Ansell <p_...@yahoo.com>
Committed: Sat Mar 28 19:04:41 2015 +1100

----------------------------------------------------------------------
 .../commons/rdf/api/AbstractGraphTest.java      | 36 +++++-----
 .../rdf/api/AbstractRDFTermFactoryTest.java     | 11 +--
 .../commons/rdf/simple/BlankNodeImpl.java       | 36 +++++-----
 .../apache/commons/rdf/simple/GraphImpl.java    | 40 ++++++++++-
 .../apache/commons/rdf/simple/TripleImpl.java   | 70 +++-----------------
 5 files changed, 89 insertions(+), 104 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/9522337b/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java b/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
index ff21dd3..4c1d035 100644
--- a/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
+++ b/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
@@ -48,8 +48,8 @@ public abstract class AbstractGraphTest {
 	private IRI name;
 	private IRI knows;
 	private IRI member;
-	private BlankNode org1;
-	private BlankNode org2;
+	private BlankNode bnode1;
+	private BlankNode bnode2;
 	private Literal aliceName;
 	private Literal bobName;
 	private Literal secretClubName;
@@ -70,8 +70,8 @@ public abstract class AbstractGraphTest {
 		knows = factory.createIRI("http://xmlns.com/foaf/0.1/knows");
 		member = factory.createIRI("http://xmlns.com/foaf/0.1/member");
 		try {
-			org1 = factory.createBlankNode("org1");
-			org2 = factory.createBlankNode("org2");
+			bnode1 = factory.createBlankNode("org1");
+			bnode2 = factory.createBlankNode("org2");
 		} catch (UnsupportedOperationException ex) {
 			// leave as null
 		}
@@ -90,8 +90,8 @@ public abstract class AbstractGraphTest {
 		}
 		graph.add(alice, knows, bob);
 
-		if (org1 != null) {
-			graph.add(alice, member, org1);
+		if (bnode1 != null) {
+			graph.add(alice, member, bnode1);
 		}
 
 		if (bobName != null) {
@@ -104,12 +104,12 @@ public abstract class AbstractGraphTest {
 				graph.add(bobNameTriple);
 			}
 		}
-		if (org1 != null) {
-			graph.add(factory.createTriple(bob, member, org1));
-			graph.add(factory.createTriple(bob, member, org2));
+		if (bnode1 != null) {
+			graph.add(factory.createTriple(bob, member, bnode1));
+			graph.add(factory.createTriple(bob, member, bnode2));
 			if (secretClubName != null) {
-				graph.add(org1, name, secretClubName);
-				graph.add(org2, name, companyName);
+				graph.add(bnode1, name, secretClubName);
+				graph.add(bnode2, name, companyName);
 			}
 		}
 	}
@@ -123,14 +123,14 @@ public abstract class AbstractGraphTest {
 				.startsWith(
 						"<http://example.com/alice> <http://xmlns.com/foaf/0.1/name> \"Alice\" ."));
 		assertTrue(graph.toString().endsWith(
-				"_:org2 <http://xmlns.com/foaf/0.1/name> \"A company\" ."));
+				" <http://xmlns.com/foaf/0.1/name> \"A company\" ."));
 
 	}
 
 	@Test
 	public void size() throws Exception {
 		assertTrue(graph.size() > 0);
-		Assume.assumeNotNull(org1, org2, aliceName, bobName, secretClubName,
+		Assume.assumeNotNull(bnode1, bnode2, aliceName, bobName, secretClubName,
 				companyName, bobNameTriple);
 		// Can only reliably predict size if we could create all triples
 		assertEquals(8, graph.size());
@@ -211,7 +211,7 @@ public abstract class AbstractGraphTest {
 		assertTrue(tripleCount > 0);
 		assertTrue(graph.getTriples().allMatch(t -> graph.contains(t)));
 		// Check exact count
-		Assume.assumeNotNull(org1, org2, aliceName, bobName, secretClubName,
+		Assume.assumeNotNull(bnode1, bnode2, aliceName, bobName, secretClubName,
 				companyName, bobNameTriple);
 		assertEquals(8, tripleCount);
 	}
@@ -224,10 +224,10 @@ public abstract class AbstractGraphTest {
 		Assume.assumeNotNull(aliceName);
 		assertEquals(3, aliceCount);
 
-		Assume.assumeNotNull(org1, org2, bobName, companyName, secretClubName);
+		Assume.assumeNotNull(bnode1, bnode2, bobName, companyName, secretClubName);
 		assertEquals(4, graph.getTriples(null, name, null).count());
-		Assume.assumeNotNull(org1);
-		assertEquals(2, graph.getTriples(null, member, org1).count());
+		Assume.assumeNotNull(bnode1);
+		assertEquals(3, graph.getTriples(null, member, null).count());
 	}
 
 	/**
@@ -249,7 +249,7 @@ public abstract class AbstractGraphTest {
 	 */
 	@Test
 	public void whyJavaStreamsMightNotTakeOverFromSparql() throws Exception {
-		Assume.assumeNotNull(org1, org2, secretClubName);
+		Assume.assumeNotNull(bnode1, bnode2, secretClubName);
 		// Find a secret organizations
 		assertEquals(
 				"\"The Secret Club\"",

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/9522337b/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTermFactoryTest.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTermFactoryTest.java b/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTermFactoryTest.java
index a4f6e98..b45f6ba 100644
--- a/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTermFactoryTest.java
+++ b/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTermFactoryTest.java
@@ -83,16 +83,14 @@ public abstract class AbstractRDFTermFactoryTest {
 
 	@Test
 	public void testCreateBlankNodeIdentifier() throws Exception {
-		BlankNode bnode;
 		try {
-			bnode = factory.createBlankNode("example1");
+			factory.createBlankNode("example1");
 		} catch (UnsupportedOperationException ex) {
 			Assume.assumeNoException(ex);
 			return;
 		}
-		assertEquals("example1", bnode.internalIdentifier());
-		// .. but we can't assume the internal identifier leaks into
-		// ntriplesString
+		// We can't assume anything about the resulting bnode
+		// assertEquals("example1", bnode.internalIdentifier());
 		// assertEquals("_:example1", bnode.ntriplesString());
 	}
 
@@ -107,10 +105,13 @@ public abstract class AbstractRDFTermFactoryTest {
 			Assume.assumeNoException(ex);
 			return;
 		}
+		// We don't know what the identifier is, but it MUST be the same
 		assertEquals(bnode1.internalIdentifier(), bnode2.internalIdentifier());
 		// 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.internalIdentifier(),
+				bnode3.internalIdentifier());
 		assertNotEquals(bnode1.ntriplesString(), bnode3.ntriplesString());
 	}
 

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/9522337b/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java
index 398ad37..47cc211 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java
@@ -33,21 +33,28 @@ import org.apache.commons.rdf.api.Graph;
 final class BlankNodeImpl implements BlankNode {
 
 	private static AtomicLong bnodeCounter = new AtomicLong();
+
+	private static final Object DEFAULT_SEED = new Object();
+
 	private final String id;
-	private final Graph localScope;
 
 	public BlankNodeImpl() {
-		this(Optional.empty(), "b:" + bnodeCounter.incrementAndGet());
+		this(DEFAULT_SEED, "genid:" + bnodeCounter.incrementAndGet());
 	}
 
-	public BlankNodeImpl(Optional<Graph> localScope, String id) {
-		this.localScope = Objects.requireNonNull(localScope).orElse(null);
+	public BlankNodeImpl(Object uuidSeed, String id) {
 		if (Objects.requireNonNull(id).isEmpty()) {
 			throw new IllegalArgumentException("Invalid blank node id: " + id);
-			// NOTE: It is valid for the id to not be a valid ntriples bnode id.
-			// See ntriplesString().
 		}
-		this.id = id;
+		String uuidInput = uuidSeed.toString() + ":" + id;
+		// Both the scope and the id are used to create the UUID, ensuring that
+		// a caller can reliably create the same bnode if necessary by sending
+		// in the same scope.
+		// In addition, it would be very difficult for the default constructor
+		// to interfere with this process since it uses a local object as its
+		// reference.
+		this.id = UUID.nameUUIDFromBytes(
+				uuidInput.getBytes(StandardCharsets.UTF_8)).toString();
 	}
 
 	@Override
@@ -57,11 +64,6 @@ final class BlankNodeImpl implements BlankNode {
 
 	@Override
 	public String ntriplesString() {
-		if (id.contains(":")) {
-			return "_:u"
-					+ UUID.nameUUIDFromBytes(id
-							.getBytes(StandardCharsets.UTF_8));
-		}
 		return "_:" + id;
 	}
 
@@ -72,7 +74,7 @@ final class BlankNodeImpl implements BlankNode {
 
 	@Override
 	public int hashCode() {
-		return Objects.hash(localScope, id);
+		return id.hashCode();
 	}
 
 	@Override
@@ -83,6 +85,7 @@ final class BlankNodeImpl implements BlankNode {
 		if (obj == null) {
 			return false;
 		}
+		// We don't support equality with other implementations
 		if (!(obj instanceof BlankNodeImpl)) {
 			return false;
 		}
@@ -94,13 +97,6 @@ final class BlankNodeImpl implements BlankNode {
 		} else if (!id.equals(other.id)) {
 			return false;
 		}
-		if (localScope == null) {
-			if (other.localScope != null) {
-				return false;
-			}
-		} else if (!localScope.equals(other.localScope)) {
-			return false;
-		}
 		return true;
 	}
 

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/9522337b/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
index 30ab15e..81bbcee 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
@@ -25,9 +25,11 @@ import java.util.function.Predicate;
 import java.util.stream.Collectors;
 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.Graph;
 import org.apache.commons.rdf.api.IRI;
+import org.apache.commons.rdf.api.Literal;
 import org.apache.commons.rdf.api.RDFTerm;
 import org.apache.commons.rdf.api.Triple;
 
@@ -51,10 +53,44 @@ final class GraphImpl implements Graph {
 
 	}
 
+	private <T extends RDFTerm> RDFTerm internallyMap(T object) {
+		if (object instanceof BlankNode) {
+			BlankNode blankNode = (BlankNode) object;
+			// This guarantees that adding the same BlankNode multiple times to
+			// this graph will generate a local object that is mapped to an
+			// equivalent object, based on the code in the package private
+			// BlankNodeImpl class
+			return new BlankNodeImpl(this, blankNode.internalIdentifier());
+		} else if (object instanceof IRI && !(object instanceof IRIImpl)) {
+			IRI iri = (IRI) object;
+			return new IRIImpl(iri.getIRIString());
+		} else if (object instanceof Literal
+				&& !(object instanceof LiteralImpl)) {
+			Literal literal = (Literal) object;
+			if (literal.getLanguageTag().isPresent()) {
+				return new LiteralImpl(literal.getLexicalForm(), literal
+						.getLanguageTag().get());
+			} else {
+				return new LiteralImpl(literal.getLexicalForm(),
+						(IRI) internallyMap(literal.getDatatype()));
+			}
+		} else {
+			return object;
+		}
+	}
+
 	@Override
 	public void add(Triple triple) {
-		triples.add(new TripleImpl(Optional.of(this), Objects
-				.requireNonNull(triple)));
+		if (!(triple instanceof TripleImpl)) {
+			BlankNodeOrIRI subject = (BlankNodeOrIRI) internallyMap(triple
+					.getSubject());
+			IRI predicate = (IRI) internallyMap(triple.getPredicate());
+			RDFTerm object = internallyMap(triple.getObject());
+			triples.add(new TripleImpl(subject, predicate, object));
+		} else {
+			triples.add(new TripleImpl(triple.getSubject(), triple
+					.getPredicate(), triple.getObject()));
+		}
 	}
 
 	@Override

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/9522337b/simple/src/main/java/org/apache/commons/rdf/simple/TripleImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/TripleImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/TripleImpl.java
index 6c9c825..0fe76d9 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/TripleImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/TripleImpl.java
@@ -18,13 +18,9 @@
 package org.apache.commons.rdf.simple;
 
 import java.util.Objects;
-import java.util.Optional;
 
-import org.apache.commons.rdf.api.BlankNode;
 import org.apache.commons.rdf.api.BlankNodeOrIRI;
-import org.apache.commons.rdf.api.Graph;
 import org.apache.commons.rdf.api.IRI;
-import org.apache.commons.rdf.api.Literal;
 import org.apache.commons.rdf.api.RDFTerm;
 import org.apache.commons.rdf.api.Triple;
 
@@ -41,64 +37,20 @@ final class TripleImpl implements Triple {
 	/**
 	 * Construct Triple from its constituent parts.
 	 * <p>
-	 * The parts may be copied to ensure they are in scope.
+	 * The objects are not changed. All mapping of BNode objects is done in
+	 * {@link SimpleRDFTermFactory#createTriple(BlankNodeOrIRI, IRI, RDFTerm)}.
 	 * 
-	 * @param subject subject of triple
-	 * @param predicate predicate of triple
-	 * @param object object of triple
+	 * @param subject
+	 *            subject of triple
+	 * @param predicate
+	 *            predicate of triple
+	 * @param object
+	 *            object of triple
 	 */
 	public TripleImpl(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
-		this.subject = (BlankNodeOrIRI) inScope(Optional.empty(),
-				Objects.requireNonNull(subject));
-		this.predicate = (IRI) inScope(null, Objects.requireNonNull(predicate));
-		this.object = inScope(Optional.empty(), Objects.requireNonNull(object));
-	}
-
-	/**
-	 * Construct Triple by cloning another Triple and its constituent parts.
-	 * <p>
-	 * The parts of the triple may be copied to ensure they are in scope.
-	 * 
-	 * @param localScope
-	 *            Scope to create new triple in.
-	 * @param triple
-	 *            Triple to clone
-	 */
-	public TripleImpl(Optional<Graph> localScope, Triple triple) {
-		Objects.requireNonNull(localScope);
-		Objects.requireNonNull(triple);
-
-		this.subject = (BlankNodeOrIRI) inScope(localScope, triple.getSubject());
-		this.predicate = (IRI) inScope(localScope, triple.getPredicate());
-		this.object = inScope(localScope, triple.getObject());
-	}
-
-	private RDFTerm inScope(Optional<Graph> localScope, RDFTerm object) {
-		if (!(object instanceof BlankNode) && !(object instanceof IRI)
-				& !(object instanceof Literal)) {
-			throw new IllegalArgumentException(
-					"RDFTerm must be BlankNode, IRI or Literal");
-		}
-		if (object instanceof BlankNode) {
-			BlankNode blankNode = (BlankNode) object;
-			return new BlankNodeImpl(Objects.requireNonNull(localScope),
-					blankNode.internalIdentifier());
-		} else if (object instanceof IRI && !(object instanceof IRIImpl)) {
-			IRI iri = (IRI) object;
-			return new IRIImpl(iri.getIRIString());
-		} else if (object instanceof Literal
-				&& !(object instanceof LiteralImpl)) {
-			Literal literal = (Literal) object;
-			if (literal.getLanguageTag().isPresent()) {
-				return new LiteralImpl(literal.getLexicalForm(), literal
-						.getLanguageTag().get());
-			} else {
-				IRI dataType = (IRI) inScope(localScope, literal.getDatatype());
-				return new LiteralImpl(literal.getLexicalForm(), dataType);
-			}
-		} else {
-			return object;
-		}
+		this.subject = Objects.requireNonNull(subject);
+		this.predicate = Objects.requireNonNull(predicate);
+		this.object = Objects.requireNonNull(object);
 	}
 
 	@Override


[08/18] incubator-commonsrdf git commit: Verify the results of TestWritingGraph

Posted by an...@apache.org.
Verify the results of TestWritingGraph


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

Branch: refs/heads/master
Commit: 5364be39a69ea92a71a07a54c608adab1320f291
Parents: c75c537
Author: Peter Ansell <p_...@yahoo.com>
Authored: Sat Mar 28 21:04:14 2015 +1100
Committer: Peter Ansell <p_...@yahoo.com>
Committed: Sat Mar 28 21:04:14 2015 +1100

----------------------------------------------------------------------
 .../apache/commons/rdf/simple/TestWritingGraph.java   | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/5364be39/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java b/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java
index f4a5857..3c0ab63 100644
--- a/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java
@@ -17,6 +17,8 @@
  */
 package org.apache.commons.rdf.simple;
 
+import static org.junit.Assert.*;
+
 import java.nio.charset.Charset;
 import java.nio.file.Files;
 import java.nio.file.Path;
@@ -39,7 +41,7 @@ public class TestWritingGraph {
 	 * 200k triples should do - about 7 MB on disk. Override with
 	 * -Dtriples=20000000 to exercise your memory banks.
 	 */
-	private static final int TRIPLES = Integer.getInteger("triples", 200000);
+	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");
@@ -52,7 +54,7 @@ public class TestWritingGraph {
 	public static void createGraph() throws Exception {
 		factory = new SimpleRDFTermFactory();
 		graph = factory.createGraph();
-		BlankNode subject = factory.createBlankNode("subj");
+		IRI subject = factory.createIRI("subj");
 		IRI predicate = factory.createIRI("pred");
 		List<IRI> types = new ArrayList<>(Types.values());
 		// Ensure we don't try to create a literal with rdf:langString but
@@ -60,7 +62,10 @@ public class TestWritingGraph {
 		types.remove(Types.RDF_LANGSTRING);
 		Collections.shuffle(types);
 		for (int i = 0; i < TRIPLES; i++) {
-			if (i % 5 == 0) {
+			if (i % 11 == 0) {
+				graph.add(subject, predicate,
+						factory.createBlankNode("Example " + i));
+			} else if (i % 5 == 0) {
 				graph.add(subject, predicate,
 						factory.createLiteral("Example " + i, "en"));
 			} else if (i % 3 == 0) {
@@ -89,11 +94,12 @@ public class TestWritingGraph {
 
 	@Test
 	public void countQuery() {
-		BlankNode subject = factory.createBlankNode("subj");
+		IRI subject = factory.createIRI("subj");
 		IRI predicate = factory.createIRI("pred");
 		long count = graph.getTriples(subject, predicate, null).unordered()
 				.parallel().count();
 		System.out.println("Counted - " + count);
+		assertEquals(count, TRIPLES);
 	}
 
 	@Test


[09/18] incubator-commonsrdf git commit: Add test to verify that filter with no matches is significantly faster

Posted by an...@apache.org.
Add test to verify that filter with no matches is significantly faster

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

Branch: refs/heads/master
Commit: 728270b68c0309ba5bbf2f4c83d1750015c8d51a
Parents: 5364be3
Author: Peter Ansell <p_...@yahoo.com>
Authored: Sat Mar 28 21:07:42 2015 +1100
Committer: Peter Ansell <p_...@yahoo.com>
Committed: Sat Mar 28 21:07:42 2015 +1100

----------------------------------------------------------------------
 .../commons/rdf/simple/TestWritingGraph.java    | 22 +++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/728270b6/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java b/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java
index 3c0ab63..681c6e9 100644
--- a/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java
@@ -111,8 +111,7 @@ public class TestWritingGraph {
 			graphFile.toFile().deleteOnExit();
 		}
 
-		Stream<CharSequence> stream = graph.getTriples().unordered()
-				.map(Object::toString);
+		Stream<CharSequence> stream = graph.getTriples().map(Object::toString);
 		Files.write(graphFile, stream::iterator, Charset.forName("UTF-8"));
 	}
 
@@ -125,7 +124,24 @@ public class TestWritingGraph {
 			graphFile.toFile().deleteOnExit();
 		}
 
-		BlankNode subject = factory.createBlankNode("subj");
+		IRI subject = factory.createIRI("subj");
+		IRI predicate = factory.createIRI("pred");
+		Stream<CharSequence> stream = graph
+				.getTriples(subject, predicate, null).map(Object::toString);
+		Files.write(graphFile, stream::iterator, Charset.forName("UTF-8"));
+
+	}
+
+	@Test
+	public void writeGraphFromStreamFilteredNoMatches() throws Exception {
+		Path graphFile = Files.createTempFile("graph-empty-", ".nt");
+		if (KEEP_FILES) {
+			System.out.println("Filtered stream: " + graphFile);
+		} else {
+			graphFile.toFile().deleteOnExit();
+		}
+
+		IRI subject = factory.createIRI("nonexistent");
 		IRI predicate = factory.createIRI("pred");
 		Stream<CharSequence> stream = graph
 				.getTriples(subject, predicate, null).map(Object::toString);


[03/18] incubator-commonsrdf git commit: Optimise GraphImpl.add(Triple)

Posted by an...@apache.org.
Optimise GraphImpl.add(Triple)

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

Branch: refs/heads/master
Commit: 7e42caeef4d8eb3d784358b8b43b4d1262b567cc
Parents: 243e85c
Author: Peter Ansell <p_...@yahoo.com>
Authored: Sat Mar 28 20:31:32 2015 +1100
Committer: Peter Ansell <p_...@yahoo.com>
Committed: Sat Mar 28 20:32:09 2015 +1100

----------------------------------------------------------------------
 .../apache/commons/rdf/simple/GraphImpl.java    | 34 ++++++++++++--------
 1 file changed, 21 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/7e42caee/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
index 3fd4bca..5f81048 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
@@ -19,7 +19,6 @@ package org.apache.commons.rdf.simple;
 
 import java.util.LinkedHashSet;
 import java.util.Objects;
-import java.util.Optional;
 import java.util.Set;
 import java.util.function.Predicate;
 import java.util.stream.Collectors;
@@ -52,10 +51,28 @@ final class GraphImpl implements Graph {
 
 	@Override
 	public void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
-		add(new TripleImpl(Objects.requireNonNull(subject),
-				Objects.requireNonNull(predicate),
-				Objects.requireNonNull(object)));
+		BlankNodeOrIRI newSubject = (BlankNodeOrIRI) internallyMap(subject);
+		IRI newPredicate = (IRI) internallyMap(predicate);
+		RDFTerm newObject = internallyMap(object);
+		triples.add(factory.createTriple(newSubject, newPredicate, newObject));
+	}
 
+	@Override
+	public void add(Triple triple) {
+		BlankNodeOrIRI newSubject = (BlankNodeOrIRI) internallyMap(triple
+				.getSubject());
+		IRI newPredicate = (IRI) internallyMap(triple.getPredicate());
+		RDFTerm newObject = internallyMap(triple.getObject());
+		// Check if any of the object references changed during the mapping, to
+		// avoid creating a new Triple object if possible
+		if (newSubject == triple.getSubject()
+				&& newPredicate == triple.getPredicate()
+				&& newObject == triple.getObject()) {
+			triples.add(triple);
+		} else {
+			triples.add(factory.createTriple(newSubject, newPredicate,
+					newObject));
+		}
 	}
 
 	private <T extends RDFTerm> RDFTerm internallyMap(T object) {
@@ -87,15 +104,6 @@ final class GraphImpl implements Graph {
 	}
 
 	@Override
-	public void add(Triple triple) {
-		BlankNodeOrIRI subject = (BlankNodeOrIRI) internallyMap(triple
-				.getSubject());
-		IRI predicate = (IRI) internallyMap(triple.getPredicate());
-		RDFTerm object = internallyMap(triple.getObject());
-		triples.add(factory.createTriple(subject, predicate, object));
-	}
-
-	@Override
 	public void clear() {
 		triples.clear();
 	}


[04/18] incubator-commonsrdf git commit: rename seed to salt, which seems more appropriate

Posted by an...@apache.org.
rename seed to salt, which seems more appropriate

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

Branch: refs/heads/master
Commit: bfd037e6cf3efa5c9cbb18751ce83014448ceb06
Parents: 7e42cae
Author: Peter Ansell <p_...@yahoo.com>
Authored: Sat Mar 28 20:38:49 2015 +1100
Committer: Peter Ansell <p_...@yahoo.com>
Committed: Sat Mar 28 20:38:49 2015 +1100

----------------------------------------------------------------------
 .../org/apache/commons/rdf/simple/BlankNodeImpl.java     | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/bfd037e6/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java
index 47cc211..e54a7d9 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java
@@ -19,34 +19,31 @@ package org.apache.commons.rdf.simple;
 
 import java.nio.charset.StandardCharsets;
 import java.util.Objects;
-import java.util.Optional;
 import java.util.UUID;
 import java.util.concurrent.atomic.AtomicLong;
 
 import org.apache.commons.rdf.api.BlankNode;
-import org.apache.commons.rdf.api.Graph;
 
 /**
  * A simple implementation of BlankNode.
- *
  */
 final class BlankNodeImpl implements BlankNode {
 
 	private static AtomicLong bnodeCounter = new AtomicLong();
 
-	private static final Object DEFAULT_SEED = new Object();
+	private static final Object DEFAULT_SALT = new Object();
 
 	private final String id;
 
 	public BlankNodeImpl() {
-		this(DEFAULT_SEED, "genid:" + bnodeCounter.incrementAndGet());
+		this(DEFAULT_SALT, "genid:" + bnodeCounter.incrementAndGet());
 	}
 
-	public BlankNodeImpl(Object uuidSeed, String id) {
+	public BlankNodeImpl(Object uuidSalt, String id) {
 		if (Objects.requireNonNull(id).isEmpty()) {
 			throw new IllegalArgumentException("Invalid blank node id: " + id);
 		}
-		String uuidInput = uuidSeed.toString() + ":" + id;
+		String uuidInput = uuidSalt.toString() + ":" + id;
 		// Both the scope and the id are used to create the UUID, ensuring that
 		// a caller can reliably create the same bnode if necessary by sending
 		// in the same scope.


[02/18] incubator-commonsrdf git commit: Rewrite contracts relating to BlankNode to be based on RDFTermFactory objects

Posted by an...@apache.org.
Rewrite contracts relating to BlankNode to be based on RDFTermFactory
objects

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

Branch: refs/heads/master
Commit: 243e85c4ce679eb06e6ba00e55e7789e36025fe3
Parents: 9522337
Author: Peter Ansell <p_...@yahoo.com>
Authored: Sat Mar 28 20:22:29 2015 +1100
Committer: Peter Ansell <p_...@yahoo.com>
Committed: Sat Mar 28 20:22:29 2015 +1100

----------------------------------------------------------------------
 .../org/apache/commons/rdf/api/BlankNode.java   | 142 ++++++++-----------
 .../apache/commons/rdf/api/RDFTermFactory.java  |  59 +++++---
 .../apache/commons/rdf/simple/GraphImpl.java    |  30 ++--
 .../rdf/simple/SimpleRDFTermFactory.java        |   7 +-
 4 files changed, 115 insertions(+), 123 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/243e85c4/api/src/main/java/org/apache/commons/rdf/api/BlankNode.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/BlankNode.java b/api/src/main/java/org/apache/commons/rdf/api/BlankNode.java
index ff29d0b..ca6d198 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/BlankNode.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/BlankNode.java
@@ -17,39 +17,51 @@
  */
 package org.apache.commons.rdf.api;
 
+import java.util.UUID;
+
 /**
  * A <a href= "http://www.w3.org/TR/rdf11-concepts/#dfn-blank-node" >RDF-1.1
  * Blank Node</a>, as defined by <a href=
  * "http://www.w3.org/TR/rdf11-concepts/#section-blank-nodes" >RDF-1.1 Concepts
  * and Abstract Syntax</a>, a W3C Recommendation published on 25 February 2014.<br>
  * <p>
- * Note: 
- * <blockquote>
- *   <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-blank-node">Blank nodes</a>
- *   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.
- * </blockquote>
+ * Note: <blockquote> <a
+ * href="http://www.w3.org/TR/rdf11-concepts/#dfn-blank-node">Blank nodes</a>
+ * 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. </blockquote>
  * <p>
- * Also note that: 
- * <blockquote>
- * <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-blank-node-identifier">Blank node identifiers</a>
- * are local identifiers that are used in
- * some concrete RDF syntaxes or RDF store implementations. They are always
- * <em>locally scoped</em> to the file or RDF store, and are <em>not</em> persistent 
- * or portable
- * identifiers for blank nodes. Blank node identifiers are <em>not</em> 
- * part of the RDF
- * abstract syntax, but are entirely dependent on the concrete syntax or
+ * Also note that: <blockquote> <a
+ * href="http://www.w3.org/TR/rdf11-concepts/#dfn-blank-node-identifier">Blank
+ * node identifiers</a> are local identifiers that are used in some concrete RDF
+ * syntaxes or RDF store implementations. They are always
+ * <em>locally scoped</em> to the file or RDF store, and are <em>not</em>
+ * persistent or portable identifiers for blank nodes. Blank node identifiers
+ * are <em>not</em> 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.
- * The syntactic restrictions on blank node identifiers, if any,
- * therefore also depend on the concrete RDF syntax or implementation.
  * <p>
  * 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.
- * </blockquote>
+ * by the syntax. </blockquote>
+ * <p>
+ * A BlankNode object created through the
+ * {@link RDFTermFactory#createBlankNode()} method must be universally unique,
+ * and SHOULD contain a {@link UUID} as part of its
+ * {@link #internalIdentifier()}.
+ * <p>
+ * A BlankNode object created through the
+ * {@link RDFTermFactory#createBlankNode(String)} method must be universally
+ * unique, but also produce the same {@link #internalIdentifier()} as any
+ * previous or future calls to that method on that factory with the same
+ * parameters. In addition, it SHOULD contain a {@link UUID} as part of its
+ * {@link #internalIdentifier()}, created using
+ * {@link UUID#nameUUIDFromBytes(byte[])} using a constant salt for each
+ * instance of {@link RDFTermFactory}, with the given identifier joined to that
+ * salt in a consistent manner.
+ * <p>
  *
  * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-blank-node">RDF-1.1
  *      Blank Node</a>
@@ -58,80 +70,42 @@ public interface BlankNode extends BlankNodeOrIRI {
 
 	/**
 	 * Return a <a href=
-	 * "http://www.w3.org/TR/rdf11-concepts/#dfn-blank-node-identifier"
-	 * >label</a> for the blank node. This is not a serialization/syntax label.
-	 * It should be uniquely identifying within the local scope it is created in
-	 * but has no uniqueness guarantees other than that.
+	 * "http://www.w3.org/TR/rdf11-concepts/#dfn-blank-node-identifier" >unique
+	 * label</a> for the blank node. This label is generated by either
+	 * {@link RDFTermFactory#createBlankNode()} or
+	 * {@link RDFTermFactory#createBlankNode(String)} and is unique within the
+	 * context of the instance of the factory. In particular, successive calls
+	 * to the {@link RDFTermFactory#createBlankNode(String)} method on a single
+	 * factory with the same parameters MUST return BlankNode objects with
+	 * identical internalIdentifiers, but the identifiers SHOULD be mapped to
+	 * unique values in the context of the factory instance.
 	 * <p>
-	 * In particular, the existence of two objects of type {@link BlankNode}
-	 * with the same value returned from {@link #internalIdentifier()} are not
-	 * equivalent unless they are known to have been created in the same local
-	 * scope (see {@link #equals(Object)})
+	 * IMPORTANT: This is not a serialization/syntax label, and there are no
+	 * guarantees that it is a valid identifier in any concrete syntax. For an
+	 * N-Triples compatible identifier use {@link #ntriplesString()}. For all
+	 * other syntaxes, the result of this method must be sanitized to produce a
+	 * valid concrete identifier if one is needed.
 	 * <p>
-	 * An example of a local scope may be an instance of a Java Virtual Machine
-	 * (JVM). In the context of a JVM instance, an implementor may support
-	 * insertion and removal of {@link Triple} objects containing Blank Nodes
-	 * without modifying the blank node labels.
-	 * <p>
-	 * Another example of a local scope may be a <a
-	 * href="http://www.w3.org/TR/rdf11-concepts/#section-rdf-graph">Graph</a>
-	 * or <a
-	 * href="http://www.w3.org/TR/rdf11-concepts/#section-dataset">Dataset</a>
-	 * created from a single document. In this context, an implementor should
-	 * reasonably guarantee that the label returned by getLabel only maps to
-	 * equivalent blank nodes in the same Graph or Dataset, but they may not
-	 * guarantee that it is unique for the JVM instance. In this case, the
-	 * implementor may support a mechanism to provide a mapping for blank nodes
-	 * between Graph or Dataset instances to guarantee their uniqueness.
-	 * <p>
-	 * If implementors support <a
-	 * href="http://www.w3.org/TR/rdf11-concepts/#section-skolemization"
-	 * >Skolemisation</a>, they may map instances of {@link BlankNode} objects
-	 * to {@link IRI} objects to reduce scoping issues.
-	 * <p>
-	 * It is not a requirement for the internal identifier to be a part of the
-	 * {@link #ntriplesString()}, except that two BlankNode instances with the
-	 * same internalIdentifier() and same local scope should have the same
-	 * {@link #ntriplesString()}.
-	 *
-	 * @return An internal, system identifier for the {@link BlankNode}.
+	 * 
+	 * @return An internal, system identifier for the {@link BlankNode} that is
+	 *         used primarily to check whether two BlankNode's are equivalent.
 	 */
 	String internalIdentifier();
 
 	/**
-	 * Check it this BlankNode is equal to another BlankNode. <blockquote> <a
-	 * href
-	 * ="http://www.w3.org/TR/rdf11-concepts/#dfn-blank-node-identifier">Blank
-	 * node identifiers</a> 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 <em>not</em> persistent or portable
-	 * identifiers for blank nodes. Blank node identifiers are <em>not</em> 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. 
-	 * <p>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. 
-	 * </blockquote>
-	 * <p>
-	 * Implementations MUST check the local scope, as two BlankNode in different
-	 * Graphs MUST differ. On the other hand, two BlankNodes found in triples of
-	 * the same Graph instance MUST equal if and only if they have the same
-	 * {@link #internalIdentifier()}.
-	 * </p>
+	 * Check it this BlankNode is equal to another BlankNode. Two BlankNodes
+	 * MUST be equal if, and only if, they have the same
+	 * {@link #internalIdentifier()}. </p>
 	 * <p>
 	 * Implementations MUST also override {@link #hashCode()} so that two equal
 	 * Literals produce the same hash code.
 	 * </p>
 	 * 
-	 * @see Object#equals(Object)
-	 * 
 	 * @param other
 	 *            Another object
 	 * @return true if other is a BlankNode, is in the same local scope and is
 	 *         equal to this BlankNode
+	 * @see Object#equals(Object)
 	 */
 	@Override
 	public boolean equals(Object other);
@@ -139,12 +113,12 @@ public interface BlankNode extends BlankNodeOrIRI {
 	/**
 	 * Calculate a hash code for this BlankNode.
 	 * <p>
-	 * This method MUST be implemented when implementing {@link #equals(Object)}
-	 * so that two equal BlankNodes produce the same hash code.
-	 * 
-	 * @see Object#hashCode()
+	 * 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();

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/243e85c4/api/src/main/java/org/apache/commons/rdf/api/RDFTermFactory.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/RDFTermFactory.java b/api/src/main/java/org/apache/commons/rdf/api/RDFTermFactory.java
index e0a64ff..3cbd430 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/RDFTermFactory.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/RDFTermFactory.java
@@ -18,6 +18,7 @@
 package org.apache.commons.rdf.api;
 
 import java.util.Locale;
+import java.util.UUID;
 
 /**
  * Factory for creating RDFTerm and Graph instances.
@@ -33,7 +34,6 @@ import java.util.Locale;
  * because an IRI is considered invalid, then it SHOULD throw
  * IllegalArgumentException.
  * 
- * 
  * @see RDFTerm
  * @see Graph
  * 
@@ -43,12 +43,16 @@ public interface RDFTermFactory {
 	/**
 	 * Create a new blank node.
 	 * <p>
-	 * Two BlankNodes created with this method MUST NOT be equal.
+	 * All pairs of {@link BlankNode}s created with this method MUST NOT be
+	 * equal.
 	 * <p>
 	 * If supported, the {@link BlankNode#internalIdentifier()} of the returned
-	 * blank node MUST be an auto-generated value.
+	 * blank node MUST be a universally unique value across both this and any
+	 * other {@link RDFTermFactory} objects running in the JVM when compared
+	 * with both past and future calls both to this method, and calls to
+	 * {@link #createBlankNode(String)} with any inputs.
 	 * 
-	 * @return A new BlankNode
+	 * @return A new {@link BlankNode}
 	 * @throws UnsupportedOperationException
 	 *             If the operation is not supported.
 	 */
@@ -58,28 +62,37 @@ public interface RDFTermFactory {
 	}
 
 	/**
-	 * Create a blank node for the given internal identifier.
+	 * Create a blank node based on the given identifier.
 	 * <p>
-	 * Two BlankNodes created with the same identifier using this method MUST be
-	 * equal if they are in the same local scope (e.g. in the same Graph). See
-	 * the equals contract for {@link BlankNode} for more information.
+	 * All BlankNodes created using this method with the same parameter for a
+	 * single instance of RDFTermFactory MUST be equivalent. Ie,
+	 * {@link BlankNode#equals(Object)} MUST return true. A BlankNode object
+	 * created through the {@link RDFTermFactory#createBlankNode()} method must
+	 * be universally unique, and SHOULD contain a {@link UUID} as part of its
+	 * {@link #internalIdentifier()}.
 	 * <p>
-	 * If supported, the {@link BlankNode#internalIdentifier()} of the returned
-	 * blank node MAY be equal to the provided identifier.
+	 * A BlankNode object created through the
+	 * {@link RDFTermFactory#createBlankNode(String)} method must be universally
+	 * unique, but also produce the same {@link #internalIdentifier()} as any
+	 * previous or future calls to that method on that factory with the same
+	 * parameters. In addition, it SHOULD contain a {@link UUID} as part of its
+	 * {@link #internalIdentifier()}, created using
+	 * {@link UUID#nameUUIDFromBytes(byte[])} using a constant salt for each
+	 * instance of {@link RDFTermFactory}, with the given identifier joined to
+	 * that salt in a consistent manner.
+	 * <p>
+	 * BlankNodes created using this method with the same parameter, for
+	 * different instances of RDFTermFactory, SHOULD NOT be equivalent.
 	 * 
 	 * @param identifier
-	 *            A non-empty String that is unique to this blank node in this
-	 *            scope, and which may be used as the internal identifier for
-	 *            the blank node.
+	 *            A non-empty, non-null, String that is unique to this blank
+	 *            node in the context of this {@link RDFTermFactory}.
 	 * @return A BlankNode for the given identifier
-	 * @throws IllegalArgumentException
-	 *             if the identifier is not acceptable, e.g. was empty or
-	 *             contained unsupported characters.
 	 * @throws UnsupportedOperationException
 	 *             If the operation is not supported.
 	 */
 	default BlankNode createBlankNode(String identifier)
-			throws IllegalArgumentException, UnsupportedOperationException {
+			throws UnsupportedOperationException {
 		throw new UnsupportedOperationException(
 				"createBlankNode(String) not supported");
 	}
@@ -89,6 +102,11 @@ public interface RDFTermFactory {
 	 * <p>
 	 * It is undefined if the graph will be persisted by any underlying storage
 	 * mechanism.
+	 * <p>
+	 * {@link BlankNode} objects added to the {@link Graph} returned from this
+	 * method SHOULD be mapped using the {@link #createBlankNode(String)} of
+	 * this factory, called using the {@link BlankNode#internalIdentifier()} as
+	 * the parameter, before they are inserted into the Graph.
 	 * 
 	 * @return A new Graph
 	 * @throws UnsupportedOperationException
@@ -164,8 +182,9 @@ public interface RDFTermFactory {
 	 * <p>
 	 * 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 SHOULD return a
-	 * {@link Literal#getDatatype()} that is equal to the provided dataType IRI.
+	 * {@link Literal#getLanguageTag()} present, and MUST return a
+	 * {@link Literal#getDatatype()} that is equivalent to the provided dataType
+	 * IRI.
 	 * 
 	 * @param lexicalForm
 	 *            The literal value
@@ -204,7 +223,7 @@ public interface RDFTermFactory {
 	 * <code>http://www.w3.org/1999/02/22-rdf-syntax-ns#langString</code>, and
 	 * MUST have a {@link Literal#getLanguageTag()} present which SHOULD be
 	 * equal to the provided language tag (compared as
-	 * {@link String#toLowerCase(Locale)} in {@link Locale#ENGLISH}).
+	 * {@link String#toLowerCase(Locale)} using {@link Locale#ENGLISH}).
 	 * 
 	 * @param lexicalForm
 	 *            The literal value

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/243e85c4/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
index 81bbcee..3fd4bca 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
@@ -44,6 +44,11 @@ final class GraphImpl implements Graph {
 
 	private static final int TO_STRING_MAX = 10;
 	private final Set<Triple> triples = new LinkedHashSet<Triple>();
+	private final SimpleRDFTermFactory factory;
+
+	GraphImpl(SimpleRDFTermFactory simpleRDFTermFactory) {
+		this.factory = simpleRDFTermFactory;
+	}
 
 	@Override
 	public void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
@@ -60,37 +65,34 @@ final class GraphImpl implements Graph {
 			// this graph will generate a local object that is mapped to an
 			// equivalent object, based on the code in the package private
 			// BlankNodeImpl class
-			return new BlankNodeImpl(this, blankNode.internalIdentifier());
+			return factory.createBlankNode(blankNode.internalIdentifier());
 		} else if (object instanceof IRI && !(object instanceof IRIImpl)) {
 			IRI iri = (IRI) object;
-			return new IRIImpl(iri.getIRIString());
+			return factory.createIRI(iri.getIRIString());
 		} else if (object instanceof Literal
 				&& !(object instanceof LiteralImpl)) {
 			Literal literal = (Literal) object;
 			if (literal.getLanguageTag().isPresent()) {
-				return new LiteralImpl(literal.getLexicalForm(), literal
+				return factory.createLiteral(literal.getLexicalForm(), literal
 						.getLanguageTag().get());
 			} else {
-				return new LiteralImpl(literal.getLexicalForm(),
+				return factory.createLiteral(literal.getLexicalForm(),
 						(IRI) internallyMap(literal.getDatatype()));
 			}
 		} else {
+			// The object is a local implementation, and is not a BlankNode, so
+			// can be returned directly
 			return object;
 		}
 	}
 
 	@Override
 	public void add(Triple triple) {
-		if (!(triple instanceof TripleImpl)) {
-			BlankNodeOrIRI subject = (BlankNodeOrIRI) internallyMap(triple
-					.getSubject());
-			IRI predicate = (IRI) internallyMap(triple.getPredicate());
-			RDFTerm object = internallyMap(triple.getObject());
-			triples.add(new TripleImpl(subject, predicate, object));
-		} else {
-			triples.add(new TripleImpl(triple.getSubject(), triple
-					.getPredicate(), triple.getObject()));
-		}
+		BlankNodeOrIRI subject = (BlankNodeOrIRI) internallyMap(triple
+				.getSubject());
+		IRI predicate = (IRI) internallyMap(triple.getPredicate());
+		RDFTerm object = internallyMap(triple.getObject());
+		triples.add(factory.createTriple(subject, predicate, object));
 	}
 
 	@Override

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/243e85c4/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java b/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java
index d7a1c1f..471af67 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java
@@ -17,8 +17,6 @@
  */
 package org.apache.commons.rdf.simple;
 
-import java.util.Optional;
-
 import org.apache.commons.rdf.api.BlankNode;
 import org.apache.commons.rdf.api.BlankNodeOrIRI;
 import org.apache.commons.rdf.api.Graph;
@@ -34,7 +32,6 @@ import org.apache.commons.rdf.api.Triple;
  * The {@link RDFTerm} and {@link Graph} instances created by this factory are
  * simple in-memory Implementations that are not thread-safe or efficient, but
  * which may be useful for testing and prototyping purposes.
- *
  */
 public class SimpleRDFTermFactory implements RDFTermFactory {
 
@@ -45,12 +42,12 @@ public class SimpleRDFTermFactory implements RDFTermFactory {
 
 	@Override
 	public BlankNode createBlankNode(String identifier) {
-		return new BlankNodeImpl(Optional.empty(), identifier);
+		return new BlankNodeImpl(this, identifier);
 	}
 
 	@Override
 	public Graph createGraph() {
-		return new GraphImpl();
+		return new GraphImpl(this);
 	}
 
 	@Override


[17/18] incubator-commonsrdf git commit: Use hash check before iterating over ALL_TYPES

Posted by an...@apache.org.
Use hash check before iterating over ALL_TYPES

No simple way with Set to get the actual object that we want to return
as the replacement, so still need to iterate if we think we have it.

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

Branch: refs/heads/master
Commit: 1cb8056b07261c5586d21c7ff87b19ad519c5fb1
Parents: 21207cb
Author: Peter Ansell <p_...@yahoo.com>
Authored: Sat Mar 28 21:57:51 2015 +1100
Committer: Peter Ansell <p_...@yahoo.com>
Committed: Sat Mar 28 21:57:51 2015 +1100

----------------------------------------------------------------------
 .../main/java/org/apache/commons/rdf/simple/Types.java  | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/1cb8056b/simple/src/main/java/org/apache/commons/rdf/simple/Types.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/Types.java b/simple/src/main/java/org/apache/commons/rdf/simple/Types.java
index a8e9f52..45ee85e 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/Types.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/Types.java
@@ -273,7 +273,7 @@ public final class Types implements IRI {
 	public int hashCode() {
 		return this.field.hashCode();
 	}
-	
+
 	@Override
 	public String toString() {
 		return this.field.toString();
@@ -299,9 +299,13 @@ public final class Types implements IRI {
 	 *         {@link Optional#empty()} if it is not present here.
 	 */
 	public static Optional<IRI> get(IRI nextIRI) {
-		for (IRI nextType : values()) {
-			if (nextType.equals(nextIRI)) {
-				return Optional.of(nextType);
+		if (ALL_TYPES.contains(nextIRI)) {
+			// If we know about this IRI, then look through our set to find the
+			// object that matches and return it
+			for (IRI nextType : ALL_TYPES) {
+				if (nextType.equals(nextIRI)) {
+					return Optional.of(nextType);
+				}
 			}
 		}
 		return Optional.empty();


[07/18] incubator-commonsrdf git commit: Simplify GraphImpl triple matching since equals is now guaranteed to directly work

Posted by an...@apache.org.
Simplify GraphImpl triple matching since equals is now guaranteed to
directly work

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

Branch: refs/heads/master
Commit: c75c537d99b1047f1b56d2bc84327c6b2994d593
Parents: a8ba2a6
Author: Peter Ansell <p_...@yahoo.com>
Authored: Sat Mar 28 20:56:04 2015 +1100
Committer: Peter Ansell <p_...@yahoo.com>
Committed: Sat Mar 28 20:56:04 2015 +1100

----------------------------------------------------------------------
 .../main/java/org/apache/commons/rdf/simple/GraphImpl.java  | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/c75c537d/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
index 5f81048..24720b3 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
@@ -133,18 +133,15 @@ final class GraphImpl implements Graph {
 				// Lacking the requirement for .equals() we have to be silly
 				// and test ntriples string equivalance
 				if (subject != null
-						&& !t.getSubject().ntriplesString()
-								.equals(subject.ntriplesString())) {
+						&& !t.getSubject().equals(subject)) {
 					return false;
 				}
 				if (predicate != null
-						&& !t.getPredicate().ntriplesString()
-								.equals(predicate.ntriplesString())) {
+						&& !t.getPredicate().equals(predicate)) {
 					return false;
 				}
 				if (object != null
-						&& !t.getObject().ntriplesString()
-								.equals(object.ntriplesString())) {
+						&& !t.getObject().equals(object)) {
 					return false;
 				}
 				return true;


[15/18] incubator-commonsrdf git commit: Remove unused imports

Posted by an...@apache.org.
Remove unused imports

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

Branch: refs/heads/master
Commit: e84b8b1483df5a134fccaa03f8cec57a55e74748
Parents: 8d78597
Author: Peter Ansell <p_...@yahoo.com>
Authored: Sat Mar 28 21:34:15 2015 +1100
Committer: Peter Ansell <p_...@yahoo.com>
Committed: Sat Mar 28 21:34:15 2015 +1100

----------------------------------------------------------------------
 simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java   | 1 -
 .../test/java/org/apache/commons/rdf/simple/TestWritingGraph.java   | 1 -
 2 files changed, 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/e84b8b14/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
index e67d263..0d40d4a 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
@@ -18,7 +18,6 @@
 package org.apache.commons.rdf.simple;
 
 import java.util.HashSet;
-import java.util.LinkedHashSet;
 import java.util.Objects;
 import java.util.Set;
 import java.util.function.Predicate;

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/e84b8b14/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java b/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java
index 681c6e9..47746b6 100644
--- a/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java
@@ -30,7 +30,6 @@ import java.util.stream.Stream;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
-import org.apache.commons.rdf.api.BlankNode;
 import org.apache.commons.rdf.api.Graph;
 import org.apache.commons.rdf.api.IRI;
 import org.apache.commons.rdf.api.RDFTermFactory;


[10/18] incubator-commonsrdf git commit: fix javadoc

Posted by an...@apache.org.
fix javadoc

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

Branch: refs/heads/master
Commit: 75bca628299dfda16670f5b0f6f685f50f92c53d
Parents: 728270b
Author: Peter Ansell <p_...@yahoo.com>
Authored: Sat Mar 28 21:19:31 2015 +1100
Committer: Peter Ansell <p_...@yahoo.com>
Committed: Sat Mar 28 21:19:31 2015 +1100

----------------------------------------------------------------------
 api/src/main/java/org/apache/commons/rdf/api/BlankNode.java    | 3 +--
 .../main/java/org/apache/commons/rdf/api/RDFTermFactory.java   | 6 +++---
 2 files changed, 4 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/75bca628/api/src/main/java/org/apache/commons/rdf/api/BlankNode.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/BlankNode.java b/api/src/main/java/org/apache/commons/rdf/api/BlankNode.java
index ca6d198..a8283c9 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/BlankNode.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/BlankNode.java
@@ -95,11 +95,10 @@ public interface BlankNode extends BlankNodeOrIRI {
 	/**
 	 * Check it this BlankNode is equal to another BlankNode. Two BlankNodes
 	 * MUST be equal if, and only if, they have the same
-	 * {@link #internalIdentifier()}. </p>
+	 * {@link #internalIdentifier()}.
 	 * <p>
 	 * Implementations MUST also override {@link #hashCode()} so that two equal
 	 * Literals produce the same hash code.
-	 * </p>
 	 * 
 	 * @param other
 	 *            Another object

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/75bca628/api/src/main/java/org/apache/commons/rdf/api/RDFTermFactory.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/RDFTermFactory.java b/api/src/main/java/org/apache/commons/rdf/api/RDFTermFactory.java
index 3cbd430..1140e4a 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/RDFTermFactory.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/RDFTermFactory.java
@@ -69,14 +69,14 @@ public interface RDFTermFactory {
 	 * {@link BlankNode#equals(Object)} MUST return true. A BlankNode object
 	 * created through the {@link RDFTermFactory#createBlankNode()} method must
 	 * be universally unique, and SHOULD contain a {@link UUID} as part of its
-	 * {@link #internalIdentifier()}.
+	 * {@link BlankNode#internalIdentifier()}.
 	 * <p>
 	 * A BlankNode object created through the
 	 * {@link RDFTermFactory#createBlankNode(String)} method must be universally
-	 * unique, but also produce the same {@link #internalIdentifier()} as any
+	 * unique, but also produce the same {@link BlankNode#internalIdentifier()} as any
 	 * previous or future calls to that method on that factory with the same
 	 * parameters. In addition, it SHOULD contain a {@link UUID} as part of its
-	 * {@link #internalIdentifier()}, created using
+	 * {@link BlankNode#internalIdentifier()}, created using
 	 * {@link UUID#nameUUIDFromBytes(byte[])} using a constant salt for each
 	 * instance of {@link RDFTermFactory}, with the given identifier joined to
 	 * that salt in a consistent manner.


[11/18] incubator-commonsrdf git commit: Remove getTriples(Predicate) as it doesn't support mapping

Posted by an...@apache.org.
Remove getTriples(Predicate) as it doesn't support mapping

Also, map the values sent into GraphImpl.getTriples(...) and do not map
BlankNodeImpl objects, as we know they are universally unique locally ,
based on the factory they were created with, without mapping

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

Branch: refs/heads/master
Commit: a8ff114197bc706ba67d4d8e00a0a0ec347d0180
Parents: 75bca62
Author: Peter Ansell <p_...@yahoo.com>
Authored: Sat Mar 28 21:21:17 2015 +1100
Committer: Peter Ansell <p_...@yahoo.com>
Committed: Sat Mar 28 21:21:17 2015 +1100

----------------------------------------------------------------------
 .../java/org/apache/commons/rdf/api/Graph.java  | 19 --------
 .../apache/commons/rdf/simple/GraphImpl.java    | 49 +++++++++-----------
 2 files changed, 23 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/a8ff1141/api/src/main/java/org/apache/commons/rdf/api/Graph.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Graph.java b/api/src/main/java/org/apache/commons/rdf/api/Graph.java
index f376fe2..0ca3929 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/Graph.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/Graph.java
@@ -161,23 +161,4 @@ public interface Graph extends AutoCloseable {
 	 */
 	Stream<? extends Triple> getTriples(BlankNodeOrIRI subject, IRI predicate,
 			RDFTerm object);
-
-	/**
-	 * Get all triples contained by the graph matched with the pattern.
-	 * <p>
-	 * The iteration does not contain any duplicate triples, as determined by
-	 * the equals method for each {@link Triple}.
-	 * <p>
-	 * The behaviour of the Stream is not specified if add, remove, or clear,
-	 * are called on the Stream before it terminates.<br>
-	 * <p>
-	 * Implementations may throw ConcurrentModificationException from Stream
-	 * methods if they detect a conflict while the Stream is active.
-	 *
-	 * @param filter
-	 *            A filter to match against each triple in the graph.
-	 * @return A {@link Stream} over the matched triples.
-	 */
-	Stream<? extends Triple> getTriples(Predicate<Triple> filter);
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/a8ff1141/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
index 24720b3..b0b3124 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
@@ -17,6 +17,7 @@
  */
 package org.apache.commons.rdf.simple;
 
+import java.util.HashSet;
 import java.util.LinkedHashSet;
 import java.util.Objects;
 import java.util.Set;
@@ -42,7 +43,7 @@ import org.apache.commons.rdf.api.Triple;
 final class GraphImpl implements Graph {
 
 	private static final int TO_STRING_MAX = 10;
-	private final Set<Triple> triples = new LinkedHashSet<Triple>();
+	private final Set<Triple> triples = new HashSet<Triple>();
 	private final SimpleRDFTermFactory factory;
 
 	GraphImpl(SimpleRDFTermFactory simpleRDFTermFactory) {
@@ -76,7 +77,7 @@ final class GraphImpl implements Graph {
 	}
 
 	private <T extends RDFTerm> RDFTerm internallyMap(T object) {
-		if (object instanceof BlankNode) {
+		if (object instanceof BlankNode && !(object instanceof BlankNodeImpl)) {
 			BlankNode blankNode = (BlankNode) object;
 			// This guarantees that adding the same BlankNode multiple times to
 			// this graph will generate a local object that is mapped to an
@@ -121,38 +122,34 @@ final class GraphImpl implements Graph {
 
 	@Override
 	public Stream<Triple> getTriples() {
-		return triples.parallelStream();
+		return triples.parallelStream().unordered();
 	}
 
 	@Override
 	public Stream<Triple> getTriples(final BlankNodeOrIRI subject,
 			final IRI predicate, final RDFTerm object) {
-		Predicate<Triple> match = new Predicate<Triple>() {
-			@Override
-			public boolean test(Triple t) {
-				// Lacking the requirement for .equals() we have to be silly
-				// and test ntriples string equivalance
-				if (subject != null
-						&& !t.getSubject().equals(subject)) {
-					return false;
-				}
-				if (predicate != null
-						&& !t.getPredicate().equals(predicate)) {
-					return false;
-				}
-				if (object != null
-						&& !t.getObject().equals(object)) {
-					return false;
-				}
-				return true;
+		final BlankNodeOrIRI newSubject = (BlankNodeOrIRI) internallyMap(subject);
+		final IRI newPredicate = (IRI) internallyMap(predicate);
+		final RDFTerm newObject = internallyMap(object);
+
+		return getTriples(t -> {
+			// Lacking the requirement for .equals() we have to be silly
+			// and test ntriples string equivalance
+			if (subject != null && !t.getSubject().equals(newSubject)) {
+				return false;
 			}
-		};
-		return getTriples(match);
+			if (predicate != null && !t.getPredicate().equals(newPredicate)) {
+				return false;
+			}
+			if (object != null && !t.getObject().equals(newObject)) {
+				return false;
+			}
+			return true;
+		});
 	}
 
-	@Override
-	public Stream<Triple> getTriples(final Predicate<Triple> filter) {
-		return getTriples().unordered().filter(filter);
+	private Stream<Triple> getTriples(final Predicate<Triple> filter) {
+		return getTriples().filter(filter);
 	}
 
 	@Override


[12/18] incubator-commonsrdf git commit: Remove graph triple ordering from test

Posted by an...@apache.org.
Remove graph triple ordering from test

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

Branch: refs/heads/master
Commit: 08bb8c6b3cfb02af054ba71921cd5bfae40a8932
Parents: a8ff114
Author: Peter Ansell <p_...@yahoo.com>
Authored: Sat Mar 28 21:23:09 2015 +1100
Committer: Peter Ansell <p_...@yahoo.com>
Committed: Sat Mar 28 21:23:09 2015 +1100

----------------------------------------------------------------------
 .../test/java/org/apache/commons/rdf/api/AbstractGraphTest.java  | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/08bb8c6b/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java b/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
index 4c1d035..aaa5636 100644
--- a/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
+++ b/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
@@ -120,9 +120,9 @@ public abstract class AbstractGraphTest {
 		System.out.println(graph);
 		assertTrue(graph
 				.toString()
-				.startsWith(
+				.contains(
 						"<http://example.com/alice> <http://xmlns.com/foaf/0.1/name> \"Alice\" ."));
-		assertTrue(graph.toString().endsWith(
+		assertTrue(graph.toString().contains(
 				" <http://xmlns.com/foaf/0.1/name> \"A company\" ."));
 
 	}


[18/18] incubator-commonsrdf git commit: Merge branch 'bnode-uuids'

Posted by an...@apache.org.
Merge branch 'bnode-uuids'


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

Branch: refs/heads/master
Commit: 20b0b000fc92a5699e0d79f9205cb62babe444bd
Parents: cf5f515 1cb8056
Author: Peter Ansell <p_...@yahoo.com>
Authored: Mon Mar 30 12:07:17 2015 +1100
Committer: Peter Ansell <p_...@yahoo.com>
Committed: Mon Mar 30 12:07:17 2015 +1100

----------------------------------------------------------------------
 .../org/apache/commons/rdf/api/BlankNode.java   | 141 ++++++++-----------
 .../java/org/apache/commons/rdf/api/Graph.java  |  37 ++---
 .../apache/commons/rdf/api/RDFTermFactory.java  |  59 +++++---
 .../commons/rdf/api/AbstractGraphTest.java      |  40 +++---
 .../rdf/api/AbstractRDFTermFactoryTest.java     |  11 +-
 .../commons/rdf/simple/BlankNodeImpl.java       |  39 +++--
 .../apache/commons/rdf/simple/GraphImpl.java    | 120 +++++++++++-----
 .../rdf/simple/SimpleRDFTermFactory.java        |  10 +-
 .../apache/commons/rdf/simple/TripleImpl.java   |  70 ++-------
 .../org/apache/commons/rdf/simple/Types.java    |  12 +-
 .../commons/rdf/simple/DefaultGraphTest.java    |   2 +-
 .../commons/rdf/simple/TestWritingGraph.java    |  69 ++++++---
 12 files changed, 305 insertions(+), 305 deletions(-)
----------------------------------------------------------------------



[16/18] incubator-commonsrdf git commit: Add comments to explain the use of this variable in SimpleRDFTermFactory

Posted by an...@apache.org.
Add comments to explain the use of this variable in SimpleRDFTermFactory

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

Branch: refs/heads/master
Commit: 21207cb022e73f641ded54e4e73e239ba1990835
Parents: e84b8b1
Author: Peter Ansell <p_...@yahoo.com>
Authored: Sat Mar 28 21:38:21 2015 +1100
Committer: Peter Ansell <p_...@yahoo.com>
Committed: Sat Mar 28 21:38:21 2015 +1100

----------------------------------------------------------------------
 .../java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java  | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/21207cb0/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java b/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java
index 471af67..6305e63 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java
@@ -42,11 +42,14 @@ public class SimpleRDFTermFactory implements RDFTermFactory {
 
 	@Override
 	public BlankNode createBlankNode(String identifier) {
+		// Creates a BlankNodeImpl object using this object as the salt
 		return new BlankNodeImpl(this, identifier);
 	}
 
 	@Override
 	public Graph createGraph() {
+		// Creates a GraphImpl object using this object as the factory for
+		// delegating all object creation to
 		return new GraphImpl(this);
 	}
 


[06/18] incubator-commonsrdf git commit: fix test to use new GraphImpl constructor

Posted by an...@apache.org.
fix test to use new GraphImpl constructor

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

Branch: refs/heads/master
Commit: a8ba2a61ae3fced64055f3b8209885488431671f
Parents: c85e918
Author: Peter Ansell <p_...@yahoo.com>
Authored: Sat Mar 28 20:41:38 2015 +1100
Committer: Peter Ansell <p_...@yahoo.com>
Committed: Sat Mar 28 20:41:38 2015 +1100

----------------------------------------------------------------------
 .../test/java/org/apache/commons/rdf/simple/DefaultGraphTest.java  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/a8ba2a61/simple/src/test/java/org/apache/commons/rdf/simple/DefaultGraphTest.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/DefaultGraphTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/DefaultGraphTest.java
index 87c9048..5cfcda6 100644
--- a/simple/src/test/java/org/apache/commons/rdf/simple/DefaultGraphTest.java
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/DefaultGraphTest.java
@@ -37,7 +37,7 @@ public class DefaultGraphTest extends AbstractGraphTest {
 		return new RDFTermFactory() {
 			@Override
 			public Graph createGraph() throws UnsupportedOperationException {
-				return new GraphImpl();
+				return new GraphImpl(new SimpleRDFTermFactory());
 			}
 
 			@Override


[05/18] incubator-commonsrdf git commit: Refactor test to use factory as its basis, not direct calls to the constructors

Posted by an...@apache.org.
Refactor test to use factory as its basis, not direct calls to the
constructors

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

Branch: refs/heads/master
Commit: c85e918541d7d24a14b68237f4f09307656aad48
Parents: bfd037e
Author: Peter Ansell <p_...@yahoo.com>
Authored: Sat Mar 28 20:40:09 2015 +1100
Committer: Peter Ansell <p_...@yahoo.com>
Committed: Sat Mar 28 20:40:09 2015 +1100

----------------------------------------------------------------------
 .../commons/rdf/simple/TestWritingGraph.java    | 38 ++++++++++++--------
 1 file changed, 23 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/c85e9185/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java b/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java
index 28bf360..f4a5857 100644
--- a/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java
@@ -23,14 +23,15 @@ import java.nio.file.Path;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
-import java.util.Optional;
 import java.util.stream.Stream;
 
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.apache.commons.rdf.api.BlankNode;
+import org.apache.commons.rdf.api.Graph;
 import org.apache.commons.rdf.api.IRI;
+import org.apache.commons.rdf.api.RDFTermFactory;
 
 public class TestWritingGraph {
 
@@ -43,13 +44,16 @@ public class TestWritingGraph {
 	/** Run tests with -Dkeepfiles=true to inspect /tmp files **/
 	private static boolean KEEP_FILES = Boolean.getBoolean("keepfiles");
 
-	private static GraphImpl graph;
+	private static Graph graph;
+
+	private static RDFTermFactory factory;
 
 	@BeforeClass
 	public static void createGraph() throws Exception {
-		graph = new GraphImpl();
-		BlankNode subject = new BlankNodeImpl(Optional.of(graph), "subj");
-		IRI predicate = new IRIImpl("pred");
+		factory = new SimpleRDFTermFactory();
+		graph = factory.createGraph();
+		BlankNode subject = factory.createBlankNode("subj");
+		IRI predicate = factory.createIRI("pred");
 		List<IRI> types = new ArrayList<>(Types.values());
 		// Ensure we don't try to create a literal with rdf:langString but
 		// without a language tag
@@ -57,17 +61,21 @@ public class TestWritingGraph {
 		Collections.shuffle(types);
 		for (int i = 0; i < TRIPLES; i++) {
 			if (i % 5 == 0) {
-				graph.add(subject, predicate, new LiteralImpl("Example " + i,
-						"en"));
+				graph.add(subject, predicate,
+						factory.createLiteral("Example " + i, "en"));
 			} else if (i % 3 == 0) {
-				graph.add(subject, predicate, new LiteralImpl("Example " + i,
-						types.get(i % types.size())));
+				graph.add(
+						subject,
+						predicate,
+						factory.createLiteral("Example " + i,
+								types.get(i % types.size())));
 			} else {
-				graph.add(subject, predicate, new LiteralImpl("Example " + i));
+				graph.add(subject, predicate,
+						factory.createLiteral("Example " + i));
 			}
 		}
 	}
-	
+
 	@AfterClass
 	public static void tearDownClass() throws Exception {
 		graph.clear();
@@ -81,8 +89,8 @@ public class TestWritingGraph {
 
 	@Test
 	public void countQuery() {
-		BlankNode subject = new BlankNodeImpl(Optional.of(graph), "subj");
-		IRI predicate = new IRIImpl("pred");
+		BlankNode subject = factory.createBlankNode("subj");
+		IRI predicate = factory.createIRI("pred");
 		long count = graph.getTriples(subject, predicate, null).unordered()
 				.parallel().count();
 		System.out.println("Counted - " + count);
@@ -111,8 +119,8 @@ public class TestWritingGraph {
 			graphFile.toFile().deleteOnExit();
 		}
 
-		BlankNode subject = new BlankNodeImpl(Optional.of(graph), "subj");
-		IRI predicate = new IRIImpl("pred");
+		BlankNode subject = factory.createBlankNode("subj");
+		IRI predicate = factory.createIRI("pred");
 		Stream<CharSequence> stream = graph
 				.getTriples(subject, predicate, null).map(Object::toString);
 		Files.write(graphFile, stream::iterator, Charset.forName("UTF-8"));


[13/18] incubator-commonsrdf git commit: Change "does not" for Graph duplicates to "SHOULD NOT" for clarity and permissivity for implementations that cannot guarantee "MUST NOT" levels of surety for duplicates.

Posted by an...@apache.org.
Change "does not" for Graph duplicates to "SHOULD NOT" for clarity and
permissivity for implementations that cannot guarantee "MUST NOT" levels
of surety for duplicates.

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

Branch: refs/heads/master
Commit: 32ee522cc22ae9aff78f3f8977b7f5d32e05c6af
Parents: 08bb8c6
Author: Peter Ansell <p_...@yahoo.com>
Authored: Sat Mar 28 21:26:19 2015 +1100
Committer: Peter Ansell <p_...@yahoo.com>
Committed: Sat Mar 28 21:26:19 2015 +1100

----------------------------------------------------------------------
 api/src/main/java/org/apache/commons/rdf/api/Graph.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/32ee522c/api/src/main/java/org/apache/commons/rdf/api/Graph.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Graph.java b/api/src/main/java/org/apache/commons/rdf/api/Graph.java
index 0ca3929..c4097b6 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/Graph.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/Graph.java
@@ -126,7 +126,7 @@ public interface Graph extends AutoCloseable {
 	/**
 	 * Get all triples contained by the graph.<br>
 	 * <p>
-	 * The iteration does not contain any duplicate triples, as determined by
+	 * The iteration SHOULD NOT contain any duplicate triples, as determined by
 	 * the equals method for each {@link Triple}.
 	 * <p>
 	 * The behaviour of the Stream is not specified if add, remove, or clear,


Re: [14/18] incubator-commonsrdf git commit: Return the Triple that was actually added to Graph, including any mapped components as necessary

Posted by Stian Soiland-Reyes <st...@apache.org>.
Yes, a Triple lookup would work fine just like that - but I am not
sure what this is useful for (unless you want to cast it to an
implementation subclass that provides additional methods).



So that only works if it is OK to query with the previously inserted
BlankNodes - which I would have hoped for to work, but which I can see
can get tricky if those BlankNodes came from a different
implementation and needs to be 'mapped' somehow.


Let's say there is an independent parser that produces Triples (using
simple.* instances) for

_:b1 foaf:knows _:b2 .
_:b2 foaf:knows _:b1 .

which you then add to a Graph from a secondary implementation, which
has its own BlankNode, Triple etc.

It might do its own BlankNode substitution on insert, e.g. like Jena
TDB who uses 64-bits integer to map to its disk-based indexes.
Obviously this would have to consistently map both statements to the
same substituted b1 and b2.

The substituted b1 and b2 (if you looked them up through getTriples)
might or might not have the same internalIdentifier() as the originals
- I don't think we require either now.


Now at a later stage you want add an additional statement about _:b1 -
I assume it would be OK to simply keep the original _:b1 instance in
memory and re-use that?

As we don't have a graph.addAll(Set<Triples>) or any kind of
'transaction' - then the Graph would have to support both of the above
and really can't tell which one it is.


Now with getTriples() I should presumably get back (in some form) the
expected triples I just added if I query/filter with that original b1
instance, which would be included in the results for statements with
predicate foaf:knows.

Is the original b1 .equal() to the substituted b1 instance returned
from that query? One should expect so - otherwise how did it pass the
filter?

Triple.equals() is defined from its constituent parts.


Now if all of the above is true - then why do you need to look up the
substituted Triple instance?


On 31 March 2015 at 12:02, Andy Seaborne <an...@apache.org> wrote:
> On 31/03/15 11:43, Stian Soiland-Reyes wrote:
>>
>> It might be that the Graph needs a method to look up blank nodes by
>> some measure, without having to query for a big graph pattern of what
>> was just inserted.
>
>
> You mean shorthand for
>
> graph
>   .getTriples(t.getSubject(), t.getPrediate(), t.getObject())
>   .findFirst.get() ;
>
> as the 3 elements are grounded, I'd expect that to be very fast.
>
>
>>
>> So now if you do
>>
>> String s = blankNode.internalIdentifier();
>> graph.add(blankNode, p, blankNode)
>>
>> and look it up again - than do I understand the contract correctly in
>> that Graph is not required to return the same internalIdentifier()?
>>
>> If I get those BlankNodes out again - are they still .equal() to the
>> inserted blankNode?
>>
>>
>> On 31 March 2015 at 10:52, Andy Seaborne <an...@apache.org> wrote:
>>>
>>> On 30/03/15 23:10, Peter Ansell wrote:
>>>>
>>>>
>>>> All of the BlankNode's in the Triple that was added may be internally
>>>> remapped during the add operation. Hence, the .equals will change when
>>>> the remapping occurs. Returning the mapped values enables a user to
>>>> get access to that information.
>>>>
>>>> Removing the return value is fine with me if it can't be supported in
>>>> a performant way. It just removes the simple way for a user to know
>>>> what BlankNode remapping occurred.
>>>
>>>
>>>
>>> Peter,
>>>
>>> Great - and I see the change in git.
>>>
>>> A simpler example would have been a parser not wanting to use the return
>>> from add() and an implementation that does not store Triple objects, but
>>> has
>>> data structures using the subject/predicate/object directly. Returned
>>> triples are just object churn albeit probably quite efficient churn.
>>>
>>> (hmm - interesting - so once mapped, the mapping is stable.)
>>>
>>>          Andy
>>>
>>>
>>>>
>>>> On 31 March 2015 at 06:46, Andy Seaborne <an...@apache.org> wrote:
>>>>>>
>>>>>>
>>>>>> -     void add(Triple triple);
>>>>>> +     Triple add(Triple triple);
>>>>>
>>>>>
>>>>>
>>>>> Returning something from add() does not work for me.
>>>>>
>>>>> (And even if it did, I would have expected "boolean" as to whether the
>>>>> triple was actually added or not.)
>>>>>
>>>>> 1/ I don't understand "possibly mapping" being in the API.  A triple is
>>>>> a
>>>>> triple. What is the client supposed to do differently with .equals one
>>>>> returned (it is .equals?)
>>>>>
>>>>> 2/ I am finding that having a flow back from add operations difficult
>>>>> to
>>>>> deal with.
>>>>>
>>>>> A sequence of add(Triple) can be batched up and only need to be
>>>>> performed
>>>>> before another operation is called that can observe the change.
>>>>>
>>>>> In the case a remote destination, the overhead per add is significant
>>>>> (network rounds).  But if it is delayed, then the return of anything is
>>>>> not
>>>>> available.
>>>>>
>>>>> For a general interface, this should be
>>>>>
>>>>>       void add(Triple)
>>>>>
>>>>>           Andy
>>>>>
>>>>>
>>>
>>
>>
>>
>



-- 
Stian Soiland-Reyes
Apache Taverna (incubating), Apache Commons RDF (incubating)
http://orcid.org/0000-0001-9842-9718

Re: [14/18] incubator-commonsrdf git commit: Return the Triple that was actually added to Graph, including any mapped components as necessary

Posted by Andy Seaborne <an...@apache.org>.
On 31/03/15 11:43, Stian Soiland-Reyes wrote:
> It might be that the Graph needs a method to look up blank nodes by
> some measure, without having to query for a big graph pattern of what
> was just inserted.

You mean shorthand for

graph
   .getTriples(t.getSubject(), t.getPrediate(), t.getObject())
   .findFirst.get() ;

as the 3 elements are grounded, I'd expect that to be very fast.

>
> So now if you do
>
> String s = blankNode.internalIdentifier();
> graph.add(blankNode, p, blankNode)
>
> and look it up again - than do I understand the contract correctly in
> that Graph is not required to return the same internalIdentifier()?
>
> If I get those BlankNodes out again - are they still .equal() to the
> inserted blankNode?
>
>
> On 31 March 2015 at 10:52, Andy Seaborne <an...@apache.org> wrote:
>> On 30/03/15 23:10, Peter Ansell wrote:
>>>
>>> All of the BlankNode's in the Triple that was added may be internally
>>> remapped during the add operation. Hence, the .equals will change when
>>> the remapping occurs. Returning the mapped values enables a user to
>>> get access to that information.
>>>
>>> Removing the return value is fine with me if it can't be supported in
>>> a performant way. It just removes the simple way for a user to know
>>> what BlankNode remapping occurred.
>>
>>
>> Peter,
>>
>> Great - and I see the change in git.
>>
>> A simpler example would have been a parser not wanting to use the return
>> from add() and an implementation that does not store Triple objects, but has
>> data structures using the subject/predicate/object directly. Returned
>> triples are just object churn albeit probably quite efficient churn.
>>
>> (hmm - interesting - so once mapped, the mapping is stable.)
>>
>>          Andy
>>
>>
>>>
>>> On 31 March 2015 at 06:46, Andy Seaborne <an...@apache.org> wrote:
>>>>>
>>>>> -     void add(Triple triple);
>>>>> +     Triple add(Triple triple);
>>>>
>>>>
>>>> Returning something from add() does not work for me.
>>>>
>>>> (And even if it did, I would have expected "boolean" as to whether the
>>>> triple was actually added or not.)
>>>>
>>>> 1/ I don't understand "possibly mapping" being in the API.  A triple is a
>>>> triple. What is the client supposed to do differently with .equals one
>>>> returned (it is .equals?)
>>>>
>>>> 2/ I am finding that having a flow back from add operations difficult to
>>>> deal with.
>>>>
>>>> A sequence of add(Triple) can be batched up and only need to be performed
>>>> before another operation is called that can observe the change.
>>>>
>>>> In the case a remote destination, the overhead per add is significant
>>>> (network rounds).  But if it is delayed, then the return of anything is
>>>> not
>>>> available.
>>>>
>>>> For a general interface, this should be
>>>>
>>>>       void add(Triple)
>>>>
>>>>           Andy
>>>>
>>>>
>>
>
>
>


Re: [14/18] incubator-commonsrdf git commit: Return the Triple that was actually added to Graph, including any mapped components as necessary

Posted by Stian Soiland-Reyes <st...@apache.org>.
It might be that the Graph needs a method to look up blank nodes by
some measure, without having to query for a big graph pattern of what
was just inserted.

So now if you do

String s = blankNode.internalIdentifier();
graph.add(blankNode, p, blankNode)

and look it up again - than do I understand the contract correctly in
that Graph is not required to return the same internalIdentifier()?

If I get those BlankNodes out again - are they still .equal() to the
inserted blankNode?


On 31 March 2015 at 10:52, Andy Seaborne <an...@apache.org> wrote:
> On 30/03/15 23:10, Peter Ansell wrote:
>>
>> All of the BlankNode's in the Triple that was added may be internally
>> remapped during the add operation. Hence, the .equals will change when
>> the remapping occurs. Returning the mapped values enables a user to
>> get access to that information.
>>
>> Removing the return value is fine with me if it can't be supported in
>> a performant way. It just removes the simple way for a user to know
>> what BlankNode remapping occurred.
>
>
> Peter,
>
> Great - and I see the change in git.
>
> A simpler example would have been a parser not wanting to use the return
> from add() and an implementation that does not store Triple objects, but has
> data structures using the subject/predicate/object directly. Returned
> triples are just object churn albeit probably quite efficient churn.
>
> (hmm - interesting - so once mapped, the mapping is stable.)
>
>         Andy
>
>
>>
>> On 31 March 2015 at 06:46, Andy Seaborne <an...@apache.org> wrote:
>>>>
>>>> -     void add(Triple triple);
>>>> +     Triple add(Triple triple);
>>>
>>>
>>> Returning something from add() does not work for me.
>>>
>>> (And even if it did, I would have expected "boolean" as to whether the
>>> triple was actually added or not.)
>>>
>>> 1/ I don't understand "possibly mapping" being in the API.  A triple is a
>>> triple. What is the client supposed to do differently with .equals one
>>> returned (it is .equals?)
>>>
>>> 2/ I am finding that having a flow back from add operations difficult to
>>> deal with.
>>>
>>> A sequence of add(Triple) can be batched up and only need to be performed
>>> before another operation is called that can observe the change.
>>>
>>> In the case a remote destination, the overhead per add is significant
>>> (network rounds).  But if it is delayed, then the return of anything is
>>> not
>>> available.
>>>
>>> For a general interface, this should be
>>>
>>>      void add(Triple)
>>>
>>>          Andy
>>>
>>>
>



-- 
Stian Soiland-Reyes
Apache Taverna (incubating), Apache Commons RDF (incubating)
http://orcid.org/0000-0001-9842-9718

Re: [14/18] incubator-commonsrdf git commit: Return the Triple that was actually added to Graph, including any mapped components as necessary

Posted by Andy Seaborne <an...@apache.org>.
On 30/03/15 23:10, Peter Ansell wrote:
> All of the BlankNode's in the Triple that was added may be internally
> remapped during the add operation. Hence, the .equals will change when
> the remapping occurs. Returning the mapped values enables a user to
> get access to that information.
>
> Removing the return value is fine with me if it can't be supported in
> a performant way. It just removes the simple way for a user to know
> what BlankNode remapping occurred.

Peter,

Great - and I see the change in git.

A simpler example would have been a parser not wanting to use the return 
from add() and an implementation that does not store Triple objects, but 
has data structures using the subject/predicate/object directly. 
Returned triples are just object churn albeit probably quite efficient 
churn.

(hmm - interesting - so once mapped, the mapping is stable.)

	Andy

>
> On 31 March 2015 at 06:46, Andy Seaborne <an...@apache.org> wrote:
>>> -     void add(Triple triple);
>>> +     Triple add(Triple triple);
>>
>> Returning something from add() does not work for me.
>>
>> (And even if it did, I would have expected "boolean" as to whether the
>> triple was actually added or not.)
>>
>> 1/ I don't understand "possibly mapping" being in the API.  A triple is a
>> triple. What is the client supposed to do differently with .equals one
>> returned (it is .equals?)
>>
>> 2/ I am finding that having a flow back from add operations difficult to
>> deal with.
>>
>> A sequence of add(Triple) can be batched up and only need to be performed
>> before another operation is called that can observe the change.
>>
>> In the case a remote destination, the overhead per add is significant
>> (network rounds).  But if it is delayed, then the return of anything is not
>> available.
>>
>> For a general interface, this should be
>>
>>      void add(Triple)
>>
>>          Andy
>>
>>


Re: [14/18] incubator-commonsrdf git commit: Return the Triple that was actually added to Graph, including any mapped components as necessary

Posted by Peter Ansell <an...@gmail.com>.
All of the BlankNode's in the Triple that was added may be internally
remapped during the add operation. Hence, the .equals will change when
the remapping occurs. Returning the mapped values enables a user to
get access to that information.

Removing the return value is fine with me if it can't be supported in
a performant way. It just removes the simple way for a user to know
what BlankNode remapping occurred.

On 31 March 2015 at 06:46, Andy Seaborne <an...@apache.org> wrote:
>> -     void add(Triple triple);
>> +     Triple add(Triple triple);
>
> Returning something from add() does not work for me.
>
> (And even if it did, I would have expected "boolean" as to whether the
> triple was actually added or not.)
>
> 1/ I don't understand "possibly mapping" being in the API.  A triple is a
> triple. What is the client supposed to do differently with .equals one
> returned (it is .equals?)
>
> 2/ I am finding that having a flow back from add operations difficult to
> deal with.
>
> A sequence of add(Triple) can be batched up and only need to be performed
> before another operation is called that can observe the change.
>
> In the case a remote destination, the overhead per add is significant
> (network rounds).  But if it is delayed, then the return of anything is not
> available.
>
> For a general interface, this should be
>
>     void add(Triple)
>
>         Andy
>
>

Re: [14/18] incubator-commonsrdf git commit: Return the Triple that was actually added to Graph, including any mapped components as necessary

Posted by Andy Seaborne <an...@apache.org>.
 > -	void add(Triple triple);
 > +	Triple add(Triple triple);

Returning something from add() does not work for me.

(And even if it did, I would have expected "boolean" as to whether the 
triple was actually added or not.)

1/ I don't understand "possibly mapping" being in the API.  A triple is 
a triple. What is the client supposed to do differently with .equals one 
returned (it is .equals?)

2/ I am finding that having a flow back from add operations difficult to 
deal with.

A sequence of add(Triple) can be batched up and only need to be 
performed before another operation is called that can observe the change.

In the case a remote destination, the overhead per add is significant 
(network rounds).  But if it is delayed, then the return of anything is 
not available.

For a general interface, this should be

     void add(Triple)

	Andy



[14/18] incubator-commonsrdf git commit: Return the Triple that was actually added to Graph, including any mapped components as necessary

Posted by an...@apache.org.
Return the Triple that was actually added to Graph, including any mapped
components as necessary

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

Branch: refs/heads/master
Commit: 8d78597f93925115fcb7647a6ce207882511c31b
Parents: 32ee522
Author: Peter Ansell <p_...@yahoo.com>
Authored: Sat Mar 28 21:32:06 2015 +1100
Committer: Peter Ansell <p_...@yahoo.com>
Committed: Sat Mar 28 21:32:06 2015 +1100

----------------------------------------------------------------------
 .../main/java/org/apache/commons/rdf/api/Graph.java | 16 ++++++++++------
 .../org/apache/commons/rdf/simple/GraphImpl.java    | 15 ++++++++++-----
 2 files changed, 20 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/8d78597f/api/src/main/java/org/apache/commons/rdf/api/Graph.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Graph.java b/api/src/main/java/org/apache/commons/rdf/api/Graph.java
index c4097b6..399a9bf 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/Graph.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/Graph.java
@@ -17,7 +17,6 @@
  */
 package org.apache.commons.rdf.api;
 
-import java.util.function.Predicate;
 import java.util.stream.Stream;
 
 /**
@@ -29,15 +28,19 @@ import java.util.stream.Stream;
 public interface Graph extends AutoCloseable {
 
 	/**
-	 * Add a triple to the graph.
+	 * Add a triple to the graph, possibly mapping any of the components of the
+	 * Triple to those supported by this Graph.
 	 *
 	 * @param triple
 	 *            The triple to add
+	 * @return The Triple that was added to the graph, including any mapped
+	 *         components.
 	 */
-	void add(Triple triple);
+	Triple add(Triple triple);
 
 	/**
-	 * Add a triple to the graph.
+	 * Add a triple to the graph, possibly mapping any of the components to
+	 * those supported by this Graph.
 	 *
 	 * @param subject
 	 *            The triple subject
@@ -45,8 +48,10 @@ public interface Graph extends AutoCloseable {
 	 *            The triple predicate
 	 * @param object
 	 *            The triple object
+	 * @return The Triple that was added to the graph, including any mapped
+	 *         components.
 	 */
-	void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
+	Triple add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
 
 	/**
 	 * Check if graph contains triple.
@@ -109,7 +114,6 @@ public interface Graph extends AutoCloseable {
 
 	/**
 	 * Clear the graph, removing all triples.
-	 * 
 	 */
 	void clear();
 

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/8d78597f/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
index b0b3124..e67d263 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
@@ -51,15 +51,17 @@ final class GraphImpl implements Graph {
 	}
 
 	@Override
-	public void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+	public Triple add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
 		BlankNodeOrIRI newSubject = (BlankNodeOrIRI) internallyMap(subject);
 		IRI newPredicate = (IRI) internallyMap(predicate);
 		RDFTerm newObject = internallyMap(object);
-		triples.add(factory.createTriple(newSubject, newPredicate, newObject));
+		Triple result = factory.createTriple(newSubject, newPredicate, newObject);
+		triples.add(result);
+		return result;
 	}
 
 	@Override
-	public void add(Triple triple) {
+	public Triple add(Triple triple) {
 		BlankNodeOrIRI newSubject = (BlankNodeOrIRI) internallyMap(triple
 				.getSubject());
 		IRI newPredicate = (IRI) internallyMap(triple.getPredicate());
@@ -70,9 +72,12 @@ final class GraphImpl implements Graph {
 				&& newPredicate == triple.getPredicate()
 				&& newObject == triple.getObject()) {
 			triples.add(triple);
+			return triple;
 		} else {
-			triples.add(factory.createTriple(newSubject, newPredicate,
-					newObject));
+			Triple result = factory.createTriple(newSubject, newPredicate,
+					newObject);
+			triples.add(result);
+			return result;
 		}
 	}