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
| public class Insert extends JPanel{
public static final String owlFile="file:///C:/Program Files/Protege_3.4.7/examples/Krs1.owl";
public static final String NL = System.getProperty("line.separator") ;
private JLabel label = new JLabel("Une ComboBox");
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 m=ModelFactory.createMemModelMaker().createModel(null);
// Lecture du fichier OWL. Le Namespace de notre ontologie doit etre specifié
FileManager.get().readModel( m, owlFile );
//
String myOntologyName = "ProjetHela";
String uri="file:///C:/Program 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
// + had + NL
String queryString=
"PREFIX reuses: <http://www.owl-ontologies.com/reuses.owl#>"
+ "SELECT ?hasnameelement"
+ " WHERE "
+ "{"
+ "?Element reuses:hasnameelement ?hasnameelement"
+ " } ";
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, m) ;
JFrame frame = new JFrame("choix");
// frame.setSize(900,450);
frame.setMinimumSize(new Dimension(700, 200));
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setLocationRelativeTo(SwingUtilities.getRoot(frame));
JComboBox com= new JComboBox();
com.setBounds(70, 50, 70, 25);
JDesktopPane desktop = new JDesktopPane();
frame.setLayout(new FlowLayout ());
//Choice c = new Choice();
frame.add(com);
frame.show();
frame.pack();
// 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("hasnameelement").getString();
//frame.addItem(rs.getString(y.toString()));
//System.out.print}
com.addItem(y.toString() + ";\n");
}
/* for(Iterator i=m.listClasses();i.hasNext();)
{
OntClass c = (OntClass) i.next();
com.addItem(c.getLocalName());
}
return com; }*/
}
finally{
qexec.close() ;
}
}
} |
Partager