コード例 #1
0
 function test_merge_object_call()
 {
     $g1 = array('#x' => array('name' => array(array('value' => 'Joe', 'type' => 'literal'))), '_:y' => array('name' => array(array('value' => 'Joan', 'type' => 'literal'))));
     $g2 = array('#x' => array('knows' => array(array('value' => '_:y', 'type' => 'bnode'))), '_:y' => array('name' => array(array('value' => 'Susan', 'type' => 'literal'))));
     $g3 = array('#x' => array('name' => array(0 => array('value' => 'Joe', 'type' => 'literal')), 'knows' => array(0 => array('value' => '_:y1', 'type' => 'bnode'))), '_:y' => array('name' => array(0 => array('value' => 'Joan', 'type' => 'literal'))), '_:y1' => array('name' => array(0 => array('value' => 'Susan', 'type' => 'literal'))));
     $g4 = array('#x' => array('#knows' => array('type' => 'uri', 'value' => 'Me')));
     $graph = new SimpleGraph($g1);
     $r1 = $graph->merge($g2);
     $this->assertEquals($r1, $g3);
 }
コード例 #2
0
 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 = SimpleGraph::diff($this->after, $this->before);
     }
     //Get the triples to be removed
     if (empty($this->after)) {
         $removals = $this->before;
     } else {
         $removals = SimpleGraph::diff($this->before, $this->after);
     }
     // $removals = !empty($this->after)? SimpleGraph::diff($this->before, $this->after) : $this->before;
     //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]);
                 }
             }
         }
     }
     //    print_r(array_keys($additions));
     //    print_r(array_keys($removals));
     //    print_r(array_merge(array_keys($additions), array_keys($removals)));
     // 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)));
     //    print_r($subjectIndex);
     // 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 = SimpleGraph::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 = SimpleGraph::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');
         }
     }
     // foreach($this->_index as $uri => $props){
     //  if(
     //      !isset($props[$CSNS.'removal'])
     //      AND
     //      !isset($props[$CSNS.'addition'])
     //      ){
     //        unset($this->_index[$uri]);
     //    }
     //
     // }
     $this->_index = SimpleGraph::merge($this->_index, $reifiedAdditions, $reifiedRemovals);
 }