Sparql query doesn't upadate when insert some data through java code

前端 未结 1 2081
故里飘歌
故里飘歌 2021-01-06 12:38

I\'m trying to insert data through my java code to the owl file which is loaded into Fuseki server. Update query doesn\'t give any error message. But owl file doesn\'t updat

相关标签:
1条回答
  • 2021-01-06 13:09

    It would help if you have provided a minimal complete example i.e. you had included your Fuseki configuration and the details of how your OWL file is loaded into Fuseki.

    However I will assume you have not used any specific configuration and just launching Fuseki like so:

    java -jar fuseki-server-VER.jar --update --loc /path/to/db /ds
    

    So what you've done here is launch Fuseki with updates enabled and using the location /path/to/db as the on-disk TDB database location and the URL /ds for your dataset

    The you open your browser and click through Control Panel > /ds and then use the Upload file function to upload your OWL file. When you upload a file it is read into Fuseki and copied into the dataset, in this example your dataset is the on disk TDB database located at /path/to/db.

    It is important to understand that no reference to the original file is kept since Fuseki has simply copied the data from the file to the dataset.

    You then use the SPARQL Update form to add some data (or in your case you do this via Java code). The update is applied to the dataset which to reiterate is in this example the on disk TDB database located at /path/to/db which has no reference to the original file. Therefore your original file will not change.

    Using SPARQL Update to update the original file

    If Fuseki is not essential then you could just load your file into local memory and run the update there instead:

    Model m = ModelFactory.createDefaultModel();
    m.read("example.owl", "RDF/XML");
    
    // Prepare your update...
    
    // Create an UpdateExecution on the local model
    UpdateProcessor processor = UpdateExecutionFactory.create(update, GraphStoreFactory.create(m));
    processor.execute();
    
    // Save the updated model 
    updated.write(new FileOutputStream("example.owl"), "RDF/XML");
    

    However if you want to/must stick with using Fuseki you can update your original file by retrieving the modified graph from Fuseki and writing it back out to your file e.g.

    DatasetAccessor accessor = DatasetAccessorFactory.createHTTP("http://localhost:3030/ds/data");
    
    // Download the updated model
    Model updated = accessor.getModel();
    
    // Save the updated model over the original file
    updated.write(new FileOutputStream("example.owl"), "RDF/XML");
    

    This example assumes that you have loaded the OWL file into the default graph, if not use the getModel("http://graph") overload to load the relevant named graph

    0 讨论(0)
提交回复
热议问题