org.openrdf.rio.RDFParseException Java Examples
The following examples show how to use
org.openrdf.rio.RDFParseException.
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: TestNoExceptions.java From database with GNU General Public License v2.0 | 6 votes |
private void executeQuery(final SailRepository repo, final String query) throws RepositoryException, MalformedQueryException, QueryEvaluationException, RDFParseException, IOException, RDFHandlerException { try { repo.initialize(); final RepositoryConnection conn = repo.getConnection(); conn.setAutoCommit(false); try { final ValueFactory vf = conn.getValueFactory(); conn.commit(); TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); TupleQueryResult tqr = tq.evaluate(); tqr.close(); } finally { conn.close(); } } finally { repo.shutDown(); } }
Example #2
Source File: BigdataNTriplesParserTestCase.java From database with GNU General Public License v2.0 | 6 votes |
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(); } }
Example #3
Source File: TestStandaloneRDRParsers.java From database with GNU General Public License v2.0 | 6 votes |
private void testStandaloneParser(RDFParser parser, String resourceName) throws IOException, RDFParseException, RDFHandlerException { bNodeFound = false; parser.setRDFHandler(new RDFHandlerBase(){ @Override public void handleStatement(Statement st) throws RDFHandlerException { if (st.getSubject() instanceof BNode) { bNodeFound = true; } super.handleStatement(st); } }); try (InputStream is = getClass().getClassLoader().getResourceAsStream(resourceName)) { parser.parse(is, ""); } assertTrue(bNodeFound); }
Example #4
Source File: BigdataComplexSparqlQueryTest.java From database with GNU General Public License v2.0 | 6 votes |
/** * Overridden to turn off auto commit and to commit after the data set is * loaded. */ @Override protected void loadTestData(String dataFile, Resource... contexts) throws RDFParseException, RepositoryException, IOException { logger.debug("loading dataset " + dataFile); InputStream dataset = ComplexSPARQLQueryTest.class.getResourceAsStream(dataFile); try { conn.setAutoCommit(false); conn.add(dataset, "", RDFFormat.forFileName(dataFile), contexts); conn.commit(); } finally { dataset.close(); } logger.debug("dataset loaded."); }
Example #5
Source File: BigdataNTriplesParserTestCase.java From database with GNU General Public License v2.0 | 6 votes |
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(); } }
Example #6
Source File: BigdataNTriplesParserTestCase.java From database with GNU General Public License v2.0 | 6 votes |
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(); } }
Example #7
Source File: BigdataSPARQLUpdateTest.java From database with GNU General Public License v2.0 | 6 votes |
/** * Note: Overridden to turn off autocommit and commit after the data are * loaded. */ @Override protected void loadDataset(String datasetFile) throws RDFParseException, RepositoryException, IOException { logger.debug("loading dataset..."); InputStream dataset = SPARQLUpdateTest.class.getResourceAsStream(datasetFile); try { // con.setAutoCommit(false); con.add(dataset, "", RDFFormat.forFileName(datasetFile));//RDFFormat.TRIG); con.commit(); } finally { dataset.close(); } logger.debug("dataset loaded."); }
Example #8
Source File: SPARQLUpdateTestv2.java From database with GNU General Public License v2.0 | 6 votes |
/** * Note: Overridden to turn off autocommit and commit after the data are * loaded. */ protected void loadDataset(String datasetFile) throws RDFParseException, RepositoryException, IOException { logger.debug("loading dataset..."); InputStream dataset = SPARQLUpdateTest.class.getResourceAsStream(datasetFile); try { // con.setAutoCommit(false); con.add(dataset, "", RDFFormat.forFileName(datasetFile));//RDFFormat.TRIG); con.commit(); } finally { dataset.close(); } logger.debug("dataset loaded."); }
Example #9
Source File: CustomSesameDataset.java From GeoTriples with Apache License 2.0 | 6 votes |
/** * Load data in specified graph (use default graph if contexts is null) * * @param filePath * @param format * @param contexts * @throws RepositoryException * @throws IOException * @throws RDFParseException */ public void loadDataFromFile(String filePath, RDFFormat format, Resource... contexts) throws RepositoryException, RDFParseException, IOException { RepositoryConnection con = null; try { con = currentRepository.getConnection(); // upload a file File f = new File(filePath); con.add(f, null, format, contexts); } finally { try { con.close(); } catch (RepositoryException e) { e.printStackTrace(); } } }
Example #10
Source File: TestTicket632.java From database with GNU General Public License v2.0 | 6 votes |
private void executeQuery(final URI serviceUri, final SailRepository repo) throws RepositoryException, MalformedQueryException, QueryEvaluationException, RDFParseException, IOException, RDFHandlerException { try { repo.initialize(); final RepositoryConnection conn = repo.getConnection(); final ValueFactory vf = conn.getValueFactory(); conn.setAutoCommit(false); try { final String query = "SELECT ?x { SERVICE <" + serviceUri.stringValue() + "> { ?x <u:1> ?bool1 } }"; final TupleQuery q = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); q.setBinding("bool1", vf.createLiteral(true)); final TupleQueryResult tqr = q.evaluate(); try { tqr.hasNext(); } finally { tqr.close(); } } finally { conn.close(); } } finally { repo.shutDown(); } }
Example #11
Source File: RepositoryConnectionTest.java From database with GNU General Public License v2.0 | 6 votes |
@Test public void testAddMalformedLiteralsStrictConfig() throws Exception { Set<RioSetting<?>> empty = Collections.emptySet(); testCon.getParserConfig().setNonFatalErrors(empty); try { testCon.add( RepositoryConnectionTest.class.getResourceAsStream(TEST_DIR_PREFIX + "malformed-literals.ttl"), "", RDFFormat.TURTLE); fail("upload of malformed literals should fail with error in strict configuration"); } catch (RDFParseException e) { // ingnore, as expected. } }
Example #12
Source File: BigdataTurtleParser.java From database with GNU General Public License v2.0 | 6 votes |
protected Value parseURIOrSid() throws IOException, RDFParseException { // First character should be '<' int c = read(); verifyCharacterOrFail(c, "<"); int n = peek(); if (n == '<') { read(); if (this.valueFactory == null) { reportFatalError("must use a BigdataValueFactory to use the RDR syntax"); } return parseSid(); } else { unread(c); return parseURI(); } }
Example #13
Source File: TestRemoteGOM.java From database with GNU General Public License v2.0 | 6 votes |
/** * Utility to load statements from a resource */ private void load(final URL n3, final RDFFormat rdfFormat) throws IOException, RDFParseException, RepositoryException { final InputStream in = n3.openConnection().getInputStream(); try { final Reader reader = new InputStreamReader(in); // FIXME: Loads into server directly, should change later to load // view ObjectManager final BigdataSailRepositoryConnection m_cxn = repo.getConnection(); try { m_cxn.setAutoCommit(false); m_cxn.add(reader, "kb", rdfFormat); m_cxn.commit(); } finally { m_cxn.close(); } } finally { in.close(); } }
Example #14
Source File: RemoteGOMTestCase.java From database with GNU General Public License v2.0 | 6 votes |
/** * Utility to load statements from a resource */ @Override public void load(final URL n3, final RDFFormat rdfFormat) throws IOException, RDFParseException, RepositoryException { final InputStream in = n3.openConnection().getInputStream(); try { final Reader reader = new InputStreamReader(in); // FIXME: Loads into server directly, should change later to load // view ObjectManager final BigdataSailRepositoryConnection m_cxn = repo.getConnection(); try { m_cxn.setAutoCommit(false); m_cxn.add(reader, "kb", rdfFormat); m_cxn.commit(); } finally { m_cxn.close(); } } finally { in.close(); } }
Example #15
Source File: LocalGOMTestCase.java From database with GNU General Public License v2.0 | 6 votes |
/** * Utility to load n3 statements from a resource */ public void load(final URL n3, final RDFFormat rdfFormat) throws IOException, RDFParseException, RepositoryException { final InputStream in = n3.openConnection().getInputStream(); try { final Reader reader = new InputStreamReader(in); try { final BigdataSailRepositoryConnection cxn = m_repo .getConnection(); try { cxn.setAutoCommit(false); cxn.add(reader, "", rdfFormat); cxn.commit(); } finally { cxn.close(); } } finally { reader.close(); } } finally { in.close(); } }
Example #16
Source File: BigdataNTriplesParser.java From database with GNU General Public License v2.0 | 6 votes |
private int parsePredicate(int c) throws IOException, RDFParseException { // predicate must be an uriref (<foo://bar>) if (c == '<') { // predicate is an uriref final StringBuilder sb = getBuffer(); c = parseUriRef(c, sb); peek().predicate = createURI(sb.toString()); } else if (c == -1) { throwEOFException(); } else { reportFatalError("Expected '<', found: " + (char)c); } return c; }
Example #17
Source File: BigdataNTriplesParser.java From database with GNU General Public License v2.0 | 6 votes |
private int parseUriRef(int c, StringBuilder uriRef) throws IOException, RDFParseException { assert c == '<' : "Supplied char should be a '<', is: " + c; // Read up to the next '>' character c = reader.read(); while (c != '>') { if (c == -1) { throwEOFException(); } uriRef.append((char)c); c = reader.read(); } // c == '>', read next char c = reader.read(); return c; }
Example #18
Source File: BigdataNTriplesParser.java From database with GNU General Public License v2.0 | 6 votes |
protected Literal createLiteral(String label, String lang, String datatype) throws RDFParseException { try { label = NTriplesUtil.unescapeString(label); } catch (IllegalArgumentException e) { reportFatalError(e.getMessage()); } if (lang.length() == 0) { lang = null; } if (datatype.length() == 0) { datatype = null; } URI dtURI = null; if (datatype != null) { dtURI = createURI(datatype); } return super.createLiteral(label, lang, dtURI); }
Example #19
Source File: TestTicket4249.java From database with GNU General Public License v2.0 | 6 votes |
private void executeQuery(final RepositoryConnection conn, final String string, final double start, final double length, final String expected) throws RepositoryException, MalformedQueryException, QueryEvaluationException, RDFParseException, IOException, VisitorException { final ValueFactory vf = conn.getValueFactory(); final String query = "select ?substring WHERE { BIND ( SUBSTR(?string, ?start, ?length) as ?substring ) . }"; final TupleQuery q = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); q.setBinding("string", vf.createLiteral(string)); q.setBinding("start", vf.createLiteral(start)); q.setBinding("length", vf.createLiteral(length)); final TupleQueryResult tqr = q.evaluate(); try { while (tqr.hasNext()) { final BindingSet bindings = tqr.next(); // assert expected value assertEquals(expected, bindings.getBinding("substring").getValue().stringValue()); } } finally { tqr.close(); } }
Example #20
Source File: CustomSesameDataset.java From GeoTriples with Apache License 2.0 | 6 votes |
public void loadDataFromInputStream(InputStream is, RDFFormat format, Resource... contexts) throws RepositoryException, RDFParseException, IOException { RepositoryConnection con = null; try { con = currentRepository.getConnection(); con.add(is, "http://geotriples.eu", format, contexts); } finally { try { con.close(); } catch (RepositoryException e) { e.printStackTrace(); } } }
Example #21
Source File: SPARQLStarUpdateDataBlockParser.java From database with GNU General Public License v2.0 | 5 votes |
@Override protected Value parseValue() throws IOException, RDFParseException { if (checkSparqlStarSyntax()) { return parseStmtValue(); } return super.parseValue(); }
Example #22
Source File: BigdataTurtleParser.java From database with GNU General Public License v2.0 | 5 votes |
/** * Parses an RDF value. This method parses uriref, qname, node ID, quoted * literal, integer, double and boolean. */ protected Value parseValue() throws IOException, RDFParseException { int c = peek(); if (c == '<') { // uriref, e.g. <foo://bar> return parseURIOrSid(); } else if (c == ':' || TurtleUtil.isPrefixStartChar(c)) { // qname or boolean return parseQNameOrBoolean(); } else if (c == '_') { // node ID, e.g. _:n1 return parseNodeID(); } else if (c == '"' || c == '\'') { // quoted literal, e.g. "foo" or """foo""" or 'foo' or '''foo''' return parseQuotedLiteral(); } else if (ASCIIUtil.isNumber(c) || c == '.' || c == '+' || c == '-') { // integer or double, e.g. 123 or 1.2e3 return parseNumber(); } else if (c == -1) { throwEOFException(); return null; } else { reportFatalError("Expected an RDF value here, found '" + (char)c + "'"); return null; } }
Example #23
Source File: BigdataNTriplesParser.java From database with GNU General Public License v2.0 | 5 votes |
/** * Verifies that there is only whitespace until the end of the line. */ protected int assertLineTerminates(int c) throws IOException, RDFParseException { c = reader.read(); c = skipWhitespace(c); if (c != -1 && c != '\r' && c != '\n') { reportFatalError("Content after '.' is not allowed"); } return c; }
Example #24
Source File: BigdataNTriplesParser.java From database with GNU General Public License v2.0 | 5 votes |
private int parseNodeID(int c, StringBuilder name) throws IOException, RDFParseException { assert c == '_' : "Supplied char should be a '_', is: " + c; c = reader.read(); if (c == -1) { throwEOFException(); } else if (c != ':') { reportError("Expected ':', found: " + (char)c, NTriplesParserSettings.FAIL_ON_NTRIPLES_INVALID_LINES); } c = reader.read(); if (c == -1) { throwEOFException(); } // modified to allow fully numeric bnode ids //// else if (!NTriplesUtil.isLetter(c)) { // else if (!/*NTriplesUtil.*/isLetter(c)) { // reportError("Expected a letter, found: " + (char)c); // } name.append((char)c); // Read all following letter and numbers, they are part of the name c = reader.read(); // while (c != -1 && NTriplesUtil.isLetterOrNumber(c)) { while (c != -1 && /*NTriplesUtil.*/isLetterOrNumber(c)) { name.append((char)c); c = reader.read(); } return c; }
Example #25
Source File: TestTicket275.java From database with GNU General Public License v2.0 | 5 votes |
private void executeQuery(final SailRepository repo) throws RepositoryException, MalformedQueryException, QueryEvaluationException, RDFParseException, IOException { try { repo.initialize(); final RepositoryConnection conn = repo.getConnection(); conn.setAutoCommit(false); try { conn.add(getClass().getResourceAsStream("TestTicket275.ttl"), "", RDFFormat.TURTLE); conn.commit(); final String query = "SELECT ?lookup WHERE { ?lookup <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <os:class/Lookup> . ?lookup <os:prop/lookup/majorType> ?majorType . OPTIONAL{?lookup <os:prop/lookup/minorType> ?minorType}. FILTER(STR(?majorType) = ?argMajorType). FILTER(!bound(?minorType))}"; final TupleQuery q = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); q.setBinding("argMajorType", conn.getValueFactory() .createLiteral("majoor")); final TupleQueryResult tqr = q.evaluate(); while (tqr.hasNext()) { final Set<String> bindingNames = tqr.next().getBindingNames(); if(log.isInfoEnabled()) log.info("bindingNames="+bindingNames); } tqr.close(); } finally { conn.close(); } } finally { repo.shutDown(); } }
Example #26
Source File: BigdataNTriplesParser.java From database with GNU General Public License v2.0 | 5 votes |
@Override protected URI createURI(String uri) throws RDFParseException { try { uri = NTriplesUtil.unescapeString(uri); } catch (IllegalArgumentException e) { reportError(e.getMessage(), NTriplesParserSettings.FAIL_ON_NTRIPLES_INVALID_LINES); } return super.createURI(uri); }
Example #27
Source File: DavidsTestBOps.java From database with GNU General Public License v2.0 | 5 votes |
private void load ( RepositoryConnection rc, String kb, Resource g ) throws RepositoryException, RDFParseException, IOException { rc.add ( new ByteArrayInputStream ( kb.toString ().getBytes ( "UTF-8" ) ) , "http://xyz.com/test" , RDFFormat.TURTLE , g ) ; rc.commit () ; }
Example #28
Source File: FileSesameDataset.java From GeoTriples with Apache License 2.0 | 5 votes |
@Override public void loadDataFromURL(String stringURL) throws RepositoryException, RDFParseException, IOException { URL url = new URL(stringURL); RDFFormat format = RDFFormat.forFileName(stringURL); if (this.format.equals(format)) { //append to file } else { //convert, then append to file } }
Example #29
Source File: TestTicket276.java From database with GNU General Public License v2.0 | 5 votes |
private void executeQuery(final SailRepository repo) throws RepositoryException, MalformedQueryException, QueryEvaluationException, RDFParseException, IOException, RDFHandlerException { try { repo.initialize(); final RepositoryConnection conn = repo.getConnection(); conn.setAutoCommit(false); try { final ValueFactory vf = conn.getValueFactory(); addData(conn); conn.commit(); final String query = "SELECT ?x { ?x ?a ?t . ?x ?lookup ?l }"; final TupleQuery q = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); q.setBinding( "a", vf.createURI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")); q.setBinding("t", vf.createURI("os:class/Location")); q.setBinding("lookup", vf.createURI("os:prop/lookupName")); q.setBinding("l", vf.createLiteral("amsterdam")); final TupleQueryResult tqr = q.evaluate(); while (tqr.hasNext()) { final Set<String> bindingNames = tqr.next() .getBindingNames(); if (log.isInfoEnabled()) log.info("bindingNames=" + bindingNames); } tqr.close(); } finally { conn.close(); } } finally { repo.shutDown(); } }
Example #30
Source File: SesameRepositoryImpl.java From sparql-playground with GNU General Public License v2.0 | 5 votes |
private static void addTTLFiles(final File folder, RepositoryConnection conn) throws RDFParseException, RepositoryException, IOException { long start = System.currentTimeMillis(); for (final File fileEntry : folder.listFiles()) { if (!fileEntry.isDirectory()) { logger.debug("Loading " + fileEntry); conn.add(fileEntry, "", RDFFormat.TURTLE, new Resource[] {}); } } logger.info("Loading turtle files finished in " + (System.currentTimeMillis() - start) + " ms"); }