我想知道是否有可能通过这样的表达式:
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>)))) )
animal
and (eats only (not (animal)))
and (eats only (not (part_of some animal)))
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);
}
}
输入表达式是函数语法的,不幸的是,这种格式的解析器需要一个完整的本体作为输入,而不仅仅是一个公理。您可以通过用本体头包装字符串并将其输出为曼彻斯特语法格式来获得您想要的部分效果:
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)))
有没有办法将OWL公理转换成曼彻斯特语法?我知道OWL-API将允许您将曼彻斯特语法中的一个句子解析为OWL函数语法,但我需要做的正好相反。
我正在用Java编写一个利用OWL API 3.1.0版的程序。我有一个表示一个使用曼彻斯特OWL语法的公理,我想在对象中转换这个字符串,因为我需要使用方法(它是的方法)将结果公理添加到一个本体中。我怎么能那样做?
问题内容: 考虑以下示例代码 在这里,价值和是完全相同且等于 ,所以, 两者之间到底有什么区别? 哪一个效率更高?为什么? 传播语法的确切用途是什么? 您是否不认为以正式的广泛语言引入这些小捷径可能会留下一些未被注意的错误,我的意思是要么根本没有必要,要么我没有意识到确实需要这样做。 问题答案: 在给出的示例中,两者之间基本上没有区别 是显著更有效:http://jsperf.com/spread
我知道Bellman-Ford算法最多需要| V |-1次迭代才能找到最短路径,如果图不包含负权重循环。有没有办法修改Bellman-Ford算法,使其在1次迭代中找到最短路径?
我正在尝试使用Stanford OWL API,但我发现文档有点不清楚。使用Java,我通过Protégé加载一个用户准备好的本体,得到一个。该属性的值是本体论中某个类中的个体。我怎么才能找到班级?下面的代码段: 我想获得的类。