use of org.apache.jena.rdf.model.RDFReaderI 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")) {
RDFReaderI 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 = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
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]);
}
}
use of org.apache.jena.rdf.model.RDFReaderI in project jena by apache.
the class SAX2RDFTest method runTest.
@Override
public void runTest() throws Exception {
// System.err.println(base+" + "+this.file);
Model m = ModelFactory.createDefaultModel();
Model m2 = ModelFactory.createDefaultModel();
RDFEHArray eh = new RDFEHArray();
try (InputStream in = new FileInputStream(file)) {
RDFReaderI w = m.getReader();
w.setErrorHandler(eh);
w.read(m, in, base);
}
RDFEHArray eh2 = new RDFEHArray();
try (InputStream in = new FileInputStream(file)) {
/*
* w = m.getReader(); w.setErrorHandler(eh2); w.read(m2,in,base);
* in.close();
*/
loadXMLModel(m2, in, eh2);
}
/*
* 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 < eh.v.size(); i++) System.err.println(eh.v.get(i));
System.err.println("---");
for (int i = 0; i < eh2.v.size(); i++) System.err.println(eh2.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]);
}
}
use of org.apache.jena.rdf.model.RDFReaderI in project jena by apache.
the class MoreTests method testIRIRules_4.
public void testIRIRules_4() {
Model model = ModelFactory.createDefaultModel();
RDFReaderI r = model.getReader("RDF/XML");
r.setProperty("iri-rules", "strict");
r.setProperty("WARN_MALFORMED_URI", ARPErrorNumbers.EM_ERROR);
r.setErrorHandler(this);
// Errors actually continue.
expected = new int[] { WARN_MALFORMED_URI, WARN_MALFORMED_URI };
r.read(model, new StringReader(RDF_TEXT), "http://example/");
checkExpected();
}
use of org.apache.jena.rdf.model.RDFReaderI in project jena by apache.
the class MoreTests method testBadBaseParamOK.
public void testBadBaseParamOK() throws IOException {
Model m = createMemModel();
Model m1 = createMemModel();
RDFReaderI rdr = m.getReader();
try (FileInputStream fin = new FileInputStream("testing/wg/rdfms-identity-anon-resources/test001.rdf")) {
rdr.setErrorHandler(this);
expected = new int[] { WARN_MALFORMED_URI };
rdr.read(m, fin, "http://jjc^3.org/demo.mp3");
}
try (FileInputStream fin = new FileInputStream("testing/wg/rdfms-identity-anon-resources/test001.rdf")) {
rdr.read(m1, fin, "");
}
assertTrue("Bad base URI should have no effect on model.[" + m1.toString() + "]", m.isIsomorphicWith(m1));
checkExpected();
}
use of org.apache.jena.rdf.model.RDFReaderI in project jena by apache.
the class MoreTests method testNullBaseParamOK.
// JENA-1537
// Character encoding checks removed due to lack of support in JDK XML parser APIs.
// public void testEncodingMismatch2() throws IOException {
// FileReader r = new FileReader(
// "testing/wg/rdf-charmod-literals/test001.rdf");
//
// subTestEncodingMismatch2(r);
// }
//
// public void testEncodingMismatch3() throws IOException {
// try ( FileInputStream fin = new FileInputStream("testing/wg/rdf-charmod-literals/test001.rdf") ;
// InputStreamReader r = new InputStreamReader(fin,"MS950")) {
// subTestEncodingMismatch2(r);
// }catch (java.io.UnsupportedEncodingException e) {
// System.err
// .println("WARNING: Encoding mismatch3 test not executed on platform without MS950 encoding.");
// return;
// }
// }
//
// private void subTestEncodingMismatch2(InputStreamReader r) {
// if (r.getEncoding().startsWith("UTF")) {
// // see above for warning message.
// return;
// }
// Model m = createMemModel();
// RDFReader rdr = m.getReader();
//
// rdr.setErrorHandler(this);
// expected = new int[] { WARN_ENCODING_MISMATCH, ERR_ENCODING_MISMATCH };
// rdr.read(m, r, "http://example.org/");
//
// checkExpected();
// }
public void testNullBaseParamOK() throws IOException {
Model m = createMemModel();
Model m1 = createMemModel();
RDFReaderI rdr = m.getReader();
try (FileInputStream fin = new FileInputStream("testing/wg/rdfms-identity-anon-resources/test001.rdf")) {
rdr.setErrorHandler(this);
expected = new int[] {};
rdr.read(m, fin, "http://example.org/");
}
try (FileInputStream fin = new FileInputStream("testing/wg/rdfms-identity-anon-resources/test001.rdf")) {
rdr.read(m1, fin, null);
}
assertTrue("Base URI should have no effect.", m.isIsomorphicWith(m1));
checkExpected();
}
Aggregations