2017-05-01 1 views
0

J'ai créé un fichier de hibou utilisant Jena:Créer personnes utilisant Jena

<rdf:RDF xmlns="file:/D:/onto/owl_ontologies/diagnostic.owl#" 
xml:base="file:/D:/onto/owl_ontologies/diagnostic.owl" 
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" 
xmlns:diag="file:/D:/onto/owl_ontologies/diagnostic.owl#" 
xmlns:owl="http://www.w3.org/2002/07/owl#" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema#" 
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> 
<owl:Ontology rdf:about="file:/D:/onto/owl_ontologies/diagnostic.owl"/> 



<owl:ObjectProperty rdf:about="&diag;hasSymptom"> 
    <rdfs:domain rdf:resource="&diag;Desease"/> 
    <rdfs:range rdf:resource="&diag;Symptom"/> 
</owl:ObjectProperty> 


<owl:DatatypeProperty rdf:about="&diag;DesId"> 
    <rdfs:domain rdf:resource="&diag;Desease"/> 
    <rdfs:range rdf:resource="&xsd;string"/> 
</owl:DatatypeProperty> 



<owl:DatatypeProperty rdf:about="&diag;DesLabel"> 
    <rdfs:domain rdf:resource="&diag;Desease"/> 
    <rdfs:range rdf:resource="&xsd;string"/> 
</owl:DatatypeProperty> 


<owl:DatatypeProperty rdf:about="&diag;SympId"> 
    <rdfs:domain rdf:resource="&diag;Symptom"/> 
    <rdfs:range rdf:resource="&xsd;string"/> 
</owl:DatatypeProperty> 


<owl:DatatypeProperty rdf:about="&diag;SympLabel"> 
    <rdfs:domain rdf:resource="&diag;Symptom"/> 
    <rdfs:range rdf:resource="&xsd;string"/> 
</owl:DatatypeProperty> 




<owl:Class rdf:about="&diag;Desease"/> 

<owl:Class rdf:about="&diag;Symptom"/> 



<!-- 
/////////////////////////////////////////////////////////////////////////////////////// 
// 
// Individuals 
// 
/////////////////////////////////////////////////////////////////////////////////////// 
--> 

Je veux créer des individus, ceci est mon code Java pour créer le ontModel:

//******************************Create new Ontology******************************************* 
    ontoDiag = modelDiag.createOntology(baseURI); 

    modelDiag.setNsPrefix("diag", ns); 

    //*****************Create Classes Desease && Symptoms **************************************** 
    desease = modelDiag.createClass(ns + "Desease"); 
    symptom = modelDiag.createClass(ns + "Symptom"); 

    //*********************Create DataType Property label && id for symptom class*********************** 
    name = modelDiag.createDatatypeProperty(ns + "SympLabel"); 
    name.setDomain(symptom); 
    name.setRange(XSD.xstring); 
    id = modelDiag.createDatatypeProperty(ns + "SympId"); 
    id.setDomain(symptom); 
    id.setRange(XSD.xstring); 
    //*********************Create DataType Property label && id for desease class*********************** 
    nameDes = modelDiag.createDatatypeProperty(ns + "DesLabel"); 
    nameDes.setDomain(desease); 
    nameDes.setRange(XSD.xstring); 
    idDes = modelDiag.createDatatypeProperty(ns + "DesId"); 
    idDes.setDomain(desease); 
    idDes.setRange(XSD.xstring); 

    //*********************Create Object Property hasSymptom ******************************************* 
    hasSymptom = modelDiag.createObjectProperty(ns + "hasSymptom"); 
    hasSymptom.addDomain(desease); 
    hasSymptom.addRange(symptom); 

et c'est la partie où je crée des individus

//***********************************Create Individual Desease**************************** 

     Individual IndivDes = modelDiag.createIndividual(ns + desChoosen, desease); 

     //***************add the property name to desease ************************************** 
     Literal desName = modelDiag.createTypedLiteral(desChoosen, XSDDatatype.XSDstring); 
     Statement desNameSt = modelDiag.createStatement(IndivDes, name, desName); 
     modelDiag.add(desNameSt); 

     //***************add the property id to desease ************************************** 
     Literal desId = modelDiag.createTypedLiteral(IdDes, XSDDatatype.XSDstring); 
     Statement desIdSt = modelDiag.createStatement(IndivDes, id, desId); 
     modelDiag.add(desIdSt); 

Le travail de code parfaitement, mais le problème est que les individus créé ressembler à ceci:

<diag:Desease rdf:about="file:/D:/onto/owl_ontologies/diagnostic.owl#orbital cyst"> 
<diag:hasSymptom> 
    <diag:Symptom rdf:about="file:/D:/onto/owl_ontologies/diagnostic.owl#severe chest pain"> 
    <diag:SympLabel>severe chest pain</diag:SympLabel> 
    </diag:Symptom> 
</diag:hasSymptom> 
<diag:SympId>DES:000001</diag:SympId> 
<diag:SympLabel>orbital cyst</diag:SympLabel> 

à la place:

<owl:NamedIndividual rdf:about="&diag;desease2"> 
    <rdf:type rdf:resource="&diag;Desease"/> 
    <hasSymptom rdf:resource="&diag;pain2"/> 
</owl:NamedIndividual> 

Je vous remercie de votre aide merci ..

+0

Quel est le problème avec ça? La sémantique est la même, la sérialisation est différente. Tout analyseur OWL vous donnera le même ensemble d'axiomes OWL retour ... – AKSW

+0

J'ai des erreurs quand j'ouvre le fichier avec Protege –

+0

Comment vous stockez le modèle avec Jena. Et quelle erreur obtenez-vous dans Protege? Nous avons besoin de plus d'informations, n'est-ce pas évident? Et pourquoi avez-vous des espaces blancs dans vos URI? Pensez-vous que cela a du sens? – AKSW

Répondre

0

Essayez d'ajouter explicitement rdf: type = owl: NamedIndividual:

public static void main(String ... strings) { 
    OntModel m = ModelFactory.createOntologyModel(); 
    m.setNsPrefix("test", "http://test#"); 
    Individual i = m.createIndividual("http://test#indi", m.createResource("http://test#cl")); 
    i.addProperty(RDFS.comment, "something"); 
    i.addRDFType(OWL2.NamedIndividual); 
    m.write(System.out); 
} 

Cet extrait produira rdf-XML suivant:

<rdf:RDF 
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
    xmlns:owl="http://www.w3.org/2002/07/owl#" 
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" 
    xmlns:test="http://test#" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"> 
    <owl:NamedIndividual rdf:about="http://test#indi"> 
    <rdfs:comment>something</rdfs:comment> 
    <rdf:type rdf:resource="http://test#cl"/> 
    </owl:NamedIndividual> 
</rdf:RDF> 

tout sans "i.addRDFType (OWL.NamedIndividual)" la sortie serait suit:

<rdf:RDF 
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
    xmlns:owl="http://www.w3.org/2002/07/owl#" 
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" 
    xmlns:test="http://test#" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"> 
    <test:cl rdf:about="http://test#indi"> 
    <rdfs:comment>something</rdfs:comment> 
    </test:cl> 
</rdf:RDF> 

Note: hibou: NamedIndividual est la déclaration OWL2. il n'y a pas une telle chose dans OWL1. Jena ne supporte pas OWL2, bien qu'il y ait une classe de vocabulaire pour cela (voir org.apache.jena.vocabulary.OWL2)