use of org.eclipse.rdf4j.rio.ParserConfig in project rdf4j by eclipse.
the class CustomTurtleParserTest method testParsingNamespacesWithOverride.
@Test
public void testParsingNamespacesWithOverride() throws Exception {
ParserConfig aConfig = new ParserConfig();
aConfig.set(BasicParserSettings.NAMESPACES, Collections.<Namespace>singleton(new NamespaceImpl("foo", SKOS.NAMESPACE)));
Model model = Rio.parse(new StringReader("@prefix skos : <urn:not_skos:> ." + "<urn:a> skos:broader <urn:b>."), "", RDFFormat.TURTLE, aConfig, vf, new ParseErrorLogger());
assertEquals(1, model.size());
assertTrue(model.contains(vf.createIRI("urn:a"), vf.createIRI("urn:not_skos:broader"), vf.createIRI("urn:b")));
}
use of org.eclipse.rdf4j.rio.ParserConfig in project rdf4j by eclipse.
the class SPARQLXMLParserCustomTest method testEntityExpansionUnrelatedSettings.
/**
* Test with unrelated ParserConfig settings
*
* @throws Exception
*/
@Test
public void testEntityExpansionUnrelatedSettings() throws Exception {
ParserConfig config = new ParserConfig();
QueryResultCollector handler = new QueryResultCollector();
ParseErrorCollector errorCollector = new ParseErrorCollector();
QueryResultParser aParser = QueryResultIO.createTupleParser(TupleQueryResultFormat.SPARQL).setQueryResultHandler(handler).setParserConfig(config).setParseErrorListener(errorCollector);
try {
// this should trigger a SAX parse exception that will blow up at
// the 64k entity limit rather than OOMing
aParser.parseQueryResult(this.getClass().getResourceAsStream("/sparqlxml/bad-entity-expansion-limit.srx"));
fail("Parser did not throw an exception");
} catch (QueryResultParseException e) {
// assertTrue(e.getMessage().contains(
// "The parser has encountered more than \"64,000\" entity
// expansions in this document; this is the limit imposed by the
// "));
}
assertEquals(0, errorCollector.getWarnings().size());
assertEquals(0, errorCollector.getErrors().size());
assertEquals(1, errorCollector.getFatalErrors().size());
}
use of org.eclipse.rdf4j.rio.ParserConfig in project rdf4j by eclipse.
the class RDFXMLParserCustomTest method testEntityExpansionUnrelatedSettings.
/**
* Test with unrelated ParserConfig settings
*
* @throws Exception
*/
@Test
public void testEntityExpansionUnrelatedSettings() throws Exception {
final Model aGraph = new LinkedHashModel();
ParseErrorCollector errorCollector = new ParseErrorCollector();
ParserConfig config = new ParserConfig();
RDFParser aParser = Rio.createParser(RDFFormat.RDFXML).setRDFHandler(new StatementCollector(aGraph)).setParserConfig(config).setParseErrorListener(errorCollector);
try {
// this should trigger a SAX parse exception that will blow up at the
// 64k entity limit rather than OOMing
aParser.parse(this.getClass().getResourceAsStream("/testcases/rdfxml/openrdf/bad-entity-expansion-limit.rdf"), "http://example.org");
fail("Parser did not throw an exception");
} catch (RDFParseException e) {
// assertTrue(e.getMessage().contains(
// "The parser has encountered more than \"64,000\" entity expansions in this document; this is the limit imposed by the "));
}
assertEquals(0, errorCollector.getWarnings().size());
assertEquals(0, errorCollector.getErrors().size());
assertEquals(1, errorCollector.getFatalErrors().size());
}
use of org.eclipse.rdf4j.rio.ParserConfig in project rdf4j by eclipse.
the class RDFParserHelperTest method setUp.
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
parserConfig = new ParserConfig();
// By default we wipe out the SPI loaded datatype and language handlers
parserConfig.set(BasicParserSettings.DATATYPE_HANDLERS, Collections.<DatatypeHandler>emptyList());
parserConfig.set(BasicParserSettings.LANGUAGE_HANDLERS, Collections.<LanguageHandler>emptyList());
// Ensure that the set of non-fatal errors is empty by default
parserConfig.setNonFatalErrors(new HashSet<RioSetting<?>>());
errListener = new ParseErrorCollector();
valueFactory = SimpleValueFactory.getInstance();
}
use of org.eclipse.rdf4j.rio.ParserConfig in project rdf4j by eclipse.
the class JSONLDWriterTest method testRoundTripNamespaces.
@Test
public void testRoundTripNamespaces() throws Exception {
String exNs = "http://example.org/";
IRI uri1 = vf.createIRI(exNs, "uri1");
IRI uri2 = vf.createIRI(exNs, "uri2");
Literal plainLit = vf.createLiteral("plain", XMLSchema.STRING);
Statement st1 = vf.createStatement(uri1, uri2, plainLit);
ByteArrayOutputStream out = new ByteArrayOutputStream();
RDFWriter rdfWriter = rdfWriterFactory.getWriter(out);
rdfWriter.getWriterConfig().set(JSONLDSettings.JSONLD_MODE, JSONLDMode.COMPACT);
rdfWriter.handleNamespace("ex", exNs);
rdfWriter.startRDF();
rdfWriter.handleStatement(st1);
rdfWriter.endRDF();
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
RDFParser rdfParser = rdfParserFactory.getParser();
ParserConfig config = new ParserConfig();
config.set(BasicParserSettings.FAIL_ON_UNKNOWN_DATATYPES, true);
config.set(BasicParserSettings.FAIL_ON_UNKNOWN_LANGUAGES, true);
rdfParser.setParserConfig(config);
rdfParser.setValueFactory(vf);
Model model = new LinkedHashModel();
rdfParser.setRDFHandler(new StatementCollector(model));
rdfParser.parse(in, "foo:bar");
assertEquals("Unexpected number of statements, found " + model.size(), 1, model.size());
assertTrue("missing namespaced statement", model.contains(st1));
if (rdfParser.getRDFFormat().supportsNamespaces()) {
assertTrue("Expected at least one namespace, found " + model.getNamespaces().size(), model.getNamespaces().size() >= 1);
assertEquals(exNs, model.getNamespace("ex").get().getName());
}
}
Aggregations