Précédent   Forum du club des développeurs et IT Pro > Webmasters - Développement Web > Web sémantique > Frameworks
Frameworks Forum d'entraide sur les frameworks du Web sémantique (Jena, Sesame, etc.).
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 30/05/2012, 16h17   #1
helabah
Invité régulier
 
Femme
Étudiant
Inscription : mai 2012
Messages : 31
Détails du profil
Informations personnelles :
Sexe : Femme
Localisation : Tunisie

Informations professionnelles :
Activité : Étudiant
Secteur : High Tech - Matériel informatique

Informations forums :
Inscription : mai 2012
Messages : 31
Points : 6
Points : 6
Par défaut Insérer des individus dans une ontologie

Bonjour,
je veux ajouter des individus à mon ontologie.
j'ai suivi vos instructions pour l'ajout d'individus mais j'ai des problèmes dans le code .
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
package conn;
 
import com.hp.hpl.jena.iri.impl.Main;
import com.hp.hpl.jena.ontology.DatatypeProperty;
import com.hp.hpl.jena.ontology.Individual;
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.*;
import com.hp.hpl.jena.util.FileManager;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.vocabulary.XSD;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
 
public class ExpleInsert {
 
   public static final String NL      = System.getProperty("line.separator") ;
   public static final String URIB="http://www.owl-ontologies.com/reuses.owl#";
    public static final String owlFile="file:///C:/Program20%Files/Protege_3.4.7/examples/Krs1.owl";
 
   public void connect() throws FileNotFoundException
   {  
 
 
       OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_MICRO_RULE_INF);
 
       String inputFileName ="file:///C:/Program Files/Protege_3.4.7/examples/Krs1.owl";
       // use the FileManager to find the input file
       InputStream in = FileManager.get().open(inputFileName );
       if (in == null) {
                   model.read(in, " ", inputFileName);
           throw new IllegalArgumentException("File: " + inputFileName + " not found");}
       OntModel ontology = ModelFactory.createOntologyModel();
       OntModel mod = ModelFactory.createOntologyModel();
/*OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_MICRO_RULE_INF); 
 
InputStream is = new BufferedInputStream(new FileInputStream(owlFile));
//C:\\Users\\sarah\\Desktop\\ontocerist.owl
OntModel ontology = ModelFactory.createOntologyModel();
model.read(is, "RDF/XML");
 
OntModel mod = ModelFactory.createOntologyModel();*/
 
OntClass BesoinClass = ontology.getOntClass("http://www.owl-ontologies.com/reuses.owl#Besoin");
Individual c = mod.createIndividual("http://www.owl-ontologies.com/reuses.owl#Besoin",BesoinClass);
DatatypeProperty nomProp = ontology.getDatatypeProperty("http://www.owl-ontologies.com/reuses.owl#hasnamebesoin");
//DatatypeProperty prenomProp = ontology.getDatatypeProperty("http://www.semanticweb.org/SEVEN7/ontologies/2012/2/Ontology1331977184905.owl#Prenom");
 
 
// on peut éventuellement mettre un langageTag:
Literal n = mod.createLiteral("sarah");
//Literal p = mod.createLiteral("sefti"); // idem
 
//c.addLiteral(nomProp, n);
mod.createStatement(c,nomProp,n);
//mod.createStatement(c,prenomProp,p);
 
 
 
 
 
 
 
 
}
 
 
 
 
 
 
 
 
    public static void main(String[]  args)throws Exception {
 
 ExpleInsert a=new  ExpleInsert ();
 a.connect();
 
 
 
    }
 
 
    }
voici les erreurs
Citation:
Exception in thread "main" java.lang.NullPointerException
at com.hp.hpl.jena.rdf.model.impl.StatementImpl.<init>(StatementImpl.java:31)
at com.hp.hpl.jena.rdf.model.impl.ModelCom.createStatement(ModelCom.java:1126)
at conn.ExpleInsert.connect(ExpleInsert.java:65)
at conn.ExpleInsert.main(ExpleInsert.java:87)
helabah est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/05/2012, 17h51   #2
CesarR
Membre habitué
 
Homme
Inscription : juillet 2005
Messages : 82
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : Etats-Unis

Informations forums :
Inscription : juillet 2005
Messages : 82
Points : 105
Points : 105
Envoyer un message via MSN à CesarR
On dirait que ligne 65, un des paramètres de createStatement est null.

A toi de les vérifier.

Edit: C'est normal d'avoir l'URI pour ta classe Besoin et ton individu? (ligne 54 et 55)
CesarR est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/05/2012, 21h56   #3
helabah
Invité régulier
 
Femme
Étudiant
Inscription : mai 2012
Messages : 31
Détails du profil
Informations personnelles :
Sexe : Femme
Localisation : Tunisie

Informations professionnelles :
Activité : Étudiant
Secteur : High Tech - Matériel informatique

Informations forums :
Inscription : mai 2012
Messages : 31
Points : 6
Points : 6
bonsoir,
merci pour votre attention et pour les paramètres ne sont pas null.
helabah est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 31/05/2012, 17h53   #4
CesarR
Membre habitué
 
Homme
Inscription : juillet 2005
Messages : 82
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : Etats-Unis

Informations forums :
Inscription : juillet 2005
Messages : 82
Points : 105
Points : 105
Envoyer un message via MSN à CesarR
Tu as lu toute ma reponse?

Y'a un probleme ligne 54 et 55 ...

Tiens, ca va t'aider la doc sur la methode createIndividual
CesarR 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 17h01.


 
 
 
 
Partenaires

Hébergement Web