[英]How to run a Java Sesame Application From Eclipse
我對Java芝麻很陌生。 我試圖從非常簡單的事情開始。 這是我到目前為止已完成的步驟:
1-部署了war
文件: Tomcat Manager
openrdf-sesame
和openrdf-workbench
。 2-通過openrdf-workbench
創建了一個名為Sample
的存儲庫3-在Eclipse中,我得到了以下代碼:
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 }
}
}
作為Java Sesame的初學者,我有兩個問題,因為我是在openrdf-workbench
創建存儲庫的, openrdf-workbench
如何在Eclipse中執行上述代碼?
我的第二個問題:這是向存儲庫添加RDF語句的正確方法嗎? 我擁有的文件是一個JSON文件,如下所示: Sample_Sesame.json
{
"http://example.org/about" :
{
"http://purl.org/dc/elements/1.1/title": [ { "type" : "literal" , "value" : "Rich's Homepage" } ]
}
}
非常感謝您的協助。
要執行代碼,只需創建一個main方法:
public static void main(String[] args) {
RDF rdf = new RDF();
rdf.create();
}
您的RDF似乎是Sesame 2.7支持的RDF / JSON格式,因此您必須指定RDFFormat.RDFJSON 。
或者,您可以將文件轉換為其他一些普遍接受的格式,例如N-Triples。 看看http://rdf-translator.appspot.com/並嘗試將示例json復制粘貼到那里。 對於輸入,請選擇RDF / JSON,對於輸出,請選擇N-Triples。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.