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);
}
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();
}
}
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);
}
}
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();
}
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]);
}
}
Aggregations