You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commonsrdf.apache.org by st...@apache.org on 2016/06/02 16:45:56 UTC
[44/50] incubator-commonsrdf git commit: Merge branch 'master' into
quad
Merge branch 'master' into quad
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/14f246e7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/14f246e7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/14f246e7
Branch: refs/heads/rdf4j
Commit: 14f246e74cf89ca37efad1360b2bcd142cb60759
Parents: c7e1a5b 058f781
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Thu Jun 2 17:24:33 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Thu Jun 2 17:24:33 2016 +0100
----------------------------------------------------------------------
RELEASE-NOTES.txt | 39 +++++
RELEASE-PROCESS.md | 16 ++
api/pom.xml | 2 +-
.../commons/rdf/api/AbstractGraphTest.java | 172 +++++++++++++++++++
.../rdf/api/AbstractRDFTermFactoryTest.java | 29 ++++
examples/pom.xml | 4 +-
examples/src/example/UserGuideTest.java | 1 +
pom.xml | 95 +++++-----
simple/pom.xml | 3 +-
src/assembly/src.xml | 45 +++++
src/main/assembly/src.xml | 44 -----
src/site/markdown/download.md | 34 ++--
src/site/markdown/userguide.md | 60 +++++--
13 files changed, 414 insertions(+), 130 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/14f246e7/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
----------------------------------------------------------------------
diff --cc api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
index 15773df,5986958..27b9ff4
--- a/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
+++ b/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
@@@ -260,11 -266,177 +266,177 @@@ public abstract class AbstractGraphTes
assertEquals(3, aliceCount);
Assume.assumeNotNull(bnode1, bnode2, bobName, companyName, secretClubName);
- assertEquals(4, graph.getTriples(null, name, null).count());
+ assertEquals(4, graph.stream(null, name, null).count());
Assume.assumeNotNull(bnode1);
- assertEquals(3, graph.getTriples(null, member, null).count());
+ assertEquals(3, graph.stream(null, member, null).count());
}
+ @Test
+ public void addBlankNodesFromMultipleGraphs() {
+
+ try {
+ // Create two separate Graph instances
+ Graph g1 = createGraph1();
+ Graph g2 = createGraph2();
+
+ // and add them to a new Graph g3
+ Graph g3 = factory.createGraph();
+ addAllTriples(g1, g3);
+ addAllTriples(g2, g3);
+
+
+ // Let's make a map to find all those blank nodes after insertion
+ // (The Graph implementation is not currently required to
+ // keep supporting those BlankNodes with contains() - see COMMONSRDF-15)
+
+ final Map<String, BlankNodeOrIRI> whoIsWho = new ConcurrentHashMap<>();
+ // ConcurrentHashMap as we will try parallel forEach below,
+ // which should not give inconsistent results (it does with a
+ // HashMap!)
+
+ // look up BlankNodes by name
+ IRI name = factory.createIRI("http://xmlns.com/foaf/0.1/name");
+ g3.getTriples(null, name, null).parallel().forEach( t ->
+ whoIsWho.put( t.getObject().ntriplesString(), t.getSubject()));
+
+ assertEquals(4, whoIsWho.size());
+ // and contains 4 unique values
+ assertEquals(4, new HashSet<BlankNodeOrIRI>(whoIsWho.values()).size());
+
+ BlankNodeOrIRI b1Alice = whoIsWho.get("\"Alice\"");
+ assertNotNull(b1Alice);
+ BlankNodeOrIRI b2Bob = whoIsWho.get("\"Bob\"");
+ assertNotNull(b2Bob);
+ BlankNodeOrIRI b1Charlie = whoIsWho.get("\"Charlie\"");
+ assertNotNull(b1Charlie);
+ BlankNodeOrIRI b2Dave = whoIsWho.get("\"Dave\"");
+ assertNotNull(b2Dave);
+
+ // All blank nodes should differ
+ notEquals(b1Alice, b2Bob);
+ notEquals(b1Alice, b1Charlie);
+ notEquals(b1Alice, b2Dave);
+ notEquals(b2Bob, b1Charlie);
+ notEquals(b2Bob, b2Dave);
+ notEquals(b1Charlie, b2Dave);
+
+ // And we should be able to query with them again
+ // as we got them back from g3
+ IRI hasChild = factory.createIRI("http://example.com/hasChild");
+ assertTrue(g3.contains(b1Alice, hasChild, b2Bob));
+ assertTrue(g3.contains(b2Dave, hasChild, b1Charlie));
+ // But not
+ assertFalse(g3.contains(b1Alice, hasChild, b1Alice));
+ assertFalse(g3.contains(b1Alice, hasChild, b1Charlie));
+ assertFalse(g3.contains(b1Alice, hasChild, b2Dave));
+ // nor
+ assertFalse(g3.contains(b2Dave, hasChild, b1Alice));
+ assertFalse(g3.contains(b2Dave, hasChild, b1Alice));
+
+ // and these don't have any children (as far as we know)
+ assertFalse(g3.contains(b2Bob, hasChild, null));
+ assertFalse(g3.contains(b1Charlie, hasChild, null));
+ } catch (UnsupportedOperationException ex) {
+ Assume.assumeNoException(ex);
+ }
+ }
+
+ private void notEquals(BlankNodeOrIRI node1, BlankNodeOrIRI node2) {
+ assertFalse(node1.equals(node2));
+ // in which case we should be able to assume
+ // (as they are in the same graph)
+ assertFalse(node1.ntriplesString().equals(node2.ntriplesString()));
+ }
+
+ /**
+ * Add all triples from the source to the target.
+ * <p>
+ * The triples may be copied in any order.
+ * No special conversion or adaptation of {@link BlankNode}s are performed.
+ *
+ * @param source Source Graph to copy triples from
+ * @param target Target Graph where triples will be added
+ */
+ private void addAllTriples(Graph source, Graph target) {
+
+ // unordered() as we don't need to preserve triple order
+ // sequential() as we don't (currently) require target Graph to be thread-safe
+ source.getTriples().unordered().sequential().forEach(t -> target.add(t));
+ }
+
+ /**
+ * Make a new graph with two BlankNodes - each with a different uniqueReference
+ */
+ private Graph createGraph1() {
+ RDFTermFactory factory1 = createFactory();
+
+ IRI name = factory1.createIRI("http://xmlns.com/foaf/0.1/name");
+ Graph g1 = factory1.createGraph();
+ BlankNode b1 = createOwnBlankNode("b1", "0240eaaa-d33e-4fc0-a4f1-169d6ced3680");
+ g1.add(b1, name, factory1.createLiteral("Alice"));
+
+
+ BlankNode b2 = createOwnBlankNode("b2", "9de7db45-0ce7-4b0f-a1ce-c9680ffcfd9f");
+ g1.add(b2, name, factory1.createLiteral("Bob"));
+
+ IRI hasChild = factory1.createIRI("http://example.com/hasChild");
+ g1.add(b1, hasChild, b2);
+
+ return g1;
+ }
+
+ /**
+ * Create a different implementation of BlankNode to be tested with
+ * graph.add(a,b,c);
+ * (the implementation may or may not then choose to translate such to
+ * its own instances)
+ *
+ * @param name
+ * @return
+ */
+ private BlankNode createOwnBlankNode(String name, String uuid) {
+ return new BlankNode() {
+ @Override
+ public String ntriplesString() {
+ return "_: " + name;
+ }
+ @Override
+ public String uniqueReference() {
+ return uuid;
+ }
+ @Override
+ public int hashCode() {
+ return uuid.hashCode();
+ }
+ @Override
+ public boolean equals(Object obj) {
+ if (!( obj instanceof BlankNode)) {
+ return false;
+ }
+ BlankNode other = (BlankNode)obj;
+ return uuid.equals(other.uniqueReference());
+ }
+ };
+ }
+
+ private Graph createGraph2() {
+ RDFTermFactory factory2 = createFactory();
+ IRI name = factory2.createIRI("http://xmlns.com/foaf/0.1/name");
+
+ Graph g2 = factory2.createGraph();
+
+ BlankNode b1 = createOwnBlankNode("b1", "bc8d3e45-a08f-421d-85b3-c25b373abf87");
+ g2.add(b1, name, factory2.createLiteral("Charlie"));
+
+ BlankNode b2 = createOwnBlankNode("b2", "2209097a-5078-4b03-801a-6a2d2f50d739");
+ g2.add(b2, name, factory2.createLiteral("Dave"));
+
+ IRI hasChild = factory2.createIRI("http://example.com/hasChild");
+ // NOTE: Opposite direction of loadGraph1
+ g2.add(b2, hasChild, b1);
+ return g2;
+ }
+
/**
* An attempt to use the Java 8 streams to look up a more complicated query.
* <p>