function test_is_empty()
 {
     $g = new SimpleGraph();
     $this->assertTrue($g->is_empty());
     $g->add_resource_triple('http://example.org/subj', 'http://example.org/pred1', 'http://example.org/obj1');
     $this->assertFalse($g->is_empty());
 }
 function get_differences($query_results)
 {
     $res = $query_results;
     $g_before = new SimpleGraph();
     $g_after = new SimpleGraph();
     $row_count = $res->num_rows();
     $node_index = 0;
     $diffs = array();
     if ($row_count === 0) {
         if ($this->_subject) {
             $s = $this->_subject;
         } else {
             $s = "_:s";
         }
         $g_after = $this->get_data_as_graph($s);
         $index = $g_after->get_index();
         if (array_key_exists($s, $index)) {
             $additions = $index[$s];
         } else {
             $additions = array();
         }
         $diffs[$s] = array('additions' => $additions, 'removals' => array());
     } else {
         $subjects = array();
         for ($i = 0; $i < $row_count; $i++) {
             $row = $res->row_array($i);
             $rowdata = $res->rowdata($i);
             if (array_key_exists('_uri', $row)) {
                 $s = $row['_uri'];
             } else {
                 if ($this->_subject) {
                     $s = $this->_subject;
                 } else {
                     $s = "_:s";
                 }
             }
             $subjects[] = $s;
             foreach ($this->_data as $field => $field_info) {
                 if (array_key_exists($field, $row)) {
                     $p = $this->_rmap[$field];
                     if ($rowdata[$field]['type'] === 'literal') {
                         $g_before->add_literal_triple($s, $p, $row[$field], $rowdata[$field]['lang'], $rowdata[$field]['datatype']);
                     } else {
                         if ($rowdata[$field]['type'] === 'uri') {
                             $g_before->add_resource_triple($s, $p, $row[$field]);
                         } else {
                             if ($rowdata[$field]['type'] === 'bnode') {
                                 $g_before->add_resource_triple($s, $p, '_:' . $row[$field]);
                             }
                         }
                     }
                 }
             }
         }
         if (count($subjects) > 0) {
             $subjects = array_unique($subjects);
             foreach ($subjects as $s) {
                 $g_after->add_graph($this->get_data_as_graph($s));
             }
         }
         if ($g_after->is_empty()) {
             $additions = array();
             if ($g_before->is_empty()) {
                 $removals = array();
             } else {
                 $removals = $g_before->get_index();
             }
         } else {
             if ($g_before->is_empty()) {
                 $additions = $g_after->get_index();
                 $removals = array();
             } else {
                 $removals = SimpleGraph::diff($g_before->get_index(), $g_after->get_index());
                 $additions = SimpleGraph::diff($g_after->get_index(), $g_before->get_index());
             }
         }
         foreach ($subjects as $s) {
             $diff = array('additions' => array(), 'removals' => array());
             if (array_key_exists($s, $additions)) {
                 $diff['additions'] = $additions[$s];
             }
             if (array_key_exists($s, $removals)) {
                 $diff['removals'] = $removals[$s];
             }
             $diffs[$s] = $diff;
         }
     }
     return $diffs;
 }