public VerbatimRdfizer(final RDFFormat format, final RDFParser.DatatypeHandling datatypeHandling) { this.format = format; parser = Rio.createParser(format); parser.setDatatypeHandling(datatypeHandling); }
public RDFParser getParser() { RDFParser p = pf.getParser(); p.setDatatypeHandling(RDFParser.DatatypeHandling.IGNORE); return p; } };
public VerbatimRdfizer(final RDFFormat format, final RDFParser.DatatypeHandling datatypeHandling) { this.format = format; parser = Rio.createParser(format); parser.setDatatypeHandling(datatypeHandling); }
public RDFBlueprintsHandler(final Configuration configuration) throws IOException { this.enablePath = configuration.getBoolean(FaunusCompiler.PATH_ENABLED, false); this.useFragments = configuration.getBoolean(RDFInputFormat.FAUNUS_GRAPH_INPUT_RDF_USE_LOCALNAME, false); this.literalAsProperty = configuration.getBoolean(RDFInputFormat.FAUNUS_GRAPH_INPUT_RDF_LITERAL_AS_PROPERTY, false); for (final String property : configuration.getStringCollection(RDFInputFormat.FAUNUS_GRAPH_INPUT_RDF_AS_PROPERTIES)) { this.asProperties.add(property.trim()); } String formatName = configuration.get(RDFInputFormat.FAUNUS_GRAPH_INPUT_RDF_FORMAT); if (null == formatName) { throw new RuntimeException("RDF format is required. Use " + RDFInputFormat.FAUNUS_GRAPH_INPUT_RDF_FORMAT); } RDFFormat format = formats.get(formatName); if (null == format) { throw new RuntimeException("unknown RDF format: " + formatName); } this.parser = Rio.createParser(format); this.parser.setRDFHandler(this); this.parser.setDatatypeHandling(RDFParser.DatatypeHandling.IGNORE); }
/** * Apply the options to the parser. * * @param p * The parser. */ synchronized public void apply(final RDFParser p) { p.setDatatypeHandling(datatypeHandling); p.setPreserveBNodeIDs(preserveBNodeIDs); p.setStopAtFirstError(stopAtFirstError); p.setVerifyData(verifyData); }
/** * Apply the options to the parser. * * @param p * The parser. */ synchronized public void apply(final RDFParser p) { p.setDatatypeHandling(datatypeHandling); p.setPreserveBNodeIDs(preserveBNodeIDs); p.setStopAtFirstError(stopAtFirstError); p.setVerifyData(verifyData); }
public void testNTriplesFileWithReification() throws Exception { RDFParser turtleParser = createRDFParser(); turtleParser.setDatatypeHandling(RDFParser.DatatypeHandling.IGNORE); turtleParser.setRDFHandler(new RDFHandlerBase() { public void handleStatement(final Statement st) throws RDFHandlerException { if (log.isInfoEnabled()) log.info("Statement: " + st); } }); final String fileUrl = BigdataNTriplesParser.class.getResource( NTRIPLES_TEST_FILE_WITH_REIFICATION).toExternalForm(); // Note: This is a local copy. InputStream in = BigdataNTriplesParser.class .getResourceAsStream(NTRIPLES_TEST_FILE_WITH_REIFICATION); try { turtleParser.parse(in, fileUrl); } catch (RDFParseException e) { fail("Failed to parse N-Triples test document: " + e.getMessage(), e); } finally { in.close(); } }
public void testNTriplesFileWithSIDS() throws Exception { RDFParser turtleParser = createRDFParser(); turtleParser.setDatatypeHandling(RDFParser.DatatypeHandling.IGNORE); turtleParser.setRDFHandler(new RDFHandlerBase() { public void handleStatement(final Statement st) throws RDFHandlerException { if (log.isInfoEnabled()) log.info("Statement: " + st); } }); final String fileUrl = BigdataNTriplesParser.class.getResource( NTRIPLES_TEST_FILE_WITH_SIDS).toExternalForm(); // Note: This is a local copy. InputStream in = BigdataNTriplesParser.class .getResourceAsStream(NTRIPLES_TEST_FILE_WITH_SIDS); try { turtleParser.parse(in, fileUrl); } catch (RDFParseException e) { fail("Failed to parse N-Triples test document: " + e.getMessage(), e); } finally { in.close(); } }
private Set<Statement> readExpectedGraphQueryResult() throws Exception { RDFFormat rdfFormat = Rio.getParserFormatForFileName(resultFileURL); if (rdfFormat != null) { RDFParser parser = Rio.createParser(rdfFormat); parser.setDatatypeHandling(DatatypeHandling.IGNORE); parser.setPreserveBNodeIDs(true); Set<Statement> result = new LinkedHashSet<Statement>(); parser.setRDFHandler(new StatementCollector(result)); InputStream in = new URL(resultFileURL).openStream(); try { parser.parse(in, resultFileURL); } finally { in.close(); } return result; } else { throw new RuntimeException("Unable to determine file type of results file"); } }
@Override protected void runTest() { try { // Try parsing the input; this should result in an error being // reported. RDFParser turtleParser = createRDFParser(); turtleParser.setDatatypeHandling(RDFParser.DatatypeHandling.IGNORE); turtleParser.setRDFHandler(new StatementCollector()); InputStream in = inputURL.openStream(); turtleParser.parse(in, base(inputURL.toExternalForm())); in.close(); fail("Parser parses erroneous data without reporting errors"); } catch (RDFParseException e) { // This is expected as the input file is incorrect RDF } catch (Exception e) { fail("Error: " + e.getMessage()); } }
@Override protected void runTest() { try { // Try parsing the input; this should result in an error being // reported. RDFParser rdfjsonParser = createRDFParser(); rdfjsonParser.setDatatypeHandling(RDFParser.DatatypeHandling.IGNORE); rdfjsonParser.setRDFHandler(new StatementCollector()); InputStream in = this.getClass().getResourceAsStream(inputURL); rdfjsonParser.parse(in, baseURL); in.close(); fail("Parser parses erroneous data without reporting errors"); } catch (RDFParseException e) { // This is expected as the input file is incorrect RDF } catch (Exception e) { fail("Error: " + e.getMessage()); } }
private Model loadModel(String fileName) throws Exception { URL modelURL = this.getClass().getResource(TESTCASES_DIR + fileName); assertNotNull("Test file not found: " + fileName, modelURL); Model model = createEmptyModel(); Optional<RDFFormat> rdfFormat = Rio.getParserFormatForFileName(fileName); assertTrue("Unable to determine RDF format for file: " + fileName, rdfFormat.isPresent()); RDFParser parser = Rio.createParser(rdfFormat.get()); parser.setDatatypeHandling(DatatypeHandling.IGNORE); parser.setPreserveBNodeIDs(true); parser.setRDFHandler(new StatementCollector(model)); InputStream in = modelURL.openStream(); try { parser.parse(in, modelURL.toString()); return model; } finally { in.close(); } }
public void testNTriplesFile() throws Exception { RDFParser turtleParser = createRDFParser(); turtleParser.setDatatypeHandling(RDFParser.DatatypeHandling.IGNORE); turtleParser.setRDFHandler(new RDFHandlerBase() { public void handleStatement(Statement st) throws RDFHandlerException { if (log.isInfoEnabled()) log.info("Statement: " + st); } }); // Note: This is a local copy. InputStream in = BigdataNTriplesParser.class.getResourceAsStream(NTRIPLES_TEST_FILE); try { turtleParser.parse(in, NTRIPLES_TEST_URL); } catch (RDFParseException e) { fail("Failed to parse N-Triples test document: " + e.getMessage()); } finally { in.close(); } }
protected final Set<Statement> readExpectedGraphQueryResult() throws Exception { RDFFormat rdfFormat = Rio.getParserFormatForFileName(resultFileURL).orElseThrow( Rio.unsupportedFormat(resultFileURL)); RDFParser parser = Rio.createParser(rdfFormat); parser.setDatatypeHandling(DatatypeHandling.IGNORE); parser.setPreserveBNodeIDs(true); parser.setValueFactory(dataRep.getValueFactory()); Set<Statement> result = new LinkedHashSet<Statement>(); parser.setRDFHandler(new StatementCollector(result)); InputStream in = new URL(resultFileURL).openStream(); try { parser.parse(in, resultFileURL); } finally { in.close(); } return result; }
private void addData(final RepositoryConnection conn) throws IOException, RDFParseException, RepositoryException, RDFHandlerException { final RDFParser rdfParser = Rio.createParser(RDFFormat.NTRIPLES, conn.getValueFactory()); rdfParser.setVerifyData(true); rdfParser.setStopAtFirstError(true); rdfParser.setDatatypeHandling(RDFParser.DatatypeHandling.IGNORE); rdfParser.setRDFHandler(new RDFHandlerBase() { @Override public void handleStatement(Statement st) throws RDFHandlerException { try { conn.add(st); } catch (OpenRDFException e) { throw new RDFHandlerException(e); } } }); rdfParser.parse(getClass().getResourceAsStream("TestTicket276.n3"), ""); } }
/** * Utility method applies the options to the {@link RDFParser}. * * @param opts * The options. * @param p * The parser. */ public static void apply(final IRDFParserOptions opts, final RDFParser p) { p.setDatatypeHandling(opts.getDatatypeHandling()); p.setPreserveBNodeIDs(opts.getPreserveBNodeIDs()); p.setStopAtFirstError(opts.getStopAtFirstError()); p.setVerifyData(opts.getVerifyData()); }
@Test public void testExceptionHandlingWithDefaultSettings() throws Exception { String data = "invalid nt"; RDFParser ntriplesParser = createRDFParser(); ntriplesParser.setDatatypeHandling(RDFParser.DatatypeHandling.IGNORE); Model model = new LinkedHashModel(); ntriplesParser.setRDFHandler(new StatementCollector(model)); try { ntriplesParser.parse(new StringReader(data), NTRIPLES_TEST_URL); fail("expected RDFParseException due to invalid data"); } catch (RDFParseException expected) { assertEquals(expected.getLineNumber(), 1); } }
public void testNTriplesFileWithReification() throws Exception { RDFParser turtleParser = createRDFParser(); turtleParser.setDatatypeHandling(RDFParser.DatatypeHandling.IGNORE); turtleParser.setRDFHandler(new RDFHandlerBase() { public void handleStatement(final Statement st) throws RDFHandlerException { if (log.isInfoEnabled()) log.info("Statement: " + st); } }); final String fileUrl = BigdataNTriplesParser.class.getResource( NTRIPLES_TEST_FILE_WITH_REIFICATION).toExternalForm(); // Note: This is a local copy. InputStream in = BigdataNTriplesParser.class .getResourceAsStream(NTRIPLES_TEST_FILE_WITH_REIFICATION); try { turtleParser.parse(in, fileUrl); } catch (RDFParseException e) { fail("Failed to parse N-Triples test document: " + e.getMessage(), e); } finally { in.close(); } }
/** * Utility method applies the options to the {@link RDFParser}. * * @param opts * The options. * @param p * The parser. */ public static void apply(final IRDFParserOptions opts, final RDFParser p) { p.setDatatypeHandling(opts.getDatatypeHandling()); p.setPreserveBNodeIDs(opts.getPreserveBNodeIDs()); p.setStopAtFirstError(opts.getStopAtFirstError()); p.setVerifyData(opts.getVerifyData()); }
private void addData(final RepositoryConnection conn) throws IOException, RDFParseException, RepositoryException, RDFHandlerException { final RDFParser rdfParser = Rio.createParser(RDFFormat.NTRIPLES, conn.getValueFactory()); rdfParser.setVerifyData(true); rdfParser.setStopAtFirstError(true); rdfParser.setDatatypeHandling(RDFParser.DatatypeHandling.IGNORE); rdfParser.setRDFHandler(new RDFHandlerBase() { @Override public void handleStatement(Statement st) throws RDFHandlerException { try { conn.add(st); } catch (OpenRDFException e) { throw new RDFHandlerException(e); } } }); rdfParser.parse(getClass().getResourceAsStream("TestTicket276.n3"), ""); } }