1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| OntModel model = ModelFactory.createOntologyModel();
/*Afficher le fichier texte de l'ontologie*/
String inputFileName = "D:\\BaseO\\finale.owl";
// use the FileManager to find the input file
java.io.InputStream in = FileManager.get().open(inputFileName );
if (in == null) {
throw new IllegalArgumentException("File:" + inputFileName + " not found");}
model.read(in, "", "RDF/XML");
model.write(System.out);
/*Afficher les Concepts de l'ontologie*/
OntClass ontClass=null;
Iterator classIter2 = model.listClasses();
while (classIter2.hasNext()) {
ontClass = (OntClass) classIter2.next();
System.out.println("\n class :-------> "+ontClass.getLocalName());
//*********************************************
/*Afficher les propriétés des Concepts de l'ontologie*/
Iterator propIter = ontClass.listDeclaredProperties();
while (propIter.hasNext()) {
OntProperty property = (OntProperty) propIter.next();
/* dom + rng */
String propertyName = property.getLocalName();
String dom = "";
String rng = "";
if(property.getDomain()!=null)
dom = property.getDomain().getLocalName();
if(property.getRange()!=null)
rng = property.getRange().getLocalName();
System.out.println("property: "+ propertyName +"....:("+dom+")--> ("+rng+") ");
}
}
} |
Partager