# HG changeset patch # User ymh # Date 1486383819 -3600 # Node ID 265992e5b37984f5559018706b66f5bfcdebb345 # Parent f3474aeec884aba0172c3431598250aa4d6fe2f3 Add description to documents interface and indexation. Prepare #0025746 diff -r f3474aeec884 -r 265992e5b379 server/src/app/Console/Commands/IndexDocuments.php --- a/server/src/app/Console/Commands/IndexDocuments.php Mon Feb 06 10:03:33 2017 +0100 +++ b/server/src/app/Console/Commands/IndexDocuments.php Mon Feb 06 13:23:39 2017 +0100 @@ -103,6 +103,15 @@ ] ] ], + 'description' => [ + 'type' => 'string', + 'fields' => [ + 'french' => [ + 'type' => 'string', + 'analyzer' => 'french' + ] + ] + ], 'date' => [ 'type' => 'date', 'index' => 'not_analyzed'], 'geonames_hierarchy' => [ 'type' => 'string', 'index' => 'not_analyzed'], 'geonames_country' => ['type' => 'string', 'index' => 'not_analyzed'], @@ -524,6 +533,21 @@ }, []); } + private function getDescriptions($doc) { + return array_reduce($doc->getDescriptions(), function($res, $desc) { + $val = null; + if(is_string($desc)) { + $val = $desc; + } elseif($desc instanceof Literal) { + $val = $desc->getValue(); + } + if(!empty($val)) { + array_push($res, $val); + } + return $res; + }, []); + } + private function getDocBody($doc) { list($geonamesCountry, $geonamesHierarchy) = $this->getGeonamesHierarchy($doc); return [ @@ -537,6 +561,7 @@ 'geonames_country' => $geonamesCountry, 'geonames_hierarchy' => $geonamesHierarchy, 'subject' => $this->getSubjects($doc), + 'description' => $this->getDescriptions($doc), ]; } diff -r f3474aeec884 -r 265992e5b379 server/src/app/Models/Document.php --- a/server/src/app/Models/Document.php Mon Feb 06 10:03:33 2017 +0100 +++ b/server/src/app/Models/Document.php Mon Feb 06 13:23:39 2017 +0100 @@ -30,6 +30,7 @@ private $contributors = null; private $subjects = null; private $types = null; + private $descriptions = null; private $geoInfo = false; protected function clearMemoizationCache() { @@ -39,6 +40,7 @@ $this->contributors = null; $this->subjects = null; $this->types = null; + $this->descriptions = null; $this->transcript = false; $this->geoInfo = false; } @@ -310,6 +312,19 @@ } + /** + * Get subjects list + */ + public function getDescriptions() { + if(is_null($this->descriptions)) { + $this->descriptions = []; + $this->descriptions = array_merge($this->descriptions, $this->getProvidedCHO()->all('')); + $this->descriptions = array_merge($this->descriptions, $this->getProvidedCHO()->all('')); + $this->descriptions = array_merge($this->descriptions, $this->getProvidedCHO()->all('')); + } + return $this->descriptions; + } + public function isIsomorphic($doc) { return Isomorphic::isomorphic($this->graph, $doc->graph); @@ -359,6 +374,10 @@ function($s) { return Utils::processLiteralResourceOrString($s); }, $this->getTypes() ); + $descriptions = array_map( + function($s) { return Utils::processLiteralResourceOrString($s); }, + $this->getDescriptions() + ); $res = array_merge($res, [ 'publishers' => $publishers, @@ -367,7 +386,8 @@ 'types' => $types, 'transcript' => $transcript, 'mediaArray'=> $mediaArray, - 'geoInfo' => $geoInfo + 'geoInfo' => $geoInfo, + 'descriptions' => $descriptions ]); } diff -r f3474aeec884 -r 265992e5b379 server/src/tests/Models/DocumentTest.php --- a/server/src/tests/Models/DocumentTest.php Mon Feb 06 10:03:33 2017 +0100 +++ b/server/src/tests/Models/DocumentTest.php Mon Feb 06 13:23:39 2017 +0100 @@ -13,6 +13,7 @@ const TEST_INPUT_DOCS = [ 'TEST' => __DIR__.'/files/DocumentTest/test_doc.ttl', 'TEST_NO_GEOINFO' => __DIR__.'/files/DocumentTest/test_no_geoinfo.ttl', + 'TEST_NO_DESCRIPTION' => __DIR__.'/files/DocumentTest/test_doc_no_description.ttl', ]; private $inputGraphes = []; @@ -427,7 +428,9 @@ $this->assertTrue(is_array($json), 'Returned json must be an array'); $this->assertEquals( - ["id", "uri", "title", "languages", "modified", "issued", "created", "publishers", "contributors", "subjects", "types", "transcript", "mediaArray", "geoInfo"], + [ "id", "uri", "title", "languages", "modified", "issued", + "created", "publishers", "contributors", "subjects", "types", + "transcript", "mediaArray", "geoInfo", "descriptions" ], array_keys($json) ); $this->assertEquals(sprintf('%1$s/crdo-CFPP2000_35_SOUNDid', config('corpusparole.handle_prefix')), $json['id']); @@ -501,5 +504,26 @@ $this->assertEquals(9, $res->getCurrentDelta()->getAddedGraph()->countTriples(), "Added graph must have 7 triples"); } + public function testDescriptions() { + $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST']); + + $descriptions = $doc->getDescriptions(); + + $this->assertTrue(is_array($descriptions)); + + $this->assertCount(4, $descriptions); + } + + public function testNoDescription() { + $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-CFPP2000_35_SOUND", $this->inputGraphes['TEST_NO_DESCRIPTION']); + + $descriptions = $doc->getDescriptions(); + + $this->assertTrue(is_array($descriptions)); + + $this->assertCount(0, $descriptions); + } + + } diff -r f3474aeec884 -r 265992e5b379 server/src/tests/Models/files/DocumentTest/test_doc.ttl --- a/server/src/tests/Models/files/DocumentTest/test_doc.ttl Mon Feb 06 10:03:33 2017 +0100 +++ b/server/src/tests/Models/files/DocumentTest/test_doc.ttl Mon Feb 06 13:23:39 2017 +0100 @@ -22,6 +22,8 @@ ; , "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 ; + "2- ech'cratcheu"@pcd; + "Participants : deux employées. Enregistré par James Mallinson. Contenu : JSM se renseigne sur billet."@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" ; ; ; @@ -77,4 +79,4 @@ "PT48M26S" ; "2013-10-12T14:35:57+02:00"^^ ; ; - . \ No newline at end of file + . diff -r f3474aeec884 -r 265992e5b379 server/src/tests/Models/files/DocumentTest/test_doc_no_description.ttl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/src/tests/Models/files/DocumentTest/test_doc_no_description.ttl Mon Feb 06 13:23:39 2017 +0100 @@ -0,0 +1,79 @@ +@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" ; + "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"^^ ; + ; + .