I am very new to Java Sesame. I am trying to start with something very simple. Here are the steps I have done so far:
1- Deployed the war
files: openrdf-sesame
and openrdf-workbench
in Tomcat Manager
. 2- created a repository called Sample
through openrdf-workbench
3- In Eclipse, I have got this code:
import org.openrdf.repository.Repository;
import org.openrdf.repository.RepositoryConnection;
import org.openrdf.repository.RepositoryException;
import org.openrdf.repository.config.RepositoryConfigException;
import org.openrdf.repository.manager.RemoteRepositoryManager;
import java.io.File;
import org.openrdf.rio.RDFFormat;
import java.net.URL;
import org.openrdf.OpenRDFException;
import java.io.IOException;
public class RDF{
public void create() throws RepositoryConfigException, RepositoryException
{
String serverUrl = "http://localhost:8080/openrdf-sesame";
RemoteRepositoryManager manager = new RemoteRepositoryManager(serverUrl);
manager.initialize();
Repository repository = manager.getRepository("Sample");
File file = new File("Sample_Sesame.json");
String baseURI = "file://Sample_Sesame.json";
try {
RepositoryConnection con = repository.getConnection();
try {
con.add(file, baseURI, RDFFormat.N3);
URL url = new URL("/Users/Documents/newsample/folder/Sample_Sesame.json");
con.add(url, url.toString(), RDFFormat.RDFXML);
}
finally { con.close(); }
}
catch (OpenRDFException e) { // handle exception }
catch (IOException e) { // handle io exception }
}
}
As being a beginner in Java Sesame, I have two questions, since I created the repository in openrdf-workbench
, how can I execute the above code in Eclipse?
My second question: is this the right way of adding an RDF statement into the repository? The file I am having is a JSON file as below: Sample_Sesame.json
{
"http://example.org/about" :
{
"http://purl.org/dc/elements/1.1/title": [ { "type" : "literal" , "value" : "Rich's Homepage" } ]
}
}
Your assistance would be sincerely more than appreciated.
To execute your code, you simply create a main method:
public static void main(String[] args) {
RDF rdf = new RDF();
rdf.create();
}
Your RDF seems to be in the RDF/JSON format which seems to be supported by Sesame 2.7, so you have to specify the RDFFormat.RDFJSON .
Alternatively, you could convert your file to some other, universally accepted format such as N-Triples. Have a look at http://rdf-translator.appspot.com/ and try to copy paste your sample json there. For input select RDF/JSON and for output N-Triples.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.