二、jena解析关于基因的go.owl文件(创建、新增复杂类)

本文介绍了一个具体的OWL源码实例,展示了如何通过Java程序操作OWL文件,包括创建类、属性及添加相关信息,并给出了程序实现的具体代码及最终的OWL文件修改结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.go.owl源码

<owl:Class rdf:about="http://purl.obolibrary.org/obo/GO_0045019">
    <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 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;

public class Insert2 {

    public static void main(String args[]) throws FileNotFoundException{
        final 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#";
        //新建类
        OntClass ontClass = ontModel.createClass(OBO+"GO_0045019");

        //新建property
        AnnotationProperty p = ontModel.createAnnotationProperty(OBO+"IAO_0000115");
        p.addLabel("definition", "");

        Property p1 = ontModel.createProperty(OBOINOWL+"id");
        Property p2 = ontModel.createProperty(OBOINOWL+"hasOBONamespace");
        Property p3 = ontModel.createProperty(OBOINOWL+"hasExactSynonym");

        ontClass.addProperty(p, "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.");
        ontClass.addProperty(p1, "GO:0045019");
        ontClass.addProperty(p2, "biological_process");
        ontClass.addProperty(p3, "down regulation of nitric oxide biosynthetic process");

        ontModel.write(new FileOutputStream("f://go-minus1.owl"));
    }

}

3.实现结果

 <owl:Class rdf:about="http://purl.obolibrary.org/obo/GO_0045019">
    <oboInOwl:hasExactSynonym>down regulation of nitric oxide biosynthetic process</oboInOwl:hasExactSynonym>
    <oboInOwl:hasOBONamespace>biological_process</oboInOwl:hasOBONamespace>
    <oboInOwl:id>GO:0045019</oboInOwl:id>
    <obo:IAO_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.</obo:IAO_0000115>
  </owl:Class>

  <owl:AnnotationProperty rdf:about="http://purl.obolibrary.org/obo/IAO_0000115">
    <rdfs:label>definition</rdfs:label>
  </owl:AnnotationProperty>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值