Jena getNsPrefixUri 返回 null(如何为 OWL 本体定义基本 URI?)
Jena getNsPrefixUri returning null (how to define base URI for OWL ontologies?)
我正在尝试使用 Jena 和以下方法创建一个个体(实例):
public void createInstance(String name) {
String NS = ontology.getNsPrefixURI("http://james.miranda.br/Onto");
OntClass class = ontology.createClass(NS + "Requisito");
Individual instance = class.createIndividual(NS + name);
System.out.println("Instance created:" + instance.getURI());
}
ontology
是基于 this ontology 的 OntModel 实例(一些术语是葡萄牙语)。此方法无效,因为 getNsPrefixURI
返回 null。
当我使用下面的代码遍历 类 时:
ExtendedIterator<OntClass> classIterator = ontology.listClasses();
while (classIterator.hasNext()) {
OntClass ontClass = classIterator.next();
System.out.println(ontClass.toString());
}
(部分)结果是:
http://james.miranda.br/Onto#Requisito
http://james.miranda.br/Onto#Micro
http://james.miranda.br/Onto#Certo
使用 getNsPrefixURI("")
我有 NS http://www.w3.org/2002/07/owl
但我的方法也不起作用。我一直在寻找如何在 SO 中定义基本 uri,但 solution 在我的情况下不起作用。
为了获取所有命名空间,我使用了代码:
Map<String,String> list = ontology.getNsPrefixMap();
System.out.println(list.toString());
结果是:{=http://www.w3.org/2002/07/owl#, xsd=http://www.w3.org/2001/XMLSchema#, rdfs=http://www.w3.org/2000/01/rdf-schema#, owl=http://www.w3.org/2002/07/owl#, rdf=http://www.w3.org/1999/02/22-rdf-syntax-ns#}
.
我没有收到“http://james.miranda.br/Onto”的前缀。是否应该在任何地方声明?
我的代码有什么问题吗?
getNsPrefixURI
的文档说 "Get the URI bound to a specific prefix, null if there isn't one." 即前缀输入,URI 输出。
"http://james.miranda.br/Onto" 不是合法的前缀。
http://james.miranda.br/Onto没有名称空间前缀。
这不设置前缀:
<Ontology rdf:about="http://james.miranda.br/Onto">
我们希望看到:
xmlns:onto="http://james.miranda.br/Onto#"
我正在尝试使用 Jena 和以下方法创建一个个体(实例):
public void createInstance(String name) {
String NS = ontology.getNsPrefixURI("http://james.miranda.br/Onto");
OntClass class = ontology.createClass(NS + "Requisito");
Individual instance = class.createIndividual(NS + name);
System.out.println("Instance created:" + instance.getURI());
}
ontology
是基于 this ontology 的 OntModel 实例(一些术语是葡萄牙语)。此方法无效,因为 getNsPrefixURI
返回 null。
当我使用下面的代码遍历 类 时:
ExtendedIterator<OntClass> classIterator = ontology.listClasses();
while (classIterator.hasNext()) {
OntClass ontClass = classIterator.next();
System.out.println(ontClass.toString());
}
(部分)结果是:
http://james.miranda.br/Onto#Requisito
http://james.miranda.br/Onto#Micro
http://james.miranda.br/Onto#Certo
使用 getNsPrefixURI("")
我有 NS http://www.w3.org/2002/07/owl
但我的方法也不起作用。我一直在寻找如何在 SO 中定义基本 uri,但 solution 在我的情况下不起作用。
为了获取所有命名空间,我使用了代码:
Map<String,String> list = ontology.getNsPrefixMap();
System.out.println(list.toString());
结果是:{=http://www.w3.org/2002/07/owl#, xsd=http://www.w3.org/2001/XMLSchema#, rdfs=http://www.w3.org/2000/01/rdf-schema#, owl=http://www.w3.org/2002/07/owl#, rdf=http://www.w3.org/1999/02/22-rdf-syntax-ns#}
.
我没有收到“http://james.miranda.br/Onto”的前缀。是否应该在任何地方声明?
我的代码有什么问题吗?
getNsPrefixURI
的文档说 "Get the URI bound to a specific prefix, null if there isn't one." 即前缀输入,URI 输出。
"http://james.miranda.br/Onto" 不是合法的前缀。
http://james.miranda.br/Onto没有名称空间前缀。
这不设置前缀:
<Ontology rdf:about="http://james.miranda.br/Onto">
我们希望看到:
xmlns:onto="http://james.miranda.br/Onto#"