2014-05-24 55 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 =“ ..“