Search in sources :

Example 16 with RDFReader

use of org.apache.jena.rdf.model.RDFReader in project jena by apache.

the class TestTurtleReader method test0.

public void test0() {
    RDFReader r = ModelFactory.createDefaultModel().getReader("Turtle");
    assertNotNull(r);
}
Also used : RDFReader(org.apache.jena.rdf.model.RDFReader)

Example 17 with RDFReader

use of org.apache.jena.rdf.model.RDFReader in project jena by apache.

the class TestXMLFeatures method checkPropURI.

public void checkPropURI(String s, String p, Object val, int behaviour) throws IOException {
    // create triple and graph.
    // BaseXMLWriter.dbg = true;
    // SystemOutAndErr.block();
    // TestLogger tl = new TestLogger(BaseXMLWriter.class);
    blockLogger();
    Node blank = NodeFactory.createBlankNode();
    Node prop = NodeFactory.createURI(s);
    Graph g = Factory.createGraphMem();
    g.add(Triple.create(blank, prop, blank));
    // create Model
    Model m = ModelFactory.createModelForGraph(g);
    // serialize
    RDFWriter rw = m.getWriter(lang);
    if (p != null)
        rw.setProperty(p, val);
    try (StringWriter w = new StringWriter()) {
        rw.write(m, w, "http://example.org/");
        String f = w.toString();
        switch(behaviour) {
            case BadPropURI:
                fail("Bad property URI <" + s + "> was not detected.");
                return;
            case BadURI:
                fail("Bad URI <" + s + "> was not detected.");
                return;
        }
        // read back in
        Model m2 = createMemModel();
        RDFReader rdr = m2.getReader("RDF/XML");
        rdr.setProperty("error-mode", "lax");
        try (StringReader sr = new StringReader(f)) {
            rdr.read(m2, sr, "http://example.org/");
        }
        // check
        switch(behaviour) {
            case ExtraTriples:
                assertTrue("Expecting Brickley behaviour.", m2.size() == 3);
                break;
            case NoError:
                assertTrue("Comparing Model written out and read in.", m.isIsomorphicWith(m2));
                break;
        }
    } catch (BadURIException e) {
        if (behaviour == BadURI)
            return;
        throw e;
    } catch (InvalidPropertyURIException je) {
        if (behaviour == BadPropURI)
            return;
        throw je;
    } catch (JenaException e) {
        throw e;
    } finally {
        // BaseXMLWriter.dbg = false;
        // tl.end();
        unblockLogger();
    // SystemOutAndErr.unblock();
    }
}
Also used : BadURIException(org.apache.jena.shared.BadURIException) JenaException(org.apache.jena.shared.JenaException) Model(org.apache.jena.rdf.model.Model) RDFWriter(org.apache.jena.rdf.model.RDFWriter) InvalidPropertyURIException(org.apache.jena.shared.InvalidPropertyURIException) RDFReader(org.apache.jena.rdf.model.RDFReader)

Example 18 with RDFReader

use of org.apache.jena.rdf.model.RDFReader in project jena by apache.

the class RDFReaderFImpl method setBaseReaderClassName.

/**
     * Use RIOT to add custom RDF parsers. See
     * {@code RDFParserRegistry.registerLang}
     * 
     * @deprecated Register with RIOT.
     */
@Deprecated
public static String setBaseReaderClassName(String lang, String className) {
    if (rewiredAlternative != null)
        Log.error(RDFReaderFImpl.class, "Rewired RDFReaderFImpl - configuration changes have no effect on reading");
    String oldClassName = currentEntry(lang);
    try {
        @SuppressWarnings("unchecked") Class<? extends RDFReader> newClass = (Class<? extends RDFReader>) Class.forName(className, false, Thread.currentThread().getContextClassLoader());
        custom.put(lang, newClass);
        return oldClassName;
    } catch (ClassNotFoundException e) {
        throw new ConfigException("Reader not found on classpath", e);
    } catch (Exception e) {
        throw new JenaException(e);
    }
}
Also used : JenaException(org.apache.jena.shared.JenaException) ConfigException(org.apache.jena.shared.ConfigException) RDFReader(org.apache.jena.rdf.model.RDFReader) NoReaderForLangException(org.apache.jena.shared.NoReaderForLangException) JenaException(org.apache.jena.shared.JenaException) ConfigException(org.apache.jena.shared.ConfigException)

Example 19 with RDFReader

use of org.apache.jena.rdf.model.RDFReader in project jena by apache.

the class MoreTests method testIcu2.

public void testIcu2() throws IOException {
    //		  "இந்தியா"
    //		    Normalizer.  isNormalized(
    //		            "்தியா"
    //		            ,Normalizer.NFC,0);
    Model m = createMemModel();
    RDFReader rdr = m.getReader();
    try (FileInputStream r = new FileInputStream("testing/arp/i18n/icubugtwo.rdf")) {
        rdr.setErrorHandler(this);
        expected = new int[] { WARN_STRING_NOT_NORMAL_FORM_C };
        rdr.read(m, r, "http://example.org/");
    }
    checkExpected();
}
Also used : Model(org.apache.jena.rdf.model.Model) RDFReader(org.apache.jena.rdf.model.RDFReader)

Example 20 with RDFReader

use of org.apache.jena.rdf.model.RDFReader in project jena by apache.

the class SAX2RDFMoreTests method testLang.

public void testLang() throws Exception {
    Model m = ModelFactory.createDefaultModel();
    Model m2 = ModelFactory.createDefaultModel();
    RDFEHArray eh = new RDFEHArray();
    try (InputStream in = new FileInputStream("testing/wg/rdfms-xmllang/test004.rdf")) {
        RDFReader w = m.getReader();
        w.setErrorHandler(eh);
        w.read(m, in, "http://example.org/");
    }
    RDFEHArray eh2 = new RDFEHArray();
    try (InputStream in = new FileInputStream("testing/wg/rdfms-xmllang/test003.rdf")) {
        XMLReader saxParser = new SAXParser();
        SAX2Model handler = SAX2Model.create("http://example.org/", m2, "fr");
        SAX2RDF.installHandlers(saxParser, handler);
        handler.setErrorHandler(eh2);
        InputSource ins = new InputSource(in);
        ins.setSystemId("http://example.org/");
        try {
            try {
                saxParser.parse(ins);
            } finally {
                handler.close();
            }
        } catch (SAXParseException e) {
        // already reported, leave it be.
        }
    }
    /*
		 * System.out.println("Normal:"); m.write(System.out,"N-TRIPLE");
		 * 
		 * System.out.println("New:"); m2.write(System.out,"N-TRIPLE");
		 */
    if (eh.v.size() == 0)
        assertTrue("Not isomorphic", m.isIsomorphicWith(m2));
    /*
		 * if ( eh.v.size()!=eh2.v.size()) { for (int i=0; i <a.length;i++)
		 * System.err.println(eh.v.get(i)); }
		 */
    assertEquals("Different number of errors", eh.v.size(), eh2.v.size());
    Object[] a = eh.v.toArray();
    Object[] a2 = eh2.v.toArray();
    Arrays.sort(a);
    Arrays.sort(a2);
    for (int i = 0; i < eh.v.size(); i++) {
        assertEquals("Error " + i + " different.", a[i], a2[i]);
    }
}
Also used : InputSource(org.xml.sax.InputSource) SAX2Model(org.apache.jena.rdfxml.xmlinput.SAX2Model) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileInputStream(java.io.FileInputStream) RDFReader(org.apache.jena.rdf.model.RDFReader) SAXParseException(org.xml.sax.SAXParseException) SAX2Model(org.apache.jena.rdfxml.xmlinput.SAX2Model) Model(org.apache.jena.rdf.model.Model) RDFEHArray(org.apache.jena.rdfxml.xmlinput.SAX2RDFTest.RDFEHArray) SAXParser(org.apache.xerces.parsers.SAXParser) XMLReader(org.xml.sax.XMLReader)

Aggregations

RDFReader (org.apache.jena.rdf.model.RDFReader)34 Model (org.apache.jena.rdf.model.Model)30 JenaException (org.apache.jena.shared.JenaException)8 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 SAX2Model (org.apache.jena.rdfxml.xmlinput.SAX2Model)2 StringReader (java.io.StringReader)1 IRIFactory (org.apache.jena.iri.IRIFactory)1 TurtleParseException (org.apache.jena.n3.turtle.TurtleParseException)1 TurtleReader (org.apache.jena.n3.turtle.TurtleReader)1 RDFWriter (org.apache.jena.rdf.model.RDFWriter)1 RecordingModelListener (org.apache.jena.rdf.model.test.helpers.RecordingModelListener)1 RDFEHArray (org.apache.jena.rdfxml.xmlinput.SAX2RDFTest.RDFEHArray)1 BadURIException (org.apache.jena.shared.BadURIException)1 ConfigException (org.apache.jena.shared.ConfigException)1 InvalidPropertyURIException (org.apache.jena.shared.InvalidPropertyURIException)1 NoReaderForLangException (org.apache.jena.shared.NoReaderForLangException)1 SAXParser (org.apache.xerces.parsers.SAXParser)1 InputSource (org.xml.sax.InputSource)1 SAXParseException (org.xml.sax.SAXParseException)1