server/src/app/Repositories/RdfDocumentRepository.php
changeset 168 17f10b56c079
parent 125 e550b10fe3ca
child 169 8fddc113095e
equal deleted inserted replaced
167:009efee954f7 168:17f10b56c079
     2 
     2 
     3 namespace CorpusParole\Repositories;
     3 namespace CorpusParole\Repositories;
     4 
     4 
     5 use Config;
     5 use Config;
     6 use Log;
     6 use Log;
       
     7 use CorpusParole\Models\DocumentResult;
     7 use CorpusParole\Models\Document;
     8 use CorpusParole\Models\Document;
     8 use CorpusParole\Libraries\CorpusParoleException;
     9 use CorpusParole\Libraries\CorpusParoleException;
     9 use CorpusParole\Libraries\Sparql\SparqlClient;
    10 use CorpusParole\Libraries\Sparql\SparqlClient;
    10 use CorpusParole\Services\LexvoResolverInterface;
    11 use CorpusParole\Services\LexvoResolverInterface;
    11 
    12 
    50                 $newGraph->add($doc->doc, "http://purl.org/dc/terms/issued", $doc->issued);
    51                 $newGraph->add($doc->doc, "http://purl.org/dc/terms/issued", $doc->issued);
    51             }
    52             }
    52             if(isset($doc->modified)) {
    53             if(isset($doc->modified)) {
    53                 $newGraph->add($doc->doc, "http://purl.org/dc/terms/modified", $doc->modified);
    54                 $newGraph->add($doc->doc, "http://purl.org/dc/terms/modified", $doc->modified);
    54             }
    55             }
    55             array_push($data, new Document($doc->uri->getUri(), $newGraph));
    56             array_push($data, new DocumentResult($doc->uri->getUri(), $newGraph));
    56         }
    57         }
    57 
    58 
    58         return $data;
    59         return $data;
    59     }
    60     }
    60 
    61 
    70         "        OPTIONAL {?doc <http://purl.org/dc/terms/modified> ?modified.} }".
    71         "        OPTIONAL {?doc <http://purl.org/dc/terms/modified> ?modified.} }".
    71         "    } ORDER BY ?uri"
    72         "    } ORDER BY ?uri"
    72         );
    73         );
    73     }
    74     }
    74 
    75 
    75     public function get($id) {
    76     public function get($id, bool $short=false) {
    76 
    77 
    77         if(strpos($id, config('corpusparole.corpus_id_scheme')) === 0) {
    78         if(strpos($id, config('corpusparole.corpus_id_scheme')) === 0) {
    78             $id = substr($id, strlen(config('corpusparole.corpus_id_scheme')));
    79             $id = substr($id, strlen(config('corpusparole.corpus_id_scheme')));
    79         }
    80         }
    80         $docUri = Config::get('corpusparole.corpus_doc_id_base_uri').$id;
    81         $docUri = Config::get('corpusparole.corpus_doc_id_base_uri').$id;
    88         if($doc->isEmpty()) {
    89         if($doc->isEmpty()) {
    89             return null;
    90             return null;
    90         }
    91         }
    91 
    92 
    92         // clone the graph to force the URI
    93         // clone the graph to force the URI
    93         return new Document($docUri, new Graph($docUri, $doc->toRdfPhp()));
    94         $DocumentKlass = $short?DocumentResult::class:Document::class;
       
    95         return new $DocumentKlass($docUri, new Graph($docUri, $doc->toRdfPhp()));
    94 
    96 
    95     }
    97     }
    96 
    98 
    97     /**
    99     /**
    98      * save document.
   100      * save document.