Précédent   Forum du club des développeurs et IT Pro > Webmasters - Développement Web > Web sémantique
Web sémantique Forum d'entraide sur le Web sémantique (ajout de contenu sémantique - RDFa, microformats, microdonnées... -, ontologies - OWL, OWL2... - et utilisation - SPARQL, Jena...)
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 16/06/2012, 13h14   #1
menoulette
Nouveau Membre du Club
 
Avatar de menoulette
 
Inscription : août 2009
Messages : 181
Détails du profil
Informations forums :
Inscription : août 2009
Messages : 181
Points : 30
Points : 30
Par défaut Problème ObjectProperty "Conversion d'un fichier xml en owl"

Bonsoir à vous tous ,
Je veux convertir un fichier (.XML) en (.owl) je manipule le document XML en utilisant l'API JDOm et pour la création de l'ontologie j'utilise Jena , la conversion passe bien sauf au niveau des ObjectProperty le programme ne créé pas de ObjectProperty je n'ai pas pu trouver une solution efficace car j'ai trouvé des difficultés pour parcourir le document XML pour extraire le range pour se faire j'ai rajouté un attribut range pour chaque nœud que je veux rendre (ObjectProperty ) et c'est là où j'ai trouvé le problème. Les codes suivants illustre ce que je viens de dire
le document XML
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
 
 
<?xml version="1.0" encoding="UTF-8"?>
<TouristDataRoot xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="file:/C:/Users/Manel/Desktop/XML/sourcedonne/doc1.xsd">
    <touristData>
        <Tripper>
            <IDTripper  nature="PrimaryKey" >1</IDTripper>
            <nameTripper>lkklkj</nameTripper>
            <firstNameTripper>Manel</firstNameTripper>
            <Adress>kkkfjj</Adress>
            <Email> khkhk@hotmail.com</Email>
            <phoneNumber>bjbjbjb </phoneNumber>
        </Tripper>
        <Motel>
            <ID_Motel nature="PrimaryKey">H100</ID_Motel>
            <ComfortLevel>*****</ComfortLevel>
            <nameMotel>Hilton</nameMotel>
            <city>London</city>
            <country>GB</country>
        </Motel>
        <room>
            <ID_room nature="PrimaryKey">R1_1</ID_room>
            <ID_Motel nature="ForeignKey" Range="Motel">H100</ID_Motel>
        </room>
        <Allocation>
            <IDTripper nature="ForeignKey" Range="Tripper">1</IDTripper>
            <ID_room nature="ForeignKey" Range="Room">R1_1</ID_room>
            <ID_Motel nature="ForeignKey" Range="Motel">H100</ID_Motel>
            <duration>P5M</duration>
            <date_start>2011-03-11</date_start>
            <date_end>2011-08-11</date_end>
            <price unite="Euro">2000</price>
        </Allocation>
    </touristData>
</TouristDataRoot>
voici le code java
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
 
 
import java.io.File;
 
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
 
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
 
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;
 
import com.hp.hpl.jena.ontology.DatatypeProperty;
import com.hp.hpl.jena.ontology.ObjectProperty;
import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.rdf.model.ModelFactory;
 
 
public class Main {
 
 
    static org.jdom2.Document document;
    static Element racine ;
 
    static void lireFichier(String fichier ) throws JDOMException, IOException{
        SAXBuilder sxb=new SAXBuilder();
        document=sxb.build(new File(fichier));
        racine=document.getRootElement();
        System.out.println(racine);
 
    }
    static void afficherElement(String element) throws FileNotFoundException{
        OntModel onto ;
        File file=new File("DataTourist.owl"); 
        onto =ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM, null);
        String uriBase="http://www.ontologie.fr/DataTourist#";
        onto.createOntology(uriBase);
        FileOutputStream fichierXML=null;
 
        List listFilsDirect =racine.getChildren();
        Iterator i= listFilsDirect.iterator();
         String str = "";
 
        while(i.hasNext()){
            Element courant = (Element) i.next();
            while(!str.equals(courant.toString())){
                str=courant.toString();
            System.out.println("..........ici on affichera les tourist Data..........");
            System.out.println("le fils direct est:"+courant);
            List listChildren=courant.getChildren();
            if( listChildren!=null){
                Iterator j = listChildren.iterator();
                        while(j.hasNext()){
                            Element filsCourant=(Element)j.next();
                            System.out.println("le fils du fils DataTourist : "+filsCourant);
 
                              OntClass classe=onto.createClass(uriBase+filsCourant.getName());
                            //liste des datatYpe
                            List listChildrenOfChildren =filsCourant.getChildren();
                              if(listChildrenOfChildren !=null){
                                  Iterator k=listChildrenOfChildren.iterator();
                                   while(k.hasNext()){
                                       Element FilsFilsCourant=(Element)k.next();
                                       DatatypeProperty prop=onto.createDatatypeProperty(uriBase+FilsFilsCourant.getName());
                                       System.out.println(" le petit fils est : "+ FilsFilsCourant);
                                        if( FilsFilsCourant.hasAttributes()==true){
                                            System.out.println("le sous fils du fils direct posséde un attribut "+FilsFilsCourant.getAttributes());
                                            //if(FilsFilsCourant.getAttributeValue("nature").equals("ForeignKey") ){
                                            if("[[Attribute: nature=ForeignKey]]".equalsIgnoreCase(FilsFilsCourant.getAttributes().toString())){
                                                ObjectProperty prop2=onto.createObjectProperty(uriBase+FilsFilsCourant.getName());
                                                OntClass c =onto.createClass(uriBase+FilsFilsCourant.getAttributeValue("range")) ;     
                                                // System.out.println(FilsFilsCourant.getAttributeValue("Domaine").toString());
                                                prop2.setRange(c);
                                                OntClass domaine=onto.createClass(uriBase+FilsFilsCourant.getParent());
                                                prop2.setDomain(domaine) ;
                                            }
 
 
                                        }
                                   }
 
                              }
 
 
 
                        }
            }
            }
 
        }
        fichierXML= new FileOutputStream (file);
        onto.write (fichierXML);
    }
 
 
    public static void main(String[] args) throws JDOMException, IOException {
        // TODO Auto-generated method stub
        lireFichier("touristData.xml");
        afficherElement("racine");
    }
 
}
Merci d'avance
Cordialement
menoulette est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 17/06/2012, 11h38   #2
April Fool
Membre confirmé
 
Avatar de April Fool
 
Homme Information Inexacte
Fou d'avril
Inscription : février 2012
Messages : 97
Détails du profil
Informations personnelles :
Nom : Homme Information Inexacte
Localisation : France

Informations professionnelles :
Activité : Fou d'avril

Informations forums :
Inscription : février 2012
Messages : 97
Points : 206
Points : 206
Premièrement, dans ton code XML, tu utilises "Range" tandis que dans ton code Java, tu cherches l'attribut "range". XML est sensible à la casse.

Deuxièmement, le test :
Code :
if("[[Attribute: nature=ForeignKey]]".equalsIgnoreCase(FilsFilsCourant.getAttributes().toString()))
est vraiment très étrange. L'objective ici est de savoir s'il y a un attribut "nature" avec la valeur "ForeignKey". C'est ça qu'on veut tester, et non pas la façon dont les attributs sont affichés quand on demande de les imprimer.
Donc un truc du genre :
Code :
if(FilsFilsCourant.getAttribute("nature") != null && FilsFilsCourant.getAttributeValue("nature").equalsIgnoreCase("ForeignKey"))
devrait fonctionner.
__________________
7susd bl'ham owsql wuul pô!
April Fool est déconnecté   Envoyer un message privé Réponse avec citation 10
Vieux 17/06/2012, 12h15   #3
menoulette
Nouveau Membre du Club
 
Avatar de menoulette
 
Inscription : août 2009
Messages : 181
Détails du profil
Informations forums :
Inscription : août 2009
Messages : 181
Points : 30
Points : 30
Citation:
Envoyé par April Fool Voir le message
Premièrement, dans ton code XML, tu utilises "Range" tandis que dans ton code Java, tu cherches l'attribut "range". XML est sensible à la casse.

Deuxièmement, le test :
Code :
if("[[Attribute: nature=ForeignKey]]".equalsIgnoreCase(FilsFilsCourant.getAttributes().toString()))
est vraiment très étrange. L'objective ici est de savoir s'il y a un attribut "nature" avec la valeur "ForeignKey". C'est ça qu'on veut tester, et non pas la façon dont les attributs sont affichés quand on demande de les imprimer.
Donc un truc du genre :
Code :
if(FilsFilsCourant.getAttribute("nature") != null && FilsFilsCourant.getAttributeValue("nature").equalsIgnoreCase("ForeignKey"))
devrait fonctionner.
Quand j'ai fait votre test y'a des exceptions qui se génèrent :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 
 
Exception in thread "main" com.hp.hpl.jena.shared.BadURIException: Only well-formed absolute URIrefs can be included in RDF/XML output: <http://www.ontologie.fr/DataTourist#[Element: <Allocation/>]> Code: 0/ILLEGAL_CHARACTER in FRAGMENT: The character violates the grammar rules for URIs/IRIs.
	at com.hp.hpl.jena.xmloutput.impl.BaseXMLWriter.checkURI(BaseXMLWriter.java:829)
	at com.hp.hpl.jena.xmloutput.impl.BaseXMLWriter.relativize(BaseXMLWriter.java:806)
	at com.hp.hpl.jena.xmloutput.impl.Basic.writeResourceReference(Basic.java:148)
	at com.hp.hpl.jena.xmloutput.impl.Basic.writePredicate(Basic.java:101)
	at com.hp.hpl.jena.xmloutput.impl.Basic.writeRDFStatements(Basic.java:77)
	at com.hp.hpl.jena.xmloutput.impl.Basic.writeRDFStatements(Basic.java:66)
	at com.hp.hpl.jena.xmloutput.impl.Basic.writeBody(Basic.java:40)
	at com.hp.hpl.jena.xmloutput.impl.BaseXMLWriter.writeXMLBody(BaseXMLWriter.java:500)
	at com.hp.hpl.jena.xmloutput.impl.BaseXMLWriter.write(BaseXMLWriter.java:472)
	at com.hp.hpl.jena.xmloutput.impl.BaseXMLWriter.write(BaseXMLWriter.java:458)
	at com.hp.hpl.jena.rdf.model.impl.ModelCom.write(ModelCom.java:271)
	at com.hp.hpl.jena.ontology.impl.OntModelImpl.write(OntModelImpl.java:2552)
	at Main.afficherElement(Main.java:98)
	at Main.main(Main.java:144)
menoulette est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 18/06/2012, 08h23   #4
April Fool
Membre confirmé
 
Avatar de April Fool
 
Homme Information Inexacte
Fou d'avril
Inscription : février 2012
Messages : 97
Détails du profil
Informations personnelles :
Nom : Homme Information Inexacte
Localisation : France

Informations professionnelles :
Activité : Fou d'avril

Informations forums :
Inscription : février 2012
Messages : 97
Points : 206
Points : 206
Le problème est sur cette ligne:
Code :
OntClass domaine=onto.createClass(uriBase+FilsFilsCourant.getParent());
Ce serait peut-être bien d'utiliser un debugger, non ?
__________________
7susd bl'ham owsql wuul pô!
April Fool est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 18/06/2012, 19h08   #5
menoulette
Nouveau Membre du Club
 
Avatar de menoulette
 
Inscription : août 2009
Messages : 181
Détails du profil
Informations forums :
Inscription : août 2009
Messages : 181
Points : 30
Points : 30
Je ne trouve pas de solution pour transformer les clé étrangère en ObjectProperty!!!
menoulette est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 05h25.


 
 
 
 
Partenaires

Hébergement Web