INSERT behaviour

1 view
Skip to first unread message

andrew....@elucidbio.com

unread,
Apr 20, 2016, 10:27:48 AM4/20/16
to Stardog
We have some code I am trying to grok.  If I am not mistaken, the intention is to add whatever is new, leaving whatever portion is already existing; that is, to the extent that triples already exist, level them alone, but to the extent anything is different, then add in such a way as to achieve the same end of the triples being there after the operation, whether they had already been there or not.  But since we are getting strange behavior, I want to check assumptions.  Is that what the code below is doing?


@
def add(self, data, graph='elucidbio'):
        expanded = jsonld.expand(data, {'base': ELUCID.iri, 'expandContext': self.context})
        rdf = jsonld.to_rdf(expanded, {'base': ELUCID.iri, 'format': 'application/nquads'})
        triples = rdf.strip().split('\n')

        update = []
        update.append('INSERT DATA')
        update.append('{')
        if graph:
            update.append('GRAPH <%s>' % (os.path.join(ELUCID.iri, graph)))
            update.append('{')

        for triple in triples:
            if isinstance(triple, tuple):
                update.append(' '.join([str(t) for t in triple]) + ' . ')
            else:
                update.append(triple)
        update.append('}')
        if graph:
            update.append('}')

        return self.update('\n'.join(update))
@

Pavel Klinov

unread,
Apr 20, 2016, 10:48:28 AM4/20/16
to sta...@clarkparsia.com
No, it's not what the code is doing. It doesn't make much sense to filter out duplicate triples when producing an INSERT DATA query since the server will do it anyway when processing the query.

The code produces a SPARQL query string for an INSERT DATA query. If you think the query produces strange results, print it before sending to the server. That way you can replicate the behavior using the Stardog CLI and track down the problem.

Cheers,
Pavel

--
-- --
You received this message because you are subscribed to the C&P "Stardog" group.
To post to this group, send email to sta...@clarkparsia.com
To unsubscribe from this group, send email to
stardog+u...@clarkparsia.com
For more options, visit this group at
http://groups.google.com/a/clarkparsia.com/group/stardog?hl=en

Andrew J. Buckler (Elucid Bioimaging)

unread,
Apr 20, 2016, 10:54:28 AM4/20/16
to sta...@clarkparsia.com

That sounds like I’m way off, then.  Are you saying that the code doesn’t add anything in, just returns a query result?

 

But, here is a snippet from https://www.w3.org/Submission/SPARQL-Update/ that suggests to me that it is inserting, not just querying?:

 

2 Examples

This section gives some example snippets in the proposed SPARQL/Update language that would be used to update a remote RDF store.

(a) Adding some triples to a graph. The snippet describes two RDF triples to be inserted into the default graph of the RDF store.

PREFIX dc: <http://purl.org/dc/elements/1.1/>

INSERT DATA

{ <http://example/book3> dc:title    "A new book" ;

                         dc:creator  "A.N.Other" .

---
You received this message because you are subscribed to a topic in the Google Groups "Stardog" group.
To unsubscribe from this topic, visit https://groups.google.com/a/clarkparsia.com/d/topic/stardog/vk2UjxDbIl8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stardog+u...@clarkparsia.com.

Pavel Klinov

unread,
Apr 20, 2016, 11:08:47 AM4/20/16
to sta...@clarkparsia.com
Very quickly: 

i) the method does send the query string to the server. But your problem is the query itself that's why I suggested to look at it before it goes to the server.
ii) I'm using the term "query" loosely meaning both SPARQL Query and Update operations. If that's confusing, you can call it "insert operation".

Pavel

Andrew J. Buckler (Elucid Bioimaging)

unread,
Apr 20, 2016, 11:12:31 AM4/20/16
to sta...@clarkparsia.com

In brief:

1.     Is it true that it looks like it is trying to add (it seems yes it does?)

2.     If the data it wants to add is already there, does it fail, or just do nothing?

3.     I am assuming if yes to question 1, then when the data it wants to add hadn’t been in the kb before, it will be after. Please confirm?

Pavel Klinov

unread,
Apr 20, 2016, 11:18:34 AM4/20/16
to sta...@clarkparsia.com
On Wed, Apr 20, 2016 at 5:12 PM, Andrew J. Buckler (Elucid Bioimaging) <andrew....@elucidbio.com> wrote:

In brief:

1.     Is it true that it looks like it is trying to add (it seems yes it does?)

Yes 

2.     If the data it wants to add is already there, does it fail, or just do nothing?

Do nothing.

3.     I am assuming if yes to question 1, then when the data it wants to add hadn’t been in the kb before, it will be after. Please confirm?

Yes 

Andrew J. Buckler (Elucid Bioimaging)

unread,
Apr 20, 2016, 11:26:33 AM4/20/16
to sta...@clarkparsia.com

Good, Pavel, this answers this one.

Reply all
Reply to author
Forward
0 new messages