diff --git a/VERSIONS_WIP/160212 b/VERSIONS_WIP/160212 new file mode 100644 index 0000000000000000000000000000000000000000..265c52e5ad91d13879f1950b8684b6bcee278892 --- /dev/null +++ b/VERSIONS_WIP/160212 @@ -0,0 +1 @@ + - correctif #160212 : Indexation : Lorsque l'année de publication (210$d ou 214$d) contient du texte libre, Bokeh prend comme année la première série de 4 chiffres consécutifs \ No newline at end of file diff --git a/cosmogramme/php/classes/classe_unimarc.php b/cosmogramme/php/classes/classe_unimarc.php index dc01ca7aa3dd890396e47b1cc7cfe932aabef42a..7c21e8a2b1b972113fc502af4c93c8038fdce867 100644 --- a/cosmogramme/php/classes/classe_unimarc.php +++ b/cosmogramme/php/classes/classe_unimarc.php @@ -1371,22 +1371,8 @@ class notice_unimarc extends iso2709_record { } - public function getAnnee() { - if (!$data = (new Class_Notice_PublicationDate($this))->getPublicationDate()) - return ''; - - $annee = ''; - for($i=0; $i < strlen($data[0]); $i++) { - $car = strMid($data[0], $i, 1); - if($car >= '0' and $car <= '9') - $annee = $annee .$car; - if(strLen($annee) == 4) - break; - } - - if($annee < '1000' or $annee > '3000') - $annee = ''; - return($annee); + public function getAnnee() : string { + return (new Class_Notice_PublicationDate($this))->getPublicationYear() ?? ''; } diff --git a/cosmogramme/tests/php/classes/NoticeIntegrationTest.php b/cosmogramme/tests/php/classes/NoticeIntegrationTest.php index 29006511fddb39030f3f1a21592eded5a4e64793..710a18b3190f34fbdba5f86debb6ac866da699f1 100644 --- a/cosmogramme/tests/php/classes/NoticeIntegrationTest.php +++ b/cosmogramme/tests/php/classes/NoticeIntegrationTest.php @@ -577,6 +577,82 @@ class NoticeIntegrationLearningWithRenvoisTest extends NoticeIntegrationTestCase +class NoticePublicationYearExtractionTest extends NoticeIntegrationTestCase{ + public function publicationDatesForUnimarc(){ + return [ + [ + '1991', + [[210, ['d' => '1991']]] + ], + [ + '', + [[210, ['d' => '0999']]] + ], + [ + '', + [[210, ['d' => '3001']]] + ], + [ + '1991', + [[210, ['d' => 'DL 1991']]] + ], + [ + '1992', + [[210, ['d' => '12-12-1992']]] + ], + [ + '1993', + [[210, ['d' => '12ème édition novembre 1993']]] + ], + [ + '', + [[210, ['d' => '12ème édition novembre 70']]] + ], + [ + '1994', + [[214, ['d' => 'dernier semestre 1994']]] + ], + [ + '2021', + [ + [214, ['d' => '2021']], + [214, ['d' => '1981']], + ] + ], + [ + '2022', + [ + [210, ['d' => '1981']], + [214, ['d' => '2022']], + ] + ], + ]; + } + + /** + * @dataProvider publicationDatesForUnimarc + * @test + */ + public function unimarcShouldGeneratePublicationYear($expected_year, $zones) { + $unimarc = (new Class_NoticeUnimarc_Fluent) + ->zoneWithContent('001', '1234') + ->zoneWithChildren('200', ['a' => 'Documentaire']) + ->zoneWithChildren('995',['a' => 1, + 'b' => 1, + 'f' => '12345678']); + foreach($zones as $zone) + $unimarc->zoneWithChildren($zone[0], $zone[1]); + + $this->loadNoticeFromString($unimarc->render()); + + $this->assertEquals($expected_year, + Class_Notice::find(1)->getAnnee()); + } +} + + + + class NoticeIntegrationBearsBeerMicrobibTest extends NoticeIntegrationTestCase { public function getProfilDonnees() { return diff --git a/library/Class/Notice/PublicationDate.php b/library/Class/Notice/PublicationDate.php index 3b0d48cfe0296d12228bbb010b6c2c1f17458fbe..061be37800fbcb98b5026273e92ef2a2a1fe3f67 100644 --- a/library/Class/Notice/PublicationDate.php +++ b/library/Class/Notice/PublicationDate.php @@ -41,4 +41,14 @@ class Class_Notice_PublicationDate { ? array_filter($data) : []; } + + + public function getPublicationYear() : string { + $strings = $this->getPublicationDate(); + foreach ($strings as $publication_string){ + if (preg_match('/[12][0-9]{3}/', $publication_string, $matches)) + return $matches[0]; + } + return ''; + } }