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 persist($entity)
 {
     $reflection = new \ReflectionClass($entity);
     $originURI = $entity->getOrigin();
     if (!$originURI) {
         throw new \Exception("Cannot persist entity, because origin URI is not defined");
     }
     $sparql = '';
     $annotationReader = new AnnotationReader();
     $iri = $annotationReader->getClassAnnotation($reflection, 'Soil\\DiscoverBundle\\Annotation\\Iri');
     if ($iri) {
         $iri = $iri->value;
         $sparql .= "<{$originURI}> rdf:type {$iri} . " . PHP_EOL;
     }
     $props = $reflection->getProperties();
     foreach ($props as $prop) {
         $matchAnnotation = $annotationReader->getPropertyAnnotation($prop, 'Soil\\DiscoverBundle\\Annotation\\Iri');
         if ($matchAnnotation && $matchAnnotation->persist) {
             $match = $matchAnnotation->value;
             $prop->setAccessible(true);
             $value = $prop->getValue($entity);
             $sparql .= "<{$originURI}> {$match} <{$value}> . " . PHP_EOL;
         }
     }
     if ($sparql) {
         $this->logger->addInfo('Persisting: ');
         $this->logger->addInfo($sparql);
         $num = $this->endpoint->insert($sparql);
         $this->logger->addInfo('Return: ' . print_r($num, true));
         return $num;
     } else {
         return null;
     }
 }
Exemplo n.º 3
0
 /**
  * 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);
 }
    public function subscribe($agentURI, $digestSubscriptionURI, $period)
    {
        $index = 1;
        $query = <<<INSERT
            <{$agentURI}> tal:subscriptionApplied _:b{$index} .
            _:b{$index} tal:subscriptionType <{$digestSubscriptionURI}> .
            _:b{$index} tal:subscriptionPeriod {$period} .
INSERT;
        $graphIRI = 'tal:SubscriptionGraph';
        $graphURI = RdfNamespace::expand($graphIRI);
        echo $query;
        try {
            $this->endpoint->insert($query, $graphURI);
        } catch (\EasyRdf\Http\Exception $e) {
            echo $e->getBody();
        }
    }
<?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');