2013-04-13 36 views
3

嗨,我已經創建使用門生(.owl文件)的本體。現在我想導入到一個java程序(使用Eclipse的耶拿)這一點,並創建它的實例(我的意思是,我的本體代表的東西一般情況下,一個國家範圍內的,該實例應該代表一個特定的狀態。) 的進口和需要創造。如何使用耶拿導入.owl文件到Eclipse,並創建它的實例

後來我打算比較用戶輸入(這是包含實例文件)和輸出什麼狀態實例中。

我是新來這個,非常新。所以所有的幫助表示讚賞。

謝謝

貓頭鷹文件的內容如下:

<?xml version="1.0"?> 


<!DOCTYPE rdf:RDF [ 
<!ENTITY owl "http://www.w3.org/2002/07/owl#" > 
<!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 Ontology1365003423152 "http://www.semanticweb.org/ontologies/2013/3/Ontology1365003423152.owl#" > 
]> 


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



<!-- 
/////////////////////////////////////////////////////////////////////////////////////// 
// 
// Datatypes 
// 
/////////////////////////////////////////////////////////////////////////////////////// 
--> 




<!-- 
/////////////////////////////////////////////////////////////////////////////////////// 
// 
// Data properties 
// 
/////////////////////////////////////////////////////////////////////////////////////// 
--> 




<!-- http://www.semanticweb.org/ontologies/2013/3/Ontology1365003423152.owl#HasDuration --> 

<DatatypeProperty rdf:about="&Ontology1365003423152;HasDuration"> 
    <rdf:type rdf:resource="&owl;FunctionalProperty"/> 
    <rdfs:domain rdf:resource="&Ontology1365003423152;Attack"/> 
    <rdfs:range rdf:resource="&xsd;positiveInteger"/> 
</DatatypeProperty> 



<!-- http://www.semanticweb.org/ontologies/2013/3/Ontology1365003423152.owl#HasFlag --> 

<DatatypeProperty rdf:about="&Ontology1365003423152;HasFlag"> 
    <rdf:type rdf:resource="&owl;FunctionalProperty"/> 
    <rdfs:domain rdf:resource="&Ontology1365003423152;Attack"/> 
    <rdfs:range rdf:resource="&xsd;string"/> 
</DatatypeProperty> 



<!-- http://www.semanticweb.org/ontologies/2013/3/Ontology1365003423152.owl#HasProtocol --> 

<DatatypeProperty rdf:about="&Ontology1365003423152;HasProtocol"> 
    <rdf:type rdf:resource="&owl;FunctionalProperty"/> 
    <rdfs:domain rdf:resource="&Ontology1365003423152;Attack"/> 
    <rdfs:range rdf:resource="&xsd;string"/> 
</DatatypeProperty> 



<!-- http://www.semanticweb.org/ontologies/2013/3/Ontology1365003423152.owl#HasService --> 

<DatatypeProperty rdf:about="&Ontology1365003423152;HasService"> 
    <rdf:type rdf:resource="&owl;FunctionalProperty"/> 
    <rdfs:domain rdf:resource="&Ontology1365003423152;Attack"/> 
    <rdfs:range rdf:resource="&xsd;string"/> 
</DatatypeProperty> 



<!-- 
/////////////////////////////////////////////////////////////////////////////////////// 
// 
// Classes 
// 
/////////////////////////////////////////////////////////////////////////////////////// 
--> 




<!-- http://www.semanticweb.org/ontologies/2013/3/Ontology1365003423152.owl#0 --> 

<Class rdf:about="&Ontology1365003423152;0"> 
    <rdfs:subClassOf rdf:resource="&Ontology1365003423152;AttackDuration"/> 
</Class> 



<!-- http://www.semanticweb.org/ontologies/2013/3/Ontology1365003423152.owl#1 --> 

<Class rdf:about="&Ontology1365003423152;1"> 
    <rdfs:subClassOf rdf:resource="&Ontology1365003423152;AttackDuration"/> 
</Class> 



<!-- http://www.semanticweb.org/ontologies/2013/3/Ontology1365003423152.owl#2 --> 

<Class rdf:about="&Ontology1365003423152;2"> 
    <rdfs:subClassOf rdf:resource="&Ontology1365003423152;AttackDuration"/> 
</Class> 



<!-- http://www.semanticweb.org/ontologies/2013/3/Ontology1365003423152.owl#6 --> 

<Class rdf:about="&Ontology1365003423152;6"> 
    <rdfs:subClassOf rdf:resource="&Ontology1365003423152;AttackDuration"/> 
</Class> 



<!-- http://www.semanticweb.org/ontologies/2013/3/Ontology1365003423152.owl#Attack --> 

<Class rdf:about="&Ontology1365003423152;Attack"/> 



<!-- http://www.semanticweb.org/ontologies/2013/3/Ontology1365003423152.owl#AttackDuration --> 

<Class rdf:about="&Ontology1365003423152;AttackDuration"/> 



<!-- http://www.semanticweb.org/ontologies/2013/3/Ontology1365003423152.owl#AttackFlag --> 

<Class rdf:about="&Ontology1365003423152;AttackFlag"/> 



<!-- http://www.semanticweb.org/ontologies/2013/3/Ontology1365003423152.owl#AttackProtocolType --> 

<Class rdf:about="&Ontology1365003423152;AttackProtocolType"/> 



<!-- http://www.semanticweb.org/ontologies/2013/3/Ontology1365003423152.owl#AttackService --> 

<Class rdf:about="&Ontology1365003423152;AttackService"/> 



<!-- http://www.semanticweb.org/ontologies/2013/3/Ontology1365003423152.owl#Domain_u --> 

<Class rdf:about="&Ontology1365003423152;Domain_u"> 
    <rdfs:subClassOf rdf:resource="&Ontology1365003423152;AttackService"/> 
</Class> 



<!-- http://www.semanticweb.org/ontologies/2013/3/Ontology1365003423152.owl#Eco_i --> 

<Class rdf:about="&Ontology1365003423152;Eco_i"> 
    <rdfs:subClassOf rdf:resource="&Ontology1365003423152;AttackService"/> 
</Class> 



<!-- http://www.semanticweb.org/ontologies/2013/3/Ontology1365003423152.owl#Ecr_i --> 

<Class rdf:about="&Ontology1365003423152;Ecr_i"> 
    <rdfs:subClassOf rdf:resource="&Ontology1365003423152;AttackService"/> 
</Class> 



<!-- http://www.semanticweb.org/ontologies/2013/3/Ontology1365003423152.owl#Finger --> 

<Class rdf:about="&Ontology1365003423152;Finger"> 
    <rdfs:subClassOf rdf:resource="&Ontology1365003423152;AttackService"/> 
</Class> 



<!-- http://www.semanticweb.org/ontologies/2013/3/Ontology1365003423152.owl#Ftp_data --> 

<Class rdf:about="&Ontology1365003423152;Ftp_data"> 
    <rdfs:subClassOf rdf:resource="&Ontology1365003423152;AttackService"/> 
</Class> 



<!-- http://www.semanticweb.org/ontologies/2013/3/Ontology1365003423152.owl#Http --> 

<Class rdf:about="&Ontology1365003423152;Http"> 
    <rdfs:subClassOf rdf:resource="&Ontology1365003423152;AttackService"/> 
</Class> 



<!-- http://www.semanticweb.org/ontologies/2013/3/Ontology1365003423152.owl#Icmp --> 

<Class rdf:about="&Ontology1365003423152;Icmp"> 
    <rdfs:subClassOf rdf:resource="&Ontology1365003423152;AttackProtocolType"/> 
</Class> 



<!-- http://www.semanticweb.org/ontologies/2013/3/Ontology1365003423152.owl#Mailbomb --> 

<Class rdf:about="&Ontology1365003423152;Mailbomb"> 
    <rdfs:subClassOf rdf:resource="&Ontology1365003423152;Attack"/> 
</Class> 



<!-- http://www.semanticweb.org/ontologies/2013/3/Ontology1365003423152.owl#NoAttack --> 

<Class rdf:about="&Ontology1365003423152;NoAttack"> 
    <rdfs:subClassOf rdf:resource="&Ontology1365003423152;Attack"/> 
</Class> 



<!-- http://www.semanticweb.org/ontologies/2013/3/Ontology1365003423152.owl#Private --> 

<Class rdf:about="&Ontology1365003423152;Private"> 
    <rdfs:subClassOf rdf:resource="&Ontology1365003423152;AttackService"/> 
</Class> 



<!-- http://www.semanticweb.org/ontologies/2013/3/Ontology1365003423152.owl#SF --> 

<Class rdf:about="&Ontology1365003423152;SF"> 
    <rdfs:subClassOf rdf:resource="&Ontology1365003423152;AttackFlag"/> 
</Class> 



<!-- http://www.semanticweb.org/ontologies/2013/3/Ontology1365003423152.owl#Smtp --> 

<Class rdf:about="&Ontology1365003423152;Smtp"> 
    <rdfs:subClassOf rdf:resource="&Ontology1365003423152;AttackService"/> 
</Class> 



<!-- http://www.semanticweb.org/ontologies/2013/3/Ontology1365003423152.owl#Smurf --> 

<Class rdf:about="&Ontology1365003423152;Smurf"> 
    <rdfs:subClassOf rdf:resource="&Ontology1365003423152;Attack"/> 
</Class> 



<!-- http://www.semanticweb.org/ontologies/2013/3/Ontology1365003423152.owl#Tcp --> 

<Class rdf:about="&Ontology1365003423152;Tcp"> 
    <rdfs:subClassOf rdf:resource="&Ontology1365003423152;AttackProtocolType"/> 
</Class> 



<!-- http://www.semanticweb.org/ontologies/2013/3/Ontology1365003423152.owl#Udp --> 

<Class rdf:about="&Ontology1365003423152;Udp"> 
    <rdfs:subClassOf rdf:resource="&Ontology1365003423152;AttackProtocolType"/> 
</Class> 
</rdf:RDF> 



<!-- Generated by the OWL API (version 3.2.3.1824) http://owlapi.sourceforge.net --> 

回答

7

問題描述比較混亂,所以我剛剛創建了一個基本框架的應用程序,會告訴你的基本腳步。順便說一句,有一些與您輸入的本體問題:

  • 這不是你正在使用的命名空間中的URL發佈 - 不是致命的,但你應該在某個時候解決這個問題。我已經使用備用位置機制內置在耶拿

  • 圍繞它的工作,你有屬性名稱以大寫字母(例如HasDuration)開始。 RDF風格是使用領先的大寫字母作爲本地名稱,並且使用領先的小寫字母表示本地名稱(例如:hasDuration

  • 但實際上,一般約定是省略「has」和「是,」無論如何(所以:duration

  • 你似乎有一些類稱爲012等,是的Attack超類和不具有任何目的

總之,這裏是一個骨架應用程序,它可以適應您的需求:

package examples; 


import com.hp.hpl.jena.ontology.*; 
import com.hp.hpl.jena.rdf.model.Model; 
import com.hp.hpl.jena.rdf.model.ModelFactory; 
import com.hp.hpl.jena.util.FileManager; 

public class SamThomasExample 
{ 
    /***********************************/ 
    /* Constants      */ 
    /***********************************/ 

    // where the ontology should be 
    public static final String SOURCE_URL = "http://www.semanticweb.org/ontologies/2013/3/Ontology1365003423152.owl"; 

    // where we've stashed it on disk for the time being 
    protected static final String SOURCE_FILE = "./src/main/resources/Ontology1365003423152.owl"; 

    // the namespace of the ontology 
    public static final String NS = SOURCE_URL + "#"; 

    /***********************************/ 
    /* External signature methods  */ 
    /***********************************/ 

    public static void main(String[] args) { 
     new SamThomasExample().run(); 
    } 

    public void run() { 
     OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); 

     loadModel(m); 

     // get an OntClass reference to one of the classes in the model 
     // note: ideally, we would delegate this step to Jena's schemagen tool 
     OntClass attack = m.getOntClass(NS + "Attack"); 

     // similarly a reference to the attack duration property, 
     // and again, using schemagen would be better 
     OntProperty attackDuration = m.getDatatypeProperty(NS + "HasDuration"); 

     // create an instance of the attack class to represent the current attack 
     Individual attack01 = m.createIndividual(NS + "attack01", attack); 

     // add a duration to the attack 
     attack01.addProperty(attackDuration, m.createTypedLiteral(10)); 

     // finally, print out the model to show that we have some data 
     m.write(System.out, "Turtle"); 
    } 

    /***********************************/ 
    /* Internal implementation methods */ 
    /***********************************/ 

    /** read the ontology and add it as a sub-model of the given ontmodel */ 
    protected void loadModel(OntModel m) { 
     FileManager.get().getLocationMapper().addAltEntry(SOURCE_URL, SOURCE_FILE); 
     Model baseOntology = FileManager.get().loadModel(SOURCE_URL); 
     m.addSubModel(baseOntology); 

     // for compactness, add a prefix declaration st: (for Sam Thomas) 
     m.setNsPrefix("st", NS); 
    } 

} 

和這裏的輸出我得到:

@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . 
@prefix owl:  <http://www.w3.org/2002/07/owl#> . 
@prefix xsd:  <http://www.w3.org/2001/XMLSchema#> . 
@prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . 
@prefix st:  <http://www.semanticweb.org/ontologies/2013/3/Ontology1365003423152.owl#> . 

st:attack01 
    a  st:Attack ; 
    st:HasDuration "10"^^xsd:int .