commonsrdf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject [28/50] incubator-commonsrdf git commit: factory converter methods called asSomething()
Date Tue, 04 Oct 2016 01:30:49 GMT
factory converter methods called asSomething()

e.g. asGraph(rdfDataSet)


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

Branch: refs/heads/rdf4j
Commit: fd8dcefd08170804ac80e24bc770fc7abfb5d1e7
Parents: e3a4fba
Author: Stian Soiland-Reyes <stain@apache.org>
Authored: Fri Sep 9 15:42:09 2016 +0100
Committer: Stian Soiland-Reyes <stain@apache.org>
Committed: Fri Sep 9 15:43:42 2016 +0100

----------------------------------------------------------------------
 .../commons/rdf/jsonldjava/JsonLdDataset.java   | 10 +++---
 .../commons/rdf/jsonldjava/JsonLdGraph.java     | 12 ++++---
 .../commons/rdf/jsonldjava/JsonLdGraphLike.java |  4 +--
 .../rdf/jsonldjava/JsonLdParserBuilder.java     |  5 ++-
 .../commons/rdf/jsonldjava/JsonLdQuadLike.java  | 10 +++---
 .../rdf/jsonldjava/JsonLdRDFTermFactory.java    | 33 ++++++++++++++------
 .../rdf/jsonldjava/JsonLdUnionGraph.java        |  8 ++---
 7 files changed, 51 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/fd8dcefd/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdDataset.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdDataset.java
b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdDataset.java
index 569180e..1ab4b11 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdDataset.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdDataset.java
@@ -32,9 +32,9 @@ import org.apache.commons.rdf.api.RDFTerm;
 
 import com.github.jsonldjava.core.RDFDataset;
 
-public class JsonLdDataset extends JsonLdGraphLike<org.apache.commons.rdf.api.Quad>
implements Dataset {
+class JsonLdDataset extends JsonLdGraphLike<org.apache.commons.rdf.api.Quad> implements
Dataset {
 
-	public JsonLdDataset(RDFDataset rdfDataSet) {
+	JsonLdDataset(RDFDataset rdfDataSet) {
 		super(rdfDataSet);
 	}
 
@@ -75,7 +75,7 @@ public class JsonLdDataset extends JsonLdGraphLike<org.apache.commons.rdf.api.Qu
 	public Stream<BlankNodeOrIRI> getGraphNames() {
 		return rdfDataSet.graphNames().parallelStream().filter(Predicate.isEqual("@default").negate())
 				.map(s -> s.startsWith("_:") ? new RDFDataset.BlankNode(s) : new RDFDataset.IRI(s))
-				.map(n -> (BlankNodeOrIRI) factory.asTerm(n, bnodePrefix));		
+				.map(n -> (BlankNodeOrIRI) factory.asRDFTerm(n));
 	}
 
 	@Override
@@ -95,7 +95,7 @@ public class JsonLdDataset extends JsonLdGraphLike<org.apache.commons.rdf.api.Qu
 		return filteredGraphs(graphName)
 				.flatMap(List::stream)
 				.filter(quadFilter(subject, predicate, object))
-				.map(factory::createQuad);
+				.map(factory::asQuad);
 	}
 
 	@Override
@@ -105,7 +105,7 @@ public class JsonLdDataset extends JsonLdGraphLike<org.apache.commons.rdf.api.Qu
 
 	@Override
 	Quad asTripleOrQuad(com.github.jsonldjava.core.RDFDataset.Quad jsonldQuad) {
-		return factory.createQuad(jsonldQuad);
+		return factory.asQuad(jsonldQuad);
 	}
 
 

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/fd8dcefd/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 5e13a4e..a07f9b1 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
@@ -30,11 +30,15 @@ import org.apache.commons.rdf.api.Triple;
 
 import com.github.jsonldjava.core.RDFDataset;
 
-public class JsonLdGraph extends JsonLdGraphLike<org.apache.commons.rdf.api.Triple>
implements Graph {
+/**
+ * A {@link Graph} view of a JsonLd {@link RDFDataset}.
+ * 
+ */
+class JsonLdGraph extends JsonLdGraphLike<org.apache.commons.rdf.api.Triple> implements
Graph {
 
 	private final Optional<BlankNodeOrIRI> graphName;
 
-	public JsonLdGraph(RDFDataset rdfDataSet) {
+	JsonLdGraph(RDFDataset rdfDataSet) {
 		super(rdfDataSet);
 		this.graphName = Optional.empty();
 	}
@@ -99,12 +103,12 @@ public class JsonLdGraph extends JsonLdGraphLike<org.apache.commons.rdf.api.Trip
 		return filteredGraphs(graphName)
 				.flatMap(List::stream)
 				.filter(quadFilter(subject, predicate, object))
-				.map(factory::createTriple);
+				.map(factory::asTriple);
 	}
 	
 	@Override
 	JsonLdTriple asTripleOrQuad(com.github.jsonldjava.core.RDFDataset.Quad jsonldQuad) {
-		return factory.createTriple(jsonldQuad);
+		return factory.asTriple(jsonldQuad);
 	}
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/fd8dcefd/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdGraphLike.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdGraphLike.java
b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdGraphLike.java
index ad2cc23..81f2ee7 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdGraphLike.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdGraphLike.java
@@ -175,8 +175,8 @@ abstract class JsonLdGraphLike<T extends TripleLike<BlankNodeOrIRI,
IRI, RDFTerm
 	 * Convert JsonLd Quad to a Commons RDF {@link Triple} or {@link org.apache.commons.rdf.api.Quad}
 	 * 
 	 * 
-	 * @see JsonLdRDFTermFactory#createTriple(Quad)
-	 * @see JsonLdRDFTermFactory#createQuad(Quad)
+	 * @see JsonLdRDFTermFactory#asTriple(Quad)
+	 * @see JsonLdRDFTermFactory#asQuad(Quad)
 	 * @param jsonldQuad jsonld quad to convert
 	 * @return converted {@link TripleLike}
 	 */

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/fd8dcefd/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdParserBuilder.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdParserBuilder.java
b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdParserBuilder.java
index 4b6edfe..d609aa8 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdParserBuilder.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdParserBuilder.java
@@ -92,8 +92,7 @@ public class JsonLdParserBuilder extends AbstractRDFParserBuilder {
 			rdfDataset = (RDFDataset) JsonLdProcessor.toRDF(json, options);
 		} catch (JsonLdError e) {
 			throw new RDFParseException(e);
-		}
-
+		}		
 		Graph intoGraph = getIntoGraph().get();
 		if (intoGraph instanceof JsonLdGraph && ! intoGraph.contains(null, null, null))
{
 			// Empty graph, we can just move over the map content directly:
@@ -103,7 +102,7 @@ public class JsonLdParserBuilder extends AbstractRDFParserBuilder {
 			// TODO: Modify JsonLdProcessor to have an actual triple callback
 			try (JsonLdGraph parsedGraph = new JsonLdGraph(rdfDataset)) {
 				// sequential() as we don't know if intoGraph is thread safe :-/
-				parsedGraph.getTriples().sequential().forEach(intoGraph::add);
+				parsedGraph.stream().sequential().forEach(intoGraph::add);
 			}
 		}
 	}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/fd8dcefd/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdQuadLike.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdQuadLike.java
b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdQuadLike.java
index 753e332..224dc30 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdQuadLike.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdQuadLike.java
@@ -30,6 +30,8 @@ public interface JsonLdQuadLike<S extends RDFTerm, P extends RDFTerm,
O extends
 	
 	class JsonLdQuadLikeImpl<S extends RDFTerm, P extends RDFTerm, O extends RDFTerm, G extends
RDFTerm> implements JsonLdQuadLike<S,P,O,G> {
 		
+		// Note: We always pass the blankNodePrefix and don't rely on the internal
+		// blankNodePrefix in this static factory
 		private static JsonLdRDFTermFactory rdfTermFactory = new JsonLdRDFTermFactory();
 		
 		private final Quad quad;
@@ -43,26 +45,26 @@ public interface JsonLdQuadLike<S extends RDFTerm, P extends RDFTerm,
O extends
 		@SuppressWarnings("unchecked")	
 		@Override
 		public Optional<G> getGraphName() {
-			G g = (G) rdfTermFactory.asTerm(quad.getGraph(), blankNodePrefix);
+			G g = (G) rdfTermFactory.asRDFTerm(quad.getGraph(), blankNodePrefix);
 			return Optional.ofNullable(g);
 		}
 		
 		@SuppressWarnings("unchecked")
 		@Override
 		public S getSubject() {
-			return (S) rdfTermFactory.asTerm(quad.getSubject(), blankNodePrefix);
+			return (S) rdfTermFactory.asRDFTerm(quad.getSubject(), blankNodePrefix);
 		}
 	
 		@SuppressWarnings("unchecked")
 		@Override
 		public P getPredicate() {
-			return (P) rdfTermFactory.asTerm(quad.getPredicate(), blankNodePrefix);
+			return (P) rdfTermFactory.asRDFTerm(quad.getPredicate(), blankNodePrefix);
 		}
 	
 		@SuppressWarnings("unchecked")
 		@Override
 		public O getObject() {
-			return (O) rdfTermFactory.asTerm(quad.getObject(), blankNodePrefix);
+			return (O) rdfTermFactory.asRDFTerm(quad.getObject(), blankNodePrefix);
 		}
 	
 		public Quad asJsonLdQuad() {

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/fd8dcefd/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdRDFTermFactory.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdRDFTermFactory.java
b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdRDFTermFactory.java
index 1dff9fb..6d490b8 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdRDFTermFactory.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdRDFTermFactory.java
@@ -48,7 +48,7 @@ public final class JsonLdRDFTermFactory implements RDFTermFactory {
 		// An "outside Graph" bnodePrefix
 		this("urn:uuid:" + UUID.randomUUID() + "#b");
 	}
-	
+		
 	JsonLdRDFTermFactory(String bnodePrefix) {
 		this.bnodePrefix = Objects.requireNonNull(bnodePrefix);
 	}
@@ -61,8 +61,7 @@ public final class JsonLdRDFTermFactory implements RDFTermFactory {
 		if (term instanceof IRI) {
 			return new RDFDataset.IRI( ((IRI)term).getIRIString() );
 		}
-		if (term instanceof BlankNode) {
-			
+		if (term instanceof BlankNode) {			
 			String ref = ((BlankNode)term).uniqueReference();
 			if (ref.startsWith(bnodePrefix)) {
 				// one of our own (but no longer a JsonLdBlankNode),
@@ -113,14 +112,26 @@ public final class JsonLdRDFTermFactory implements RDFTermFactory {
 		// TODO: Check if name is valid JSON-LD BlankNode identifier		
 		return new JsonLdBlankNodeImpl(new RDFDataset.BlankNode(id), bnodePrefix);
 	}
-	
+
 	@Override
-	public Dataset createDataset() throws UnsupportedOperationException {
+	public Dataset createDataset() {
 		return new JsonLdDataset(bnodePrefix);
 	}
+	
+	public Dataset asDataset(RDFDataset rdfDataSet) {
+		return new JsonLdDataset(rdfDataSet);
+	}
 
+	public Graph asGraph(RDFDataset rdfDataSet) {
+		return new JsonLdGraph(rdfDataSet);
+	}
+
+	public Graph asUnionGraph(RDFDataset rdfDataSet) {
+		return new JsonLdUnionGraph(rdfDataSet);
+	}
+	
 	@Override
-	public Graph createGraph() throws UnsupportedOperationException {
+	public Graph createGraph() {
 		return new JsonLdGraph(bnodePrefix);
 	}
 	
@@ -151,7 +162,7 @@ public final class JsonLdRDFTermFactory implements RDFTermFactory {
 	}
 	
 
-	public JsonLdQuad createQuad(final RDFDataset.Quad quad) {
+	public JsonLdQuad asQuad(final RDFDataset.Quad quad) {
 		return new JsonLdQuadImpl(quad, bnodePrefix);
 	}
 
@@ -160,11 +171,15 @@ public final class JsonLdRDFTermFactory implements RDFTermFactory {
 		return new JsonLdTripleImpl(asJsonLdQuad(subject, predicate, object), bnodePrefix);
 	}
 	
-	public JsonLdTriple createTriple(final RDFDataset.Quad quad) {
+	public JsonLdTriple asTriple(final RDFDataset.Quad quad) {
 		return new JsonLdTripleImpl(quad, bnodePrefix);
 	}
 	
-	JsonLdTerm asTerm(final Node node, String blankNodePrefix) {	
+	public JsonLdTerm asRDFTerm(final Node node) {
+		return asRDFTerm(node, bnodePrefix);
+	}
+	
+	JsonLdTerm asRDFTerm(final Node node, String blankNodePrefix) {	
 		if (node == null) {
 			return null; // e.g. default graph
 		}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/fd8dcefd/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdUnionGraph.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdUnionGraph.java
b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdUnionGraph.java
index 6b32f8c..46598ed 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdUnionGraph.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdUnionGraph.java
@@ -46,13 +46,13 @@ import com.github.jsonldjava.core.RDFDataset;
  * inefficient as they skip any duplicate triples from multiple
  * graphs.
  */
-public class JsonLdUnionGraph extends JsonLdGraphLike<org.apache.commons.rdf.api.Triple>
implements Graph {
+class JsonLdUnionGraph extends JsonLdGraphLike<org.apache.commons.rdf.api.Triple> implements
Graph {
 
 	JsonLdUnionGraph(String bnodePrefix) {
 		super(bnodePrefix);
 	}
 	
-	public JsonLdUnionGraph(RDFDataset rdfDataSet) {
+	JsonLdUnionGraph(RDFDataset rdfDataSet) {
 		super(rdfDataSet);
 	}
 	
@@ -88,7 +88,7 @@ public class JsonLdUnionGraph extends JsonLdGraphLike<org.apache.commons.rdf.api
 		return filteredGraphs(null)
 				.flatMap(List::stream)
 				.filter(quadFilter(subject, predicate, object))
-				.map(factory::createTriple)
+				.map(factory::asTriple)
 				// Make sure we don't have duplicate triples
 				// NOTE: This can be quite inefficient
 				.distinct();
@@ -103,7 +103,7 @@ public class JsonLdUnionGraph extends JsonLdGraphLike<org.apache.commons.rdf.api
 
 	@Override
 	JsonLdTriple asTripleOrQuad(com.github.jsonldjava.core.RDFDataset.Quad jsonldQuad) {
-		return factory.createTriple(jsonldQuad);
+		return factory.asTriple(jsonldQuad);
 	}
 	
 	@Override


Mime
View raw message