jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1362983 - in /jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_reader: Langs.java PROCESS.java RDFReaderFactoryRIOT.java TS_ReaderRIOT.java TestJenaReaderRIOT.java TestReadDataset.java WebReader2.java
Date Wed, 18 Jul 2012 15:37:41 GMT
Author: andy
Date: Wed Jul 18 15:37:40 2012
New Revision: 1362983

URL: http://svn.apache.org/viewvc?rev=1362983&view=rev
Log: (empty)

Added:
    jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_reader/TestReadDataset.java
Modified:
    jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_reader/Langs.java
    jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_reader/PROCESS.java
    jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_reader/RDFReaderFactoryRIOT.java
    jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_reader/TS_ReaderRIOT.java
    jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_reader/TestJenaReaderRIOT.java
    jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_reader/WebReader2.java

Modified: jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_reader/Langs.java
URL: http://svn.apache.org/viewvc/jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_reader/Langs.java?rev=1362983&r1=1362982&r2=1362983&view=diff
==============================================================================
--- jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_reader/Langs.java (original)
+++ jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_reader/Langs.java Wed Jul 18 15:37:40
2012
@@ -19,6 +19,7 @@
 package projects.riot_reader;
 
 import java.io.InputStream ;
+import java.util.Locale ;
 import java.util.Map ;
 
 import org.openjena.atlas.lib.DS ;
@@ -58,7 +59,7 @@ public class Langs
     private static Map<String, Lang2> mapContentTypeToLang              = DS.map()
;
     private static MultiMap<Lang2, String> langToExt                    = MultiMap.createMapList()
;
     private static Map<String, Lang2> extToLang                         = DS.map()
;
-    private static Map<String, Lang2> jenaName                          = DS.map()
;
+    private static Map<String, Lang2> shortNameToLang                   = DS.map()
;
    
     // This code understands different types of things it can read:
     //   triples, quads, result sets, unknown
@@ -125,11 +126,18 @@ public class Langs
         return langToQuads.get(language) ;
     }
 
-    private static void jenaName(String name, Lang2 lang)
+    private static void registerShortNameForLang(String name, Lang2 lang)
     {
-        jenaName.put(name, lang) ;
+        shortNameToLang.put(lowerCase(name), lang) ;
     }
 
+    public static Lang2 shortNameToLang(String name)
+    {
+        return shortNameToLang.get(lowerCase(name)) ;
+    }
+
+    private static String lowerCase(String x) { return x.toLowerCase(Locale.US) ; }
+    
     static void addTripleSyntax$(Lang2 language, String contentType, ReaderRIOTFactory<Triple>
factory, String ... fileExt)
     {
         addTripleSyntax$(language, ContentType.parse(contentType), factory, fileExt) ;
@@ -193,27 +201,27 @@ public class Langs
         addContentTypeLang$(WebContent.contentTypeNQuadsAlt, langNQuads) ;
         
         // Reader name and variations to lang (compatibility)
-        jenaName("RDF/XML",         langRDFXML) ;
-        jenaName("RDFXML",          langRDFXML) ;
-        jenaName("RDF/XML-ABBREV",  langRDFXML) ;
+        registerShortNameForLang("RDF/XML",         langRDFXML) ;
+        registerShortNameForLang("RDFXML",          langRDFXML) ;
+        registerShortNameForLang("RDF/XML-ABBREV",  langRDFXML) ;
         
-        jenaName("N-TRIPLE",        langNTriples) ;
-        jenaName("N-TRIPLES",       langNTriples) ;
-        jenaName("NTRIPLE",         langNTriples) ;
-        jenaName("NTRIPLES",        langNTriples) ;
-        jenaName("NT",              langNTriples) ;
+        registerShortNameForLang("N-TRIPLE",        langNTriples) ;
+        registerShortNameForLang("N-TRIPLES",       langNTriples) ;
+        registerShortNameForLang("NTRIPLE",         langNTriples) ;
+        registerShortNameForLang("NTRIPLES",        langNTriples) ;
+        registerShortNameForLang("NT",              langNTriples) ;
             
-        jenaName("TURTLE",          langTurtle) ;
-        jenaName("TTL",             langTurtle) ;
+        registerShortNameForLang("TURTLE",          langTurtle) ;
+        registerShortNameForLang("TTL",             langTurtle) ;
 
-        jenaName("N-QUADS",         langNQuads) ;
-        jenaName("NQUADS",          langNQuads) ;
-        jenaName("NQ",              langNQuads) ;
+        registerShortNameForLang("N-QUADS",         langNQuads) ;
+        registerShortNameForLang("NQUADS",          langNQuads) ;
+        registerShortNameForLang("NQ",              langNQuads) ;
             
-        jenaName("RDF/JSON",        langRDFJSON) ;
-        jenaName("RDFJSON",         langRDFJSON) ;
+        registerShortNameForLang("RDF/JSON",        langRDFJSON) ;
+        registerShortNameForLang("RDFJSON",         langRDFJSON) ;
         
-        jenaName("TRIG",            langTriG) ;
+        registerShortNameForLang("TRIG",            langTriG) ;
     }
     
     
@@ -268,35 +276,35 @@ public class Langs
     }
     
     /** Attempt to guess the content type string from a language name */   
-    public static String jenaNameToContentTypeStr(String jenaShortName)
+    public static String shortNameToContentTypeStr(String jenaShortName)
     {
-        return jenaNameToContentTypeStr(jenaShortName, null) ;
+        return shortNameToContentTypeStr(jenaShortName, null) ;
     }
 
     /** Attempt to guess the content type string from a language name */   
-    public static String jenaNameToContentTypeStr(String jenaShortName, String dft)
+    public static String shortNameToContentTypeStr(String jenaShortName, String dft)
     {
-        ContentType ct = jenaNameToContentType(jenaShortName) ;
+        ContentType ct = shortNameToContentType(jenaShortName) ;
         if ( ct == null )
             return dft ;
         return ct.getContentType() ;
     }
     
     /** Attempt to guess the content type string from a language name */   
-    public static ContentType jenaNameToContentType(String jenaShortName)
+    public static ContentType shortNameToContentType(String jenaShortName)
     {
-        Lang2 lang = jenaNameToLang(jenaShortName) ;
+        Lang2 lang = shortNameToLang(jenaShortName) ;
         if ( lang == null )
             return null ;
         return lang.getContentType() ;
     }
 
-    /** Attempt to guess the content type string from a language name */   
-    public static Lang2 jenaNameToLang(String jenaShortName)
-    {
-        return jenaName.get(jenaShortName) ;
-    }
-
+//    /** Attempt to guess the content type string from a language name */   
+//    public static Lang2 jenaNameToLang(String jenaShortName)
+//    {
+//        return shortNameToLang.get(jenaShortName) ;
+//    }
+//
     static Lang convert(Lang2 language)
     {
         if ( language.equals(langRDFXML))     return Lang.RDFXML ;

Modified: jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_reader/PROCESS.java
URL: http://svn.apache.org/viewvc/jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_reader/PROCESS.java?rev=1362983&r1=1362982&r2=1362983&view=diff
==============================================================================
--- jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_reader/PROCESS.java (original)
+++ jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_reader/PROCESS.java Wed Jul 18
15:37:40 2012
@@ -19,33 +19,34 @@
 package projects.riot_reader;
 
 
+
 /** Not a class. */
 
 public class PROCESS
 {
     // ****
     // Testing
-    // 1 - Does not override readerfactory (fixed in ModelCom as a static!)
-    //   => does not use hint lang because hint lang not passed down to .read.
-    // 2 - Webreader2 - does not have base override operations.
+    /* read-30
+     * "D-not-TTL.ttl"
+     * m1.read(in.getInput(), null, "RDF/XML") ;
+     * ModelCom.read: readerFactory .getReader(lang) .read(this, reader, base);
+     *   => generic reader
+     *   but hint does not go to .read(this,reader,base)
+     *   ==> generic reader .getHint?
+     */
     
-    // Quad tests
+    /* read_base_1
+     * Test is jenaread("D-no-base.ttl", "http://baseuri/", "TTL") ;
+     * ModelCom read(url, base, lang )
+     *   Immediately opnes connection in a hardwired fashion, needs protocol.
+     */
     
     // File extension and HTTP
     // 303's
     
-    // test failures:
-    //   read-30 (hardwrided ModelCom), read_base-1 (ditto)
-    
     // Lang/Lang2
     // Use of Lang as an enum in switch statements.
     
-    // webreader2.processTriples - 
-    // if hint is different from extensions file type?
-    //   Currently, extension wins.  Opps.
-    
-    // java.io.Reader as input.
-    
     // Update documentation
     //  http://jena.apache.org/documentation/io/index.html
     //  http://jena.apache.org/documentation/io/iohowto.html

Modified: jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_reader/RDFReaderFactoryRIOT.java
URL: http://svn.apache.org/viewvc/jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_reader/RDFReaderFactoryRIOT.java?rev=1362983&r1=1362982&r2=1362983&view=diff
==============================================================================
--- jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_reader/RDFReaderFactoryRIOT.java
(original)
+++ jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_reader/RDFReaderFactoryRIOT.java
Wed Jul 18 15:37:40 2012
@@ -39,7 +39,7 @@ public class RDFReaderFactoryRIOT implem
     public RDFReader getReader(String lang)
     {
         // If RDF/XML, then return an ARP 
-        if (WebContent.contentTypeRDFXML.equals(Langs.jenaNameToContentType(lang)) )
+        if (WebContent.contentTypeRDFXML.equals(Langs.shortNameToContentType(lang)) )
             return new RDFReaderRIOT_ARP() ;
         
         return new RDFReaderRIOT(lang) ; 

Modified: jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_reader/TS_ReaderRIOT.java
URL: http://svn.apache.org/viewvc/jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_reader/TS_ReaderRIOT.java?rev=1362983&r1=1362982&r2=1362983&view=diff
==============================================================================
--- jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_reader/TS_ReaderRIOT.java (original)
+++ jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_reader/TS_ReaderRIOT.java Wed Jul
18 15:37:40 2012
@@ -25,8 +25,9 @@ import org.junit.runners.Suite.SuiteClas
 @RunWith(Suite.class)
 @SuiteClasses(
 { 
-    TestFileManagerRIOT.class 
-    , TestJenaReaderRIOT.class
+    TestJenaReaderRIOT.class
+    , TestFileManagerRIOT.class 
+    , TestReadDataset.class
     
 })
 

Modified: jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_reader/TestJenaReaderRIOT.java
URL: http://svn.apache.org/viewvc/jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_reader/TestJenaReaderRIOT.java?rev=1362983&r1=1362982&r2=1362983&view=diff
==============================================================================
--- jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_reader/TestJenaReaderRIOT.java
(original)
+++ jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_reader/TestJenaReaderRIOT.java
Wed Jul 18 15:37:40 2012
@@ -114,8 +114,6 @@ public class TestJenaReaderRIOT extends 
         // 1/ Fix Jena - remove RDFReaderF
         // 2/ Change RDFReaderF to pass in the language name. 
         
-        if ( true ) return ;
-        
         // Read via Jena API.
         Model m2 = ModelFactory.createDefaultModel() ;
         FileInputStream in2 = new FileInputStream(filename) ;

Added: jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_reader/TestReadDataset.java
URL: http://svn.apache.org/viewvc/jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_reader/TestReadDataset.java?rev=1362983&view=auto
==============================================================================
--- jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_reader/TestReadDataset.java (added)
+++ jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_reader/TestReadDataset.java Wed
Jul 18 15:37:40 2012
@@ -0,0 +1,99 @@
+/**
+ * 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 projects.riot_reader;
+
+import java.io.FileInputStream ;
+import java.io.IOException ;
+
+import org.junit.AfterClass ;
+import org.junit.BeforeClass ;
+import org.junit.Test ;
+import org.openjena.atlas.junit.BaseTest ;
+
+import com.hp.hpl.jena.query.Dataset ;
+import com.hp.hpl.jena.query.DatasetFactory ;
+import com.hp.hpl.jena.sparql.util.Context ;
+
+public class TestReadDataset extends BaseTest
+{
+    private static final String directory = "testing/RIOT/Reader" ;
+
+    private static Context context = new Context() ;
+    
+    @BeforeClass static public void beforeClass()
+    { 
+        WebReader2.wireIntoJena() ;
+    }
+    
+    @AfterClass static public void afterClass()
+    { 
+        // Unwire?
+    }
+
+    @Test public void read_01() { read("D.nq") ; }
+    @Test public void read_02() { read("D.trig") ; }
+
+    @Test public void read_11() { read("D.nq", "N-Quads") ; }
+    @Test public void read_12() { read("D.nq", "NQuads") ; }
+    @Test public void read_13() { read("D.nq", "NQ") ; }
+    @Test public void read_14() { read("D.trig", "TriG") ; }
+    @Test public void read_15() { read("D.trig", "trig") ; } 
+
+    @Test public void read_21() { read("D-nq",  "NQuads") ; }
+    @Test public void read_22() { read("D-trig", "TRIG") ; }
+
+    @Test public void read_input_1() throws IOException
+    { read_stream("D.nq", "NQ") ; }
+        
+    @Test public void read_input_2() throws IOException
+    { read_stream("D.trig", "trig") ; }
+    
+    private static String filename(String filename) { return directory+"/"+filename ; }
+
+    // Base.
+    
+    private static void read(String dataurl) { read(dataurl, null) ; }
+    
+    private static void read(String dataurl, String lang)
+    {
+        dataurl = filename(dataurl) ;
+        Dataset ds = DatasetFactory.createMem() ;
+        WebReader2.read(ds, dataurl, lang) ;
+    }
+
+    
+    private static void read_stream(String filename, String lang) throws IOException
+    {
+        filename = filename(filename) ;
+        
+        // Read with a base
+        Dataset ds0 = DatasetFactory.createMem() ;
+        FileInputStream in0 = new FileInputStream(filename) ;
+        WebReader2.read(ds0, in0, "http://example/base2", lang) ;
+        in0.close() ;
+
+        // Read again, but without base
+        Dataset ds1 = DatasetFactory.createMem() ;
+        FileInputStream in1 = new FileInputStream(filename) ;
+        WebReader2.read(ds1, in1, null, lang) ;
+        in1.close() ;
+    }
+
+}
+

Modified: jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_reader/WebReader2.java
URL: http://svn.apache.org/viewvc/jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_reader/WebReader2.java?rev=1362983&r1=1362982&r2=1362983&view=diff
==============================================================================
--- jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_reader/WebReader2.java (original)
+++ jena/Scratch/AFS/Dev/trunk/src/main/java/projects/riot_reader/WebReader2.java Wed Jul
18 15:37:40 2012
@@ -158,6 +158,15 @@ public class WebReader2
      *  Throws {@link RiotNotFoundException} if the location is not found - the model is
unchanged.
      *  Throws parse errors depending on the language and reader; the Model modelaybe partially
updated. 
      */
+    public static void read(Dataset dataset, String uri, String hintLang)
+    {
+        read(dataset, uri, hintLang, null) ;
+    }
+
+    /** Read quads into a Dataset from the given location, with hint of langauge and the
with some parameters for the reader 
+     *  Throws {@link RiotNotFoundException} if the location is not found - the model is
unchanged.
+     *  Throws parse errors depending on the language and reader; the Model modelaybe partially
updated. 
+     */
     public static void read(Dataset dataset, String uri, String hintLang, Context context)
     {
         DatasetGraph dsg = dataset.asDatasetGraph() ;
@@ -165,7 +174,16 @@ public class WebReader2
         readQuads(sink, uri, hintLang, context) ;
     }
 
-    /** Read triples into a model with chars from an Reader.
+    /** Read quads into a dataset with bytes from an input stream.
+     */
+    public static void read(Dataset dataset, InputStream in, String base, String hintlang)
+    {
+        DatasetGraph dsg = dataset.asDatasetGraph() ;
+        Sink<Quad> sink = new SinkQuadsToDataset(dsg) ;
+        processQuads(sink, base, new TypedInputStream2(in), hintlang, null) ;
+    }
+    
+    /** Read quads into a dataset with chars from an Reader.
      * Use java.io.Readers is not encouraged - use with a StringReader is the primary use
case.
      * For files, open a {@link java.io.FileInputStream} to ensure correct character set
handling.
      */
@@ -176,7 +194,6 @@ public class WebReader2
         processQuads(sink, base, in, hintlang, null) ;
     }
 
-    
     public static void addTripleSyntax(Lang2 language, ContentType contentType, ReaderRIOTFactory<Triple>
factory, String ... fileExt )
     { 
         Langs.addTripleSyntax$(language, contentType, factory, fileExt) ;
@@ -278,7 +295,7 @@ public class WebReader2
     private static void processTriples(Sink<Triple> sink, String base, Reader in, String
hintLang, Context context)
     {
         Tokenizer tokenizer = TokenizerFactory.makeTokenizer(in) ;
-        Lang2 lang2 = Langs.jenaNameToLang(hintLang) ;
+        Lang2 lang2 = Langs.shortNameToLang(hintLang) ;
         Lang lang = Langs.convert(lang2) ;
         LangRIOT parser = RiotReader.createParserTriples(tokenizer, lang, base, sink) ;
         parser.parse() ;
@@ -309,7 +326,7 @@ public class WebReader2
     private static void processQuads(Sink<Quad> sink, String base, Reader in, String
hintLang, Context context)
     {
         Tokenizer tokenizer = TokenizerFactory.makeTokenizer(in) ;
-        Lang2 lang2 = Langs.jenaNameToLang(hintLang) ;
+        Lang2 lang2 = Langs.shortNameToLang(hintLang) ;
         Lang lang = Langs.convert(lang2) ;
         LangRIOT parser = RiotReader.createParserQuads(tokenizer, lang, base, sink) ;
         parser.parse() ;
@@ -328,7 +345,7 @@ public class WebReader2
             if ( hintLang == null )
                 ct = Langs.guessContentType(target) ;
             else
-                ct = Langs.jenaNameToContentType(hintLang) ;
+                ct = Langs.shortNameToContentType(hintLang) ;
         }
         return ct ;
     }



Mime
View raw message