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/02/09 11:06:29 UTC
svn commit: r1242258 - in /incubator/jena/Scratch/AFS/Dev/trunk:
src-dev/dev/RunAFS.java src/main/java/riot/reader/Langs.java
Author: andy
Date: Thu Feb 9 10:06:29 2012
New Revision: 1242258
URL: http://svn.apache.org/viewvc?rev=1242258&view=rev
Log: (empty)
Modified:
incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/RunAFS.java
incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/riot/reader/Langs.java
Modified: incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/RunAFS.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/RunAFS.java?rev=1242258&r1=1242257&r2=1242258&view=diff
==============================================================================
--- incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/RunAFS.java (original)
+++ incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/RunAFS.java Thu Feb 9 10:06:29 2012
@@ -37,6 +37,12 @@ public class RunAFS
System.exit(code) ;
}
+
+ static public void main(String ... args){
+ exit(0) ;
+
+ }
+
static IRIFactory iriFactory = new IRIFactory();
static {
// IRIFactory.iriImplementation() ...
Modified: incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/riot/reader/Langs.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/riot/reader/Langs.java?rev=1242258&r1=1242257&r2=1242258&view=diff
==============================================================================
--- incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/riot/reader/Langs.java (original)
+++ incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/riot/reader/Langs.java Thu Feb 9 10:06:29 2012
@@ -18,32 +18,159 @@
package riot.reader;
+import java.io.InputStream ;
import java.util.HashMap ;
import java.util.Map ;
-import com.hp.hpl.jena.util.FileUtils ;
+import com.hp.hpl.jena.graph.Triple ;
+import com.hp.hpl.jena.sparql.core.Quad ;
+import com.hp.hpl.jena.sparql.engine.binding.Binding ;
+import com.hp.hpl.jena.sparql.util.Symbol ;
import org.openjena.atlas.lib.MultiMap ;
+import org.openjena.atlas.lib.NotImplemented ;
+import org.openjena.atlas.lib.Sink ;
import org.openjena.riot.ContentType ;
import org.openjena.riot.Lang ;
+import org.openjena.riot.RiotException ;
+import org.openjena.riot.RiotReader ;
import org.openjena.riot.WebContent ;
+import org.openjena.riot.lang.LangRIOT ;
public class Langs
{
- // Constants and wiring.
+ // Constants and wiring. Work-in-progress.
+
+ // A parser encapsulates a process
+ // A parser can be called more than once (internally it must cope with this)
+ // A parser has exclusive access the input stream (no concurrency at this level).
+
+ // A parser factory generates parsers.
+ //
+
+ // --------
+ // Formally one-shot or many?
+ // Accumulator model.??
+ static interface Parser { void parse(InputStream in, String baseURI) ; }
+
+ // The destination has to go in the constructor as it's <T>
+ // Uck. abstract class?
+ static interface ParserFactory<T> { Parser create(Lang2 language, Sink<T> sink) ; }
+ // --------
+
// Languages as constants. Lang is an "open enum" (you can add your own),
- // registered with their MIME type or offical name,
+ // registered with their MIME type or official name,
static Lang2 langRDFXML = Lang2.create(WebContent.contentTypeRDFXML) ;
static Lang2 langTurtle = Lang2.create(WebContent.contentTypeRDFXML) ;
static Lang2 langNTriples = Lang2.create(WebContent.contentTypeNTriplesAlt) ; // Exception: not text/plain.
static Lang2 langN3 = Lang2.create(WebContent.contentTypeN3) ;
static Lang2 langRDFJSON = Lang2.create(WebContent.contentTypeRDFJSON) ;
+ // JSON-LD
static Lang2 langNQuads = Lang2.create(WebContent.contentTypeNQuads) ;
static Lang2 langTriG = Lang2.create(WebContent.contentTypeTriG) ;
+ // This code understands different types fo things it can read:
+ // triples, quads, result sets, unknown
+ // These form (disjoint) value spaces static ParserFactory<Triple> pfTriples = new ParserFactory<Triple>() {
+ // This is needed because we need to determine the output type of the reading process.
+ // The decision is driven by the Content-Type.
+ // Up until the response header, the code does not need to know but given the content type,
+ // it needs to determine the class of parser that's going to be needed.
+ // (We won't need to do this if we could pass in the type information at runtime.)
+
+// private static String BASE = "http://jena.apastatic ParserFactory<Triple> pfTriples = new ParserFactory<Triple>() {che.org/parserType/" ;
+// // Open enum. Allows extensibility but what the use case?
+// private Symbol TRIPLES = Symbol.create(BASE+"triples") ;
+// private Symbol QUADS = Symbol.create(BASE+"quads") ;
+// private Symbol RESULTSET = Symbol.create(BASE+"table") ;
+// private Symbol OTHER = Symbol.create(BASE+"unknown") ;
+
+ enum DestClass { TRIPLES, QUADS, RESULTSET } ;
+
+ // Triples
+ // Generic parser factory.
+ static ParserFactory<Triple> pfTriples = new ParserFactory<Triple>() {
+ @Override
+ public Parser create(final Lang2 language, final Sink<Triple> sink)
+ {
+ return new Parser() {
+ // Needs sorting out
+ @Override
+ public void parse(InputStream in, String baseURI)
+ {
+ Lang lang = convert(language) ;
+ LangRIOT parser = RiotReader.createParserTriples(in, lang, baseURI, sink) ;
+ parser.parse() ;
+ }} ;
+ }} ;
+
+ static Map<Lang2, ParserFactory<Triple>> langToTriples = new HashMap<Lang2, ParserFactory<Triple>>() ;
+ static {
+ langToTriples.put(langRDFXML, pfTriples) ;
+ langToTriples.put(langTurtle, pfTriples) ;
+ langToTriples.put(langNTriples, pfTriples) ;
+ langToTriples.put(langN3, pfTriples) ;
+ langToTriples.put(langRDFJSON, pfTriples) ;
+ langToTriples.put(langTurtle, pfTriples) ;
+ // JSON-LD
+ }
+
+ // Triples
+ // Generic parser factory.
+ static ParserFactory<Quad> pfQuads = new ParserFactory<Quad>() {
+ @Override
+ public Parser create(final Lang2 language, final Sink<Quad> sink)
+ {
+ return new Parser() {
+ // Needs sorting out
+ @Override
+ public void parse(InputStream in, String baseURI)
+ {
+ Lang lang = convert(language) ;
+ LangRIOT parser = RiotReader.createParserQuads(in, lang, baseURI, sink) ;
+ parser.parse() ;
+ }} ;
+ }} ;
+ static Map<Lang2, ParserFactory<Quad>> langToQuads = new HashMap<Lang2, ParserFactory<Quad>>() ;
+ static {
+ langToQuads.put(langNQuads, pfQuads) ;
+ langToQuads.put(langTriG, pfQuads) ;
+ }
+
+ static ParserFactory<Binding> pfBindings = new ParserFactory<Binding>() {
+ @Override
+ public Parser create(Lang2 language, Sink<Binding> sink)
+ {
+ throw new NotImplemented() ;
+ }} ;
+ static Map<Lang2, ParserFactory<Binding>> langToBindings = new HashMap<Lang2, ParserFactory<Binding>>() ;
+ static {
+ //langToBindings.put(????, pfBindings) ;
+ }
+
+ // ---- THE WORKERS
+ public static void readTriples(InputStream in, String contentType, Sink<Triple> dest)
+ {
+ Lang2 lang = contentTypeToLang(contentType) ;
+// if ( ! lang.isTriples() )
+// throw new RiotException() ;
+ ParserFactory<Triple> pf = langToTriples.get(lang) ;
+ if ( pf == null )
+ {}
+
+ Parser parser = pf.create(lang, dest) ;
+ parser.parse(in, contentType) ;
+ }
+
+ private static Lang2 contentTypeToLang(String contentType)
+ {
+ return null ;
+ }
+ // ---- THE WORKERS
+
public static ContentType guessContentType(String filenameOrIRI)
{
Lang lang = Lang.guess(filenameOrIRI) ;