开发者

Insert an Induvidual to file.owl

开发者 https://www.devze.com 2023-03-11 23:30 出处:网络
I\'m trying to insert an individual into my file owl with Sparql update 1.1 but it doesn\'t work. If any one has an example, please don\'t hesitate to give me an answer.

I'm trying to insert an individual into my file owl with Sparql update 1.1 but it doesn't work. If any one has an example, please don't hesitate to give me an answer.

public static void main(String[] args) {
    // TODO Auto-generated method stub
    String ont="http://localhost:8080/webdav/elearning";
    OntModel model=ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
    model.read(ont+".owl");
    String requete="PREFIX table: <http://www.owl-ontologies.com/Ontology1239120737.owl#>\r\n" +
    "INSERT DATA { table:etud1 :APourNom 'Saleh' ." +
    " table:etud1 :APourLogin 'saleh' ." +
    " table:etud1 :APourPWD 'saleh' . }";

    GraphStore graphstore=GraphStoreFactory.create();
    graphstore.setDefaultGraph(model.getGraph());
    UpdateRequest updaterequest=UpdateFactory.create(requete);
    updaterequest.exec(graphstore);
    System.out.println("OK");
}

When I run my开发者_如何学运维 program, I get a message that tells me that all is ok but when I open my ontology, I don't find the element inserted. Please help me to resolve this problem.


What you are doing here is to update an in-memory graph object which contains a copy the contents of your ontology, which you originally fetched from http://localhost:8080/webdav/elearning. That copy is not the same as the document hosted by the application server sitting on port 8080, so it's not surprising that you don't see changes in the original app-server hosted document.

There are basically four ways you can go about this:

  • Instead of a normal web server (like Tomcat or Jetty), you have an RDF-specific data server, such as Fuseki. Then, correctly configured, it will be able to respond to SPARQL update requests directly - so rather than copy the document into a local graph you update the graph in-situ.

  • You could do as you are doing now, and then when you are finished updating the graph you can arrange to HTTP POST the updated graph back to the application server on port 8080. This will require you to set up a route for the update (e.g. http://localhost:8080/webdav/elearning/update) and a suitable handler, but it's quite doable.

  • Instead of accessing your ontology from a web URL, you could instead access a file on your file system. Again, though, once you are finished updating you will have to save the contents of the updated graph back to the file system.

  • Instead of accessing your ontology from a web URL, you could instead load it into a persistent store such as TDB. With this approach, you open up a Jena Dataset which connects directly to the store, and run the SPARQL queries and updates against that. There is no need to separately save anything: all updates will go directly into the TDB instance.

Your original sample uses Pellet as a reasoning engine. If this is important for your application, then really you do want a copy of the data in-memory for efficiency. Thus the second and third solutions above would be better suited than the others.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号