Hello guys, I am trying to read off the subject, predicate, and object from 3 different arrayList and whatever they are, I create some ValueFactory and bind them to the query. Below is an example of what I am trying to do though:

ValueFactory f = con.getValueFactory(); TupleQuery query = con.prepareTupleQuery(QueryLanguage.SPARQL, testQuery); TupleQueryResult result = query.evaluate();

        while (result.hasNext()) {
            BindingSet bindingSet = result.next();
            Value resource = bindingSet.getValue("c");
            subjectArrayList.add(resource.toString());
        }

        int i = 0;
        while (!predicateArrayList.isEmpty()
                && i < predicateArrayList.size()) {
            // URI uri = f.createURI(subjectArrayList.get(i));
            if (i == predicateArrayList.size() - 1
                    || (predicateArrayList.size() == 1)) {
                query.setBinding("c",
                        f.createBNode(subjectArrayList.get(i)));
                query.setBinding("p",
                        f.createURI(predicateArrayList.get(i)));
                query.setBinding(
                        "o",
                        f.createLiteral("\"" + userInputArrayList.get(i)
                                + "\"" + "."));

Update update = con.prepareUpdate(QueryLanguage.SPARQL, updateQuery); update.execute();

After this, I went to the sesame workbench and ran the query to see if the triple was changed dynamically but it didn't. Anyone care to explain why this didn't change?

asked 09 May '14, 17:32

helpdesk's gravatar image

helpdesk
1224
accept rate: 0%

edited 09 May '14, 20:09


It does not work like that. E.g. you could not modify your data by altering the bindings of a query result. You'll need to remove the no longer needed triples and add the newly ones erither by using add/remove operations to the repository or executing a sparql update.

link

answered 10 May '14, 02:11

Damyan%20Ognyanov's gravatar image

Damyan Ognyanov ♦♦
34317
accept rate: 25%

Hello, I did execute the openrdf sparql udate query as shown in my code:

        while (result.hasNext()) {
            BindingSet bindingSet = result.next();
            Value resource = bindingSet.getValue("c");
            subjectArrayList.add(resource.toString());
        }

int i = 0;
        while (!predicateArrayList.isEmpty()
                && i < predicateArrayList.size()) {
            if (i == predicateArrayList.size() - 1
                    || (predicateArrayList.size() == 1)) {
                query.setBinding("c",
                        f.createBNode(subjectArrayList.get(i)));
                query.setBinding("p",
                        f.createURI(predicateArrayList.get(i)));
                query.setBinding(
                        "o",
                        f.createLiteral("\"" + userInputArrayList.get(i)
                                + "\"" + "."));
            } else {
                query.setBinding("c",
                        f.createBNode(subjectArrayList.get(i)));
                query.setBinding("p",
                        f.createURI(predicateArrayList.get(i)));
                query.setBinding(
                        "o",
                        f.createLiteral("\"" + userInputArrayList.get(i)
                                + "\"" + ";"));
                System.out.println(query.getBindings());
            }
            i++;
            // update sparql here..
            Update update = con.prepareUpdate(QueryLanguage.SPARQL,
                    updateQuery);
            update.execute();

}
(10 May '14, 06:46) helpdesk
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×18

Asked: 09 May '14, 17:32

Seen: 4,423 times

Last updated: 01 Jun, 04:43

powered by BitNami OSQA