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 2012/12/26 18:15:59 UTC
svn commit: r1425968 - in
/jena/trunk/jena-arq/src-examples/arq/examples/riot: ExRIOT_1.java
ExRIOT_2.java ExRIOT_3.java
Author: andy
Date: Wed Dec 26 17:15:59 2012
New Revision: 1425968
URL: http://svn.apache.org/viewvc?rev=1425968&view=rev
Log:
Update RIOT examples.
Modified:
jena/trunk/jena-arq/src-examples/arq/examples/riot/ExRIOT_1.java
jena/trunk/jena-arq/src-examples/arq/examples/riot/ExRIOT_2.java
jena/trunk/jena-arq/src-examples/arq/examples/riot/ExRIOT_3.java
Modified: jena/trunk/jena-arq/src-examples/arq/examples/riot/ExRIOT_1.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src-examples/arq/examples/riot/ExRIOT_1.java?rev=1425968&r1=1425967&r2=1425968&view=diff
==============================================================================
--- jena/trunk/jena-arq/src-examples/arq/examples/riot/ExRIOT_1.java (original)
+++ jena/trunk/jena-arq/src-examples/arq/examples/riot/ExRIOT_1.java Wed Dec 26 17:15:59 2012
@@ -18,12 +18,16 @@
package arq.examples.riot;
-import org.apache.jena.riot.IO_Jena ;
+import org.apache.jena.riot.RDFDataMgr ;
+import org.apache.jena.riot.RDFLanguages ;
+import org.apache.jena.riot.RIOT ;
import com.hp.hpl.jena.rdf.model.Model ;
-import com.hp.hpl.jena.util.FileManager ;
+import com.hp.hpl.jena.rdf.model.ModelFactory ;
/** Example of using RIOT with Jena readers.
+ * Normally, the application just needs to call model.read and
+ * not interact with RIOT directly.
*/
public class ExRIOT_1
{
@@ -32,21 +36,25 @@ public class ExRIOT_1
// Ensure RIOT loaded.
// This is only needed to be sure - touching any ARQ code will load RIOT.
// This operation can be called several times.
- IO_Jena.wireIntoJena() ;
-
- Model m = null ;
+ RIOT.init() ;
+
+ Model m = ModelFactory.createDefaultModel() ;
+ // read into the model.
+ m.read("data.ttl") ;
+
+ // Alternatively, use the RDFDataMgr, which reads from the web,
+ // with content negotiation. Plain names are assumed to be
+ // local files where file extension indicates the syntax.
- // Load data, creating the model
- m = FileManager.get().loadModel("D.ttl") ;
+ Model m2 = RDFDataMgr.loadModel("data.ttl") ;
- // Or read into an existing model.
- FileManager.get().readModel(m, "D2.ttl") ;
+ // read in more data, the remote server serves up the data
+ // with the right MIME type.
+ RDFDataMgr.read(m2, "http://host/some-published-data") ;
- // Or use Model.read
- m.read("D3.nt", "TTL") ;
- // Go back to using the old Jena readers.
- IO_Jena.resetJenaReaders() ;
- m = FileManager.get().loadModel("D.nt") ;
+ // Read some data but also give a hint for the synatx if it is not
+ // discovered by inspectying the file or by HTTP content negotiation.
+ RDFDataMgr.read(m2, "some-more-data.out", RDFLanguages.Turtle) ;
}
}
Modified: jena/trunk/jena-arq/src-examples/arq/examples/riot/ExRIOT_2.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src-examples/arq/examples/riot/ExRIOT_2.java?rev=1425968&r1=1425967&r2=1425968&view=diff
==============================================================================
--- jena/trunk/jena-arq/src-examples/arq/examples/riot/ExRIOT_2.java (original)
+++ jena/trunk/jena-arq/src-examples/arq/examples/riot/ExRIOT_2.java Wed Dec 26 17:15:59 2012
@@ -34,6 +34,13 @@ import org.apache.jena.riot.system.Parse
import org.apache.jena.riot.system.RiotLib ;
/** Example of using RIOT directly.
+ *
+ * RDFDataMgr is the general place to read data - see {@link ExRIOT_1}
+ *
+ * RiotReader is the place for making parsers and can be used to read
+ * from files or InputStreams. It can give more detailed control of error handling
+ * and specialised destination of parser output.
+ * It does not perform HTTP content negotiation.
*/
public class ExRIOT_2
{
@@ -42,9 +49,9 @@ public class ExRIOT_2
// Ensure RIOT loaded.
RIOT.init() ;
+ // ---- Parse to a Sink.
RDFParserOutput noWhere = RDFParserOutputLib.sinkNull() ;
- // ---- Parse to a Sink.
// RIOT controls the conversion from bytes to java chars.
InputStream in = new FileInputStream("data.trig") ;
@@ -53,6 +60,8 @@ public class ExRIOT_2
// --- Or create a parser and do the parsing as separate steps.
String baseURI = "http://example/base" ;
+ // It is always better to use an InputStream, rather than a Java Reader.
+ // The parsers will do the necessary character set conversion.
in = new FileInputStream("data.trig") ;
LangRIOT parser = RiotReader.createParserQuads(in, RDFLanguages.TriG, "http://example/base", noWhere) ;
@@ -65,7 +74,7 @@ public class ExRIOT_2
// Just set the error handler.
parser.getProfile().setHandler(errHandler) ;
- // Or replave the whole parser profile.
+ // Or replace the whole parser profile.
parser.setProfile(profile) ;
// Do the work.
Modified: jena/trunk/jena-arq/src-examples/arq/examples/riot/ExRIOT_3.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src-examples/arq/examples/riot/ExRIOT_3.java?rev=1425968&r1=1425967&r2=1425968&view=diff
==============================================================================
--- jena/trunk/jena-arq/src-examples/arq/examples/riot/ExRIOT_3.java (original)
+++ jena/trunk/jena-arq/src-examples/arq/examples/riot/ExRIOT_3.java Wed Dec 26 17:15:59 2012
@@ -18,13 +18,14 @@
package arq.examples.riot;
+import static org.apache.jena.riot.RDFLanguages.TriG ;
import org.apache.jena.riot.RDFDataMgr ;
import org.apache.jena.riot.RIOT ;
import com.hp.hpl.jena.query.Dataset ;
import com.hp.hpl.jena.query.DatasetFactory ;
-/** Example of using RIOT : reading dada into datasets. */
+/** Example of using RIOT : reading data into datasets. */
public class ExRIOT_3
{
public static void main(String...argv)
@@ -43,8 +44,8 @@ public class ExRIOT_3
// Create a dataset,
Dataset ds2 = DatasetFactory.createMem() ;
- // read in data.
- RDFDataMgr.read(ds2, "data2.trig") ;
-
+ // read in data, indicating the syntax in case the remote end does not
+ // correctly provide the HTTP content type.
+ RDFDataMgr.read(ds2, "http://host/data2.unknown", TriG) ;
}
}