我使用APACHE ONT模型解析RDF/XML OWL文件并处理它们。对于当前的ONT模型,使用owl:maxQualifiedCardinality和owl:minQualifiedCardinality的限制在ONT模型中是不被识别的。我还查看了org.apache.jena.ontology包的限制接口,发现这些限制不受支持,相反,owl:minCardinality和owl:maxCardinality是受支持的。我想知道Jena ONT模型是否也可以考虑这些限制: owl:maxQualifiedCardinality,owl:minQualifiedCardinality
如果你能告诉我你的经历,我会很高兴的。使用Jena ont模型处理这些限制并处理它们的数据
<owl:Class rdf:about="http://test#Numeric">
<rdfs:subClassOf rdf:resource="http://test#Characteristic"/>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="http://test#hasUnit"/>
<owl:maxQualifiedCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger">1</owl:maxQualifiedCardinality>
<owl:onClass rdf:resource="http://test#Scale"/>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:label>Numeric</rdfs:label>
</owl:Class>发布于 2018-02-08 11:35:28
Apache本体API (org.apache.jena.ontology.OntModel)不支持OWL2 DL。您可以看看基于耶拿的替代方案(即ONT-API)。这是OWL-2的另一个专门的jena接口,它支持诸如owl:maxQualifiedCardinality这样的东西。
示例:
OntModel m = OntModelFactory.createModel();
m.setID("http://test");
OntObjectProperty property = m.createObjectProperty("http://test#hasUnit");
OntClass clazz = m.createOntClass("http://test#Numeric");
clazz.addLabel("Numeric", null);
clazz.addSuperClass(m.createOntClass("http://test#Characteristic"))
.addSuperClass(m.createObjectMaxCardinality(property, 1,
m.createOntClass("http://test#Scale")));
StringWriter sw = new StringWriter();
m.write(sw, "rdf/xml");
System.out.println(sw);
// another way to create OntGraphModel:
InputStream in = new ByteArrayInputStream(sw.toString().getBytes(StandardCharsets.UTF_8));
OntModel reloaded = OntManagers.createONT().loadOntologyFromOntologyDocument(in).asGraphModel();
int cardinality = reloaded.ontObjects(OntClass.ObjectMaxCardinality.class)
.mapToInt(OntClass.CardinalityRestrictionCE::getCardinality)
.findFirst().orElseThrow(IllegalStateException::new);
System.out.println(cardinality);产出:
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<owl:Ontology rdf:about="http://test"/>
<owl:Class rdf:about="http://test#Characteristic"/>
<owl:Class rdf:about="http://test#Scale"/>
<owl:Class rdf:about="http://test#Numeric">
<rdfs:subClassOf>
<owl:Restriction>
<owl:onClass rdf:resource="http://test#Scale"/>
<owl:maxQualifiedCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger"
>1</owl:maxQualifiedCardinality>
<owl:onProperty>
<owl:ObjectProperty rdf:about="http://test#hasUnit"/>
</owl:onProperty>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf rdf:resource="http://test#Characteristic"/>
<rdfs:label>Numeric</rdfs:label>
</owl:Class>
</rdf:RDF>
1如果您认为原始的Jena本体API更方便,则可以将图形传递回org.apache.jena.ontology.OntModel接口:
OntModel jena = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM, reloaded);
jena.write(System.out, "rdf/xml");https://stackoverflow.com/questions/48684076
复制相似问题