For some reason, the classes that I define in an ontology are not being stored 
in TDB. Here's the test class:

package tdb;

import java.util.Iterator;
import com.hp.hpl.jena.ontology.*;
import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.query.ReadWrite;
import com.hp.hpl.jena.rdf.model.*;
import com.hp.hpl.jena.tdb.TDBFactory;

/**
* @author <a href="http://www.ganae.com/edswing";>Edward Swing</a>
*/
public class OntTest {
    protected static String BASE_URI = "http://foo.bar/";;
    protected static String USER_CLASS = BASE_URI + "User";
    protected static String PROJECT_CLASS = BASE_URI + "Project";
    // object property linking project to who checked it out
    protected static String CAN_READ_PROP = BASE_URI + "canRead";
    // object property linking user to a project he can read
    protected static String CAN_EDIT_PROP = BASE_URI + "canEdit";


    public void createRepository() {
        OntModel model = ModelFactory.createOntologyModel();
        OntClass userCls = model.createClass(USER_CLASS);
        OntClass projCls = model.createClass(PROJECT_CLASS);
        // TODO: define a Concept as a union between Class, Thing, and
        // Property
        RDFList clsList = model.createList(new RDFNode[] { userCls, projCls });
        model.createAllDifferent(clsList);
        // now add properties
        ObjectProperty canRead = model.createObjectProperty(CAN_READ_PROP);
        ObjectProperty canEdit = model.createObjectProperty(CAN_EDIT_PROP);
        canRead.setDomain(userCls);
        canEdit.setDomain(userCls);
        canRead.setRange(projCls);
        canEdit.setRange(projCls);
        // now write the model into the store
        Dataset dataset = TDBFactory.createDataset("tdb/data");
        dataset.begin(ReadWrite.WRITE);
        Model meta = dataset.getNamedModel("metadata");
        meta.setNsPrefix("", BASE_URI);
        meta.add(model);
        dataset.commit();
        dataset.end();
    }


    public void listOntClasses() {
        Dataset dataset = TDBFactory.createDataset("tdb/data");
        dataset.begin(ReadWrite.READ);
        Model model = dataset.getNamedModel("metadata");
        System.out.println("ModelURI:" + model.getNsPrefixURI(""));
        OntModel ontModel =
            ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF);
        // copy the model into the in-memory ontology model
        ontModel.add(model);
        ontModel.setNsPrefixes(model);
        dataset.end();
        System.out.println("OntModel:" + ontModel.getNsPrefixURI(""));
        for (Iterator<OntClass> clsIter = ontModel.listClasses(); clsIter
            .hasNext();) {
            OntClass cls = clsIter.next();
            System.out.println("CLS: " + cls.getLocalName());
        }
    }

    public static void main(String[] args) {
        OntTest nsTest = new OntTest();
        nsTest.createRepository();
        nsTest.listOntClasses();
    }

The results of the print do not contain the User or Project classes. Any help 
would be appreciated.

Edward Swing
Applied Research Technologist
Vision Systems + Technology, Inc., a SAS Company
6021 University Boulevard * Suite 360 * Ellicott City * Maryland * 21043
Tel: 410.418.5555 Ext: 919 * Fax: 410.418.8580
Email: [email protected]<mailto:[email protected]>
Web: http://www.vsticorp.com<http://www.vsticorp.com/>

Reply via email to