以下代碼是讀取模式和數據文件以查找colin和Person的rdf.type。但是,我收到錯誤:使用Jena失敗讀取RDF數據
線程「main」org.apache.jena.riot.RiotException中的異常:[line:1,col:1]在prolog中不允許使用內容。代碼如下:
public void reason(){
String NS = "urn:x-hp:eg/";
String fnameschema = "D://Work//EclipseWorkspace//Jena//data//rdfsDemoSchema.rdf";
String fnameinstance = "D://Work//EclipseWorkspace//Jena//data//rdfsDemoData.rdf";
Model schema = FileManager.get().loadModel(fnameschema);
Model data = FileManager.get().loadModel(fnameinstance);
InfModel infmodel = ModelFactory.createRDFSModel(schema, data);
Resource colin = infmodel.getResource(NS+"colin");
System.out.println("Colin has types");
for (StmtIterator i = infmodel.listStatements(colin, RDF.type, (RDFNode)null); i.hasNext();) {
Statement s = i.nextStatement();
System.out.println(s);
}
Resource Person = infmodel.getResource(NS+"Person");
System.out.println("\nPerson has types:");
for (StmtIterator i = infmodel.listStatements(Person, RDF.type, (RDFNode)null); i.hasNext();) {
Statement s = i.nextStatement();
System.out.println(s);
}
}
文件rdfsDemoData.rdf
@prefix eg: <urn:x-hp:eg/> .
<Teenager rdf:about="⪚colin">
<mum rdf:resource="⪚rosy" />
<age>13</age>
</Teenager>
文件rdfsDemoSchema.rdf
@prefix eg: <urn:x-hp:eg/> .
<rdf:Description rdf:about="⪚mum">
<rdfs:subPropertyOf rdf:resource="⪚parent"/>
</rdf:Description>
<rdf:Description rdf:about="⪚parent">
<rdfs:range rdf:resource="⪚Person"/>
<rdfs:domain rdf:resource="⪚Person"/>
</rdf:Description>
<rdf:Description rdf:about="⪚age">
<rdfs:range rdf:resource="&xsd;integer" />
</rdf:Description>
不清楚爲什麼這個問題已被投票。澄清將有助於未來。 – Bonson