2012-06-14 37 views
0

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

我的问题是,有时我只需要实例化本体的一个概念。自从在耶拿,我感到困惑,我们需要一个完整的陈述来实例化一个本体。

假设我有以下本体论。

enter image description here

什么是声明对本体例如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> 

感谢您的回复!

回答

1

你是正确的,在RDF您存储的语句,而不是单个术语或概念。 然而任何事物都有一个类型,即使它只是rdfs:Resource(或猫头鹰通常owl: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); 

甚至更​​好使用耶拿本体API:

OntClass eventTypeResource = ontModel.createClass(eventTypeURI); 

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

耶拿提供这是一个不错的introduction to the ontology api

+0

嗨,我试试你的下面的代码'资源eventTypeResource = model.createResource(eventTypeURI); model.add(eventTypeResource,RDF.type,OWL.class);',它运行良好,但他的结果是向ontologie添加新闻(自动发现的)类。我想要这样的'model.add(eventTypeResource,RDF.object,model.getOntClass('Event'));'。实现班级“事件”的对象。感谢您的回复 ! –

+0

啊,我明白了。然后,只需使用'model.add(eventTypeResource,RDF.type,model.getOntClass(eventURI));'或简单地'model.createIndividual(model.getOntClass(eventURI))'(在ont api中)。 – user205512

+0

我试过这个代码,但他们仍然没有使用错误'resource = domainModel.createResource(xmlbase +“frame”+ frameNum); domainModel.add(resource,RDF.type,domainModel.getOntClass(“Event”)) ;'什么可能是写代码?谢谢你的时间! –

1

很难做到准确,因为你没有提供数据或本体论(所以我们不能尝试你的代码)。然而,这是很可能,这就是问题所在:

domainModel.getOntClass("Event") 

"Event"不是一个URI,所以它是不太可能,你的本体论这个名字的事件类(如果是的话,你应该改变它改为使用完整的URI!)。

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

domainModel.getOntClass(EVENT_NS + "Event")