如何在耶拿使用cidoc-crm [英] how to use cidoc-crm in jena

查看:59
本文介绍了如何在耶拿使用cidoc-crm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我正在尝试使用Jena来创建语义Web以创建RDF并进行查询.现在,我已经在耶拿成功制作了一个基于猫头鹰的RDF文件.但是,当我尝试使用其他本体(例如cidoc-crm)时,我不知道如何将这些本体导入到Jena.有人知道如何将其导入到Jena吗?我需要创建一个新的本体模型吗?

Recently, I'm trying to approach semantic web using Jena to create RDF and make query. Now, I have successfully made a owl based RDF file in Jena. However, when I trying to use different ontologies (such as: cidoc-crm), I do not know how to import those ontologies to Jena. Does anyone know how to import them to Jena? Do I need to create a new ontology model?

推荐答案

Jena的

Jena's OntModel interface provides a convenient way of working with ontologies (including RDFS ontologies). The following code shows how you can get an OntModel that contains the data of the ontology. In this code, I then create another OntModel with inference support that includes the CIDOC model that I created. With the inferencing model, it is easy to create individuals and see computed types for them, or see subclass relationships derived by the inference model.

import com.hp.hpl.jena.ontology.Individual;
import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;

public class CIDOCExample {

    final static String CIDOCNS = "http://www.cidoc-crm.org/cidoc-crm/";

    public static void main( String[] args ) {
        // Load the CIDOC-CRM into an OntModel.  We won't add any reasoning capability to this model, but
        // we'll use it as a submodel of OntModels that do.  Jena can pull the document from the web, but
        // you could also download a local copy and read that.  It would certainly a bit quicker than 
        // downloading it every time.
        final OntModel cidocModel = ModelFactory.createOntologyModel( OntModelSpec.RDFS_MEM );
        cidocModel.read( "http://www.cidoc-crm.org/rdfs/cidoc_crm_v5.1-draft-2013May.rdfs" );

        // Create an OntModel that imports the cidocModel, and give it inference support.
        final OntModel model = ModelFactory.createOntologyModel( OntModelSpec.RDFS_MEM_RDFS_INF );
        model.addSubModel( cidocModel );

        // Retrieve a class from the OntModel and shows its subclasses.
        final OntClass e5_event = model.getOntClass( CIDOCNS+"E5_Event" );
        System.out.println( "Subclasses of E5_Event:" );
        for ( final ExtendedIterator<OntClass> it = e5_event.listSubClasses(); it.hasNext() ;) {
            System.out.println( "\t* "+it.next() );
        }

        // Create your own instance data in an OntModel that imports the cidocModel
        final Individual someJoining = model.createIndividual( "http://example.org/someJoining", cidocModel.getOntClass( CIDOCNS+"E85_Joining"));
        System.out.println( "Types of "+someJoining );
        for ( final ExtendedIterator<Resource> types = someJoining.listRDFTypes(false); types.hasNext(); ) {
            System.out.println( "\t* "+types.next() );
        }
    }
}

使用OntModel.getOntClass(CIDCOCNS+"...")获取类有点笨拙,而且很容易打错字.耶拿(Jena)提供了一个出色的 schemagen 工具,该工具采用本体并生成一类常量,该常量可以表示本体中声明的类,属性和个人.例如,您可以使用schemagen创建一个CIDOC类,例如,为E5_Event提供一个常量OntClass对象,以便代替

Having to obtain the classes using OntModel.getOntClass(CIDCOCNS+"...") is a bit clumsy, and it's very easy to make a typo. Jena provides an excellent schemagen tool that takes an ontology and generates a class of constants that represent the classes, properties, and individuals declared in the ontology. For instance, you could use schemagen to create a CIDOC class with, e.g., a constant OntClass object for E5_Event so that instead of

final OntClass e5_event = model.getOntClass( CIDOCNS+"E5_Event" );
System.out.println( "Subclasses of E5_Event:" );
for ( final ExtendedIterator<OntClass> it = e5_event.listSubClasses(); it.hasNext() ;) {
  System.out.println( "\t* "+it.next() );
}

您可以做到

System.out.println( "Subclasses of E5_Event:" );
for ( final ExtendedIterator<OntClass> it = CIDOC.E5_Event.inModel( model ).listSubClasses(); it.hasNext() ;) {
  System.out.println( "\t* "+it.next() );
}

这篇关于如何在耶拿使用cidoc-crm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆