# HG changeset patch # User Chloe Laisne # Date 1474551732 -7200 # Node ID 5d2621f71f39755314cb47c4e1cf6355dd66441d # Parent f2c2c80a49f78417afe962e99486656d03e987b4# Parent bd4bc1db4f404825cf92490d80cf354f2b848871 Merge Hg: changed server/src/app/Http/Controllers/Api/DocumentController.php diff -r f2c2c80a49f7 -r 5d2621f71f39 cms/app-client/mirage/serializers/sparse-document.js --- a/cms/app-client/mirage/serializers/sparse-document.js Thu Sep 22 15:34:10 2016 +0200 +++ b/cms/app-client/mirage/serializers/sparse-document.js Thu Sep 22 15:42:12 2016 +0200 @@ -3,7 +3,7 @@ import _ from 'lodash'; export default BaseSerializer.extend({ - attrs: ['id', 'title', 'language', 'url', 'issued', 'modified', 'publishers', 'mediaArray'], + attrs: ['id', 'title', 'language', 'url', 'issued', 'modified', 'publishers', 'mediaArray', 'transcript'], serialize(response, request) { @@ -12,9 +12,10 @@ let json = BaseSerializer.prototype.serialize.apply(this, arguments); json['documents'] = _.map(json['documents'], function(doc) { - let res = _.omit(doc, ['publishers', 'mediaArray']); + let res = _.omit(doc, ['publishers', 'mediaArray', 'transcript']); res['publisher'] = doc['publishers'].join(', '); res['duration_ms'] = doc['mediaArray']?doc['mediaArray'][_(Object.keys(doc['mediaArray'])).first()]['extent_ms']:0; + res['transcript_url'] = (doc['transcript'] && doc['transcript']['url'])?doc['transcript']['url']:null; return res; }); diff -r f2c2c80a49f7 -r 5d2621f71f39 server/bo_client/app/models/document.js --- a/server/bo_client/app/models/document.js Thu Sep 22 15:34:10 2016 +0200 +++ b/server/bo_client/app/models/document.js Thu Sep 22 15:42:12 2016 +0200 @@ -17,10 +17,12 @@ subjects: DS.attr({defaultValue: function() { return []; }}), + reflocs: DS.attr({defaultValue: function() { return []; }}), + mediaArray: DS.attr({defaultValue: function() { return []; }}), encodedId: Ember.computed('id', function() { - return encodeURIComponent(this.get('id')); + return encodeURIComponent(this.get('id')); }), mediaList: Ember.computed('mediaArray', function() { diff -r f2c2c80a49f7 -r 5d2621f71f39 server/src/.env.example --- a/server/src/.env.example Thu Sep 22 15:34:10 2016 +0200 +++ b/server/src/.env.example Thu Sep 22 15:42:12 2016 +0200 @@ -19,6 +19,8 @@ MAIL_USERNAME=null MAIL_PASSWORD=null +CORPUSPAROLE_ONTOLOGY_URL=http://corpusdelaparole.culture.fr/ontology/ + CORPUSPAROLE_COCOON_RDF_BASE_URI= CORPUSPAROLE_COCOON_OAIPMH_URL= CORPUSPAROLE_SESAME_BASE_URL=http://172.16.1.5:8080/openrdf-sesame @@ -57,5 +59,3 @@ HANDLE_TEST_DSA_KEY="" HANDLE_TEST_DSA_PASSWORD=NULL HANDLE_TEST_DSA_ADMIN_HANDLE="" - - diff -r f2c2c80a49f7 -r 5d2621f71f39 server/src/app/Http/Controllers/Api/DocumentController.php --- a/server/src/app/Http/Controllers/Api/DocumentController.php Thu Sep 22 15:34:10 2016 +0200 +++ b/server/src/app/Http/Controllers/Api/DocumentController.php Thu Sep 22 15:42:12 2016 +0200 @@ -127,6 +127,8 @@ //for now, update contributors and subjects only $doc->setContributors($document['contributors']); $doc->setSubjects($document['subjects']); + $doc->addGeoInfo()->setRefLocs($document['reflocs']); + $doc->getGeoInfo()->commit(); $doc->setModified(); diff -r f2c2c80a49f7 -r 5d2621f71f39 server/src/app/Libraries/RdfModel/RdfModelDelta.php --- a/server/src/app/Libraries/RdfModel/RdfModelDelta.php Thu Sep 22 15:34:10 2016 +0200 +++ b/server/src/app/Libraries/RdfModel/RdfModelDelta.php Thu Sep 22 15:42:12 2016 +0200 @@ -9,12 +9,15 @@ class RdfModelDelta { public function __construct($uri) { + $this->uri = $uri; $this->deletedGraph = new Graph($uri); $this->addedGraph = new Graph($uri); + $this->deleteWhere = []; } private $deletedGraph; private $addedGraph; + private $deleteWhere; public function getDeletedGraph() { return $this->deletedGraph; @@ -24,4 +27,17 @@ return $this->addedGraph; } + public function getDeleteWhere() { + return $this->deleteWhere; + } + + public function addDeleteWhere(string $value) { + array_push($this->deleteWhere, $value); + return $this; + } + + public function getUri() { + return $this->uri; + } + } diff -r f2c2c80a49f7 -r 5d2621f71f39 server/src/app/Libraries/RdfModel/RdfModelResource.php --- a/server/src/app/Libraries/RdfModel/RdfModelResource.php Thu Sep 22 15:34:10 2016 +0200 +++ b/server/src/app/Libraries/RdfModel/RdfModelResource.php Thu Sep 22 15:42:12 2016 +0200 @@ -18,16 +18,27 @@ protected $currentDelta = null; protected $uri = null; + protected function additionalDeltaLists() { + return []; + } + public function isDirty() { - return !is_null($this->deltaList) && count($this->deltaList)>0; + return $this->deltaCount()>0; } public function deltaCount() { - return is_null($this->deltaList)?0:count($this->deltaList); + $deltaList = $this->getDeltaList(); + return is_null($deltaList)?0:count($deltaList); } public function getDeltaList() { - return $this->deltaList; + $deltaList = is_null($this->deltaList)?[]:$this->deltaList; + $additionalDeltaLists = $this->additionalDeltaLists(); + if(!empty($additionalDeltaLists)) { + array_unshift($additionalDeltaLists, $deltaList); + $deltaList = call_user_func_array('array_merge', $additionalDeltaLists); + } + return $deltaList; } public function getUri() { @@ -35,7 +46,7 @@ } public function getCurrentDelta() { - return $this->getCurrentDelta; + return $this->currentDelta; } public function startDelta() { diff -r f2c2c80a49f7 -r 5d2621f71f39 server/src/app/Libraries/Sparql/SparqlClient.php --- a/server/src/app/Libraries/Sparql/SparqlClient.php Thu Sep 22 15:34:10 2016 +0200 +++ b/server/src/app/Libraries/Sparql/SparqlClient.php Thu Sep 22 15:42:12 2016 +0200 @@ -130,15 +130,19 @@ public function deleteWhere($whereClauses, string $graphUri = null) { - if(is_array($whereClause)) { - $whereClause = implode(" .", $whereClause); + if(empty($whereClauses)) { + return; } + if(is_array($whereClauses)) { + $whereClauses = implode(" .", $whereClauses); + } + + $query = "DELETE { ?s ?p ?o } WHERE { $whereClauses }"; if($graphUri) { - $whereClause = "GRAPH <$graphUri> { $whereClause }"; + $query = "WITH <$graphUri> $query"; } - $query = "DELETE WHERE { $whereClause }"; // doc : http://rdf4j.org/doc/4/articles/REST-API/transaction-operations.docbook?view // cf. bug : https://openrdf.atlassian.net/browse/SES-2295 diff -r f2c2c80a49f7 -r 5d2621f71f39 server/src/app/Models/Document.php --- a/server/src/app/Models/Document.php Thu Sep 22 15:34:10 2016 +0200 +++ b/server/src/app/Models/Document.php Thu Sep 22 15:42:12 2016 +0200 @@ -41,6 +41,13 @@ $this->geoInfo = false; } + protected function additionalDeltaLists() { + + $geoInfo = $this->getGeoInfo(); + $geoInfoDeltas = is_null($geoInfo)?[]:$geoInfo->getDeltaList(); + return empty($geoInfoDeltas)?[]:[$geoInfoDeltas,]; + } + private function parseWebResources() { @@ -208,19 +215,42 @@ } /** - * + * get the GeoInfoObject + * Ths returned object should be limited for read only activities. + * If it needs to be edited use the addGeoInfo method. */ public function getGeoInfo() { if($this->geoInfo === false) { $places = $this->getProvidedCHO()->all(''); $this->geoInfo = null; if($places) { - $this->geoInfo = new GeoResource($places[0]->getUri(), $this->graph); + $this->geoInfo = new GeoResource($places[0]->getUri(), $this->graph, $this->getProvidedCHO()); } } return $this->geoInfo; } + public function addGeoInfo() { + $geoInfo = $this->getGeoInfo(); + if(!is_null($geoInfo)) { + // if there already is a geo info, just return it. + $geoInfo->setReadOnly(false); + $geoInfo->setNeedDelete(true); + return $geoInfo; + } + + $this->geoInfo = false; + + $geoinfoNode = $this->getGraph()->newBNode("http://www.europeana.eu/schemas/edm/Place"); + $this->getProvidedCHO()->addResource("http://purl.org/dc/terms/spatial", $geoinfoNode); + + $this->geoInfo = new GeoResource($geoinfoNode->getUri(), $this->graph, $this->getProvidedCHO()); + $this->geoInfo->setReadOnly(false); + $this->geoInfo->setNeedDelete(false); + + return $this->geoInfo; + } + /** * change subjecs list */ diff -r f2c2c80a49f7 -r 5d2621f71f39 server/src/app/Models/DocumentResult.php --- a/server/src/app/Models/DocumentResult.php Thu Sep 22 15:34:10 2016 +0200 +++ b/server/src/app/Models/DocumentResult.php Thu Sep 22 15:42:12 2016 +0200 @@ -23,12 +23,14 @@ private $publishers = false; private $duration = false; private $durationMs = -1; + private $transcriptUrl = false; protected function clearMemoizationCache() { parent::clearMemoizationCache(); $this->publishers = false; $this->duration = false; - $this->$durationMs = -1; + $this->durationMs = -1; + $this->transcriptUrl = false; } @@ -66,6 +68,17 @@ return $this->durationMs; } + public function getTranscriptUrl() { + if($this->transcriptUrl === false) { + try { + $this->transcriptUrl = $this->getProvidedCHO()->getLiteral("<".config('corpusparole.corpus_ontology_url').'transcript'.">"); + } catch(\Exception $e) { + $this->transcriptUrl = null; + } + } + return is_null($this->transcriptUrl)?null:$this->transcriptUrl->getValue(); + } + public function jsonSerialize() { $res = parent::jsonSerialize(); @@ -73,7 +86,8 @@ if($this->graph) { $res = array_merge($res, [ 'publishers' => $this->getPublishersValue(), - 'duration' => $this->getDurationValue() + 'duration' => $this->getDurationValue(), + 'transcript_url' => $this->getTranscriptUrl() ]); } return $res; diff -r f2c2c80a49f7 -r 5d2621f71f39 server/src/app/Models/GeoResource.php --- a/server/src/app/Models/GeoResource.php Thu Sep 22 15:34:10 2016 +0200 +++ b/server/src/app/Models/GeoResource.php Thu Sep 22 15:42:12 2016 +0200 @@ -1,6 +1,7 @@ providedCHO = $providedCHO; + $this->readOnly = true; + $this->changePending = false; + $this->needDelete = false; } + private $providedCHO = null; + private $readOnly = true; + private $changePending = false; + private $needDelete = false; + private $refLocs = null; private $notes = null; + private $latitude = false; + private $longitude = false; + + public function getDeltaList() { + if($this->changePending) { + throw new CorpusParoleException('GetDeltaList called when changes are pending'); + } + return parent::getDeltaList(); + } public function clearMemoizationCache() { $this->refLocs = null; $this->notes = null; + $this->latitude = false; + $this->longitude = false; } public function getRefLocs() { @@ -30,6 +51,21 @@ return $this->refLocs; } + public function setRefLocs($refLocs) { + if(!$this->changePending) { + throw new CorpusParoleException('Can call setRefLocs only when changes are pending'); + } + + $this->delete(""); + + foreach($refLocs as $refLocUri) { + $this->addResource("http://www.w3.org/2002/07/owl#sameAs", $refLocUri); + } + + $this->clearMemoizationCache(); + + } + public function getNotes() { if(is_null($this->notes)) { $this->notes = $this->all(''); @@ -37,6 +73,40 @@ return $this->notes; } + public function getLatitude() { + if($this->latitude === false) { + try { + $this->latitude = $this->getLiteral(''); + } catch(\Exception $e) { + $this->latitude = null; + } + } + return $this->latitude; + } + + public function getLatitudeValue() { + $lat = $this->getLatitude(); + return is_null($lat)?null:$lat->getValue(); + } + + public function getLongitude() { + if($this->longitude === false) { + try { + $this->longitude = $this->getLiteral(''); + } catch(\Exception $e) { + $this->longitude = null; + } + } + return $this->longitude; + } + + public function getLongitudeValue() { + $long = $this->getLongitude(); + return is_null($long)?null:$long->getValue(); + } + + + public function jsonSerialize() { $notes = array_map( function($note) { return Utils::processLiteralResourceOrString($note); }, @@ -44,8 +114,65 @@ ); return [ 'ref-locs' => $this->getRefLocs(), - 'notes' => $notes + 'notes' => $notes, + 'latitude' => $this->getLatitudeValue(), + 'longitude' => $this->getLongitudeValue(), ]; } + public function setReadOnly($ro) { + if($this->readOnly and !$ro) { + $this->changePending = true; + } + $this->readOnly = $ro; + } + + public function setNeedDelete($nd) { + $this->needDelete = $nd; + } + + public function rollback() { + $this->changePending = false; + } + + public function commit() { + + // Do nothing if there is no change pending + if(!$this->changePending) { + return; + } + + $delta = $this->startDelta(); + + //delete the previous blank node + if($this->needDelete) { + $delta->addDeleteWhere( + "?s ?p ?o. ". + "{ ". + " ?_ ?s. ". + "} ". + "UNION { ". + " ?s ?o ". + "}" + ); + } + + // add the node + $geoinfoNodeAdded = $delta->getAddedGraph()->newBNode("http://www.europeana.eu/schemas/edm/Place"); + $delta->getAddedGraph()->add($this->providedCHO, "http://purl.org/dc/terms/spatial", $geoinfoNodeAdded); + + foreach($this->propertyUris() as $prop) { + if($prop == "http://www.w3.org/1999/02/22-rdf-syntax-ns#type") { + continue; + } + foreach($this->all("<$prop>") as $propVal) { + $delta->getAddedGraph()->add($geoinfoNodeAdded, $prop, $propVal); + } + } + + $this->changePending = false; + + } + + } \ No newline at end of file diff -r f2c2c80a49f7 -r 5d2621f71f39 server/src/app/Repositories/RdfDocumentRepository.php --- a/server/src/app/Repositories/RdfDocumentRepository.php Thu Sep 22 15:34:10 2016 +0200 +++ b/server/src/app/Repositories/RdfDocumentRepository.php Thu Sep 22 15:42:12 2016 +0200 @@ -24,8 +24,8 @@ */ class RdfDocumentRepository implements DocumentRepository { - const ALL_QUERIES = [ - "SELECT". + const BASE_DOC_QUERY + = "SELECT". " ?uri". " ?doc". " ?title". @@ -33,17 +33,18 @@ " ?modified". " ?lang". " (group_concat(distinct ?publisher;separator=\", \") as ?publishers) ". - "WHERE {". - "GRAPH ?uri { ?doc a .". + " WHERE {". + " GRAPH ?uri { ?doc a .". " ?doc ?title.". " OPTIONAL {?doc ?lang.} ". " OPTIONAL {?doc ?issued.} ". " OPTIONAL {?doc ?modified.} ". " OPTIONAL {?doc ?publisher.} }". - "} ". - "GROUP BY ?uri ?doc ?title ?issued ?modified ?lang ". - "ORDER BY ?uri", + " } ". + " GROUP BY ?uri ?doc ?title ?issued ?modified ?lang ". + " ORDER BY ?uri"; + const ADDITIONAL_DOC_QUERIES = [ "SELECT". " ?uri". " ?doc". @@ -54,10 +55,25 @@ " ?uri ?s. ". " ?uri ?doc. ". " OPTIONAL {?s ?ext.}". - " }". + " }. ". + " %s". "} ". - "GROUP BY ?uri ?doc ". - "ORDER BY ?uri" + "GROUP BY ?uri ?doc", + + "SELECT". + " ?uri". + " ?doc". + " (sample(distinct str(?s)) as ?transcript_url) ". + "WHERE {". + " GRAPH ?uri {". + " ?s a . ". + " ?uri ?doc. ". + " OPTIONAL {?s ?f.} ". + " }. ". + " FILTER(str(?f) IN ( \"application/xml\", \"application/pdf\" )). ". + " %s". + "} ". + "GROUP BY ?uri ?doc" ]; private $sparqlClient; @@ -73,6 +89,11 @@ } private function getResGraph($doc) { + + if(empty((array)$doc)) { + return null; + } + $newGraph = new Graph($doc->uri->getUri()); $newGraph->add($doc->uri, "rdf:type", $newGraph->resource("http://www.openarchives.org/ore/terms/Aggregation")); $newGraph->add($doc->uri, "http://www.europeana.eu/schemas/edm/aggregatedCHO", $doc->doc); @@ -95,17 +116,51 @@ if(isset($doc->extent)) { $newGraph->add($doc->doc, "http://purl.org/dc/terms/extent", $doc->extent); } + if(isset($doc->transcript_url)) { + $newGraph->add($doc->doc, config('corpusparole.corpus_ontology_url').'transcript', $doc->transcript_url); + } return $newGraph; } - private function queryDocs($queries) { + private function queryDocs($offset=null, $limit=null) { $resDocs = []; + $limitsClauses = []; + $limitsClausesStr = ""; - foreach($queries as $query) { - $docs = $this->sparqlClient->query($query); + if(!is_null($offset)) { + array_push($limitsClauses, "OFFSET $offset"); + } + if(!is_null($limit)) { + array_push($limitsClauses, "LIMIT $limit"); + } + if(!empty($limitsClauses)) { + $limitsClausesStr = "\n" . join(" ", $limitsClauses); + } + + $docs = $this->sparqlClient->query(self::BASE_DOC_QUERY.$limitsClausesStr); + foreach($docs as $doc) { + $graph = $this->getResGraph($doc); + if(is_null($graph)) { + continue; + } + $uri = $doc->uri->getUri(); + $resDocs[$uri] = $graph; + } + + if(count($resDocs) == 0) { + return []; + } + + $filterUris = "FILTER(?uri in (<".join(">, <" , array_keys($resDocs)).">)) "; + + foreach(self::ADDITIONAL_DOC_QUERIES as $query) { + $docs = $this->sparqlClient->query(sprintf($query, $filterUris)); foreach($docs as $doc) { $graph = $this->getResGraph($doc); + if(is_null($graph)) { + continue; + } $uri = $doc->uri->getUri(); if(array_key_exists($uri, $resDocs)) { @@ -113,7 +168,6 @@ } else { $resDocs[$uri] = $graph; } - } } @@ -121,7 +175,7 @@ } public function all() { - return $this->queryDocs(self::ALL_QUERIES); + return $this->queryDocs(); } public function get($id, bool $short=false) { @@ -159,6 +213,7 @@ try { foreach($doc->getDeltaList() as $delta) { + $this->sparqlClient->deleteWhere($delta->getDeleteWhere(), $delta->getUri()); $this->sparqlClient->delete($delta->getDeletedGraph()); $this->sparqlClient->add($delta->getAddedGraph()); } @@ -207,7 +262,7 @@ $offset = max(0,($page - 1) * $perPage); - $results = $this->queryDocs(array_map(function($q) use ($offset, $perPage) { return $q . "\nOFFSET $offset LIMIT $perPage"; }, self::ALL_QUERIES)); + $results = $this->queryDocs($offset, $perPage); return new LengthAwarePaginator($results, $total, $perPage, $page, [ 'path' => Paginator::resolveCurrentPath(), diff -r f2c2c80a49f7 -r 5d2621f71f39 server/src/config/corpusparole.php --- a/server/src/config/corpusparole.php Thu Sep 22 15:34:10 2016 +0200 +++ b/server/src/config/corpusparole.php Thu Sep 22 15:42:12 2016 +0200 @@ -13,7 +13,7 @@ 'sesame_update_url' => $sesameBaseUrl.'repositories/'.env('CORPUSPAROLE_SESAME_REPOSITORY').'/statements', 'sesame_query_url_raw' => $sesameBaseUrl.'repositories/'.env('CORPUSPAROLE_SESAME_REPOSITORY_RAW'), 'sesame_update_url_raw' => $sesameBaseUrl.'repositories/'.env('CORPUSPAROLE_SESAME_REPOSITORY_RAW').'/statements', - + 'corpus_ontology_url' => env('CORPUSPAROLE_ONTOLOGY_URL', 'http://corpusdelaparole.culture.fr/ontology/'), 'cocoon_rdf_base_uri' => env('CORPUSPAROLE_COCOON_RDF_BASE_URI'), 'cocoon_oaipmh_url' => env('CORPUSPAROLE_COCOON_OAIPMH_URL'), diff -r f2c2c80a49f7 -r 5d2621f71f39 server/src/tests/Models/DocumentTest.php --- a/server/src/tests/Models/DocumentTest.php Thu Sep 22 15:34:10 2016 +0200 +++ b/server/src/tests/Models/DocumentTest.php Thu Sep 22 15:42:12 2016 +0200 @@ -3,122 +3,53 @@ use CorpusParole\Models\Document; use CorpusParole\Libraries\CocoonUtils; +use EasyRdf\RdfNamespace; + /** * */ class DocumentTest extends TestCase { - const TEST_DOC = << . - @prefix rdfs: . - @prefix sesame: . - @prefix owl: . - @prefix xsd: . - @prefix fn: . - - <%1\$scrdo-CFPP2000_35_SOUND> a ; - ; - "Langage et langues : description, théorisation, transmission" ; - , , ; - ; - ; - "Corpus de la Parole"@fr ; - . + const TEST_INPUT_DOCS = [ + 'TEST' => __DIR__.'/files/DocumentTest/test_doc.ttl', + 'TEST_NO_GEOINFO' => __DIR__.'/files/DocumentTest/test_no_geoinfo.ttl', + ]; - a ; - "Freely available for non-commercial use" ; - "2010-11-17"^^ ; - "PT48M26S" ; - "2013-10-12T14:35:57+02:00"^^ ; - ; - , "Tanguy, Noalig" , "Chevrier, Michel" , "Kiliç, Ozgur" , "Salvegas, Etienne" , "du-Breuil-de-Pont-en-Auge, Augustin" , "du-Breuil-de-Pont-en-Auge, Benoît" ; - "Enregistrement issu du Corpus de Français Parlé Parisien des années 2000 (CFPP2000)"@fr , "Quartier(s) concerné(s) : Paris 3e, et 20e (pour l'âge adulte); Anonymisation : Noalig TANGUY;"@fr ; - "ark:/87895/1.17-375004" , "%2\$scrdo-CFPP2000_35_SOUNDid" , "oai:crdo.vjf.cnrs.fr:crdo-CFPP2000_35" , "Cote producteur: [03-01] Ozgur_Kilic_H_32_alii_3e"@fr , "ark:/87895/1.17-372593" , "oai:crdo.vjf.cnrs.fr:crdo-CFPP2000_35_SOUND" ; - ; - ; - , "anthropological_linguistics"^^ , "lexicography"^^ , "phonetics"^^ , , , , "general_linguistics"^^ , , "text_and_corpus_linguistics"^^ , "Français"@fr , , "phonology"^^ , "semantics"^^ , "sociolinguistics"^^ , "syntax"^^ , "typology"^^ , , , "discourse_analysis"^^ , "historical_linguistics"^^ , "language_documentation"^^ , , , , , , "mathematical_linguistics"^^ ; - "Entretien de Ozgur Kiliç 2"@fr ; - , , , "primary_text"^^ , , "narrative"^^ , "report"^^ , "unintelligible_speech"^^ ; - "2013-10-12"^^ ; - [ - a ; - owl:sameAs ; - "FR"^^ , "France, Île-de-France, Paris, Université Sorbonne Nouvelle Paris 3, site Censier"@fr , "Domicile de Ozgur Kiliç"@fr , "France, Île-de-France, Paris 20"@fr - ]; - , ; - ; - ; - "Tanguy, Noalig" ; - "Quartier concerné : 3e"@fr ; - "Chevrier, Michel" , "Kiliç, Ozgur" , "Salvegas, Etienne" , "du-Breuil-de-Pont-en-Auge, Augustin" , "du-Breuil-de-Pont-en-Auge, Benoît" ; - . - - - a ; - "application/xml"^^ ; - "Freely available for non-commercial use" ; - "2010-11-17"^^ ; - "2013-11-04T22:20:07+01:00"^^ ; - ; - . - - a ; - "audio/x-wav"^^ ; - "Freely available for non-commercial use" ; - "2010-11-17"^^ ; - "PT48M26S" ; - "2013-10-12T14:35:57+02:00"^^ ; - . - - a ; - "audio/mpeg"^^ ; - "Freely available for non-commercial use" ; - "2010-11-17"^^ ; - "PT48M26S" ; - "2013-10-12T14:35:57+02:00"^^ ; - ; - . - - a ; - "audio/x-wav"^^ ; - "Freely available for non-commercial use" ; - "2010-11-17"^^ ; - "PT48M26S" ; - "2013-10-12T14:35:57+02:00"^^ ; - ; - . -EOT; - + private $inputGraphes = []; public function setUp() { + parent::setup(); - parent::setup(); - $this->graph = new EasyRdf\Graph(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", sprintf(DocumentTest::TEST_DOC, config('corpusparole.corpus_doc_id_base_uri'), config('corpusparole.corpus_id_scheme'))); + foreach(self::TEST_INPUT_DOCS as $key => $inputDoc) { + $this->inputGraphes[$key] = new EasyRdf\Graph(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", sprintf(file_get_contents($inputDoc), config('corpusparole.corpus_doc_id_base_uri'), config('corpusparole.corpus_id_scheme'))); + } + } public function testConstructor() { - $this->assertNotNull($this->graph, 'Graph shoud not be null'); + $this->assertNotNull($this->inputGraphes['TEST'], 'Graph shoud not be null'); - $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph); + $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']); $this->assertEquals(config('corpusparole.corpus_id_scheme').'crdo-CFPP2000_35_SOUNDid',$doc->getId(),'Must have the correct id'); } public function testTitle() { - $this->assertNotNull($this->graph, 'Graph shoud not be null'); + $this->assertNotNull($this->inputGraphes['TEST'], 'Graph shoud not be null'); - $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph); + $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']); $this->assertEquals("Entretien de Ozgur Kiliç 2",$doc->getTitle(),'Must have correct title'); $this->assertInstanceOf(EasyRdf\Literal::class, $doc->getTitle(), "Title must be a literal"); $this->assertEquals('fr', $doc->getTitle()->getLang(), "Language title must be fr"); } + public function testModified() { - $this->assertNotNull($this->graph, 'Graph shoud not be null'); + $this->assertNotNull($this->inputGraphes['TEST'], 'Graph shoud not be null'); - $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph); + $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']); $this->assertInstanceOf(EasyRdf\Literal::class, $doc->getModified(), "Modified must be a literal"); $this->assertEquals("http://purl.org/dc/terms/W3CDTF", $doc->getModified()->getDatatypeURI(), "type must be http://purl.org/dc/terms/W3CDTF"); $this->assertEquals("2013-10-12T14:35:57+02:00", $doc->getModified(), "modified must be 2013-10-12T14:35:57+02:00"); @@ -127,7 +58,7 @@ public function testSetModified() { $currentTime = gmdate(DateTime::ATOM); - $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph); + $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']); $doc->setModified($currentTime); $this->assertInstanceOf(EasyRdf\Literal::class, $doc->getModified(), "Modified must be a literal"); $this->assertEquals("http://purl.org/dc/terms/W3CDTF", $doc->getModified()->getDatatypeURI(), "type must be http://purl.org/dc/terms/W3CDTF"); @@ -135,7 +66,7 @@ } public function testSetModifiedNull() { - $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph); + $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']); $doc->setModified(); $this->assertInstanceOf(EasyRdf\Literal::class, $doc->getModified(), "Modified must be a literal"); $this->assertEquals("http://purl.org/dc/terms/W3CDTF", $doc->getModified()->getDatatypeURI(), "type must be http://purl.org/dc/terms/W3CDTF"); @@ -146,7 +77,7 @@ public function testPublisher() { - $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph); + $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']); $this->assertCount(1, $doc->getPublishers(), 'Publisher is an array of size 1'); $this->assertInstanceOf('EasyRdf\Resource', $doc->getPublishers()[0], 'publisher is a resource'); @@ -154,7 +85,7 @@ } public function testMediaArray() { - $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph); + $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']); $this->assertCount(3, $doc->getMediaArray(), "Media array must be of size 3"); //print_r($doc->getMediaArray()); @@ -191,7 +122,7 @@ } public function testGetTypes() { - $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph); + $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']); $this->assertCount(8, $doc->getTypes(), "types array must be of size 5"); @@ -207,7 +138,7 @@ } public function testGetOtherTypes() { - $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph); + $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']); $this->assertCount(5, $doc->getOtherTypes(), "types array must be of size 5"); @@ -223,7 +154,7 @@ } public function testGetDiscourseTypes() { - $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph); + $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']); $this->assertCount(3, $doc->getDiscourseTypes(), "types array must be of size 3"); @@ -234,7 +165,7 @@ } public function testCloneDocument() { - $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph); + $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']); $doc2 = clone $doc; @@ -245,8 +176,8 @@ } public function testIsIsomorphic() { - $doc1 = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph); - $doc2 = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", new EasyRdf\Graph(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", sprintf(DocumentTest::TEST_DOC, config('corpusparole.corpus_doc_id_base_uri'), config('corpusparole.corpus_id_scheme')))); + $doc1 = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']); + $doc2 = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", new EasyRdf\Graph(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", sprintf(file_get_contents(DocumentTest::TEST_INPUT_DOCS['TEST']) , config('corpusparole.corpus_doc_id_base_uri'), config('corpusparole.corpus_id_scheme')))); $this->assertTrue($doc1->isIsomorphic($doc2),"document must be isomorphic"); @@ -259,7 +190,7 @@ $newDiscourseTypes = ['oratory','dialogue','narrative', 'formulaic', 'ludic']; - $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph); + $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']); $this->assertCount(3, $doc->getDiscourseTypes(), "types array must be of size 3"); $doc->updateDiscourseTypes($newDiscourseTypes); @@ -277,7 +208,7 @@ $newDiscourseTypes = ['oratory','dialogue','narrative', 'formulaic', 'ludic']; - $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph); + $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']); $doc->updateDiscourseTypes($newDiscourseTypes); @@ -305,7 +236,7 @@ } public function testUpdateTitle() { - $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph); + $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']); $oldTitle = $doc->getTitle(); @@ -333,16 +264,16 @@ $newDiscourseTypes = ['oratory','dialogue','narrative']; - $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph); + $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']); $doc->updateDiscourseTypes($newDiscourseTypes); - $doc2 = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", new EasyRdf\Graph(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", sprintf(DocumentTest::TEST_DOC, config('corpusparole.corpus_doc_id_base_uri'), config('corpusparole.corpus_id_scheme')))); + $doc2 = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", new EasyRdf\Graph(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", sprintf(file_get_contents(DocumentTest::TEST_INPUT_DOCS['TEST']), config('corpusparole.corpus_doc_id_base_uri'), config('corpusparole.corpus_id_scheme')))); $this->assertFalse($doc->isIsomorphic($doc2),"document must not be isomorphic after adding discourse type"); } public function testGetContributors() { - $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph); + $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']); $contributors = $doc->getContributors(); @@ -358,7 +289,7 @@ } public function testSetContributors() { - $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph); + $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']); $contributors = $doc->getContributors(); @@ -435,7 +366,7 @@ } public function testGetSubjects() { - $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph); + $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']); $subjects = $doc->getSubjects(); @@ -453,7 +384,7 @@ } public function testSetSubjects() { - $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph); + $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']); $newSubjects = [ "http://ark.bnf.fr/ark:/12148/cb13318415c", @@ -491,7 +422,7 @@ //TODO: test null transcript + null media array public function testJsonSerialize() { - $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->graph); + $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']); $json = $doc->jsonSerialize(); @@ -506,5 +437,68 @@ } + public function testAddGeoInfo() { + + $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST_NO_GEOINFO']); + //$doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']); + + $res = $doc->addGeoInfo(); + $res->commit(); + + $this->assertNotNull($res, "A new georesource object must have been created"); + + $this->assertInstanceOf('CorpusParole\Models\GeoResource', $res, "the object created must be a geo resource"); + + $allSpatials = $doc->getProvidedCHO()->allResources(""); + + $this->assertCount(1, $allSpatials, "Must have only one spatial node"); + + $spatial = $allSpatials[0]; + + $this->assertTrue($spatial->isBNode(), "Spatial node must be a blank node"); + $this->assertEquals($spatial->typeAsResource(), "http://www.europeana.eu/schemas/edm/Place", "type must be a http://www.europeana.eu/schemas/edm/Place"); + + $this->assertTrue($doc->isDirty(), "Document must be dirty"); + $this->assertEquals(1, $doc->deltaCount(), "Must have only one delta."); + + $this->assertNotNull($res->getCurrentDelta(), "CurrentDelta is not null"); + $this->assertTrue($res->getCurrentDelta()->getDeletedGraph()->isEmpty(), "deleted graph must be empty"); + $this->assertEmpty($res->getCurrentDelta()->getDeleteWhere(), "Delete where must be empty"); + $this->assertNotNull($res->getCurrentDelta()->getAddedGraph(), "Added graph is not null"); + $this->assertEquals(2, $res->getCurrentDelta()->getAddedGraph()->countTriples(), "Added graph must have 2 triples"); + + } + + + public function testAddGeoInfoNotEmpty() { + + $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']); + + $res = $doc->addGeoInfo(); + $res->commit(); + + $this->assertNotNull($res, "A new georesource object must have been created"); + + $this->assertInstanceOf('CorpusParole\Models\GeoResource', $res, "the object created must be a geo resource"); + + $allSpatials = $doc->getProvidedCHO()->allResources(""); + + $this->assertCount(1, $allSpatials, "Must have only one spatial node"); + + $spatial = $allSpatials[0]; + + $this->assertTrue($spatial->isBNode(), "Spatial node must be a blank node"); + $this->assertEquals($spatial->typeAsResource(), "http://www.europeana.eu/schemas/edm/Place", "type must be a http://www.europeana.eu/schemas/edm/Place"); + + $this->assertTrue($doc->isDirty(), "Document must not be dirty"); + $this->assertEquals(1, $doc->deltaCount(), "Must have only one delta."); + + $this->assertNotNull($res->getCurrentDelta(), "CurrentDelta is not null"); + $this->assertTrue($res->getCurrentDelta()->getDeletedGraph()->isEmpty(), "deleted graph must be empty"); + $this->assertCount(1, $res->getCurrentDelta()->getDeleteWhere(), "Delete where must have one element"); + $this->assertNotNull($res->getCurrentDelta()->getAddedGraph(), "Added graph is not null"); + $this->assertEquals(9, $res->getCurrentDelta()->getAddedGraph()->countTriples(), "Added graph must have 7 triples"); + } + } diff -r f2c2c80a49f7 -r 5d2621f71f39 server/src/tests/Models/GeoResourceTest.php --- a/server/src/tests/Models/GeoResourceTest.php Thu Sep 22 15:34:10 2016 +0200 +++ b/server/src/tests/Models/GeoResourceTest.php Thu Sep 22 15:42:12 2016 +0200 @@ -1,6 +1,7 @@ << . - @prefix rdfs: . - @prefix sesame: . - @prefix owl: . - @prefix xsd: . - @prefix fn: . - - <%1\$scrdo-CFPP2000_35_SOUND> a ; - ; - "Langage et langues : description, théorisation, transmission" ; - , , ; - ; - ; - "Corpus de la Parole"@fr ; - . - - a ; - "Freely available for non-commercial use" ; - "2010-11-17"^^ ; - "PT48M26S" ; - "2013-10-12T14:35:57+02:00"^^ ; - ; - , "Tanguy, Noalig" , "Chevrier, Michel" , "Kiliç, Ozgur" , "Salvegas, Etienne" , "du-Breuil-de-Pont-en-Auge, Augustin" , "du-Breuil-de-Pont-en-Auge, Benoît" ; - "Enregistrement issu du Corpus de Français Parlé Parisien des années 2000 (CFPP2000)"@fr , "Quartier(s) concerné(s) : Paris 3e, et 20e (pour l'âge adulte); Anonymisation : Noalig TANGUY;"@fr ; - "ark:/87895/1.17-375004" , "%2\$scrdo-CFPP2000_35_SOUNDid" , "oai:crdo.vjf.cnrs.fr:crdo-CFPP2000_35" , "Cote producteur: [03-01] Ozgur_Kilic_H_32_alii_3e"@fr , "ark:/87895/1.17-372593" , "oai:crdo.vjf.cnrs.fr:crdo-CFPP2000_35_SOUND" ; - ; - ; - , "anthropological_linguistics"^^ , "lexicography"^^ , "phonetics"^^ , , , , "general_linguistics"^^ , , "text_and_corpus_linguistics"^^ , "Français"@fr , , "phonology"^^ , "semantics"^^ , "sociolinguistics"^^ , "syntax"^^ , "typology"^^ , , , "discourse_analysis"^^ , "historical_linguistics"^^ , "language_documentation"^^ , , , , , , "mathematical_linguistics"^^ ; - "Entretien de Ozgur Kiliç 2"@fr ; - , , , "primary_text"^^ , , "narrative"^^ , "report"^^ , "unintelligible_speech"^^ ; - "2013-10-12"^^ ; - [ - a ; - owl:sameAs ; - "FR"^^ , "France, Île-de-France, Paris, Université Sorbonne Nouvelle Paris 3, site Censier"@fr , "Domicile de Ozgur Kiliç"@fr , "France, Île-de-France, Paris 20"@fr - ]; - , ; - ; - ; - "Tanguy, Noalig" ; - "Quartier concerné : 3e"@fr ; - "Chevrier, Michel" , "Kiliç, Ozgur" , "Salvegas, Etienne" , "du-Breuil-de-Pont-en-Auge, Augustin" , "du-Breuil-de-Pont-en-Auge, Benoît" ; - . - - - a ; - "application/xml"^^ ; - "Freely available for non-commercial use" ; - "2010-11-17"^^ ; - "2013-11-04T22:20:07+01:00"^^ ; - ; - . - - a ; - "audio/x-wav"^^ ; - "Freely available for non-commercial use" ; - "2010-11-17"^^ ; - "PT48M26S" ; - "2013-10-12T14:35:57+02:00"^^ ; - . - - a ; - "audio/mpeg"^^ ; - "Freely available for non-commercial use" ; - "2010-11-17"^^ ; - "PT48M26S" ; - "2013-10-12T14:35:57+02:00"^^ ; - ; - . - - a ; - "audio/x-wav"^^ ; - "Freely available for non-commercial use" ; - "2010-11-17"^^ ; - "PT48M26S" ; - "2013-10-12T14:35:57+02:00"^^ ; - ; - . -EOT - , - "LOC2" => << . - @prefix rdfs: . - @prefix sesame: . - @prefix owl: . - @prefix xsd: . - @prefix fn: . - - a ; - "Freely available for non-commercial use" ; - "2010-11-17"^^ ; - "PT48M26S" ; - "2013-10-12T14:35:57+02:00"^^ ; - ; - "Enregistrement issu du Corpus de Français Parlé Parisien des années 2000 (CFPP2000)"@fr , "Quartier(s) concerné(s) : Paris 3e, et 20e (pour l'âge adulte); Anonymisation : Noalig TANGUY;"@fr ; - "ark:/87895/1.17-375004" , "%2\$scrdo-CFPP2000_35_SOUNDid" , "oai:crdo.vjf.cnrs.fr:crdo-CFPP2000_35" , "Cote producteur: [03-01] Ozgur_Kilic_H_32_alii_3e"@fr , "ark:/87895/1.17-372593" , "oai:crdo.vjf.cnrs.fr:crdo-CFPP2000_35_SOUND" ; - ; - ; - "Entretien de Ozgur Kiliç 2"@fr ; - "2013-10-12"^^ ; - [ - a ; - "FR"^^ , "France, Île-de-France, Paris, Université Sorbonne Nouvelle Paris 3, site Censier"@fr , "Domicile de Ozgur Kiliç"@fr , "France, Île-de-France, Paris 20"@fr - ] . -EOT - , - "LOC3" => << . - @prefix rdfs: . - @prefix sesame: . - @prefix owl: . - @prefix xsd: . - @prefix fn: . - - a ; - "Freely available for non-commercial use" ; - "2010-11-17"^^ ; - "PT48M26S" ; - "2013-10-12T14:35:57+02:00"^^ ; - ; - "Enregistrement issu du Corpus de Français Parlé Parisien des années 2000 (CFPP2000)"@fr , "Quartier(s) concerné(s) : Paris 3e, et 20e (pour l'âge adulte); Anonymisation : Noalig TANGUY;"@fr ; - "ark:/87895/1.17-375004" , "%2\$scrdo-CFPP2000_35_SOUNDid" , "oai:crdo.vjf.cnrs.fr:crdo-CFPP2000_35" , "Cote producteur: [03-01] Ozgur_Kilic_H_32_alii_3e"@fr , "ark:/87895/1.17-372593" , "oai:crdo.vjf.cnrs.fr:crdo-CFPP2000_35_SOUND" ; - ; - ; - "Entretien de Ozgur Kiliç 2"@fr ; - "2013-10-12"^^ ; - [ - a ; - owl:sameAs ; - owl:sameAs ; - "FR"^^ , "France, Île-de-France, Paris, Université Sorbonne Nouvelle Paris 3, site Censier"@fr , "Domicile de Ozgur Kiliç"@fr , "France, Île-de-France, Paris 20"@fr - ] . -EOT + "LOC1" => __DIR__.'/files/GeoResourceTest/loc1.ttl', + "LOC2" => __DIR__.'/files/GeoResourceTest/loc2.ttl', + "LOC3" => __DIR__.'/files/GeoResourceTest/loc3.ttl', ]; public function setUp() { @@ -152,18 +22,27 @@ $this->graphUrl = sprintf("%1\$scrdo-CFPP2000_35_SOUND", config('corpusparole.corpus_doc_id_base_uri')); foreach(self::TEST_DOCS as $k => $ttl) { - $this->graphs[$k] = new EasyRdf\Graph($this->graphUrl, sprintf($ttl, config('corpusparole.corpus_doc_id_base_uri'), config('corpusparole.corpus_id_scheme'))); + $this->graphs[$k] = new EasyRdf\Graph($this->graphUrl, sprintf(file_get_contents($ttl), config('corpusparole.corpus_doc_id_base_uri'), config('corpusparole.corpus_id_scheme'))); } } public function getGeoResource($key) { $graph = $this->graphs[$key]; + $providedCHO = $graph->get("<".config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND>", ""); $places = $graph->allOfType(""); assert(count($places)>0); $place = $places[0]; - return new GeoResource($place->getUri(), $graph); + return new GeoResource($place->getUri(), $graph, $providedCHO); + + } + + public function getGeoResourceEdit($key) { + $graph = $this->graphs[$key]; + $doc = new Document($this->graphUrl, $graph); + + return $doc->addGeoInfo(); } @@ -218,13 +97,32 @@ } + public function testLatitude() { + + $geoInfo = $this->getGeoResource("LOC1"); + + $this->assertEquals(48.73194, $geoInfo->getLatitude()->getValue(),'Must have correct latitude'); + $this->assertInstanceOf(EasyRdf\Literal::class, $geoInfo->getLatitude(), "Latitude must be a literal"); + $this->assertEquals('http://www.w3.org/2001/XMLSchema#float', $geoInfo->getLatitude()->getDatatypeUri(), "Datatype title must be 'http://www.w3.org/2001/XMLSchema#float'"); + } + + public function testLongitude() { + + $geoInfo = $this->getGeoResource("LOC1"); + + $this->assertEquals(7.70833, $geoInfo->getLongitude()->getValue(),'Must have correct longitude'); + $this->assertInstanceOf(EasyRdf\Literal::class, $geoInfo->getLongitude(), "Longitude must be a literal"); + $this->assertEquals('http://www.w3.org/2001/XMLSchema#float', $geoInfo->getLongitude()->getDatatypeUri(), "Datatype title must be 'http://www.w3.org/2001/XMLSchema#float'"); + } + + public function testJsonSerialize() { $geoResource = $this->getGeoResource("LOC1"); $json = $geoResource->jsonSerialize(); - $this->assertEquals(["ref-locs", "notes"], array_keys($json)); + $this->assertEquals(["ref-locs", "notes", "latitude", "longitude"], array_keys($json)); $this->assertEquals(["http://sws.geonames.org/6618626/"], $json['ref-locs']); $notes = $json['notes']; @@ -248,10 +146,50 @@ $json = $geoResource->jsonSerialize(); - $this->assertEquals(["ref-locs", "notes"], array_keys($json)); + $this->assertEquals(["ref-locs", "notes", "latitude", "longitude"], array_keys($json)); $this->assertEquals(["http://sws.geonames.org/6618626/", "http://fr.dbpedia.org/resource/Gramazie"], $json['ref-locs']); } + public function testSetRefLocs() { + + $geoResource = $this->getGeoResourceEdit("LOC1"); + + + + $oldRefLocs = $geoResource->getRefLocs(); + sort($oldRefLocs); + + $newRefLocs = [ 'http://sws.geonames.org/2643743/' ]; + + $geoResource->setRefLocs($newRefLocs); + + $refLoc = $geoResource->getRefLocs(); + + $this->assertEquals(['http://sws.geonames.org/2643743/'], $refLoc); + + $geoResource->commit(); + + $deltaList = $geoResource->getDeltaList(); + + $this->assertNotNull($deltaList); + $this->assertCount(1, $deltaList, "Must have one delta"); + + + $delta = $deltaList[0]; + + $this->assertTrue($delta->getDeletedGraph()->isEmpty(), "deleted graph must be empty"); + $this->assertCount(1, $delta->getDeleteWhere(), "Delete where must have one element"); + $this->assertNotNull($delta->getAddedGraph(), "Added graph is not null"); + $this->assertEquals(9, $delta->getAddedGraph()->countTriples(), "Added graph must have 7 triples"); + $places = $delta->getAddedGraph()->allOfType("http://www.europeana.eu/schemas/edm/Place"); + $this->assertCount(1, $places); + $place = $places[0]; + $sames = $places[0]->all(''); + $this->assertCount(1, $sames); + $this->assertEquals('http://sws.geonames.org/2643743/', $sames[0]->getUri()); + + } + } diff -r f2c2c80a49f7 -r 5d2621f71f39 server/src/tests/Models/files/DocumentTest/test_doc.ttl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/src/tests/Models/files/DocumentTest/test_doc.ttl Thu Sep 22 15:42:12 2016 +0200 @@ -0,0 +1,80 @@ +@prefix rdf: . +@prefix rdfs: . +@prefix sesame: . +@prefix owl: . +@prefix xsd: . +@prefix fn: . + +<%1$scrdo-CFPP2000_35_SOUND> a ; + ; + "Langage et langues : description, théorisation, transmission" ; + , , ; + ; + ; + "Corpus de la Parole"@fr ; + . + + a ; + "Freely available for non-commercial use" ; + "2010-11-17"^^ ; + "PT48M26S" ; + "2013-10-12T14:35:57+02:00"^^ ; + ; + , "Tanguy, Noalig" , "Chevrier, Michel" , "Kiliç, Ozgur" , "Salvegas, Etienne" , "du-Breuil-de-Pont-en-Auge, Augustin" , "du-Breuil-de-Pont-en-Auge, Benoît" ; + "Enregistrement issu du Corpus de Français Parlé Parisien des années 2000 (CFPP2000)"@fr , "Quartier(s) concerné(s) : Paris 3e, et 20e (pour l'âge adulte); Anonymisation : Noalig TANGUY;"@fr ; + "ark:/87895/1.17-375004" , "%2$scrdo-CFPP2000_35_SOUNDid" , "oai:crdo.vjf.cnrs.fr:crdo-CFPP2000_35" , "Cote producteur: [03-01] Ozgur_Kilic_H_32_alii_3e"@fr , "ark:/87895/1.17-372593" , "oai:crdo.vjf.cnrs.fr:crdo-CFPP2000_35_SOUND" ; + ; + ; + , "anthropological_linguistics"^^ , "lexicography"^^ , "phonetics"^^ , , , , "general_linguistics"^^ , , "text_and_corpus_linguistics"^^ , "Français"@fr , , "phonology"^^ , "semantics"^^ , "sociolinguistics"^^ , "syntax"^^ , "typology"^^ , , , "discourse_analysis"^^ , "historical_linguistics"^^ , "language_documentation"^^ , , , , , , "mathematical_linguistics"^^ ; + "Entretien de Ozgur Kiliç 2"@fr ; + , , , "primary_text"^^ , , "narrative"^^ , "report"^^ , "unintelligible_speech"^^ ; + "2013-10-12"^^ ; + [ + a ; + owl:sameAs ; + "48.73194"^^xsd:float; + "7.70833"^^xsd:float; + "FR"^^ , "France, Île-de-France, Paris, Université Sorbonne Nouvelle Paris 3, site Censier"@fr , "Domicile de Ozgur Kiliç"@fr , "France, Île-de-France, Paris 20"@fr + ]; + , ; + ; + ; + "Tanguy, Noalig" ; + "Quartier concerné : 3e"@fr ; + "Chevrier, Michel" , "Kiliç, Ozgur" , "Salvegas, Etienne" , "du-Breuil-de-Pont-en-Auge, Augustin" , "du-Breuil-de-Pont-en-Auge, Benoît" ; + . + + + a ; + "application/xml"^^ ; + "Freely available for non-commercial use" ; + "2010-11-17"^^ ; + "2013-11-04T22:20:07+01:00"^^ ; + ; + . + + a ; + "audio/x-wav"^^ ; + "Freely available for non-commercial use" ; + "2010-11-17"^^ ; + "PT48M26S" ; + "2013-10-12T14:35:57+02:00"^^ ; + . + + a ; + "audio/mpeg"^^ ; + "Freely available for non-commercial use" ; + "2010-11-17"^^ ; + "PT48M26S" ; + "2013-10-12T14:35:57+02:00"^^ ; + ; + . + + a ; + "audio/x-wav"^^ ; + "Freely available for non-commercial use" ; + "2010-11-17"^^ ; + "PT48M26S" ; + "2013-10-12T14:35:57+02:00"^^ ; + ; + . \ No newline at end of file diff -r f2c2c80a49f7 -r 5d2621f71f39 server/src/tests/Models/files/DocumentTest/test_no_geoinfo.ttl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/src/tests/Models/files/DocumentTest/test_no_geoinfo.ttl Thu Sep 22 15:42:12 2016 +0200 @@ -0,0 +1,73 @@ +@prefix rdf: . +@prefix rdfs: . +@prefix sesame: . +@prefix owl: . +@prefix xsd: . +@prefix fn: . + +<%1$scrdo-CFPP2000_35_SOUND> a ; + ; + "Langage et langues : description, théorisation, transmission" ; + , , ; + ; + ; + "Corpus de la Parole"@fr ; + . + + a ; + "Freely available for non-commercial use" ; + "2010-11-17"^^ ; + "PT48M26S" ; + "2013-10-12T14:35:57+02:00"^^ ; + ; + , "Tanguy, Noalig" , "Chevrier, Michel" , "Kiliç, Ozgur" , "Salvegas, Etienne" , "du-Breuil-de-Pont-en-Auge, Augustin" , "du-Breuil-de-Pont-en-Auge, Benoît" ; + "Enregistrement issu du Corpus de Français Parlé Parisien des années 2000 (CFPP2000)"@fr , "Quartier(s) concerné(s) : Paris 3e, et 20e (pour l'âge adulte); Anonymisation : Noalig TANGUY;"@fr ; + "ark:/87895/1.17-375004" , "%2$scrdo-CFPP2000_35_SOUNDid" , "oai:crdo.vjf.cnrs.fr:crdo-CFPP2000_35" , "Cote producteur: [03-01] Ozgur_Kilic_H_32_alii_3e"@fr , "ark:/87895/1.17-372593" , "oai:crdo.vjf.cnrs.fr:crdo-CFPP2000_35_SOUND" ; + ; + ; + , "anthropological_linguistics"^^ , "lexicography"^^ , "phonetics"^^ , , , , "general_linguistics"^^ , , "text_and_corpus_linguistics"^^ , "Français"@fr , , "phonology"^^ , "semantics"^^ , "sociolinguistics"^^ , "syntax"^^ , "typology"^^ , , , "discourse_analysis"^^ , "historical_linguistics"^^ , "language_documentation"^^ , , , , , , "mathematical_linguistics"^^ ; + "Entretien de Ozgur Kiliç 2"@fr ; + , , , "primary_text"^^ , , "narrative"^^ , "report"^^ , "unintelligible_speech"^^ ; + "2013-10-12"^^ ; + , ; + ; + ; + "Tanguy, Noalig" ; + "Quartier concerné : 3e"@fr ; + "Chevrier, Michel" , "Kiliç, Ozgur" , "Salvegas, Etienne" , "du-Breuil-de-Pont-en-Auge, Augustin" , "du-Breuil-de-Pont-en-Auge, Benoît" ; + . + + + a ; + "application/xml"^^ ; + "Freely available for non-commercial use" ; + "2010-11-17"^^ ; + "2013-11-04T22:20:07+01:00"^^ ; + ; + . + + a ; + "audio/x-wav"^^ ; + "Freely available for non-commercial use" ; + "2010-11-17"^^ ; + "PT48M26S" ; + "2013-10-12T14:35:57+02:00"^^ ; + . + + a ; + "audio/mpeg"^^ ; + "Freely available for non-commercial use" ; + "2010-11-17"^^ ; + "PT48M26S" ; + "2013-10-12T14:35:57+02:00"^^ ; + ; + . + + a ; + "audio/x-wav"^^ ; + "Freely available for non-commercial use" ; + "2010-11-17"^^ ; + "PT48M26S" ; + "2013-10-12T14:35:57+02:00"^^ ; + ; + . \ No newline at end of file diff -r f2c2c80a49f7 -r 5d2621f71f39 server/src/tests/Models/files/GeoResourceTest/loc1.ttl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/src/tests/Models/files/GeoResourceTest/loc1.ttl Thu Sep 22 15:42:12 2016 +0200 @@ -0,0 +1,80 @@ +@prefix rdf: . +@prefix rdfs: . +@prefix sesame: . +@prefix owl: . +@prefix xsd: . +@prefix fn: . + +<%1$scrdo-CFPP2000_35_SOUND> a ; + ; + "Langage et langues : description, théorisation, transmission" ; + , , ; + ; + ; + "Corpus de la Parole"@fr ; + . + + a ; + "Freely available for non-commercial use" ; + "2010-11-17"^^ ; + "PT48M26S" ; + "2013-10-12T14:35:57+02:00"^^ ; + ; + , "Tanguy, Noalig" , "Chevrier, Michel" , "Kiliç, Ozgur" , "Salvegas, Etienne" , "du-Breuil-de-Pont-en-Auge, Augustin" , "du-Breuil-de-Pont-en-Auge, Benoît" ; + "Enregistrement issu du Corpus de Français Parlé Parisien des années 2000 (CFPP2000)"@fr , "Quartier(s) concerné(s) : Paris 3e, et 20e (pour l'âge adulte); Anonymisation : Noalig TANGUY;"@fr ; + "ark:/87895/1.17-375004" , "%2\$scrdo-CFPP2000_35_SOUNDid" , "oai:crdo.vjf.cnrs.fr:crdo-CFPP2000_35" , "Cote producteur: [03-01] Ozgur_Kilic_H_32_alii_3e"@fr , "ark:/87895/1.17-372593" , "oai:crdo.vjf.cnrs.fr:crdo-CFPP2000_35_SOUND" ; + ; + ; + , "anthropological_linguistics"^^ , "lexicography"^^ , "phonetics"^^ , , , , "general_linguistics"^^ , , "text_and_corpus_linguistics"^^ , "Français"@fr , , "phonology"^^ , "semantics"^^ , "sociolinguistics"^^ , "syntax"^^ , "typology"^^ , , , "discourse_analysis"^^ , "historical_linguistics"^^ , "language_documentation"^^ , , , , , , "mathematical_linguistics"^^ ; + "Entretien de Ozgur Kiliç 2"@fr ; + , , , "primary_text"^^ , , "narrative"^^ , "report"^^ , "unintelligible_speech"^^ ; + "2013-10-12"^^ ; + [ + a ; + owl:sameAs ; + "48.73194"^^xsd:float; + "7.70833"^^xsd:float; + "FR"^^ , "France, Île-de-France, Paris, Université Sorbonne Nouvelle Paris 3, site Censier"@fr , "Domicile de Ozgur Kiliç"@fr , "France, Île-de-France, Paris 20"@fr + ]; + , ; + ; + ; + "Tanguy, Noalig" ; + "Quartier concerné : 3e"@fr ; + "Chevrier, Michel" , "Kiliç, Ozgur" , "Salvegas, Etienne" , "du-Breuil-de-Pont-en-Auge, Augustin" , "du-Breuil-de-Pont-en-Auge, Benoît" ; + . + + + a ; + "application/xml"^^ ; + "Freely available for non-commercial use" ; + "2010-11-17"^^ ; + "2013-11-04T22:20:07+01:00"^^ ; + ; + . + + a ; + "audio/x-wav"^^ ; + "Freely available for non-commercial use" ; + "2010-11-17"^^ ; + "PT48M26S" ; + "2013-10-12T14:35:57+02:00"^^ ; + . + + a ; + "audio/mpeg"^^ ; + "Freely available for non-commercial use" ; + "2010-11-17"^^ ; + "PT48M26S" ; + "2013-10-12T14:35:57+02:00"^^ ; + ; + . + + a ; + "audio/x-wav"^^ ; + "Freely available for non-commercial use" ; + "2010-11-17"^^ ; + "PT48M26S" ; + "2013-10-12T14:35:57+02:00"^^ ; + ; + . diff -r f2c2c80a49f7 -r 5d2621f71f39 server/src/tests/Models/files/GeoResourceTest/loc2.ttl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/src/tests/Models/files/GeoResourceTest/loc2.ttl Thu Sep 22 15:42:12 2016 +0200 @@ -0,0 +1,23 @@ +@prefix rdf: . +@prefix rdfs: . +@prefix sesame: . +@prefix owl: . +@prefix xsd: . +@prefix fn: . + +<%1$scrdo-CFPP2000_35_SOUND> a ; + "Freely available for non-commercial use" ; + "2010-11-17"^^ ; + "PT48M26S" ; + "2013-10-12T14:35:57+02:00"^^ ; + ; + "Enregistrement issu du Corpus de Français Parlé Parisien des années 2000 (CFPP2000)"@fr , "Quartier(s) concerné(s) : Paris 3e, et 20e (pour l'âge adulte); Anonymisation : Noalig TANGUY;"@fr ; + "ark:/87895/1.17-375004" , "%2\$scrdo-CFPP2000_35_SOUNDid" , "oai:crdo.vjf.cnrs.fr:crdo-CFPP2000_35" , "Cote producteur: [03-01] Ozgur_Kilic_H_32_alii_3e"@fr , "ark:/87895/1.17-372593" , "oai:crdo.vjf.cnrs.fr:crdo-CFPP2000_35_SOUND" ; + ; + ; + "Entretien de Ozgur Kiliç 2"@fr ; + "2013-10-12"^^ ; + [ + a ; + "FR"^^ , "France, Île-de-France, Paris, Université Sorbonne Nouvelle Paris 3, site Censier"@fr , "Domicile de Ozgur Kiliç"@fr , "France, Île-de-France, Paris 20"@fr + ] . diff -r f2c2c80a49f7 -r 5d2621f71f39 server/src/tests/Models/files/GeoResourceTest/loc3.ttl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/src/tests/Models/files/GeoResourceTest/loc3.ttl Thu Sep 22 15:42:12 2016 +0200 @@ -0,0 +1,27 @@ +@prefix rdf: . +@prefix rdfs: . +@prefix sesame: . +@prefix owl: . +@prefix xsd: . +@prefix fn: . + +<%1$scrdo-CFPP2000_35_SOUND> a ; + "Freely available for non-commercial use" ; + "2010-11-17"^^ ; + "PT48M26S" ; + "2013-10-12T14:35:57+02:00"^^ ; + ; + "Enregistrement issu du Corpus de Français Parlé Parisien des années 2000 (CFPP2000)"@fr , "Quartier(s) concerné(s) : Paris 3e, et 20e (pour l'âge adulte); Anonymisation : Noalig TANGUY;"@fr ; + "ark:/87895/1.17-375004" , "%2\$scrdo-CFPP2000_35_SOUNDid" , "oai:crdo.vjf.cnrs.fr:crdo-CFPP2000_35" , "Cote producteur: [03-01] Ozgur_Kilic_H_32_alii_3e"@fr , "ark:/87895/1.17-372593" , "oai:crdo.vjf.cnrs.fr:crdo-CFPP2000_35_SOUND" ; + ; + ; + "Entretien de Ozgur Kiliç 2"@fr ; + "2013-10-12"^^ ; + [ + a ; + owl:sameAs ; + owl:sameAs ; + "48.73194"^^xsd:float; + "7.70833"^^xsd:float; + "FR"^^ , "France, Île-de-France, Paris, Université Sorbonne Nouvelle Paris 3, site Censier"@fr , "Domicile de Ozgur Kiliç"@fr , "France, Île-de-France, Paris 20"@fr + ] . diff -r f2c2c80a49f7 -r 5d2621f71f39 server/src/tests/Repositories/DocumentRepositoryIntegrationTest.php --- a/server/src/tests/Repositories/DocumentRepositoryIntegrationTest.php Thu Sep 22 15:34:10 2016 +0200 +++ b/server/src/tests/Repositories/DocumentRepositoryIntegrationTest.php Thu Sep 22 15:42:12 2016 +0200 @@ -15,87 +15,10 @@ class DocumentRepositoryIntegrationTest extends TestCase { - const REPO_CREATION_TTL = <<. - @prefix rep: . - @prefix sr: . - @prefix sail: . - @prefix ms: . - - [] a rep:Repository ; - rep:repositoryID "%1\$s" ; - rdfs:label "%1\$s test repository" ; - rep:repositoryImpl [ - rep:repositoryType "openrdf:SailRepository" ; - sr:sailImpl [ - sail:sailType "openrdf:MemoryStore" ; - ms:persist false ; - ms:syncDelay 0 - ] - ]. -EOT; - - const TEST_DOC = << . - @prefix rdfs: . - @prefix sesame: . - @prefix owl: . - @prefix xsd: . - @prefix fn: . - - _:genid-2267740936ad4d04a567e6787732f0dd-genid1 a ; - owl:sameAs ; - "northlimit=47.431892250000033; southlimit=49.053971250000046;westlimit=6.846186050000028; eastlimit=8.232571550000074;"^^ , "FR"^^ , "France, Alsace"@fr . - - <%1\$scrdo-ALA_738> a ; - ; - "Atlas linguistiques, cultures et parlers régionaux de France" ; - , ; - ; - ; - "Corpus de la Parole"@fr ; - . + const REPO_CREATION_TTL = __DIR__.'/files/DocumentRepositoryIntegrationTest/repo_creation.ttl'; - a ; - "audio/mpeg"^^ ; - "1996"^^ ; - "PT01H11M29S" ; - "2014-11-10T14:27:08+01:00"^^ ; - . - - a ; - "audio/x-wav"^^ ; - "1996"^^ ; - "PT01H11M29S" ; - "2014-11-10T14:27:08+01:00"^^ . - - a ; - "audio/x-wav"^^ ; - "1996"^^ ; - "PT01H11M29S" ; - "2014-11-10T14:27:08+01:00"^^ ; - . - - a ; - "1996"^^ ; - "PT01H11M29S" ; - "2014-11-10T14:27:08+01:00"^^ ; - , ; - "Extrait des enquêtes dialectologiques en vue de constituer un atlas linguistique de l'Alsace."@fr ; - ; - "Atlas linguistiques, cultures et parlers régionaux de France" ; - "Copyright (c) Département de dialectologie alsacienne et mosellane de l'Université de Strasbourg" ; - , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , "anthropological_linguistics"^^ , "lexicography"^^ , "phonetics"^^ ; - "Atlas Linguistique et ethnographique de l'Alsace - Enquetes sur la conscience linguistique - ALA_738"@fr ; - , , , "dialogue"^^ , "primary_text"^^ ; - "Freely available for non-commercial use" ; - "2004-07-03"^^ ; - , ; - ; - _:genid-2267740936ad4d04a567e6787732f0dd-genid1 ; - ; - , . -EOT; + const TEST_DOC = __DIR__.'/files/DocumentRepositoryIntegrationTest/test_doc.ttl'; + const TEST_DOC_NO_GEO = __DIR__.'/files/DocumentRepositoryIntegrationTest/test_doc_no_geo.ttl'; function __construct(string $name = null) { parent::__construct($name); @@ -103,7 +26,7 @@ public function setUp() { parent::setUp(); - $this->graph = new EasyRdf\Graph(config('corpusparole.corpus_doc_id_base_uri')."crdo-ALA_738", sprintf(DocumentRepositoryIntegrationTest::TEST_DOC, config('corpusparole.corpus_doc_id_base_uri'))); + $this->graph = new EasyRdf\Graph(config('corpusparole.corpus_doc_id_base_uri')."crdo-ALA_738", sprintf(file_get_contents(DocumentRepositoryIntegrationTest::TEST_DOC), config('corpusparole.corpus_doc_id_base_uri'))); $this->httpClient = new Client(['base_uri' => config('corpusparole.sesame_base_url')]); $this->sesameRepository = config('corpusparole.sesame_repository'); @@ -111,7 +34,7 @@ $this->documentRepository = $this->app->make('CorpusParole\Repositories\DocumentRepository'); $uniqueid = uniqid('corpusparole', true); - $repoCreateStmt = sprintf(DocumentRepositoryIntegrationTest::REPO_CREATION_TTL, $this->sesameRepository); + $repoCreateStmt = sprintf(file_get_contents(DocumentRepositoryIntegrationTest::REPO_CREATION_TTL), $this->sesameRepository); $this->httpClient->delete("repositories/$this->sesameRepository", ['http_errors' => false]); $this->httpClient->post('repositories/SYSTEM/statements', [ 'headers' => ['Content-type' => 'application/x-turtle;charset=UTF-8'], @@ -120,20 +43,26 @@ ]); $this->httpClient->put("repositories/$this->sesameRepository/statements", [ 'headers' => ['Content-type' => 'text/turtle;charset=UTF-8'], - 'body' => sprintf(DocumentRepositoryIntegrationTest::TEST_DOC, config('corpusparole.corpus_doc_id_base_uri')), + 'body' => sprintf(file_get_contents(DocumentRepositoryIntegrationTest::TEST_DOC), config('corpusparole.corpus_doc_id_base_uri')), 'query' => ['context' => "<".config('corpusparole.corpus_doc_id_base_uri')."crdo-ALA_738>"], ]); + $this->httpClient->put("repositories/$this->sesameRepository/statements", [ + 'headers' => ['Content-type' => 'text/turtle;charset=UTF-8'], + 'body' => sprintf(file_get_contents(DocumentRepositoryIntegrationTest::TEST_DOC_NO_GEO), config('corpusparole.corpus_doc_id_base_uri')), + 'query' => ['context' => "<".config('corpusparole.corpus_doc_id_base_uri')."crdo-ALA_739>"], + ]); + } public function tearDown() { - //$this->httpClient->delete("repositories/$this->sesameRepository"); + $this->httpClient->delete("repositories/$this->sesameRepository"); parent::tearDown(); } public function testAll() { $expectedId = $this->corpusDocIdBaseUri.'crdo-ALA_738'; $docList = $this->documentRepository->all(); - $this->assertCount(1, $docList, "Should have one element"); + $this->assertCount(2, $docList, "Should have one element"); $resDoc = $docList[0]; @@ -147,7 +76,7 @@ public function testGet() { $expectedId = $this->corpusDocIdBaseUri.'crdo-ALA_738'; - $returnedGraph = new EasyRdf\Graph($expectedId, sprintf(DocumentRepositoryIntegrationTest::TEST_DOC,config('corpusparole.corpus_doc_id_base_uri'))); + $returnedGraph = new EasyRdf\Graph($expectedId, sprintf(file_get_contents(DocumentRepositoryIntegrationTest::TEST_DOC),config('corpusparole.corpus_doc_id_base_uri'))); $res = $this->documentRepository->get('crdo-ALA_738'); @@ -161,7 +90,7 @@ public function testGetShort() { $expectedId = $this->corpusDocIdBaseUri.'crdo-ALA_738'; - $returnedGraph = new EasyRdf\Graph($expectedId, sprintf(DocumentRepositoryIntegrationTest::TEST_DOC,config('corpusparole.corpus_doc_id_base_uri'))); + $returnedGraph = new EasyRdf\Graph($expectedId, sprintf(file_get_contents(DocumentRepositoryIntegrationTest::TEST_DOC),config('corpusparole.corpus_doc_id_base_uri'))); $res = $this->documentRepository->get('crdo-ALA_738', true); @@ -172,6 +101,111 @@ $this->assertTrue(EasyRdf\Isomorphic::isomorphic($res->getGraph(),$returnedGraph)); } + public function testNoGeo() { + $expectedId = $this->corpusDocIdBaseUri.'crdo-ALA_739'; + $returnedGraph = new EasyRdf\Graph($expectedId, sprintf(file_get_contents(DocumentRepositoryIntegrationTest::TEST_DOC_NO_GEO),config('corpusparole.corpus_doc_id_base_uri'))); + + $res = $this->documentRepository->get('crdo-ALA_739'); + + $this->assertNull($res->getGeoInfo(), "Must have no geo info"); + + } + + /** + * @expectedException CorpusParole\Libraries\CorpusParoleException + * @expectedExceptionMessage GetDeltaList called when changes are pending + */ + public function testAddGeoNoCommit() { + + $doc = $this->documentRepository->get('crdo-ALA_739'); + + $geoInfo = $doc->addGeoInfo(); + + $res = $this->documentRepository->save($doc); + } + + + public function testAddGeo() { + + $doc = $this->documentRepository->get('crdo-ALA_739'); + + $geoInfo = $doc->addGeoInfo(); + $geoInfo->commit(); + + $res = $this->documentRepository->save($doc); + + $res = $this->documentRepository->get('crdo-ALA_739'); + + $geoInfo = $res->getGeoInfo(); + + $this->assertNotNull($geoInfo, "Must have Geo info"); + + $notes = $geoInfo->getNotes(); + + $this->assertTrue(is_array($notes)); + $this->assertCount(0, $notes); + + $refLocs = $geoInfo->getRefLocs(); + + $this->assertTrue(is_array($refLocs)); + $this->assertCount(0,$refLocs); + + } + + public function testAddGeoExisting() { + + $doc = $this->documentRepository->get('crdo-ALA_738'); + + $geoInfo = $doc->addGeoInfo(); + $geoInfo->commit(); + + $res = $this->documentRepository->save($doc); + + $res = $this->documentRepository->get('crdo-ALA_738'); + + $geoInfo = $res->getGeoInfo(); + + $this->assertNotNull($geoInfo, "Must have Geo info"); + + $notes = $geoInfo->getNotes(); + + $this->assertTrue(is_array($notes)); + $this->assertCount(3, $notes); + + $refLocs = $geoInfo->getRefLocs(); + + $this->assertTrue(is_array($refLocs)); + $this->assertCount(1,$refLocs); + + } + + public function testGeoSetRefLoc() { + + $doc = $this->documentRepository->get('crdo-ALA_738'); + $geoInfo = $doc->addGeoInfo(); + + $newRefLocs = [ 'http://sws.geonames.org/2643743/' ]; + + $geoInfo->setRefLocs($newRefLocs); + + $geoInfo->commit(); + + $res = $this->documentRepository->save($doc); + + $res = $this->documentRepository->get('crdo-ALA_738'); + + $geoInfo = $res->getGeoInfo(); + + $refLocs = $geoInfo->getRefLocs(); + + $this->assertTrue(is_array($refLocs)); + $this->assertCount(1,$refLocs); + + $this->assertEquals(['http://sws.geonames.org/2643743/'], $refLocs); + + } + + public function testSave() { @@ -204,7 +238,7 @@ $res = $this->documentRepository->getCount(); $this->assertNotNull($res, "Res should not be null"); - $this->assertSame(1, $res, "should heve only one document"); + $this->assertSame(2, $res, "should have 2 documents"); } diff -r f2c2c80a49f7 -r 5d2621f71f39 server/src/tests/Repositories/DocumentRepositoryTest.php --- a/server/src/tests/Repositories/DocumentRepositoryTest.php Thu Sep 22 15:34:10 2016 +0200 +++ b/server/src/tests/Repositories/DocumentRepositoryTest.php Thu Sep 22 15:42:12 2016 +0200 @@ -156,6 +156,7 @@ $sparqlClientMock = m::mock('CorpusParole\Libraries\Sparql\SparqlClient', function($mock) { $mock->shouldReceive('startTransaction')->andReturn(true) + ->shouldReceive('deleteWhere') ->shouldReceive('delete')->shouldReceive('add') ->shouldReceive('commit')->andReturn(true); }); diff -r f2c2c80a49f7 -r 5d2621f71f39 server/src/tests/Repositories/files/DocumentRepositoryIntegrationTest/repo_creation.ttl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/src/tests/Repositories/files/DocumentRepositoryIntegrationTest/repo_creation.ttl Thu Sep 22 15:42:12 2016 +0200 @@ -0,0 +1,17 @@ +@prefix rdfs: . +@prefix rep: . +@prefix sr: . +@prefix sail: . +@prefix ms: . + +[] a rep:Repository ; + rep:repositoryID "%1$s" ; + rdfs:label "%1$s test repository" ; + rep:repositoryImpl [ + rep:repositoryType "openrdf:SailRepository" ; + sr:sailImpl [ + sail:sailType "openrdf:MemoryStore" ; + ms:persist false ; + ms:syncDelay 0 + ] + ]. diff -r f2c2c80a49f7 -r 5d2621f71f39 server/src/tests/Repositories/files/DocumentRepositoryIntegrationTest/test_doc.ttl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/src/tests/Repositories/files/DocumentRepositoryIntegrationTest/test_doc.ttl Thu Sep 22 15:42:12 2016 +0200 @@ -0,0 +1,61 @@ +@prefix rdf: . +@prefix rdfs: . +@prefix sesame: . +@prefix owl: . +@prefix xsd: . +@prefix fn: . + +_:genid-2267740936ad4d04a567e6787732f0dd-genid1 a ; + owl:sameAs ; + "northlimit=47.431892250000033; southlimit=49.053971250000046;westlimit=6.846186050000028; eastlimit=8.232571550000074;"^^ , "FR"^^ , "France, Alsace"@fr ; + "48.73194"^^xsd:float ; + "7.70833"^^xsd:float . + +<%1$scrdo-ALA_738> a ; + ; + "Atlas linguistiques, cultures et parlers régionaux de France" ; + , ; + ; + ; + "Corpus de la Parole"@fr ; + . + + a ; + "audio/mpeg"^^ ; + "1996"^^ ; + "PT01H11M29S" ; + "2014-11-10T14:27:08+01:00"^^ ; + . + + a ; + "audio/x-wav"^^ ; + "1996"^^ ; + "PT01H11M29S" ; + "2014-11-10T14:27:08+01:00"^^ . + + a ; + "audio/x-wav"^^ ; + "1996"^^ ; + "PT01H11M29S" ; + "2014-11-10T14:27:08+01:00"^^ ; + . + + a ; + "1996"^^ ; + "PT01H11M29S" ; + "2014-11-10T14:27:08+01:00"^^ ; + , ; + "Extrait des enquêtes dialectologiques en vue de constituer un atlas linguistique de l'Alsace."@fr ; + ; + "Atlas linguistiques, cultures et parlers régionaux de France" ; + "Copyright (c) Département de dialectologie alsacienne et mosellane de l'Université de Strasbourg" ; + , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , "anthropological_linguistics"^^ , "lexicography"^^ , "phonetics"^^ ; + "Atlas Linguistique et ethnographique de l'Alsace - Enquetes sur la conscience linguistique - ALA_738"@fr ; + , , , "dialogue"^^ , "primary_text"^^ ; + "Freely available for non-commercial use" ; + "2004-07-03"^^ ; + , ; + ; + _:genid-2267740936ad4d04a567e6787732f0dd-genid1 ; + ; + , . diff -r f2c2c80a49f7 -r 5d2621f71f39 server/src/tests/Repositories/files/DocumentRepositoryIntegrationTest/test_doc_no_geo.ttl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/src/tests/Repositories/files/DocumentRepositoryIntegrationTest/test_doc_no_geo.ttl Thu Sep 22 15:42:12 2016 +0200 @@ -0,0 +1,54 @@ +@prefix rdf: . +@prefix rdfs: . +@prefix sesame: . +@prefix owl: . +@prefix xsd: . +@prefix fn: . + +<%1$scrdo-ALA_739> a ; + ; + "Atlas linguistiques, cultures et parlers régionaux de France" ; + , ; + ; + ; + "Corpus de la Parole"@fr ; + . + + a ; + "audio/mpeg"^^ ; + "1996"^^ ; + "PT01H11M29S" ; + "2014-11-10T14:27:08+01:00"^^ ; + . + + a ; + "audio/x-wav"^^ ; + "1996"^^ ; + "PT01H11M29S" ; + "2014-11-10T14:27:08+01:00"^^ . + + a ; + "audio/x-wav"^^ ; + "1996"^^ ; + "PT01H11M29S" ; + "2014-11-10T14:27:08+01:00"^^ ; + . + + a ; + "1996"^^ ; + "PT01H11M29S" ; + "2014-11-10T14:27:08+01:00"^^ ; + , ; + "Extrait des enquêtes dialectologiques en vue de constituer un atlas linguistique de l'Alsace."@fr ; + ; + "Atlas linguistiques, cultures et parlers régionaux de France" ; + "Copyright (c) Département de dialectologie alsacienne et mosellane de l'Université de Strasbourg" ; + , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , "anthropological_linguistics"^^ , "lexicography"^^ , "phonetics"^^ ; + "Atlas Linguistique et ethnographique de l'Alsace - Enquetes sur la conscience linguistique - ALA_738"@fr ; + , , , "dialogue"^^ , "primary_text"^^ ; + "Freely available for non-commercial use" ; + "2004-07-03"^^ ; + , ; + ; + ; + , .