OWLapi: problème de création d'une même relation avec plusieurs domain et range
Bonjour, en fait je suis entrain de créer une ontologie dans un projet avec Netbeans en utilisant OWL Api. En effet j'ai un ensemble de concepts et un ensemble de relations entre concepts. J'ai seulement deux types de relation "sorte de" et "sous Thème de". Donc plusieurs concepts ont le même type de relation. J'ai implémenté une classe Owl.java contient une méthode qui crée une ontologie à partir de deux listes de concepts et de relations. Le problème est quand j'utilise owlapi pour le génération de l'ontologie en langage OWL il n'affiche pas les concepts pour une relation donnée de façon correcte. Le code ci dessous est la classe OWL.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
import java.io.File;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.io.StreamDocumentTarget;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLObjectPropertyDomainAxiom;
import org.semanticweb.owlapi.model.OWLObjectPropertyRangeAxiom;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyChange;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.model.OWLOntologyStorageException;
import org.semanticweb.owlapi.reasoner.OWLReasoner;
/**
*
* @author hela
*/
public class Owl {
public void createNewOnto(List<String[][]> cps, LinkedList<Map<String, String>> rel ) throws OWLOntologyCreationException,
OWLOntologyStorageException {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLDataFactory factory = manager.getOWLDataFactory();
OWLOntology ontology = manager.createOntology();
for(Map<String, String> rmp : rel){
Set<OWLClass> classes = ontology.getClassesInSignature();
List<OWLClass> listc = new ArrayList(classes);
IRI ir = IRI.create("#"+rmp.get("concept1"));
OWLClass c1=null;
if(ontology.containsClassInSignature(ir)){
int i=0;
while(i<listc.size()&& c1==null){
if(listc.get(i).getIRI().toString().compareTo(ir.toString())==0)
c1=listc.get(i);
i++;
}
}
else
c1 = factory.getOWLClass(IRI.create("#"+rmp.get("concept1")));
IRI ir2 = IRI.create("#"+rmp.get("concept2"));
OWLClass c2=null;
if(ontology.containsClassInSignature(ir2)){
int i=0;
while(i<listc.size()&& c2==null){
if(listc.get(i).getIRI().toString().compareTo(ir2.toString())==0)
c2=listc.get(i);
i++;
}
}
else
c2 = factory.getOWLClass(IRI.create("#"+rmp.get("concept2")));
OWLObjectPropertyDomainAxiom domainAxiom=null;
OWLObjectPropertyRangeAxiom rangeAxiom= null;
if(rmp.get("relation").compareTo("sorte de")==0){
domainAxiom = factory.getOWLObjectPropertyDomainAxiom(factory.getOWLObjectProperty(IRI.create("#sorte de")),c1);
rangeAxiom = factory.getOWLObjectPropertyRangeAxiom(factory.getOWLObjectProperty(IRI.create("#sorte de")),c2);
}
else{
domainAxiom = factory.getOWLObjectPropertyDomainAxiom(factory.getOWLObjectProperty(IRI.create("#sousThème de")),c1);
rangeAxiom = factory.getOWLObjectPropertyRangeAxiom(factory.getOWLObjectProperty(IRI.create("#sousThème de")),c2);
}
List<OWLOntologyChange> ladd =manager.addAxiom(ontology, domainAxiom);
List<OWLOntologyChange> ladd2= manager.addAxiom(ontology, rangeAxiom);
for(OWLOntologyChange ch : ladd){
manager.applyChange(ch);
}
for(OWLOntologyChange ch2 : ladd2){
manager.applyChange(ch2);
}
String[][] cp1 = this.getConcept(cps,rmp.get("concept1") );
String[][] cp2 = this.getConcept(cps,rmp.get("concept2") );
cps.remove(cp2);
cps.remove(cp1);
// Now we apply the change using the manager.
//manager.applyChange(addAxiom1);
}
for(String[][] ct: cps){
factory.getOWLClass(IRI.create("#"+ct[0][0]));
}
File file = new File("/C:/Users/hela/Desktop/fichierOwl/Annot2Onto.owl");
manager.saveOntology(ontology, IRI.create(file.toURI()));
manager.saveOntology(ontology, new StreamDocumentTarget(System.out));
/*IRI ontologyIRI2 = IRI.create("http://owl.cs.man.ac.uk/ontology");
OWLOntologyManager man = OWLManager.createOWLOntologyManager();
OWLDataFactory factory2 = man.getOWLDataFactory();
PrefixManager pm = new DefaultPrefixManager(ontologyIRI+"#");
try {
OWLOntology ontology = man.createOntology(ontologyIRI);
System.out.println("Created: "+ontology.getOntologyID().getOntologyIRI());
OWLClass student = factory2.getOWLClass(":Student",pm);
OWLDeclarationAxiom declaration = factory.getOWLDeclarationAxiom(student);
man.addAxiom(ontology, declaration);
System.out.println(student);
} catch (OWLOntologyCreationException e) {
e.printStackTrace();
}*/
}
public String[][] getConcept(List<String[][]> cps, String s){
String[][] cp =null;
int i=0;
while((i<cps.size()) && (cp==null) ){
if(cps.get(i)[0][0].compareTo(s)==0)
cp=cps.get(i);
i++;
}
return cp;
}
public static void main(String[] args){
Owl o = new Owl();
/*try{
o.createNewOnto();
} catch (OWLOntologyCreationException e) {
e.printStackTrace();
}catch (OWLOntologyStorageException e) {
e.printStackTrace();
}*/
}
} |
en fait par exmple dans la liste de relation j'ai CRYPTOGRAPHY sorte de validation je la trouve plus cependant je trouve d'autres affectation erronée. Voici le fihier .owl en résultat.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
<?xml version="1.0"?>
<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: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#">
<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Object Properties
//
///////////////////////////////////////////////////////////////////////////////////////
-->
<!-- #sorte de -->
<ObjectProperty rdf:about="#sorte de">
<rdfs:domain rdf:resource="#AUTHENTICATION"/>
<rdfs:range rdf:resource="#CRYPTOGRAPHY"/>
<rdfs:range rdf:resource="#ENCRYPTION"/>
<rdfs:domain rdf:resource="#ENCRYPTION"/>
<rdfs:range rdf:resource="#coding"/>
<rdfs:domain rdf:resource="#compression"/>
<rdfs:range rdf:resource="#management"/>
<rdfs:range rdf:resource="#system"/>
<rdfs:range rdf:resource="#validation"/>
<rdfs:domain rdf:resource="#DATABASE MANAGEMENT"/>
<rdfs:domain rdf:resource="#INFORMATION SYSTEMS"/>
</ObjectProperty>
<!-- #sousThème de -->
<ObjectProperty rdf:about="#sousThème de">
<rdfs:domain rdf:resource="#CRYPTOGRAPHY"/>
<rdfs:range rdf:resource="#SECURITY"/>
<rdfs:domain rdf:resource="#WATERMARKING"/>
<rdfs:domain rdf:resource="#APPLICATION AND EXPERT SYSTEMS"/>
<rdfs:range rdf:resource="#ARTIFICIAL INTELLIGENCE"/>
<rdfs:domain rdf:resource="#DATABASE MANAGEMENT"/>
<rdfs:range rdf:resource="#INFORMATION SYSTEMS"/>
<rdfs:domain rdf:resource="#INFORMATION STORAGE AND RETRIEVAL"/>
<rdfs:domain rdf:resource="#KNOWLEDGE REPRESENTATION FORMALISMS AND METHODS"/>
<rdfs:domain rdf:resource="#NATURAL LANGUAGE PROCESSING"/>
<rdfs:domain rdf:resource="#NETWORK SECURITY"/>
</ObjectProperty>
<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Classes
//
///////////////////////////////////////////////////////////////////////////////////////
-->
<!-- #AUTHENTICATION -->
<Class rdf:about="#AUTHENTICATION"/>
<!-- #CRYPTOGRAPHY -->
<Class rdf:about="#CRYPTOGRAPHY"/>
<!-- #ENCRYPTION -->
<Class rdf:about="#ENCRYPTION"/>
<!-- #SECURITY -->
<Class rdf:about="#SECURITY"/>
<!-- #WATERMARKING -->
<Class rdf:about="#WATERMARKING"/>
<!-- #coding -->
<Class rdf:about="#coding"/>
<!-- #compression -->
<Class rdf:about="#compression"/>
<!-- #management -->
<Class rdf:about="#management"/>
<!-- #system -->
<Class rdf:about="#system"/>
<!-- #validation -->
<Class rdf:about="#validation"/>
<!-- #APPLICATION AND EXPERT SYSTEMS -->
<Class rdf:about="#APPLICATION AND EXPERT SYSTEMS"/>
<!-- #ARTIFICIAL INTELLIGENCE -->
<Class rdf:about="#ARTIFICIAL INTELLIGENCE"/>
<!-- #DATABASE MANAGEMENT -->
<Class rdf:about="#DATABASE MANAGEMENT"/>
<!-- #INFORMATION SYSTEMS -->
<Class rdf:about="#INFORMATION SYSTEMS"/>
<!-- #INFORMATION STORAGE AND RETRIEVAL -->
<Class rdf:about="#INFORMATION STORAGE AND RETRIEVAL"/>
<!-- #KNOWLEDGE REPRESENTATION FORMALISMS AND METHODS -->
<Class rdf:about="#KNOWLEDGE REPRESENTATION FORMALISMS AND METHODS"/>
<!-- #NATURAL LANGUAGE PROCESSING -->
<Class rdf:about="#NATURAL LANGUAGE PROCESSING"/>
<!-- #NETWORK SECURITY -->
<Class rdf:about="#NETWORK SECURITY"/>
</rdf:RDF>
<!-- Generated by the OWL API (version 3.4.8) http://owlapi.sourceforge.net --> |
Ici dans le fichier AYTHETIFICATION sorte de CRYPTOGRAPHY alors que c'est pas le cas. Je pense que le problème réside que je dois à chaque fois que j'ai une OWLClass domain et range je dois créer une relation je suis pas sûre mais si c'est ça je sais pas comment je dois procéder car
Code:
factory.getOWLObjectProperty(IRI.create("relation"))
cherche l'uri s'il existe sinon elle le créée.
Avez-vous une solution s'il vous plaît?
Problème d'affectation du Domain et Range
Bonjour hela_sfar
Je vous avoue que j'ai de la difficulté à comprendre votre problème, mais j'ai tout de même j'ai quelques remarques qui pourraient vous aider.
En OWL la déclaration d'un domaine à une propriété indique qu'une relation instanciée de la propriété réfère à son origine à un individu de la classe indiquée par le domaine. Par exemple: P domain Ca indique que les individus de la classe Ca sont susceptible d'être à l'origine de la relation instancié de P.
Maintenant, si l'on déclare plusieurs domain à P, par exemple:
P domain Ca
P domain Cb
P domain Cc
Alors, les individus susceptible d'être la source de la relation instanciée de P peuvent parvenir de la classe Ca ou de Cb ou de CC
Il en va de même pour le range: par exemple
P range Cd
P range Ce
les individus à la cible de relation P peuvent appartenir à la classe Cd ou Ce
Avec cette ontologie de range et de domain les énoncés suivants seront tous vrais:
ca p ce
cb p cd
cc p cd
Mais les énoncés suivants ne seront pas nécessairement vrai
ca p cb
cd p ce
Si vous souhaitez particulariser le range et le domain d'une propriété à des combinaisons spécifiques vous devez utiliser la restriction universelle et existentielle
Autre remarque:
En OWL il est préférable d'employer rdfs:subClassOf plustot que "sorte de"
Bonne continuation