Loading a .trig file into TDB?

霸气de小男生 提交于 2019-12-25 04:07:03

问题


I am currently writing some code in Java, using Jena and TDB -- on a Windows 7.

I want to be able to load a (large) .trig file into TDB Dataset so that querying is a bit faster. The code that I currently have is:

Dataset dataset = TDBFactory.createDataset(directoryPath);
Model tdb = dataset.getDefaultModel();
RDFDataMgr.read(tdb, inputFilePath);
try {
        String theQuery = readFile(testQueryPath, Charset.defaultCharset());        
        Query query = QueryFactory.create(theQuery);
        QueryExecution qe = QueryExecutionFactory.create(query, dataset);
        com.hp.hpl.jena.query.ResultSet results =  qe.execSelect();

        // Output query results    
        ResultSetFormatter.out(System.out, results, query);
        qe.close();

} catch (IOException e) {
        e.printStackTrace();
}

I also tried:

FileManager.get().readModel( tdb, inputFilePath);

instead of:

RDFDataMgr.read(tdb, inputFilePath);

I get the following warning:

2014-06-13 13:02:26 WARN riot:77 - Only triples or default graph data expected : named graph data ignored

The SPARQL queries I ran are:

PREFIX xsd: http://www.w3.org/2001/XMLSchema#

PREFIX dc: http://purl.org/dc/elements/1.1/

PREFIX : <.>

SELECT *

{

{ ?s ?p ?o } UNION { GRAPH ?g { ?s ?p ?o } }

}

and also the same one but without the UNION and GRAPH things.

The queries return nothing.

Does anyone see an apparent problem or know how to load .trig files into TDB?


回答1:


You just read into the dataset:

RDFDataMgr.read(dataset, inputFilePath);

Inside write transaction would be better else call TDB.sync(dataset) before you exit.

You code loads it every run. If the file is really big, use tdbloader, the bulk loader, before running the query program.



来源:https://stackoverflow.com/questions/24213961/loading-a-trig-file-into-tdb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!