helaba
Messages postés12Date d'inscriptionvendredi 10 décembre 2010StatutMembreDernière intervention 6 septembre 2013
-
17 mai 2012 à 07:25
amaljar -
28 mars 2016 à 13:04
bonjour,
j'ai écrit un code pour récupérer les instances de mon ontologie . voici le code
package conn;
import java.io.InputStream;
import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.shared.NotFoundException;
import com.hp.hpl.jena.sparql.util.IndentedWriter;
import com.hp.hpl.jena.util.FileManager;
import com.hp.hpl.jena.vocabulary.RDF;
public class Recupererinstance {
public static final String inputFileName="C:/Program20%Files/Protege_3.4.7/examples/Krs1.owl";
public static final String NL = System.getProperty("line.separator") ;
private static final Model model = null;
public static void main( String[] args ) {
// try {
// InputStream in=null;
// in=new FileInputStream(new File("C:/Program Files/Protege_3.4.8/examples/rdf/fichier.rdf"));
// Creation d'un modele d'ontologie pour une ontologie OWL-DL avec un resonneur RDFS
// Model m = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RDFS_INF);
Model model =ModelFactory.createMemModelMaker().createModel(null);
// Lecture du fichier OWL. Le Namespace de notre ontologie doit etre specifié
//InputStream in = (InputStream) FileManager.get().readModel( m, inputFileName );
//if ( in == null )
// throw new NotFoundException("Not found: "+inputFileName) ;
// return load(in, "RDF/XML") ;
}
InputStream in = (InputStream) FileManager.get().readModel( model, inputFileName );
if (in == null) {
throw new IllegalArgumentException("File: " + inputFileName
+ " not found");
}
// model.read(in, "RDF/XML");
//
String myOntologyName = "ProjetHela";
//
String uri="file:/C:/Program20%Files/Protege_3.4.7/examples/Krs1.owl";
// Définition de prefixe pour simplifier l'utilisation de SPARQL
String reuses = "reuses: <"+RDF.getURI()+">" ;
// String myOntologyPrefix = "PREFIX "+myOntologyName+": <"+myOntologyNS+">" ;
String myOntologyPrefix = "PREFIX "+myOntologyName+": <"+uri+">" ;
// Construction de la requete
// String queryString = myOntologyPrefix + NL
// + reuses + NL
// "SELECT ?hasnamefonctioncontrainte ?hasnamefonctionprincipale WHERE
//{{ ?Fonction_contrainte reuses:hasnamefonctioncontrainte ?hasnamefonctioncontrainte}UNION" +
// " { ?Fonction_principale reuses:hasnamefonctionprincipale ?hasnamefonctionprincipale}}")
String queryString=
"PREFIX reuses: <http://www.owl-ontologies.com/reuses.owl#>"
+ "SELECT ?hasnameactivite"
+ " WHERE "
+ "{"
+ "{"
+ " ?Activite reuses:hasnameactivite"
// + " ?name had:nameactivite ?ac."
+ " } ";
Query query = QueryFactory.create(queryString) ;
// // Affichage de la requete sur la sortie standard.
query.serialize(new IndentedWriter(System.out,true)) ;
System.out.println() ;
// Create a single execution of this query, apply to a model
// which is wrapped up as a Dataset
QueryExecution qexec = QueryExecutionFactory.create(query, model) ;
// Execution de la requete
try {
// Pour l'instant nous nous limitons a des requetes de type SELECT
ResultSet rs = qexec.execSelect() ;
// Affichage des resultats
for ( ; rs.hasNext() ; ){
System.out.print("");
QuerySolution rb = rs.nextSolution() ;
String y = rb.getLiteral("hasnameactivite").getString();
System.out.print("uri : "+y.toString()+"--- ");
}
}
finally{
qexec.close() ;
}
} }
après le run :
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at conn.Recupererinstance.main(Recupererinstance.java:21)
Twinuts
Messages postés5375Date d'inscriptiondimanche 4 mai 2003StatutModérateurDernière intervention14 juin 2023111 20 mai 2012 à 11:11
Salut,
Et concrètement ? c'est quoi la ligne 21 de ta classe Recupererinstance ?
Ensuite c'est bien beau d'enlever les try {... } catch(...) {...} mais tu sais en java ils sont très souvent (pour pas dire TOUJOURS) obligatoire.
-----
"On n'est pas au resto : ici on ne fait pas dans les plats tout cuits ..."
mwara
Messages postés6Date d'inscriptionmardi 19 mai 2009StatutMembreDernière intervention14 juin 2012 14 juin 2012 à 11:29
Bonjour tout le monde,
J'exécuté ce code, mais j'ai des erreur lors de la première instruction du Main : Création du modèle.
Voici l'erreur:
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at com.hp.hpl.jena.util.Metadata.<clinit>(Metadata.java:26)
at com.hp.hpl.jena.JenaRuntime.<clinit>(JenaRuntime.java:25)
at com.hp.hpl.jena.rdf.model.impl.RDFReaderFImpl.<clinit>(RDFReaderFImpl.java:85)
at com.hp.hpl.jena.rdf.model.impl.ModelCom.<clinit>(ModelCom.java:42)
at com.hp.hpl.jena.rdf.model.impl.ModelMakerImpl.makeModel(ModelMakerImpl.java:34)
at com.hp.hpl.jena.rdf.model.impl.ModelMakerImpl.createModel(ModelMakerImpl.java:46)
at com.hp.hpl.jena.rdf.model.impl.ModelMakerImpl.createModel(ModelMakerImpl.java:49)
at menu.main(menu.java:56)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 8 more
Java Result: 1
Svp, celui ou celle qui a déjà rencontré une erreur du genre, avec ce programme, ou qu'elle a une idée pour la résoudre,j'apprécirai vraiment son aide.
helaba
Messages postés12Date d'inscriptionvendredi 10 décembre 2010StatutMembreDernière intervention 6 septembre 20132 Modifié par helaba le 6/09/2013 à 01:43
mannoulty224
Messages postés4Date d'inscriptionmercredi 2 juin 2010StatutMembreDernière intervention12 septembre 2013 8 sept. 2013 à 15:32
Bonjour ,
Dans l'exécution de ce code j'obtient des probleme aux niveaux des import com.hp " the import com.hp cannot be resolved " commment je peux les corriger ???
il se peut qu'il y a un package manquant il faut l'importer
mannoulty224
Messages postés4Date d'inscriptionmercredi 2 juin 2010StatutMembreDernière intervention12 septembre 2013 10 sept. 2013 à 11:43
Bonjour,
dans l'exécution de ce code j'obtient les erreurs suivantes, svp aidez moi
1-The method addFrame(FrameID, String, Frame) in the type SystemFrames is not applicable for the arguments (FrameID, OWLDatatypeProperty) OWLSystemFrames.java /ontologie/src/ontologie
2-The method getName() is undefined for the type FrameID OWLSystemFrames.java /ontologie/src/ontologie
3- The method replaceFrame(FrameID, OWLDatatypeProperty) is undefined for the type OWLSystemFrames OWLSystemFrames.java /ontologie/src/ontologie
4- The constructor FrameID(String) is undefined OWLSystemFrames.java /ontologie/src/ontologie
5- EQUIVALENT_PROPERTY cannot be resolved or is not a field OWLSystemFrames.java /ontologie/src/ontologie
6- LABEL cannot be resolved or is not a field OWLSystemFrames.java /ontologie/src/ontologie line 334 Java Problem
TOP_LEVEL_ONTOLOGY_URI cannot be resolved or is not a field OWLSystemFrames.java /ontologie/src/ontologie
JButton des=new JButton("Deselection tout");
public ListPanel listSession_formation;
public ListPanel listEvaluation;
public ListPanel listFormateurs;
public ListPanel listSeances;
public ListPanel listGroupes;
public ListPanel listApprenant;
public ListPanel listThemes;
public ListPanel listModule;
public ListPanel listCours;
public ListPanel listChapitre;
public ListPanel listPrpositions_Reponses;
public ListPanel listQuestions;
public void affontologie() {
OWLModel owlModel;
String uri = "file:///c:/ontologie1/ontologieE_learning.owl";
JFrame fen=new JFrame();
fen.setTitle("Les sessions de formations");
Container cont = fen.getContentPane();
try
{
owlModel = ProtegeOWL.createJenaOWLModelFromURI(uri);
OWLNamedClass Session_Formation = owlModel.getOWLNamedClass("Session_formation");
listSession_formation = new ListPanel(Session_Formation);
listSession_formation.setBorder(javax.swing.BorderFactory.createTitledBorder(Session_Formation.getBrowserText()));
OWLNamedClass Evaluation = owlModel.getOWLNamedClass("Evaluation");
listEvaluation = new ListPanel(Evaluation);
listEvaluation.setBorder(javax.swing.BorderFactory.createTitledBorder(Evaluation.getBrowserText()));
OWLNamedClass Formateurs = owlModel.getOWLNamedClass("Formateurs");
listFormateurs = new ListPanel(Formateurs);
listFormateurs.setBorder(javax.swing.BorderFactory.createTitledBorder(Formateurs.getBrowserText()));
OWLNamedClass Seances = owlModel.getOWLNamedClass("Seances");
listSeances = new ListPanel(Seances);
listSeances.setBorder(javax.swing.BorderFactory.createTitledBorder(Seances.getBrowserText()));
OWLNamedClass Groupes = owlModel.getOWLNamedClass("Groupes");
listGroupes = new ListPanel(Groupes);
listGroupes.setBorder(javax.swing.BorderFactory.createTitledBorder(Groupes.getBrowserText()));
OWLNamedClass Apprenant = owlModel.getOWLNamedClass("Apprenant");
listApprenant= new ListPanel(Apprenant);
listApprenant.setBorder(javax.swing.BorderFactory.createTitledBorder(Session_Formation.getBrowserText()));
OWLNamedClass Themes = owlModel.getOWLNamedClass("Themes");
listThemes = new ListPanel(Themes);
listThemes.setBorder(javax.swing.BorderFactory.createTitledBorder(Themes.getBrowserText()));
OWLNamedClass Module = owlModel.getOWLNamedClass("Module");
listModule = new ListPanel(Module);
listModule.setBorder(javax.swing.BorderFactory.createTitledBorder(Module.getBrowserText()));
OWLNamedClass Cours = owlModel.getOWLNamedClass("Cours");
listCours = new ListPanel(Cours);
listCours.setBorder(javax.swing.BorderFactory.createTitledBorder(Cours.getBrowserText()));
OWLNamedClass Chapitre = owlModel.getOWLNamedClass("Chapitre");
listChapitre = new ListPanel(Chapitre);
listChapitre.setBorder(javax.swing.BorderFactory.createTitledBorder(Chapitre.getBrowserText()));
OWLNamedClass Prpositions_Reponses = owlModel.getOWLNamedClass("Prpositions_Reponses");
listPrpositions_Reponses = new ListPanel(Prpositions_Reponses);
listPrpositions_Reponses .setBorder(javax.swing.BorderFactory.createTitledBorder(Prpositions_Reponses.getBrowserText()));
OWLNamedClass Questions = owlModel.getOWLNamedClass("Questions");
listQuestions = new ListPanel(Questions);
listQuestions.setBorder(javax.swing.BorderFactory.createTitledBorder(Questions.getBrowserText()));