三、jena解析关于基因的go.owl文件(读取信息)
来源:互联网 发布:花生壳域名打不开 编辑:程序博客网 时间:2024/05/29 04:52
1.读取源文件
<owl:Class rdf:about="http://purl.obolibrary.org/obo/GO_0045019"> <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">negative regulation of nitric oxide biosynthetic process</rdfs:label> <rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/GO_0031327"/> <rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/GO_0045428"/> <rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/GO_1903427"/> <rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/GO_1904406"/> <obo:IAO_0000115 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Any process that stops, prevents, or reduces the frequency, rate or extent of the chemical reactions and pathways resulting in the formation of nitric oxide.</obo:IAO_0000115> <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">GO:0045019</oboInOwl:id> <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">biological_process</oboInOwl:hasOBONamespace> <oboInOwl:hasExactSynonym rdf:datatype="http://www.w3.org/2001/XMLSchema#string">down regulation of nitric oxide biosynthetic process</oboInOwl:hasExactSynonym> <oboInOwl:hasExactSynonym rdf:datatype="http://www.w3.org/2001/XMLSchema#string">down-regulation of nitric oxide biosynthetic process</oboInOwl:hasExactSynonym> <oboInOwl:hasExactSynonym rdf:datatype="http://www.w3.org/2001/XMLSchema#string">downregulation of nitric oxide biosynthetic process</oboInOwl:hasExactSynonym> <oboInOwl:hasNarrowSynonym rdf:datatype="http://www.w3.org/2001/XMLSchema#string">inhibition of nitric oxide biosynthetic process</oboInOwl:hasNarrowSynonym> <oboInOwl:hasExactSynonym rdf:datatype="http://www.w3.org/2001/XMLSchema#string">negative regulation of nitric oxide anabolism</oboInOwl:hasExactSynonym> <oboInOwl:hasExactSynonym rdf:datatype="http://www.w3.org/2001/XMLSchema#string">negative regulation of nitric oxide biosynthesis</oboInOwl:hasExactSynonym> <oboInOwl:hasExactSynonym rdf:datatype="http://www.w3.org/2001/XMLSchema#string">negative regulation of nitric oxide formation</oboInOwl:hasExactSynonym> <oboInOwl:hasExactSynonym rdf:datatype="http://www.w3.org/2001/XMLSchema#string">negative regulation of nitric oxide synthesis</oboInOwl:hasExactSynonym> </owl:Class>
2.实现程序
package test;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.util.Iterator;import org.apache.jena.ontology.AnnotationProperty;import org.apache.jena.ontology.OntClass;import org.apache.jena.ontology.OntModel;import org.apache.jena.ontology.OntModelSpec;import org.apache.jena.rdf.model.ModelFactory;import org.apache.jena.rdf.model.Property;import org.apache.jena.rdf.model.impl.LiteralImpl;public class Query { public static void main(String args[]) throws FileNotFoundException{ OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); ontModel.read(new FileInputStream("f://myowl.owl"), ""); String OBO = "http://purl.obolibrary.org/obo/"; String OBOINOWL = "http://www.geneontology.org/formats/oboInOwl#"; String OWL = "http://www.w3.org/2002/07/owl#"; String RDF = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"; for (Iterator<?> i = ontModel.listClasses(); i.hasNext();) { OntClass c = (OntClass) i.next(); // 返回类型强制转换 if (!c.isAnon()) { // 如果不是匿名类,则打印类的名字 System.out.print("Class:"); System.out.println("localname:"+c.getLocalName()); //读取标签名 System.out.println("标签名:"+c.getLabel("")); //迭代显示当前类的直接父类 for (Iterator<?> it = c.listSuperClasses(); it.hasNext();) { OntClass sp = (OntClass) it.next(); //父类不是匿名类 if (!sp.isAnon()){ String str = c.getModel().getGraph().getPrefixMapping().shortForm(c.getURI())+ "'s superClass is " ; // 获取URI String strSP = sp.getURI(); if(strSP != null){ try{ // 另一种简化处理URI的方法 str = str + ":" + strSP.substring(strSP.indexOf('#')+1); System.out.println("Class" +str); }catch( Exception e ){} } } } // super class ends //一些propery AnnotationProperty p1 = ontModel.createAnnotationProperty(OBO+"IAO_0000115"); Property p2 = ontModel.createProperty(OBOINOWL+"id"); Property p3 = ontModel.createProperty(OBOINOWL+"hasOBONamespace"); Property p4 = ontModel.createProperty(OBOINOWL+"hasExactSynonym"); Property p5 = ontModel.createProperty(OBOINOWL+"hasNarrowSynonym"); System.out.println("IAO_0000115:"+c.getPropertyValue(p1)); System.out.println("id:"+c.getPropertyValue(p2)); System.out.println("hasOBONamespace:"+c.getPropertyValue(p3)); System.out.println("hasNarrowSynonym:"+c.getPropertyValue(p5)); //遍历某个属性p3 for (Iterator<?> j = c.listPropertyValues(p4); j.hasNext();) { LiteralImpl p = (LiteralImpl) j.next(); System.out.println("hasExactSynonym:"+p.getValue().toString()); } System.out.println(); ontModel.write(new FileOutputStream("f://go-minus1.owl")); } } }}
3.显示结果
因为只读取这一段,所以父类没有在owl文件中,无法读取。如果是完整的owl文件,上面的代码则没有问题。
Class:localname:GO_0045019标签名:negative regulation of nitric oxide biosynthetic processIAO_0000115:Any process that stops, prevents, or reduces the frequency, rate or extent of the chemical reactions and pathways resulting in the formation of nitric oxide.id:GO:0045019hasOBONamespace:biological_processhasNarrowSynonym:inhibition of nitric oxide biosynthetic processhasExactSynonym:negative regulation of nitric oxide formationhasExactSynonym:negative regulation of nitric oxide biosynthesishasExactSynonym:down-regulation of nitric oxide biosynthetic processhasExactSynonym:negative regulation of nitric oxide anabolismhasExactSynonym:down regulation of nitric oxide biosynthetic processhasExactSynonym:downregulation of nitric oxide biosynthetic processhasExactSynonym:negative regulation of nitric oxide synthesis
阅读全文
0 0
- 三、jena解析关于基因的go.owl文件(读取信息)
- jena解析关于基因的go.owl文件(正在学习中)
- 一、jena解析关于基因的go.owl文件(正在学习中)
- 二、jena解析关于基因的go.owl文件(创建、新增类、以及一些节点)
- 二、jena解析关于基因的go.owl文件(创建、新增复杂类)
- 利用jena读取owl文件的父子属性以及其他属性
- jena 简单查询(不带推理,直接读取owl文件)
- jena构建本体,读取owl文件,输出owl文件相关知识
- 解析基因的owl文件学习过程,让学习sparql不走弯路。
- 关于jena OWL持久化 Table 'jena.jena_sys_stmt' doesn't exist的解决
- owl jena
- jena读取本体的三种方法
- 一些与OWL相关的推理机的区别(如:Jess、Jena、Pellet等)
- Jena将owl文件持久化到数据库中
- Jena将owl文件持久化到数据库中
- go 读取文件源码解析
- Jena API 在OWL中应用的体会
- 用Jena解析本体Ontology Jena的使用 Jena实例
- RocketMQ 使用案例
- ibatis基本环境搭建
- 如何提高python的运行效率/缩短运行时间
- 排序算法总结
- 数据挖掘
- 三、jena解析关于基因的go.owl文件(读取信息)
- 11
- tensorflow从0.8.0升级到1.4.0
- Oracle正则表达式实战
- OpenCV3.x-OpenCL的糟糕体验
- linux的系统环境安装
- qt msvc2015配置
- html的学习
- bzoj2150 部落战争 二分图匹配