0

当我运行“getEquivalentClass()”并且我的等价类是远程的(例如:http://dbpedia.org/data3/Film.rdf 时引发错误:

无法将节点http://dbpedia.org/data3/Film.rdf转换为 OntClass:它没有 rdf:type owl:Class 或等效项

我的代码是:

OntModel m = ModelFactory.createOntologyModel();
    m.read("http://localhost/ontology/my_ontology.owl#Film");
    Resource r = m.getResource(outputs.get(i).getParamType().getURI().toString());
    OntClass filmClass = (OntClass) r.as( OntClass.class );
    for (Iterator j = filmClass.listEquivalentClasses(); j.hasNext(); ) {
        System.out.println(j.next());
    }

电影本体(my_ontology.owl#Film):

<owl:Class rdf:about="#Film">
<rdfs:subClassOf rdf:resource="#Media"/>
<rdfs:subClassOf>
<owl:Restriction>
<owl:minCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger">1</owl:minCardinality>
<owl:onProperty rdf:resource="#Title"/>
</owl:Restriction>
</rdfs:subClassOf>
<owl:equivalentClass rdf:resource="http://dbpedia.org/data3/Film.rdf"/>
</owl:Class>

有可能吗?我浪费了很多时间来寻找这个解决方案。

谢谢你帮助我!

4

1 回答 1

2

Jena 用户列表的Dave Reynolds的回答:

这与资源是否是远程无关,而是本地模型是否知道资源确实是一个类。

最简单的解决方案是设置:

m.setStrictMode(false);

An alternative is to enable inference so the inference can deduce from the fact that it is the object of an owl:equivalentClass assertion that http://dbpedia.org/data3/Film.rdf must be a class. But inference is overkill here.

BTW that's the wrong URI, the dbpedia resource URI for film is actually:

  http://dbpedia.org/ontology/Film
于 2013-03-31T19:04:22.957 回答