Adding and Removing Statements from a Graph

This topic provides instructions for using the Anzo CLI update subcommand to add and remove statements from an existing graph in the Anzo local volume. You might want to use the update subcommand when making minor changes to a graph or its metadata.

Follow these steps to update a graph:

  1. View the Existing Graph
  2. Create a TriG File with Statements to Add
  3. Create a TriG File with Statements to Remove
  4. Update the Graph with the Changes

View the Existing Graph

Use the get subcommand to view the statements for the graph that you want to change. For example, this command retrieves the statements for the movie King Kong in the Movie data set.

anzo get http://cambridgesemantics.com/Movie/473086
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
<http://cambridgesemantics.com/Movie/473086> {
<http://cambridgesemantics.com/Movie/473086>
<http://cambridgesemantics.com/ontologies/2009/08/Film#hasMovieCredits>
<http://cambridgesemantics.com/movieCredits/473086> ;
  <http://cambridgesemantics.com/ontologies/2009/08/Film#hasMovieRevenue>
<http://cambridgesemantics.com/4dcd6ab2-1234-4c07-ab96-72b16e433e39> ;
  <http://cambridgesemantics.com/ontologies/2009/08/Film#homepage> "http://kingkongmovie.com" ;
  <http://cambridgesemantics.com/ontologies/2009/08/Film#movieAbstract>
"King Kong is a 2005 epic monster film co-written, produced, and directed by Peter Jackson..." ;
  <http://cambridgesemantics.com/ontologies/2009/08/Film#movieBudget>
<http://cambridgesemantics.com/0af6876b-73a5-4e7c-b55a-0470e03be50f> ;
  <http://cambridgesemantics.com/ontologies/2009/08/Film#movieId> "473086" ;
  <http://cambridgesemantics.com/ontologies/2009/08/Film#runtime> "11280"^^xsd:int ;
  <http://cambridgesemantics.com/ontologies/2009/08/Film#title> "King Kong (2005 film)" ;
  a <http://cambridgesemantics.com/ontologies/2009/08/Film#Movie> .
}

Create a TriG File with Statements to Add

Create a new file that includes any statements that you want to add to the existing graph. For example, the TriG file below includes a statement that adds the filming location for the movie King Kong:

# king_kong_additions.trig

@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
<http://cambridgesemantics.com/Movie/473086> {
<http://cambridgesemantics.com/Movie/473086>
<http://cambridgesemantics.com/ontologies/2009/08/Film#location> "New Zealand" .
}

Create a TriG File with Statements to Remove

Create a new file that includes any statements that you want to remove from the existing graph. For example, the TriG file below includes the abstract for King Kong. Running the update subcommand with the -r option will remove this statement from the graph:

# king_kong_deletions.trig

@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
<http://cambridgesemantics.com/Movie/473086> {
<http://cambridgesemantics.com/Movie/473086>
<http://cambridgesemantics.com/ontologies/2009/08/Film#movieAbstract>
"King Kong is a 2005 epic monster film co-written, produced, and directed by Peter Jackson..."

Update the Graph with the Changes

Run the following update subcommand to add and remove statements using the TriG files that you created:

anzo update -add filename1 -r filename2

For example, the following command updates the movie graph using the two TriG files created above:

anzo update -add king_kong_additions.trig -r king_kong_deletions.trig

Using the get subcommand to viewing the resulting graph shows that the filming location is added and the abstract is deleted:

<http://cambridgesemantics.com/Movie/473086> {
  <http://cambridgesemantics.com/Movie/473086>
<http://cambridgesemantics.com/ontologies/2009/08/Film#hasMovieCredits>
<http://cambridgesemantics.com/movieCredits/473086> ;
    <http://cambridgesemantics.com/ontologies/2009/08/Film#hasMovieRevenue>
<http://cambridgesemantics.com/4dcd6ab2-1234-4c07-ab96-72b16e433e39> ;
    <http://cambridgesemantics.com/ontologies/2009/08/Film#homepage> "http://kingkongmovie.com" ;
    <http://cambridgesemantics.com/ontologies/2009/08/Film#movieBudget>
<http://cambridgesemantics.com/0af6876b-73a5-4e7c-b55a-0470e03be50f> ;
    <http://cambridgesemantics.com/ontologies/2009/08/Film#movieId> "473086" ;
    <http://cambridgesemantics.com/ontologies/2009/08/Film#runtime> "11280"^^xsd:int ; 
    <http://cambridgesemantics.com/ontologies/2009/08/Film#title> "King Kong (2005 film)" ;
    <http://cambridgesemantics.com/ontologies/2009/08/Film#location> "New Zealand" ;
    a <http://cambridgesemantics.com/ontologies/2009/08/Film#Movie> .
}