Skip to content
Snippets Groups Projects
Commit 842ecc87 authored by Andreas Schärtl's avatar Andreas Schärtl
Browse files

Play around w/ rdf4j

parent 8c3f3683
No related branches found
No related tags found
No related merge requests found
package me.schaertl.graphcli; package me.schaertl.graphcli;
import org.eclipse.rdf4j.model.Resource;
import org.eclipse.rdf4j.model.impl.TreeModel;
import org.eclipse.rdf4j.model.vocabulary.RDF;
import org.eclipse.rdf4j.repository.Repository; import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.RepositoryConnection; import org.eclipse.rdf4j.repository.RepositoryConnection;
import org.eclipse.rdf4j.repository.config.RepositoryConfig;
import org.eclipse.rdf4j.repository.config.RepositoryConfigSchema;
import org.eclipse.rdf4j.repository.manager.LocalRepositoryManager;
import org.eclipse.rdf4j.repository.manager.RemoteRepositoryManager; import org.eclipse.rdf4j.repository.manager.RemoteRepositoryManager;
import org.eclipse.rdf4j.repository.manager.RepositoryManager; import org.eclipse.rdf4j.repository.manager.RepositoryManager;
import org.eclipse.rdf4j.rio.RDFFormat;
import org.eclipse.rdf4j.rio.RDFParser;
import org.eclipse.rdf4j.rio.Rio;
import org.eclipse.rdf4j.rio.helpers.StatementCollector;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
public class Main { public class Main {
private static void hello() throws IOException { private static void hello() throws IOException {
// Code taken from http://graphdb.ontotext.com/documentation/standard/using-graphdb-with-the-rdf4j-api.html // Code taken from http://graphdb.ontotext.com/documentation/standard/using-graphdb-with-the-rdf4j-api.html
//
// XXX: This code has bad error handling. The API isn't helpful, but in production code
// I would never do such things.
// Instantiate a local repository manager and initialize it // Instantiate a local repository manager and initialize it
final RepositoryManager repositoryManager = new RemoteRepositoryManager("http://rdf:7200"); final RepositoryManager repositoryManager = new RemoteRepositoryManager("http://rdf:7200");
repositoryManager.initialize(); repositoryManager.init();
// Instantiate a repository graph model
// final TreeModel graph = new TreeModel();
// Read repository configuration file
// InputStream config = EmbeddedGraphDB.class.getResourceAsStream("/repo-defaults.ttl");
// RDFParser rdfParser = Rio.createParser(RDFFormat.TURTLE);
// rdfParser.setRDFHandler(new StatementCollector(graph));
// rdfParser.parse(config, RepositoryConfigSchema.NAMESPACE);
// config.close();
// Retrieve the repository node as a resource
// Resource repositoryNode = GraphUtil.getUniqueSubject(graph, RDF.TYPE, RepositoryConfigSchema.REPOSITORY);
// Create a repository configuration object and add it to the repositoryManager
// RepositoryConfig repositoryConfig = RepositoryConfig.create(graph, repositoryNode);
// repositoryManager.addRepositoryConfig(repositoryConfig);
// Get the repository from repository manager, note the repository id set in configuration .ttl file
final Repository repository = repositoryManager.getRepository("chem"); final Repository repository = repositoryManager.getRepository("chem");
if (repository == null) {
throw new IOException("no such repository");
}
// Open a connection to this repository // Open a connection to this repository
final RepositoryConnection repositoryConnection = repository.getConnection(); final RepositoryConnection repositoryConnection = repository.getConnection();
...@@ -60,6 +36,5 @@ public class Main { ...@@ -60,6 +36,5 @@ public class Main {
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
Main.hello(); Main.hello();
System.out.println("done running the program");
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment