store = $store; $this->graph = $graph; $this->url = $url; } function update_tagging($graph, $taggings) { global $secret; if($taggings['key'] != $secret) { echo "Wrong key, try again"; die(); } foreach($taggings as $tagging => $moat) { /// TODO - check pour gerer la cle differement /// TODO - remove unwanted taggings !! if(!is_array($moat)) continue; foreach($moat as $tag => $uris) { foreach($uris as $uri => $value) { $ok = null; if($uri == 'new' && $value) $ok = $value; if($uri != 'new' && $value == 'on') $ok = $uri; if($ok) { $msg[] = $this->moat_tagging($graph, $tagging, $tag, $ok); $this->autotag($tag); } } } } return $msg; } // Define the meaning of a tag in a particular tagging action function moat_tagging($graph, $tagging, $tag, $uri, $type = 'moat:ValidatedTagging') { $valid = true; // do not run the check test for automatic tagging, as it's already done in the past // since automatic tagging implies it was done at least manually if($type != 'moat:AutomatedTagging') { $valid = $this->check_uri($uri); } if($valid) { $meaning = "<$tagging> moat:tagMeaning <$uri> ; moat:taggingType $type ."; $this->store->do_query("INSERT INTO <$graph> { $meaning }"); LODrTools::moat_ping($graph); LODrTools::ping($graph); } else { return "Error: <$uri> does not seem to be a ressource URI"; } } function check_uri($uri) { $urigraph = LODrTools::get_datagraph($uri); $this->store->do_query("LOAD <$uri> INTO <$urigraph> "); $res = $this->store->do_query("SELECT ?o WHERE { GRAPH <$urigraph> { <$uri> rdf:type ?o } }"); if(count($res['result']['rows']) > 0) return true; else { $this->store->do_query("DELETE FROM <$urigraph>"); return false; } } /// Ici on taggue tout ! - action autotag = 1 public function autotag($tag) { // 1) Get all possible meanings for this tag $query = " SELECT DISTINCT ?uri WHERE { ?tagging a tags:RestrictedTagging ; tags:taggedWithTag <$tag> ; moat:tagMeaning ?uri . }"; $res = $this->store->do_query($query); foreach($res['result']['rows'] as $row) { $global[] = $row['uri']; } // 2) Get all the items with that tag that have not onlready been MOAT-ed $query = " SELECT DISTINCT ?graph ?tagging WHERE { graph ?graph { ?tagging a tags:RestrictedTagging ; tags:taggedWithTag <$tag> . } OPTIONAL { ?tagging moat:tagMeaning ?uri } . FILTER (!bound(?uri)) }"; $res = $this->store->do_query($query); foreach($res['result']['rows'] as $row) { $graph = $row['graph']; $tagging = $row['tagging']; if(sizeof($global) == 1) { $this->moat_tagging($graph, $tagging, $tag, $global[0], 'moat:AutomatedTagging'); } else { if($autotag == 1) return; if($autotag == 2) { foreach($global as $uri) { $this->moat_tagging($graph, $tagging, $tag, $uri, 'moat:AutomatedTagging'); } } } } } } ?>