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 ...
随机推荐
- BZOJ2818: Gcd 欧拉函数
Description 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. Input 一个整数N Output 如题 Sample Input 4 Sam ...
- BZOJ1045 [HAOI2008]糖果传递 && BZOJ3293 [Cqoi2011]分金币
Description 有n个小朋友坐成一圈,每人有ai个糖果.每人只能给左右两人传递糖果.每人每次传递一个糖果代价为1. Input 第一行一个正整数nn<=1'000'000,表示小朋友的个 ...
- CVS导出&&自定义Attribute的使用
1.cvs导出:List转为byte[] /// <summary> /// CvsExport帮助类 /// </summary> public static class C ...
- hdu 1796 How many integers can you find 容斥定理
How many integers can you find Time Limit: 12000/5000 MS (Java/Others) Memory Limit: 65536/32768 ...
- ZC_C++类函数指针_模拟_Delphi类函数指针_Qt例子
qt-opensource-windows-x86-msvc2010_opengl-5.3.2.exe ZC: “const QString” 作传入参数的时候,不太会弄... 貌似 还是在进行构建等 ...
- Android中getLocationOnScreen和getLocationInWindow 获取屏幕大小
需要确定组件在父窗体中的坐标时,使用getLocationInWindow,需要获得组件在整个屏幕的坐标时,使用getLocationOnScreen. 其中location [0]代表x坐标,loc ...
- 【Golang 接口自动化07】struct转map的三种方式
背景 我们在前面介绍过怎么使用net/http发送json或者map数据,那么它能不能直接发送结构体数据呢?我们今天一起来学习结构体struct转map的三种方法,为后续做铺垫. struct转map ...
- 丑数问题 Ugly Number
2018-07-28 15:30:21 一.判断是否为丑数 问题描述: 问题求解: 所谓丑数,首先得是正数,然后其质数因子只包含了2,3,4,因此我们只需要对当前的数分别除2,3,4直到不能除为止. ...
- 用Omniauth来Login with Facebook(Go-rails课程)
https://gorails.com/episodes/login-with-facebook?autoplay=1 大概看了一遍,留了视频的截图. https://gorails.com/epis ...
- 玲珑杯 ACM热身赛 #2.5 A 记忆化搜索+瞎搞
#include <cstdio> #include <vector> #include <iostream> #include <algorithm> ...