如果我有一个符合特定DTD的XML文件,我将如何编写一个可以将该文件转换为OWL 2本体的程序,虽然这不是优先考虑的问题,但OWL 2语法应该是Functional的。我相信我可以使用一些API,例如XPath来转换XML,但是如何创建类呢?
我将创建一个小的本体论示例来尝试解释我的问题。假设存在关于文学的本体论,涉及不同类型的文学和文学实例(例如书籍)。
这是在普通的[[XML中序列化的样子
<Ontology>
<Literature genre = "Fiction">
<title>The Great Gatsby</title>
<author>F. Scott Fitzgerald</author>
</Literature>
<Literature genre = "Poetry">
<title>The Raven</title>
<author>Edgar Allen Poe</author>
</Literature>
</Ontology>
这就是在[[OWL / RDF中表达的样子:
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:books="http://www.books.com/literature#">
<owl:Class rdf:about="http://www.books.com/literature#genre">
<rdfs:label>Literature Genre</rdfs:label>
<rdfs:comment>The class of all literature genres.</rdfs:comment>
</owl:Class>
<owl:Class rdf:about="http://www.books.com/literature#fiction">
<rdfs:subClassOf rdf:resource="http://www.books.com/literature#genre"/>
<rdfs:label>Fictional Literature</rdfs:label>
</owl:Class>
<owl:Class rdf:about="http://www.books.com/literature#poetry">
<rdfs:subClassOf rdf:resource="http://www.books.com/literature#genre"/>
<rdfs:label>Poetry</rdfs:label>
</owl:Class>
<rdf:Description rdf:about="http://www.books.com/literature#The Great Gatsby">
<rdf:type rdf:resource="http://www.books.com/literature#fiction"/>
<dc:title>The Great Gatsby</dc:title>
<dc:author>F. Scott Fitzgerald</dc:author>
</rdf:Description>
<rdf:Description rdf:about="http://www.books.com/literature#The Raven">
<rdf:type rdf:resource="http://www.books.com/literature#poetry"/>
<dc:title>The Raven</dc:title>
<dc:author>Edgar Allen Poe</dc:author>
</rdf:Description>
</rdf:RDF>
我将如何创建一个程序,该程序知道哪些标签应该是类?也许我可以编写一个专门将XML转换为OWL / RDF的程序,但是它将如何与其他XML文件一起使用?也许还可以通过Java API处理DTD来确定哪些标签应该是类等,我将如何创建URI / IRI?非常感谢任何有关将带有DTD的XML转换为OWL 2本体的建议。