commonsrdf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject [4/4] incubator-commonsrdf git commit: Sorted methods
Date Fri, 09 Sep 2016 15:23:07 GMT
Sorted methods


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

Branch: refs/heads/jsonld-java
Commit: ddbe6bfb0404f0da82062db3d48ae7cdccd166a0
Parents: 44a40d3
Author: Stian Soiland-Reyes <stain@apache.org>
Authored: Fri Sep 9 16:22:33 2016 +0100
Committer: Stian Soiland-Reyes <stain@apache.org>
Committed: Fri Sep 9 16:22:33 2016 +0100

----------------------------------------------------------------------
 .../rdf/jsonldjava/JsonLdRDFTermFactory.java    | 232 +++++++++----------
 1 file changed, 116 insertions(+), 116 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ddbe6bfb/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 d436434..fa60213 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
@@ -52,6 +52,39 @@ public final class JsonLdRDFTermFactory implements RDFTermFactory {
 		this.bnodePrefix = Objects.requireNonNull(bnodePrefix);
 	}
 
+	/**
+	 * Adapt a JsonLd {@link RDFDataset} as a Commons RDF {@link Dataset}.
+	 * <p>
+	 * Changes to the Commons RDF {@link Dataset} are reflected in the JsonLd
+	 * {@link RDFDataset} and vice versa.
+	 * 
+	 * @see #asGraph(RDFDataset)
+	 * @param rdfDataSet JsonLd {@link RDFDataset} to adapt
+	 * @return Adapted {@link Dataset}
+	 */
+	public Dataset asDataset(RDFDataset rdfDataSet) {
+		return new JsonLdDataset(rdfDataSet);
+	}
+
+	/**
+	 * Adapt a JsonLd {@link RDFDataset} as a Commons RDF {@link Graph}.
+	 * <p>
+	 * Only triples in the <em>default graph</em> are included. To retrieve
+	 * any other graph, {@link #asDataset(RDFDataset)} together with 
+	 * {@link Dataset#getGraph(BlankNodeOrIRI)}.  
+	 * <p>
+	 * Changes to the Commons RDF {@link Graph} are reflected in the JsonLd
+	 * {@link RDFDataset} and vice versa.
+	 * 
+	 * @see #asDataset(RDFDataset)
+	 * @see #asUnionGraph(RDFDataset) 
+	 * @param rdfDataSet JsonLd {@link RDFDataset} to adapt
+	 * @return Adapted {@link Graph} covering the <em>default graph</em>
+	 */	
+	public Graph asGraph(RDFDataset rdfDataSet) {
+		return new JsonLdGraph(rdfDataSet);
+	}
+
 	public Node asJsonLdNode(RDFTerm term) {
 		if (term instanceof JsonLdTerm) {
 			// Return original Node
@@ -78,46 +111,9 @@ public final class JsonLdRDFTermFactory implements RDFTermFactory {
 					literal.getLanguageTag().orElse(null));
 		}
 		throw new IllegalArgumentException("RDFTerm not instanceof IRI, BlankNode or Literal: "
+ term);
-	}
-
-	RDFDataset.Quad createJsonLdQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate,
RDFTerm object) {
-		return new RDFDataset.Quad(asJsonLdNode(subject), asJsonLdNode(predicate), asJsonLdNode(object),
asJsonLdString(graphName));
-	}
-
-	String asJsonLdString(BlankNodeOrIRI blankNodeOrIRI) {
-		if (blankNodeOrIRI == null) {
-			return null;
-		}
-		if (blankNodeOrIRI instanceof IRI) {
-			return ((IRI)blankNodeOrIRI).getIRIString();
-		} else if (blankNodeOrIRI instanceof BlankNode) {
-			BlankNode blankNode = (BlankNode) blankNodeOrIRI;
-			String ref = blankNode.uniqueReference();
-			if (ref.startsWith(bnodePrefix)) { 
-				// One of ours (but possibly not a JsonLdBlankNode) -  
-				// we can use the suffix directly
-				return ref.replace(bnodePrefix, "_:");
-			} else {
-				// Map to unique bnode identifier, e.g. _:0dbd92ee-ab1a-45e7-bba2-7ade54f87ec5
-				UUID uuid = UUID.nameUUIDFromBytes(ref.getBytes(StandardCharsets.UTF_8));
-				return "_:"+ uuid;
-			}
-		} else {
-			throw new IllegalArgumentException("Expected a BlankNode or IRI, not: " + blankNodeOrIRI);
-		}
 	}	
 
 	/**
-	 * Adapt a Commons RDF {@link Triple} as a JsonLd {@link RDFDataset.Quad}.
-	 * 
-	 * @param triple Commons RDF {@link Triple} to adapt
-	 * @return Adapted JsonLd {@link RDFDataset.Quad}
-	 */
-	public RDFDataset.Quad asJsonLdQuad(Triple triple) {
-		return createJsonLdQuad(null, triple.getSubject(), triple.getPredicate(), triple.getObject());
-	}
-	
-	/**
 	 * Adapt a Commons RDF {@link org.apache.commons.rdf.api.Quad} as a JsonLd {@link RDFDataset.Quad}.
 	 * 
 	 * @param quad Commons RDF {@link org.apache.commons.rdf.api.Quad}  to adapt
@@ -127,56 +123,59 @@ public final class JsonLdRDFTermFactory implements RDFTermFactory {
 		BlankNodeOrIRI g = quad.getGraphName().orElse(null);		
 		return createJsonLdQuad(g, quad.getSubject(), quad.getPredicate(), quad.getObject());
 	}
-
-	@Override
-	public JsonLdBlankNode createBlankNode() {
-		String id = "_:" + UUID.randomUUID().toString();
-		return new JsonLdBlankNodeImpl(new RDFDataset.BlankNode(id), bnodePrefix);
-	}
-
-	@Override
-	public JsonLdBlankNode createBlankNode(String name) {
-		String id = "_:" + name;
-		// TODO: Check if name is valid JSON-LD BlankNode identifier
-		return new JsonLdBlankNodeImpl(new RDFDataset.BlankNode(id), bnodePrefix);
+	
+	/**
+	 * Adapt a Commons RDF {@link Triple} as a JsonLd {@link RDFDataset.Quad}.
+	 * 
+	 * @param triple Commons RDF {@link Triple} to adapt
+	 * @return Adapted JsonLd {@link RDFDataset.Quad}
+	 */
+	public RDFDataset.Quad asJsonLdQuad(Triple triple) {
+		return createJsonLdQuad(null, triple.getSubject(), triple.getPredicate(), triple.getObject());
 	}
 
-	@Override
-	public Dataset createDataset() {
-		return new JsonLdDataset(bnodePrefix);
+	/**
+	 * Adapt a JsonLd {@link RDFDataset.Quad} as a Commons RDF
+	 * {@link org.apache.commons.rdf.api.Quad}.
+	 * <p>
+	 * The underlying JsonLd quad can be retrieved with
+	 * {@link JsonLdQuad#asJsonLdQuad()}.
+	 * 
+	 * @param quad
+	 *            A JsonLd {@link RDFDataset.Quad} to adapt
+	 * @return Adapted {@link JsonLdQuad}
+	 */
+	public JsonLdQuad asQuad(final RDFDataset.Quad quad) {
+		return new JsonLdQuadImpl(quad, bnodePrefix);
 	}
 
 	/**
-	 * Adapt a JsonLd {@link RDFDataset} as a Commons RDF {@link Dataset}.
+	 * Adapt a JsonLd {@link RDFDataset.Node} as a Commons RDF {@link RDFTerm}.
 	 * <p>
-	 * Changes to the Commons RDF {@link Dataset} are reflected in the JsonLd
-	 * {@link RDFDataset} and vice versa.
+	 * The underlying node can be retrieved with
+	 * {@link JsonLdTerm#asJsonLdNode()}.
 	 * 
-	 * @see #asGraph(RDFDataset)
-	 * @param rdfDataSet JsonLd {@link RDFDataset} to adapt
-	 * @return Adapted {@link Dataset}
+	 * @param node
+	 *            A JsonLd {@link Node} to adapt
+	 * @return Adapted {@link JsonLdTerm}
 	 */
-	public Dataset asDataset(RDFDataset rdfDataSet) {
-		return new JsonLdDataset(rdfDataSet);
+	public JsonLdTerm asRDFTerm(final Node node) {
+		return asRDFTerm(node, bnodePrefix);
 	}
 
 	/**
-	 * Adapt a JsonLd {@link RDFDataset} as a Commons RDF {@link Graph}.
-	 * <p>
-	 * Only triples in the <em>default graph</em> are included. To retrieve
-	 * any other graph, {@link #asDataset(RDFDataset)} together with 
-	 * {@link Dataset#getGraph(BlankNodeOrIRI)}.  
+	 * Adapt a JsonLd {@link RDFDataset.Quad} as a Commons RDF
+	 * {@link org.apache.commons.rdf.api.Triple}.
 	 * <p>
-	 * Changes to the Commons RDF {@link Graph} are reflected in the JsonLd
-	 * {@link RDFDataset} and vice versa.
+	 * The underlying JsonLd quad can be retrieved with
+	 * {@link JsonLdTriple#asJsonLdQuad()}.
 	 * 
-	 * @see #asDataset(RDFDataset)
-	 * @see #asUnionGraph(RDFDataset) 
-	 * @param rdfDataSet JsonLd {@link RDFDataset} to adapt
-	 * @return Adapted {@link Graph} covering the <em>default graph</em>
-	 */	
-	public Graph asGraph(RDFDataset rdfDataSet) {
-		return new JsonLdGraph(rdfDataSet);
+	 * @param quad
+	 *            A JsonLd {@link RDFDataset.Quad} to adapt
+	 * @return Adapted {@link JsonLdTriple}
+	 */
+	public JsonLdTriple asTriple(final RDFDataset.Quad quad) {
+		return new JsonLdTripleImpl(quad, bnodePrefix);
 	}
 
 	/**
@@ -202,6 +201,24 @@ public final class JsonLdRDFTermFactory implements RDFTermFactory {
 	}
 
 	@Override
+	public JsonLdBlankNode createBlankNode() {
+		String id = "_:" + UUID.randomUUID().toString();
+		return new JsonLdBlankNodeImpl(new RDFDataset.BlankNode(id), bnodePrefix);
+	}
+
+	@Override
+	public JsonLdBlankNode createBlankNode(String name) {
+		String id = "_:" + name;
+		// TODO: Check if name is valid JSON-LD BlankNode identifier
+		return new JsonLdBlankNodeImpl(new RDFDataset.BlankNode(id), bnodePrefix);
+	}
+
+	@Override
+	public Dataset createDataset() {
+		return new JsonLdDataset(bnodePrefix);
+	}
+
+	@Override
 	public Graph createGraph() {
 		return new JsonLdGraph(bnodePrefix);
 	}
@@ -232,53 +249,32 @@ public final class JsonLdRDFTermFactory implements RDFTermFactory {
 		return new JsonLdQuadImpl(createJsonLdQuad(graphName, subject, predicate, object), bnodePrefix);
 	}
 
-	/**
-	 * Adapt a JsonLd {@link RDFDataset.Quad} as a Commons RDF
-	 * {@link org.apache.commons.rdf.api.Quad}.
-	 * <p>
-	 * The underlying JsonLd quad can be retrieved with
-	 * {@link JsonLdQuad#asJsonLdQuad()}.
-	 * 
-	 * @param quad
-	 *            A JsonLd {@link RDFDataset.Quad} to adapt
-	 * @return Adapted {@link JsonLdQuad}
-	 */
-	public JsonLdQuad asQuad(final RDFDataset.Quad quad) {
-		return new JsonLdQuadImpl(quad, bnodePrefix);
-	}
-
 	@Override
 	public JsonLdTriple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
{
 		return new JsonLdTripleImpl(createJsonLdQuad(null, subject, predicate, object), bnodePrefix);
 	}
 
-	/**
-	 * Adapt a JsonLd {@link RDFDataset.Quad} as a Commons RDF
-	 * {@link org.apache.commons.rdf.api.Triple}.
-	 * <p>
-	 * The underlying JsonLd quad can be retrieved with
-	 * {@link JsonLdTriple#asJsonLdQuad()}.
-	 * 
-	 * @param quad
-	 *            A JsonLd {@link RDFDataset.Quad} to adapt
-	 * @return Adapted {@link JsonLdTriple}
-	 */
-	public JsonLdTriple asTriple(final RDFDataset.Quad quad) {
-		return new JsonLdTripleImpl(quad, bnodePrefix);
-	}
-
-	/**
-	 * Adapt a JsonLd {@link RDFDataset.Node} as a Commons RDF {@link RDFTerm}.
-	 * <p>
-	 * The underlying node can be retrieved with
-	 * {@link JsonLdTerm#asJsonLdNode()}.
-	 * 
-	 * @param node
-	 *            A JsonLd {@link Node} to adapt
-	 * @return Adapted {@link JsonLdTerm}
-	 */
-	public JsonLdTerm asRDFTerm(final Node node) {
-		return asRDFTerm(node, bnodePrefix);
+	String asJsonLdString(BlankNodeOrIRI blankNodeOrIRI) {
+		if (blankNodeOrIRI == null) {
+			return null;
+		}
+		if (blankNodeOrIRI instanceof IRI) {
+			return ((IRI)blankNodeOrIRI).getIRIString();
+		} else if (blankNodeOrIRI instanceof BlankNode) {
+			BlankNode blankNode = (BlankNode) blankNodeOrIRI;
+			String ref = blankNode.uniqueReference();
+			if (ref.startsWith(bnodePrefix)) { 
+				// One of ours (but possibly not a JsonLdBlankNode) -  
+				// we can use the suffix directly
+				return ref.replace(bnodePrefix, "_:");
+			} else {
+				// Map to unique bnode identifier, e.g. _:0dbd92ee-ab1a-45e7-bba2-7ade54f87ec5
+				UUID uuid = UUID.nameUUIDFromBytes(ref.getBytes(StandardCharsets.UTF_8));
+				return "_:"+ uuid;
+			}
+		} else {
+			throw new IllegalArgumentException("Expected a BlankNode or IRI, not: " + blankNodeOrIRI);
+		}
 	}
 
 	JsonLdTerm asRDFTerm(final Node node, String blankNodePrefix) {
@@ -301,4 +297,8 @@ public final class JsonLdRDFTermFactory implements RDFTermFactory {
 		}
 	}
 
+	RDFDataset.Quad createJsonLdQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate,
RDFTerm object) {
+		return new RDFDataset.Quad(asJsonLdNode(subject), asJsonLdNode(predicate), asJsonLdNode(object),
asJsonLdString(graphName));
+	}
+
 }
\ No newline at end of file


Mime
View raw message