commonsrdf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject [3/3] incubator-commonsrdf git commit: support blanknode round trip
Date Mon, 04 Apr 2016 14:19:05 GMT
support blanknode round trip


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

Branch: refs/heads/jsonld-java
Commit: 7e4cb373ecc39a31205a8916c2d2471b95cf6a11
Parents: 79cf47d
Author: Stian Soiland-Reyes <stain@apache.org>
Authored: Mon Apr 4 15:18:48 2016 +0100
Committer: Stian Soiland-Reyes <stain@apache.org>
Committed: Mon Apr 4 15:18:48 2016 +0100

----------------------------------------------------------------------
 .../commons/rdf/jsonldjava/JsonLDGraph.java     | 28 ++++++++++++--------
 1 file changed, 17 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/7e4cb373/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLDGraph.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLDGraph.java
b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLDGraph.java
index 52ee126..7b9fed7 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLDGraph.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLDGraph.java
@@ -17,7 +17,6 @@
  */
 package org.apache.commons.rdf.jsonldjava;
 
-import java.util.Iterator;
 import java.util.List;
 import java.util.Objects;
 import java.util.Optional;
@@ -105,6 +104,10 @@ public class JsonLDGraph implements Graph {
 		};
 	}
 	
+	private String bnodePrefix() {
+		return "urn:uuid:" + SALT + "#" +  "g"+ System.identityHashCode(rdfDataSet);
+	}
+	
 	private RDFTerm asTerm(final Node node) {		
 		if (node.isIRI()) {
 			return new IRI() {				
@@ -141,7 +144,7 @@ public class JsonLDGraph implements Graph {
 				
 				@Override
 				public String uniqueReference() {					
-					return "urn:uuid:" + SALT + "#" +  "g"+ System.identityHashCode(rdfDataSet) + node.getValue();
+					return bnodePrefix() + node.getValue();
 				}
 				
 				@Override
@@ -187,7 +190,14 @@ public class JsonLDGraph implements Graph {
 			return new RDFDataset.IRI( ((IRI)term).getIRIString() );
 		}
 		if (term instanceof BlankNode) {
-			return new RDFDataset.BlankNode( ((BlankNode)term).uniqueReference() );
+			
+			String uniqueReference = ((BlankNode)term).uniqueReference();
+			if (uniqueReference.startsWith(bnodePrefix())) {
+				// one of our own
+				// TODO: Retrieve the original BlankNode
+				return new RDFDataset.BlankNode(term.ntriplesString());
+			} 
+			return new RDFDataset.BlankNode( "_:" + uniqueReference );
 		}
 		if (term instanceof Literal) {
 			Literal literal = (Literal) term;
@@ -234,11 +244,7 @@ public class JsonLDGraph implements Graph {
 
 	@Override
 	public void remove(Triple triple) {
-		// rdfDataSet has no remove method - so we'll have to remove them
-		// from the inner Lists' iterator					
-		for (Iterator<? extends Triple> it = getTriples().filter(Predicate.isEqual(triple)).iterator()
;; it.hasNext()) {
-			it.remove();
-		}		
+		remove(triple.getSubject(), triple.getPredicate(), triple.getObject());
 	}
 
 	@Override
@@ -257,13 +263,13 @@ public class JsonLDGraph implements Graph {
 		Optional<Node> objectNode = Optional.ofNullable(object).map(this::asJsonLdNode);
 		
 		return q -> {
-		    if (subjectNode.isPresent() && subjectNode.get().compareTo(q.getSubject())
== 0) {
+		    if (subjectNode.isPresent() && subjectNode.get().compareTo(q.getSubject())
!= 0) {
 		        return false;
 		    }
-		    if (predicateNode.isPresent() && predicateNode.get().compareTo(q.getPredicate())
== 0) {	          
+		    if (predicateNode.isPresent() && predicateNode.get().compareTo(q.getPredicate())
!= 0) {	          
 		        return false;
 		    }
-		    if (objectNode.isPresent() && objectNode.get().compareTo(q.getObject()) ==
0) {
+		    if (objectNode.isPresent() && objectNode.get().compareTo(q.getObject()) !=
0) {
 		        return false;
 		    }
 		    return true;			


Mime
View raw message