private static void read(String base, String name, InputStream is, RepositoryConnection cnx, Resource context) throws RepositoryException { try { cnx.add(is, base, formatFromName(name), context); } catch (IOException x) { LOG.error("Reading. IO problem {}", x.getMessage()); } catch (RDFParseException x) { LOG.error("Reading. RDF parsing problem {}", x.getMessage()); } }
private Model execGraphQuery(java.net.URI target, String query) { try { log.debug("Executing SPARQL tuple query: {}", query.replaceAll("\\s*[\\r\\n]+\\s*", " ").trim()); RDFFormat format = RDFFormat.TURTLE; CloseableHttpResponse response = client.post(target, query, format.getDefaultMIMEType(),SPARQL_QUERY_MIME_TYPE); final int status = response.getStatusLine().getStatusCode(); log.debug("Request resolved with {} status code: {}", status, response.getStatusLine().getReasonPhrase()); try { if (status >= 200 && status < 300) { String entity = EntityUtils.toString(response.getEntity()); return Rio.parse(new StringReader(entity), target.toString(), RDFFormat.TURTLE, new ParserConfig(), ValueFactoryImpl.getInstance(), new ParseErrorLogger()); } else { // TODO: improve this feedback from the sdk (400, 500, etc) throw new RuntimeException("Query failed: HTTP error code " + status + ": " + response.getStatusLine().getReasonPhrase()); } } catch (RDFParseException e) { log.error("Error parsing query results: {}", e.getMessage(), e); throw new RuntimeException(e); } finally { response.close(); } } catch (IllegalArgumentException | IOException e) { throw new RuntimeException(e); } }
public void testNQuadsFile() throws Exception { RDFParser nquadsParser = createRDFParser(); nquadsParser.setRDFHandler(new AbstractRDFHandler() {}); InputStream in = AbstractNQuadsParserUnitTest.class.getResourceAsStream(NQUADS_TEST_FILE); try { nquadsParser.parse(in, NQUADS_TEST_URL); } catch (RDFParseException e) { fail("NQuadsParser failed to parse N-Quads test document: " + e.getMessage()); } finally { in.close(); } }
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(); } }
/** * The N-Quads parser must be able to parse the N-Triples test file without * error. */ public void testNTriplesFile() throws Exception { RDFParser nquadsParser = createRDFParser(); nquadsParser.setRDFHandler(new AbstractRDFHandler() {}); InputStream in = AbstractNQuadsParserUnitTest.class.getResourceAsStream(NTRIPLES_TEST_FILE); try { nquadsParser.parse(in, NTRIPLES_TEST_URL); } catch (RDFParseException e) { fail("NQuadsParser failed to parse N-Triples test document: " + e.getMessage()); } 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(); } }
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(); } }
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 parse(URL url) { // Parse the data from inputStream, // resolving any relative URIs against the URL of the source // Set statement and error handler _parser.setParseErrorListener(new RetrieverErrorListener()); _parser.setRDFHandler(this); try { List<String> mimetypes = _parser.getRDFFormat().getMIMETypes(); InputStream input = Util.getDocumentAsInputStream(url.toString(), mimetypes); _parser.parse(input, url.toString()); } catch (RDFParseException e) { _logger.error(e.getMessage(), e); } catch (RDFHandlerException e) { _logger.error(e.getMessage(), e); } catch (HttpException e) { _logger.error(e.getMessage(), e); } catch (IOException e) { _logger.error(e.getMessage(), e); } }
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(); } }
public void load(G g, InputStream inputStream) throws SLIB_Ex_Critic { RDFHandler rdfHandler = new SlibRdfHandler(g); try { logger.info("Parser loaded for: " + parser.getRDFFormat()); parser.setRDFHandler(rdfHandler); logger.info("Parsing RDF file..."); parser.parse(inputStream, ""); } catch (IOException e) { throw new SLIB_Ex_Critic(e.getMessage()); } catch (RDFParseException e) { throw new SLIB_Ex_Critic(e.getMessage()); } catch (RDFHandlerException e) { throw new SLIB_Ex_Critic(e.getMessage()); } }
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(); } }
public void load(G g, InputStream inputStream) throws SLIB_Ex_Critic { RDFHandler rdfHandler = new SlibRdfHandler(g); try { logger.info("Parser loaded for: " + parser.getRDFFormat()); parser.setRDFHandler(rdfHandler); logger.info("Parsing RDF file..."); parser.parse(inputStream, ""); } catch (IOException e) { throw new SLIB_Ex_Critic(e.getMessage()); } catch (RDFParseException e) { throw new SLIB_Ex_Critic(e.getMessage()); } catch (RDFHandlerException e) { throw new SLIB_Ex_Critic(e.getMessage()); } }
p.parse(in, baseIri); } catch (RDFParseException e) { System.err.println("RUN ERROR: parse error: " + e.getMessage());
logger.warn("Unable to upload file {}", e.getMessage()); errors.rejectValue("contents", "repository.modify.add.error", new String[] { e.getMessage() }, "Malformed document");
@Test public void testNTriplesFile() throws Exception { RDFParser ntriplesParser = createRDFParser(); ntriplesParser.setDatatypeHandling(RDFParser.DatatypeHandling.IGNORE); Model model = new LinkedHashModel(); ntriplesParser.setRDFHandler(new StatementCollector(model)); InputStream in = this.getClass().getResourceAsStream(NTRIPLES_TEST_FILE); try { ntriplesParser.parse(in, NTRIPLES_TEST_URL); } catch (RDFParseException e) { fail("Failed to parse N-Triples test document: " + e.getMessage()); } finally { in.close(); } assertEquals(30, model.size()); assertEquals(28, model.subjects().size()); assertEquals(1, model.predicates().size()); assertEquals(23, model.objects().size()); }
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(); } }
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 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(); } }
ErrorInfo errInfo = new ErrorInfo(ErrorType.MALFORMED_DATA, e.getMessage()); throw new ClientHTTPException(SC_BAD_REQUEST, errInfo.toString());