org.openrdf.OpenRDFException Java Examples
The following examples show how to use
org.openrdf.OpenRDFException.
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: RepositoryModelSet.java From semweb4j with BSD 2-Clause "Simplified" License | 6 votes |
@Override public ClosableIterable<Statement> queryConstruct(String queryString, String queryLanguage) throws QueryLanguageNotSupportedException, ModelRuntimeException { this.assertModel(); // resolve the query language String to a QueryLanguage QueryLanguage language = ConversionUtil.toOpenRDFQueryLanguage(queryLanguage); try { // determine query result GraphQuery query = this.connection.prepareGraphQuery(language, queryString); GraphQueryResult queryResult = query.evaluate(); // wrap it in a GraphIterable return new GraphIterable(queryResult, null); } catch(OpenRDFException e) { throw new ModelRuntimeException(e); } }
Example #2
Source File: RepositoryModel.java From semweb4j with BSD 2-Clause "Simplified" License | 6 votes |
@Override public ClosableIterator<org.ontoware.rdf2go.model.Statement> findStatements( ResourceOrVariable subject, UriOrVariable predicate, NodeOrVariable object) throws ModelRuntimeException { assertModel(); // convert parameters to OpenRDF data types org.openrdf.model.Resource openRdfSubject = (org.openrdf.model.Resource)ConversionUtil .toOpenRDF(subject, this.valueFactory); org.openrdf.model.URI openRdfPredicate = (org.openrdf.model.URI)ConversionUtil.toOpenRDF( predicate, this.valueFactory); Value openRdfObject = ConversionUtil.toOpenRDF(object, this.valueFactory); try { // find the matching statements CloseableIteration<? extends org.openrdf.model.Statement,? extends OpenRDFException> statements = this.connection .getStatements(openRdfSubject, openRdfPredicate, openRdfObject, true, this.openRdfContext); // wrap them in a StatementIterable return new StatementIterator(statements, this); } catch(RepositoryException e) { throw new ModelRuntimeException(e); } }
Example #3
Source File: SampleBlazegraphSesameEmbedded.java From blazegraph-samples with GNU General Public License v2.0 | 6 votes |
public static TupleQueryResult executeSelectQuery(final Repository repo, final String query, final QueryLanguage ql) throws OpenRDFException { RepositoryConnection cxn; if (repo instanceof BigdataSailRepository) { cxn = ((BigdataSailRepository) repo).getReadOnlyConnection(); } else { cxn = repo.getConnection(); } try { final TupleQuery tupleQuery = cxn.prepareTupleQuery(ql, query); tupleQuery.setIncludeInferred(true /* includeInferred */); return tupleQuery.evaluate(); } finally { // close the repository connection cxn.close(); } }
Example #4
Source File: SparqlEvaluator.java From anno4j with Apache License 2.0 | 6 votes |
public <T> Set<T> asSet(Class<T> of) throws OpenRDFException { if (of == null || Object.class.equals(of)) return asSet(); if (BindingSet.class.equals(of)) { TupleQueryResult result = asTupleQueryResult(); try { List<BindingSet> list = new ArrayList<BindingSet>(); while (result.hasNext()) { list.add(result.next()); } return (Set<T>) list; } finally { result.close(); } } if (Value.class.isAssignableFrom(of)) return (Set<T>) asSetOfValues(); if (Statement.class.equals(of)) return (Set<T>) asModel(); return asResult(of).asSet(); }
Example #5
Source File: Utils.java From blazegraph-samples with GNU General Public License v2.0 | 6 votes |
public static TupleQueryResult executeSelectQuery(Repository repo, String query, QueryLanguage ql) throws OpenRDFException { RepositoryConnection cxn; if (repo instanceof BigdataSailRepository) { cxn = ((BigdataSailRepository) repo).getReadOnlyConnection(); } else { cxn = repo.getConnection(); } try { final TupleQuery tupleQuery = cxn.prepareTupleQuery(ql, query); tupleQuery.setIncludeInferred(true /* includeInferred */); return tupleQuery.evaluate(); } finally { // close the repository connection cxn.close(); } }
Example #6
Source File: StatementIterator.java From semweb4j with BSD 2-Clause "Simplified" License | 6 votes |
public org.ontoware.rdf2go.model.Statement next() { org.ontoware.rdf2go.model.Statement result = null; try { Statement nextStatement = this.cit.next(); result = new StatementWrapper(this.model, nextStatement); if (!this.cit.hasNext()) { close(); } } catch (OpenRDFException e) { throw new ModelRuntimeException(e); } return result; }
Example #7
Source File: TestTicket276.java From database with GNU General Public License v2.0 | 6 votes |
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"), ""); }
Example #8
Source File: SparqlEvaluator.java From anno4j with Apache License 2.0 | 5 votes |
public void toWriter(Writer writer) throws OpenRDFException, TransformerException, IOException { if (query.isGraphQuery()) { QueryResultUtil.report(asGraphQueryResult(), new RDFXMLWriter( writer)); } else if (query.isTupleQuery()) { QueryResultUtil.report(asTupleQueryResult(), new SPARQLResultsXMLWriter(new XMLWriter(writer))); } else if (query.isBooleanQuery()) { new SPARQLBooleanXMLWriter(new XMLWriter(writer)) .write(asBoolean()); } else { throw new AssertionError("Unknown query type"); } }
Example #9
Source File: StatementIterator.java From semweb4j with BSD 2-Clause "Simplified" License | 5 votes |
public void close() { try { this.cit.close(); } catch (OpenRDFException e) { throw new ModelRuntimeException(e); } this.closed = true; }
Example #10
Source File: BigdataGraph.java From database with GNU General Public License v2.0 | 5 votes |
@Override public boolean hasNext() { try { return stmts.hasNext(); } catch (OpenRDFException e) { throw new RuntimeException(e); } }
Example #11
Source File: BigdataGraph.java From database with GNU General Public License v2.0 | 5 votes |
@Override public boolean hasNext() { try { return stmts.hasNext(); } catch (OpenRDFException e) { throw new RuntimeException(e); } }
Example #12
Source File: BigdataGraph.java From database with GNU General Public License v2.0 | 5 votes |
public VertexIterable( final CloseableIteration<Statement, ? extends OpenRDFException> stmts, final boolean subject) { this.stmts = stmts; this.subject = subject; this.cache = new LinkedList<Vertex>(); }
Example #13
Source File: RepositoryModelSet.java From semweb4j with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void readFrom(InputStream in, Syntax syntax) throws IOException, ModelRuntimeException { this.assertModel(); try { this.connection.add(in, "", getRDFFormat(syntax)); } catch(OpenRDFException e) { throw new ModelRuntimeException(e); } }
Example #14
Source File: SparqlEvaluator.java From anno4j with Apache License 2.0 | 5 votes |
public void toOutputStream(OutputStream output) throws OpenRDFException, TransformerException, IOException { if (query.isGraphQuery()) { QueryResultUtil.report(asGraphQueryResult(), new RDFXMLWriter( output)); } else if (query.isTupleQuery()) { QueryResultUtil.report(asTupleQueryResult(), new SPARQLResultsXMLWriter(output)); } else if (query.isBooleanQuery()) { new SPARQLBooleanXMLWriter(output).write(asBoolean()); } else { throw new AssertionError("Unknown query type"); } }
Example #15
Source File: SparqlEvaluator.java From anno4j with Apache License 2.0 | 5 votes |
public XMLEventReader asXMLEventReader() throws OpenRDFException, TransformerException, IOException, ParserConfigurationException, XMLStreamException { InputStream in = asInputStream(); try { if (systemId == null) return inFactory.createXMLEventReader(in); return inFactory.createXMLEventReader(systemId, in); } catch (XMLStreamException e) { throw new TransformerException(e); } }
Example #16
Source File: SparqlEvaluator.java From anno4j with Apache License 2.0 | 5 votes |
public Set<? extends Value> asSetOfValues() throws OpenRDFException { Set<Value> set = new LinkedHashSet<Value>(); TupleQueryResult result = asTupleQueryResult(); try { if (result.getBindingNames().isEmpty()) return null; String name = result.getBindingNames().iterator().next(); while (result.hasNext()) { set.add(result.next().getValue(name)); } return set; } finally { result.close(); } }
Example #17
Source File: Utils.java From blazegraph-samples with GNU General Public License v2.0 | 5 votes |
public static void loadDataFromResources(Repository repo, String resource, String baseURL) throws OpenRDFException, IOException { RepositoryConnection cxn = repo.getConnection(); try { cxn.begin(); try { InputStream is = SampleBlazegraphCustomFunctionEmbedded.class.getClassLoader().getResourceAsStream(resource); if (is == null) { throw new IOException("Could not locate resource: " + resource); } Reader reader = new InputStreamReader(new BufferedInputStream(is)); try { cxn.add(reader, baseURL, RDFFormat.N3); } finally { reader.close(); } cxn.commit(); } catch (OpenRDFException ex) { cxn.rollback(); throw ex; } } finally { // close the repository connection cxn.close(); } }
Example #18
Source File: SparqlEvaluator.java From anno4j with Apache License 2.0 | 5 votes |
public DocumentFragment asDocumentFragment() throws OpenRDFException, TransformerException, IOException, ParserConfigurationException { Document doc = asDocument(); DocumentFragment frag = doc.createDocumentFragment(); frag.appendChild(doc.getDocumentElement()); return frag; }
Example #19
Source File: RepositoryModelSet.java From semweb4j with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void readFrom(InputStream in, Syntax syntax, String baseURI) throws IOException, ModelRuntimeException { this.assertModel(); try { this.connection.add(in, baseURI, getRDFFormat(syntax)); } catch(OpenRDFException e) { throw new ModelRuntimeException(e); } }
Example #20
Source File: RepositoryModelSet.java From semweb4j with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void readFrom(Reader reader, Syntax syntax) throws IOException, ModelRuntimeException { this.assertModel(); try { this.connection.add(reader, "", getRDFFormat(syntax)); } catch(OpenRDFException e) { throw new ModelRuntimeException(e); } }
Example #21
Source File: RepositoryModelSet.java From semweb4j with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void readFrom(Reader reader, Syntax syntax, String baseURI) throws IOException, ModelRuntimeException { this.assertModel(); try { this.connection.add(reader, baseURI, getRDFFormat(syntax)); } catch(OpenRDFException e) { throw new ModelRuntimeException(e); } }
Example #22
Source File: RepositoryModelSet.java From semweb4j with BSD 2-Clause "Simplified" License | 5 votes |
@Override public boolean sparqlAsk(String queryString) throws ModelRuntimeException { this.assertModel(); BooleanQuery booleanQuery; try { booleanQuery = this.connection.prepareBooleanQuery(QueryLanguage.SPARQL, queryString); boolean result = booleanQuery.evaluate(); return result; } catch(OpenRDFException e) { throw new ModelRuntimeException(e); } }
Example #23
Source File: RepositoryModelSet.java From semweb4j with BSD 2-Clause "Simplified" License | 5 votes |
@Override public ClosableIterable<Statement> sparqlConstruct(String queryString) throws ModelRuntimeException { this.assertModel(); GraphQuery query; try { query = this.connection.prepareGraphQuery(QueryLanguage.SPARQL, queryString); GraphQueryResult graphQueryResult = query.evaluate(); return new StatementIterable(graphQueryResult, null); } catch(OpenRDFException e) { throw new ModelRuntimeException(e); } }
Example #24
Source File: RepositoryModelSet.java From semweb4j with BSD 2-Clause "Simplified" License | 5 votes |
@Override public ClosableIterable<Statement> sparqlDescribe(String queryString) throws ModelRuntimeException { this.assertModel(); GraphQuery query; try { query = this.connection.prepareGraphQuery(QueryLanguage.SPARQL, queryString); GraphQueryResult graphQueryResult = query.evaluate(); return new StatementIterable(graphQueryResult, null); } catch(OpenRDFException e) { throw new ModelRuntimeException(e); } }
Example #25
Source File: RepositoryModelSet.java From semweb4j with BSD 2-Clause "Simplified" License | 5 votes |
private void writeTo(RDFWriter writer) throws ModelRuntimeException { this.assertModel(); try { this.connection.export(writer); } catch(OpenRDFException e) { throw new ModelRuntimeException(e); } }
Example #26
Source File: RepositoryQueryResultTable.java From semweb4j with BSD 2-Clause "Simplified" License | 5 votes |
public RepositoryQueryResultTable(String queryString, QueryLanguage language, RepositoryConnection connection) throws ModelRuntimeException { try { this.query = connection.prepareTupleQuery(language, queryString); this.queryResult = this.query.evaluate(); } catch(OpenRDFException e) { throw new ModelRuntimeException(e); } }
Example #27
Source File: RDFModelParser.java From ldp4j with Apache License 2.0 | 5 votes |
private void closeQuietly(RepositoryResult<?> results, String message) { if(results!=null) { try { results.close(); } catch (OpenRDFException e) { if(LOGGER.isWarnEnabled()) { LOGGER.warn(message,e); } } } }
Example #28
Source File: RDFModelParser.java From ldp4j with Apache License 2.0 | 5 votes |
private void shutDownQuietly(Repository repository) { if(repository!=null) { try { repository.shutDown(); } catch (OpenRDFException e) { if(LOGGER.isWarnEnabled()) { LOGGER.warn("Could not shutdown internal repository",e); } } } }
Example #29
Source File: RDFModelParser.java From ldp4j with Apache License 2.0 | 5 votes |
private void closeQuietly(RepositoryConnection connection) { if(connection!=null) { try { connection.close(); } catch (OpenRDFException e) { if(LOGGER.isWarnEnabled()) { LOGGER.warn("Could not close connection",e); } } } }
Example #30
Source File: RDFModelParser.java From ldp4j with Apache License 2.0 | 5 votes |
@Override public void injectTriples(TripleSink sink) throws IOException { try { Collector collector = new Collector(); RDFParser parser =Rio.createParser(this.format); parser.setRDFHandler(collector); parser.parse(new StringReader(this.content), this.base); SesameModelParser tripleParser=new SesameModelParser(collector.getNamespaces()); for(Statement st:collector.getStatements()) { sink.addTriple(tripleParser.parseStatement(st)); } } catch (OpenRDFException e) { throw new IOException(e); } }