public class List_subPropertyOf {
//static final String inputFileName = "data/dbpedia_3.9.owl";
//static final String inputFileName = "data/wnfull.rdfs";
static final String inputFileName = "data/lov.rdf";
public static void main(String args[]) {
try {
//create the reasoning model using the base
OntModel inf = ModelFactory.createOntologyModel();
// use the FileManager to find the input file
InputStream in = FileManager.get().open(inputFileName);
File logFile = new File("List_subPropertyOf.txt");
PrintStream logPrintStream = new PrintStream(logFile);
System.setOut(logPrintStream);
if (in == null) {
throw new IllegalArgumentException("File: " + inputFileName + " not found");
}
inf.read(in, "", "RDF/XML");
ExtendedIterator properties = inf.listOntProperties();
while (properties.hasNext()) {
OntProperty essaProperty = (OntProperty) properties.next();
System.out.println("Property: " + essaProperty.getLocalName());
for (Iterator i = essaProperty.listSubProperties(); i.hasNext();) {
OntProperty c = (OntProperty) i.next();
System.out.print(" " + c.getLocalName() + "\n");
} // end for
}
} catch (Exception e) {
System.out.println(e);
}
}
例外: 请看图片。 我该怎么办?我没有足够的声誉来发布图片。我不能发布超过2个链接的例外,但我的例外有......
16:55:37 WARN OntDocumentManager ::尝试从http://www.ontotext.com/proton/protontop读取时发生错误。 Msg是'org.xml.sax.SAXParseException:prolog中不允许使用内容。'。 com.hp.hpl.jena.shared.JenaException:org.xml.sax.SAXParseException:prolog中不允许使用内容。
答案 0 :(得分:1)
什么指的是http://www.ontotext.com/proton/protontop?是data / lov.rdf吗?
如果您使用的是旧版本的Jena,它会要求提供RDF / XML,但该URL会返回Turtle,无论您要求哪个都没有处理。较新的版本改变了这一点。
否则,样本数据和完整堆栈跟踪会有所帮助。