Exemple #1
0
 /**
  * @param ExtendedGraph $graph
  */
 public function label_graph(ExtendedGraph &$graph)
 {
     $labelled_properties = array();
     $index = $graph->get_index();
     foreach ($index as $s => $p_list) {
         foreach ($p_list as $p => $val) {
             if (!array_key_exists($p, $labelled_properties)) {
                 if (array_key_exists($p, $this->_labels)) {
                     if (!$graph->subject_has_property($p, RDFS_LABEL)) {
                         $graph->add_literal_triple($p, RDFS_LABEL, $this->_labels[$p][0]);
                     }
                     if (!$graph->subject_has_property($p, 'http://purl.org/net/vocab/2004/03/label#plural')) {
                         if (count($this->_labels[$p]) > 1) {
                             $graph->add_literal_triple($p, 'http://purl.org/net/vocab/2004/03/label#plural', $this->_labels[$p][1]);
                         } else {
                             $graph->add_literal_triple($p, 'http://purl.org/net/vocab/2004/03/label#plural', $this->_labels[$p][0] . 's');
                         }
                     }
                     if (!$graph->subject_has_property($p, 'http://purl.org/net/vocab/2004/03/label#inverseSingular')) {
                         if (count($this->_labels[$p]) > 2) {
                             $graph->add_literal_triple($p, 'http://purl.org/net/vocab/2004/03/label#inverseSingular', $this->_labels[$p][2]);
                         } else {
                             $graph->add_literal_triple($p, 'http://purl.org/net/vocab/2004/03/label#inverseSingular', 'is ' . $this->_labels[$p][0] . ' of');
                         }
                     }
                     $labelled_properties[$p] = 1;
                 } else {
                     if (preg_match('~^http://www.w3.org/1999/02/22-rdf-syntax-ns#_(.+)$~', $p, $m)) {
                         $graph->add_literal_triple($p, RDFS_LABEL, 'Item ' . $m[1]);
                         $labelled_properties[$p] = 1;
                     }
                 }
             }
         }
     }
 }
Exemple #2
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);
 }
 /**
  * @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);
 }