private void upload(URI graphURI, Resource context) throws Exception { RepositoryConnection con = dataRep.getConnection(); con.setAutoCommit(false); try { RDFFormat rdfFormat = Rio.getParserFormatForFileName(graphURI.toString(), RDFFormat.TURTLE); RDFParser rdfParser = Rio.createParser(rdfFormat, dataRep.getValueFactory()); rdfParser.setVerifyData(false); rdfParser.setDatatypeHandling(DatatypeHandling.IGNORE); // rdfParser.setPreserveBNodeIDs(true); RDFInserter rdfInserter = new RDFInserter(con); rdfInserter.enforceContext(context); rdfParser.setRDFHandler(rdfInserter); URL graphURL = new URL(graphURI.toString()); InputStream in = graphURL.openStream(); try { rdfParser.parse(in, graphURI.toString()); } finally { in.close(); } con.setAutoCommit(true); } finally { con.close(); } }
public void addFromURI() throws RepositoryException { ValueFactory f = repo.getValueFactory(); // create some resources and literals to make statements out of org.openrdf.model.URI alice = f.createURI(baseURI + "Alice"); org.openrdf.model.URI bob = f.createURI(baseURI + "Bob"); org.openrdf.model.URI age = f.createURI(baseURI + "age"); org.openrdf.model.URI person = f.createURI(baseURI + "Person"); Literal bobsAge = f.createLiteral(5); Literal alicesAge = f.createLiteral(14); // alice is a person con.add(alice, RDF.TYPE, person); // alice's name is "Alice" // con.add(alice, age, alicesAge); // bob is a person con.add(bob, RDF.TYPE, person); // bob's name is "Bob" // con.add(bob, age, bobsAge); }
private TupleQueryResult readExpectedTupleQueryResult() throws Exception { TupleQueryResultFormat tqrFormat = QueryResultIO.getParserFormatForFileName(resultFileURL); if (tqrFormat != null) { InputStream in = new URL(resultFileURL).openStream(); try { TupleQueryResultParser parser = QueryResultIO.createParser(tqrFormat); parser.setValueFactory(dataRep.getValueFactory()); TupleQueryResultBuilder qrBuilder = new TupleQueryResultBuilder(); parser.setTupleQueryResultHandler(qrBuilder); parser.parse(in); return qrBuilder.getQueryResult(); } finally { in.close(); } } else { Set<Statement> resultGraph = readExpectedGraphQueryResult(); return DAWGTestResultSetUtil.toTupleQueryResult(resultGraph); } }
protected static String getManifestName( Repository manifestRep, RepositoryConnection con, String manifestFileURL) throws QueryEvaluationException, RepositoryException, MalformedQueryException { // Try to extract suite name from manifest file TupleQuery manifestNameQuery = con.prepareTupleQuery( QueryLanguage.SERQL, "SELECT ManifestName FROM {ManifestURL} rdfs:label {ManifestName}"); manifestNameQuery.setBinding( "ManifestURL", manifestRep.getValueFactory().createURI(manifestFileURL)); TupleQueryResult manifestNames = manifestNameQuery.evaluate(); try { if (manifestNames.hasNext()) { return manifestNames.next().getValue("ManifestName").stringValue(); } } finally { manifestNames.close(); } // Derive name from manifest URL int lastSlashIdx = manifestFileURL.lastIndexOf('/'); int secLastSlashIdx = manifestFileURL.lastIndexOf('/', lastSlashIdx - 1); return manifestFileURL.substring(secLastSlashIdx + 1, lastSlashIdx); }
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); 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; } else { throw new RuntimeException("Unable to determine file type of results file"); } }
public ValueFactory getValueFactory() { return repository.getValueFactory(); }
@Override public void beginTransaction() { vf = repository.getValueFactory(); }