On 12/04/12 14:12, Emilio Miguelanez wrote:
Hello Andy,

The prefixes.dat is zero.

For reference, I use tbdloader2 (I believe it is better than tdbloader), and it 
uses a rdf file to populate the tdb

I used your code and it worked quite well. I managed to retrieve the prefixes,  
and the prefixes.dat is not zero now

So I guess this piece of code is a work around to the issue with bulkloader.

Yes - you can non-bulkloadd a data file of prefixes (no need for any triples).

        Andy


cheers,
Emilio

On 12 Apr 2012, at 11:53, Andy Seaborne wrote:

On 11/04/12 14:58, Emilio Miguelanez wrote:
Hi,

How can I get the prefixes from the TDB store using latest tdb version 0.9.0?

Previously, using version 0.8.10, I managed to get the prefixes using the 
following code

Model bModel = TDBFactory.createModel(repoDir);
OntModel aModel = ModelFactory.createOntologyModel(spec, bModel);
Map<String, String>   prefixMap = new HashMap<String, String>();
prefixMap = aModel.getNsPrefixMap();


Now, with the latest version and in order to support transactions, the code has 
changed to:

Dataset aDataset = TDBFactory.createDataset(repoDir);
Map<String, String>   prefixMap = new HashMap<String, String>();
Model model = dataset.getDefaultModel();
prefixMap = model.getNsPrefixMap();

but it doesn't retrieve all prefixes from the model.

Should I use a different method or API to retrieve the prefixes stored in the 
tdb?


Cheers,
Emilio

Hi there,

There is a problem with the bulkloader (see JIRA JENA-175).

Could you look in the DB directory and see if the prefixes.dat is zero or not?

I tried the code below and (on a disk-backed database) and it printed the 
prefixes:

        Andy


-----------------------------
package dev;

import java.util.Map ;

import org.openjena.atlas.lib.FileOps ;
import org.openjena.riot.SysRIOT ;

import com.hp.hpl.jena.query.Dataset ;
import com.hp.hpl.jena.query.DatasetFactory ;
import com.hp.hpl.jena.query.ReadWrite ;
import com.hp.hpl.jena.shared.PrefixMapping ;
import com.hp.hpl.jena.sparql.core.DatasetGraph ;
import com.hp.hpl.jena.sparql.core.DatasetPrefixStorage ;
import com.hp.hpl.jena.tdb.TDB ;
import com.hp.hpl.jena.tdb.TDBFactory ;
import com.hp.hpl.jena.tdb.store.DatasetGraphTDB ;
import com.hp.hpl.jena.tdb.sys.DatasetControlNone ;
import com.hp.hpl.jena.tdb.sys.SetupTDB ;
import com.hp.hpl.jena.tdb.transaction.DatasetGraphTransaction ;
import com.hp.hpl.jena.util.FileManager ;

public class Jena_TDB_prefixes
{
public static void main(String ... argv)
{
    FileOps.clearDirectory("DB") ;
    SysRIOT.wireIntoJena() ;
    DatasetGraphTransaction dsg = 
(DatasetGraphTransaction)TDBFactory.createDatasetGraph("DB") ;
    Dataset ds = DatasetFactory.create(dsg) ;
    ds.begin(ReadWrite.WRITE) ;
    FileManager.get().readModel(ds.getDefaultModel(), "D.ttl") ;
    ds.commit() ;
    ds.end() ;

    System.out.println("Prefixes (DS):") ;

    DatasetPrefixStorage prefixes = SetupTDB.makePrefixes(dsg.getLocation(), 
new DatasetControlNone()) ;
    for ( String gn : prefixes.graphNames() )
    {
        System.out.println("Graph: "+gn) ;
        PrefixMapping pmap = prefixes.getPrefixMapping(gn) ;
        Map<String, String>  x = pmap.getNsPrefixMap() ;
        for ( String k : x.keySet() )
            System.out.printf("  %-10s %s\n", k+":", x.get(k)) ;
    }


    System.out.println("Prefixes (dft model):") ;
    ds.begin(ReadWrite.READ) ;
    Map<String, String>  mapping = ds.getDefaultModel().getNsPrefixMap() ;
    System.out.println(mapping) ;

    ds.end() ;
}
}

-----------------------------
---- D.ttl
@prefix dc:<http://purl.org/dc/elements/1.1/>  .
@prefix ns:<http://example.org/ns#>  .

@prefix :<http://example.org/book/>  .

:s :p :o .



Reply via email to