equal
deleted
inserted
replaced
5 use Config; |
5 use Config; |
6 use Log; |
6 use Log; |
7 use CorpusParole\Models\Document; |
7 use CorpusParole\Models\Document; |
8 use CorpusParole\Libraries\CorpusParoleException; |
8 use CorpusParole\Libraries\CorpusParoleException; |
9 use CorpusParole\Libraries\Sparql\SparqlClient; |
9 use CorpusParole\Libraries\Sparql\SparqlClient; |
|
10 use CorpusParole\Services\LexvoResolverInterface; |
10 |
11 |
11 use EasyRdf\Graph; |
12 use EasyRdf\Graph; |
12 |
13 |
13 use Illuminate\Pagination\LengthAwarePaginator; |
14 use Illuminate\Pagination\LengthAwarePaginator; |
14 use Illuminate\Pagination\Paginator; |
15 use Illuminate\Pagination\Paginator; |
18 * TODO: certainly split the transaction management (+add, +delete +transaction ) to an external class -> for this extend the sparql client. |
19 * TODO: certainly split the transaction management (+add, +delete +transaction ) to an external class -> for this extend the sparql client. |
19 */ |
20 */ |
20 class RdfDocumentRepository implements DocumentRepository { |
21 class RdfDocumentRepository implements DocumentRepository { |
21 |
22 |
22 private $sparqlClient; |
23 private $sparqlClient; |
23 |
24 private $lexvoResolver; |
24 public function __construct(SparqlClient $sparqlClient) { |
25 |
|
26 public function __construct(SparqlClient $sparqlClient, LexvoResolverInterface $lexvoResolver) { |
25 $this->sparqlClient = $sparqlClient; |
27 $this->sparqlClient = $sparqlClient; |
|
28 $this->lexvoResolver = $lexvoResolver; |
26 } |
29 } |
27 |
30 |
28 public function getSparqlClient() { |
31 public function getSparqlClient() { |
29 return $this->sparqlClient; |
32 return $this->sparqlClient; |
30 } |
33 } |
166 'path' => Paginator::resolveCurrentPath(), |
169 'path' => Paginator::resolveCurrentPath(), |
167 'pageName' => $pageName, |
170 'pageName' => $pageName, |
168 ]); |
171 ]); |
169 } |
172 } |
170 |
173 |
|
174 /** |
|
175 * Resolve lexvo id for all documents in the list |
|
176 * this allow to optimise the call of lexvo repository |
|
177 * @param $docList Array: a list (Array) of document to resolve |
|
178 */ |
|
179 public function resolveLexvo(Array $docList) { |
|
180 |
|
181 $languageIds = []; |
|
182 #get the list pf language needing resolving |
|
183 foreach ($docList as $doc) { |
|
184 if($doc->getLanguageValue() && is_null($doc->getLanguageResolved())) { |
|
185 $languageIds[$doc->getLanguageValue()] = true; |
|
186 } |
|
187 } |
|
188 |
|
189 # call LexvoResolver |
|
190 $langNames = $this->lexvoResolver->getNames(array_keys($languageIds)); |
|
191 |
|
192 foreach ($docList as $doc) { |
|
193 if($doc->getLanguageValue() && is_null($doc->getLanguageResolved())) { |
|
194 $doc->setLanguageResolved($langNames[$doc->getLanguageValue()]); |
|
195 } |
|
196 } |
|
197 |
|
198 return $docList; |
|
199 } |
|
200 |
|
201 |
171 |
202 |
172 } |
203 } |