Add description to documents interface and indexation. Prepare #0025746
authorymh <ymh.work@gmail.com>
Mon, 06 Feb 2017 13:23:39 +0100
changeset 498 265992e5b379
parent 497 f3474aeec884
child 499 b5cff30efa0a
Add description to documents interface and indexation. Prepare #0025746
server/src/app/Console/Commands/IndexDocuments.php
server/src/app/Models/Document.php
server/src/tests/Models/DocumentTest.php
server/src/tests/Models/files/DocumentTest/test_doc.ttl
server/src/tests/Models/files/DocumentTest/test_doc_no_description.ttl
--- 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),
         ];
     }
 
--- 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('<http://purl.org/dc/elements/1.1/description>'));
+            $this->descriptions = array_merge($this->descriptions, $this->getProvidedCHO()->all('<http://purl.org/dc/terms/abstract>'));
+            $this->descriptions = array_merge($this->descriptions, $this->getProvidedCHO()->all('<http://purl.org/dc/terms/tableOfContents>'));
+        }
+        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
             ]);
 
         }
--- 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);
+    }
+
+
 
 }
--- 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 @@
     <http://purl.org/dc/terms/license> <http://creativecommons.org/licenses/by-nc-sa/3.0/> ;
     <http://purl.org/dc/elements/1.1/contributor> <http://viaf.org/viaf/93752300> , "Tanguy, Noalig" , "Chevrier, Michel" , "Kiliç, Ozgur" , "Salvegas, Etienne" , "du-Breuil-de-Pont-en-Auge, Augustin" , "du-Breuil-de-Pont-en-Auge, Benoît" ;
     <http://purl.org/dc/elements/1.1/description> "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 ;
+    <http://purl.org/dc/terms/tableOfContents> "2- ech'cratcheu"@pcd;
+    <http://purl.org/dc/terms/abstract> "Participants : deux employées. Enregistré par James Mallinson. Contenu : JSM se renseigne sur billet."@fr;
     <http://purl.org/dc/elements/1.1/identifier> "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" ;
     <http://purl.org/dc/elements/1.1/language> <http://lexvo.org/id/iso639-3/fra> ;
     <http://purl.org/dc/elements/1.1/publisher> <http://viaf.org/viaf/142432638>;
@@ -77,4 +79,4 @@
     <http://purl.org/dc/terms/extent> "PT48M26S" ;
     <http://purl.org/dc/terms/issued> "2013-10-12T14:35:57+02:00"^^<http://purl.org/dc/terms/W3CDTF> ;
     <http://purl.org/dc/terms/license> <http://creativecommons.org/licenses/by-nc-sa/3.0/> ;
-    <http://www.europeana.eu/schemas/edm/isDerivativeOf> <http://cocoon.huma-num.fr/data/archi/masters/372593.wav> .
\ No newline at end of file
+    <http://www.europeana.eu/schemas/edm/isDerivativeOf> <http://cocoon.huma-num.fr/data/archi/masters/372593.wav> .
--- /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: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix sesame: <http://www.openrdf.org/schema/sesame#> .
+@prefix owl: <http://www.w3.org/2002/07/owl#> .
+@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+@prefix fn: <http://www.w3.org/2005/xpath-functions#> .
+
+<%1$scrdo-CFPP2000_35_SOUND> a <http://www.openarchives.org/ore/terms/Aggregation> ;
+    <http://www.europeana.eu/schemas/edm/aggregatedCHO> <http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-CFPP2000_35_SOUND> ;
+    <http://www.europeana.eu/schemas/edm/dataProvider> "Langage et langues : description, théorisation, transmission" ;
+    <http://www.europeana.eu/schemas/edm/hasView> <http://cocoon.huma-num.fr/exist/crdo/cfpp2000/fra/Ozgur_Kilic_H_32_alii_3e-2.xml> , <http://cocoon.huma-num.fr/data/cfpp2000/Ozgur_Kilic_H_32_alii_3e-2.mp3> , <http://cocoon.huma-num.fr/data/cfpp2000/Ozgur_Kilic_H_32_alii_3e-2.wav> ;
+    <http://www.europeana.eu/schemas/edm/isShownAt> <http://corpusdelaparole.huma-num.fr/corpus-app#/detail/crdo-CFPP2000_35_SOUND> ;
+    <http://www.europeana.eu/schemas/edm/isShownBy> <http://cocoon.huma-num.fr/data/archi/masters/372593.wav> ;
+    <http://www.europeana.eu/schemas/edm/provider> "Corpus de la Parole"@fr ;
+    <http://www.europeana.eu/schemas/edm/rights> <http://creativecommons.org/licenses/by-nc-sa/4.0/> .
+
+<http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-CFPP2000_35_SOUND> a <http://www.europeana.eu/schemas/edm/ProvidedCHO> ;
+    <http://purl.org/dc/terms/accessRights> "Freely available for non-commercial use" ;
+    <http://purl.org/dc/terms/created> "2010-11-17"^^<http://purl.org/dc/terms/W3CDTF> ;
+    <http://purl.org/dc/terms/extent> "PT48M26S" ;
+    <http://purl.org/dc/terms/issued> "2013-10-12T14:35:57+02:00"^^<http://purl.org/dc/terms/W3CDTF> ;
+    <http://purl.org/dc/terms/license> <http://creativecommons.org/licenses/by-nc-sa/3.0/> ;
+    <http://purl.org/dc/elements/1.1/contributor> <http://viaf.org/viaf/93752300> , "Tanguy, Noalig" , "Chevrier, Michel" , "Kiliç, Ozgur" , "Salvegas, Etienne" , "du-Breuil-de-Pont-en-Auge, Augustin" , "du-Breuil-de-Pont-en-Auge, Benoît" ;
+    <http://purl.org/dc/elements/1.1/identifier> "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" ;
+    <http://purl.org/dc/elements/1.1/language> <http://lexvo.org/id/iso639-3/fra> ;
+    <http://purl.org/dc/elements/1.1/publisher> <http://viaf.org/viaf/142432638>;
+    <http://purl.org/dc/elements/1.1/subject> <http://ark.bnf.fr/ark:/12148/cb13318415c> , "anthropological_linguistics"^^<http://www.language-archives.org/OLAC/1.1/linguistic-field> , "lexicography"^^<http://www.language-archives.org/OLAC/1.1/linguistic-field> , "phonetics"^^<http://www.language-archives.org/OLAC/1.1/linguistic-field> , <http://lexvo.org/id/iso639-3/fra> , <http://ark.bnf.fr/ark:/12148/cb133188907> , <http://ark.bnf.fr/ark:/12148/cb11932762f> , "general_linguistics"^^<http://www.language-archives.org/OLAC/1.1/linguistic-field> , <http://ark.bnf.fr/ark:/12148/cb133183660> , "text_and_corpus_linguistics"^^<http://www.language-archives.org/OLAC/1.1/linguistic-field> , "Français"@fr , <http://ark.bnf.fr/ark:/12148/cb122368540> , "phonology"^^<http://www.language-archives.org/OLAC/1.1/linguistic-field> , "semantics"^^<http://www.language-archives.org/OLAC/1.1/linguistic-field> , "sociolinguistics"^^<http://www.language-archives.org/OLAC/1.1/linguistic-field> , "syntax"^^<http://www.language-archives.org/OLAC/1.1/linguistic-field> , "typology"^^<http://www.language-archives.org/OLAC/1.1/linguistic-field> , <http://ark.bnf.fr/ark:/12148/cb119418302> , <http://ark.bnf.fr/ark:/12148/cb135540729> , "discourse_analysis"^^<http://www.language-archives.org/OLAC/1.1/linguistic-field> , "historical_linguistics"^^<http://www.language-archives.org/OLAC/1.1/linguistic-field> , "language_documentation"^^<http://www.language-archives.org/OLAC/1.1/linguistic-field> , <http://ark.bnf.fr/ark:/12148/cb133192210> , <http://ark.bnf.fr/ark:/12148/cb119377452> , <http://ark.bnf.fr/ark:/12148/cb13320451h> , <http://ark.bnf.fr/ark:/12148/cb13318422n> , <http://ark.bnf.fr/ark:/12148/cb11975823c> , "mathematical_linguistics"^^<http://www.language-archives.org/OLAC/1.1/linguistic-field> ;
+    <http://purl.org/dc/elements/1.1/title> "Entretien de Ozgur Kiliç 2"@fr ;
+    <http://purl.org/dc/elements/1.1/type> <http://ark.bnf.fr/ark:/12148/cb11932135w> , <http://ark.bnf.fr/ark:/12148/cb12481481z> , <http://purl.org/dc/dcmitype/Sound> , "primary_text"^^<http://www.language-archives.org/OLAC/1.1/linguistic-type> , <http://purl.org/dc/dcmitype/Text> , "narrative"^^<http://www.language-archives.org/OLAC/1.1/discourse-type> , "report"^^<http://www.language-archives.org/OLAC/1.1/discourse-type> , "unintelligible_speech"^^<http://www.language-archives.org/OLAC/1.1/discourse-type> ;
+    <http://purl.org/dc/terms/available> "2013-10-12"^^<http://purl.org/dc/terms/W3CDTF> ;
+    <http://purl.org/dc/terms/spatial> [
+        a <http://www.europeana.eu/schemas/edm/Place> ;
+        owl:sameAs <http://sws.geonames.org/6618626/> ;
+        <http://www.w3.org/2003/01/geo/wgs84_pos#lat> "48.73194"^^xsd:float;
+        <http://www.w3.org/2003/01/geo/wgs84_pos#long> "7.70833"^^xsd:float;
+        <http://www.w3.org/2004/02/skos/core#note> "FR"^^<http://purl.org/dc/terms/ISO3166> , "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
+    ];
+    <http://www.europeana.eu/schemas/edm/isGatheredInto> <http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-COLLECTION_LANGUESDEFRANCE> , <http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-COLLECTION_CFPP2000> ;
+    <http://www.language-archives.org/OLAC/1.1/depositor> <http://viaf.org/viaf/93752300> ;
+    <http://www.language-archives.org/OLAC/1.1/interviewer> <http://viaf.org/viaf/93752300> ;
+    <http://www.language-archives.org/OLAC/1.1/transcriber> "Tanguy, Noalig" ;
+    <http://purl.org/dc/elements/1.1/coverage> "Quartier concerné : 3e"@fr ;
+    <http://www.language-archives.org/OLAC/1.1/responder> "Chevrier, Michel" , "Kiliç, Ozgur" , "Salvegas, Etienne" , "du-Breuil-de-Pont-en-Auge, Augustin" , "du-Breuil-de-Pont-en-Auge, Benoît" ;
+    <http://purl.org/dc/elements/1.1/relation> <http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-CFPP2000_31_SOUND> .
+
+
+<http://cocoon.huma-num.fr/exist/crdo/cfpp2000/fra/Ozgur_Kilic_H_32_alii_3e-2.xml> a <http://www.europeana.eu/schemas/edm/WebResource> ;
+    <http://purl.org/dc/elements/1.1/format> "application/xml"^^<http://purl.org/dc/terms/IMT> ;
+    <http://purl.org/dc/terms/accessRights> "Freely available for non-commercial use" ;
+    <http://purl.org/dc/terms/created> "2010-11-17"^^<http://purl.org/dc/terms/W3CDTF> ;
+    <http://purl.org/dc/terms/issued> "2013-11-04T22:20:07+01:00"^^<http://purl.org/dc/terms/W3CDTF> ;
+    <http://purl.org/dc/terms/license> <http://creativecommons.org/licenses/by-nc-sa/3.0/> ;
+    <http://purl.org/dc/terms/conformsTo> <http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-dtd_transcriber> .
+
+<http://cocoon.huma-num.fr/data/archi/masters/372593.wav> a <http://www.europeana.eu/schemas/edm/WebResource> ;
+    <http://purl.org/dc/elements/1.1/format> "audio/x-wav"^^<http://purl.org/dc/terms/IMT> ;
+    <http://purl.org/dc/terms/accessRights> "Freely available for non-commercial use" ;
+    <http://purl.org/dc/terms/created> "2010-11-17"^^<http://purl.org/dc/terms/W3CDTF> ;
+    <http://purl.org/dc/terms/extent> "PT48M26S" ;
+    <http://purl.org/dc/terms/issued> "2013-10-12T14:35:57+02:00"^^<http://purl.org/dc/terms/W3CDTF> ;
+    <http://purl.org/dc/terms/license> <http://creativecommons.org/licenses/by-nc-sa/3.0/> .
+
+<http://cocoon.huma-num.fr/data/cfpp2000/Ozgur_Kilic_H_32_alii_3e-2.mp3> a <http://www.europeana.eu/schemas/edm/WebResource> ;
+    <http://purl.org/dc/elements/1.1/format> "audio/mpeg"^^<http://purl.org/dc/terms/IMT> ;
+    <http://purl.org/dc/terms/accessRights> "Freely available for non-commercial use" ;
+    <http://purl.org/dc/terms/created> "2010-11-17"^^<http://purl.org/dc/terms/W3CDTF> ;
+    <http://purl.org/dc/terms/extent> "PT48M26S" ;
+    <http://purl.org/dc/terms/issued> "2013-10-12T14:35:57+02:00"^^<http://purl.org/dc/terms/W3CDTF> ;
+    <http://purl.org/dc/terms/license> <http://creativecommons.org/licenses/by-nc-sa/3.0/> ;
+    <http://www.europeana.eu/schemas/edm/isDerivativeOf> <http://cocoon.huma-num.fr/data/archi/masters/372593.wav> .
+
+<http://cocoon.huma-num.fr/data/cfpp2000/Ozgur_Kilic_H_32_alii_3e-2.wav> a <http://www.europeana.eu/schemas/edm/WebResource> ;
+    <http://purl.org/dc/elements/1.1/format> "audio/x-wav"^^<http://purl.org/dc/terms/IMT> ;
+    <http://purl.org/dc/terms/accessRights> "Freely available for non-commercial use" ;
+    <http://purl.org/dc/terms/created> "2010-11-17"^^<http://purl.org/dc/terms/W3CDTF> ;
+    <http://purl.org/dc/terms/extent> "PT48M26S" ;
+    <http://purl.org/dc/terms/issued> "2013-10-12T14:35:57+02:00"^^<http://purl.org/dc/terms/W3CDTF> ;
+    <http://purl.org/dc/terms/license> <http://creativecommons.org/licenses/by-nc-sa/3.0/> ;
+    <http://www.europeana.eu/schemas/edm/isDerivativeOf> <http://cocoon.huma-num.fr/data/archi/masters/372593.wav> .