第二步 在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 ...
随机推荐
- Maven仓库详解
转载自:Maven入门指南④:仓库 1 . 仓库简介 没有 Maven 时,项目用到的 .jar 文件通常需要拷贝到 /lib 目录,项目多了,拷贝的文件副本就多了,占用磁盘空间,且难于管理.Ma ...
- 几种 Docker 监控工具对比
轻量级虚拟化容器 Docker,自发布以来便广受业界关注,在开源界和企业界掀起了一阵风.Docker 容器相对于 VM 有以下几个优势:启动速度快:资源利用率高:性能开销小. 从图中可以看出 Dock ...
- .htaccess文件的详解以及404页面的设置
打开记事本,写入以下代码: ErrorDocument 404 /404.html保存成.htaccess文件上传到网站的根目录. /404.html是目录名和文件名,可以改成自己的名字.QUOTE: ...
- 157. Read N Characters Given Read4
题目: The API: int read4(char *buf) reads 4 characters at a time from a file. The return value is the ...
- C++11 中的线程、锁和条件变量
转自:http://blog.jobbole.com/44409/ 线程 类std::thread代表一个可执行线程,使用时必须包含头文件<thread>.std::thread可以和普通 ...
- C#实现微信公众号群发消息(突破破解一天只能发一次的限制)
总体思路:1.首先必须要在微信公众平台上申请一个公众号. 2.然后进行模拟登陆.(由于我对http传输原理和编程不是特别懂,在模拟登陆的地方,不是特别清楚,希望有大神指教) 3.模拟登陆后会获得一个t ...
- BZOJ_1005_ [HNOI2008]_明明的烦恼_(组合数学+purfer_sequence+高精度+分解因数+快速幂)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1005 一棵树有n个点,给出没给节点的度,如果没有限制则为-1,求共有多少种可能的树. 分析 蒟 ...
- Selenium IDE初探
系列教程: http://www.cnblogs.com/hyddd/archive/2009/05/30/1492536.html 使用过程中,出现了一些问题.
- [TVYJ1096]数字组合
时间: 1000ms / 空间: 131072KiB / Java类名: Main 描述 在N个数中找出其和为M的若干个数.先读入正整数N(1<N<100)和M(1<M<100 ...
- POJ 1458 Common Subsequence 最长公共子序列 LCS
LCS #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> ...