用Jena对owl本体片断进行解析

  最近,一直在学习本体可视化的方面的知识,现在本体描述语言主要是owl和rdfs两种,本体可视化就是对owl和rdfs本体片断用解析工具(jena)进行解析,然后用prefuse或touchgraph等工具进行呈现。这些工具都是基于java实现,所以我们的开发工具是eclipse.

我们选用的例子的是 河南师范大学 计算机与信息技术学院的 王岁花,张晓丹,王越 发表在 河南师范大学学报(自然科学版)第40卷 第2期上的一篇命为“基于关系数据库的OWL本体存储及查询方法”为内容,进行可视化。

用prefuse对owl本体片断进行可视化,可分为两步进行

 

一.用Jena对owl本体片断进行解析,存入数据库

此例子是由别人完成,我是只是经她同意后整理发表

OWL提供了许多描述类、属性、个体的词汇,以及丰富的公理,不仅能准确描述知识中的类、属性、个体,还能对它们之间的关系进行精确描述,为知识的推理做了良好的准备.本文通过细致考虑OWL的构词,对其中的OWL属性特征和属性约束等关键存储问题进行了重点研究,保证了OWL本体存储到关系数据库后语义信息的完整性,从而解决了资源之间的复杂关系问题.

1.1构词和公理

① OWL类的构词有6种:简单类(class),枚举类(one of),属性约束类(values of),交集类(intersection of),并集类(union of),补集类(complement of).

② 描述类公理的构词有4种:类存在,子关系公理(subclass of),等价关系公理(equivalentclass),互斥关系公理(disjoint with)

③ 描述OWL属性的构词有2种:对象属性(op,object property)和数据类型属性(dp,data property).对象属性是将主体所属类(owl:domain,定义域)的个体和客体所属类(range,值域)的个体联系起来.数据类型属性是将主体所属类的个体和客体的数据值联系起来.

④ 描述OWL属性特征的构词有6种:等价属性(equivalent  property),逆属性(inverse of),传递属性(transitive property),对称属性(symmetric property),函数型属性(functional property),反函数型属性(inversefunctional property)

⑤ 描述OWL属性值约束的构词有3种:所有值约束(allvalues from),部分值约束(somevalues),属性值(hasvalue),这些约束构词用来约束属性的值域.

⑥ 描述OWL属性基数约束的构词有3种:最小基数(mincardinality),最大基数(maxcardinality),完全基数(cardinality),这些约束构词用来约束属性取值的数量.

⑦ 描述OWL实例约束的构词有3种:sameas,different from,alldiferent.

1.2 OWL本体关系数据库的构建

从OWL本体中分离类、属性、属性特征、属性约束和实例,建立相应的关系数数据库表。

①类表  类(类URI,类名,描述类型,描述值)主键:{类URI}

②属性表  属性(属性URI,属性名,属性类型,定义域,值域) 主键:{属性URI}

属性类型字段表明该属性是对象属性(OP)还是数据类型属性(DP)。

③属性特征表  属性特征(属性URI,属性名,特征类型,特征值)主键:{属性URI}

④属性约束表 属性约束(类URI,属性URI,约束类型,约束值)

主键:{类URI,属性URI,约束类型}

此表可以作为类表和属性表间的联系表

⑤实例表 实例(实例URI,实例名,类URI,属性URI,属性值) 主键:{实例URI,属性URI}//原文此处是  主键:{实例URI}

 1.3 构建owl本体片断

<?xml version="1.0"?>


<!DOCTYPE rdf:RDF [
    <!ENTITY owl "http://www.w3.org/2002/07/owl#" >
    <!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
    <!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
    <!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
]>


<rdf:RDF xmlns="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#"
     xml:base="http://www.semanticweb.org/ontologies/2012/10/logistics.owl"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
     xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:owl="http://www.w3.org/2002/07/owl#">
    <owl:Ontology rdf:about="http://www.semanticweb.org/ontologies/2012/10/logistics.owl"/>
    


    <!-- 
    ///////////////////////////////////////////////////////////////////////////////////////
    //
    // Datatypes
    //
    ///////////////////////////////////////////////////////////////////////////////////////
     -->

    


    <!-- http://www.w3.org/2001/XMLSchema#date -->

    <rdfs:Datatype rdf:about="&xsd;date"/>
    


    <!-- 
    ///////////////////////////////////////////////////////////////////////////////////////
    //
    // Object Properties
    //
    ///////////////////////////////////////////////////////////////////////////////////////
     -->

    


    <!-- http://www.semanticweb.org/ontologies/2012/10/logistics.owl#下订单 -->

    <owl:ObjectProperty rdf:about="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#下订单">
        <rdfs:range rdf:resource="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#销售商"/>
        <rdfs:domain rdf:resource="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#顾客"/>
    </owl:ObjectProperty>
    


    <!-- http://www.semanticweb.org/ontologies/2012/10/logistics.owl#发货 -->

    <owl:ObjectProperty rdf:about="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#发货">
        <owl:inverseOf rdf:resource="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#下订单"/>
        <rdfs:domain rdf:resource="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#销售商"/>
        <rdfs:range rdf:resource="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#顾客"/>
    </owl:ObjectProperty>
    


    <!-- http://www.semanticweb.org/ontologies/2012/10/logistics.owl#订货人 -->

    <owl:ObjectProperty rdf:about="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#订货人">
        <rdfs:domain rdf:resource="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#订单"/>
        <rdfs:range rdf:resource="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#顾客"/>
    </owl:ObjectProperty>
    


    <!-- 
    ///////////////////////////////////////////////////////////////////////////////////////
    //
    // Data properties
    //
    ///////////////////////////////////////////////////////////////////////////////////////
     -->

    


    <!-- http://www.semanticweb.org/ontologies/2012/10/logistics.owl#发货日期 -->

    <owl:DatatypeProperty rdf:about="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#发货日期">
        <rdfs:domain rdf:resource="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#销售商"/>
        <rdfs:range rdf:resource="&xsd;date"/>
    </owl:DatatypeProperty>
    


    <!-- http://www.semanticweb.org/ontologies/2012/10/logistics.owl#订货数量 -->

    <owl:DatatypeProperty rdf:about="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#订货数量">
        <rdfs:domain rdf:resource="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#订单"/>
        <rdfs:range rdf:resource="&xsd;positiveInteger"/>
    </owl:DatatypeProperty>
    


    <!-- http://www.semanticweb.org/ontologies/2012/10/logistics.owl#订货日期 -->

    <owl:DatatypeProperty rdf:about="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#订货日期">
        <rdfs:domain rdf:resource="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#订单"/>
        <rdfs:range rdf:resource="&xsd;date"/>
    </owl:DatatypeProperty>
    


    <!-- 
    ///////////////////////////////////////////////////////////////////////////////////////
    //
    // Classes
    //
    ///////////////////////////////////////////////////////////////////////////////////////
     -->

    


    <!-- http://www.semanticweb.org/ontologies/2012/10/logistics.owl#一般顾客 -->

    <owl:Class rdf:about="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#一般顾客">
        <rdfs:subClassOf rdf:resource="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#顾客"/>
    </owl:Class>
    


    <!-- http://www.semanticweb.org/ontologies/2012/10/logistics.owl#团体顾客 -->

    <owl:Class rdf:about="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#团体顾客">
        <rdfs:subClassOf rdf:resource="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#顾客"/>
    </owl:Class>
    


    <!-- http://www.semanticweb.org/ontologies/2012/10/logistics.owl#订单 -->

    <owl:Class rdf:about="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#订单">
        <owl:equivalentClass>
            <owl:Restriction>
                <owl:onProperty rdf:resource="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#订货数量"/>
                <owl:minCardinality rdf:datatype="&xsd;nonNegativeInteger">1</owl:minCardinality>
                <owl:onDataRange rdf:resource="&xsd;positiveInteger"/>
            </owl:Restriction>
        </owl:equivalentClass>
        <owl:equivalentClass>
            <owl:Restriction>
                <owl:onProperty rdf:resource="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#订货数量"/>
                <owl:maxCardinality rdf:datatype="&xsd;nonNegativeInteger">100</owl:maxCardinality>
                <owl:onDataRange rdf:resource="&xsd;positiveInteger"/>
            </owl:Restriction>
        </owl:equivalentClass>
    </owl:Class>
    


    <!-- http://www.semanticweb.org/ontologies/2012/10/logistics.owl#销售商 -->

    <owl:Class rdf:about="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#销售商"/>
    


    <!-- http://www.semanticweb.org/ontologies/2012/10/logistics.owl#顾客 -->

    <owl:Class rdf:about="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#顾客"/>
    


    <!-- 
    ///////////////////////////////////////////////////////////////////////////////////////
    //
    // Individuals
    //
    ///////////////////////////////////////////////////////////////////////////////////////
     -->

    


    <!-- http://www.semanticweb.org/ontologies/2012/10/logistics.owl#李明 -->

    <owl:NamedIndividual rdf:about="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#李明">
        <rdf:type rdf:resource="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#团体顾客"/>
        <下订单 rdf:resource="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#麦考林"/>
    </owl:NamedIndividual>
    


    <!-- http://www.semanticweb.org/ontologies/2012/10/logistics.owl#淘宝 -->

    <owl:NamedIndividual rdf:about="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#淘宝">
        <rdf:type rdf:resource="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#销售商"/>
        <发货日期 rdf:datatype="&xsd;date">2011-04-05</发货日期>
    </owl:NamedIndividual>
    


    <!-- http://www.semanticweb.org/ontologies/2012/10/logistics.owl#雪地靴 -->

    <owl:NamedIndividual rdf:about="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#雪地靴">
        <rdf:type rdf:resource="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#订单"/>
        <订货日期 rdf:datatype="&xsd;date">2012-11-11</订货日期>
        <订货数量 rdf:datatype="&xsd;positiveInteger">60</订货数量>
        <订货人 rdf:resource="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#李明"/>
    </owl:NamedIndividual>
    


    <!-- http://www.semanticweb.org/ontologies/2012/10/logistics.owl#韩梅梅 -->

    <owl:NamedIndividual rdf:about="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#韩梅梅">
        <rdf:type rdf:resource="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#一般顾客"/>
        <下订单 rdf:resource="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#淘宝"/>
    </owl:NamedIndividual>
    


    <!-- http://www.semanticweb.org/ontologies/2012/10/logistics.owl#高跟鞋 -->

    <owl:NamedIndividual rdf:about="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#高跟鞋">
        <rdf:type rdf:resource="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#订单"/>
        <订货数量 rdf:datatype="&xsd;positiveInteger">10</订货数量>
        <订货日期 rdf:datatype="&xsd;date">2011-04-01</订货日期>
        <订货人 rdf:resource="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#韩梅梅"/>
    </owl:NamedIndividual>
    


    <!-- http://www.semanticweb.org/ontologies/2012/10/logistics.owl#麦考林 -->

    <owl:NamedIndividual rdf:about="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#麦考林">
        <rdf:type rdf:resource="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#销售商"/>
        <发货 rdf:resource="http://www.semanticweb.org/ontologies/2012/10/logistics.owl#李明"/>
    </owl:NamedIndividual>
</rdf:RDF>



<!-- Generated by the OWL API (version 3.1.0.20069) http://owlapi.sourceforge.net -->

1.3 用Jena进行解析

数据库选用的mysql,解析需要的jena架包是jena-2.6.4.zip解压后lib文件夹下所有*.jar。全部导入就可以。

由于这部分是别人做的,不方便把代码贴出来,贴最后效果吧

   1.类表  ontologyclass

   主键:C_Uri

2. 属性表 property

主键:Proty_URI

3.属性约束表 propertyrestriction

主键: R_Curi,R_Puri,R_Type

4.属性特征值表  propertytrait

主键 :PC_URI

5.实例表 individual

主键:Indiv_URI,Indiv_PURI

至此,就完成了owl本体片断的解析。

二.用prefuse进行可视化呈现 将在下篇文章中详细说明。    

转载本文请标明出处。

posted @ 2012-12-21 11:05  方子格  阅读(2271)  评论(2编辑  收藏  举报