Warning:
This wiki has been archived and is now read-only.
EditingFoafData
Editing Foaf files
Use Case 1
The Foafbuilder allows users to edit their existing FOAF files. Consider the example of a user editing their name:
John Smith wants to change his name to Barack Obama.
Triples before:
... <thisDocument> foaf:primaryTopic _:bNode63 _:bNode63 rdf:type foaf:Person _:bNode63 foaf:name "John Smith" ...
Triples afterwards:
... <thisDocument> foaf:primaryTopic _:bNode63 . _:bNode63 rdf:type foaf:Person . _:bNode63 foaf:name "Barack Obama" . ...
Example query:
MODIFY GRAPH <thisDocument> DELETE { ?person foaf:name ?name . } INSERT { ?person foaf:name "Barack Obama" . } WHERE { <thisDocument> foaf:primaryTopic ?person . ?person rdf:type foaf:Person . ?person foaf:name ?name . } ;
Use Case 2
A user wants to change their home address, say from somewhere in the UK to somewhere in France.
Example query:
MODIFY GRAPH <thisDocument> DELETE { ?home contact:address ?address . ?address contact:country ?country } INSERT { ?home contact:address ?address . ?address contact:country "France". } WHERE { <thisDocument> foaf:primaryTopic ?person . ?person rdf:type foaf:Person . ?person contact:home ?home . ?home rdf:type geo:ContactLocation . ?home contact:address ?address . ?address contact:country ?country } ;
Triples before:
... <thisDocument> foaf:primaryTopic _:bNode63 . _:bNode63 rdf:type foaf:Person . _:bNode63 contact:home _:bNode64 . _:bNode64 rdf:type geo:ContactLocation . _:bNode64 contact:address _:bNode65 . _:bNode65 contact:country "UK" . _:bnode64 geo:lat "1" . _:bnode64 geo:long "51" . ...
Triples afterwards:
... <thisDocument> foaf:primaryTopic _:bNode63 . _:bNode63 rdf:type foaf:Person . _:bNode63 contact:home _:bNode64 . _:bNode64 rdf:type geo:ContactLocation . _:bNode64 contact:address _:bNode65 . _:bNode65 contact:country "France" . _:bnode64 geo:lat "1" . _:bnode64 geo:long "51" . ...
This query ends up leaving the geo:lat and geo:long coordinates still pointing at the UK. I suppose we could have spotted this, deleted the old geo:lat/geo:long, and inserted correct ones. But then what if there were other triples hanging off our ?home bNode that we weren't expecting?
In the FoafBuilder, we ended up writing code to recursively delete everything hanging off a particular URI/bNode. This seems like a use case for property paths in update. Using some speculative syntax, and ignoring possible unintended side effects, we could rewrite the above query as follows:
MODIFY GRAPH < thisDocument> DELETE { ?home contact:address ?address . ?address .+ ?x } INSERT { ?home contact:address ?address . ?address contact:country "France". } WHERE { <thisDocument> foaf:primaryTopic ?person . ?person rdf:type foaf:Person . ?person contact:home ?home . ?home rdf:type geo:ContactLocation . ?home contact:address ?address . ?address contact:country ?country } ;