第二步 在D2RQ平台上配置jena环境
Jena文档《An Introduction to RDF and the Jena RDF API》的译文
文档里包含的内容很多,还是回到具体的配置上来。
log4j.rootLogger=INFO, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{HH:mm:ss} %-5p %-20c{1} :: %m%n
log4j.logger.de.fuberlin.wiwiss.d2rq=ALL
|
// Set up the ModelD2RQ using a mapping file
Model m = new ModelD2RQ("file:doc/example/mapping-iswc.ttl");
// Find anything with an rdf:type of iswc:InProceedings
StmtIterator paperIt = m.listStatements(null, RDF.type, ISWC.InProceedings);
// List found papers and print their titles
while (paperIt.hasNext()) {
Resource paper = paperIt.nextStatement().getSubject();
System.out.println("Paper: " + paper.getProperty(DC.title).getString());
// List authors of the paper and print their names
StmtIterator authorIt = paper.listProperties(DC.creator);
while (authorIt.hasNext()) {
Resource author = authorIt.nextStatement().getResource();
System.out.println("Author: " + author.getProperty(FOAF.name).getString());
}
System.out.println();
}
m.close();
|
// Load mapping file
Model mapModel = FileManager.get().loadModel("doc/example/mapping-iswc.ttl");
// Parse mapping file
MapParser parser = new MapParser(mapModel, "http://localhost:2020/");
Mapping mapping = parser.parse();
// Set up the GraphD2RQ
GraphD2RQ g = new GraphD2RQ(mapping);
// Create a find(spo) pattern
Node subject = Node.ANY;
Node predicate = DC.date.asNode();
Node object = Node.createLiteral("2003", null, XSDDatatype.XSDgYear);
Triple pattern = new Triple(subject, predicate, object);
// Query the graph
Iterator<Triple> it = g.find(pattern);
// Output query results
while (it.hasNext()) {
Triple t = (Triple) it.next();
System.out.println("Published in 2003: " + t.getSubject());
};
g.close();
|
ModelD2RQ m = new ModelD2RQ("file:doc/example/mapping-iswc.ttl");
String sparql =
"PREFIX dc: <http://purl.org/dc/elements/1.1/>" +
"PREFIX foaf: <http://xmlns.com/foaf/0.1/>" +
"SELECT ?paperTitle ?authorName WHERE {" +
" ?paper dc:title ?paperTitle . " +
" ?paper dc:creator ?author ." +
" ?author foaf:name ?authorName ." +
"}";
Query q = QueryFactory.create(sparql);
ResultSet rs = QueryExecutionFactory.create(q, m).execSelect();
while (rs.hasNext()) {
QuerySolution row = rs.nextSolution();
System.out.println("Title: " + row.getLiteral("paperTitle").getString());
System.out.println("Author: " + row.getLiteral("authorName").getString());
};
m.close();
|
@prefix : <#> .
@prefix ja: <http://jena.hpl.hp.com/2005/11/Assembler#> .
@prefix d2rq: <http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#> .
<> ja:imports d2rq: .
:myModel
a d2rq:D2RQModel;
d2rq:mappingFile <mapping-iswc.ttl>;
d2rq:resourceBaseURI <http://localhost:2020/>;
.
|
// Load assembler specification from file
Model assemblerSpec = FileManager.get().loadModel("doc/example/assembler.ttl");
// Get the model resource
Resource modelSpec = assemblerSpec.createResource(assemblerSpec.expandPrefix(":myModel"));
// Assemble a model
Model m = Assembler.general.openModel(modelSpec);
// Write it to System.out
m.write(System.out);
m.close();
|
第二步 在D2RQ平台上配置jena环境的更多相关文章
- eclipse弃坑记第一篇之在idea上配置Tomcat环境并创建Javaweb项目的详细步骤原创
IntelliJ IDEA是一款功能强大的开发工具,在代码自动提示.重构.J2EE支持.各类版本工具(如git.svn.github).maven等方面都有很好的应用. IntelliJ IDEA有免 ...
- Mac上配置GTK环境
Mac上配置GTK环境 安装command line工具, 如果安装了Xcode, 就直接跳过该步骤 安装Homebrew 使用brew install pkg-config 使用brew insta ...
- Eclipse/MyEclipse上配置Spring环境
在MyEclipse上配置Spring环境 myeclipse其实已经集成Spring的开发环境,我们只需在新建的项目上添加spring的配置环境就可以 新建一个java项目 选中创建好的项目之后,在 ...
- [eShopOnContainers 学习系列] - 03 - 在远程 Ubuntu 16.04 上配置开发环境
直接把 md 粘出来了,博客园的富文本编辑器换成 markdown,没啥效果呀 ,先凑合吧.实在不行换地方 # 在远程 Ubuntu 16.04 上配置开发环境 ## 零.因 为什么要用这么麻烦的 ...
- mac上配置react-native环境run-ios/run-android命令遇到的问题
新报错(rn版本:0.53.3)2018.3.6 今天在搞react-native环境时,遇到了一些坑,这里记录一下. 首先最重要的一点是一定要按官网一步一步来,不然可能会出现一些奇奇怪怪的问题! 官 ...
- VMware上配置DPDK环境并运行实例程序
1. 在虚拟机VMware上配置环境 VMware安装:http://www.zdfans.com/html/5928.html Ubuntu:https://www.ubuntu.com/downl ...
- 在linux上配置Maven环境变量
1.首先下载maven ,这里我使用的是3.8.1 Maven – Download Apache Maven 2.在linux环境中,将maven上传至 /usr/local/目录中 这里我将mav ...
- 教你在mac上配置adb环境变量
1.打开终端,一次输入如下命令 cd ~ touch .bash_profile open -e .bash_profile 2.这时候会在TextEdit中打开一个空白文档,输入下面的语句 a. 输 ...
- 1-如何自己在eclipse上配置Andriod环境
转载:http://blog.csdn.net/dr_neo/article/details/49870587 最新鲜最详细的Android SDK下载安装及配置教程 2015年11月16日 19:2 ...
随机推荐
- static和const
转自说出static和const关键字尽可能多的作用 static关键字至少有下列n个作用: 函数体内static变量的作用范围为该函数体,不同于auto变量,该变量的内存只被分配一次,因此其值在下次 ...
- ***PHP多线程pthreads 实现QQ号码爬虫
通过空间历史浏览,爬出查看你空间的人(一般限制20人,除非开通黄钻),然后在爬出这20人的浏览记录,依次向下爬,你可以控制爬行深度.这里仅仅给出怕中代码片段,你可以进一步优化,将QQ分类存储.通过QQ ...
- Linux使用wake_up_interruptible()唤醒注册到等待队列上的进程
http://blog.sina.com.cn/s/blog_4770ef020101h48l.html 功能:唤醒注册到等待队列上的进程 原型: #include void ...
- Log4delphi使用心得
因为delphi不是我的主力开发工具,所有一直没有使用一个正式的日志组件.偶尔要记日志时,就复制同事的一个简单的文件日志函数.现在又要用到delphi日志了,决定找个通用的日志组件,造福共事的Delp ...
- Android SurfaceView实现全屏播放例子
public class Mymedia extends Activity implements OnBufferingUpdateListener, OnCompletionListener, Me ...
- Android:MD5加密
/** * @author gongchaobin * * MD5加密 * * @version 2013-8-22 */ public class MD5Util { // 用来将字节转换成 16 ...
- 【HDOJ】Power Stations
DLX.针对每个城市,每个城市可充电的区间构成一个plan.每个决策由N*D个时间及N个精确覆盖构成. /* 3663 */ #include <iostream> #include &l ...
- Colored Sticks (字典树哈希+并查集+欧拉路)
Time Limit: 5000MS Memory Limit: 128000K Total Submissions: 27704 Accepted: 7336 Description You ...
- 屯题50AC纪念
从2.1起开始屯题,一直弄到现在才完成了一发50题的目标,实在太弱 (当然之间事比较多,还是挺不容易的) 不过总算是完成了一个小的目标了 接下来两周要进行小高考最后冲刺了,所以我大概不会再怎么刷题了 ...
- 【转】解决wine中文乱码的问题
原文网址:http://blog.chinaunix.net/uid-24993439-id-2979620.html 新装的wine中文全是乱码,需要修改一下几个配置文件,找到一篇比较详细的配置说明 ...