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
   | Model model=ModelFactory.createDefaultModel() ;
				    	 		FileManager fm = FileManager.get();
				    	 	    fm.addLocatorClassLoader(Form3.class.getClassLoader());
				    	 	    InputStream in = fm.open("Ontofolder\\MetaProPOS.owl");
 
								Location location = new Location ("C:/TDB-0.8.10/Store/DB1");
								Dataset dataset = TDBFactory.createDataset(location);
				    	 	    dataset.begin(ReadWrite.WRITE);
 
								// Load some initial data
 
							    try {
						            TDBLoader.load(TDBInternal.getBaseDatasetGraphTDB(dataset.asDatasetGraph()), in, false);
						            dataset.commit();
						        } catch (Exception e) {
						            dataset.abort();
						        } finally {
						            dataset.end();
						        }
 
 
 
 
 
				    	 	    String NL = "\n" ;
 
 
				    	 	    String requete = "PREFIX onto: <http://www.semanticweb.org/ontologies/2010/9/MetaPatternOntology.owl> \r"
				    	 	    	+NL+"INSERT DATA {"
				    	 	    	+NL+"    <http://www.semanticweb.org/ontologies/2010/9/MetaPatternOntology.owl#Identification>   a   onto:Identification;"
				    	 	    	+NL+"        onto:Identifier onto:hasIdentifier \"" + table_1.getModel().getValueAt(0,0) + "\" . "
				    	 	    	+NL+"        onto:Name onto:hasName \"" + table_1.getModel().getValueAt(0,1) + "\" . "
				    	 	    	+NL+"        onto:Author onto:hasAuthor \"" + table_1.getModel().getValueAt(0,2) + "\" . "
				    	 	    	+NL+"}";
 
 
 
				    	 	    GraphStore graphstore=GraphStoreFactory.create();
				    	 	    graphstore.setDefaultGraph(model.getGraph());
				    	 	    UpdateRequest updaterequest=UpdateFactory.create(requete);
				    	 	    UpdateAction.execute(updaterequest, graphstore);
				    	 	    OutputStream path = System.out ;
				    	 	    model.write(path, "RDF/XML-ABBREV");
 
				    	 	    /**OutputStream path;
                                                    try {
                                                        path = new FileOutputStream(new File("Ontofolder\\MetaProPOS.owl"));
                                                        model.write(path, "RDF/XML-ABBREV");
                                                    } catch (FileNotFoundException e) {
                                                        // TODO Auto-generated catch block
                                                        e.printStackTrace();
                                                    }**/
 
				    	 	    Query query = QueryFactory.create(requete);
				    	 	    QueryExecution qexec = QueryExecutionFactory.create(query, dataset);
			    	 	    	try {
			    	 	    		ResultSet results = qexec.execSelect();
			    	 	    		   while (  results.hasNext()) {
			    	 	    			   QuerySolution soln = results.nextSolution();
			    	 	    			   Literal identifier = soln.getLiteral((String) table_1.getModel().getValueAt(0, 0));
			    	 	    			   Literal name = soln.getLiteral((String) table_1.getModel().getValueAt(0, 1));
			    	 	    			   Literal author = soln.getLiteral((String) table_1.getModel().getValueAt(0, 2));
			    	 	    			   System.out.println((String) table_1.getModel().getValueAt(0, 0));
			    	 	    			   System.out.println((String) table_1.getModel().getValueAt(0, 1));
			    	 	    			   System.out.println((String) table_1.getModel().getValueAt(0, 2));
			    	 	    			   //RDFNode x = soln.get("varName") ;       // Get a result variable by name.
			    	 	    			   //Resource r = soln.getResource("VarR") ; // Get a result variable - must be a resource
								           //Literal l = soln.getLiteral("VarL") ;   // Get a result variable - must be a literal
			    	 	    			   }
			    	 	    		   } finally {
			    	 	    			   qexec.close();
			    	 	    			   }
 
 
 
			    	 	    		  dataset.begin(ReadWrite.READ);
			    	 	    		   try {
 
			    	 	    		   Iterator<Quad> iter = dataset.asDatasetGraph().find();
 
			    	 	    		   while ( iter.hasNext() ) {
			    	 	    			   Quad quad = iter.next();
			    	 	    			   System.out.println(quad);
			    	 	    			   }
			    	 	    		   } finally {
			    	 	    			   dataset.end();
			    	 	    		   } | 
Partager