我正在使用APACHE Jena ONT模型来解析RDF / XML OWL文件并对其进行处理。使用当前的ONT模型,ONT模型中无法识别 owl:maxQualifiedCardinality 和 owl:minQualifiedCardinality 的限制。我还查看了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>
答案 0 :(得分:0)
Apache Jena本体API(OntModel)不支持OWL2 DL。 您可以查看基于耶拿的替代方案(即ONT-API)。这是OWL-2特有的另一个jena接口,包括owl:maxQualifiedCardinality
等示例:
OntGraphModel model = OntModelFactory.createModel();
model.setID("http://test");
OntNOP property = model.createOntEntity(OntNOP.class, "http://test#hasUnit");
OntClass clazz = model.createOntEntity(OntClass.class, "http://test#Numeric");
clazz.addLabel("Numeric", null);
clazz.addSubClassOf(model.createOntEntity(OntClass.class, "http://test#Characteristic"));
clazz.addSubClassOf(model.createObjectMaxCardinality(property, 1,
model.createOntEntity(OntClass.class, "http://test#Scale")));
StringWriter sw = new StringWriter();
model.write(sw, "rdf/xml");
System.out.println(sw);
// another way to create OntGraphModel:
InputStream in = new ByteArrayInputStream(sw.toString().getBytes(StandardCharsets.UTF_8));
OntGraphModel reloaded = OntManagers.createONT().loadOntologyFromOntologyDocument(in).asGraphModel();
int cardinality = reloaded.ontObjects(OntCE.ObjectMaxCardinality.class)
.mapToInt(OntCE.Cardinality::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-Ontology-API,你可以将图形传递回OntModel界面:
OntModel jena = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM, reloaded);
jena.write(System.out, "rdf/xml");