Example #1
0
 protected function __init()
 {
     $csIndex = array();
     $CSNS = 'http://purl.org/vocab/changeset/schema#';
     // Get the triples to be added
     if (empty($this->before)) {
         $additions = $this->after;
     } else {
         $additions = ExtendedGraph::diff($this->after, $this->before);
     }
     //Get the triples to be removed
     if (empty($this->after)) {
         $removals = $this->before;
     } else {
         $removals = ExtendedGraph::diff($this->before, $this->after);
     }
     //remove etag triples
     foreach (array('removals' => $removals, 'additions' => $additions) as $name => $graph) {
         foreach ($graph as $uri => $properties) {
             if (isset($properties["http://schemas.talis.com/2005/dir/schema#etag"])) {
                 unset(${$name}[$uri]["http://schemas.talis.com/2005/dir/schema#etag"]);
                 if (count(${$name}[$uri]) == 0) {
                     unset(${$name}[$uri]);
                 }
             }
         }
     }
     // Get an array of all the subject uris
     $subjectIndex = !empty($this->a['subjectOfChange']) ? array($this->a['subjectOfChange']) : array_unique(array_merge(array_keys($additions), array_keys($removals)));
     // Get the metadata for all the changesets
     $date = !empty($this->a['createdDate']) ? $this->a['createdDate'] : date(DATE_ATOM);
     $creator = !empty($this->a['creatorName']) ? $this->a['creatorName'] : 'Moriarty ChangeSet Builder';
     $reason = !empty($this->a['changeReason']) ? $this->a['changeReason'] : 'Change using Moriarty ChangeSet Builder';
     $csCount = 0;
     foreach ($subjectIndex as $subjectOfChange) {
         $csID = '_:cs' . $csCount;
         $csIndex[$subjectOfChange] = $csID;
         $this->addT($csID, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $CSNS . 'ChangeSet', 'uri');
         $subjectType = strpos($subjectOfChange, '_:') === 0 ? 'bnode' : 'uri';
         $this->addT($csID, $CSNS . 'subjectOfChange', $subjectOfChange, $subjectType);
         $this->addT($csID, $CSNS . 'createdDate', $date, 'literal');
         $this->addT($csID, $CSNS . 'creatorName', $creator, 'literal');
         $this->addT($csID, $CSNS . 'changeReason', $reason, 'literal');
         /* add extra user-given properties to each changeset*/
         if (!empty($this->a['properties'])) {
             foreach ($this->a['properties'] as $p => $objs) {
                 $this->addT($csID, $p, $objs);
             }
         }
         $csCount++;
     }
     /*iterate through the triples to be added,
       reifying them,
       and linking to the Statements from the appropriate changeset
       */
     $reifiedAdditions = ExtendedGraph::reify($additions, 'Add');
     if (!empty($reifiedAdditions)) {
         foreach ($reifiedAdditions as $nodeID => $props) {
             $subject = $props['http://www.w3.org/1999/02/22-rdf-syntax-ns#subject'][0]['value'];
             if (in_array($subject, $subjectIndex)) {
                 $csID = $csIndex[$subject];
                 $this->addT($csID, $CSNS . 'addition', $nodeID, 'bnode');
             }
             // if dc:source is given in the instantiating arguments, add it to the statement as provenance
             if (isset($this->a['http://purl.org/dc/terms/source'])) {
                 $this->addT($nodeID, 'http://purl.org/dc/terms/source', $this->a['http://purl.org/dc/terms/source'], 'uri');
             }
         }
     }
     /*iterate through the triples to be removed,
       reifying them,
       and linking to the Statements from the appropriate changeset
       */
     $reifiedRemovals = ExtendedGraph::reify($removals, 'Remove');
     foreach ($reifiedRemovals as $nodeID => $props) {
         $subject = $props['http://www.w3.org/1999/02/22-rdf-syntax-ns#subject'][0]['value'];
         if (in_array($subject, $subjectIndex)) {
             $csID = $csIndex[$subject];
             $this->addT($csID, $CSNS . 'removal', $nodeID, 'bnode');
         }
     }
     $this->_index = ExtendedGraph::merge($this->_index, $reifiedAdditions, $reifiedRemovals);
 }
Example #2
0
 /**
  * @param ExtendedGraph $otherGraph
  * @return bool
  */
 public function is_equal_to(ExtendedGraph $otherGraph)
 {
     $diffThisAndThat = ExtendedGraph::diff($this->get_index(), $otherGraph->get_index());
     $diffThatAndThis = ExtendedGraph::diff($otherGraph->get_index(), $this->get_index());
     return empty($diffThisAndThat) && empty($diffThatAndThis);
 }