Récupérer des instances d'une ontologie

Résolu
helaba Messages postés 12 Date d'inscription vendredi 10 décembre 2010 Statut Membre Derniè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)

SVP aidez moi

9 réponses

Twinuts Messages postés 5375 Date d'inscription dimanche 4 mai 2003 Statut Modérateur Dernière intervention 14 juin 2023 111
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 ..."

OoWORAoO
0
mwara Messages postés 6 Date d'inscription mardi 19 mai 2009 Statut Membre Dernière intervention 14 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.

Cordialement
0
mannoulty224
28 avril 2013 à 22:50
Bonjour
quelle est la différence entre instance de l'ontologie et classe de l'ontologie
0
une instance est une classe spécifique alors qu'une classe c'est une classe/Concept générique*
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
Helaba svp est ce que tu as rectifié ton code?
0
helaba Messages postés 12 Date d'inscription vendredi 10 décembre 2010 Statut Membre Dernière intervention 6 septembre 2013 2
Modifié par helaba le 6/09/2013 à 01:43
voici le code de récupération des instances
	Model m=ModelFactory.createMemModelMaker().createModel(null);
		FileManager.get().readModel( m, owlFile );
		String myOntologyName = "ProjetHela";
		String uri="file:///C:/Project/Krs1.owl";
		// Définition de prefixe pour simplifier l'utilisation de SPARQL
		String reuses = "maj: <"+RDF.getURI()+">" ;
		// String myOntologyPrefix = "PREFIX "+myOntologyName+": <"+myOntologyNS+">" ;
		String myOntologyPrefix = "PREFIX "+myOntologyName+": <"+uri+">" ;
		String queryString= 
			"PREFIX maj: <http://www.owl-ontologies.com/reuses.owl#>"
			+ "SELECT ?hasnamebesoin"
			+ " WHERE "
			+ "{"
			+ "?Besoin maj:hasnamebesoin ?hasnamebesoin "
			+ " } ";
		Query query = QueryFactory.create(queryString) ;

		final QueryExecution qexec = QueryExecutionFactory.create(query, m) ;
		try  {
			ResultSet rs = qexec.execSelect() ;

			// Affichage des resultats
			for ( ; rs.hasNext() ; ){
			//System.out.print("");
				
		        

		   
		    QuerySolution rb = rs.nextSolution() ;
			String y = rb.getLiteral("hasnamebesoin").getString();
			 //frame.addItem(rs.getString(y.toString()));
			//System.out.print}

			
			liste.addItem(y.toString() + ";n");
			//combo.addItem(y.getSelectedItem().toString());
			}
		}
		finally{
		qexec.close() ;

		}

bon courage
0
mannoulty224 Messages postés 4 Date d'inscription mercredi 2 juin 2010 Statut Membre Dernière intervention 12 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 ???

--
0
il se peut qu'il y a un package manquant il faut l'importer
0
mannoulty224 Messages postés 4 Date d'inscription mercredi 2 juin 2010 Statut Membre Dernière intervention 12 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
0
mannoulty224 Messages postés 4 Date d'inscription mercredi 2 juin 2010 Statut Membre Dernière intervention 12 septembre 2013
12 sept. 2013 à 10:26
Erreur d'exécution
0
peux tu poster ton code
0
ce code permet d'afficher les instances d'une ontologie mais if ne fonctionne pas aidez moi!!





package e_learning;

import edu.stanford.smi.protegex.owl.ProtegeOWL;
import edu.stanford.smi.protegex.owl.model.*;
import edu.stanford.smi.protegex.owl.jena.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.lang.*;
import edu.stanford.smi.protege.model.*;
import static java.awt.Component.CENTER_ALIGNMENT;
import org.apache.commons.logging.*;
import java.io.*;

public class affontologie extends JInternalFrame{

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()));



cont.setLayout(new GridLayout(3,4));
fen.setSize(1800,600);
fen.setVisible(true);
fen.pack();

cont.add((Component) listSession_formation);
cont.add((Component) listEvaluation);
cont.add((Component)listFormateurs);
cont.add((Component)listSeances);
cont.add((Component)listGroupes);
cont.add((Component) listApprenant);
cont.add((Component) listThemes);
cont.add((Component)listModule);
cont.add((Component)listCours );
cont.add((Component)listChapitre);
cont.add((Component) listPrpositions_Reponses );
cont.add((Component) listQuestions);

JPanel p=new JPanel();
String newline = System.getProperty("line.separator");
JLabel ch=new JLabel("selectionné des causes pour ");
JLabel ch1=new JLabel("obtenir les accident potentiel");


p.add(ch);
p.add(ch1);

p.add(des);

cont.add(p);
}
catch (Exception e){}
}
public void act(){
des.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
listSession_formation.list.clearSelection();
listEvaluation.list.clearSelection();
listFormateurs.list.clearSelection();
listSeances.list.clearSelection();
listGroupes.list.clearSelection();
listApprenant.list.clearSelection();
listThemes.list.clearSelection();
listModule.list.clearSelection();
listCours.list.clearSelection();
listChapitre.list.clearSelection();
listPrpositions_Reponses.list.clearSelection();
listQuestions.list.clearSelection();
}
});





}
0
Rejoignez-nous