支持BLOB操作的Jena框架扩展——JenaBLOB
与研究语义网的同行们分享一下上半年做的一个东西,它是支持BLOB操作的Jena框架扩展——JenaBLOB,已在GitHub上开源,欢迎提出宝贵意见!
众所周知,Jena是不支持BLOB类型的Literal的,但根据RDF强大的模型来说,它并不排除属性值可以是BLOB类型。JenaBLOB用于实现这种功能。
托管地址:https://github.com/bluejoe2008/jena-blob
jena-blob
write/read/query BLOBs(binary large objects) in Jena framework
jena-blob enables RDF stores to manage both structured data and unstructred data
visit https://github.com/bluejoe2008/jena-blob/blob/master/test/JenaBlobTest.java for
example usage
create
blob objects in Java
a blob object is always accessed via an InputStream interface. BlobLiteral class provides several create() methods to create blob objects:
- public static Literal create(byte[] bytes) : creates a blob from a byte array
- public static Literal create(File file) : creates a blob which contents come from a local file
- public static Literal create(InputStreamSource source) : creates a blob which contents come from a org.springframework.core.io.InputStreamSource
- public static Literal create(String text) : create a blob from a byte array of a string
the following codes illustrate how to add a BLOB as a literal:
SAMPLE_MODEL = ModelFactory.createDefaultModel();
Literal lit = BlobLiteral.create(new File("./1.gif"));
SAMPLE_MODEL.add(SAMPLE_MODEL.createResource("http://s"), SAMPLE_MODEL.createProperty("http://p"), lit);
models
and blob storage
As we know, RDF statements can be saved in RDF models. Simply, a blob can be saved in RDF models as a string in certain encoding (BASE64Encoding, for example). However, it is not feasible for large blobs due to large size for RDF statements and long time costs
for storing/loading.
A good idea for blob storage is to choose file systems, databases, or other stream storage services. BlobStorage interface is defined to tells where and how to save/load blobs. Several types of BlobStorages are provided in jena-blob:
- ByteArrayBlobStorage : save blobs in byte arrays
- FileSystemBlobStorage : save blobs in local file systems
- KeepAsIsBlobStorage : do not save blobs, only for in-memory blob reading
BlobModelFactory provides several createXXXModel() methods to create models:
- createMemModel() : creates a plain in-memory model, blobs can be added but not be persisted
- createMemModel(BlobStorage blobStorage) : creates an in-memory model, blobs will be persisted in blobStorage
- createMemModel(File blobDir) : creates an in-memory model, blobs will be persisted in local blobDir
- createTDBModel(File dir) : creates a TDB model, blobs will be persisted in local dir/blob
- createTDBModel(File tdbDir, BlobStorage blobStorage) : creates a TDB model, blobs will be persisted in blobStorage
the following codes illustrate blob representation in a ByteArrayBlobStorage:
<http://s> <http://p> "content:R0lGODlhRgAgALP/AP///xAQEBgYGCEhITExMUpKSlpaWmtra3t7e4yMjJycnLW1tcbG
xt7e3vf39wAAACwAAAAARgAgAEAE/xDISau9OOu923CToQBNwFXOd64aAQJj4wQGILIAIjXcPAKOwoPG4CwQiBfjASLwLIVFJZGQK
HQVxfPSeBQXBODhIdjiKo3C61Q+TxwHd6jg8UoQtUzDkBg8pCspDmskAj8ZBjJxEgk1B0UUDYcWDgKAbzUOBFUTUg0IjUB0JwlMO4
tABg8PBwuERgcBQwR8lxMBnBm2ckADvL/AEx5no79hvAcFJA8FAwWqZhgIQgKBPwoDzgcEphkMWAClD6WeA5BGuxqV4Aqr6RdHEpe
qq4SD6tl5EwwJrwU6KR64wOFL34Iaey74upAgzZt85xi8IkGgCIMAExmOm/BghINuEv8cKBAC8gCqFOAmXLkwg0e7IZw+5gpGsyav
BdFs6syAYNKGhTt/GXiXIcovUDgQmPkmYegZARlXMCCqS5ipA1UYXIlK4cg9OQ0WLNBypouMArh48DnB7UBODAk8yQg5wOeFiA8M+
MmzQIWGBAem4UjgZEcBBQHsXkAAaMGSAwrCBKFqgeyKPi80rUKl7pjlBasKcD6hlICyDQugkvBTjNQIVzs6mkRBGcHGSI1Ox25Qxw
5XCx8UnDMHACMK3ccnOej7ZMk5ClEGOeWQhqkEAlJ6XihcASeARxZGhx/Ag8BroxkUGNBtIM8DDNsiqSaBPGR9CrMBDFiQIMB+01G
V8oQpWRL8sxwC3IggEXS2OLAeTrwtMIZdhO2ABCGIZbScBnP98huBQYWoUwQAOw==,length:628,digest:5ecb3255a12ef30a9
d3c3a5554e8021d,mark:R0lGODlhRgAgALP/AP///xAQEBgYGCEhITExMUpKSlo="^^<urn:x-hp-dt:blob-bytes> .
the following codes illustrate blob representation in a FileSystemBlobStorage:
<http://s> <http://p> "handle:1395714660338.bin,length:628,digest:5ecb3255a12ef30a9d3c3a5554e8021d
,mark:R0lGODlhRgAgALP/AP///xAQEBgYGCEhITExMUpKSlo="^^<urn:x-hp-dt.blob-file> .
query
on blobs
jena-blob adds some additional information on blob literals which enables blob query:
- length : length of a blob, in long integer
- digest : md5 digest string of a blob, in String (using org.apache.commons.codec.digest.DigestUtils.md5Hex(is))
- mark : the first 32-bytes of the blob, in byte[]
for a Blob object, length()/getDigest()/getMark() methods can be used to retrieve such information.
jena-blob also provides FILTER functions to enable SPARQL query on blobs:
- isBlob() : to determine a literal is a blob or not
- length() : tells the length of a blob
- digest() : tells the digest string of the blob
- mark() : to retrieve the mark of the blob
- mark(size) : to retrieve first size-bytes of mark
- mark(beginning, size) : to retrieve size-bytes of mark, from the beginning of beginning
an example SPARQL query is shown as below:
PREFIX blob: <http://bluejoe.cn/jenablob#>
select ?s ?p ?o
(blob:isBlob(?o) as ?v1) (blob:length(?o) as ?v2) (blob:digest(?o) as ?v3)
(blob:mark(?o) as ?v4) (blob:mark(?o,6) as ?v5) (blob:mark(?o,0, 6) as ?v6)
(blob:string(?o) as ?v7) (blob:bytes(?o) as ?v8)
where {?s ?p ?o. FILTER (blob:isBlob(?o))}
支持BLOB操作的Jena框架扩展——JenaBLOB的更多相关文章
- 10大支持移动“触摸操作”的JavaScript框架
摘要:移动开发行业的发展速度让人目不暇接,也在此大势之下,推出移动网站App成为开发者必经之路,如何让触屏设备 更易使用?如何让网站对触摸手势做出反应并使触摸更友好?所有这一切,皆因JavaScrip ...
- Util应用程序框架公共操作类(六):验证扩展
前面介绍了仓储的基本操作,下面准备开始扩展查询,在扩展查询之前,首先要增加两个公共操作类,一个是经常要用到的验证方法,另一个是Lambda表达式的操作类. 很多时候,我们会判断一个对象是否为null, ...
- 在Jena框架下基于MySQL数据库实现本体的存取操作
在Jena框架下基于MySQL数据库实现本体的存取操作 转自:http://blog.csdn.net/jtz_mpp/article/details/6224311 最近在做一个基于本体的管理系统. ...
- JavaSE中Collection集合框架学习笔记(2)——拒绝重复内容的Set和支持队列操作的Queue
前言:俗话说“金三银四铜五”,不知道我要在这段时间找工作会不会很艰难.不管了,工作三年之后就当给自己放个暑假. 面试当中Collection(集合)是基础重点.我在网上看了几篇讲Collection的 ...
- unittest框架扩展(基于代码驱动)自动化-下
一.数据驱动/代码驱动优缺点: 使用数据驱动的好处:- 代码复用率高.同一测试逻辑编写一次,可以被多条测试数据复用,提高了测试代码的复用率,同时可以提高测试脚本的编写效率.- 异常排查效率高.测试框架 ...
- 【ASP.NET Web API教程】2.1 创建支持CRUD操作的Web API
原文 [ASP.NET Web API教程]2.1 创建支持CRUD操作的Web API 2.1 Creating a Web API that Supports CRUD Operations2.1 ...
- C#操作Xml树的扩展类
本文提供一个操作Xml树的扩展类,与将xml字符串直接映射成实体对象的使用方法,供大家参考,学习. 下面附上源码 using System; using System.Collections.Gene ...
- UVa 11987 Almost Union-Find(支持删除操作的并查集)
传送门 Description I hope you know the beautiful Union-Find structure. In this problem, you’re to imple ...
- JAVASE02-Unit03: 日期操作 、 集合框架
Unit03: 日期操作 . 集合框架 java.util.Date package day03; import java.util.Date; /** * java.util.Date * Date ...
随机推荐
- HIbernate学习笔记(二) hibernate对象的三种状态与核心开发接口
1.在hibernate中持久化对象有三个状态,这个面试时可能会问到: (1)transient瞬时态:在数据库中没有与之匹配的数据,一般就是只new出了这个对象,并且在session缓存中也没有即此 ...
- Petshop学习第一天
1.PetShop的体系架构: 2.分层设计的目的: 分散关注.松散耦合.逻辑复用.标准定义 3.一些不明白的地方: item和product是什么关系??? Model类库中的Linq To Sql ...
- poj2152 Fire
好难啊,我弱爆了. 题解看陈启峰的论文... /** * Problem:POJ2152 * Author:Shun Yao * Time:2013.9.2 * Result:Accepted * M ...
- IEnumerable、IEnumerator与yield的学习
我们知道数组对象可以使用foreach迭代进行遍历,同时我们发现类ArrayList和List也可以使用foreach进行迭代.如果我们自己编写的类也需要使用foreach进行迭代时该怎么办呢? IE ...
- .编写Java应用程序。首先,定义一个Print类,它有一个方法void output(int x),如果x的值是1,在控制台打印出大写的英文字母表;如果x的值是2,在 控制台打印出小写的英文字母表。其次,再定义一个主类——TestClass,在主类 的main方法中创建Print类的对象,使用这个对象调用方法output ()来打印出大 小写英文字母表。
package com.homework.zw; //类Print部分 public class Print1 { int x; void output() { if(x==1) { for(int ...
- eclipse插件开发(一)
eclipse本身是一个开源平台, 给用户提供了很多扩展点.我们完全可以开发属于自己的一套插件,安装在eclipse插件目录下,即可使用我们的插件. 下面说下eclipse插件的快速开发. 1.在ec ...
- SQLMAP实用实例(转)
sqlmap使用笔记:http://wenku.baidu.com/view/8c507ffcaef8941ea76e055e.html BT5下使用SQLMAP入侵加脱裤:http://www.m ...
- SAP增强总结-第二代增强(SMOD、CMOD)【转载】
第二代增强比第二代增强安全性提高了很多,第一代增强毕竟是在原标准程序中修改,大部分传递参数都可以直接使用,第二代增强做了一些封装,对用户可以修改的参数做了限制. 1.增强点查找方法 首先根据事物码找到 ...
- Codeforces Round #321 (Div. 2) C. Kefa and Park dfs
C. Kefa and Park Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/580/probl ...
- delphi 连接mysql
Delphi连接MySQL真麻烦,研究了一天,从网上找了无数文章,下载了无数插件都没解决.最后返璞归真,老老实实用ADO来连接,发现也不是很顺利,但最终还是连接成功了.多少有点心得:ADO各个组件的作 ...