package cn.edu.shu.db;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.SQLException; import com.hp.hpl.jena.db.DBConnection;
import com.hp.hpl.jena.db.IDBConnection;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.ModelMaker; /**
*
* <p>
* ClassName OWLFile2DB
* </p>
* <p>
* Description :该类能够将owl文件持久化到数据库中。并自己主动创建生成的表。注意会生成多个表。<br/>
* 依赖的jar包是jena-2.6.0.jar/iri-0.7.jar/icu4j-3.4.4.jar/mysql驱动包
* </p>
*
* @author wangxu wangx89@126.com
* <p>
* Date 2014-10-11 下午08:32:34
* </p>
* @version V1.0
*
*/ public class OWLFile2DB {
private static final String DB = "MySQL";
String CLASSNAME = "com.mysql.jdbc.Driver";
String DBURL = "jdbc:mysql://localhost:3306/ontologyIR?useUnicode=true&characterEncoding=UTF8";
String DBUSER = "root";
String DBPWD = "admin"; public static void main(String[] args) throws ClassNotFoundException, IOException, SQLException {
new OWLFile2DB().createTable();
System.out.println("succeed");
} public void createTable() throws ClassNotFoundException, IOException, SQLException {
Class.forName(CLASSNAME);
IDBConnection conn = new DBConnection(DBURL, DBUSER, DBPWD, DB);// 获取连接
ModelMaker maker = ModelFactory.createModelRDBMaker(conn);// 创建ModelMaker对象
Model base = maker.createModel("ontologyIR");
FileInputStream inputStream = null;
File file = new File("Creature.owl");
inputStream = new FileInputStream(file);
InputStreamReader in = null;
in = new InputStreamReader(inputStream, "UTF-8"); base.read(in, null);
in.close();
base.commit();// 持久化到数据库中
conn.close();
} }

用到的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/wangxu/ontologies/2014/9/untitled-ontology-16#"
xml:base="http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<owl:Ontology rdf:about="http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16"/> <!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Object Properties
//
///////////////////////////////////////////////////////////////////////////////////////
--> <!-- http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#beEated --> <owl:ObjectProperty rdf:about="http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#beEated">
<rdfs:range rdf:resource="http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#Animal"/>
<rdfs:domain rdf:resource="http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#Animal"/>
<rdfs:domain rdf:resource="http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#Plant"/>
</owl:ObjectProperty> <!-- http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#eat --> <owl:ObjectProperty rdf:about="http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#eat">
<rdfs:range rdf:resource="http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#Animal"/>
<rdfs:domain rdf:resource="http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#GrassAnimal"/>
<rdfs:domain rdf:resource="http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#MeatAnimal"/>
<rdfs:domain rdf:resource="http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#MixeatAnimal"/>
<rdfs:range rdf:resource="http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#Plant"/>
</owl:ObjectProperty> <!-- http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#mainEat --> <owl:ObjectProperty rdf:about="http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#mainEat">
<rdfs:domain rdf:resource="http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#Animal"/>
<rdfs:range rdf:resource="http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#Animal"/>
<rdfs:domain rdf:resource="http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#GrassAnimal"/>
<rdfs:range rdf:resource="http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#Plant"/>
</owl:ObjectProperty> <!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Classes
//
///////////////////////////////////////////////////////////////////////////////////////
--> <!-- http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#Animal --> <owl:Class rdf:about="http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#Animal">
<rdfs:subClassOf rdf:resource="http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#Creature"/>
</owl:Class> <!-- http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#Branch --> <owl:Class rdf:about="http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#Branch">
<rdfs:subClassOf rdf:resource="http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#Tree"/>
</owl:Class> <!-- http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#Creature --> <owl:Class rdf:about="http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#Creature"/> <!-- http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#Grass --> <owl:Class rdf:about="http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#Grass">
<rdfs:subClassOf rdf:resource="http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#Plant"/>
</owl:Class> <!-- http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#GrassAnimal --> <owl:Class rdf:about="http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#GrassAnimal">
<rdfs:subClassOf rdf:resource="http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#Animal"/>
</owl:Class> <!-- http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#Leaf --> <owl:Class rdf:about="http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#Leaf">
<rdfs:subClassOf rdf:resource="http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#Tree"/>
</owl:Class> <!-- http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#MeatAnimal --> <owl:Class rdf:about="http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#MeatAnimal">
<rdfs:subClassOf rdf:resource="http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#Animal"/>
</owl:Class> <!-- http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#MixeatAnimal --> <owl:Class rdf:about="http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#MixeatAnimal">
<rdfs:subClassOf rdf:resource="http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#Animal"/>
</owl:Class> <!-- http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#Plant --> <owl:Class rdf:about="http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#Plant">
<rdfs:subClassOf rdf:resource="http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#Creature"/>
</owl:Class> <!-- http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#Tree --> <owl:Class rdf:about="http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#Tree">
<rdfs:subClassOf rdf:resource="http://www.semanticweb.org/wangxu/ontologies/2014/9/untitled-ontology-16#Plant"/>
</owl:Class>
</rdf:RDF> <!-- Generated by the OWL API (version 3.4.2) http://owlapi.sourceforge.net -->

Jena将owl文件持久化到数据库中的更多相关文章

  1. Sqlldr导入txt文件内容到数据库中

    需求:数据迁移,将txt文件中的内容导入oracle数据库的表中,文本文件中数据格式如下(数据以空格隔开) 1. 创建与文本数据格式相匹配的表(此处在scott用户下创建) create table ...

  2. 记录python爬取猫眼票房排行榜(带stonefont字体网页),保存到text文件,csv文件和MongoDB数据库中

    猫眼票房排行榜页面显示如下: 注意右边的票房数据显示,爬下来的数据是这样显示的: 网页源代码中是这样显示的: 这是因为网页中使用了某种字体的缘故,分析源代码可知: 亲测可行: 代码中获取的是国内票房榜 ...

  3. 使用pandas中的raad_html函数爬取TOP500超级计算机表格数据并保存到csv文件和mysql数据库中

    参考链接:https://www.makcyun.top/web_scraping_withpython2.html #!/usr/bin/env python # -*- coding: utf-8 ...

  4. php 遍历文件夹及文件,获取文件名和文件路径存入数据库中

    <?php header("Content-Type:text/html; charset=gbk"); require('../../include/connect.php ...

  5. Mapnik连接文件数据、数据库中的vertor数据和raster数据

    Mapnik的XML文件,选择其中一个Datasource. <?xml version="1.0" encoding="utf-8"?> < ...

  6. CSV文件导入到数据库中读取数据详解(接着上个帖子)

    一.controller层 二.SERVICE层 @Overridepublic Result importJinjiangAssessResult(MultipartFile file) throw ...

  7. 将文件存储到数据库中(MySQL)

    package com.play; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundEx ...

  8. JAVA读取CSV文件到MySQL数据库中

    maven项目pom配置: <dependency> <groupId>net.sourceforge.javacsv</groupId> <artifact ...

  9. js上传文件带参数,并且,返回给前台文件路径,解析上传的xml文件,存储到数据库中

    ajaxfileupload.js jQuery.extend({ createUploadIframe: function(id, uri) { //create frame var frameId ...

随机推荐

  1. BZOJ-2330-[SCOI2011]糖果(差分约束)

    Description 幼儿园里有N个小朋友,lxhgww老师现在想要给这些小朋友们分配糖果,要求每个小朋友都要分到糖果.但是小朋友们也有嫉妒心,总是会提出一些要求,比如小明不希望小红分到的糖果比他的 ...

  2. 建立LINUX服务器

    建立LINUX服务器:一. 下载UltraISO工具并用该工具制作LINUX启动U盘,制作步骤如下:http://www.linuxidc.com/Linux/2012-11/74695.htm [^ ...

  3. 《Linux命令行与shell脚本编程大全》第十章 使用编辑器

    主要介绍vim, nano, emacs,KWrite,Kate,GNOME 10.1 vim Unix系统最初的编辑器 10.1.1检查vim软件包 先搞明白你所用的Linux系统是哪种vim软件包 ...

  4. Ext3和Ext4文件系统区别

    inode http://www.cnblogs.com/itech/archive/2012/05/15/2502284.html Ex3使用15个inode查询数据块,前12个为直接数据块,直接指 ...

  5. Python待分析的模块

    fcntl 文件控制模块 http://docs.python.org/2.7/library/fcntl.html#module-fcntl struct 二进制文本处理模块 http://docs ...

  6. Hi,腾讯WeTest联合Unity官方打造的性能分析工具UPA,今日全新发布!

    早在2016年ChinaJoy开始,WeTest曾受邀出席过Unity中国的线下性能场的活动,介绍我们的自动化框架和王者荣耀的故事.当时的活动很成功,期间我们收到了不少Unity开发者的好评,也为我们 ...

  7. window下安装Apache+PHP

    本地系统为windows 10,Apache选择httpd-2.4.25-x64-vc14-r1,PHP选择php7.1_x64线程安全版. 1.安装Apache 将apache解压到c:/serve ...

  8. [动态规划]P1220 关路灯

    题目描述 某一村庄在一条路线上安装了n盏路灯,每盏灯的功率有大有小(即同一段时间内消耗的电量有多有少).老张就住在这条路中间某一路灯旁,他有一项工作就是每天早上天亮时一盏一盏地关掉这些路灯. 为了给村 ...

  9. 内存泄漏监测-LeakCanary

    内存泄漏监测方法之使用LeakCanary LeakCanary出处: github:https://github.com/square/leakcanary/issues square 公司 这个公 ...

  10. lua lua解读

    1.线程状态宏定义(thread status) #define LUA_OK 0 #define LUA_YIELD 1 #define LUA_ERRRUN 2 #define LUA_ERRSY ...