比如有一个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格式数据的更多相关文章

  1. app开发历程————Android程序解析服务器端的JSON格式数据,显示在界面上

    上一篇文章写的是服务器端利用Servlet 返回JSON字符串,本文主要是利用android客户端访问服务器端链接,解析JSON格式数据,放到相应的位置上. 首先,android程序的布局文件main ...

  2. 使用Python解析豆瓣上Json格式数据

    现在的API接口多为xml或json,json解析更简洁相对xml来说 以豆瓣的API接口为例,解析返回的json数据: https://api.douban.com/v2/book/1220562 ...

  3. 实例解析嵌套的JSON格式数据

    关于JSON数据格式的基本知识和概念,参看: http://www.cnblogs.com/zouzf/archive/2012/03/31/2426646.html <span style=& ...

  4. Python解析Yahoo的XML格式的天气预报数据

    以下是Yahoo天气预报接口xml格式数据: <rss xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xm ...

  5. iOS开发之JSON格式数据的生成与解析

    本文将从四个方面对IOS开发中JSON格式数据的生成与解析进行讲解: 一.JSON是什么? 二.我们为什么要用JSON格式的数据? 三.如何生成JSON格式的数据? 四.如何解析JSON格式的数据? ...

  6. 解析json格式数据

    实现目标 读取文件中的json格式数据,一行为一条json格式数据.进行解析封装成实体类. 通过google的Gson对象解析json格式数据 我现在解析的json格式数据为: {",&qu ...

  7. 实现android上解析Json格式数据功能

    实现android上解析Json格式数据功能,该源码转载于安卓教程网的,http://android.662p.com ,个人感觉还不错的,大家可以看看一下吧. package com.practic ...

  8. ini格式数据生成与解析具体解释

    ini格式数据生成与解析具体解释 1.ini格式数据长啥样? watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/ ...

  9. JSON(三)——java中对于JSON格式数据的解析之json-lib与jackson

    java中对于JSON格式数据的操作,主要是json格式字符串与JavaBean之间的相互转换.java中能够解析JSON格式数据的框架有很多,比如json-lib,jackson,阿里巴巴的fast ...

随机推荐

  1. UNIX系统的显示时间何时会到尽头

    本文转载自:http://www.cnblogs.com/dfcao/p/expertCprogramming_intr0.html 本文分为三个小块: 一.UNIX系统中时间的存储形式: 二. ti ...

  2. win7下把电脑设置成wlan热

    有很多公司没有无线网,只有自己的电脑可以上网,现在设置热点,可以手机上网 步骤: 1.看自己的网卡是否支持承载网络,如果不支持,本法就不适用 在CMD里用    netsh wlan show dri ...

  3. 织梦dedecms多选checkbox字段值独立输出样式调用方法

    在做织梦网站时发现dedecms的自建字段的checkboxcook输出是一段证不能把每个标签分开写样式,在晚上查了好多没页没有好的,最终用中方式来做会好 {dede:field.fyuantese ...

  4. Luogu P1533 可怜的狗狗

    题目链接:https://www.luogu.org/problemnew/show/P1533 没人写$fhq\ treap$做法,那我就补一篇qwq 看到这题第一时间想主席树,然后发现我还没学主席 ...

  5. [BZOJ1103][POI2007]大都市meg dfs序+树状数组

    Description 在经济全球化浪潮的影响下,习惯于漫步在清晨的乡间小路的邮递员Blue Mary也开始骑着摩托车传递邮件了.不过,她经常回忆起以前在乡间漫步的情景.昔日,乡下有依次编号为1..n ...

  6. 2018 Machine Learning

    2018/8/13 线性模型(西瓜书P53~P73) Optimizer https://blog.csdn.net/u012151283/article/details/78154917 2018/ ...

  7. 4、CommonChunkPlugin提取公共js-提取多个

    cnpm install css-loader --save-dev    //css-loader 是将css打包进js cnpm install style-loader --save-dev   ...

  8. CSS3屏幕密集媒体查询

    html { font-size: 50px; } body { font-size: 24px; } @media screen and (max-width: 359px) { html { fo ...

  9. 机器学习-数据可视化神器matplotlib学习之路(五)

    这次准备做一下pandas在画图中的应用,要做数据分析的话这个更为实用,本次要用到的数据是pthon机器学习库sklearn中一组叫iris花的数据,里面组要有4个特征,分别是萼片长度.萼片宽度.花瓣 ...

  10. URL重写与URL路由

    要介绍这两个内容,必须要从ASP.NET管线说起. ASP.NET管线 管线(Pipeline)这个词形象地说明了每个Asp.net请求的处理过程: 请求是在一个管道中,要经过一系列的过程点,这些过程 ...