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