Java Code Examples for org.openrdf.repository.Repository#initialize()
The following examples show how to use
org.openrdf.repository.Repository#initialize() .
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: LoadPdb.java From database with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { File file = new File("tmp-1Y26.jnl"); Properties properties = new Properties(); properties.setProperty(BigdataSail.Options.FILE, file.getAbsolutePath()); BigdataSail sail = new BigdataSail(properties); Repository repo = new BigdataSailRepository(sail); repo.initialize(); if(false) { sail.getDatabase().getDataLoader().loadData( "contrib/src/problems/alex/1Y26.rdf", new File("contrib/src/problems/alex/1Y26.rdf").toURI() .toString(), RDFFormat.RDFXML); sail.getDatabase().commit(); } // loadSomeDataFromADocument(repo, "contrib/src/problems/alex/1Y26.rdf"); // readSomeData(repo); executeSelectQuery(repo, "SELECT * WHERE { ?s ?p ?o }"); }
Example 2
Source File: SampleBlazegraphSesameEmbedded.java From blazegraph-samples with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws IOException, OpenRDFException { // load journal properties from resources final Properties props = loadProperties("/blazegraph.properties"); // instantiate a sail final BigdataSail sail = new BigdataSail(props); final Repository repo = new BigdataSailRepository(sail); try{ repo.initialize(); /* * Load data from resources * src/main/resources/data.n3 */ loadDataFromResources(repo, "/data.n3", ""); final String query = "select * {<http://blazegraph.com/blazegraph> ?p ?o}"; final TupleQueryResult result = executeSelectQuery(repo, query, QueryLanguage.SPARQL); try { while(result.hasNext()){ final BindingSet bs = result.next(); log.info(bs); } } finally { result.close(); } } finally { repo.shutDown(); } }
Example 3
Source File: SampleBlazegraphCustomFunctionEmbedded.java From blazegraph-samples with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws OpenRDFException, IOException { final Repository repo = createRepository(); registerCustomFunction(repo); try{ repo.initialize(); /* * Load data from resources * src/main/resources/data.n3 */ Utils.loadDataFromResources(repo, "data.n3", ""); final TupleQueryResult result = Utils.executeSelectQuery(repo, QUERY, QueryLanguage.SPARQL); try { while(result.hasNext()){ BindingSet bs = result.next(); log.info(bs); } } finally { result.close(); } } finally { repo.shutDown(); } }
Example 4
Source File: TestRDFSInverseInferencer.java From semweb4j with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void testRDFSPlusInversesInferencer() throws RepositoryException { // create a Sail stack Sail sail = new MemoryStore(); sail = new ForwardChainingRDFSPlusInverseInferencer(sail); // create a Repository Repository repository = new SailRepository(sail); try { repository.initialize(); } catch (RepositoryException e) { throw new RuntimeException(e); } URI a = new URIImpl("urn:test:a"); URI b = new URIImpl("urn:test:b"); URI c = new URIImpl("urn:test:c"); URI d = new URIImpl("urn:test:d"); URI nrlInverse = ForwardChainingRDFSPlusInverseInferencerConnection.NRL_InverseProperty; repository.getConnection().add(a, b, c, new Resource[0]); Assert.assertFalse(repository.getConnection().hasStatement(c, d, a, true, new Resource[0])); repository.getConnection().add(b, nrlInverse, d, new Resource[0]); Assert.assertTrue(repository.getConnection().hasStatement(c, d, a, true, new Resource[0])); }
Example 5
Source File: RepositoryTestCase.java From anno4j with Apache License 2.0 | 5 votes |
protected Repository getRepository() throws Exception, RepositoryException { Repository repository = createRepository(); repository.initialize(); RepositoryConnection con = repository.getConnection(); try { con.setAutoCommit(false); con.clear(); con.clearNamespaces(); con.setNamespace("test", "urn:test:"); con.setAutoCommit(true); } finally { con.close(); } return repository; }
Example 6
Source File: TestRDFSInverseInferencer.java From semweb4j with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void testStrangeBug() throws RepositoryException { // create a Sail stack Sail sail = new MemoryStore(); sail = new ForwardChainingRDFSPlusInverseInferencer(sail); // create a Repository Repository repository = new SailRepository(sail); try { repository.initialize(); } catch (RepositoryException e) { throw new RuntimeException(e); } URI p = new URIImpl("urn:rel:p"); URI q = new URIImpl("urn:rel:q"); URI nrlInverse = ForwardChainingRDFSPlusInverseInferencerConnection.NRL_InverseProperty; URI defaultContext = null; // new Resource[0] RepositoryConnection con = repository.getConnection(); // add p-hasInverse-q con.add(p, nrlInverse, q, defaultContext); assertTrue("just added p-haInv-q, should stil be there", con.hasStatement(p, nrlInverse, q, true, defaultContext) ); assertTrue("expect inferred stmt: q-hasInv-p", con.hasStatement(q, nrlInverse, p, true, defaultContext) ); // add (redundant) inverse stmt: q-hasInv-p con.add(q, nrlInverse, p, defaultContext); assertTrue("added p-haInv-q, should stil be there", con.hasStatement(p, nrlInverse, q, true, defaultContext) ); assertTrue( con.hasStatement(p, nrlInverse, q, true, defaultContext) ); assertTrue("added q-hasInv-p, should still be there", con.hasStatement(q, nrlInverse, p, true, defaultContext) ); }
Example 7
Source File: QuerySupport.java From ldp4j with Apache License 2.0 | 5 votes |
public static QuerySupport newInstance(QueryTemplate template) { Objects.requireNonNull(template, TEMPLATE_PARAM); try { Repository tmpRepo=new SailRepository(new MemoryStore()); tmpRepo.initialize(); return new QuerySupport(tmpRepo,template); } catch (RepositoryException e) { throw new QueryTemplateSupportFailure("Could not initialize internal Sesame repository",e); } }
Example 8
Source File: SPARQLUpdateTest.java From database with GNU General Public License v2.0 | 5 votes |
/** * Creates, initializes and clears a repository. * * @return an initialized empty repository. * @throws Exception */ protected Repository createRepository() throws Exception { Repository repository = newRepository(); repository.initialize(); RepositoryConnection con = repository.getConnection(); con.clear(); con.clearNamespaces(); con.close(); return repository; }
Example 9
Source File: SPARQLQueryTest.java From database with GNU General Public License v2.0 | 5 votes |
protected Repository createRepository() throws Exception { Repository repo = newRepository(); repo.initialize(); RepositoryConnection con = repo.getConnection(); try { con.clear(); con.clearNamespaces(); } finally { con.close(); } return repo; }
Example 10
Source File: RepositoryModelTest.java From semweb4j with BSD 2-Clause "Simplified" License | 5 votes |
@Override @Test public void testRemoveAll() throws Exception { Repository repo = new SailRepository(new MemoryStore()); repo.initialize(); RepositoryModelSet modelSet = new RepositoryModelSet(repo); modelSet.open(); URI context1 = new URIImpl("uri:context1"); URI context2 = new URIImpl("uri:context2"); modelSet.addStatement(context1, new URIImpl("uri:r1"), new URIImpl( "uri:p1"), new URIImpl("uri:r2")); modelSet.addStatement(context1, new URIImpl("uri:r1"), new URIImpl( "uri:p1"), new URIImpl("uri:r3")); modelSet.addStatement(context2, new URIImpl("uri:r4"), new URIImpl( "uri:p2"), new URIImpl("uri:r5")); modelSet.addStatement(context2, new URIImpl("uri:r4"), new URIImpl( "uri:p2"), new URIImpl("uri:r6")); Model model1 = modelSet.getModel(context1); model1.open(); Model model2 = modelSet.getModel(context2); model2.open(); assertEquals(4, modelSet.size()); assertEquals(2, model1.size()); assertEquals(2, model2.size()); model2.removeAll(); assertEquals(2, modelSet.size()); assertEquals(2, model1.size()); assertEquals(0, model2.size()); model1.close(); model2.close(); }
Example 11
Source File: TestRDFSInverseInferencer.java From semweb4j with BSD 2-Clause "Simplified" License | 4 votes |
@Test public void testInferencer_0_directly() throws RepositoryException { // create a Sail stack Sail sail = new MemoryStore(); sail = new ForwardChainingRDFSPlusInverseInferencer(sail); // create a Repository Repository repository = new SailRepository(sail); try { repository.initialize(); } catch (RepositoryException e) { throw new RuntimeException(e); } org.openrdf.model.URI a = new org.openrdf.model.impl.URIImpl( "urn:test:a"); org.openrdf.model.URI b = new org.openrdf.model.impl.URIImpl( "urn:test:b"); org.openrdf.model.URI c = new org.openrdf.model.impl.URIImpl( "urn:test:c"); org.openrdf.model.URI d = new org.openrdf.model.impl.URIImpl( "urn:test:d"); org.openrdf.model.URI nrlInverse = new org.openrdf.model.impl.URIImpl( "http://www.semanticdesktop.org/ontologies/2007/08/15/nrl#inverseProperty"); repository.getConnection().add(a, b, c, new Resource[0]); Assert.assertTrue("added [a] [b] [c]", repository.getConnection() .hasStatement(a, b, c, true, new Resource[0])); Assert.assertFalse("expect not [c] [d] [a]", repository.getConnection() .hasStatement(c, d, a, true, new Resource[0])); // add [b] hasInverse [d] repository.getConnection().add(b, nrlInverse, d, new Resource[0]); Assert.assertTrue("added [b] nrlInverse [d]", repository .getConnection().hasStatement(b, nrlInverse, d, true, new Resource[0])); Assert.assertTrue("expect [c] [d] [a]", repository.getConnection() .hasStatement(c, d, a, true, new Resource[0])); }
Example 12
Source File: HelloBlazegraph.java From blazegraph-samples with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws OpenRDFException { final Properties props = new Properties(); /* * For more configuration parameters see * http://www.blazegraph.com/docs/api/index.html?com/bigdata/journal/BufferMode.html */ props.put(Options.BUFFER_MODE, BufferMode.DiskRW); // persistent file system located journal props.put(Options.FILE, "/tmp/blazegraph/test.jnl"); // journal file location final BigdataSail sail = new BigdataSail(props); // instantiate a sail final Repository repo = new BigdataSailRepository(sail); // create a Sesame repository repo.initialize(); try { // prepare a statement final URIImpl subject = new URIImpl("http://blazegraph.com/Blazegraph"); final URIImpl predicate = new URIImpl("http://blazegraph.com/says"); final Literal object = new LiteralImpl("hello"); final Statement stmt = new StatementImpl(subject, predicate, object); // open repository connection RepositoryConnection cxn = repo.getConnection(); // upload data to repository try { cxn.begin(); cxn.add(stmt); cxn.commit(); } catch (OpenRDFException ex) { cxn.rollback(); throw ex; } finally { // close the repository connection cxn.close(); } // open connection if (repo instanceof BigdataSailRepository) { cxn = ((BigdataSailRepository) repo).getReadOnlyConnection(); } else { cxn = repo.getConnection(); } // evaluate sparql query try { final TupleQuery tupleQuery = cxn .prepareTupleQuery(QueryLanguage.SPARQL, "select ?p ?o where { <http://blazegraph.com/Blazegraph> ?p ?o . }"); final TupleQueryResult result = tupleQuery.evaluate(); try { while (result.hasNext()) { final BindingSet bindingSet = result.next(); System.err.println(bindingSet); } } finally { result.close(); } } finally { // close the repository connection cxn.close(); } } finally { repo.shutDown(); } }
Example 13
Source File: BigdataSPARQLUpdateTest.java From database with GNU General Public License v2.0 | 4 votes |
@Override protected Repository createRepository() throws Exception { Repository repo = newRepository(); repo.initialize(); return repo; }
Example 14
Source File: SPARQLUpdateTestv2.java From database with GNU General Public License v2.0 | 4 votes |
protected Repository createRepository() throws Exception { Repository repo = newRepository(); repo.initialize(); return repo; }
Example 15
Source File: ScaleOut.java From database with GNU General Public License v2.0 | 4 votes |
/** * Issue the query. * * @throws Exception */ private void doQuery() throws Exception { // this is how you get a read-only transaction. MUST be // committed or aborted later, see below. long transactionId = fed.getTransactionService().newTx(ITx.READ_COMMITTED); try { // open the read-only triple store final AbstractTripleStore tripleStore = openTripleStore(fed, transactionId); // wrap it in a Sesame SAIL final BigdataSail sail = new BigdataSail(tripleStore); final Repository repo = new BigdataSailRepository(sail); repo.initialize(); RepositoryConnection cxn = repo.getConnection(); try { final TupleQuery tupleQuery = cxn.prepareTupleQuery(QueryLanguage.SPARQL, query); tupleQuery.setIncludeInferred(true /* includeInferred */); TupleQueryResult result = tupleQuery.evaluate(); // do something with the results int resultCount = 0; while (result.hasNext()) { BindingSet bindingSet = result.next(); // log.info(bindingSet); resultCount++; } log.info(resultCount + " results"); } finally { // close the repository connection cxn.close(); } repo.shutDown(); } finally { // MUST close the transaction, abort is sufficient fed.getTransactionService().abort(transactionId); } }
Example 16
Source File: DemoSesameServer.java From database with GNU General Public License v2.0 | 4 votes |
public static void _main(String[] args) throws Exception { String sesameURL, repoID; if (args != null && args.length == 2) { sesameURL = args[0]; repoID = args[1]; } else { sesameURL = DemoSesameServer.sesameURL; repoID = DemoSesameServer.repoID; } Repository repo = new HTTPRepository(sesameURL, repoID); repo.initialize(); RepositoryConnection cxn = repo.getConnection(); cxn.setAutoCommit(false); try { // load some statements built up programmatically URI mike = new URIImpl(BD.NAMESPACE + "Mike"); URI bryan = new URIImpl(BD.NAMESPACE + "Bryan"); URI loves = new URIImpl(BD.NAMESPACE + "loves"); URI rdf = new URIImpl(BD.NAMESPACE + "RDF"); Graph graph = new GraphImpl(); graph.add(mike, loves, rdf); graph.add(bryan, loves, rdf); cxn.add(graph); cxn.commit(); } finally { cxn.close(); } { // show the entire contents of the repository SparqlBuilder sparql = new SparqlBuilder(); sparql.addTriplePattern("?s", "?p", "?o"); GraphQuery query = cxn.prepareGraphQuery( QueryLanguage.SPARQL, sparql.toString()); GraphQueryResult result = query.evaluate(); while (result.hasNext()) { Statement stmt = result.next(); System.err.println(stmt); } } }
Example 17
Source File: Anno4j.java From anno4j with Apache License 2.0 | 4 votes |
public Anno4j(Repository repository, IDGenerator idGenerator, URI defaultContext, boolean persistSchemaAnnotations, Set<URL> additionalClasses) throws RepositoryConfigException, RepositoryException { this.idGenerator = idGenerator; this.defaultContext = defaultContext; classpath = new HashSet<>(); classpath.addAll(ClasspathHelper.forClassLoader()); classpath.addAll(ClasspathHelper.forJavaClassPath()); classpath.addAll(ClasspathHelper.forManifest()); classpath.addAll(ClasspathHelper.forPackage("")); if(additionalClasses != null) { classpath.addAll(additionalClasses); } Reflections annotatedClasses = new Reflections(new ConfigurationBuilder() .setUrls(classpath) .useParallelExecutor() .filterInputsBy(FilterBuilder.parsePackages("-java, -javax, -sun, -com.sun")) .setScanners(new SubTypesScanner(), new TypeAnnotationsScanner(), new MethodAnnotationsScanner(), new FieldAnnotationsScanner())); // Bugfix: Searching for Reflections creates a lot ot Threads, that are not closed at the end by themselves, // so we close them manually. annotatedClasses.getConfiguration().getExecutorService().shutdown(); // Index conceptsByIri with @Iri annotation: indexConcepts(annotatedClasses); // find classes with @Partial annotation this.partialClasses = annotatedClasses.getTypesAnnotatedWith(Partial.class, true); scanForEvaluators(annotatedClasses); if(!repository.isInitialized()) { repository.initialize(); } this.setRepository(repository, additionalClasses, additionalClasses); // Persist schema information to repository: if(persistSchemaAnnotations) { persistSchemaAnnotations(annotatedClasses); } }
Example 18
Source File: ScaleOut.java From database with GNU General Public License v2.0 | 3 votes |
/** * Opens the triple store and writes the LUBM ontology and U10 data * files. Does a commit after every file, which is not the most * efficient way to bulk load, but simulates incremental updates. */ public void run() { try { // get the unisolated triple store for writing final AbstractTripleStore tripleStore = openTripleStore(fed, ITx.UNISOLATED); // wrap the triple store in a Sesame SAIL final BigdataSail sail = new BigdataSail(tripleStore); final Repository repo = new BigdataSailRepository(sail); repo.initialize(); // load the data loadU10(repo); // shut it down repo.shutDown(); } catch (Exception ex) { ex.printStackTrace(); } }
Example 19
Source File: BigdataSPARQLUpdateTest2.java From database with GNU General Public License v2.0 | 3 votes |
protected Repository createRepository() throws Exception { Repository repo = newRepository(); repo.initialize(); return repo; }
Example 20
Source File: SampleBlazegraphCustomFunctionEmbeddedTest.java From blazegraph-samples with GNU General Public License v2.0 | 3 votes |
@Test public void testCustomFunctionEmbedded() throws OpenRDFException, IOException{ final Repository repo = SampleBlazegraphCustomFunctionEmbedded.createRepository(); SampleBlazegraphCustomFunctionEmbedded.registerCustomFunction(repo); try { repo.initialize(); Utils.loadDataFromResources(repo, "data.n3", ""); final TupleQueryResult result = Utils.executeSelectQuery(repo, SampleBlazegraphCustomFunctionEmbedded.QUERY, QueryLanguage.SPARQL); int countResults = 0; String expected = "http://www.example.com/document1"; String actual = null; while(result.hasNext()){ BindingSet bs = result.next(); actual = bs.getBinding("doc").getValue().stringValue(); countResults++; } result.close(); Assert.assertEquals(1, countResults); Assert.assertEquals(expected, actual); }finally { repo.shutDown(); } }