【Sesame】匯出已經存在的三元組資料

來源:互聯網
上載者:User

在Sesame系列上一篇介紹了如何添加三元組資料,本文將介紹如何匯出三元組資料到檔案。

1. 建立資料庫連接

static NativeStore nativeStore;static Repository repo;static String rdfFile;static {rdfFile = "exportTemp.ttl";repoFile = new File("ldbc");nativeStore = new NativeStore(repoFile);repo = new SailRepository(nativeStore);}

2. 初始化資料庫連接

public static void databaseInitialize() {try {repo.initialize();} catch (RepositoryException e) {e.printStackTrace();}}

3. 匯出資料

public static void outputDatabase(String filename) {try {FileOutputStream out = new FileOutputStream(filename);RDFWriter writer = Rio.createWriter(RDFFormat.TURTLE, out);RepositoryConnection newConn = repo.getConnection();newConn.export(writer);} catch (RepositoryException e) {e.printStackTrace();} catch (FileNotFoundException e) {e.printStackTrace();} catch (RDFHandlerException e) {e.printStackTrace();}System.out.println("-------Output ends--------");}


相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.