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. DOM Exception error 类型

    INDEX_SIZE_ERR  code 1                              索引是负值,或者超过了索引值 DOMSTRING_SIZE_ERR  code 2       ...

  2. HTML学习笔记 基础表格案例 第二节 (原创) 参考使用表

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. Oracle 数据库常用操作语句大全

    一.Oracle数据库操作 1.创建数据库      create database databasename 2.删除数据库      drop database dbname 3.备份数据库 完全 ...

  4. Python实现翻译功能

    初入Python,一开始就被她简介的语法所吸引,代码简洁优雅,之前在C#里面打开文件写入文件等操作相比Python复杂多了,而Python打开.修改和保存文件显得简单得多. 1.打开文件的例子: fi ...

  5. C#中float, double的精度问题

    在工作中我发现了一个C#浮点数的精度问题,以下的程序运行结果并未得到我预期的结果: view source print? 01 namespace FloatTest 02 03     class ...

  6. 在moba游戏里面模拟实现绝地求生毒雾圈功能

    ---恢复内容开始--- 已经有很长一段时间没做项目了上半年大多数时间都荒废在王者荣耀,哈哈,S8赛季也上了王者,美滋滋 转回正题,公司需要开个新项目,需要把原有的moba游戏,改成类似绝地求生那玩法 ...

  7. 通过Xshell连接CentOS虚拟机

    1.通过"setup"配置网络ip(CentOS7不支持setup配置) 2.通过"service network restart"来重启网络服务 3.&quo ...

  8. [转载] Cassandra入门 框架模型 总结

    转载自http://asyty.iteye.com/blog/1202072 一.Cassandra框架二.Cassandra数据模型 Colum / Colum Family, SuperColum ...

  9. Tornado异步

    http://www.tuicool.com/articles/36ZzA3 http://www.dongwm.com/archives/shi-yong-tornadorang-ni-de-qin ...

  10. javascript第六章--BOM

    ① window对象 ② location对象 ③ navigator对象 ④ screen对象 ⑤ history对象