Jena将owl文件持久化到数据库中
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文件持久化到数据库中的更多相关文章
- Sqlldr导入txt文件内容到数据库中
需求:数据迁移,将txt文件中的内容导入oracle数据库的表中,文本文件中数据格式如下(数据以空格隔开) 1. 创建与文本数据格式相匹配的表(此处在scott用户下创建) create table ...
- 记录python爬取猫眼票房排行榜(带stonefont字体网页),保存到text文件,csv文件和MongoDB数据库中
猫眼票房排行榜页面显示如下: 注意右边的票房数据显示,爬下来的数据是这样显示的: 网页源代码中是这样显示的: 这是因为网页中使用了某种字体的缘故,分析源代码可知: 亲测可行: 代码中获取的是国内票房榜 ...
- 使用pandas中的raad_html函数爬取TOP500超级计算机表格数据并保存到csv文件和mysql数据库中
参考链接:https://www.makcyun.top/web_scraping_withpython2.html #!/usr/bin/env python # -*- coding: utf-8 ...
- php 遍历文件夹及文件,获取文件名和文件路径存入数据库中
<?php header("Content-Type:text/html; charset=gbk"); require('../../include/connect.php ...
- Mapnik连接文件数据、数据库中的vertor数据和raster数据
Mapnik的XML文件,选择其中一个Datasource. <?xml version="1.0" encoding="utf-8"?> < ...
- CSV文件导入到数据库中读取数据详解(接着上个帖子)
一.controller层 二.SERVICE层 @Overridepublic Result importJinjiangAssessResult(MultipartFile file) throw ...
- 将文件存储到数据库中(MySQL)
package com.play; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundEx ...
- JAVA读取CSV文件到MySQL数据库中
maven项目pom配置: <dependency> <groupId>net.sourceforge.javacsv</groupId> <artifact ...
- js上传文件带参数,并且,返回给前台文件路径,解析上传的xml文件,存储到数据库中
ajaxfileupload.js jQuery.extend({ createUploadIframe: function(id, uri) { //create frame var frameId ...
随机推荐
- Javascript 内核Bug
Javascript 内核Bug: js 执行(9.9+19.8)加法运算 等于 29.700000000000003) <html> <head> <title> ...
- EM 算法求解高斯混合模型python实现
注:本文是对<统计学习方法>EM算法的一个简单总结. 1. 什么是EM算法? 引用书上的话: 概率模型有时既含有观测变量,又含有隐变量或者潜在变量.如果概率模型的变量都是观测变量,可以直接 ...
- java获取当前上一周、上一月、上一年的时间
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Calendar c = Calend ...
- Python小爬虫
网页解析器下载网址: http://www.crummy.com/software/BeautifulSoup/ ...
- js从时间戳中获取日期
1,从时间戳中解析出年月日时分秒: time为时间戳: var timestr = new Date(parseInt(time) * 1000); var year = timestr.getFul ...
- YII2调试 通过日志记录将变量保存到文件
$log = new \yii\log\FileTarget(); $content=var_export($menu,"true");//将数组或对象转换字符串格式 $con ...
- 第三方插件渗透攻击之KingView
类别:堆溢出 描述:本次渗透利用了KingView6.5.3 SCADA中的ActiveX插件中存在漏洞的方法调用target.ValidateUser(arg1, arg2),通过缓冲区溢出覆盖了S ...
- Spring4 AOP详解
Spring4 AOP详解 第一章Spring 快速入门并没有对Spring4 的 AOP 做太多的描述,是因为AOP切面编程概念不好理解.所以这章主要从三个方面详解AOP:AOP简介(了解),基于注 ...
- 了解python,利用python来制作日常猜拳,猜价小游戏
初次接触python,便被它简洁优美的语言所吸引,正所谓人生苦短,python当歌.python之所以在最近几年越发的炽手可热,离不开它的一些特点: 1.易于学习:Python有相对较少的关键字,结构 ...
- 《java.util.concurrent 包源码阅读》23 Fork/Join框架之Fork的冰山一角
上篇文章一直追踪到了ForkJoinWorkerThread的pushTask方法,仍然没有办法解释Fork的原理,那么不妨来看看ForkJoinWorkerThread的run方法: public ...