Java Code Examples for org.eclipse.rdf4j.rio.ParserConfig#set()
The following examples show how to use
org.eclipse.rdf4j.rio.ParserConfig#set() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RDFParserHelperTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * @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<>()); errListener = new ParseErrorCollector(); valueFactory = SimpleValueFactory.getInstance(); }
Example 2
Source File: CustomTurtleParserTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * @throws java.lang.Exception */ @Before public void setUp() throws Exception { vf = ValueFactoryImpl.getInstance(); settingsNoVerifyLangTag = new ParserConfig(); settingsNoVerifyLangTag.set(BasicParserSettings.VERIFY_LANGUAGE_TAGS, false); errors = new ParseErrorCollector(); parser = Rio.createParser(RDFFormat.TURTLE); statementCollector = new StatementCollector(new LinkedHashModel()); parser.setRDFHandler(statementCollector); }
Example 3
Source File: CustomTurtleParserTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testParsingNamespacesWithOption() throws Exception { ParserConfig aConfig = new ParserConfig(); aConfig.set(BasicParserSettings.NAMESPACES, Collections.<Namespace>singleton(new NamespaceImpl("foo", SKOS.NAMESPACE))); Model model = Rio.parse(new StringReader("<urn:a> foo:broader <urn:b>."), "", RDFFormat.TURTLE, aConfig, vf, new ParseErrorLogger()); assertEquals(1, model.size()); assertTrue(model.contains(vf.createURI("urn:a"), SKOS.BROADER, vf.createURI("urn:b"))); }
Example 4
Source File: CustomTurtleParserTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@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"))); }
Example 5
Source File: TriGParserCustomTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * @throws java.lang.Exception */ @Before public void setUp() throws Exception { vf = SimpleValueFactory.getInstance(); settingsNoVerifyLangTag = new ParserConfig(); settingsNoVerifyLangTag.set(BasicParserSettings.VERIFY_LANGUAGE_TAGS, false); errors = new ParseErrorCollector(); parser = Rio.createParser(RDFFormat.TRIG); statementCollector = new StatementCollector(new LinkedHashModel()); parser.setRDFHandler(statementCollector); }
Example 6
Source File: JSONLDWriterBackgroundTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@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.startRDF(); rdfWriter.handleNamespace("ex", exNs); 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()); } }
Example 7
Source File: JSONLDWriterTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testRoundTripNamespaces() throws Exception { 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.startRDF(); rdfWriter.handleNamespace("ex", exNs); 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()); } }
Example 8
Source File: JSONLDWriterBackgroundTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override protected void setupParserConfig(ParserConfig config) { super.setupParserConfig(config); config.set(BasicParserSettings.FAIL_ON_UNKNOWN_DATATYPES, true); config.set(BasicParserSettings.FAIL_ON_UNKNOWN_LANGUAGES, true); }
Example 9
Source File: JSONLDWriterTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override protected void setupParserConfig(ParserConfig config) { super.setupParserConfig(config); config.set(BasicParserSettings.FAIL_ON_UNKNOWN_DATATYPES, true); config.set(BasicParserSettings.FAIL_ON_UNKNOWN_LANGUAGES, true); }
Example 10
Source File: RyaSailRepositoryConnection.java From rya with Apache License 2.0 | 4 votes |
@Override public ParserConfig getParserConfig() { final ParserConfig parserConfig = super.getParserConfig(); parserConfig.set(BasicParserSettings.VERIFY_URI_SYNTAX, false); return parserConfig; }