1

我正在研究如何使用 Jena 自动实例化一个本体。我对实例化从一组数据中发现的概念感兴趣。

我的问题是,有时我只需要实例化本体的一个概念。我很困惑,因为在耶拿,我们需要一个完整的语句来实例化一个本体。

假设我有以下本体。

在此处输入图像描述

例如,仅在本体上实例化一个概念的陈述是什么EventType

是否有必要Statement实例化一个本体?

还是我的本体不够表达?

版本:我的耶拿代码

public static void manageOntologies() throws FileNotFoundException{     

    int i,inFrame, lineSize;
    int frameNum = 0;

    Individual individu;
    Resource   resource;
    Statement  statement;
    OntModel   domainModel;

    Vector<String> lines = readFile("data/Trace.dat");

    String[] parts = null;
    String   event = null;

    domainModel = ModelFactory.createOntologyModel(ProfileRegistry.OWL_DL_LANG);
    domainModel.read((new FileInputStream(ontopath)), null);

    lineSize = lines.size(); 

    for(i = 0; i < lineSize; i++){
        parts = lines.elementAt(i).split(" ");
        event = parts[parts.length - 1];            
        resource = domainModel.createResource(xmlbase + "frame" + frameNum);//, domainModel.getOntClass(xmlbase + "Event"));
        domainModel.add(resource, RDF.type, domainModel.getOntClass("Event"));

    }

    System.out.println("Numbre de frame = " + frameNum);

    domainModel.write(System.out);
}

这是遇到的问题

Exception in thread "main" java.lang.NullPointerException
    at com.hp.hpl.jena.rdf.model.impl.ModelCom.add(ModelCom.java:929)
    at soctrace.Intology.manageOntologies(Intology.java:87) -- domainModel.add(...)
    at soctrace.Intology.main(Intology.java:38)

第 2 版:我的 OWL/XML 代码

<?xml version="1.0"?>
<!DOCTYPE rdf:RDF [
    <!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
    <!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
    <!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
    <!ENTITY tima "http://www.soctrace.org/ontologies/tima.owl#" >
]>


<rdf:RDF xmlns="http://www.w3.org/2002/07/owl#"
     xml:base="http://www.w3.org/2002/07/owl"
     xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
     xmlns:tima="http://www.soctrace.org/ontologies/tima.owl#"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
    <Ontology rdf:about="http://www.soctrace.org/ontologies/tima.owl">       
</Ontology>


<!-- http://www.soctrace.org/ontologies/tima.owl#Event -->

<Class rdf:about="&tima;Event">
    <rdfs:subClassOf rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
</Class>



<!-- http://www.soctrace.org/ontologies/tima.owl#EventDuration -->

<Class rdf:about="&tima;EventDuration">
    <rdfs:subClassOf rdf:resource="&tima;ValuePartition"/>
</Class>



<!-- http://www.soctrace.org/ontologies/tima.owl#EventType -->

<Class rdf:about="&tima;EventType">
    <rdfs:subClassOf rdf:resource="&tima;ValuePartition"/>
</Class>



<!-- http://www.soctrace.org/ontologies/tima.owl#ValuePartition -->

    <Class rdf:about="&tima;ValuePartition"/>
</rdf:RDF>

感谢您的回复!

4

2 回答 2

2

您是正确的,您在 RDF 中存储语句,而不是单个术语或概念。然而,一切都有一个类型,即使它只是rdfs:Resource(或通常在 owlowl:Individualowl:Class)。因此,你们总是通过表单的声明添加一些东西thing rdf:type Type,只需选择适当的类型。

在这种情况下想必EventType是一个类?在这种情况下:

Resource eventTypeResource = model.createResource(eventTypeURI);
model.add(eventTypeResource, RDF.type, OWL.class);

但是,这是您可以使用的常见模式:

Resource eventTypeResource = model.createResource(eventTypeURI, OWL.class);

甚至更好地使用 Jena 本体 API:

OntClass eventTypeResource = ontModel.createClass(eventTypeURI);

OntClass仍然是一个Resource,但添加了一些非常有用的方法)

Jena 很好地介绍了本体 api

于 2012-06-14T11:02:40.200 回答
2

很难准确,因为您没有提供数据或本体(因此我们无法尝试您的代码)。但是,这很可能是问题所在:

domainModel.getOntClass("Event")

"Event"不是 URI,因此您的本体不太可能具有该名称的事件类(如果有,您应该将其更改为使用完整的 URI!)。

您将需要提供完整的 URI getOntClass,否则它将返回null,因为它无法识别该类。假设您为 提供合适的值EVENT_NS,则:

domainModel.getOntClass( EVENT_NS + "Event")
于 2012-06-14T23:43:21.270 回答