public function getComments(\DateTime $startDate, \DateTime $endDate) { $startDate = (new Literal\DateTime($startDate))->dumpValue('text'); $endDate = (new Literal\DateTime($endDate))->dumpValue('text'); $query = <<<QUERY select ?comment ?author ?creationDate ?entity ?entityAuthor ?parent ?parentAuthor where { ?comment a tal:Comment . ?comment tal:author ?author . ?comment tal:relatedObject ?entity . OPTIONAL { ?comment tal:parent ?parent . ?parent tal:author ?parentAuthor . } . OPTIONAL { ?entity tal:author ?entityAuthor . }. ?comment tal:creationDate ?creationDate . FILTER (?creationDate > {$startDate} && ?creationDate < {$endDate}) . } QUERY; echo $query; $result = $this->endpoint->query($query); return $result; }
public function isSubscribed($agentURI) { $query = <<<QUERY PREFIX tal:<http://semantic.talaka.by/ns/talaka.owl#> PREFIX xsd:<http://www.w3.org/2001/XMLSchema#> SELECT ?type ?period WHERE { <{$agentURI}> tal:subscriptionApplied ?subscription . ?subscription tal:subscriptionType ?type . ?subscription tal:subscriptionPeriod ?period . } QUERY; $subscriptions = []; try { $result = $this->endpoint->query($query); foreach ($result as $resource) { $subscriptions[] = ['uri' => $resource->type->getURI(), 'period' => $resource->period->getValue()]; } } catch (\EasyRdf\Http\Exception $e) { echo $e->getBody(); } return $subscriptions; }
/** * Perform query * * @param string $item * @param array $arguments * @return \EasyRdf\Graph|\EasyRdf\Sparql\Result */ private function query($item, array $arguments = []) { $sparql = preg_replace_callback('/%(\\d+)%/', function (array $matches) use($arguments) { $position = intval($matches[1], 10) - 1; $value = $arguments[$position]; return $value; }, $this->queries[$item]); return $this->sparqlClient->query($sparql); }
<?php use EasyRdf\Sparql\Client as Sparql; function nomAccess($elem) { return $elem->nom->getValue(); } $app->get('/query', function () use($app) { $sparql = new Sparql('http://fr.dbpedia.org/sparql'); /** * Trois critères de recherches : * - departement * - nombre d'habitants * - langue d'affichage */ //$departement = "http://fr.dbpedia.org/resource/Savoie_(département)" $default_langue = 'fr'; $departement = $app->request()->params('dpt'); $nb_habitants = $app->request()->params('pop'); $langue = $app->request()->params('lang'); $order_by = $app->request()->params('order_by'); $order = $app->request()->params('order'); $villes = $sparql->query("\n prefix db-owl: <http://dbpedia.org/ontology/>\n select ?nom, ?population, ?comment where {\n ?ville db-owl:department <{$departement}> .\n ?ville rdf:type db-owl:Settlement .\n ?ville db-owl:populationTotal ?population .\n ?ville rdfs:label ?nom .\n ?ville rdfs:comment ?comment .\n FILTER (?population > {$nb_habitants}) .\n FILTER ( LANGMATCHES(LANG(?nom), \"{$langue}\") ) .\n FILTER ( LANGMATCHES(LANG(?comment), \"{$langue}\") ) .\n }\n order by {$order}(?{$order_by})\n "); $liste_villes = $sparql->query("\n prefix db-owl: <http://dbpedia.org/ontology/>\n select ?departement, ?nom where {\n ?departement rdf:type dbpedia-owl:Department .\n ?departement dbpedia-owl:region dbpedia-fr:Rhône-Alpes .\n ?departement rdfs:label ?nom .\n FILTER ( LANGMATCHES(LANG(?nom), \"{$default_langue}\") ) .\n }\n order by ?nom\n "); $langues = ['fr', 'en', 'pl', 'de', 'pt', 'es', 'eu', 'ca', 'it', 'hu', 'id', 'tr', 'nl', 'cs', 'bg', 'ru', 'ja', 'ko']; $app->render('home', ['isEmpty' => count($villes) <= 0, 'default_form_value' => array('pop_min' => 10, 'dpt_selected' => '', 'lang_selected' => $default_langue, 'order_by' => array('nom' => array('label' => "Nom", 'checked' => true), 'population' => array('label' => "Nombre d'habitants", 'checked' => false)), 'order' => array('ASC' => array('label' => "ASC", 'checked' => true), 'DESC' => array('label' => "DESC", 'checked' => false))), 'selected_filters' => array('dpt' => $departement, 'pop' => $nb_habitants, 'lang' => $langue, 'order_by' => $order_by, 'order' => $order), 'langues' => $langues, 'villes' => array_map(function ($elem) { return array('nom' => $elem->nom->getValue(), 'population' => $elem->population->getValue(), 'comment' => $elem->comment->getValue()); }, (array) $villes), 'liste_villes' => array_map(function ($elem) { return array($elem->departement->getUri() => $elem->nom->getValue()); }, (array) $liste_villes)]); })->name('query');