我尝试编写一个代码,用于从owl文件中打印所需的内容。这是我的代码:
public String execute()
{
OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM );
// get an OntClass reference to one of the classes in the model
// note: ideally, we would delegate this step to Jena's schemagen tool
InputStream in = null;
try {
in = new FileInputStream("C:/OOAD-Softwares/workspace4/SemWeb/build/src/main/resources/semrailwaysv2.owl");
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} // or any windows path
m.read(in, null);
OntClass ontclass = m.getOntClass(SOURCE_URL+"#RailwayStation");
ExtendedIterator iterator = ontclass.listInstances();
while(iterator.hasNext())
{
Object obj = iterator.next();
System.out.println("Object : "+obj.toString());
}
try {
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return SUCCESS;
}
这里我可以通过直接使用listInstances()方法作为迭代器而不分配来从我的owl文件中获取所需类的实例数,但是我无法获取每个实例的各种属性值。我该怎么办呢?此外,如果我使用参数化版本的ExtendedIterator,
ExtendedIterator<OntClass> it = ontclass.listInstances();
发出错误说
The type ExtendedIterator is not generic; it cannot be parameterized with arguments <OntClass>
我该怎么办?
我已经更新了代码,但问题仍然存在。