diff --git a/cosmogramme/php/classes/classe_indexation.php b/cosmogramme/php/classes/classe_indexation.php index fb4b4a2652860d3e2801b01d331e7ad4702cf046..c340edaaea13d528dfb96521192569d5e18c8e52 100644 --- a/cosmogramme/php/classes/classe_indexation.php +++ b/cosmogramme/php/classes/classe_indexation.php @@ -1,4 +1,4 @@ -<?PHP +<?php /** * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. * @@ -18,250 +18,17 @@ * along with BOKEH; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -//////////////////////////////////////////////////////////////////////// -// CALCUL DES INDEX -/////////////////////////////////////////////////////////////////////// -class indexation { - private $articles; // Articles rejetes - private $inclu; // Mots inclus - private $exclu; // Mots vides - private $pluriel; // Règles des pluriels - private $tableMajFrom, $tableMajTo = []; // Table de transco pour majuscules - private $tableMajUtf8; // Table de transco pour majuscules accentuées utf8 - public static $phonetixCache = []; - private $accents = ['É' => 'E', 'È' => 'E', 'Ë' => 'E', 'Ê' => 'E','Ã' => 'A', 'À' => 'A', 'Ä' => 'A', 'Â' => 'A', - 'Ã…' => 'A', 'Ã' => 'A', 'Æ' => 'E','Ã' => 'I', 'ÃŽ' => 'I', 'ÃŒ' => 'I', 'Ã' => 'I', - 'Ô' => 'O', 'Ö' => 'O', 'Ã’' => 'O', 'Ó' => 'O', 'Õ' => 'O', 'Ø' => 'O', 'Å’' => 'OEU', - 'Ú' => 'U', 'Ù' => 'U', 'Û' => 'U', 'Ãœ' => 'U','Ñ' => 'N', 'Ç' => 'S', '¿' => 'E']; +class indexation extends Class_Indexation { + protected static $phonetixCache = []; - private $min2maj = ['é' => 'É', 'è' => 'È', 'ë' => 'Ë', 'ê' => 'Ê','á' => 'Ã', 'â' => 'Â', 'à ' => 'À', 'Ä' => 'A', - 'Â' => 'A', 'Ã¥' => 'Ã…', 'ã' => 'Ã', 'æ' => 'Æ', 'ï' => 'Ã', 'î' => 'ÃŽ', 'ì' => 'ÃŒ', 'Ã' => 'Ã', - 'ô' => 'Ô', 'ö' => 'Ö', 'ò' => 'Ã’', 'ó' => 'Ó','õ' => 'Õ', 'ø' => 'Ø', 'Å“' => 'Å’', - 'ú' => 'Ú', 'ù' => 'Ù', 'û' => 'Û', 'ü' => 'Ãœ','ç' => 'Ç', 'ñ' => 'Ñ', 'ß' => 'S']; - -// Contructeur (init les règles d'indexation) - function __construct() - { + public function __construct() { if (empty(static::$phonetixCache)) static::$phonetixCache = unserialize(file_get_contents(dirname(__FILE__).'/phonetix.txt')); - - // Lire formes rejetées - $this->articles=array("L'","LE ","LA ","LES ","UN ","UNE "); - $this->inclu=array("AN","AS","OR","U2","AI","LU","XO","DO","RE","MI","FA","SI","AC","DC","XX","B","C","D","E","F","G","H","I","J","K","M","P","Q","R","S","T","V","W","X","Y","Z","L","YU","UT","LI","OC","PI","ZU","WU","TO","OZ","ZZ","XX"); - $this->exclu = array("L","LE","LA","LES","UN","UNE","LES","DES","MES","TES","CES"); - - // Pluriels - $this->pluriel=array( - array("AIL","AULX"), - array("AVAL","AVALS"), - array("BAIL","BAUX"), - array("BAL","BALS"), - array("BANAL","BANALS"), - array("BANCAL","BANCALS"), - array("BIJOU","BIJOUX"), - array("BLEU","BLEUS"), - array("CAILLOU","CAILLOUX"), - array("CAL","CALS"), - array("CARNAVAL","CARNAVALS"), - array("CEREMONIAL","CEREMONIALS"), - array("CHACAL","CHACALS"), - array("CHORAL","CHORALS"), - array("CHOU","CHOUX"), - array("CORAIL","CORAUX"), - array("DETAIL","DETAILS"), - array("EMAIL","EMAUX"), - array("EMEU","EMEUS"), - array("ETAL","ETALS"), - array("FATAL","FATALS"), - array("FESTIVAL","FESTIVALS"), - array("GEMMAIL","GEMMAUX"), - array("GENOU","GENOUX"), - array("HIBOU","HIBOUX"), - array("JOUJOU","JOUJOUX"), - array("LANDAU","LANDAUX"), - array("NATAL","NATALS"), - array("OEIL","YEUX"), - array("PAL","PALS"), - array("PNEU","PNEUS"), - array("POU","POUX"), - array("RECITAL","RECITALS"), - array("REGAL","REGALS"), - array("SARRAU","SARRAUS"), - array("SOUPIRAIL","SOUPIRAUX"), - array("TONAL","TONALS"), - array("TRAVAIL","TRAVAUX"), - array("VAL","VALS"), - array("VENTAIL","VENTAUX"), - array("VIRGINAL","VIRGINALS"), - array("VITRAIL","VITRAUX"), - array("*EAU","*EAUX"), - array("*AL","*AUX"), - array("*EU","*EUX"), - array("*AU","*AUX") - ); - - // Init table ascii pour majuscules - $this->tableMajTo = str_split(str_repeat( " ", 42 ) - . "* 0123456789 " - . "ABCDEFGHIJKLMNOPQRSTUVWXYZ " - . "ABCDEFGHIJKLMNOPQRSTUVWXYZ " - . str_repeat( " ", 63) - ."AAAAAAACEEEEIIII NOOOOO UUUUY AAAAAAACEEEEIIII NOOOOO UUUUY Y"); - - for($i=0; $i<count($this->tableMajTo); $i++) - $this->tableMajFrom[] = chr($i); - - - $this->tableMajUtf8=array(chr(0xC9) => 'E', 'È' => 'E', 'Ë' => 'E', 'Ê' => 'E','Ã' => 'A', 'À' => 'A', 'Ä' => 'A', 'Â' => 'A', - 'Ã…' => 'A', 'Ã' => 'A', 'Æ' => 'E','Ã' => 'I', 'ÃŽ' => 'I', 'ÃŒ' => 'I', 'Ã' => 'I', - 'Ô' => 'O', 'Ö' => 'O', 'Ã’' => 'O', 'Ó' => 'O', 'Õ' => 'O', 'Ø' => 'O', 'Å’' => 'OEU', - 'Ú' => 'U', 'Ù' => 'U', 'Û' => 'U', 'Ãœ' => 'U','Ñ' => 'N', 'Ç' => 'S', '¿' => 'E'); - } - // Indexation d'un titre - public function codeAlphaTitre($titre) - { - $titre=$this->alphaMaj($titre); - foreach($this->articles as $article) - { - $lg=strlen($article); - if(strLeft($titre, $lg)==$article) {$titre=strMid($titre,$lg,256); break;} - } - $titre=$this->alphaMaj($titre); - return $titre; + parent::__construct(); } - // Rend une suite de mots complete pour les formes plurielles - public function getExpressionRecherche($mot) - { - $mot=trim($mot); - if(!$mot) return false; - // Pluriel - if(strRight($mot,1) == "*") {$etoile="*";$mot=strLeft($mot, strlen($mot)-1);} - $m=$this->getPluriel($mot); - $m[2]=$this->phonetix($m[0]); - $ret="(".$m[0].$etoile." ".$m[1]." ".$m[2].")"; - return trim($ret); - } - - - public function alphaMaj( $chaine ) { - return trim(str_replace($this->tableMajFrom, - $this->tableMajTo, - utf8_decode($chaine))); - } - - - public function getClefAlpha($type_doc,$titre,$complement_titre,$auteur,$tome,$editeur,$annee) - { - $clef=$this->getClefOeuvre($titre,$complement_titre,$auteur,$tome)."-"; - $clef.=substr($this->alphaMaj(str_replace(" ","",$editeur)),0,80)."-"; - $clef.=$annee."-"; - $clef.=$type_doc; - $clef=str_replace(" ","",$clef); - return $clef; - } - -// Rend une clef alpha pour les oeuvres - public function getClefOeuvre($titre,$complement_titre,$auteur,$tome) - { - $clef = substr($this->codeAlphaTitre(strtoupper(str_replace(" ","",$titre))),0,80)."-"; - $clef.=substr($this->codeAlphaTitre(strtoupper(str_replace(" ","",$complement_titre))),0,20)."-"; - $clef.=substr($this->alphaMaj(str_replace(" ","",$auteur)),0,80)."-"; - $clef.=$this->alphaMaj($tome); - $clef=str_replace(" ","",$clef); - return $clef; - } - -// Decoupe une expression en mots en tenant compte des exclusions / inclusions - public function getMots( $chaine ) - { - $new=array(); - $chaine = str_replace( ".", "", $chaine); - $chaine = trim($this->alphaMaj($chaine)); - $mot = explode( " ", $chaine ); - $index = 0; - for( $i = 0; $i < count($mot); $i++) - { - // Retirer mots de 2 lettres sauf les inclus et les nombres - if( strLen($mot[$i]) < 3 And intVal($mot[$i])==false) - { - if( in_array( $mot[$i], $this->inclu) == false) continue; - if(strlen($mot[$i])==1) $mot[$i].="00"; // mots d'1 lettre : on double la lettre - } - // Retirer mots vides - if( in_array($mot[$i], $this->exclu ) == true ) continue; - // On garde le mot - $new[$index++] = $mot[$i]; - } - return $new; - } - -// Rend une chaine de mots dedoublonnes et filtres - public function getFulltext($data) { - if (gettype($data) != "array") - $data=array($data); - - $new=" "; - foreach($data as $chaine) - { - $mots=$this->getMots($chaine); - foreach($mots as $mot) - { - $mot=" ".$mot." "; - if(strpos($new,$mot) === false ) - { - $new.=trim($mot)." "; - $phonem=" ".$this->phonetix(trim($mot))." "; - if($phonem and strpos($new,$phonem) === false ) $new.=trim($phonem)." "; - } - } - } - return trim($new); - } - -// Rend le mot au singulier et au pluriel - public function getPluriel( $mot ) - { - if( strToUpper($mot) != $mot ) $mot=$this->alphaMaj($mot); - if(!trim($mot)) return false; - foreach($this->pluriel as $regle) - { - if(strLeft($regle[0],1) != "*") - { - if($mot==$regle[0] or $mot==$regle[1]) return $regle; - else continue; - } - $regle[0]=str_replace("*","",$regle[0]); - $regle[1]=str_replace("*","",$regle[1]); - $pattern_singulier = "(".$regle[0]."$)"; - $pattern_pluriel="(".$regle[1]."$)"; - - $pluriel=ereg_replace($pattern_singulier, $regle[1], $mot); - $singulier=ereg_replace($pattern_pluriel, $regle[0], $mot); - if($singulier != $mot or $pluriel != $mot) break; - } - // Si inchangé on ajoute le S - if($singulier == $pluriel) - { - if(strRight($mot,1)=="S") {$pluriel=$singulier; $singulier=strLeft($singulier,strlen($singulier)-1);} - else $pluriel=$singulier."S"; - } - return array($singulier,$pluriel); - } - -// --------------------------------------------------- -// Rend true si mot inclu -// --------------------------------------------------- - public function isMotInclu($mot) - { - return in_array($mot, $this->inclu); - } - -// --------------------------------------------------- -// Othographe approchante -// --------------------------------------------------- function phonetix($sIn) { if (strlen($sIn)<4 || is_numeric($sIn)) return false; @@ -276,315 +43,6 @@ class indexation { ? static::$phonetixCache[$sIn] : static::$phonetixCache[$sIn] = $this->phonetixCompute($sIn); } - - function phonetixCompute($sIn) - { - //$sIn = utf8_decode($sIn); // Selon votre implémentation, vous aurez besoin de décoder ce qui arrive pour les caractères spéciaux - $sIn = strtr( $sIn, $this->accents); // minuscules accentuées ou composées en majuscules simples - $sIn = strtr( $sIn, $this->min2maj); // majuscules accentuées ou composées en majuscules simples - $sIn = strtoupper( $sIn ); // on passe tout le reste en majuscules - $sIn = preg_replace( '`[^A-Z]`', '', $sIn ); // on garde uniquement les lettres de A à Z - - $sBack=$sIn; // on sauve le code (utilisé pour les mots très courts) - - $sIn = preg_replace( '`O[O]+`', 'OU', $sIn ); // pré traitement OO... -> OU - $sIn = str_replace( 'SAOU', 'SOU', $sIn ); // pré traitement SAOU -> SOU - $sIn = str_replace( 'OES', 'OS', $sIn ); // pré traitement OES -> OS - $sIn = str_replace( 'CCH', 'K', $sIn ); // pré traitement CCH -> K - $sIn = preg_replace( '`CC([IYE])`', 'KS$1', $sIn ); // CCI CCY CCE - $sIn = preg_replace( '`(.)\1`', '$1', $sIn ); // supression des répétitions - - // quelques cas particuliers - if ($sIn=="CD") return($sIn); - if ($sIn=="BD") return($sIn); - if ($sIn=="BV") return($sIn); - if ($sIn=="TABAC") return("TABA"); - if ($sIn=="FEU") return("FE"); - if ($sIn=="FE") return($sIn); - if ($sIn=="FER") return($sIn); - if ($sIn=="FIEF") return($sIn); - if ($sIn=="FJORD") return($sIn); - if ($sIn=="GOAL") return("GOL"); - if ($sIn=="FLEAU") return("FLEO"); - if ($sIn=="HIER") return("IER"); - if ($sIn=="HEU") return("E"); - if ($sIn=="HE") return("E"); - if ($sIn=="OS") return($sIn); - if ($sIn=="RIZ") return("RI"); - if ($sIn=="RAZ") return("RA"); - - // pré-traitements - $sIn = preg_replace( '`OIN[GT]$`', 'OIN', $sIn ); // terminaisons OING -> OIN - $sIn = preg_replace( '`E[RS]$`', 'E', $sIn ); // supression des terminaisons infinitifs et participes pluriels - $sIn = preg_replace( '`(C|CH)OEU`', 'KE', $sIn ); // pré traitement OEU -> EU - $sIn = str_replace( 'MOEU', 'ME', $sIn ); // pré traitement OEU -> EU - $sIn = preg_replace( '`OE([UI]+)([BCDFGHJKLMNPQRSTVWXZ])`', 'E$1$2', $sIn ); // pré traitement OEU OEI -> E - $sIn = preg_replace( '`^GEN[TS]$`', 'JAN', $sIn ); // pré traitement GEN -> JAN - $sIn = str_replace( 'CUEI', 'KEI', $sIn ); // pré traitement accueil - $sIn = preg_replace( '`([^AEIOUYC])AE([BCDFGHJKLMNPQRSTVWXZ])`', '$1E$2', $sIn ); // pré traitement AE -> E - $sIn = preg_replace( '`AE([QS])`', 'E$1', $sIn ); // pré traitement AE -> E - $sIn = preg_replace( '`AIE([BCDFGJKLMNPQRSTVWXZ])`', 'AI$1', $sIn ); // pré-traitement AIE(consonne) -> AI - $sIn = str_replace( 'ANIEM', 'ANIM', $sIn ); // pré traitement NIEM -> NIM - $sIn = preg_replace( '`(DRA|TRO|IRO)P$`', '$1', $sIn ); // P terminal muet - $sIn = preg_replace( '`(LOM)B$`', '$1', $sIn ); // B terminal muet - $sIn = preg_replace( '`(RON|POR)C$`', '$1', $sIn ); // C terminal muet - $sIn = preg_replace( '`PECT$`', 'PET', $sIn ); // C terminal muet - $sIn = preg_replace( '`ECUL$`', 'CU', $sIn ); // L terminal muet - $sIn = preg_replace( '`(CHA|CA|E)M(P|PS)$`', '$1N', $sIn ); // P ou PS terminal muet - $sIn = preg_replace( '`(TAN|RAN)G$`', '$1', $sIn ); // G terminal muet - - - // sons YEUX - $sIn = preg_replace( '`([^VO])ILAG`', '$1IAJ', $sIn ); - $sIn = preg_replace( '`([^TRH])UIL(AR|E)(.+)`', '$1UI$2$3', $sIn ); - $sIn = preg_replace( '`([G])UIL([AEO])`', '$1UI$2', $sIn ); - $sIn = preg_replace( '`([NSPM])AIL([AEO])`', '$1AI$2', $sIn ); - $convMIn = array('DILAI','DILON','DILER','DILEM','RILON','TAILE','GAILET','AILAI','AILAR', - 'OUILA','EILAI','EILAR','EILER','EILEM','REILET','EILET','AILOL' ); - $convMOut = array( 'DIAI', 'DION','DIER', 'DIEM', 'RION', 'TAIE', 'GAIET', 'AIAI', 'AIAR', - 'OUIA', 'AIAI', 'AIAR', 'AIER', 'AIEM', 'RAIET', 'EIET', 'AIOL' ); - $sIn = str_replace( $convMIn, $convMOut, $sIn ); - $sIn = preg_replace( '`([^AEIOUY])(SC|S)IEM([EA])`', '$1$2IAM$3', $sIn ); // IEM -> IAM - $sIn = preg_replace( '`^(SC|S)IEM([EA])`', '$1IAM$2', $sIn ); // IEM -> IAM - - // MP MB -> NP NB - $convMIn = array( 'OMB', 'AMB', 'OMP', 'AMP', 'IMB', 'EMP','GEMB','EMB', 'UMBL','CIEN'); - $convMOut = array( 'ONB', 'ANB', 'ONP', 'ANP', 'INB', 'ANP','JANB','ANB', 'INBL','SIAN'); - $sIn = str_replace( $convMIn, $convMOut, $sIn ); - - // Sons en K - $sIn = preg_replace( '`^ECHO$`', 'EKO', $sIn ); // cas particulier écho - $sIn = preg_replace( '`^ECEUR`', 'EKEUR', $sIn ); // cas particulier écÅ“uré - // Choléra ChÅ“ur mais pas chocolat! - $sIn = preg_replace( '`^CH(OG+|OL+|OR+|EU+|ARIS|M+|IRO|ONDR)`', 'K$1', $sIn ); //En début de mot - $sIn = preg_replace( '`(YN|RI)CH(OG+|OL+|OC+|OP+|OM+|ARIS|M+|IRO|ONDR)`', '$1K$2', $sIn ); //Ou devant une consonne - $sIn = preg_replace( '`CHS`', 'CH', $sIn ); - $sIn = preg_replace( '`CH(AIQ)`', 'K$1', $sIn ); - $sIn = preg_replace( '`^ECHO([^UIPY])`', 'EKO$1', $sIn ); - $sIn = preg_replace( '`ISCH(I|E)`', 'ISK$1', $sIn ); - $sIn = preg_replace( '`^ICHT`', 'IKT', $sIn ); - $sIn = preg_replace( '`ORCHID`', 'ORKID', $sIn ); - $sIn = preg_replace( '`ONCHIO`', 'ONKIO', $sIn ); - $sIn = preg_replace( '`ACHIA`', 'AKIA', $sIn ); // retouche ACHIA -> AKIA - $sIn = preg_replace( '`([^C])ANICH`', '$1ANIK', $sIn ); // ANICH -> ANIK 1/2 - $sIn = preg_replace( '`OMANIK`', 'OMANICH', $sIn ); // cas particulier 2/2 - $sIn = preg_replace( '`ACHY([^D])`', 'AKI$1', $sIn ); - $sIn = preg_replace( '`([AEIOU])C([BDFGJKLMNPQRTVWXZ])`', '$1K$2', $sIn ); // voyelle, C, consonne sauf H - $convPrIn = array('EUCHA','YCHIA','YCHA','YCHO','YCHED','ACHEO','RCHEO','RCHES', - 'ECHN','OCHTO','CHORA','CHONDR','CHORE','MACHM','BRONCHO','LICHOS','LICHOC'); - $convPrOut = array('EKA', 'IKIA', 'IKA', 'IKO', 'IKED','AKEO','RKEO', 'RKES', - 'EKN', 'OKTO', 'KORA', 'KONDR' ,'KORE' ,'MAKM', 'BRONKO', 'LIKOS', 'LIKOC'); - $sIn = str_replace( $convPrIn, $convPrOut, $sIn ); - - // Weuh (perfectible) - $convPrIn = array( 'WA','WO', 'WI','WHI','WHY','WHA','WHO'); - $convPrOut = array( 'OI', 'O','OUI','OUI','OUI','OUA', 'OU'); - $sIn = str_replace( $convPrIn, $convPrOut, $sIn ); - - // Gueu, Gneu, Jeu et quelques autres - $convPrIn = array( 'GNES','GNET','GNER','GNE', 'GI', 'GNI','GNA','GNOU','GNUR','GY','OUGAIN', - 'AGEOL', 'AGEOT','GEOLO','GEOM','GEOP','GEOG','GEOS','GEORG','GEOR','NGEOT','UGEOT','GEOT','GEOD','GEOC','GEO','GEA','GE', - 'QU', 'Q', 'CY', 'CI', 'CN','ICM','CEAT','CE', - 'CR', 'CO', 'CUEI','CU', 'VENCA','CA', 'CS','CLEN','CL', 'CZ', 'CTIQ', - 'CTIF','CTIC','CTIS','CTIL','CTIO','CTI', 'CTU', 'CTE','CTO','CTR','CT', 'PH', 'TH', - 'OW', 'LH', 'RDL', 'CHLO', 'CHR', 'PTIA'); - $convPrOut = array( 'NIES','NIET','NIER', 'NE', 'JI', 'NI','NIA','NIOU','NIUR','JI','OUGIN', - 'AJOL', 'AJOT','JEOLO','JEOM','JEOP','JEOG','JEOS','JORJ','JEOR','NJOT','UJOT','JEOT','JEOD','JEOC', 'JO','JA' ,'JE', - 'K', 'K', 'SI', 'SI', 'KN','IKM', 'SAT','SE', - 'KR', 'KO', 'KEI','KU', 'VANSA','KA', 'KS','KLAN','KL', 'KZ', 'KTIK', - 'KTIF','KTIS','KTIS','KTIL','KSIO','KTI', 'KTU', 'KTE','KTO','KTR','KT', 'F', 'T', - 'OU', 'L', 'RL', 'KLO', 'KR', 'PSIA'); - $sIn = str_replace( $convPrIn, $convPrOut, $sIn ); - - $sIn = preg_replace( '`GU([^RLMBSTPZN])`', 'G$1', $sIn ); // Gueu ! - $sIn = preg_replace( '`GNO([MLTNRKG])`', 'NIO$1', $sIn ); // GNO ! Tout sauf S pour gnos - $sIn = preg_replace( '`GNO([MLTNRKG])`', 'NIO$1', $sIn ); // bis -> gnognotte! Si quelqu'un sait le faire en une seule regexp... - - - // TI -> SI v2.0 - $convPrIn = array( 'BUTIE','BUTIA','BATIA','ANTIEL','RETION','ENTIEL','ENTIAL','ENTIO','ENTIAI','UJETION','ATIEM','PETIEN', - 'CETIE','OFETIE','IPETI','LBUTION','BLUTION','LETION','LATION','SATIET'); - $convPrOut = array( 'BUSIE','BUSIA','BASIA','ANSIEL','RESION','ENSIEL','ENSIAL','ENSIO','ENSIAI','UJESION','ASIAM','PESIEN', - 'CESIE','OFESIE','IPESI','LBUSION','BLUSION','LESION','LASION','SASIET'); - $sIn = str_replace( $convPrIn, $convPrOut, $sIn ); - $sIn = preg_replace( '`(.+)ANTI(AL|O)`', '$1ANSI$2', $sIn ); // sauf antialcoolique, antialbumine, antialarmer, ... - $sIn = preg_replace( '`(.+)INUTI([^V])`', '$1INUSI$2', $sIn ); // sauf inutilité, inutilement, diminutive, ... - $sIn = preg_replace( '`([^O])UTIEN`', '$1USIEN', $sIn ); // sauf soutien, ... - $sIn = preg_replace( '`([^DE])RATI[E]$`', '$1RASI$2', $sIn ); // sauf xxxxxcratique, ... - // TIEN TION -> SIEN SION v3.1 - $sIn = preg_replace( '`([^SNEU]|KU|KO|RU|LU|BU|TU|AU)T(IEN|ION)`', '$1S$2', $sIn ); - - - // H muet - $sIn = preg_replace( '`([^CS])H`', '$1', $sIn ); // H muet - $sIn = str_replace( 'ESH', 'ES', $sIn ); // H muet - $sIn = str_replace( 'NSH', 'NS', $sIn ); // H muet - $sIn = str_replace( 'SH', 'CH', $sIn ); // ou pas! - - // NASALES - $convNasIn = array( 'OMT','IMB', 'IMP','UMD','TIENT','RIENT','DIENT','IEN', - 'YMU','YMO','YMA','YME', 'YMI','YMN','YM', 'AHO','FAIM','DAIM','SAIM','EIN','AINS'); - $convNasOut = array( 'ONT','INB', 'INP','OND','TIANT','RIANT','DIANT', 'IN', - 'IMU','IMO','IMA','IME', 'IMI','IMN','IN', 'AO', 'FIN','DIN', 'SIN','AIN','INS'); - $sIn = str_replace( $convNasIn, $convNasOut, $sIn ); - // AIN -> IN v2.0 - $sIn = preg_replace( '`AIN$`', 'IN', $sIn ); - $sIn = preg_replace( '`AIN([BTDK])`', 'IN$1', $sIn ); - // UN -> IN - $sIn = preg_replace( '`([^O])UND`', '$1IND', $sIn ); // aucun mot français ne commence par UND! - $sIn = preg_replace( '`([JTVLFMRPSBD])UN([^IAE])`', '$1IN$2', $sIn ); - $sIn = preg_replace( '`([JTVLFMRPSBD])UN$`', '$1IN', $sIn ); - $sIn = preg_replace( '`RFUM$`', 'RFIN', $sIn ); - $sIn = str_replace( 'LUMB', 'LINB', $sIn ); - // EN -> AN - $sIn = preg_replace( '`([^BCDFGHJKLMNPQRSTVWXZ])EN`', '$1AN', $sIn ); - $sIn = preg_replace( '`([VTLJMRPDSBFKNG])EN([BRCTDKZSVN])`', '$1AN$2', $sIn ); // deux fois pour les motifs recouvrants malentendu, pendentif, ... - $sIn = preg_replace( '`([VTLJMRPDSBFKNG])EN([BRCTDKZSVN])`', '$1AN$2', $sIn ); // si quelqu'un sait faire avec une seule regexp! - $sIn = preg_replace( '`^EN([BCDFGHJKLNPQRSTVXZ]|CH|IV|ORG|OB|UI|UA|UY)`', 'AN$1', $sIn ); - $sIn = preg_replace( '`(^[JRVTH])EN([DRTFGSVJMP])`', '$1AN$2', $sIn ); - $sIn = preg_replace( '`SEN([ST])`', 'SAN$1', $sIn ); - $sIn = preg_replace( '`^DESENIV`', 'DESANIV', $sIn ); - $sIn = preg_replace( '`([^M])EN(UI)`', '$1AN$2', $sIn ); - $sIn = preg_replace( '`(.+[JTVLFMRPSBD])EN([JLFDSTG])`', '$1AN$2', $sIn ); - // EI -> AI - $sIn = preg_replace( '`([VSBSTNRLPM])E[IY]([ACDFRJLGZ])`', '$1AI$2', $sIn ); - - // Histoire d'Ô - $convNasIn = array( 'EAU', 'EU', 'Y', 'EOI', 'JEA','OIEM','OUANJ','OUA','OUENJ'); - $convNasOut = array( 'O', 'E', 'I', 'OI', 'JA' ,'OIM' ,'OUENJ', 'OI','OUANJ'); - $sIn = str_replace( $convNasIn, $convNasOut, $sIn ); - $sIn = preg_replace( '`AU([^E])`', 'O$1', $sIn ); // AU sans E qui suit - - // Les retouches! - $sIn = preg_replace( '`^BENJ`', 'BINJ', $sIn ); // retouche BENJ -> BINJ - $sIn = str_replace( 'RTIEL', 'RSIEL', $sIn ); // retouche RTIEL -> RSIEL - $sIn = str_replace( 'PINK', 'PONK', $sIn ); // retouche PINK -> PONK - $sIn = str_replace( 'KIND', 'KOND', $sIn ); // retouche KIND -> KOND - $sIn = preg_replace( '`KUM(N|P)`', 'KON$1', $sIn ); // retouche KUMN KUMP - $sIn = str_replace( 'LKOU', 'LKO', $sIn ); // retouche LKOU -> LKO - $sIn = str_replace( 'EDBE', 'EBE', $sIn ); // retouche EDBE pied-bÅ“uf - $sIn = str_replace( 'ARCM', 'ARKM', $sIn ); // retouche SCH -> CH - $sIn = str_replace( 'SCH', 'CH', $sIn ); // retouche SCH -> CH - $sIn = preg_replace( '`^OINI`', 'ONI', $sIn ); // retouche début OINI -> ONI - $sIn = preg_replace( '`([^NDCGRHKO])APT`', '$1AT', $sIn ); // retouche APT -> AT - $sIn = preg_replace( '`([L]|KON)PT`', '$1T', $sIn ); // retouche LPT -> LT - $sIn = str_replace( 'OTB', 'OB', $sIn ); // retouche OTB -> OB (hautbois) - $sIn = str_replace( 'IXA', 'ISA', $sIn ); // retouche IXA -> ISA - $sIn = str_replace( 'TG', 'G', $sIn ); // retouche TG -> G - $sIn = preg_replace( '`^TZ`', 'TS', $sIn ); // retouche début TZ -> TS - $sIn = str_replace( 'PTIE', 'TIE', $sIn ); // retouche PTIE -> TIE - $sIn = str_replace( 'GT', 'T', $sIn ); // retouche GT -> T - $sIn = str_replace( 'ANKIEM', 'ANKILEM', $sIn ); // retouche tranquillement - $sIn = preg_replace( "`(LO|RE)KEMAN`", "$1KAMAN", $sIn ); // KEMAN -> KAMAN - $sIn = preg_replace( '`NT(B|M)`', 'N$1', $sIn ); // retouche TB -> B TM -> M - $sIn = str_replace( 'GSU', 'SU', $sIn ); // retouche GS -> SU - $sIn = str_replace( 'ESD', 'ED', $sIn ); // retouche ESD -> ED - $sIn = str_replace( 'LESKEL', 'LEKEL', $sIn ); // retouche LESQUEL -> LEKEL - $sIn = str_replace( 'CK', 'K', $sIn ); // retouche CK -> K - - // Terminaisons - $sIn = preg_replace( '`USIL$`', 'USI', $sIn ); // terminaisons USIL -> USI - $sIn = preg_replace( '`X$|[TD]S$|[DS]$`', '', $sIn ); // terminaisons TS DS LS X T D S... v2.0 - $sIn = preg_replace( '`([^KL]+)T$`', '$1', $sIn ); // sauf KT LT terminal - $sIn = preg_replace( '`^[H]`', '', $sIn ); // H pseudo muet en début de mot, je sais, ce n'est pas une terminaison - $sBack2=$sIn; // on sauve le code (utilisé pour les mots très courts) - - $convPartIn = [ - '`TIL$`', // terminaisons TIL -> TI - '`LC$`', // terminaisons LC -> LK - '`L[E]?[S]?$`', // terminaisons LE LES -> L - '`(.+)N[E]?[S]?$`', // terminaisons NE NES -> N - '`EZ$`', // terminaisons EZ -> E - '`OIG$`', // terminaisons OIG -> OI - '`OUP$`', // terminaisons OUP -> OU - '`([^R])OM$`', // terminaisons OM -> ON sauf ROM - '`LOP$`', // terminaisons LOP -> LO - '`NTANP$`', // terminaisons NTANP -> NTAN - '`TUN$`', // terminaisons TUN -> TIN - '`AU$`', // terminaisons AU -> O - '`EI$`', // terminaisons EI -> AI - '`R[DG]$`', // terminaisons RD RG -> R - '`ANC$`', // terminaisons ANC -> AN - '`KROC$`', // terminaisons C muet de CROC, ESCROC - '`HOUC$`', // terminaisons C muet de CAOUTCHOUC - '`OMAC$`', // terminaisons C muet de ESTOMAC (mais pas HAMAC) - '`([J])O([NU])[CG]$`',// terminaisons C et G muet de OUC ONC OUG - '`([^GTR])([AO])NG$`',// terminaisons G muet ANG ONG sauf GANG GONG TANG TONG - '`UC$`', // terminaisons UC -> UK - '`AING$`', // terminaisons AING -> IN - '`([EISOARN])C$`', // terminaisons C -> K - '`([ABD-MO-Z]+)[EH]+$`', // terminaisons E ou H sauf pour C et N - '`EN$`', // terminaisons EN -> AN (difficile à faire avant sans avoir des soucis) Et encore, - '`(NJ)EN$`',// terminaisons EN -> AN - '`^PAIEM`', // PAIE -> PAI - '`([^NTB])EF$`', // F muet en fin de mot - '`(.)\1`' // supression des répétitions (suite à certains remplacements) - ]; - - $convPartOut = [ - 'TI', // terminaisons TIL -> TI - 'LK', // terminaisons LC -> LK - 'L', // terminaisons LE LES -> L - '$1N', // terminaisons NE NES -> N - 'E', // terminaisons EZ -> E - 'OI', // terminaisons OIG -> OI - 'OU', // terminaisons OUP -> OU - '$1ON', // terminaisons OM -> ON sauf ROM - 'LO', // terminaisons LOP -> LO - 'NTAN', // terminaisons NTANP -> NTAN - 'TIN', // terminaisons TUN -> TIN - 'O', // terminaisons AU -> O - 'AI', // terminaisons EI -> AI - 'R', // terminaisons RD RG -> R - 'AN', // terminaisons ANC -> AN - 'KRO', // terminaisons C muet de CROC, ESCROC - 'HOU', // terminaisons C muet de CAOUTCHOUC - 'OMA', // terminaisons C muet de ESTOMAC (mais pas HAMAC) - '$1O$2',// terminaisons C et G muet de OUC ONC OUG - '$1$2N',// terminaisons G muet ANG ONG sauf GANG GONG TANG TONG - 'UK', // terminaisons UC -> UK - 'IN', // terminaisons AING -> IN - '$1K', // terminaisons C -> K - '$1', // terminaisons E ou H sauf pour C et N - 'AN', // terminaisons EN -> AN (difficile à faire avant sans avoir des soucis) Et encore, c'est pas top! - '$1AN', // terminaisons EN -> AN - 'PAIM', // PAIE -> PAI - '\1', // F muet en fin de mot - '$1' // supression des répétitions (suite à certains remplacements) - ]; - - $sIn = preg_replace( $convPartIn, $convPartOut, $sIn ); - - // cas particuliers, bah au final, je n'en ai qu'un ici - $convPartIn = array( 'FUEL'); - $convPartOut = array( 'FIOUL'); - $sIn = str_replace( $convPartIn, $convPartOut, $sIn ); - - // Ce sera le seul code retourné à une seule lettre! - if ($sIn=='O') return($sIn); - - // seconde chance sur les mots courts qui ont souffert de la simplification - if (strlen($sIn)<2) - { - // Sigles ou abréviations - if (preg_match("`[BCDFGHJKLMNPQRSTVWXYZ][BCDFGHJKLMNPQRSTVWXYZ][BCDFGHJKLMNPQRSTVWXYZ][BCDFGHJKLMNPQRSTVWXYZ]*`",$sBack)) - return($sBack); - - if (preg_match("`[RFMLVSPJDF][AEIOU]`",$sBack)) - { - if (strlen($sBack)==3) - return(substr($sBack,0,2));// mots de trois lettres supposés simples - if (strlen($sBack)==4) - return(substr($sBack,0,3));// mots de quatre lettres supposés simples - } - - if (strlen($sBack2)>1) return $sBack2; - } - if (strlen($sIn)>1) - { - return substr($sIn,0,16); // Je limite à 16 caractères mais vous faites comme vous voulez! - } - else return ''; - } } + ?> \ No newline at end of file diff --git a/cosmogramme/php/classes/classe_profil_donnees.php b/cosmogramme/php/classes/classe_profil_donnees.php index 776106b2bf0988c06ad701515a35c4deb3e40b2e..0a0511d6fad0b7f87fb54173f902861dc8c9090e 100644 --- a/cosmogramme/php/classes/classe_profil_donnees.php +++ b/cosmogramme/php/classes/classe_profil_donnees.php @@ -24,6 +24,10 @@ class profil_donnees { HOMOGENIZATION_ISBN = -1, HOMOGENIZATION_EAN = -2; + protected static + $_profil_cache = [], + $_type_docs_cache = null; + private $id_profil; // Id sgbd private $libelle; // Libellé du profil private $rejet_periodiques; // Rejet des periodiques dans les imports @@ -33,9 +37,35 @@ class profil_donnees { private $format; // Format du fichier à parser (variable import_format) private $attributs; // Bloc de donnees associe au format + protected $_to_array=[]; //legacy refactoring @see getProfil + + + public static function clearCache() { + static::$_profil_cache = []; + static::$_type_docs_cache = null; + } + + public static function find($id_profil) { + if (isset(static::$_profil_cache[$id_profil])) + return static::$_profil_cache[$id_profil]; + + $profil = new static(); + $profil->lire($id_profil); + + return static::$_profil_cache[$profil->getId()] = $profil; + } + + + public function getId() { + return $this->id_profil; + } + public function lire($id_profil) { - $all_type_docs = Class_TypeDoc::findAll(); + if (!static::$_type_docs_cache) + static::$_type_docs_cache = Class_TypeDoc::findAll(); + + $all_type_docs = static::$_type_docs_cache; // Profils d'homogeneisation : -1= isbn -2=ean if ($id_profil < 0) { @@ -104,9 +134,7 @@ class profil_donnees { return $this->id_profil; } - - public function getProfil($id_profil) { - $this->lire($id_profil); + public function toArray() { $profil["id_profil"]=$this->id_profil; $profil["libelle"]=$this->libelle; $profil["accents"]=$this->accents; @@ -123,6 +151,10 @@ class profil_donnees { return $profil; } + public function getProfil($id_profil) { + return static::find($id_profil)->toArray(); + } + /** * Profils standard réhomogénéisations : -1: panier d'isbn -2:panier d'ean diff --git a/cosmogramme/php/classes/classe_unimarc.php b/cosmogramme/php/classes/classe_unimarc.php index 35f82a9edbb01d13e563f87c6f9317bc7ba18734..7d1d7bc364e0cfc1625abbe9febf79b3ce05c387 100644 --- a/cosmogramme/php/classes/classe_unimarc.php +++ b/cosmogramme/php/classes/classe_unimarc.php @@ -68,12 +68,16 @@ class notice_unimarc extends iso2709_record { $this->sigb = $sigb; $this->id_profil = $id_profil; + if($this->id_profil == 0) { - $this->profil = $this->profil_unimarc->getProfil(1); + $this->profil_unimarc = profil_donnees::find(1); + $this->profil = $this->profil_unimarc->lire(1); $this->profil['accents'] = 0; } - else + else { + $this->profil_unimarc = profil_donnees::find($this->id_profil); $this->profil = $this->profil_unimarc->getProfil($this->id_profil); + } if (!$decode_string) { $this->profil['accents'] = 0; diff --git a/cosmogramme/php/integre_traite_main.php b/cosmogramme/php/integre_traite_main.php index a3b39a51c5b8bb6d881523f66df05f6f36db4266..7290931981942fc9d275970b186a5dea78d59dbf 100644 --- a/cosmogramme/php/integre_traite_main.php +++ b/cosmogramme/php/integre_traite_main.php @@ -618,7 +618,7 @@ $log->close(); $log_erreur->close(); $log_warning->close(); print(BR . BR . '</body></html>'); -exit; + // ---------------------------------------------------------------- // Ecriture logs et affichage écran diff --git a/cosmogramme/php/profile_integration.php b/cosmogramme/php/profile_integration.php new file mode 100644 index 0000000000000000000000000000000000000000..edc4ec8f29d0b514b3160e764d22146d5e6c0ce1 --- /dev/null +++ b/cosmogramme/php/profile_integration.php @@ -0,0 +1,15 @@ +<?php + +xhprof_enable(); +require('integre_traite_main.php'); + +$xhprof_data = xhprof_disable(); + +require_once "xhprof/xhprof_lib/utils/xhprof_lib.php"; +require_once "xhprof/xhprof_lib/utils/xhprof_runs.php"; + +$xhprof_runs = new XHProfRuns_Default(); +$run_id = $xhprof_runs->save_run($xhprof_data, "cosmogramme"); +echo "View profiling data at: /xhprof/xhprof_html/index.php?run={$run_id}&source=cosmogramme\n"; + +?> \ No newline at end of file diff --git a/cosmogramme/tests/php/classes/IndexationTest.php b/cosmogramme/tests/php/classes/IndexationTest.php index 9ac54ff6bf2af1ac09e3bda5574dba15b8f882ff..e372e4eca11432e5ad4d7164fb72e672b83d47e9 100644 --- a/cosmogramme/tests/php/classes/IndexationTest.php +++ b/cosmogramme/tests/php/classes/IndexationTest.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ require_once 'classe_indexation.php'; @@ -29,7 +29,7 @@ class IndexationTranformationsTest extends PHPUnit_Framework_TestCase { public function phonetix() { - return [ + return [ ['choux', 'CHOU'], ['escroc', 'ESKRO'], ['paix', 'PAI'], @@ -51,10 +51,11 @@ class IndexationTranformationsTest extends PHPUnit_Framework_TestCase { public function alphamaj() { - return [ - ['choux', 'CHOUX'], - ['escroc', 'ESCROC'], - ['l\'été', 'L ETE'] + return [ + ['choux', 'CHOUX'], + ['escroc', 'ESCROC'], + ['l\'été', 'L ETE'], + ['Guitton, Pierre', 'GUITTON PIERRE'] ]; } @@ -69,4 +70,3 @@ class IndexationTranformationsTest extends PHPUnit_Framework_TestCase { } ?> - diff --git a/cosmogramme/tests/php/classes/NoticeIntegrationTest.php b/cosmogramme/tests/php/classes/NoticeIntegrationTest.php index ec65b9b556dfe2d8821ab75070a2f7ce3f905f00..e0d2510f376e5171cc3bf84509a44afcc8829f71 100644 --- a/cosmogramme/tests/php/classes/NoticeIntegrationTest.php +++ b/cosmogramme/tests/php/classes/NoticeIntegrationTest.php @@ -65,6 +65,7 @@ abstract class NoticeIntegrationTestCase extends ModelTestCase { global $sql; $sql = $this->_mock_sql = Storm_Test_ObjectWrapper::mock(); + profil_donnees::clearCache(); $this->_mock_sql ->whenCalled('execute')->answers(true) diff --git a/library/Class/Indexation.php b/library/Class/Indexation.php index 65a27098db2c272fc25a9020cbdb98a529d4c571..3d04ab532c408cf2ac11f3876020f438054c71a6 100644 --- a/library/Class/Indexation.php +++ b/library/Class/Indexation.php @@ -1,4 +1,4 @@ -<?PHP +<?php /** * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. * @@ -18,19 +18,28 @@ * along with BOKEH; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -//////////////////////////////////////////////////////////////////////// -// OPAC3 : CALCUL DES INDEX -/////////////////////////////////////////////////////////////////////// - class Class_Indexation { - protected static $_instance; + protected static + $_instance, + $_alpha_maj_cache = []; private $articles; // Articles rejetes private $inclu; // Mots inclus private $exclu; // Mots vides private $pluriel; // Règles des pluriels - private $tableMaj; // Table de transco pour majuscules + private $tableMajFrom, $tableMajTo = []; // Table de transco pour majuscules + private $tableMajUtf8; // Table de transco pour majuscules accentuées utf8 + + private $accents = ['É' => 'E', 'È' => 'E', 'Ë' => 'E', 'Ê' => 'E','Ã' => 'A', 'À' => 'A', 'Ä' => 'A', 'Â' => 'A', + 'Ã…' => 'A', 'Ã' => 'A', 'Æ' => 'E','Ã' => 'I', 'ÃŽ' => 'I', 'ÃŒ' => 'I', 'Ã' => 'I', + 'Ô' => 'O', 'Ö' => 'O', 'Ã’' => 'O', 'Ó' => 'O', 'Õ' => 'O', 'Ø' => 'O', 'Å’' => 'OEU', + 'Ú' => 'U', 'Ù' => 'U', 'Û' => 'U', 'Ãœ' => 'U','Ñ' => 'N', 'Ç' => 'S', '¿' => 'E']; + + private $min2maj = ['é' => 'É', 'è' => 'È', 'ë' => 'Ë', 'ê' => 'Ê','á' => 'Ã', 'â' => 'Â', 'à ' => 'À', 'Ä' => 'A', + 'Â' => 'A', 'Ã¥' => 'Ã…', 'ã' => 'Ã', 'æ' => 'Æ', 'ï' => 'Ã', 'î' => 'ÃŽ', 'ì' => 'ÃŒ', 'Ã' => 'Ã', + 'ô' => 'Ô', 'ö' => 'Ö', 'ò' => 'Ã’', 'ó' => 'Ó','õ' => 'Õ', 'ø' => 'Ø', 'Å“' => 'Å’', + 'ú' => 'Ú', 'ù' => 'Ù', 'û' => 'Û', 'ü' => 'Ãœ','ç' => 'Ç', 'ñ' => 'Ñ', 'ß' => 'S']; public static function getInstance() { @@ -39,324 +48,282 @@ class Class_Indexation { return static::$_instance; } - public function __construct() { + + function __construct() { // Lire formes rejetées - $this->articles=array("L'","LE ","LA ","LES ","UN ","UNE "); - $this->inclu=array("AN","AS","OR","U2","AI","LU","XO","DO","RE","MI","FA","SI","AC","DC","XX","B","C","D","E","F","G","H","I","J","K","M","P","Q","R","S","T","V","W","X","Y","Z","L","YU","UT","LI","OC","PI","ZU","WU","TO","OZ","ZZ","XX"); - $this->exclu = array("L","LE","LA","LES","UN","UNE","LES","DES","MES","TES","CES"); + $this->articles=array('L\'','LE ','LA ','LES ','UN ','UNE '); + $this->inclu=array('AN','AS','OR','U2','AI','LU','XO','DO','RE','MI','FA','SI','AC','DC','XX','B','C','D','E','F','G','H','I','J','K','M','P','Q','R','S','T','V','W','X','Y','Z','L','YU','UT','LI','OC','PI','ZU','WU','TO','OZ','ZZ','XX'); + $this->exclu = array('L','LE','LA','LES','UN','UNE','LES','DES','MES','TES','CES'); // Pluriels $this->pluriel=array( - array("AIL","AULX"), - array("AVAL","AVALS"), - array("BAIL","BAUX"), - array("BAL","BALS"), - array("BANAL","BANALS"), - array("BANCAL","BANCALS"), - array("BIJOU","BIJOUX"), - array("BLEU","BLEUS"), - array("CAILLOU","CAILLOUX"), - array("CAL","CALS"), - array("CARNAVAL","CARNAVALS"), - array("CEREMONIAL","CEREMONIALS"), - array("CHACAL","CHACALS"), - array("CHORAL","CHORALS"), - array("CHOU","CHOUX"), - array("CORAIL","CORAUX"), - array("DETAIL","DETAILS"), - array("EMAIL","EMAUX"), - array("EMEU","EMEUS"), - array("ETAL","ETALS"), - array("FATAL","FATALS"), - array("FESTIVAL","FESTIVALS"), - array("GEMMAIL","GEMMAUX"), - array("GENOU","GENOUX"), - array("HIBOU","HIBOUX"), - array("JOUJOU","JOUJOUX"), - array("LANDAU","LANDAUX"), - array("NATAL","NATALS"), - array("OEIL","YEUX"), - array("PAL","PALS"), - array("PNEU","PNEUS"), - array("POU","POUX"), - array("RECITAL","RECITALS"), - array("REGAL","REGALS"), - array("SARRAU","SARRAUS"), - array("SOUPIRAIL","SOUPIRAUX"), - array("TONAL","TONALS"), - array("TRAVAIL","TRAVAUX"), - array("VAL","VALS"), - array("VENTAIL","VENTAUX"), - array("VIRGINAL","VIRGINALS"), - array("VITRAIL","VITRAUX"), - array("*EAU","*EAUX"), - array("*AL","*AUX"), - array("*EU","*EUX"), - array("*AU","*AUX") - ); + array('AIL','AULX'), + array('AVAL','AVALS'), + array('BAIL','BAUX'), + array('BAL','BALS'), + array('BANAL','BANALS'), + array('BANCAL','BANCALS'), + array('BIJOU','BIJOUX'), + array('BLEU','BLEUS'), + array('CAILLOU','CAILLOUX'), + array('CAL','CALS'), + array('CARNAVAL','CARNAVALS'), + array('CEREMONIAL','CEREMONIALS'), + array('CHACAL','CHACALS'), + array('CHORAL','CHORALS'), + array('CHOU','CHOUX'), + array('CORAIL','CORAUX'), + array('DETAIL','DETAILS'), + array('EMAIL','EMAUX'), + array('EMEU','EMEUS'), + array('ETAL','ETALS'), + array('FATAL','FATALS'), + array('FESTIVAL','FESTIVALS'), + array('GEMMAIL','GEMMAUX'), + array('GENOU','GENOUX'), + array('HIBOU','HIBOUX'), + array('JOUJOU','JOUJOUX'), + array('LANDAU','LANDAUX'), + array('NATAL','NATALS'), + array('OEIL','YEUX'), + array('PAL','PALS'), + array('PNEU','PNEUS'), + array('POU','POUX'), + array('RECITAL','RECITALS'), + array('REGAL','REGALS'), + array('SARRAU','SARRAUS'), + array('SOUPIRAIL','SOUPIRAUX'), + array('TONAL','TONALS'), + array('TRAVAIL','TRAVAUX'), + array('VAL','VALS'), + array('VENTAIL','VENTAUX'), + array('VIRGINAL','VIRGINALS'), + array('VITRAIL','VITRAUX'), + array('*EAU','*EAUX'), + array('*AL','*AUX'), + array('*EU','*EUX'), + array('*AU','*AUX') + ); // Init table ascii pour majuscules - $this->tableMaj = str_repeat( " ", 41 ) - . "* 0123456789 " - . "ABCDEFGHIJKLMNOPQRSTUVWXYZ " - . "ABCDEFGHIJKLMNOPQRSTUVWXYZ " - . str_repeat( " ", 63) - ."AAAAAAACEEEEIIII NOOOOO UUUUY AAAAAAACEEEEIIII NOOOOO UUUUY Y"; - } + $this->tableMajTo = str_split(str_repeat( ' ', 42 ) + . '* 0123456789 ' + . 'ABCDEFGHIJKLMNOPQRSTUVWXYZ ' + . 'ABCDEFGHIJKLMNOPQRSTUVWXYZ ' + . str_repeat( ' ', 63) + .'AAAAAAACEEEEIIII NOOOOO UUUUY AAAAAAACEEEEIIII NOOOOO UUUUY Y'); - public function getClefAlpha($type_doc, $titre, $complement_titre, $auteur, $tome, $editeur, $annee) { - $clef = $this->getClefOeuvre($titre, $complement_titre, $auteur, $tome) . '-'; - $clef .= substr($this->alphaMaj(str_replace(' ', '', $editeur)), 0, 80) . '-'; - $clef .= $annee . '-'; - $clef .= $type_doc; - return str_replace(' ', '', $clef); - } + for($i=0; $i<count($this->tableMajTo); $i++) + $this->tableMajFrom[] = chr($i); - public function getClefOeuvre($titre, $complement_titre, $auteur, $tome) { - $clef = substr($this->codeAlphaTitre(strtoupper(str_replace(" ","",$titre))),0,80)."-"; - $clef .= substr($this->codeAlphaTitre(strtoupper(str_replace(" ","",$complement_titre))),0,20)."-"; - $clef .= substr($this->alphaMaj(str_replace(' ', '',$auteur)),0,80) . "-"; - $clef .= $this->alphaMaj($tome); - $clef = str_replace(' ', '', $clef); - return $clef; + $this->tableMajUtf8=array(chr(0xC9) => 'E', 'È' => 'E', 'Ë' => 'E', 'Ê' => 'E','Ã' => 'A', 'À' => 'A', 'Ä' => 'A', 'Â' => 'A', + 'Ã…' => 'A', 'Ã' => 'A', 'Æ' => 'E','Ã' => 'I', 'ÃŽ' => 'I', 'ÃŒ' => 'I', 'Ã' => 'I', + 'Ô' => 'O', 'Ö' => 'O', 'Ã’' => 'O', 'Ó' => 'O', 'Õ' => 'O', 'Ø' => 'O', 'Å’' => 'OEU', + 'Ú' => 'U', 'Ù' => 'U', 'Û' => 'U', 'Ãœ' => 'U','Ñ' => 'N', 'Ç' => 'S', '¿' => 'E'); } - - // Indexation d'un titre - public function codeAlphaTitre($titre) { - $titre = $this->alphaMaj($titre); - foreach($this->articles as $article) { - $lg = strlen($article); - if (strLeft($titre, $lg)==$article) { - $titre = strMid($titre,$lg,256); - break; + public function codeAlphaTitre($titre) + { + $titre=$this->alphaMaj($titre); + foreach($this->articles as $article) + { + $lg=strlen($article); + if(strLeft($titre, $lg)==$article) {$titre=strMid($titre,$lg,256); break;} } - } $titre=$this->alphaMaj($titre); return $titre; } - /** Rend une suite de mots complete pour les formes plurielles */ + // Rend une suite de mots complete pour les formes plurielles public function getExpressionRecherche($mot) { - $mot = trim($mot); - if (!$mot) + if (!$mot=trim($mot)) return false; // Pluriel $etoile = ''; - if (strRight($mot,1) == "*") { - $etoile = "*"; - $mot = strLeft($mot, strlen($mot)-1); + if(strRight($mot,1) == '*') { + $etoile='*'; + $mot=strLeft($mot, strlen($mot)-1); } $m = $this->getPluriel($mot); $m[2] = $this->phonetix($m[0]); - $ret = "(" . $m[0] . $etoile . " " . $m[1] . " " . $m[2] . ")"; - return trim($ret); + return trim('('.$m[0].$etoile.' '.$m[1].' '.$m[2].')'); } - /** Transformation en majuscules */ - public function alphaMaj($chaine) { - $chaine = utf8_decode($chaine); - $new = ''; - for ($i=0; $i < strLen($chaine); $i++) { - $car = $chaine[$i]; - $ascii = ord($car); - $car = $this->tableMaj[$ascii -1]; - $new = $new . $car; - } - return trim($new); + + public function alphaMaj( $chaine ) { + if (isset(static::$_alpha_maj_cache[$chaine])) + return static::$_alpha_maj_cache[$chaine]; + + return static::$_alpha_maj_cache[$chaine] = trim(str_replace($this->tableMajFrom, + $this->tableMajTo, + utf8_decode($chaine))); } - /** Remet les articles entre parenthèses au début du titre */ - public function setArticleDebut($titre) { - if (substr($titre, -1) != ')') - return $titre; - - foreach($this->articles as $article) { - $compare = '(' . trim($article) . ')'; - $lg = strlen($compare); - if (strtoUpper(substr($titre,-$lg))==$compare) { - $deb = substr($titre, -$lg); - $deb = str_replace("(", "", $article); - $deb = str_replace(")", "", $article); - if (substr($deb,-1) != "'") - $deb .= " "; - $new = $deb.trim(substr($titre, 0, (strlen($titre) - $lg))); - - return $new; - } - } - return $titre; + + public function getClefAlpha($type_doc,$titre,$complement_titre,$auteur,$tome,$editeur,$annee) + { + $clef=$this->getClefOeuvre($titre,$complement_titre,$auteur,$tome).'-'; + $clef.=substr($this->alphaMaj(str_replace(' ','',$editeur)),0,80).'-'; + $clef.=$annee.'-'; + $clef.=$type_doc; + $clef=str_replace(' ','',$clef); + return $clef; + } + +// Rend une clef alpha pour les oeuvres + public function getClefOeuvre($titre,$complement_titre,$auteur,$tome) + { + $clef = substr($this->codeAlphaTitre(strtoupper(str_replace(' ','',$titre))),0,80).'-'; + $clef.=substr($this->codeAlphaTitre(strtoupper(str_replace(' ','',$complement_titre))),0,20).'-'; + $clef.=substr($this->alphaMaj(str_replace(' ','',$auteur)),0,80).'-'; + $clef.=$this->alphaMaj($tome); + $clef=str_replace(' ','',$clef); + return $clef; } - /** Decoupe une expression en mots en tenant compte des exclusions / inclusions */ - public function getMots($chaine) { - $new = []; - $chaine = str_replace(".", "", $chaine); +// Decoupe une expression en mots en tenant compte des exclusions / inclusions + public function getMots( $chaine ) + { + $new=array(); + $chaine = str_replace( '.', '', $chaine); $chaine = trim($this->alphaMaj($chaine)); - $mot = explode(" ", $chaine); + $mot = explode( ' ', $chaine ); $index = 0; - for($i = 0; $i < count($mot); $i++) { - // Retirer mots de 2 lettres sauf les inclus et les nombres - if (strLen($mot[$i]) < 3 and intVal($mot[$i]) == false) { - if (in_array( $mot[$i], $this->inclu) == false) continue; - if (strlen($mot[$i])==1) $mot[$i] .= '00'; // mots d'1 lettre : on rajoute 00 + for( $i = 0; $i < count($mot); $i++) + { + // Retirer mots de 2 lettres sauf les inclus et les nombres + if( strLen($mot[$i]) < 3 And intVal($mot[$i])==false) + { + if( in_array( $mot[$i], $this->inclu) == false) continue; + if(strlen($mot[$i])==1) $mot[$i].='00'; // mots d'1 lettre : on double la lettre + } + // Retirer mots vides + if( in_array($mot[$i], $this->exclu ) == true ) continue; + // On garde le mot + $new[$index++] = $mot[$i]; } - // Retirer mots vides - if (in_array($mot[$i], $this->exclu)) continue; - - // On garde le mot - $new[$index++] = $mot[$i]; - } return $new; } - /** Rend une chaine de mots dedoublonnes et filtres */ +// Rend une chaine de mots dedoublonnes et filtres public function getFulltext($data) { if (gettype($data) != 'array') - $data = array($data); - - $new = ''; - foreach($data as $chaine) { - $mots = $this->getMots($chaine); - foreach($mots as $mot) { - $mot = " " . $mot . " "; - if (strpos($new, $mot) === false) - $new .= $mot; + $data=array($data); + + $new=' '; + foreach($data as $chaine) + { + $mots=$this->getMots($chaine); + foreach($mots as $mot) + { + $mot=' '.$mot.' '; + if(strpos($new,$mot) === false ) + { + $new.=trim($mot).' '; + $phonem=' '.$this->phonetix(trim($mot)).' '; + if($phonem and strpos($new,$phonem) === false ) $new.=trim($phonem).' '; + } + } } - } return trim($new); } - /** - * Rend le mot au singulier et au pluriel - */ - public function getPluriel($mot) { - if (strToUpper($mot) != $mot) - $mot = $this->alphaMaj($mot); - if (!trim($mot)) - return false; - - foreach($this->pluriel as $regle) { - if(strLeft($regle[0],1) != "*") { - if($mot==$regle[0] or $mot==$regle[1]) return $regle; - else continue; +// Rend le mot au singulier et au pluriel + public function getPluriel( $mot ) + { + if( strToUpper($mot) != $mot ) $mot=$this->alphaMaj($mot); + if(!trim($mot)) return false; + foreach($this->pluriel as $regle) + { + if(strLeft($regle[0],1) != '*') + { + if($mot==$regle[0] or $mot==$regle[1]) return $regle; + else continue; + } + $regle[0]=str_replace('*','',$regle[0]); + $regle[1]=str_replace('*','',$regle[1]); + $pattern_singulier = '('.$regle[0].'$)'; + $pattern_pluriel='('.$regle[1].'$)'; + + $pluriel=ereg_replace($pattern_singulier, $regle[1], $mot); + $singulier=ereg_replace($pattern_pluriel, $regle[0], $mot); + if($singulier != $mot or $pluriel != $mot) break; } - - $regle[0] = str_replace("*", "", $regle[0]); - $regle[1] = str_replace("*", "", $regle[1]); - $pattern_singulier = "(".$regle[0]."$)"; - $pattern_pluriel = "(".$regle[1]."$)"; - - $pluriel = preg_replace($pattern_singulier, $regle[1], $mot); - $singulier = preg_replace($pattern_pluriel, $regle[0], $mot); - if ($singulier != $mot or $pluriel != $mot) break; - } - // Si inchangé on ajoute le S - if ($singulier == $pluriel) { - if (strRight($mot,1)=="S") { - $pluriel = $singulier; - $singulier = strLeft($singulier,strlen($singulier)-1); - } else { - $pluriel=$singulier."S"; + if($singulier == $pluriel) + { + if(strRight($mot,1)=='S') {$pluriel=$singulier; $singulier=strLeft($singulier,strlen($singulier)-1);} + else $pluriel=$singulier.'S'; } - - } return array($singulier,$pluriel); } - /** Compare deux expression et rend true si tous les mots correspondent */ - public function compare_expression($texte1, $texte2) { - $mots_vides = ';THE;'; - - $texte1 = convertFromUtf8($texte1); - $texte2 = convertFromUtf8($texte2); - // Decouper par mots - $chaine = trim($this->AlphaMaj($texte1)); - $mot1 = explode(' ', $chaine); - $chaine = trim($this->AlphaMaj($texte2)); - $mot2 = explode(' ', $chaine); - - // Comparer - for($i=0;$i<count($mot1); $i++) { - if (!trim($mot1[$i])) continue; - if (strPos($mots_vides,";".$mot1[$i].";") !== false) continue; - if (!in_array($mot1[$i],$mot2)) return false; - - } - return true; - } - - public function isMotInclu($mot) { +// --------------------------------------------------- +// Rend true si mot inclu +// --------------------------------------------------- + public function isMotInclu($mot) + { return in_array($mot, $this->inclu); } - - public function phonetix($sIn) { - if (strlen($sIn) < 4) +// --------------------------------------------------- +// Othographe approchante +// --------------------------------------------------- + function phonetix($sIn) { + if (strlen($sIn)<4 || is_numeric($sIn)) return false; + return $this->phonetixCompute($sIn); + } - - $accents = array('É' => 'E', 'È' => 'E', 'Ë' => 'E', 'Ê' => 'E','Ã' => 'A', 'À' => 'A', 'Ä' => 'A', 'Â' => 'A', - 'Ã…' => 'A', 'Ã' => 'A', 'Æ' => 'E','Ã' => 'I', 'ÃŽ' => 'I', 'ÃŒ' => 'I', 'Ã' => 'I', - 'Ô' => 'O', 'Ö' => 'O', 'Ã’' => 'O', 'Ó' => 'O', 'Õ' => 'O', 'Ø' => 'O', 'Å’' => 'OEU', - 'Ú' => 'U', 'Ù' => 'U', 'Û' => 'U', 'Ãœ' => 'U','Ñ' => 'N', 'Ç' => 'S', '¿' => 'E'); - - $min2maj = array('é' => 'É', 'è' => 'È', 'ë' => 'Ë', 'ê' => 'Ê','á' => 'Ã', 'â' => 'Â', 'à ' => 'À', 'Ä' => 'A', - 'Â' => 'A', 'Ã¥' => 'Ã…', 'ã' => 'Ã', 'æ' => 'Æ', 'ï' => 'Ã', 'î' => 'ÃŽ', 'ì' => 'ÃŒ', 'Ã' => 'Ã', - 'ô' => 'Ô', 'ö' => 'Ö', 'ò' => 'Ã’', 'ó' => 'Ó','õ' => 'Õ', 'ø' => 'Ø', 'Å“' => 'Å’', - 'ú' => 'Ú', 'ù' => 'Ù', 'û' => 'Û', 'ü' => 'Ãœ','ç' => 'Ç', 'ñ' => 'Ñ', 'ß' => 'S'); - - - //$sIn = utf8_decode($sIn); // Selon votre implémentation, vous aurez besoin de décoder ce qui arrive pour les caractères spéciaux - $sIn = strtr( $sIn, $min2maj); // minuscules accentuées ou composées en majuscules simples - $sIn = strtr( $sIn, $accents); // majuscules accentuées ou composées en majuscules simples + function phonetixCompute($sIn) { + $sIn = strtr( $sIn, $this->accents); // minuscules accentuées ou composées en majuscules simples + $sIn = strtr( $sIn, $this->min2maj); // majuscules accentuées ou composées en majuscules simples $sIn = strtoupper( $sIn ); // on passe tout le reste en majuscules $sIn = preg_replace( '`[^A-Z]`', '', $sIn ); // on garde uniquement les lettres de A à Z $sBack=$sIn; // on sauve le code (utilisé pour les mots très courts) $sIn = preg_replace( '`O[O]+`', 'OU', $sIn ); // pré traitement OO... -> OU - $sIn = preg_replace( '`SAOU`', 'SOU', $sIn ); // pré traitement SAOU -> SOU - $sIn = preg_replace( '`OES`', 'OS', $sIn ); // pré traitement OES -> OS - $sIn = preg_replace( '`CCH`', 'K', $sIn ); // pré traitement CCH -> K + $sIn = str_replace( 'SAOU', 'SOU', $sIn ); // pré traitement SAOU -> SOU + $sIn = str_replace( 'OES', 'OS', $sIn ); // pré traitement OES -> OS + $sIn = str_replace( 'CCH', 'K', $sIn ); // pré traitement CCH -> K $sIn = preg_replace( '`CC([IYE])`', 'KS$1', $sIn ); // CCI CCY CCE $sIn = preg_replace( '`(.)\1`', '$1', $sIn ); // supression des répétitions // quelques cas particuliers - if ($sIn=="CD") return($sIn); - if ($sIn=="BD") return($sIn); - if ($sIn=="BV") return($sIn); - if ($sIn=="TABAC") return("TABA"); - if ($sIn=="FEU") return("FE"); - if ($sIn=="FE") return($sIn); - if ($sIn=="FER") return($sIn); - if ($sIn=="FIEF") return($sIn); - if ($sIn=="FJORD") return($sIn); - if ($sIn=="GOAL") return("GOL"); - if ($sIn=="FLEAU") return("FLEO"); - if ($sIn=="HIER") return("IER"); - if ($sIn=="HEU") return("E"); - if ($sIn=="HE") return("E"); - if ($sIn=="OS") return($sIn); - if ($sIn=="RIZ") return("RI"); - if ($sIn=="RAZ") return("RA"); + if ($sIn=='CD') return($sIn); + if ($sIn=='BD') return($sIn); + if ($sIn=='BV') return($sIn); + if ($sIn=='TABAC') return('TABA'); + if ($sIn=='FEU') return('FE'); + if ($sIn=='FE') return($sIn); + if ($sIn=='FER') return($sIn); + if ($sIn=='FIEF') return($sIn); + if ($sIn=='FJORD') return($sIn); + if ($sIn=='GOAL') return('GOL'); + if ($sIn=='FLEAU') return('FLEO'); + if ($sIn=='HIER') return('IER'); + if ($sIn=='HEU') return('E'); + if ($sIn=='HE') return('E'); + if ($sIn=='OS') return($sIn); + if ($sIn=='RIZ') return('RI'); + if ($sIn=='RAZ') return('RA'); // pré-traitements $sIn = preg_replace( '`OIN[GT]$`', 'OIN', $sIn ); // terminaisons OING -> OIN $sIn = preg_replace( '`E[RS]$`', 'E', $sIn ); // supression des terminaisons infinitifs et participes pluriels $sIn = preg_replace( '`(C|CH)OEU`', 'KE', $sIn ); // pré traitement OEU -> EU - $sIn = preg_replace( '`MOEU`', 'ME', $sIn ); // pré traitement OEU -> EU + $sIn = str_replace( 'MOEU', 'ME', $sIn ); // pré traitement OEU -> EU $sIn = preg_replace( '`OE([UI]+)([BCDFGHJKLMNPQRSTVWXZ])`', 'E$1$2', $sIn ); // pré traitement OEU OEI -> E $sIn = preg_replace( '`^GEN[TS]$`', 'JAN', $sIn ); // pré traitement GEN -> JAN - $sIn = preg_replace( '`CUEI`', 'KEI', $sIn ); // pré traitement accueil + $sIn = str_replace( 'CUEI', 'KEI', $sIn ); // pré traitement accueil $sIn = preg_replace( '`([^AEIOUYC])AE([BCDFGHJKLMNPQRSTVWXZ])`', '$1E$2', $sIn ); // pré traitement AE -> E $sIn = preg_replace( '`AE([QS])`', 'E$1', $sIn ); // pré traitement AE -> E $sIn = preg_replace( '`AIE([BCDFGJKLMNPQRSTVWXZ])`', 'AI$1', $sIn ); // pré-traitement AIE(consonne) -> AI - $sIn = preg_replace( '`ANIEM`', 'ANIM', $sIn ); // pré traitement NIEM -> NIM + $sIn = str_replace( 'ANIEM', 'ANIM', $sIn ); // pré traitement NIEM -> NIM $sIn = preg_replace( '`(DRA|TRO|IRO)P$`', '$1', $sIn ); // P terminal muet $sIn = preg_replace( '`(LOM)B$`', '$1', $sIn ); // B terminal muet $sIn = preg_replace( '`(RON|POR)C$`', '$1', $sIn ); // C terminal muet @@ -371,10 +338,10 @@ class Class_Indexation { $sIn = preg_replace( '`([^TRH])UIL(AR|E)(.+)`', '$1UI$2$3', $sIn ); $sIn = preg_replace( '`([G])UIL([AEO])`', '$1UI$2', $sIn ); $sIn = preg_replace( '`([NSPM])AIL([AEO])`', '$1AI$2', $sIn ); - $convMIn = array("DILAI","DILON","DILER","DILEM","RILON","TAILE","GAILET","AILAI","AILAR", - "OUILA","EILAI","EILAR","EILER","EILEM","REILET","EILET","AILOL" ); - $convMOut = array( "DIAI", "DION","DIER", "DIEM", "RION", "TAIE", "GAIET", "AIAI", "AIAR", - "OUIA", "AIAI", "AIAR", "AIER", "AIEM", "RAIET", "EIET", "AIOL" ); + $convMIn = array('DILAI','DILON','DILER','DILEM','RILON','TAILE','GAILET','AILAI','AILAR', + 'OUILA','EILAI','EILAR','EILER','EILEM','REILET','EILET','AILOL' ); + $convMOut = array( 'DIAI', 'DION','DIER', 'DIEM', 'RION', 'TAIE', 'GAIET', 'AIAI', 'AIAR', + 'OUIA', 'AIAI', 'AIAR', 'AIER', 'AIEM', 'RAIET', 'EIET', 'AIOL' ); $sIn = str_replace( $convMIn, $convMOut, $sIn ); $sIn = preg_replace( '`([^AEIOUY])(SC|S)IEM([EA])`', '$1$2IAM$3', $sIn ); // IEM -> IAM $sIn = preg_replace( '`^(SC|S)IEM([EA])`', '$1IAM$2', $sIn ); // IEM -> IAM @@ -403,9 +370,9 @@ class Class_Indexation { $sIn = preg_replace( '`ACHY([^D])`', 'AKI$1', $sIn ); $sIn = preg_replace( '`([AEIOU])C([BDFGJKLMNPQRTVWXZ])`', '$1K$2', $sIn ); // voyelle, C, consonne sauf H $convPrIn = array('EUCHA','YCHIA','YCHA','YCHO','YCHED','ACHEO','RCHEO','RCHES', - 'ECHN','OCHTO','CHORA','CHONDR','CHORE','MACHM','BRONCHO','LICHOS','LICHOC'); + 'ECHN','OCHTO','CHORA','CHONDR','CHORE','MACHM','BRONCHO','LICHOS','LICHOC'); $convPrOut = array('EKA', 'IKIA', 'IKA', 'IKO', 'IKED','AKEO','RKEO', 'RKES', - 'EKN', 'OKTO', 'KORA', 'KONDR' ,'KORE' ,'MAKM', 'BRONKO', 'LIKOS', 'LIKOC'); + 'EKN', 'OKTO', 'KORA', 'KONDR' ,'KORE' ,'MAKM', 'BRONKO', 'LIKOS', 'LIKOC'); $sIn = str_replace( $convPrIn, $convPrOut, $sIn ); // Weuh (perfectible) @@ -415,17 +382,17 @@ class Class_Indexation { // Gueu, Gneu, Jeu et quelques autres $convPrIn = array( 'GNES','GNET','GNER','GNE', 'GI', 'GNI','GNA','GNOU','GNUR','GY','OUGAIN', - 'AGEOL', 'AGEOT','GEOLO','GEOM','GEOP','GEOG','GEOS','GEORG','GEOR','NGEOT','UGEOT','GEOT','GEOD','GEOC','GEO','GEA','GE', - 'QU', 'Q', 'CY', 'CI', 'CN','ICM','CEAT','CE', - 'CR', 'CO', 'CUEI','CU', 'VENCA','CA', 'CS','CLEN','CL', 'CZ', 'CTIQ', - 'CTIF','CTIC','CTIS','CTIL','CTIO','CTI', 'CTU', 'CTE','CTO','CTR','CT', 'PH', 'TH', - 'OW', 'LH', 'RDL', 'CHLO', 'CHR', 'PTIA'); + 'AGEOL', 'AGEOT','GEOLO','GEOM','GEOP','GEOG','GEOS','GEORG','GEOR','NGEOT','UGEOT','GEOT','GEOD','GEOC','GEO','GEA','GE', + 'QU', 'Q', 'CY', 'CI', 'CN','ICM','CEAT','CE', + 'CR', 'CO', 'CUEI','CU', 'VENCA','CA', 'CS','CLEN','CL', 'CZ', 'CTIQ', + 'CTIF','CTIC','CTIS','CTIL','CTIO','CTI', 'CTU', 'CTE','CTO','CTR','CT', 'PH', 'TH', + 'OW', 'LH', 'RDL', 'CHLO', 'CHR', 'PTIA'); $convPrOut = array( 'NIES','NIET','NIER', 'NE', 'JI', 'NI','NIA','NIOU','NIUR','JI','OUGIN', - 'AJOL', 'AJOT','JEOLO','JEOM','JEOP','JEOG','JEOS','JORJ','JEOR','NJOT','UJOT','JEOT','JEOD','JEOC', 'JO','JA' ,'JE', - 'K', 'K', 'SI', 'SI', 'KN','IKM', 'SAT','SE', - 'KR', 'KO', 'KEI','KU', 'VANSA','KA', 'KS','KLAN','KL', 'KZ', 'KTIK', - 'KTIF','KTIS','KTIS','KTIL','KSIO','KTI', 'KTU', 'KTE','KTO','KTR','KT', 'F', 'T', - 'OU', 'L', 'RL', 'KLO', 'KR', 'PSIA'); + 'AJOL', 'AJOT','JEOLO','JEOM','JEOP','JEOG','JEOS','JORJ','JEOR','NJOT','UJOT','JEOT','JEOD','JEOC', 'JO','JA' ,'JE', + 'K', 'K', 'SI', 'SI', 'KN','IKM', 'SAT','SE', + 'KR', 'KO', 'KEI','KU', 'VANSA','KA', 'KS','KLAN','KL', 'KZ', 'KTIK', + 'KTIF','KTIS','KTIS','KTIL','KSIO','KTI', 'KTU', 'KTE','KTO','KTR','KT', 'F', 'T', + 'OU', 'L', 'RL', 'KLO', 'KR', 'PSIA'); $sIn = str_replace( $convPrIn, $convPrOut, $sIn ); $sIn = preg_replace( '`GU([^RLMBSTPZN])`', 'G$1', $sIn ); // Gueu ! @@ -435,9 +402,9 @@ class Class_Indexation { // TI -> SI v2.0 $convPrIn = array( 'BUTIE','BUTIA','BATIA','ANTIEL','RETION','ENTIEL','ENTIAL','ENTIO','ENTIAI','UJETION','ATIEM','PETIEN', - 'CETIE','OFETIE','IPETI','LBUTION','BLUTION','LETION','LATION','SATIET'); + 'CETIE','OFETIE','IPETI','LBUTION','BLUTION','LETION','LATION','SATIET'); $convPrOut = array( 'BUSIE','BUSIA','BASIA','ANSIEL','RESION','ENSIEL','ENSIAL','ENSIO','ENSIAI','UJESION','ASIAM','PESIEN', - 'CESIE','OFESIE','IPESI','LBUSION','BLUSION','LESION','LASION','SASIET'); + 'CESIE','OFESIE','IPESI','LBUSION','BLUSION','LESION','LASION','SASIET'); $sIn = str_replace( $convPrIn, $convPrOut, $sIn ); $sIn = preg_replace( '`(.+)ANTI(AL|O)`', '$1ANSI$2', $sIn ); // sauf antialcoolique, antialbumine, antialarmer, ... $sIn = preg_replace( '`(.+)INUTI([^V])`', '$1INUSI$2', $sIn ); // sauf inutilité, inutilement, diminutive, ... @@ -449,15 +416,15 @@ class Class_Indexation { // H muet $sIn = preg_replace( '`([^CS])H`', '$1', $sIn ); // H muet - $sIn = str_replace( "ESH", "ES", $sIn ); // H muet - $sIn = str_replace( "NSH", "NS", $sIn ); // H muet - $sIn = str_replace( "SH", "CH", $sIn ); // ou pas! + $sIn = str_replace( 'ESH', 'ES', $sIn ); // H muet + $sIn = str_replace( 'NSH', 'NS', $sIn ); // H muet + $sIn = str_replace( 'SH', 'CH', $sIn ); // ou pas! // NASALES $convNasIn = array( 'OMT','IMB', 'IMP','UMD','TIENT','RIENT','DIENT','IEN', - 'YMU','YMO','YMA','YME', 'YMI','YMN','YM', 'AHO','FAIM','DAIM','SAIM','EIN','AINS'); + 'YMU','YMO','YMA','YME', 'YMI','YMN','YM', 'AHO','FAIM','DAIM','SAIM','EIN','AINS'); $convNasOut = array( 'ONT','INB', 'INP','OND','TIANT','RIANT','DIANT', 'IN', - 'IMU','IMO','IMA','IME', 'IMI','IMN','IN', 'AO', 'FIN','DIN', 'SIN','AIN','INS'); + 'IMU','IMO','IMA','IME', 'IMI','IMN','IN', 'AO', 'FIN','DIN', 'SIN','AIN','INS'); $sIn = str_replace( $convNasIn, $convNasOut, $sIn ); // AIN -> IN v2.0 $sIn = preg_replace( '`AIN$`', 'IN', $sIn ); @@ -467,7 +434,7 @@ class Class_Indexation { $sIn = preg_replace( '`([JTVLFMRPSBD])UN([^IAE])`', '$1IN$2', $sIn ); $sIn = preg_replace( '`([JTVLFMRPSBD])UN$`', '$1IN', $sIn ); $sIn = preg_replace( '`RFUM$`', 'RFIN', $sIn ); - $sIn = preg_replace( '`LUMB`', 'LINB', $sIn ); + $sIn = str_replace( 'LUMB', 'LINB', $sIn ); // EN -> AN $sIn = preg_replace( '`([^BCDFGHJKLMNPQRSTVWXZ])EN`', '$1AN', $sIn ); $sIn = preg_replace( '`([VTLJMRPDSBFKNG])EN([BRCTDKZSVN])`', '$1AN$2', $sIn ); // deux fois pour les motifs recouvrants malentendu, pendentif, ... @@ -489,30 +456,30 @@ class Class_Indexation { // Les retouches! $sIn = preg_replace( '`^BENJ`', 'BINJ', $sIn ); // retouche BENJ -> BINJ - $sIn = preg_replace( '`RTIEL`', 'RSIEL', $sIn ); // retouche RTIEL -> RSIEL - $sIn = preg_replace( '`PINK`', 'PONK', $sIn ); // retouche PINK -> PONK - $sIn = preg_replace( '`KIND`', 'KOND', $sIn ); // retouche KIND -> KOND + $sIn = str_replace( 'RTIEL', 'RSIEL', $sIn ); // retouche RTIEL -> RSIEL + $sIn = str_replace( 'PINK', 'PONK', $sIn ); // retouche PINK -> PONK + $sIn = str_replace( 'KIND', 'KOND', $sIn ); // retouche KIND -> KOND $sIn = preg_replace( '`KUM(N|P)`', 'KON$1', $sIn ); // retouche KUMN KUMP - $sIn = preg_replace( '`LKOU`', 'LKO', $sIn ); // retouche LKOU -> LKO - $sIn = preg_replace( '`EDBE`', 'EBE', $sIn ); // retouche EDBE pied-bÅ“uf - $sIn = preg_replace( '`ARCM`', 'ARKM', $sIn ); // retouche SCH -> CH - $sIn = preg_replace( '`SCH`', 'CH', $sIn ); // retouche SCH -> CH + $sIn = str_replace( 'LKOU', 'LKO', $sIn ); // retouche LKOU -> LKO + $sIn = str_replace( 'EDBE', 'EBE', $sIn ); // retouche EDBE pied-bÅ“uf + $sIn = str_replace( 'ARCM', 'ARKM', $sIn ); // retouche SCH -> CH + $sIn = str_replace( 'SCH', 'CH', $sIn ); // retouche SCH -> CH $sIn = preg_replace( '`^OINI`', 'ONI', $sIn ); // retouche début OINI -> ONI $sIn = preg_replace( '`([^NDCGRHKO])APT`', '$1AT', $sIn ); // retouche APT -> AT $sIn = preg_replace( '`([L]|KON)PT`', '$1T', $sIn ); // retouche LPT -> LT - $sIn = preg_replace( '`OTB`', 'OB', $sIn ); // retouche OTB -> OB (hautbois) - $sIn = preg_replace( '`IXA`', 'ISA', $sIn ); // retouche IXA -> ISA - $sIn = preg_replace( '`TG`', 'G', $sIn ); // retouche TG -> G + $sIn = str_replace( 'OTB', 'OB', $sIn ); // retouche OTB -> OB (hautbois) + $sIn = str_replace( 'IXA', 'ISA', $sIn ); // retouche IXA -> ISA + $sIn = str_replace( 'TG', 'G', $sIn ); // retouche TG -> G $sIn = preg_replace( '`^TZ`', 'TS', $sIn ); // retouche début TZ -> TS - $sIn = preg_replace( '`PTIE`', 'TIE', $sIn ); // retouche PTIE -> TIE - $sIn = preg_replace( '`GT`', 'T', $sIn ); // retouche GT -> T - $sIn = str_replace( "ANKIEM", "ANKILEM", $sIn ); // retouche tranquillement - $sIn = preg_replace( "`(LO|RE)KEMAN`", "$1KAMAN", $sIn ); // KEMAN -> KAMAN + $sIn = str_replace( 'PTIE', 'TIE', $sIn ); // retouche PTIE -> TIE + $sIn = str_replace( 'GT', 'T', $sIn ); // retouche GT -> T + $sIn = str_replace( 'ANKIEM', 'ANKILEM', $sIn ); // retouche tranquillement + $sIn = preg_replace( '`(LO|RE)KEMAN`', '$1KAMAN', $sIn ); // KEMAN -> KAMAN $sIn = preg_replace( '`NT(B|M)`', 'N$1', $sIn ); // retouche TB -> B TM -> M - $sIn = preg_replace( '`GSU`', 'SU', $sIn ); // retouche GS -> SU - $sIn = preg_replace( '`ESD`', 'ED', $sIn ); // retouche ESD -> ED - $sIn = preg_replace( '`LESKEL`','LEKEL', $sIn ); // retouche LESQUEL -> LEKEL - $sIn = preg_replace( '`CK`', 'K', $sIn ); // retouche CK -> K + $sIn = str_replace( 'GSU', 'SU', $sIn ); // retouche GS -> SU + $sIn = str_replace( 'ESD', 'ED', $sIn ); // retouche ESD -> ED + $sIn = str_replace( 'LESKEL', 'LEKEL', $sIn ); // retouche LESQUEL -> LEKEL + $sIn = str_replace( 'CK', 'K', $sIn ); // retouche CK -> K // Terminaisons $sIn = preg_replace( '`USIL$`', 'USI', $sIn ); // terminaisons USIL -> USI @@ -520,35 +487,72 @@ class Class_Indexation { $sIn = preg_replace( '`([^KL]+)T$`', '$1', $sIn ); // sauf KT LT terminal $sIn = preg_replace( '`^[H]`', '', $sIn ); // H pseudo muet en début de mot, je sais, ce n'est pas une terminaison $sBack2=$sIn; // on sauve le code (utilisé pour les mots très courts) - $sIn = preg_replace( '`TIL$`', 'TI', $sIn ); // terminaisons TIL -> TI - $sIn = preg_replace( '`LC$`', 'LK', $sIn ); // terminaisons LC -> LK - $sIn = preg_replace( '`L[E]?[S]?$`', 'L', $sIn ); // terminaisons LE LES -> L - $sIn = preg_replace( '`(.+)N[E]?[S]?$`', '$1N', $sIn ); // terminaisons NE NES -> N - $sIn = preg_replace( '`EZ$`', 'E', $sIn ); // terminaisons EZ -> E - $sIn = preg_replace( '`OIG$`', 'OI', $sIn ); // terminaisons OIG -> OI - $sIn = preg_replace( '`OUP$`', 'OU', $sIn ); // terminaisons OUP -> OU - $sIn = preg_replace( '`([^R])OM$`', '$1ON', $sIn ); // terminaisons OM -> ON sauf ROM - $sIn = preg_replace( '`LOP$`', 'LO', $sIn ); // terminaisons LOP -> LO - $sIn = preg_replace( '`NTANP$`', 'NTAN', $sIn ); // terminaisons NTANP -> NTAN - $sIn = preg_replace( '`TUN$`', 'TIN', $sIn ); // terminaisons TUN -> TIN - $sIn = preg_replace( '`AU$`', 'O', $sIn ); // terminaisons AU -> O - $sIn = preg_replace( '`EI$`', 'AI', $sIn ); // terminaisons EI -> AI - $sIn = preg_replace( '`R[DG]$`', 'R', $sIn ); // terminaisons RD RG -> R - $sIn = preg_replace( '`ANC$`', 'AN', $sIn ); // terminaisons ANC -> AN - $sIn = preg_replace( '`KROC$`', 'KRO', $sIn ); // terminaisons C muet de CROC, ESCROC - $sIn = preg_replace( '`HOUC$`', 'HOU', $sIn ); // terminaisons C muet de CAOUTCHOUC - $sIn = preg_replace( '`OMAC$`', 'OMA', $sIn ); // terminaisons C muet de ESTOMAC (mais pas HAMAC) - $sIn = preg_replace( '`([J])O([NU])[CG]$`', '$1O$2', $sIn );// terminaisons C et G muet de OUC ONC OUG - $sIn = preg_replace( '`([^GTR])([AO])NG$`', '$1$2N', $sIn );// terminaisons G muet ANG ONG sauf GANG GONG TANG TONG - $sIn = preg_replace( '`UC$`', 'UK', $sIn ); // terminaisons UC -> UK - $sIn = preg_replace( '`AING$`', 'IN', $sIn ); // terminaisons AING -> IN - $sIn = preg_replace( '`([EISOARN])C$`', '$1K', $sIn ); // terminaisons C -> K - $sIn = preg_replace( '`([ABD-MO-Z]+)[EH]+$`', '$1', $sIn ); // terminaisons E ou H sauf pour C et N - $sIn = preg_replace( '`EN$`', 'AN', $sIn ); // terminaisons EN -> AN (difficile à faire avant sans avoir des soucis) Et encore, c'est pas top! - $sIn = preg_replace( '`(NJ)EN$`', '$1AN', $sIn ); // terminaisons EN -> AN - $sIn = preg_replace( '`^PAIEM`', 'PAIM', $sIn ); // PAIE -> PAI - $sIn = preg_replace( '`([^NTB])EF$`', '\1', $sIn ); // F muet en fin de mot - $sIn = preg_replace( '`(.)\1`', '$1', $sIn ); // supression des répétitions (suite à certains remplacements) + + $convPartIn = [ + '`TIL$`', // terminaisons TIL -> TI + '`LC$`', // terminaisons LC -> LK + '`L[E]?[S]?$`', // terminaisons LE LES -> L + '`(.+)N[E]?[S]?$`', // terminaisons NE NES -> N + '`EZ$`', // terminaisons EZ -> E + '`OIG$`', // terminaisons OIG -> OI + '`OUP$`', // terminaisons OUP -> OU + '`([^R])OM$`', // terminaisons OM -> ON sauf ROM + '`LOP$`', // terminaisons LOP -> LO + '`NTANP$`', // terminaisons NTANP -> NTAN + '`TUN$`', // terminaisons TUN -> TIN + '`AU$`', // terminaisons AU -> O + '`EI$`', // terminaisons EI -> AI + '`R[DG]$`', // terminaisons RD RG -> R + '`ANC$`', // terminaisons ANC -> AN + '`KROC$`', // terminaisons C muet de CROC, ESCROC + '`HOUC$`', // terminaisons C muet de CAOUTCHOUC + '`OMAC$`', // terminaisons C muet de ESTOMAC (mais pas HAMAC) + '`([J])O([NU])[CG]$`',// terminaisons C et G muet de OUC ONC OUG + '`([^GTR])([AO])NG$`',// terminaisons G muet ANG ONG sauf GANG GONG TANG TONG + '`UC$`', // terminaisons UC -> UK + '`AING$`', // terminaisons AING -> IN + '`([EISOARN])C$`', // terminaisons C -> K + '`([ABD-MO-Z]+)[EH]+$`', // terminaisons E ou H sauf pour C et N + '`EN$`', // terminaisons EN -> AN (difficile à faire avant sans avoir des soucis) Et encore, + '`(NJ)EN$`',// terminaisons EN -> AN + '`^PAIEM`', // PAIE -> PAI + '`([^NTB])EF$`', // F muet en fin de mot + '`(.)\1`' // supression des répétitions (suite à certains remplacements) + ]; + + $convPartOut = [ + 'TI', // terminaisons TIL -> TI + 'LK', // terminaisons LC -> LK + 'L', // terminaisons LE LES -> L + '$1N', // terminaisons NE NES -> N + 'E', // terminaisons EZ -> E + 'OI', // terminaisons OIG -> OI + 'OU', // terminaisons OUP -> OU + '$1ON', // terminaisons OM -> ON sauf ROM + 'LO', // terminaisons LOP -> LO + 'NTAN', // terminaisons NTANP -> NTAN + 'TIN', // terminaisons TUN -> TIN + 'O', // terminaisons AU -> O + 'AI', // terminaisons EI -> AI + 'R', // terminaisons RD RG -> R + 'AN', // terminaisons ANC -> AN + 'KRO', // terminaisons C muet de CROC, ESCROC + 'HOU', // terminaisons C muet de CAOUTCHOUC + 'OMA', // terminaisons C muet de ESTOMAC (mais pas HAMAC) + '$1O$2',// terminaisons C et G muet de OUC ONC OUG + '$1$2N',// terminaisons G muet ANG ONG sauf GANG GONG TANG TONG + 'UK', // terminaisons UC -> UK + 'IN', // terminaisons AING -> IN + '$1K', // terminaisons C -> K + '$1', // terminaisons E ou H sauf pour C et N + 'AN', // terminaisons EN -> AN (difficile à faire avant sans avoir des soucis) Et encore, c'est pas top! + '$1AN', // terminaisons EN -> AN + 'PAIM', // PAIE -> PAI + '\1', // F muet en fin de mot + '$1' // supression des répétitions (suite à certains remplacements) + ]; + + $sIn = preg_replace( $convPartIn, $convPartOut, $sIn ); // cas particuliers, bah au final, je n'en ai qu'un ici $convPartIn = array( 'FUEL'); @@ -560,26 +564,26 @@ class Class_Indexation { // seconde chance sur les mots courts qui ont souffert de la simplification if (strlen($sIn)<2) - { - // Sigles ou abréviations - if (preg_match("`[BCDFGHJKLMNPQRSTVWXYZ][BCDFGHJKLMNPQRSTVWXYZ][BCDFGHJKLMNPQRSTVWXYZ][BCDFGHJKLMNPQRSTVWXYZ]*`",$sBack)) - return($sBack); - - if (preg_match("`[RFMLVSPJDF][AEIOU]`",$sBack)) { - if (strlen($sBack)==3) - return(substr($sBack,0,2));// mots de trois lettres supposés simples - if (strlen($sBack)==4) - return(substr($sBack,0,3));// mots de quatre lettres supposés simples + // Sigles ou abréviations + if (preg_match('`[BCDFGHJKLMNPQRSTVWXYZ][BCDFGHJKLMNPQRSTVWXYZ][BCDFGHJKLMNPQRSTVWXYZ][BCDFGHJKLMNPQRSTVWXYZ]*`',$sBack)) + return($sBack); + + if (preg_match('`[RFMLVSPJDF][AEIOU]`',$sBack)) + { + if (strlen($sBack)==3) + return(substr($sBack,0,2));// mots de trois lettres supposés simples + if (strlen($sBack)==4) + return(substr($sBack,0,3));// mots de quatre lettres supposés simples + } + + if (strlen($sBack2)>1) return $sBack2; } - - if (strlen($sBack2)>1) return $sBack2; - } if (strlen($sIn)>1) - { - return substr($sIn,0,16); // Je limite à 16 caractères mais vous faites comme vous voulez! - } + { + return substr($sIn,0,16); // Je limite à 16 caractères mais vous faites comme vous voulez! + } else return ''; - } + } } ?> \ No newline at end of file diff --git a/library/Class/Notice.php b/library/Class/Notice.php index eb30cc04e9a38fcf85277781e678b04c54a516bc..74ac823a19ec4d576b456f5e773f39934b48066d 100644 --- a/library/Class/Notice.php +++ b/library/Class/Notice.php @@ -1674,6 +1674,7 @@ class Class_Notice extends Storm_Model_Abstract { return ''; foreach($auteurs as $auteur) { + xdebug_break(); $code_alpha = (new Class_Indexation())->alphaMaj($auteur); if (!$code_alpha = str_replace(" ","x",$code_alpha)) continue; diff --git a/library/Class/WebService/Lastfm.php b/library/Class/WebService/Lastfm.php index c7e40df2104b988073ecb5b30ff4d3d27f98ba4e..f6a874f8ab71392349b557406dadb1d6da62d190 100644 --- a/library/Class/WebService/Lastfm.php +++ b/library/Class/WebService/Lastfm.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -39,7 +39,7 @@ class Class_WebService_Lastfm extends Class_WebService_Abstract { static::$_instance = $instance; } - + public function __construct() { $this->id_afi = "76d470da0d3d5cb08a7025aae2c8686a"; $this->xml = new Class_Xml(); @@ -47,7 +47,7 @@ class Class_WebService_Lastfm extends Class_WebService_Abstract { $this->ix = new Class_Indexation(); $this->player = '<embed id="lfmPlayer" height="221" width="300" align="middle" swliveconnect="true" name="lfmPlayer" allowfullscreen="true" allowscriptaccess="always" flashvars="lang=fr&lfmMode=playlist&FOD=true&resname=@TITRE@&restype=track&artist=@AUTEUR@&albumArt=&autostart=true" bgcolor="#fff" wmode="transparent" quality="high" menu="true" pluginspage="http://www.macromedia.com/go/getflashplayer" src="http://cdn.last.fm/webclient/s12n/s/5/lfmPlayer.swf" type="application/x-shockwave-flash"/>'; } - + public function requete($req) { $url = $this->req.$req; @@ -56,22 +56,45 @@ class Class_WebService_Lastfm extends Class_WebService_Abstract { } + /** Compare deux expression et rend true si tous les mots correspondent */ + public function compare_expression($texte1, $texte2) { + $mots_vides = ';THE;'; + + $texte1 = convertFromUtf8($texte1); + $texte2 = convertFromUtf8($texte2); + // Decouper par mots + $chaine = trim($this->ix->alphaMaj($texte1)); + $mot1 = explode(' ', $chaine); + $chaine = trim($this->ix->alphaMaj($texte2)); + $mot2 = explode(' ', $chaine); + + // Comparer + for($i=0;$i<count($mot1); $i++) { + if (!trim($mot1[$i])) continue; + if (strPos($mots_vides,";".$mot1[$i].";") !== false) continue; + if (!in_array($mot1[$i],$mot2)) return false; + + } + return true; + } + + public function getAlbum($titre, $auteur) { $titre = implode(' ', $this->ix->getMots($this->ix->codeAlphaTitre($titre))); $req = $this->getRequete('album.search', 'album', $titre); - if ($this->requete($req)==false) + if ($this->requete($req)==false) return false; - + $nodes = $this->xml->index['ALBUM']; - if(!$nodes) + if(!$nodes) return false; foreach($nodes as $node) { $album = $this->xml->get_child_value($node, "NAME"); $artist = $this->xml->get_child_value($node, "ARTIST"); - if($this->ix->compare_expression($titre, $album) - and $this->ix->compare_expression($auteur, $artist)) + if($this->compare_expression($titre, $album) + and $this->compare_expression($auteur, $artist)) break; $album = $artist = ''; @@ -89,15 +112,15 @@ class Class_WebService_Lastfm extends Class_WebService_Abstract { if (!$album) return false; - + $notice["auteur"] = $artist; $notice["url"] = $this->xml->get_child_value($node, "URL"); $node_image = $this->xml->get_child_node($node, "IMAGE"); - if ($this->xml->get_attribut($node_image,"SIZE") == "small") + if ($this->xml->get_attribut($node_image,"SIZE") == "small") $notice["vignette"] = $this->xml->get_value($node_image); $node_image += 4; - if($this->xml->get_attribut($node_image,"SIZE") == "large") + if($this->xml->get_attribut($node_image,"SIZE") == "large") $notice["image"] = $this->xml->get_value($node_image); return $notice; } @@ -114,7 +137,7 @@ class Class_WebService_Lastfm extends Class_WebService_Abstract { $posfin=strPos($data,'</table>',$pos); $pos=strPos($data,'<tbody',$pos); $data=substr($data,$pos,($posfin-$pos)); - + // Prendre les pistes $volume=1; $piste=0; @@ -146,11 +169,11 @@ class Class_WebService_Lastfm extends Class_WebService_Abstract { public function getPhotos($auteur) { $req = $this->getRequete('artist.search', 'artist', $auteur); - if($this->requete($req)==false) + if($this->requete($req)==false) return false; $nodes = $this->xml->index["ARTIST"]; - if(!$nodes) + if(!$nodes) return false; foreach($nodes as $node) { @@ -163,22 +186,22 @@ class Class_WebService_Lastfm extends Class_WebService_Abstract { if (!$artist) { foreach($nodes as $node) { $artist = $this->xml->get_child_value($node, "NAME"); - if ($this->ix->compare_expression($auteur,$artist) == true) + if ($this->compare_expression($auteur,$artist) == true) break; $artist = ''; } } - if(!$artist) + if(!$artist) return false; - + // Url pour les photos $url=$this->xml->get_child_value($node, "URL")."/+images"; if(substr($url,0,4)!="http") $url="http://".$url; $url=str_replace(" ","+",$url); $data = self::getHttpClient()->open_url($url); - + // Bloc des photos $pos=strPos($data,'<ul id="pictures"',0); if(!$pos) return false; @@ -196,23 +219,23 @@ class Class_WebService_Lastfm extends Class_WebService_Abstract { } return $photo; } - + public function getDiscographie($auteur) { $req=$this->getRequete("artist.search","artist",$auteur); if($this->requete($req)==false) return false; - + // Controle de l'auteur $nodes=$this->xml->index["ARTIST"]; if(!$nodes) return false; foreach($nodes as $node) { $artist=$this->xml->get_child_value($node, "NAME"); - if($this->ix->compare_expression($auteur,$artist) == true) break; + if($this->compare_expression($auteur,$artist) == true) break; $artist=""; } if(!$artist) return false; - + // Url pour la discographie $url=$this->xml->get_child_value($node, "URL")."/+albums"; if(substr($url,0,4)!="http") $url="http://".$url; diff --git a/library/Class/WebService/Premiere.php b/library/Class/WebService/Premiere.php index 8c78c85e10672d31c5bfcd34327ff95da022ad45..1c985b05febcd6b7aaee8683e5a5c5025060268d 100644 --- a/library/Class/WebService/Premiere.php +++ b/library/Class/WebService/Premiere.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ ////////////////////////////////////////////////////////////////////////////////////////// // OPAC3 - PREMIERE.fr @@ -24,7 +24,7 @@ class Class_WebService_Premiere { var $url_base; // Urls de base - + function __construct() { $url_base="http://www.premiere.fr"; @@ -43,7 +43,7 @@ class Class_WebService_Premiere { 'texte' => $resume)); return array(); } - + //------------------------------------------------------------------------------------------------------ // Résumé //------------------------------------------------------------------------------------------------------ @@ -101,21 +101,44 @@ class Class_WebService_Premiere { return $img; } -//------------------------------------------------------------------------------------------------------ -// encoder le titre //------------------------------------------------------------------------------------------------------ - function encoder_titre($titre) - { +// encoder le titre +//------------------------------------------------------------------------------------------------------ + function encoder_titre($titre) { // Retirer l'auteur $pos=strscan($titre," / ",0); if($pos >0) $titre=trim(strleft($titre,$pos)); // Clef alphamaj - $ix=new Class_Indexation(); - $titre=$ix->setArticleDebut($titre); - $titre=strtolower($ix->AlphaMaj($titre)); + $titre=$this->setArticleDebut($titre); + $titre=strtolower(Class_Indexation::getInstance()->alphaMaj($titre)); // Formatter avec des tirets $titre=str_replace(" ","-",$titre); $titre=str_replace("--","-",$titre); - return $titre; + return $titre; + } + + + + /** Remet les articles entre parenthèses au début du titre */ + public function setArticleDebut($titre) { + if (substr($titre, -1) != ')') + return $titre; + + foreach($this->articles as $article) { + $compare = '(' . trim($article) . ')'; + $lg = strlen($compare); + if (strtoUpper(substr($titre,-$lg))==$compare) { + $deb = substr($titre, -$lg); + $deb = str_replace("(", "", $article); + $deb = str_replace(")", "", $article); + if (substr($deb,-1) != "'") + $deb .= " "; + $new = $deb.trim(substr($titre, 0, (strlen($titre) - $lg))); + + return $new; + } + } + return $titre; } + } diff --git a/library/storm b/library/storm index 2a7223b57f7209914df1e543fb774996d8cf0779..08c073b2bfde86b0d4d4f4ed3ef8503543fa4506 160000 --- a/library/storm +++ b/library/storm @@ -1 +1 @@ -Subproject commit 2a7223b57f7209914df1e543fb774996d8cf0779 +Subproject commit 08c073b2bfde86b0d4d4f4ed3ef8503543fa4506 diff --git a/tests/application/modules/admin/controllers/AlbumControllerTest.php b/tests/application/modules/admin/controllers/AlbumControllerTest.php index cc6dc75bf6afdd04fcc9e3bfd761a5b50787b28d..9a0a98b81edb02e976aee69fca1938968a9de292 100644 --- a/tests/application/modules/admin/controllers/AlbumControllerTest.php +++ b/tests/application/modules/admin/controllers/AlbumControllerTest.php @@ -1047,7 +1047,9 @@ class Admin_AlbumControllerPostAlbumRenaissanceToPatrimoineTest /** @test */ public function shouldHaveDeweyLectureAndEncyclopedie() { - $this->assertContains('LECTURE ENCYCLOPEDIES', $this->new_notice->getDewey()); + $terms = explode(' ', $this->new_notice->getDewey()); + $this->assertContains('LECTURE', $terms); + $this->assertContains('ENCYCLOPEDIES', $terms); } diff --git a/tests/library/Class/Cosmogramme/Integration/PhaseTestCase.php b/tests/library/Class/Cosmogramme/Integration/PhaseTestCase.php index a55d980fffe006c1c95a902ccce60f216b8c9360..843b408622f10cd59ae2a075bd9952717df8659c 100644 --- a/tests/library/Class/Cosmogramme/Integration/PhaseTestCase.php +++ b/tests/library/Class/Cosmogramme/Integration/PhaseTestCase.php @@ -18,6 +18,10 @@ * along with BOKEH; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + + +require_once('cosmogramme/php/classes/classe_profil_donnees.php'); + abstract class Class_Cosmogramme_Integration_PhaseTestCase extends ModelTestCase { protected $_storm_default_to_volatile = true, @@ -30,6 +34,8 @@ abstract class Class_Cosmogramme_Integration_PhaseTestCase extends ModelTestCase public function setUp() { parent::setUp(); + profil_donnees::clearCache(); + $append_log = function($content) { $this->_log_content .= $content; }; $this->_log = $this->mock() ->whenCalled('addError')->willDo($append_log)