Search code examples
sparqlstardog

SPARQL Update the type of an individual


I have a simple ontology which is structured that way:

| Cell
    | CellFree
    | CellTree
    | CellPlayer

My app is using Stardog and I want to dynamically update the type of an individual which is at the beginning a Cell and needs to be updated to one of the sub-classes.

My first approach was this one:

DELETE {?c rdf:type :Cell}
INSERT {?c rdf:type :CellFree}
WHERE {?c a :Cell . ?c :x 6 . ?c :y 3}

Unfortunately this deletes the cell but doesn't insert it back. How can I achieve this? Every Cell has properties and data so it's important to not lose them in the process (I'm new to SPARQL).


Solution

  • Something being a member of a subclass does not usually mean it isn't a member of the superclass (so you might just leave out the DELETE entirely). I understand this is your currently chosen workaround.

    That said, this is just a guess, and I think it shouldn't matter, but have you tried simply reversing the order of the DELETE and INSERT? Given what you've described overall, you could also try making these into two distinct SPARQL queries that are executed sequentially (in which case you definitely want to to the INSERT first). Beyond these thoughts (and even if they do what you want), the behavior you've described sounds like a bug in Stardog, so I'd also pursue direct support from them.