2014-05-24 56 views
1

我有一個局部本體與幾類,如User錯誤的命名空間:耶拿表示本體類

<rdf:RDF 
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#" 
    xmlns:foaf="http://xmlns.com/foaf/0.1/" 
    xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" 
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
    xmlns:domain="http://www.somedomain.com/data/#"> 

    <rdfs:Class rdf:ID="User"> 
     <rdfs:subClassOf rdf:resource="http://xmlns.com/foaf/0.1/Agent" /> 
     <rdfs:comment> 
      The class of users. 
     </rdfs:comment> 
    </rdfs:Class> 

</rdf:RDF> 

如果我嘗試打印這樣所有的類:

/* Lists all classes */ 
ExtendedIterator<OntClass> classIterator = model.listClasses(); 
while (classIterator.hasNext()) { 
    OntClass ontClass = classIterator.next(); 
    System.out.println(ontClass.toString()); 
} 

我得到他們與本地路徑:

file:///home/myusername/#User 

相反的

http://www.somedomain.com/data/#User 

這是很煩人的,因爲我在耶拿的命名空間,因此是file:///home/myusername/#,我不相信這是正確的。我究竟做錯了什麼?

+1

您正在使用相對URI,它們正在根據文件的路徑名得到解決。這與[Jena模型中的RDF資源的URI]中描述的問題相同(http://stackoverflow.com/questions/22657447/uri-of-an-rdf-resource-in-jena-model)。 –

回答

1
<rdfs:Class rdf:ID="User"> 

表示針對基本URI解析「User」,即file:/// home/myusername /。這是對的。

要麼將​​base URI設置爲您在model.read操作中需要的值,要麼給出URI:一個有用的XML實體:定義實體並在rdf:ID =「..」和xmlns:domain =「 ..「