java - How to use Jena TDB to store local version of Linked Movie Database -
i have local version of linkedmdb in n-triples format , want query it. now, want use jena tdb, can store data can used querying later. checked documentation tdb java api, unable load n-triples file , query sparql. i've used following code:
string directory = "e:\\applications\\tdb-0.8.9\\tdb-0.8.9\\bin\\tdb"; dataset dataset = tdbfactory.createdataset(directory); // assume want default model, or named model here model tdb = dataset.getdefaultmodel(); // read input file - needs done once string source = "e:\\applications\\linkedmdb-18-05-2009-dump.nt"; filemanager.get().readmodel( tdb, source, "n-triples" ); and got following exception
exception in thread "main" com.hp.hpl.jena.tdb.base.file.fileexception: not directory: e:\applications\tdb-0.8.9\tdb-0.8.9\bin\tdb @ com.hp.hpl.jena.tdb.base.file.location.<init>(location.java:83) @ com.hp.hpl.jena.tdb.tdbfactory.createdataset(tdbfactory.java:79) @ tutorial.temp.main(temp.java:14)
reading tdb-backed model java straightforward, see the tdb wiki details. example, could:
// open tdb dataset string directory = "./tdb"; dataset dataset = tdbfactory.createdataset(directory); // assume want default model, or named model here model tdb = dataset.getdefaultmodel(); // read input file - needs done once string source = "path/to/input.nt"; filemanager.get().readmodel( tdb, source, "n-triples" ); // run query string q = "select * {?s ?p ?o} limit 10"; query query = queryfactory.create(q); queryexecution qexec = queryexecutionfactory.create(query, tdb); resultset results = qexec.execselect(); ... etc ... as user205512 mentioned, can use tdbloader2 command line on linux or mac, faster on large rdf files. once tdb indexes have been created, can copy files other machines. can load data on linux server, ship files inside tdb directory windows machine continue development.
to run tdbloader command line on windows machine, you'll need cygwin allow run unix-style scripts. you'll need set environment variable tdbroot.
Comments
Post a Comment