简体   繁体   中英

Jena Ontology API: Add property values for individual through Anonymous classes

For following model

在此处输入图片说明

i need to create individuals for class1 and set literal values for property4 and property5 for created individuals. For this i am creating individual for Anonymous class2(in1) and setting property values for it. Then i create individual for Anonymous class1(in0) and use addproperty(property2,in1), again i create individual for class 1(in) and use addproperty(property1,in0).

    String ns = "url.com";
    OntModel model =  ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM);
    OntClass class1 = model.createClass(ns+"class1");
    OntClass Aclass1= model.createClass();
    OntClass Aclass2= model.createClass();

    OntProperty pro1 = model.createOntProperty(ns + "pro1");
    OntProperty pro2 = model.createOntProperty(ns + "pro2");
    OntProperty pro3 = model.createOntProperty(ns + "pro3");

    DatatypeProperty pro4 = model.createDatatypeProperty(ns + "pro4");
    DatatypeProperty pro5 = model.createDatatypeProperty(ns + "pro5");

    Individual in1 = Aclass2.createIndividual(ns + "in1");
    in1.addProperty( pro4, model.createTypedLiteral( 50 ) )
    .addProperty( pro5, model.createTypedLiteral( 60) );

    Individual in0=Aclass1.createIndividual(ns+"in2");
    in0.addProperty(pro2,in1);

    Individual in=class1.createIndividual(ns+"indi");
    in.addProperty(pro1, in0);

this is giving following exception when run

Exception in thread "main" com.hp.hpl.jena.ontology.ProfileException: Attempted to use language construct DATATYPE_PROPERTY that is not supported in the current language profile: RDFS
at com.hp.hpl.jena.ontology.impl.OntModelImpl.checkProfileEntry(OntModelImpl.java:3058)
at com.hp.hpl.jena.ontology.impl.OntModelImpl.createDatatypeProperty(OntModelImpl.java:1395)
at com.hp.hpl.jena.ontology.impl.OntModelImpl.createDatatypeProperty(OntModelImpl.java:1375)
at test1.Hello.main(Hello.java:46)

What am i doing wrong and is there a better way for doing this?

The spec is wrong, it does not support owl:DatatypeProperty (and a lot of things from OntModel), but only RDFS vocabulary.

Try OntModelSpec.OWL_DL_MEM. It should eliminate exception.

But note: OntModelSpec#OWL_DL_MEM is about OWL1-DL, not OWL2DL. Jena does not support OWL2 at all.

If you want to use full OWL2DL specification with Jena, you can take a look on ONT-API , which is jena-based OWL-API.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM