You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2016/10/03 10:35:58 UTC

[26/41] jena git commit: sample code

sample code

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

Branch: refs/heads/master
Commit: e2707e6e88a94e6442c200671be5bac4e98a0bf7
Parents: 3208545
Author: Franc\u0327ois-Paul Servant <fp...@semanlink.net>
Authored: Sat Sep 24 19:28:04 2016 +0200
Committer: Franc\u0327ois-Paul Servant <fp...@semanlink.net>
Committed: Sat Sep 24 19:28:04 2016 +0200

----------------------------------------------------------------------
 .../arq/examples/riot/ExJsonLD.java             | 370 +++++++++++++++++++
 .../apache/jena/riot/writer/JsonLDWriter.java   |   5 +-
 .../jena/riot/writer/TestJsonLDWriter.java      |  47 ++-
 3 files changed, 396 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/e2707e6e/jena-arq/src-examples/arq/examples/riot/ExJsonLD.java
----------------------------------------------------------------------
diff --git a/jena-arq/src-examples/arq/examples/riot/ExJsonLD.java b/jena-arq/src-examples/arq/examples/riot/ExJsonLD.java
new file mode 100644
index 0000000..ce0f69c
--- /dev/null
+++ b/jena-arq/src-examples/arq/examples/riot/ExJsonLD.java
@@ -0,0 +1,370 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package arq.examples.riot;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.StringReader;
+
+import org.apache.jena.query.DatasetFactory;
+import org.apache.jena.rdf.model.Model ;
+import org.apache.jena.rdf.model.ModelFactory;
+import org.apache.jena.rdf.model.Resource;
+import org.apache.jena.riot.JsonLDWriteContext;
+import org.apache.jena.riot.RDFDataMgr;
+import org.apache.jena.riot.RDFFormat;
+import org.apache.jena.riot.WriterDatasetRIOT;
+import org.apache.jena.riot.system.PrefixMap;
+import org.apache.jena.riot.system.RiotLib;
+import org.apache.jena.sparql.core.DatasetGraph;
+import org.apache.jena.sparql.util.Context;
+import org.apache.jena.vocabulary.RDF;
+import org.apache.jena.vocabulary.RDFS;
+
+import com.github.jsonldjava.core.JsonLdOptions;
+
+/** Example writing as JSON-LD */
+public class ExJsonLD
+{
+    public static void main(String[] args) {
+        (new ExJsonLD()).doIt();
+    }
+
+    void doIt() {
+        doSimpleStuff();
+        moreControl();
+    }
+
+    /**
+     * Simple stuff.
+     * 
+     * output using defaults, 
+     * in "expanded"", compacted" or "flattened" format
+     * (framed is more difficult, not handled here)
+     */
+    void doSimpleStuff() {
+        Model m = aSimpleModel();
+
+        // to get a default output: just do like for any other lang
+        System.out.println("--- DEFAULT ---");
+        m.write(System.out, "JSON-LD");
+
+        // same thing, using the more modern RDFDataMgr, and specifying the RDFFormat
+        System.out.println("\n--- DEFAULT ---");
+        RDFDataMgr.write(System.out, m, RDFFormat.JSONLD);
+
+        // output can be pretty (with line breaks), or not
+        System.out.println("\n--- DEFAULT, PRETTY (same as above, BTW) ---");
+        RDFDataMgr.write(System.out, m, RDFFormat.JSONLD_PRETTY);
+
+        System.out.println("\n--- DEFAULT, FLAT ---");
+        RDFDataMgr.write(System.out, m, RDFFormat.JSONLD_FLAT);
+
+        // all these default outputs use the JsonLD "Compact" format
+        // (note the "@context" node in the output)
+
+        // if prefixes are defined in the model,
+        // they are used in computing the @context,
+        // and corresponding values are displayed as prefix:localname
+        // (note something nice with jsonld: look at the value of "seeAlso")
+        m.setNsPrefix("ex", "http://www.ex.com/");
+        m.setNsPrefix("sh", "http://schema.org/");
+        System.out.println("\n--- DEFAULT, model including prefix mappings ---");
+        RDFDataMgr.write(System.out, m, RDFFormat.JSONLD_PRETTY);
+
+        // Besides "Compact", JSON-LD defines the following kinds of outputs: expanded, flattened, and framed
+        // For each of them, there is a dedicated RDFFormat -- actually, 2 of them (one pretty, one flat)
+        // As previously seen, RDFFormat.JSONLD is just an alias of RDFFormat.JSONLD_COMPACT_PRETYY
+        // Let's try the other ones:
+
+        // Expand is the fastest one
+        // no @context in it
+        System.out.println("\n--- EXPAND ---");
+        RDFDataMgr.write(System.out, m, RDFFormat.JSONLD_EXPAND_PRETTY);
+
+        // flatten has an @context node
+        System.out.println("\n--- FLATTEN ---");
+        RDFDataMgr.write(System.out, m, RDFFormat.JSONLD_FLATTEN_PRETTY);
+
+        // framed requires some more parameters to run, we'll get back to it later
+    }
+
+
+    /**
+     * To get more control about the output,
+     * we have to use a mechanism provided by jena to pass information
+     * to the writing process
+     * 
+     * This requires a few lines of code, see {@link #write(DatasetGraph, RDFFormat, Context)}
+     * 
+     * Here we use this write method to see what can be customized.
+     */
+    public void moreControl() {
+        Model m = aSimpleModel();
+        m.setNsPrefix("ex", "http://www.ex.com/");
+        m.setNsPrefix("sh", "http://schema.org/");
+
+        // Note that the write method takes a DatasetGraph as input to represent the data that we want to output
+        // Let's create one from our model:
+        DatasetGraph g = DatasetFactory.create(m).asDatasetGraph();
+
+        // and let's use this new write method to output it in compact format,
+        // passing a null Context for the moment
+        System.out.println("\n--- COMPACT with a null Context: same result as default ---");
+        write(g, RDFFormat.JSONLD_COMPACT_PRETTY, null);
+
+        // A Context is just a way to pass implementation-specific parameters as named values
+        // to a given general interface (the WriterDatasetRIOT, in this case).
+        // In order to make it easier to define the named values relevant here,
+        // there is a subclass of Context that defines setters for the values:
+        // the JsonLDWriteContext class
+
+        // so, the way to proceed is:
+        // JsonLDWriteContext ctx = new JsonLDWriteContext();       
+        // ctx.setSomething(...)
+        // write(g, RDFFormat.JSONLD_COMPACT_PRETTY, ctx);
+
+        // let's see now what can be customized with the JsonLDWriteContext object
+
+        controllingAtContext();
+        settingAtContextToURI();
+        frame();
+        controllingJsonLDApiOptions();
+    }
+
+
+    /**
+     * Shows how to customize the "@context" in "compacted" and "flattened" format.
+     * 
+     * To set it to the URI of a vocab, {@link #settingAtContextToURI()}
+     */
+    void controllingAtContext() {
+        Model m = aSimpleModel();
+        m.setNsPrefix("ex", "http://www.ex.com/");
+        m.setNsPrefix("sh", "http://schema.org/");
+        DatasetGraph g = DatasetFactory.create(m).asDatasetGraph();
+        JsonLDWriteContext ctx = new JsonLDWriteContext();
+
+        // When none is provided, Jena computes one from the defined prefixes, and from the content
+        // of the data. This default is probably good enough in most of the cases, but you may want to customize it. 
+        // Or, if it is always the same one, you may consider that computing it again and again
+        // (each time that you output data), is a waste of time (the computing of the "@context" implies to loop through all the triples)
+        // You may therefore want to compute it once for all, and to pass it to the output process
+
+        // To pass a given "@context" to the writing process,
+        // you pass the corresponding value as a JSON string
+        // (alternatively, you can directly pass the object expected by the JSON-LD API)
+
+        // for instance, we can pass a simple context 
+        // that uses jsonld "@vocab" to define the "default vocabulary"
+        // as being schema.org.
+        String atContextAsJson = "{\"@vocab\":\"http://schema.org/\"}";
+        ctx.setJsonLDContext(atContextAsJson);
+        System.out.println("\n--- COMPACT using a Context that defines @vocab ---");
+        write(g, RDFFormat.JSONLD_COMPACT_PRETTY, ctx);
+    }
+
+    /**
+     * Shows how to set "@context" to a URI.
+     */
+    void settingAtContextToURI() {
+        // One thing you'll probably want to do is to set the "@context" to the URL of a file
+        // containing the actual JSON-LD context.
+
+        // Let's take Model that only uses schema.org terms,
+        // and let's try to set the "@Context" to the URL of schema.org 
+        // "@context" : "http://schema.org/"
+
+        Model m = aModelThatOnlyUsesSchemaDotOrg();
+        DatasetGraph g = DatasetFactory.create(m).asDatasetGraph();
+        JsonLDWriteContext ctx = new JsonLDWriteContext();
+
+        // The following should work, but it doesn't (with JSONLD-java 0.8.3):
+        ctx.setJsonLDContext("\"http://schema.org/\"");
+        System.out.println("\n--- Setting the context to a URI, WRONG WAY: it's slow, and the output is not JSON-LD. Sorry about that. ---");
+        write(g, RDFFormat.JSONLD_COMPACT_PRETTY, ctx);
+
+        // But don't worry (be happy): 
+        // - there is a solution
+        // - and what we tried is not what we would want to do, anyway.
+        // The output process needs to have the content of the "@context" at hand
+        // in order to compute the output. So, if passing the URL of the vocab,
+        // the output process must download the vocab before anything.
+        // (that's why it is slow)
+        // -> that would not be an efficient way to output your data.
+        // And it doesn't work eventually (at least with JSONLD-java 0.8.3)
+        // -> that would be a very bad way
+        // But well, no regret.
+
+        // To achieve the expected result,
+        // you have to do 2 things:
+
+        // 1)
+        // you have to pass the dereferenced content of http://schema.org/
+        // or the relevant subset of it (we only use a very limited subset).
+        // Here it is:
+        String atContextAsJson = "{\"name\":{\"@id\":\"http://schema.org/name\"},\"Person\": {\"@id\": \"http://schema.org/Person\"}}";
+        ctx.setJsonLDContext(atContextAsJson);
+        // Alternatively, we could just pass "null":
+        // ctx.setJsonLDContext(null);
+        // and let jena compute the context (as the model only uses schema.org vocab)
+
+        // 2)
+        // and then you pass the schema.org url using:
+        ctx.setJsonLDContextSubstitution("\"http://schema.org/\"");
+
+        // To summarize:
+        // - ctx.setJsonLDContext allows to define the @context used to compute the output
+        // - ctx.setJsonLDContextSubstitution allows to change the value of the "@context" in the output
+        System.out.println("\n--- COMPACT with @context replaced by schema.org URI ---");
+        write(g, RDFFormat.JSONLD_COMPACT_PRETTY, ctx);
+
+        // Final note: BEWARE when replacing the context:
+        // if you let some things undefined, the output will be json, not jsonld
+
+    }
+
+    void frame() {
+        Model m = ModelFactory.createDefaultModel();
+        String ns = "http://schema.org/";
+        Resource person = m.createResource(ns + "Person");
+        Resource s = m.createResource();
+        m.add(s, m.createProperty(ns + "name"), "Jane Doe");
+        m.add(s, m.createProperty(ns + "url"), "http://www.janedoe.com");
+        m.add(s, m.createProperty(ns + "jobTitle"), "Professor");
+        m.add(s, RDF.type, person);
+        s = m.createResource();
+        m.add(s, m.createProperty(ns + "name"), "Gado Salamatou");
+        m.add(s, m.createProperty(ns + "url"), "http://www.salamatou.com");
+        m.add(s, RDF.type, person);
+        s = m.createResource();
+        m.add(s, m.createProperty(ns + "name"), "Not a person");
+        m.add(s, RDF.type, m.createResource(ns + "Event"));
+
+        DatasetGraph g = DatasetFactory.create(m).asDatasetGraph();
+        JsonLDWriteContext ctx = new JsonLDWriteContext();
+
+        // only output the persons using a frame
+        String frame = "{\"@type\" : \"http://schema.org/Person\"}";
+        ctx.setFrame(frame);
+        System.out.println("\n--- Using frame to select resources to be output: only output persons ---");
+        write(g, RDFFormat.JSONLD_FRAME_PRETTY, ctx);
+    }
+
+    /**
+     *  the JSON-LD java API (that jena uses for JSON-LD I/O) defines a set of options
+     *  that can be customized
+     */
+    void controllingJsonLDApiOptions() {
+        Model m = aSimpleModel();
+        m.setNsPrefix("ex", "http://www.ex.com/");
+        m.setNsPrefix("sh", "http://schema.org/");
+        DatasetGraph g = DatasetFactory.create(m).asDatasetGraph();
+        JsonLDWriteContext ctx = new JsonLDWriteContext();
+        JsonLdOptions opts = new JsonLdOptions();
+        ctx.setOptions(opts);
+        opts.setCompactArrays(false); // default is true
+        System.out.println("\n--- COMPACT with CompactArrays false: there is an @graph node");
+        write(g, RDFFormat.JSONLD_COMPACT_PRETTY, ctx);
+    }
+
+    /**
+     * Write RDF data as JSON-LD.
+     * 
+     * To get more control about the output,
+     * we have to use a mechanism provided by jena to pass information
+     * to the writing process (cf. org.apache.jena.riot.WriterDatasetRIOT and the "Context" mechanism).
+     * For that, we have to create a WriterDatasetRIOT (a one-time use object)
+     * and we pass a "Context" object (not to be confused with the "@context" in JSON-LD) as argument to its write method
+     * 
+     * @param out
+     * @param f RDFFormat of the output, eg. RDFFormat.JSONLD_COMPACT_PRETTY
+     * @param g the data that we want to output as JSON-LD
+     * @param ctx the object that allows to control the writing process (a set of parameters)
+     */
+    void write(OutputStream out, DatasetGraph g, RDFFormat f, Context ctx) {
+        // create a WriterDatasetRIOT with the RDFFormat
+        WriterDatasetRIOT w = RDFDataMgr.createDatasetWriter(f) ;
+        PrefixMap pm = RiotLib.prefixMap(g);
+        String base = null;
+        w.write(out, g, pm, base, ctx) ;     
+    }
+
+    /** Write RDF data to the console */
+    private void write(DatasetGraph g, RDFFormat f, Context ctx) {
+        write(System.out, g, f, ctx);
+    }
+
+    // following 2 methods: if you want to test
+    // that everything is OK in a roundtrip: model -> jsonld -> model
+    // something like:
+    // String jsonld = write2String(g, RDFFormat.JSONLD_COMPACT_PRETTY, ctx);
+    // Model m2 = parse(jsonld);
+    // System.out.println("ISO : " + m.isIsomorphicWith(m2));
+
+    /** Write RDF data into a String */
+    private String write2String(DatasetGraph g, RDFFormat f, Context ctx) {
+        try {
+            ByteArrayOutputStream out = new ByteArrayOutputStream();
+            write(out, g, f, ctx);
+            out.flush();
+            String x = out.toString("UTF-8");
+            out.close();
+            return x;
+        } catch (IOException e) { throw new RuntimeException(e); }
+    }
+
+    /** Parse a jsonld string into a Model */
+    private Model parse(String jsonld) {
+        Model m = ModelFactory.createDefaultModel();
+        StringReader reader = new StringReader(jsonld);
+        m.read(reader, null, "JSON-LD");
+        return m;
+    }
+
+    private Model aSimpleModel() {
+        Model m = ModelFactory.createDefaultModel();
+        String ns = "http://schema.org/";
+        Resource person = m.createResource(ns + "Person");
+        Resource s;
+        s = m.createResource("http://www.ex.com/janedoe");
+        m.add(s, m.createProperty(ns + "name"), "Jane Doe");
+        m.add(s, RDF.type, person);
+        m.add(s, RDFS.seeAlso, m.createResource("http://www.ex.com/janedoe/moreinfo"));
+        //        m.add(s, m.createProperty(ns + "url"), "http://www.janedoe.com");
+        //        m.add(s, m.createProperty(ns + "jobTitle"), "Professor");
+        //        s = m.createResource();
+        //        m.add(s, m.createProperty(ns + "name"), "Salamatou Gado");
+        //        m.add(s, m.createProperty(ns + "url"), "http://www.salamatou.com");
+        return m;
+    }
+
+    private Model aModelThatOnlyUsesSchemaDotOrg() {
+        Model m = ModelFactory.createDefaultModel();
+        String ns = "http://schema.org/";
+        Resource person = m.createResource(ns + "Person");
+        Resource s;
+        s = m.createResource("http://www.ex.com/janedoe");
+        m.add(s, m.createProperty(ns + "name"), "Jane Doe");
+        m.add(s, RDF.type, person);
+        return m;
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/jena/blob/e2707e6e/jena-arq/src/main/java/org/apache/jena/riot/writer/JsonLDWriter.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/writer/JsonLDWriter.java b/jena-arq/src/main/java/org/apache/jena/riot/writer/JsonLDWriter.java
index 1c85706..581c4bb 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/writer/JsonLDWriter.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/writer/JsonLDWriter.java
@@ -110,7 +110,7 @@ public class JsonLDWriter extends WriterDatasetRIOTBase
      * Note that it is supposed to be a JSON String: to set the value of @context to a URI,
      * the String must be quoted.*/
     public static final Symbol JSONLD_CONTEXT_SUBSTITUTION = createSymbol("JSONLD_CONTEXT_SUBSTITUTION");		
-    /** value: the frame object expected by JsonLdProcessor.frame */
+    /** value: a JSON String, or the frame object expected by JsonLdProcessor.frame */
     public static final Symbol JSONLD_FRAME = createSymbol("JSONLD_FRAME");
     /** value: the option object expected by JsonLdProcessor (instance of JsonLdOptions) */
     public static final Symbol JSONLD_OPTIONS = createSymbol("JSONLD_OPTIONS");
@@ -196,6 +196,9 @@ public class JsonLDWriter extends WriterDatasetRIOTBase
                     throw new IllegalArgumentException("No frame object found in jena Context");
                 }
 
+                if (frame instanceof String) {
+                    frame = JsonUtils.fromString((String) frame);
+                }
                 obj = JsonLdProcessor.frame(obj, frame, opts);
 
             } else { // compact or flatten

http://git-wip-us.apache.org/repos/asf/jena/blob/e2707e6e/jena-arq/src/test/java/org/apache/jena/riot/writer/TestJsonLDWriter.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/riot/writer/TestJsonLDWriter.java b/jena-arq/src/test/java/org/apache/jena/riot/writer/TestJsonLDWriter.java
index 2e9d99a..f1eef17 100644
--- a/jena-arq/src/test/java/org/apache/jena/riot/writer/TestJsonLDWriter.java
+++ b/jena-arq/src/test/java/org/apache/jena/riot/writer/TestJsonLDWriter.java
@@ -185,7 +185,7 @@ public class TestJsonLDWriter extends BaseTest {
         // the model wo prefix, output as jsonld using a context that defines the prefix    
         JsonLDWriteContext jenaCtx = new JsonLDWriteContext();
         jenaCtx.setJsonLDContext(js);
-                
+
         String s3 = toString(m, RDFFormat.JSONLD_COMPACT_FLAT, jenaCtx);
 
         assertTrue(s3.length() == s1.length());
@@ -197,7 +197,7 @@ public class TestJsonLDWriter extends BaseTest {
         // to be noted: things also work if passing the "@context"
         js = "{\"@context\":" + js + "}";
         jenaCtx.setJsonLDContext(js);
-        
+
         String s4 = toString(m, RDFFormat.JSONLD_COMPACT_FLAT, jenaCtx);
 
         assertTrue(s4.length() == s1.length());
@@ -243,10 +243,7 @@ public class TestJsonLDWriter extends BaseTest {
         assertTrue(m3.isIsomorphicWith(m));
         assertTrue(m3.isIsomorphicWith(m1));
     }
-    
-// KO
-    
-    
+
     /**
      * Checks that one can pass a context defined by its URI
      * 
@@ -259,7 +256,7 @@ public class TestJsonLDWriter extends BaseTest {
         m.add(s, m.createProperty(ns + "name"), "Jane Doe");
         m.add(s, m.createProperty(ns + "url"), "http://www.janedoe.com");
         m.add(s, RDF.type, "Person");
-        
+
         // we can pass an uri in the context, as a quoted string (it is a JSON string)
         JsonLDWriteContext jenaContext = new JsonLDWriteContext();
         try {
@@ -269,7 +266,7 @@ public class TestJsonLDWriter extends BaseTest {
             Model m2 = parse(jsonld);
 
             // assertTrue(m2.isIsomorphicWith(m)); // It should be the case, but no.
-            
+
         } catch (Throwable e) {
             // maybe test run in a setting wo external connectivity - not a real problem
             String mess = e.getMessage();
@@ -305,7 +302,7 @@ public class TestJsonLDWriter extends BaseTest {
         m.add(s, RDF.type, person);
 
         // change @context to a URI
-        
+
         JsonLDWriteContext jenaCtx = new JsonLDWriteContext();
         jenaCtx.setJsonLDContextSubstitution((new JsonString(ns)).toString());
         String jsonld;
@@ -313,14 +310,14 @@ public class TestJsonLDWriter extends BaseTest {
         String c = "\"@context\":\"http://schema.org/\"";
         assertTrue(jsonld.indexOf(c) > -1);
 
-         // change @context to a given ctx
+        // change @context to a given ctx
 
         String ctx = "{\"jobTitle\":{\"@id\":\"http://ex.com/jobTitle\"},\"url\":{\"@id\":\"http://ex.com/url\"},\"name\":{\"@id\":\"http://ex.com/name\"}}";
         jenaCtx.setJsonLDContextSubstitution(ctx);
         jsonld = toString(m, RDFFormat.JSONLD_COMPACT_FLAT, jenaCtx);
         assertTrue(jsonld.indexOf("http://ex.com/name") > -1);
     }
-    
+
     /**
      * Checking frames
      */
@@ -347,7 +344,7 @@ public class TestJsonLDWriter extends BaseTest {
         // only output the persons using a frame
 
         frame.put("@type", ns +"Person");
-        jenaCtx.set(JsonLDWriter.JSONLD_FRAME, JsonUtils.fromString(frame.toString()));
+        jenaCtx.set(JsonLDWriter.JSONLD_FRAME, frame.toString());
         String jsonld = toString(m, RDFFormat.JSONLD_FRAME_PRETTY, jenaCtx);
 
         Model m2 = parse(jsonld);
@@ -402,16 +399,16 @@ public class TestJsonLDWriter extends BaseTest {
         Resource s = m.createResource();
         String ns1 = "http://schema.org/";
         String ns2 = "http://ex.com/";
- 
+
         m.add(s, m.createProperty(ns1 + "name"), "schema.org name");
         m.add(s, m.createProperty(ns2 + "name"), "ex.com name");
-       
+
         String jsonld = toString(m, RDFFormat.JSONLD, null);
-        
+
         // in one case, we have "name" : "xxx", and the other "http://.../name" : "yyy"
         assertTrue(jsonld.indexOf("\"name\" : \"") > -1);
         assertTrue(jsonld.indexOf("/name\" : \"") > -1);
- 
+
         m.setNsPrefix("ns1", ns1);
         m.setNsPrefix("ns2", "http://ex.com/");
         jsonld = toString(m, RDFFormat.JSONLD, null);
@@ -419,12 +416,12 @@ public class TestJsonLDWriter extends BaseTest {
         /*
         "name" : "ex.com name",
         "ns1:name" : "schema.org name",
-        */
+         */
         // or
         /*
         "name" : "schema.org name",
         "ns2:name" : "ex.com name",
-        */
+         */
         assertTrue(jsonld.indexOf("\"name\" : \"") > -1);
         assertTrue((jsonld.indexOf("\"ns1:name\" : \"") > -1) || (jsonld.indexOf("\"ns2:name\" : \"") > -1));
     }
@@ -439,21 +436,21 @@ public class TestJsonLDWriter extends BaseTest {
         m.add(s, m.createProperty(ns + "jobTitle"), "Professor");
 
         // our default uses true for compactArrays
-        
+
         String jsonld = toString(m, RDFFormat.JSONLD, null);
-        
+
         // compactArrays is true -> no "@graph"
         assertTrue(jsonld.indexOf("@graph") < 0);
         // compactArrays is true -> string, not an array for props with one value
         assertTrue(jsonld.indexOf("\"jobTitle\" : \"Professor\"") > -1);
-        
+
         // now output using a value for JsonLdOptions in Context that sets compactArrays to false
-        
+
         JsonLDWriteContext jenaCtx = new JsonLDWriteContext();
-        
+
         JsonLdOptions opts = new JsonLdOptions(null);
         opts.setCompactArrays(false);       
- 
+
         jenaCtx.setOptions(opts);
 
         jsonld = toString(m, RDFFormat.JSONLD, jenaCtx);
@@ -463,7 +460,7 @@ public class TestJsonLDWriter extends BaseTest {
         // compactArrays is false -> an array for all props, even when there's only one value
         assertTrue(jsonld.indexOf("\"jobTitle\" : [ \"Professor\" ]") > -1);
     }
-    
+
     //
     // some utilities
     //