use of org.eclipse.rdf4j.rio.ParserConfig in project rdf4j by eclipse.
the class JSONLDWriterBackgroundTest 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());
}
}
use of org.eclipse.rdf4j.rio.ParserConfig in project rdf4j by eclipse.
the class TriGParserCustomTest method setUp.
/**
* @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);
}
use of org.eclipse.rdf4j.rio.ParserConfig in project rdf4j by eclipse.
the class CustomTurtleParserTest method test780IRISpace.
@Test
public void test780IRISpace() throws Exception {
String ttl = "_:b25978837 a <http://purl.bioontology.org/ontology/UATC/\\u0020SERINE\\u0020\\u0020> .";
try {
Rio.parse(new StringReader(ttl), "", RDFFormat.TURTLE);
fail();
} catch (RDFParseException e) {
// Invalid IRI
}
Model model = Rio.parse(new StringReader(ttl), "", RDFFormat.TURTLE, new ParserConfig().set(BasicParserSettings.VERIFY_URI_SYNTAX, false), SimpleValueFactory.getInstance(), new ParseErrorLogger());
assertEquals(1, model.size());
model.filter(null, RDF.TYPE, null).objects().forEach(obj -> assertEquals("http://purl.bioontology.org/ontology/UATC/%20SERINE%20%20", obj.stringValue()));
}
use of org.eclipse.rdf4j.rio.ParserConfig in project rdf4j by eclipse.
the class CustomTurtleParserTest method setUp.
/**
* @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);
}
use of org.eclipse.rdf4j.rio.ParserConfig in project rdf4j by eclipse.
the class CustomTurtleParserTest method testParsingNamespacesWithOption.
@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")));
}
Aggregations