Jena解析rdf、nt、ttl格式数据
比如有一个ttl格式的文件名为cco.ttl
package com.jena; import java.io.InputStream; import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.util.FileManager; public class test
{
public static void main(String args[])
{
//String inputFileName = "E:\\Pattern Mining\\test.rdf";
//String inputFileName = "E:\\Pattern Mining\\test.nt";
String inputFileName = "E:\\ChEMBL\\cco.ttl"; Model model = ModelFactory.createDefaultModel(); InputStream in = FileManager.get().open(inputFileName);
if (in == null)
{
throw new IllegalArgumentException("File: " + inputFileName + " not found");
} //model.read(in, "","RDF/XML");//根据文件格式选用参数即可解析不同类型
//model.read(in, "","N3");
model.read(in, "","TTL");
System.out.println("开始");
// list the statements in the graph
StmtIterator iter = model.listStatements(); // print out the predicate, subject and object of each statement
while (iter.hasNext())
{
Statement stmt = iter.nextStatement(); // get next statement
//Resource subject = stmt.getSubject(); // get the subject
//Property predicate = stmt.getPredicate(); // get the predicate
//RDFNode object = stmt.getObject(); // get the object String subject = stmt.getSubject().toString(); // get the subject
String predicate = stmt.getPredicate().toString(); // get the predicate
RDFNode object = stmt.getObject(); // get the object System.out.print("主语 " + subject+"\t");
System.out.print(" 谓语 " + predicate+"\t");
if (object instanceof Resource)
{
System.out.print(" 宾语 " + object);
}
else {// object is a literal
System.out.print("宾语 \"" + object.toString() + "\"");
}
System.out.println(" .");
}
}
}
运行结果
主语 http://rdf.ebi.ac.uk/terms/chembl#NonMolecular 谓语 http://www.w3.org/2004/02/skos/core#prefLabel 宾语 "ChEMBL NonMolecular Class^^http://www.w3.org/2001/XMLSchema#string" .
主语 http://rdf.ebi.ac.uk/terms/chembl#NonMolecular 谓语 http://www.w3.org/2000/01/rdf-schema#subClassOf 宾语 http://rdf.ebi.ac.uk/terms/chembl#Target .
主语 http://rdf.ebi.ac.uk/terms/chembl#NonMolecular 谓语 http://www.w3.org/2000/01/rdf-schema#label 宾语 "ChEMBL NonMolecular Class^^http://www.w3.org/2001/XMLSchema#string" .
主语 http://rdf.ebi.ac.uk/terms/chembl#NonMolecular 谓语 http://www.w3.org/1999/02/22-rdf-syntax-ns#type 宾语 http://www.w3.org/2002/07/owl#Class .
主语 http://rdf.ebi.ac.uk/terms/chembl#PubchemThomPharmRef 谓语 http://www.w3.org/2004/02/skos/core#prefLabel 宾语 "Pubchem Thomson Pharma Subset Cross Reference^^http://www.w3.org/2001/XMLSchema#string" .
主语 http://rdf.ebi.ac.uk/terms/chembl#PubchemThomPharmRef 谓语 http://www.w3.org/2000/01/rdf-schema#subClassOf 宾语 http://rdf.ebi.ac.uk/terms/chembl#MoleculeDbRef .
主语 http://rdf.ebi.ac.uk/terms/chembl#PubchemThomPharmRef 谓语 http://www.w3.org/2000/01/rdf-schema#label 宾语 "Pubchem Thomson Pharma Subset Cross Reference^^http://www.w3.org/2001/XMLSchema#string" .
主语 http://rdf.ebi.ac.uk/terms/chembl#PubchemThomPharmRef 谓语 http://www.w3.org/1999/02/22-rdf-syntax-ns#type 宾语 http://www.w3.org/2002/07/owl#Class .
主语 http://rdf.ebi.ac.uk/terms/chembl#Activity 谓语 http://www.w3.org/2004/02/skos/core#prefLabel 宾语 "ChEMBL Activity Class^^http://www.w3.org/2001/XMLSchema#string" .
主语 http://rdf.ebi.ac.uk/terms/chembl#Activity 谓语 http://www.w3.org/2000/01/rdf-schema#subClassOf 宾语 http://rdf.ebi.ac.uk/terms/chembl#ChEMBL .
主语 http://rdf.ebi.ac.uk/terms/chembl#Activity 谓语 http://www.w3.org/2000/01/rdf-schema#label 宾语 "ChEMBL Activity Class^^http://www.w3.org/2001/XMLSchema#string" .
主语 http://rdf.ebi.ac.uk/terms/chembl#Activity 谓语 http://www.w3.org/1999/02/22-rdf-syntax-ns#type 宾语 http://www.w3.org/2002/07/owl#Class .
主语 http://rdf.ebi.ac.uk/terms/chembl#assaySubCellFrac 谓语 http://www.w3.org/2004/02/skos/core#prefLabel 宾语 "ChEMBL Assay Subcellular Fraction ^^http://www.w3.org/2001/XMLSchema#string" .
主语 http://rdf.ebi.ac.uk/terms/chembl#assaySubCellFrac 谓语 http://purl.org/dc/elements/1.1/description 宾语 "Name of subcellular fraction used in the assay system (e.g., microsomes, mitochondria).^^http://www.w3.org/2001/XMLSchema#string" .
主语 http://rdf.ebi.ac.uk/terms/chembl#assaySubCellFrac 谓语 http://www.w3.org/2000/01/rdf-schema#range 宾语 http://www.w3.org/2001/XMLSchema#string .
主语 http://rdf.ebi.ac.uk/terms/chembl#assaySubCellFrac 谓语 http://www.w3.org/2000/01/rdf-schema#label 宾语 "ChEMBL Assay Subcellular Fraction ^^http://www.w3.org/2001/XMLSchema#string" .
主语 http://rdf.ebi.ac.uk/terms/chembl#assaySubCellFrac 谓语 http://www.w3.org/2000/01/rdf-schema#domain 宾语 http://rdf.ebi.ac.uk/terms/chembl#Assay .
主语 http://rdf.ebi.ac.uk/terms/chembl#assaySubCellFrac 谓语 http://www.w3.org/1999/02/22-rdf-syntax-ns#type 宾语 http://www.w3.org/2002/07/owl#DatatypeProperty .
主语 -71367f46:15678e1eebc:-7ffb 谓语 http://www.w3.org/1999/02/22-rdf-syntax-ns#rest 宾语 -71367f46:15678e1eebc:-7ffa .
主语 -71367f46:15678e1eebc:-7ffb 谓语 http://www.w3.org/1999/02/22-rdf-syntax-ns#first 宾语 http://rdf.ebi.ac.uk/terms/chembl#Source .
主语 http://rdf.ebi.ac.uk/terms/chembl#FabPrime 谓语 http://www.w3.org/2004/02/skos/core#prefLabel 宾语 "ChEMBL FabPrime Class^^http://www.w3.org/2001/XMLSchema#string" .
主语 http://rdf.ebi.ac.uk/terms/chembl#FabPrime 谓语 http://purl.org/dc/elements/1.1/description 宾语 "Fragment, antigen-binding, including hinge region (one arm)^^http://www.w3.org/2001/XMLSchema#string" .
主语 http://rdf.ebi.ac.uk/terms/chembl#FabPrime 谓语 http://www.w3.org/2000/01/rdf-schema#subClassOf 宾语 http://rdf.ebi.ac.uk/terms/chembl#Antibody .
主语 http://rdf.ebi.ac.uk/terms/chembl#FabPrime 谓语 http://www.w3.org/2000/01/rdf-schema#label 宾语 "ChEMBL FabPrime Class^^http://www.w3.org/2001/XMLSchema#string" .
主语 http://rdf.ebi.ac.uk/terms/chembl#FabPrime 谓语 http://www.w3.org/1999/02/22-rdf-syntax-ns#type 宾语 http://www.w3.org/2002/07/owl#Class .
Jena解析rdf、nt、ttl格式数据的更多相关文章
- app开发历程————Android程序解析服务器端的JSON格式数据,显示在界面上
上一篇文章写的是服务器端利用Servlet 返回JSON字符串,本文主要是利用android客户端访问服务器端链接,解析JSON格式数据,放到相应的位置上. 首先,android程序的布局文件main ...
- 使用Python解析豆瓣上Json格式数据
现在的API接口多为xml或json,json解析更简洁相对xml来说 以豆瓣的API接口为例,解析返回的json数据: https://api.douban.com/v2/book/1220562 ...
- 实例解析嵌套的JSON格式数据
关于JSON数据格式的基本知识和概念,参看: http://www.cnblogs.com/zouzf/archive/2012/03/31/2426646.html <span style=& ...
- Python解析Yahoo的XML格式的天气预报数据
以下是Yahoo天气预报接口xml格式数据: <rss xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xm ...
- iOS开发之JSON格式数据的生成与解析
本文将从四个方面对IOS开发中JSON格式数据的生成与解析进行讲解: 一.JSON是什么? 二.我们为什么要用JSON格式的数据? 三.如何生成JSON格式的数据? 四.如何解析JSON格式的数据? ...
- 解析json格式数据
实现目标 读取文件中的json格式数据,一行为一条json格式数据.进行解析封装成实体类. 通过google的Gson对象解析json格式数据 我现在解析的json格式数据为: {",&qu ...
- 实现android上解析Json格式数据功能
实现android上解析Json格式数据功能,该源码转载于安卓教程网的,http://android.662p.com ,个人感觉还不错的,大家可以看看一下吧. package com.practic ...
- ini格式数据生成与解析具体解释
ini格式数据生成与解析具体解释 1.ini格式数据长啥样? watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/ ...
- JSON(三)——java中对于JSON格式数据的解析之json-lib与jackson
java中对于JSON格式数据的操作,主要是json格式字符串与JavaBean之间的相互转换.java中能够解析JSON格式数据的框架有很多,比如json-lib,jackson,阿里巴巴的fast ...
随机推荐
- windows的gvim总是报错: +iconv fencview.vim
iconv是用来转换gvim文件的编码的, 需要插件: iconv.dll gvim7.3的文件目录结构: vim/vim73是它的核心文件, 而vimfiles是扩展文件, 里面的plugin是专门 ...
- lightoj 1341 Aladdin and the Flying Carpet(算术基本定理)题解
题意:给一个矩形(非正方形)面积a和最小边长b,要求边长均大于b,求这样的矩形有几个 思路:先用到了之前学的质因数分解,还有一个新的公式: 然后我们可以先算出a的所有约数,因为只算约数个数面积重复,所 ...
- MongoDB树形结构表示法
http://docs.mongodb.org/manual/tutorial/model-tree-structures/ MongoDB五种树形结构表示法 第一种:父链接结构 db.categor ...
- 【TCP/IP详解 卷一:协议】第十七章 TCP:传输控制协议
本章作为TCP的入门章节,简单的概述了一些TCP的知识,和TCP数据报的首部格式. TCP 最重要的特性:reliable. 17.1 引言 本章介绍的是 TCP为应用层提供的服务. 17.2 TCP ...
- 【Django】【待解决问题】
1. from Crypto.Cipher import AES File "/Library/Frameworks/Python.framework/Versions/3.5/lib/py ...
- Jmeter 中Cookie管理器的使用
Jmeter中有好几个地方可以管理Cookie,比如 Http Cookie Manager HTTP Header Manager jmeter.property文件中: #CookieManage ...
- 测试报告 之 testNG + Velocity 编写自定义html测试报告
之前用testNG自带的test-outputemailable-report.html,做出的UI自动化测试报告,页面不太好看. 在网上找到一个新的报告编写,自己尝试了一下,埋了一些坑,修改了输出时 ...
- vuejs2点滴
在Vue定义一个不被添加getter setter 的属性: https://github.com/vuejs/vue/issues/1988 博客: 0.vux的x-input源码分析. http: ...
- SpringBoot读取war包jar包Resource资源文件解决办法
SpringBoot读取war包jar包Resource资源文件解决办法 场景描述 在开发过程中我们经常会碰到要在代码中获取资源文件的情况,而我在最近在SpringBoot项目中时碰到一个问题,就是在 ...
- jsp / get 中文乱码问题
POST 方式下的解决方式还算简单,因为POST 方式下提交的数据都是以二进制的方式附加在http请求的body部分发送,只需要在后台指定编码格式就足矣解决. GET 方式下会将参数直接附加到url ...