zoukankan      html  css  js  c++  java
  • WEB数据挖掘(七)——Aperture数据抽取(3):RDF存储引擎

    如果我们已经了解语义网的相关知识,那么接下来继续深入Aperture框架实现数据解析的机制

    Aperture框架内部是基于RDF2Go框架来实现RDF模型的存储引擎,RDF模型涉及语义网的概念,下面我们来看一个简单的XML格式的RDF文件

    <rdf:RDF
      xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
      xmlns:vCard='http://www.w3.org/2001/vcard-rdf/3.0#'
       >
    
      <rdf:Description rdf:about="http://somewhere/JohnSmith/">
        <vCard:FN>John Smith</vCard:FN>
        <vCard:N rdf:parseType="Resource">
        <vCard:Family>Smith</vCard:Family>
        <vCard:Given>John</vCard:Given>
        </vCard:N>
      </rdf:Description>
    
      <rdf:Description rdf:about="http://somewhere/RebeccaSmith/">
        <vCard:FN>Becky Smith</vCard:FN>
        <vCard:N rdf:parseType="Resource">
        <vCard:Family>Smith</vCard:Family>
        <vCard:Given>Rebecca</vCard:Given>
        </vCard:N>
      </rdf:Description>
    
      <rdf:Description rdf:about="http://somewhere/SarahJones/">
        <vCard:FN>Sarah Jones</vCard:FN>
        <vCard:N rdf:parseType="Resource">
        <vCard:Family>Jones</vCard:Family>
        <vCard:Given>Sarah</vCard:Given>
        </vCard:N>
      </rdf:Description>
    
      <rdf:Description rdf:about="http://somewhere/MattJones/">
        <vCard:FN>Matt Jones</vCard:FN>
        <vCard:N
        vCard:Family="Jones"
        vCard:Given="Matthew"/>
      </rdf:Description>
    
    </rdf:RDF>

    对于RDF模型我们可以联想到语文学习里面的陈述句,一个RDF文件里面是有很多资源组成的,每一个资源又由一些陈述句组成,用来描述这个资源;一个陈述句由主词、谓词和宾词组成,主词是被描述的对象,宾词是描述的属性,谓词则是关系,在具体场景代表不同的关系。

    RDF模型本人觉得是对逻辑学推理的一种形式化,基本上了解了逻辑学也就同时了解了语义网,在西方哲学领域本体的概念与实体的概念两者经常存在交叉歧义,不过对于语义网意义上的本体我们不必深究那么多了

    (补充:RDF模型起初是用于描述元数据信息,感觉这种方式与GSA的xmlfeed目的与方式都是比较类似的)

    RDF2Go框架本身并没有提供对rdf模型存储引擎的具体实现,它只提供了一个抽象层,类似于java类库里面的一些规范,而具体的实现则依赖于第三方的组件;RDF2Go框架主要是实现对第三方的RDF存储引擎的接口转换功能,使之适配成共同的处理方式。

    根据RDF2Go官方文档,RDF2Go框架目前支持以下RDF存储引擎

    Jena Adapter (rdf2go.impl.jena)

    Implements the API and extends the impl.base classes. Delegates all calls to a Jena 2.10.1 model. This adapter provides a Modelimplementation and, new also a ModelSet.

    Sesame Adapter (rdf2go.impl.sesame)

    Implements the API and extends the impl.base classes. Delegates all calls to a Sesame 2.7.1 repository. This adapter provides aModel and a ModelSet implementation.

    • Maven reports including links to JavaDocs, changelog, source code as HTML, JUnit test results, developer team, dependencies, list of open TODO tags in the code, ...
    • Releases (consider downloding the distribution instead)
    • Anonymous Subversion (use https:// for developer access)
    • Status: up-to date with RDF2Go 4.8.3 API

    OWLIM (com.ontotext.trree.rdf2go)

    Implements API and uses a BigOWLIM SAIL as part of the SemanticSpaces project.

    上面这些第三方框架,都是具体的RDF存储引擎,本人只对其中的Apache Jena稍微熟悉一点,不过这并不影响我们对RDF存储引擎的理解;我们可以将RDF存储引擎类比于数据库,我们可以对RDF模型进行添加 修改 检索等功能,至于RDF模型怎么存储、怎么索引、怎么实现查询接口(SPARQL)则是RDF存储引擎所要实现的功能。

    这些第三方的RDF存储引擎的API本文就不作演示了,本人在这里要实现的是利用RDF2Go框架开发一个操作RDF模型的示例

    如果读者对Semweb4j框架有所了解的话,那么我们开发起来也就相对易于上手了,Semweb4j是一个开源的语义搜索引擎框架,这个系统本身即是基于RDF2Go框架和RDFReactor框架的。

    首先我们在eclipse开发工具中建立maven项目(本人特别不愿意采用手动加入jar文件依赖的方式),这里我们导入Semweb4j框架的相关依赖

    <!--rdf2go-->
    <dependency>
                <groupId>org.semweb4j</groupId>
                <artifactId>rdf2go.api</artifactId>
                <version>${project.version}</version>
            </dependency>
    
            <dependency>
                <groupId>org.semweb4j</groupId>
                <artifactId>rdf2go.impl.sesame</artifactId>
                <version>${project.version}</version>
            </dependency>
    
            <dependency>
                <groupId>org.semweb4j</groupId>
                <artifactId>rdf2go.impl.jena</artifactId>
                <version>${project.version}</version>
            </dependency>
           <!--rdfreactor-->
            <dependency>
                <groupId>org.semweb4j</groupId>
                <artifactId>rdfreactor.generator</artifactId>
                <version>${project.version}</version>
            </dependency>
    
            <dependency>
                <groupId>org.semweb4j</groupId>
                <artifactId>rdfreactor.runtime</artifactId>
                <version>${project.version}</version>
            </dependency>
    
            <dependency>
                <groupId>org.semweb4j</groupId>
                <artifactId>rdfreactor-maven-plugin</artifactId>
                <version>${project.version}</version>
            </dependency>

    上面是显式的导入RDF2Go框架和RDFReactor框架的相关依赖,当然我们也可以更简短的方式导入依赖

    <dependency>
                <groupId>org.semweb4j</groupId>
                <artifactId>dist</artifactId>
                <version>${project.version}</version>
                <type>pom</type>
            </dependency>

    本人采用的Semweb4j版本为4.8.3

    /**
         * @param args
         */
        public static void main(String[] args) throws ModelRuntimeException{
            // TODO Auto-generated method stub
            // getting model factory
            ModelFactory modelFactory = RDF2Go.getModelFactory();       // getting model
            Model model = modelFactory.createModel();
            model.open();
            assert model.isOpen();
    
            // creating URIs
            String foafURI = "http://xmlns.com/foaf/0.1/";
            URI max = model.createURI("http://xam.de/foaf.rdf.xml#i");
            URI currentProject = model.createURI(foafURI + "#term_currentProject");
            URI name = model.createURI(foafURI + "#term_name");
            URI semweb4j = model.createURI("http://semweb4j.org");
    
            // adding a statement to the model
            model.addStatement(max, currentProject, semweb4j);
            model.addStatement(max, name, "Max Völkel");
    
            // dumping model to the screen
            model.dump();
    
            // removing a statement from the model
            model.removeStatement(max, currentProject, semweb4j);
    
            // dumping model to the screen
            model.dump();
    
        }

    运行该类的main方法,控制台输出结果如下

    Dumping Repository contents ----------------------------------------------
    http://xam.de/foaf.rdf.xml#i - http://xmlns.com/foaf/0.1/#term_currentProject - http://semweb4j.org
    http://xam.de/foaf.rdf.xml#i - http://xmlns.com/foaf/0.1/#term_name - Max Völkel
    Dumping Repository contents ----------------------------------------------
    http://xam.de/foaf.rdf.xml#i - http://xmlns.com/foaf/0.1/#term_name - Max Völkel

    至此,第一个RDF模型的示例程序已经运行成功了,如果本人理解有误,还请各位同仁指正

    --------------------------------------------------------------------------- 

    本系列WEB数据挖掘系本人原创

    作者 博客园 刺猬的温驯 

    本文链接http://www.cnblogs.com/chenying99/archive/2013/06/12/3132406.html

    本文版权归作者所有,未经作者同意,严禁转载及用作商业传播,否则将追究法律责任。

  • 相关阅读:
    sp2010 升级sp2013 用户无法打开网站
    powerviot install in sharepoint 2013
    can not connect cube in performancce dashboard
    westrac server security configure user info
    添加报表服务在多服务器场
    sharepoint 2013 office web app 2013 文档在线浏览 IE11 浏览器不兼容解决方法
    delete job definition
    目前付款申请单内网打开慢的问题
    item style edit in sharepoint 2013
    Could not load file or assembly '$SharePoint.Project.AssemblyFullName$'
  • 原文地址:https://www.cnblogs.com/chenying99/p/3132406.html
Copyright © 2011-2022 走看看