Example #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;
                     }
                 }
             }
         }
     }
 }