use*_*321 0 rdf semantic-web owl jena
我从网上下载了一个OWL文件,我需要知道它是如何使用Jena编写的.我可以编写简单的RDF文档,但是我无法理解编写OWL文档.OWL文件内容如下.
<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/">
<!-- OWL Header Example -->
<owl:Ontology rdf:about="http://www.linkeddatatools.com/plants">
<dc:title>The LinkedDataTools.com Example Plant Ontology</dc:title>
<dc:description>An example ontology written for the LinkedDataTools.com RDFS & OWL introduction tutorial</dc:description>
</owl:Ontology>
<!-- OWL Class Definition Example -->
<owl:Class rdf:about="http://www.linkeddatatools.com/plants#planttype">
<rdfs:label>The plant type</rdfs:label>
<rdfs:comment>The class of plant types.</rdfs:comment>
<rdfs:description> Plant type description </rdfs:description>
</owl:Class>
</rdf:RDF>
Run Code Online (Sandbox Code Playgroud)
没有区别.在RDF中编码的OWL本体只是另一个RDF文档 - 就Jena而言,OWL语法没有什么特别之处.在RDF文档中重要的是它包含的三倍:这就是为什么你可以用XML,Turtle或N-triples编码RDF,它们都是等价的 - 只是写下相同三元组的不同方式.
一旦RDF工具将三元组加载到图形中(即Model在Jena中),它就可以对owl:命名空间中的术语进行不同的解释.
更新
好的,这里的评论中的以下请求是生成输出样本的代码:
package example;
import com.hp.hpl.jena.ontology.*;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.vocabulary.*;
public class OWLOutputExample
{
public static final String PLANTS = "http://www.linkeddatatools.com/plants";
public static void main( String[] args ) {
new OWLOutputExample().run();
}
public void run() {
OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM );
setNamespaces( m );
populateOntology( m );
writeOntology( m );
}
private void setNamespaces( OntModel m ) {
m.setNsPrefix( "owl", OWL.getURI() );
m.setNsPrefix( "rdf", RDF.getURI() );
m.setNsPrefix( "rdfs", RDFS.getURI() );
m.setNsPrefix( "dc", DC_11.getURI() );
m.setNsPrefix( "plants", PLANTS );
}
private void populateOntology( OntModel m ) {
Ontology ont = m.createOntology( PLANTS );
ont.addProperty( DC_11.title, "The LinkedDataTools.com Example Plant Ontology" )
.addProperty( DC_11.description, "An example ontology written for the " +
"LinkedDataTools.com RDFS & OWL introduction tutorial" );
OntClass plantType = m.createClass( PLANTS + "#planttype" );
plantType.addProperty( RDFS.label, "The plant type" )
.addProperty( RDFS.comment, "The class of plant types." );
}
private void writeOntology( OntModel m ) {
m.write( System.out, "RDF/XML-ABBREV" );
}
}
Run Code Online (Sandbox Code Playgroud)
输出:
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:plants="http://www.linkeddatatools.com/plants"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<owl:Ontology rdf:about="http://www.linkeddatatools.com/plants">
<dc:description>An example ontology written for the LinkedDataTools.com RDFS & OWL introduction tutorial</dc:description>
<dc:title>The LinkedDataTools.com Example Plant Ontology</dc:title>
</owl:Ontology>
<owl:Class rdf:about="http://www.linkeddatatools.com/plants#planttype">
<rdfs:comment>The class of plant types.</rdfs:comment>
<rdfs:label>The plant type</rdfs:label>
</owl:Class>
</rdf:RDF>
Run Code Online (Sandbox Code Playgroud)
请注意,这rdfs:description不是已知的RDFS属性,因此我将其删除.
| 归档时间: |
|
| 查看次数: |
844 次 |
| 最近记录: |