0

I'm new to Jena and the Semantic web.

I'm now making a model having an OntClass "Person" using Jena. This is what I've tried:

OntModel model = ModelFactory.createOntologyModel();
String NS = http://purl.org/ontology#
model.setNsPrefix("Ont", NS);

model.setNsPrefix("foaf", "http://xmlns.com/foaf/0.1#");  
OntClass person = model.createClass(NS + "Person");

person.setSameAs(FOAF.Person);
person.addProperty(FOAF.account, "account");

But it doesn't seem working because when generating the Turtle file, I receive:

Ont:Person  a    owl:Class ;
        owl:sameAs    <http://xmlns.com/foaf/0.1/Person> ;
        <http://xmlns.com/foaf/0.1/account>
                "account" .

instead of having:

@prefix foaf:    <http://xmlns.com/foaf/spec/#> .

Ont:Person  a    owl:Class ;
            owl:sameAs    foaf:Person ;
            foaf:account        "account" .

So what is the right way to link a OntClass in OntModel to a remote namespace ?in this case it's to link my OntClass person to "http://xmlns.com/foaf/0.1#"

Thank you in advance for your help!

4

1 回答 1

1

其实我只需要更换:

model.setNsPrefix("foaf", "http://xmlns.com/foaf/0.1#");  

model.setNsPrefix("foaf", FOAF.getURI());

它有效!

于 2020-07-02T13:48:48.177 回答