commonsrdf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject [1/4] incubator-commonsrdf git commit: externalize the blankNodePrefix
Date Mon, 04 Apr 2016 14:47:35 GMT
Repository: incubator-commonsrdf
Updated Branches:
  refs/heads/jsonld-java 6c72b27a3 -> 3dc5a4492


externalize the blankNodePrefix


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

Branch: refs/heads/jsonld-java
Commit: 85bf54d32b0d3f31c3f3aca0b0bdec9c6b819cc3
Parents: 6c72b27
Author: Stian Soiland-Reyes <stain@apache.org>
Authored: Mon Apr 4 15:35:40 2016 +0100
Committer: Stian Soiland-Reyes <stain@apache.org>
Committed: Mon Apr 4 15:35:40 2016 +0100

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


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/85bf54d3/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 a58f358..bfe504c 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
@@ -41,10 +41,12 @@ import com.github.jsonldjava.core.RDFDataset.Quad;
 
 public class JsonLDGraph implements Graph {
 	
-	private final class JsonLdBlankNode implements BlankNode {
+	private static final class JsonLdBlankNode implements BlankNode {
 		private final Node node;
+		private String blankNodePrefix;
 
-		private JsonLdBlankNode(Node node) {
+		private JsonLdBlankNode(Node node, String blankNodePrefix) {
+			this.blankNodePrefix = blankNodePrefix;
 			this.node = node;
 		}
 
@@ -55,7 +57,7 @@ public class JsonLDGraph implements Graph {
 
 		@Override
 		public String uniqueReference() {					
-			return bnodePrefix() + node.getValue();
+			return blankNodePrefix + node.getValue();
 		}
 
 		@Override
@@ -73,7 +75,7 @@ public class JsonLDGraph implements Graph {
 		}
 	}
 
-	private final class JsonLdIRI implements IRI {
+	private static final class JsonLdIRI implements IRI {
 		private final Node node;
 
 		private JsonLdIRI(Node node) {
@@ -105,26 +107,28 @@ public class JsonLDGraph implements Graph {
 		}
 	}
 
-	private final class JsonLdTriple implements Triple {
+	private static final class JsonLdTriple implements Triple {
 		private final Quad quad;
+		private String blankNodePrefix;
 
-		private JsonLdTriple(Quad quad) {
+		private JsonLdTriple(Quad quad, String blankNodePrefix) {
 			this.quad = quad;
+			this.blankNodePrefix = blankNodePrefix;			
 		}
 
 		@Override
 		public BlankNodeOrIRI getSubject() {
-			return (BlankNodeOrIRI) asTerm(quad.getSubject());
+			return (BlankNodeOrIRI) asTerm(quad.getSubject(), blankNodePrefix);
 		}
 
 		@Override
 		public IRI getPredicate() {
-			return (IRI) asTerm(quad.getPredicate());
+			return (IRI) asTerm(quad.getPredicate(), blankNodePrefix);
 		}
 
 		@Override
 		public RDFTerm getObject() {
-			return asTerm(quad.getObject());
+			return asTerm(quad.getObject(), blankNodePrefix);
 		}
 
 		@Override
@@ -170,18 +174,18 @@ public class JsonLDGraph implements Graph {
 	private static RDFTermFactory rdfTermFactory = new SimpleRDFTermFactory();
 
 	private Triple asTriple(final RDFDataset.Quad quad) {
-		return new JsonLdTriple(quad);
+		return new JsonLdTriple(quad, bnodePrefix());
 	}
 	
 	private String bnodePrefix() {
 		return "urn:uuid:" + SALT + "#" +  "g"+ System.identityHashCode(rdfDataSet);
 	}
 	
-	private RDFTerm asTerm(final Node node) {		
+	private static RDFTerm asTerm(final Node node, String blankNodePrefix) {		
 		if (node.isIRI()) {
 			return new JsonLdIRI(node);
 		} else if (node.isBlankNode()) {
-			return new JsonLdBlankNode(node);
+			return new JsonLdBlankNode(node, blankNodePrefix);
 		} else if (node.isLiteral()) {
 			// TODO: Our own JsonLdLiteral
 			if (node.getLanguage() != null) {


Mime
View raw message