比如有一个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. 完整的Android开发环境Eclipse+ADT+SDK(22.0.1)

    现在开始学习Android嵌入式编程,首要的问题就是在Windows中搭建开发环境,就这个都要摸索很长的时间,总是在版本之间折腾折腾去,而且Google的Android正式差劲得很,经常是连不上,要不 ...

  2. dp暑假专题 训练记录

    A 回文串的最小划分 题意:给出长度不超过1000的字符串,把它分割成若干个回文字串,求能分成的最少字串数. #include <iostream> #include <cstdio ...

  3. LeetCode——Find Bottom Left Tree Value

    Question Given a binary tree, find the leftmost value in the last row of the tree. Example 1: Input: ...

  4. js媒体查询设置根字号

    !function(n){var e=n.document,t=e.documentElement,i=750,d=i/50,o="orientationchange"in n?& ...

  5. HDU 5876 Sparse Graph(补图中求最短路)

    http://acm.hdu.edu.cn/showproblem.php?pid=5876 题意: 在补图中求s到其余各个点的最短路. 思路:因为这道题目每条边的距离都是1,所以可以直接用bfs来做 ...

  6. HDU 1686 Oulippo

    http://acm.hdu.edu.cn/showproblem.php?pid=1686 题意:给定一个文本串和给定一个模式串,求文本串中有几个模式串. 思路:直接套用KMP模板. #includ ...

  7. UVa 1471 防线

    https://vjudge.net/problem/UVA-1471 题意:给出一个序列,删除一个连续子序列,使得剩下的序列中有一个长度最大的连续递增子序列,输出个数. 思路:首先可以计算出以i结尾 ...

  8. python 处理命令行参数--转载

    标题写了那么久,现在现在才有时间,整理下自己的思路.首先先总结下自己对sys模块的理解.手册上对sys的描述是系统参数和系统函数,这里的系统实际上是python解释器.这个模块提供了用户可以访问的解释 ...

  9. GBDT 简述

    GBDT 全称 Gradient Boosting Decision Tree,梯度提升决策树. 梯度增强决策树的思想来源于两个地方,首先是增强算法(Boosting),然后是梯度增强(Gradien ...

  10. Codeforces Beta Round #94 div 1 D Numbers map+思路

    D. Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...