Reputation: 13
I have a class, MAN
. I want to add an individual, jack
, with properties:
hasage="50"
hasadress="france"
How can I create my individual jack
and add properties to him and save them into my file database.owl
? Here is the connection. I use Eclipse and the Jena API.
JenaOWLModel owlModel ;
OntModel model;
owlModel = ProtegeOWL.createJenaOWLModelFromURI("file:///C:/database.owl");
model = owlModel.getOntModel();
i am begging you to help me , it still fiew days for my thesis defence this CODE work perfectly i can save individuals in my file.owl BUT i couldnt add properties to those individuals and save them with.
please help me what should i do , i am realy worried thanks a lot in advance
public class testins {
static JenaOWLModel owlModel ;
public static void main(String[] args) {
OntModel model;
javax.swing.JDialog jDialog1 = new javax.swing.JDialog();
try{
owlModel = ProtegeOWL.createJenaOWLModelFromURI("file:///D:/file.owl");// the link of my owl file
model = owlModel.getOntModel();
JOptionPane.showMessageDialog(jDialog1,
"loaded with success","Information",JOptionPane.INFORMATION_MESSAGE);
}
catch(Exception e){
JOptionPane.showMessageDialog(jDialog1,
"error",
"Information",
JOptionPane.INFORMATION_MESSAGE);
}
OWLNamedClass theAlert = owlModel.getOWLNamedClass("Alert"); //my class Alert
theAlert.createOWLIndividual("indivname1"); //i add here an indevidual
theAlert.createOWLIndividual("indivname2"); //i add here another indevidual
// now how to add to those two Individuals properties ?? each individual has 2
// properties , the property witch its name est_evaluer and the second est_analyser those
// to properties will contain values so here is my problem how to add those values to an
// individual and save all of them
Collection errors ;
String fileName ;
fileName= ("D:/file.owl");
errors = new ArrayList();
//here i'll save it and it work ,it mean that i find in my file "file.owl"
//individuals i added witch are "indivname1" and "indivname2" in my class ALERT
// so now my problem is how to add properties to those indiviuals i add , and save them also
try{ owlModel.save(new File(fileName).toURI(), FileUtils.langXMLAbbrev, errors);
System.out.println("File saved with " + errors.size() + " errors.");
}
catch(Exception e){
}
}
}
Upvotes: 1
Views: 2148
Reputation: 13305
You didn't say what the namespace you are using is. So I'm going to assume http://example.org/example#
, adjust as necessary.
String NS = "http://example.org/example#";
// create ex:Man class
OntClass man = model.createClass( NS + "Man" );
// create individual ex:jack
Individual jack = model.createIndividual( NS + "jack", man );
// create some properties - probably better to use FOAF here really
DatatypeProperty age = model.createDatatypeProperty( NS + "age" );
DatatypeProperty address = model.createDatatypeProperty( NS + "address" );
jack.addProperty( age, model.createTypedLiteral( 50 ) )
.addProperty( address, model.createLiteral( "France" ) );
Upvotes: 3