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 2023/03/25 11:49:20 UTC

[jena] branch main updated: GH-1773: GH-1577: Update RDF/XML examples

This is an automated email from the ASF dual-hosted git repository.

andy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/jena.git


The following commit(s) were added to refs/heads/main by this push:
     new f700ddac0b GH-1773: GH-1577: Update RDF/XML examples
     new c7341b14ea Merge pull request #1813 from afs/rdfxml-examples
f700ddac0b is described below

commit f700ddac0bda1773d6f2d85b43732b4413c14159
Author: Andy Seaborne <an...@apache.org>
AuthorDate: Sat Mar 25 10:50:46 2023 +0000

    GH-1773: GH-1577: Update RDF/XML examples
---
 .../riot/ExRIOT_RDFXML_ReaderProperties.java       | 14 +++----
 ...operties.java => ExRIOT_RDFXML_WritePlain.java} | 43 ++++------------------
 ...es.java => ExRIOT_RDFXML_WriterProperties.java} | 28 ++++----------
 3 files changed, 23 insertions(+), 62 deletions(-)

diff --git a/jena-examples/src/main/java/arq/examples/riot/ExRIOT_RDFXML_ReaderProperties.java b/jena-examples/src/main/java/arq/examples/riot/ExRIOT_RDFXML_ReaderProperties.java
index 3fd3af61cc..2650d50576 100644
--- a/jena-examples/src/main/java/arq/examples/riot/ExRIOT_RDFXML_ReaderProperties.java
+++ b/jena-examples/src/main/java/arq/examples/riot/ExRIOT_RDFXML_ReaderProperties.java
@@ -30,7 +30,6 @@ import org.apache.jena.riot.Lang;
 import org.apache.jena.riot.RDFDataMgr;
 import org.apache.jena.riot.RDFParser;
 import org.apache.jena.riot.SysRIOT;
-import org.apache.jena.sparql.util.Context;
 
 /** Set properties of the RDF/XML parser (ARP) */
 public class ExRIOT_RDFXML_ReaderProperties {
@@ -49,22 +48,23 @@ public class ExRIOT_RDFXML_ReaderProperties {
         System.out.println(data);
         System.out.println();
         // Properties to be set.
+        // See
+        //   https://jena.apache.org/documentation/io/rdfxml-io.html
+        //   https://jena.apache.org/documentation/io/rdfxml-input.html
         // This is a map propertyName->value
         Map<String, Object> properties = new HashMap<>();
-        // See class ARPErrorNumbers for the possible ARP properies.
+        // See class ARPErrorNumbers for the possible ARP properties.
         properties.put("WARN_BAD_NAME", "EM_IGNORE");
 
-        // Put a properties object into the Context.
-        Context cxt = new Context();
-        cxt.set(SysRIOT.sysRdfReaderProperties, properties);
-
         Model model = ModelFactory.createDefaultModel();
         // Build and run a parser
         RDFParser.create()
             .lang(Lang.RDFXML)
             .source(new StringReader(data))
-            .context(cxt)
+            .set(SysRIOT.sysRdfReaderProperties, properties)
+            .base("http://example/base/")
             .parse(model);
+        System.out.println();
         System.out.println("== Parsed data output in Turtle");
         RDFDataMgr.write(System.out,  model, Lang.TURTLE);
     }
diff --git a/jena-examples/src/main/java/arq/examples/riot/ExRIOT_RDFXML_WriteProperties.java b/jena-examples/src/main/java/arq/examples/riot/ExRIOT_RDFXML_WritePlain.java
similarity index 55%
copy from jena-examples/src/main/java/arq/examples/riot/ExRIOT_RDFXML_WriteProperties.java
copy to jena-examples/src/main/java/arq/examples/riot/ExRIOT_RDFXML_WritePlain.java
index 5c1944513a..888b0c955a 100644
--- a/jena-examples/src/main/java/arq/examples/riot/ExRIOT_RDFXML_WriteProperties.java
+++ b/jena-examples/src/main/java/arq/examples/riot/ExRIOT_RDFXML_WritePlain.java
@@ -19,64 +19,37 @@
 package arq.examples.riot;
 
 import java.io.StringReader;
-import java.util.HashMap ;
-import java.util.Map ;
 
 import org.apache.jena.atlas.lib.StrUtils;
 import org.apache.jena.atlas.logging.LogCtl;
 import org.apache.jena.rdf.model.Model;
 import org.apache.jena.rdf.model.ModelFactory;
-import org.apache.jena.riot.*;
-import org.apache.jena.sparql.util.Context;
+import org.apache.jena.riot.Lang;
+import org.apache.jena.riot.RDFDataMgr;
+import org.apache.jena.riot.RDFFormat;
 
 /** Example of setting properties for RDF/XML writer via RIOT */
-public class ExRIOT_RDFXML_WriteProperties {
+public class ExRIOT_RDFXML_WritePlain {
     static { LogCtl.setLogging(); }
 
     public static void main(String... args) {
         // Data.
         String x = StrUtils.strjoinNL
             ("PREFIX : <http://example.org/>"
+            ,":s a :T ."
             ,":s :p :o ."
             );
         Model model = ModelFactory.createDefaultModel();
         RDFDataMgr.read(model, new StringReader(x), null, Lang.TURTLE);
 
-        // Write, default settings.
-        writePlain(model);
-        System.out.println();
+        System.out.println("**** RDFXML_ABBREV");
+        RDFDataMgr.write(System.out, model, RDFFormat.RDFXML_ABBREV);
 
-        // Write, with properties
-        writeProperties(model);
-    }
+        System.out.println();
 
-    /** Write in plain, not pretty ("abbrev") format. */
-    private static void writePlain(Model model) {
         System.out.println("**** RDFXML_PLAIN");
         RDFDataMgr.write(System.out, model, RDFFormat.RDFXML_PLAIN);
-        System.out.println();
-    }
-
-    /** Write with properties */
-    public static void writeProperties(Model model) {
-        System.out.println("**** RDFXML_PLAIN+properties");
-        System.out.println("**** Adds XML declaration");
-
-        // Properties to be set.
-        // See https://jena.apache.org/documentation/io/rdfxml_howto.html#advanced-rdfxml-output
-        // for details of properties.
-        Map<String, Object> properties = new HashMap<>() ;
-        properties.put("showXmlDeclaration", "true");
 
-        // Put a properties object into the Context.
-        Context cxt = new Context();
-        cxt.set(SysRIOT.sysRdfWriterProperties, properties);
 
-        RDFWriter.create()
-            .base("http://example.org/")
-            .format(RDFFormat.RDFXML_ABBREV)
-            .context(cxt)
-            .source(model)
-            .output(System.out);
     }
 }
diff --git a/jena-examples/src/main/java/arq/examples/riot/ExRIOT_RDFXML_WriteProperties.java b/jena-examples/src/main/java/arq/examples/riot/ExRIOT_RDFXML_WriterProperties.java
similarity index 74%
rename from jena-examples/src/main/java/arq/examples/riot/ExRIOT_RDFXML_WriteProperties.java
rename to jena-examples/src/main/java/arq/examples/riot/ExRIOT_RDFXML_WriterProperties.java
index 5c1944513a..4690428c92 100644
--- a/jena-examples/src/main/java/arq/examples/riot/ExRIOT_RDFXML_WriteProperties.java
+++ b/jena-examples/src/main/java/arq/examples/riot/ExRIOT_RDFXML_WriterProperties.java
@@ -27,10 +27,9 @@ import org.apache.jena.atlas.logging.LogCtl;
 import org.apache.jena.rdf.model.Model;
 import org.apache.jena.rdf.model.ModelFactory;
 import org.apache.jena.riot.*;
-import org.apache.jena.sparql.util.Context;
 
 /** Example of setting properties for RDF/XML writer via RIOT */
-public class ExRIOT_RDFXML_WriteProperties {
+public class ExRIOT_RDFXML_WriterProperties {
     static { LogCtl.setLogging(); }
 
     public static void main(String... args) {
@@ -38,44 +37,33 @@ public class ExRIOT_RDFXML_WriteProperties {
         String x = StrUtils.strjoinNL
             ("PREFIX : <http://example.org/>"
             ,":s :p :o ."
+            ,":s a :T ."
             );
         Model model = ModelFactory.createDefaultModel();
         RDFDataMgr.read(model, new StringReader(x), null, Lang.TURTLE);
 
-        // Write, default settings.
-        writePlain(model);
-        System.out.println();
-
         // Write, with properties
         writeProperties(model);
     }
 
-    /** Write in plain, not pretty ("abbrev") format. */
-    private static void writePlain(Model model) {
-        System.out.println("**** RDFXML_PLAIN");
-        RDFDataMgr.write(System.out, model, RDFFormat.RDFXML_PLAIN);
-        System.out.println();
-    }
-
     /** Write with properties */
     public static void writeProperties(Model model) {
         System.out.println("**** RDFXML_PLAIN+properties");
         System.out.println("**** Adds XML declaration");
+        System.out.println();
 
         // Properties to be set.
-        // See https://jena.apache.org/documentation/io/rdfxml_howto.html#advanced-rdfxml-output
+        // See
+        //   https://jena.apache.org/documentation/io/rdfxml-io.html
+        //   https://jena.apache.org/documentation/io/rdfxml-output.html
         // for details of properties.
         Map<String, Object> properties = new HashMap<>() ;
         properties.put("showXmlDeclaration", "true");
 
-        // Put a properties object into the Context.
-        Context cxt = new Context();
-        cxt.set(SysRIOT.sysRdfWriterProperties, properties);
-
         RDFWriter.create()
             .base("http://example.org/")
-            .format(RDFFormat.RDFXML_ABBREV)
-            .context(cxt)
+            .format(RDFFormat.RDFXML_PLAIN)
+            .set(SysRIOT.sysRdfWriterProperties, properties)
             .source(model)
             .output(System.out);
     }