我有我的班级Alert
,其中包含个人
Alert_1
Alert_2
Alert_3
并且每个人都有属性,例如包含值
Alert_1 :
hasanalyser : analyser546
hastime: 10
hasdatainfo: difficult
我现在可以获取所有个人,但无法获取那些 (hasanalyser
和hastime
)hasdatainfo
值
这是我的代码,它可以工作。请问我怎样才能得到我想要的?
owlModel = ProtegeOWL.createJenaOWLModelFromURI("file:///D:/base_connaissance.owl");
OntModel model = owlModel.getOntModel();
OWLNamedClass theAlert = owlModel.getOWLNamedClass("Alert");
Collection CAlerte = theAlert.getInstances();
int nombreAlerte =CAlerte.size();
String[ ] list_alerte=new String[ nombreAlerte ];
OWLIndividual[ ] idorg=(OWLIndividual[ ]) CAlerte.toArray(new OWLIndividual[ 0 ]);
for(int j=0;j< nombreAlerte;j++){
list_alerte[ j ]=idorg[ j ].getName();
}
System.out.println(" le nombres des alerte est:"+nombreAlerte);
OntModel inf1 = ModelFactory.createOntologyModel();
for(int k=0;k< nombreAlerte;k++){
System.out.println(" \n"+list_alerte[k]);
}
在这里它显示我的
Alert_1
Alert_2
Alert_3
如何获得它们的属性?
更新:
感谢您的回答,它还没有工作。我现在试着像你说的那样做
JenaOWLModel owlModel = ProtegeOWL.createJenaOWLModelFromURI("file:///D:/base_connaissance.owl");
OntModel model = owlModel.getOntModel();
ArrayList<Resource> results = new ArrayList<Resource>();
ExtendedIterator individuals = model.listIndividuals();
while (individuals.hasNext()) {
Resource individual = (Resource) individuals.next();
results.add(individual);
}
for(int i = 0; i < results.size(); i++)
{
System.out.println("individual number " + i + " = " + results.get(i));//here it display my individual
Individual ind = model.getIndividual(results.get(i).toString());
Property hasTime = model.createProperty( "file:///D:/base_connaissance.owl#hasanalyser" );
RDFNode time = ind.getPropertyValue( hasTime );
System.out.println("property value of hasanalyser "+time);
最后,它显示我个人的所有姓名,并在每个人之后显示属性值hasanalyser NULL
。
请问哪里有问题