Java Code Examples for org.eclipse.rdf4j.repository.Repository#init()
The following examples show how to use
org.eclipse.rdf4j.repository.Repository#init() .
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: FedXWithRemoteRepositoryManager.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
public static void main(String[] args) throws Exception { // connection URL of a RDF4J server which manages the repositories String serverUrl = "http://localhost:8080/rdf4j-server"; RepositoryManager repoManager = new RemoteRepositoryManager(serverUrl); // assumes that remote repositories exist Repository localRepo = FedXFactory.newFederation() .withRepositoryResolver(repoManager) .withResolvableEndpoint("my-repository-1") .withResolvableEndpoint("my-repository-2") .create(); localRepo.init(); try (RepositoryConnection conn = localRepo.getConnection()) { try (RepositoryResult<Statement> repoResult = conn.getStatements(null, RDF.TYPE, FOAF.PERSON)) { repoResult.forEach(st -> System.out.println(st)); } } localRepo.shutDown(); repoManager.shutDown(); }
Example 2
Source File: SPARQLServerBaseTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Load a dataset. Note: the repositories are cleared before loading data * * @param rep * @param datasetFile * @throws RDFParseException * @throws RepositoryException * @throws IOException */ protected void loadDataSet(Repository rep, String datasetFile) throws RDFParseException, RepositoryException, IOException { log.debug("loading dataset..."); InputStream dataset = SPARQLServerBaseTest.class.getResourceAsStream(datasetFile); boolean needToShutdown = false; if (!rep.isInitialized()) { rep.init(); needToShutdown = true; } RepositoryConnection con = rep.getConnection(); try { con.clear(); con.add(dataset, "", Rio.getParserFormatForFileName(datasetFile).get()); } finally { dataset.close(); con.close(); if (needToShutdown) { rep.shutDown(); } } log.debug("dataset loaded."); }
Example 3
Source File: Demo2.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static void main(String[] args) throws Exception { if (System.getProperty("log4j.configuration") == null) { System.setProperty("log4j.configuration", "file:local/log4j.properties"); } File dataConfig = new File("local/LifeScience-FedX-SPARQL.ttl"); Repository repo = FedXFactory.createFederation(dataConfig); repo.init(); String q = "SELECT ?Drug ?IntDrug ?IntEffect WHERE { " + "?Drug <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/ontology/Drug> . " + "?y <http://www.w3.org/2002/07/owl#sameAs> ?Drug . " + "?Int <http://www4.wiwiss.fu-berlin.de/drugbank/resource/drugbank/interactionDrug1> ?y . " + "?Int <http://www4.wiwiss.fu-berlin.de/drugbank/resource/drugbank/interactionDrug2> ?IntDrug . " + "?Int <http://www4.wiwiss.fu-berlin.de/drugbank/resource/drugbank/text> ?IntEffect . }"; try (RepositoryConnection conn = repo.getConnection()) { TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, q); try (TupleQueryResult res = query.evaluate()) { while (res.hasNext()) { System.out.println(res.next()); } } } repo.shutDown(); System.out.println("Done."); System.exit(0); }
Example 4
Source File: LocalRepositoryManager.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override protected Repository createRepository(String id) throws RepositoryConfigException, RepositoryException { Repository repository = null; RepositoryConfig repConfig = getRepositoryConfig(id); if (repConfig != null) { repConfig.validate(); repository = createRepositoryStack(repConfig.getRepositoryImplConfig()); repository.setDataDir(getRepositoryDir(id)); repository.init(); } return repository; }
Example 5
Source File: HBaseRepositoryManager.java From Halyard with Apache License 2.0 | 5 votes |
@Override protected Repository createRepository(String id) throws RepositoryConfigException, RepositoryException { Repository repository = null; RepositoryConfig repConfig = getRepositoryConfig(id); if (repConfig != null) { repConfig.validate(); repository = createRepositoryStack(repConfig.getRepositoryImplConfig()); repository.init(); } return repository; }
Example 6
Source File: QueryPlanLogDemo.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static void main(String[] args) throws Exception { FedXConfig config = new FedXConfig().withEnableMonitoring(true).withLogQueryPlan(true); Repository repo = FedXFactory.newFederation() .withSparqlEndpoint("http://dbpedia.org/sparql") .withSparqlEndpoint("https://query.wikidata.org/sparql") .withConfig(config) .create(); repo.init(); String q = "PREFIX wd: <http://www.wikidata.org/entity/> " + "PREFIX wdt: <http://www.wikidata.org/prop/direct/> " + "SELECT * WHERE { " + " ?country a <http://dbpedia.org/class/yago/WikicatMemberStatesOfTheEuropeanUnion> ." + " ?country <http://www.w3.org/2002/07/owl#sameAs> ?countrySameAs . " + " ?countrySameAs wdt:P2131 ?gdp ." + "}"; try (RepositoryConnection conn = repo.getConnection()) { TupleQuery query = repo.getConnection().prepareTupleQuery(QueryLanguage.SPARQL, q); try (TupleQueryResult res = query.evaluate()) { int count = 0; while (res.hasNext()) { res.next(); count++; } System.out.println("# Done, " + count + " results"); } System.out.println("# Optimized Query Plan:"); System.out.println(QueryPlanLog.getQueryPlan()); } repo.shutDown(); System.out.println("Done."); System.exit(0); }
Example 7
Source File: CustomFederationConnectionTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Test public void testAssertionErrorReproduction() { for (int i = 0; i < 1000; i++) { ValueFactory vf = SimpleValueFactory.getInstance(); BNode address = vf.createBNode(); BNode anotherAddress = vf.createBNode(); ModelBuilder builder = new ModelBuilder(); builder .setNamespace("ex", "http://example.org/") .subject("ex:Picasso") .add(RDF.TYPE, "ex:Artist") .add(FOAF.FIRST_NAME, "Pablo") .add("ex:homeAddress", address) .subject("ex:AnotherArtist") .add(RDF.TYPE, "ex:Artist") .add(FOAF.FIRST_NAME, "AnotherArtist") .add("ex:homeAddress", anotherAddress) .subject(address) .add("ex:street", "31 Art Gallery") .add("ex:city", "Madrid") .add("ex:country", "Spain") .subject(anotherAddress) .add("ex:street", "32 Art Gallery") .add("ex:city", "London") .add("ex:country", "UK"); Model model = builder.build(); Repository repo1 = new SailRepository(new MemoryStore()); repo1.init(); try (RepositoryConnection connection = repo1.getConnection()) { connection.add(model); } Repository repo2 = new SailRepository(new MemoryStore()); repo2.init(); Federation fed = new Federation(); fed.addMember(repo1); fed.addMember(repo2); String ex = "http://example.org/"; String queryString = "PREFIX rdf: <" + RDF.NAMESPACE + ">\n" + "PREFIX foaf: <" + FOAF.NAMESPACE + ">\n" + "PREFIX ex: <" + ex + ">\n" + "select (count(?persons) as ?count) {\n" + " ?persons rdf:type ex:Artist ;\n" + " ex:homeAddress ?country .\n" + " ?country ex:country \"Spain\" . }"; SailRepository fedRepo = new SailRepository(fed); fedRepo.init(); IntStream.range(0, 100).parallel().forEach(j -> { try (SailRepositoryConnection fedRepoConn = fedRepo.getConnection()) { fedRepoConn.begin(); TupleQuery query = fedRepoConn.prepareTupleQuery(QueryLanguage.SPARQL, queryString); try (TupleQueryResult eval = query.evaluate()) { if (eval.hasNext()) { Value next = eval.next().getValue("count"); assertEquals(1, ((Literal) next).intValue()); } else { fail("No result"); } } fedRepoConn.commit(); } }); fedRepo.shutDown(); } }