我正在尝试使用Jena阅读本体论。我在代码中显示的正确目录中有一个文件Pizza.owl,但我仍然收到一个错误,即找不到该文件。
public static void ReadOntology(){
OntModel onto = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null);
String inputFileName = "C:\\Users\\najib\\studies\\pizza.owl";
try {
Logger logger = Logger.getLogger(Operations.class);
PropertyConfigurator.configure("C://Users//najib//Downloads//apache-jena-2.12.0//jena-log4j.properties");
//create the reasoning model using the base
OntModel model = ModelFactory.createOntologyModel();
// use the FileManager to find the input file
InputStream in = FileManager.get().open(inputFileName);
if (in == null) {
throw new IllegalArgumentException("File: " + inputFileName + " not found");
}
model.read(in, "");
//to list classes
ExtendedIterator<OntClass> classes = model.listClasses();
while (classes.hasNext()) {
OntClass cls = (OntClass) classes.next();
System.out.println("Classes: " + cls.getLocalName());
for (ExtendedIterator<OntClass> i = cls.listSubClasses(true); i.hasNext();) {
OntClass c = (OntClass) i.next();
System.out.print(" " + c.getLocalName() + "\n");
} // end for
}
} catch (Exception e) {
System.out.println(e);
}
}
}
我收到以下错误:java.lang.IllegalArgumentException: File: C:\Users\najib\studies\pizza.owl not found
答案 0 :(得分:0)
当我阅读FileManager
的javadoc
时,我发现您必须在文件参数前加上"file:"
所以(没有测试这个答案)我建议尝试:
String inputFileName = "file:/C:/Users/najib/studies/pizza.owl";