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 ...
随机推荐
- 2016年蓝桥杯B组C/C++省赛(预选赛)试题
2016年蓝桥杯B组C/C++ 点击查看2016年蓝桥杯B组省赛题目解析(答案) 第一题:煤球数目 有一堆煤球,堆成三角棱锥形.具体: 第一层放1个, 第二层3个(排列成三角形), 第三层6个(排列成 ...
- Planar Shadow
Unity上平面阴影的计算与实现 //如何求顶点投影到平面上的点(阴影点) //当平面上取不相等的任意两个点组成一个向量,与平面的法线总是垂直的,向量垂直点乘为0,因此可以通过一个点和一个法线来定义, ...
- jekins,报错 stderr: Could not create directory '/usr/share/tomcat7/.ssh'. Failed to add the host to the list of
public key是在~/.ssh/id_rsa.pub,而private key是~/.ssh/id_rsa 设置的时候,Jenkins需要的是private key
- stack_01
A.添加/移除 A.1.void stack::push(elemValue); // 栈头 添加元素 A.2.void stack::pop(); // 栈头 移除第一个元素 B.随机存取 C.数据 ...
- deque_01
A.头尾 添加/移除 A.1.deque::push_back(elemValue); A.2.deque::pop_back(); A.3.deque::push_front(elemValue); ...
- [原][osg][osgEarth]关于在OE中使用物理引擎的调研
关于物理引擎旋转的一些整理 参考文档 http://blog.wolfire.com/2010/03/Comparing-ODE-and-Bullet 介绍ODE和bullet的利弊 http://s ...
- ubuntu 常用设置
●1 问题:使用virt-manager创建虚拟机时,Virtual network 'default':NAT(Inactive) 解决方法:1,查看网络状态sudo virsh net-list ...
- Codeforces 447C - DZY Loves Sequences
447C - DZY Loves Sequences 思路:dp 代码: #include<bits/stdc++.h> using namespace std; #define ll l ...
- Paket介绍
在国外.NET社区有一个很火的话题是Packet(https://fsprojects.github.io/Paket/index.html ),它本质上是Nuget 之外的另一种方式管理.NET项目 ...
- ngIf 和 template的结合使用
前提: 当遇到 一个种情况,一个元素中既可以显示 一个字符串变量,也可以显示一个模板 实现: // html <span class="ant-alert-message" ...