我想知道是否可以从这样的表达式中传递信息:
EquivalentClasses(<http://owl.man.ac.uk/2006/07/sssw/people#vegetarian> ObjectIntersectionOf(<http://owl.man.ac.uk/2006/07/sssw/people#animal> ObjectAllValuesFrom(<http://owl.man.ac.uk/2006/07/sssw/people#eats> ObjectComplementOf(<http://owl.man.ac.uk/2006/07/sssw/people#animal>)) ObjectAllValuesFrom(<http://owl.man.ac.uk/2006/07/sssw/people#eats> ObjectComplementOf(ObjectSomeValuesFrom(<http://owl.man.ac.uk/2006/07/sssw/people#part_of> <http://owl.man.ac.uk/2006/07/sssw/people#animal>)))) )
对于这种类型的表达式,这里的问题不是缩短IRI,这里的问题是使用OWLAPI将其翻译为“ and,only ...”:
animal
and (eats only (not (animal)))
and (eats only (not (part_of some animal)))
我使用的本体是http://owl.man.ac.uk/2006/07/sssw/people.owl,获得表达式的方法是这样(在这种情况下,等同于素食主义者):
public static void getEquivalentClasses2() throws OWLOntologyCreationException {
IRI iri = IRI.create("http://owl.man.ac.uk/2006/07/sssw/people.owl");
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology ont = manager.loadOntologyFromOntologyDocument(iri);
System.out.println("Loaded " + ont.getOntologyID());
//OWLReasonerFactory reasonerFactory = new Reasoner.ReasonerFactory();
OWLReasonerFactory reasonerFactory = new StructuralReasonerFactory();
//OWLReasonerFactory reasonerFactory = PelletReasonerFactory.getInstance();
//OWLReasoner reasoner = reasonerFactory.createReasoner(ont, new SimpleConfiguration());
ConsoleProgressMonitor progressMonitor = new ConsoleProgressMonitor();
OWLReasonerConfiguration config = new SimpleConfiguration(progressMonitor);
OWLReasoner reasoner = reasonerFactory.createReasoner(ont, config);
Set<OWLEquivalentClassesAxiom> setEquivalentes = null;
OWLDataFactory fac = manager.getOWLDataFactory();
OWLClass expr = fac.getOWLClass(IRI.create("http://owl.man.ac.uk/2006/07/sssw/people#vegetarian"));
setEquivalentes = ont.getEquivalentClassesAxioms(expr);
String equi = "";
for(OWLEquivalentClassesAxiom e : setEquivalentes)
{
System.out.println(e);
}
}
答案 0 :(得分:0)
输入表达式以函数语法表示,不幸的是,这种格式的解析器希望将完整的本体作为输入,而不仅仅是一个公理。您可以通过使用本体头将字符串包装并输出为曼彻斯特语法格式来获得所需效果的一部分:
String axiom =
"EquivalentClasses(<http://owl.man.ac.uk/2006/07/sssw/people#vegetarian> ObjectIntersectionOf(<http://owl.man.ac.uk/2006/07/sssw/people#animal> ObjectAllValuesFrom(<http://owl.man.ac.uk/2006/07/sssw/people#eats> ObjectComplementOf(<http://owl.man.ac.uk/2006/07/sssw/people#animal>)) ObjectAllValuesFrom(<http://owl.man.ac.uk/2006/07/sssw/people#eats> ObjectComplementOf(ObjectSomeValuesFrom(<http://owl.man.ac.uk/2006/07/sssw/people#part_of> <http://owl.man.ac.uk/2006/07/sssw/people#animal>)))) )";
String ontology = "Prefix(xsd:=<http://www.w3.org/2001/XMLSchema#>)\n"
+ "Prefix(owl:=<http://www.w3.org/2002/07/owl#>)\n"
+ "Prefix(xml:=<http://www.w3.org/XML/1998/namespace>)\n"
+ "Prefix(rdf:=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>)\n"
+ "Prefix(rdfs:=<http://www.w3.org/2000/01/rdf-schema#>)\n"
+ "Prefix(:=<http://owl.man.ac.uk/2006/07/sssw/people#>)\n"
+ "Ontology(<file:test.owl>\n" + axiom + "\n)";
OWLOntology o = OWLManager.createOWLOntologyManager()
.loadOntologyFromOntologyDocument(new StringDocumentSource(ontology));
StringDocumentTarget documentTarget = new StringDocumentTarget();
ManchesterSyntaxDocumentFormat ontologyFormat = new ManchesterSyntaxDocumentFormat();
ontologyFormat.asPrefixOWLDocumentFormat()
.copyPrefixesFrom(o.getFormat().asPrefixOWLDocumentFormat());
o.saveOntology(ontologyFormat, documentTarget);
System.out.println(documentTarget.toString());
输出为:
Prefix: : <http://owl.man.ac.uk/2006/07/sssw/people#>
Prefix: owl: <http://www.w3.org/2002/07/owl#>
Prefix: rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
Prefix: rdfs: <http://www.w3.org/2000/01/rdf-schema#>
Prefix: xml: <http://www.w3.org/XML/1998/namespace>
Prefix: xsd: <http://www.w3.org/2001/XMLSchema#>
Ontology: <file:test.owl>
ObjectProperty: eats
ObjectProperty: part_of
Class: animal
Class: vegetarian
EquivalentTo:
animal
and (eats only (not (animal)))
and (eats only (not (part_of some animal)))
答案 1 :(得分:0)
对我有用的解决方案是使用ManchesterOWLSyntaxOWLObjectRendererImpl类及其方法render()将表达式转换为曼彻斯特语法。进行更改以解决问题后,方法保持如下:
public static void getEquivalentClasses2() throws OWLOntologyCreationException {
IRI iri = IRI.create("http://owl.man.ac.uk/2006/07/sssw/people.owl");
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology ont = manager.loadOntologyFromOntologyDocument(iri);
System.out.println("Loaded " + ont.getOntologyID());
Set<OWLEquivalentClassesAxiom> setEquivalentes = null;
OWLDataFactory fac = manager.getOWLDataFactory();
OWLClass expr = fac.getOWLClass(IRI.create("http://owl.man.ac.uk/2006/07/sssw/people#vegetarian"));
setEquivalentes = ont.getEquivalentClassesAxioms(expr);
ManchesterOWLSyntaxOWLObjectRendererImpl rend = new ManchesterOWLSyntaxOWLObjectRendererImpl();
for(OWLEquivalentClassesAxiom e : setEquivalentes)
{
System.out.println(rend.render(e));
}
}