第二步 在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 ...
随机推荐
- 标准初始化css样式表
body { font-size:12px; line-height:1.3; font-family:'微软雅黑', Tahoma,Helvetica,Arial,'宋体', sans-serif; ...
- bzoj 2406: 矩阵 上下界网络流判定
2406: 矩阵 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 138 Solved: 46[Submit][Status][Discuss] De ...
- [cc150] 硬币问题
Given an infinite number of quarters (25 cents), dimes (10 cents), nickels (5 cents) and pennies (1 ...
- 李洪强漫谈iOS开发[C语言-019]-断点调试
- M-JPEG和MPEG-4的区别 M-JPEG VS MPEG
http://blog.sina.com.cn/s/blog_4b357b300100gre9.html M-JPEG VS MPEG http://blog.csdn.net/bluesky_sun ...
- spring声明式事务 同一类内方法调用事务失效
只要避开Spring目前的AOP实现上的限制,要么都声明要事务,要么分开成两个类,要么直接在方法里使用编程式事务 [问题] Spring的声明式事务,我想就不用多介绍了吧,一句话“自从用了Spring ...
- 结构体page_cur_t
/** Type of the index page */ typedef byte page_t; /** Index page cursor */ typedef struct page_cur_ ...
- POJ_1269_Intersecting_Lines_(计算几何基础)
描述 http://poj.org/problem?id=1269 给出两条直线,判断它们是平行,重合,还是相交,如果相交,求出交点. 分析 比较裸的一道题.学习了直线的写法(参数方程) #inclu ...
- BZOJ1324: Exca王者之剑
1324: Exca王者之剑 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 256 Solved: 131[Submit][Status] Desc ...
- POJ 2513 Colored Sticks 解题报告
第一次接触欧拉回路.虽然在离散数学里学过,敲代码还是第一次. 本题是说端点颜色相同的两根木棒可连接,能否将所有的木棒连成一条直线. 将颜色视为节点v,将木棒视为边e,构成图G.如果能找到一条一笔画的路 ...