Constructing a Changeset
From n² wiki
Contents |
[edit] Constructing a ChangeSet
A Changeset document is an RDF/XML document describing a ChangeSet resource, and reified rdf:Statements that the ChangeSet links to as candidates either for removal, or addition, to the store.
[edit] Reification
Reification in RDF, is the construction of a resource to describe a triple. To reify a triple:
- Create a new Resource
- give it an rdf:type property of rdf:Statement
- give it an rdf:subject property, where the value is the subject of the triple
- give it an rdf:predicate property, where the value is the predicate of the triple
- give it an rdf:object property, where the value is the object of the triple
eg: (in Turtle notation) to reify
<http://example.com/> <http://purl.org/dc/elements/1.1/title> "Anna Wilder's Homepage"@en .
do:
@prefix: rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix cs:<http://purl.org/vocab/changeset/schema#> . _:Statement_1 a rdf:Statement; rdf:subject <http://example.com/> rdf:predicate <http://purl.org/dc/elements/1.1/title> rdf:object "Anna Wilder's Homepage"@en .
[edit] Creating the ChangeSet
[edit] Required properties of the ChangeSet
The ChangeSet resource should have
- an rdf:type of http://purl.org/vocab/changeset/schema#ChangeSet
- a http://purl.org/vocab/changeset/schema#subjectOfChange property, with a value equal to the rdf:subject property of every rdf:Statement (reified triple) that the ChangeSet wants to add or remove.
- a http://purl.org/vocab/changeset/schema#createdDate property
- a http://purl.org/vocab/changeset/schema#creatorName property
- a http://purl.org/vocab/changeset/schema#changeReason property
In addition (if the ChangeSet is to have any affect on your data), it should have http://purl.org/vocab/changeset/schema#addition and http://purl.org/vocab/changeset/schema#removal properties pointing to the reified triples that are to be added or removed.
[edit] Working out which triples to add and remove
- Retrieve a Concise Bounded Description of the resource you want to change the description of. It should be the most current description of the resource; if you try to remove any properties of the resource that it does not have, the whole ChangeSet will fail (ChangeSets are atomic - they work or fail completely). Think of this as the before description.
- Construct a description of the resource as you would like it to be. Think of this as the after description.
- Parse both before and after into two sets of triples.
- Iterate over the before triples
- For each before triple, look for an identical triple in the after set. If you don't find a match, reify that before triple as an rdf:Statement, and add that rdf:Statement as a cs:removal to the ChangeSet.
- Iterate over the after triples
- For each after triple, look for an identical triple in the before set. If you don't find a match, reify that after triple as an rdf:Statement, and add that rdf:Statement as a cs:addition to the ChangeSet.

