Subversion Repositories eFlore/Applications.cel

Rev

Rev 2459 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2459 Rev 2462
Line 1... Line 1...
1
<?php
1
<?php
2
 
-
 
-
 
2
// declare(encoding='UTF-8');
3
/**
3
/**
-
 
4
 * Classe permettant de convertir une chaine d'un nom scientifique en un format standard.
-
 
5
 *
-
 
6
 * Source orignale :
4
 * Taxamatch-Webservice PHP v1.0.0
7
 * Taxamatch-Webservice PHP v1.0.0
5
 * @author Michael Giddens
8
 * @author Michael Giddens
6
 * @link http://www.silverbiology.com
9
 * @link http://www.silverbiology.com
7
 */
10
 *
8
 
11
 *
9
 /* Adapation par David Delon Decembre 2010 : gestion sous espece
12
 * @internal   Mininum PHP version : 5.2
10
 */
13
 * @category   CEL
11
 
-
 
12
 
-
 
13
/**
14
 * @package    Services
-
 
15
 * @subpackage Bibliothèques
14
 * Class NameParser
16
 * @version    0.1
15
 * Used to convert a string to a standarized format.
17
 * @author     Mathias CHOUET <mathias@tela-botanica.org>
-
 
18
 * @author     David DELON <david@clapas.net>
-
 
19
 * @author     Jean-Pascal MILCENT <jpm@tela-botanica.org>
-
 
20
 * @author     Aurelien PERONNET <aurelien@tela-botanica.org>
-
 
21
 * @license    GPL v3 <http://www.gnu.org/licenses/gpl.txt>
-
 
22
 * @license    CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
-
 
23
 * @copyright  1999-2014 Tela Botanica <accueil@tela-botanica.org>
16
 */
24
 */
17
class NameParser {
25
class NameParser {
Line 18... Line 26...
18
 
26
 
19
	/**
27
	/**
20
	 * Whether to debug or nor
28
	 * Whether to debug or nor
21
	 * @var bool|integer
29
	 * @var bool|integer
22
	 */
30
	 */
Line 23... Line -...
23
	public $debug_flag;
-
 
24
 
-
 
25
 
-
 
26
 
-
 
27
	/**
-
 
28
	 * Constructor 
-
 
29
	 */
-
 
30
	public function __construct( ) {
-
 
31
	}
31
	public $debug_flag;
32
 
32
 
33
	/**
33
	/**
34
	 * Sets value to the method property
34
	 * Sets value to the method property
35
	 * @param mixed $name class property name
35
	 * @param mixed $name class property name
Line 44... Line 44...
44
	 * This will reduce the string to only allow once space between characters
44
	 * This will reduce the string to only allow once space between characters
45
	 * @param string $str : string to reduce space
45
	 * @param string $str : string to reduce space
46
	 * @return string : string with only once space between characters
46
	 * @return string : string with only once space between characters
47
	 */
47
	 */
48
	private function reduce_spaces( $str ) {
48
	private function reduce_spaces($str) {
49
	
-
 
50
		$str = preg_replace("/ {2,}/", ' ', $str );
49
		$str = preg_replace('/ {2,}/', ' ', $str );
51
		$str = trim( $str );
50
		$str = trim( $str );
52
		
-
 
53
		return( $str );
51
		return( $str );
54
	}
52
	}
Line 55... Line 53...
55
 
53
 
56
	/**
54
	/**
Line 71... Line 69...
71
	 * @param string $str : authority string
69
	 * @param string $str : authority string
72
	 * @param integer $upcase : convert to uppercase if $upcase = 1
70
	 * @param integer $upcase : convert to uppercase if $upcase = 1
73
	 * @return string : parsed author string
71
	 * @return string : parsed author string
74
	 */
72
	 */
75
	public function parse_auth( $str, $upcase=1 ) {
73
	public function parse_auth($str, $upcase = 1) {
76
 
-
 
77
		$this->debug['parse_auth'][] = "1";
74
		$this->debug['parse_auth'][] = "1";
78
		$temp = $str = trim($str);
75
		$temp = $str = trim($str);
Line 79... Line 76...
79
			
76
 
80
  		if ( ($str == NULL) || ($str == '') ) {
77
  		if ( ($str == NULL) || ($str == '') ) {
Line 139... Line 136...
139
			$temp = str_replace(' -', '-', $temp);
136
			$temp = str_replace(' -', '-', $temp);
Line 140... Line 137...
140
 
137
 
Line 141... Line 138...
141
			$this->debug['parse_auth'][] = "6 (temp:$temp)";
138
			$this->debug['parse_auth'][] = "6 (temp:$temp)";
142
			
-
 
143
			foreach( explode(' ', $temp) as $this_word ) {
139
 
144
			
140
			foreach (explode(' ', $temp) as $this_word) {
145
				//$this->debug['parse_auth'][] = "7 (this_word:$this_word)";
141
				//$this->debug['parse_auth'][] = "7 (this_word:$this_word)";
146
				$elapsed_chars = '';
142
				$elapsed_chars = '';
147
				//	like '(%'
143
				//	like '(%'
Line 153... Line 149...
153
 
149
 
154
				// Add back the word to the final translation
150
				// Add back the word to the final translation
155
				$elapsed_chars .= $this_word . ' ';
151
				$elapsed_chars .= $this_word . ' ';
156
				//$this->debug['parse_auth'][] = "7c (this_word:$this_word) (elapsed_chars:$elapsed_chars)";
152
				//$this->debug['parse_auth'][] = "7c (this_word:$this_word) (elapsed_chars:$elapsed_chars)";
157
			}
-
 
158
			
153
			}
159
			$elapsed_chars = $this->reduce_spaces( str_replace(' )', ')', $elapsed_chars) );
-
 
160
			
154
			$elapsed_chars = $this->reduce_spaces( str_replace(' )', ')', $elapsed_chars) );
161
			return trim( $elapsed_chars ) ;
155
			return trim( $elapsed_chars ) ;
162
		}
-
 
163
 
156
		}
Line 164... Line 157...
164
	}
157
	}
165
		
158
 
166
	/**
159
	/**
Line 194... Line 187...
194
	 *
187
	 *
195
	 * @param string $str : input string ( genus, genus+species, or genus+species+authority )
188
	 * @param string $str : input string ( genus, genus+species, or genus+species+authority )
196
	 * @return string : parsed string
189
	 * @return string : parsed string
197
	 */
190
	 */
198
	public function parse( $str = NULL ) {
191
	public function parse( $str = NULL ) {
199
		
-
 
200
		unset($this->debug['parse']);
192
		unset($this->debug['parse']);
201
 
-
 
202
		$temp = '';
193
		$temp = '';
203
		$first_str_part = NULL;
194
		$first_str_part = NULL;
204
		$second_str_part = NULL;
195
		$second_str_part = NULL;
205
		$temp_genus = '';
196
		$temp_genus = '';
206
		$temp_species = '';
197
		$temp_species = '';
Line 230... Line 221...
230
			$temp = str_replace( $set, '&', $temp );
221
			$temp = str_replace( $set, '&', $temp );
Line 231... Line 222...
231
 
222
 
Line 232... Line 223...
232
			//$this->debug['parse'][] = "2b1 (temp:$temp)";
223
			//$this->debug['parse'][] = "2b1 (temp:$temp)";
233
 
224
 
234
			// remove any content in angle brackets (e.g. html tags - <i>, </i>, etc.)
225
			// remove any content in angle brackets (e.g. html tags - <i>, </i>, etc.)
235
			$html_pattern = "(\<(/?[^\>]+)\>)";
226
			$html_pattern = '(\<(/?[^\>]+)\>)';
236
			//? This should not just handle html tags but all <*>				
227
			//? This should not just handle html tags but all <*>
Line 237... Line 228...
237
			$temp = preg_replace( $html_pattern, '', $temp);
228
			$temp = preg_replace( $html_pattern, '', $temp);
238
			//$this->debug['parse'][] = "2b2 (temp:$temp)";
229
			//$this->debug['parse'][] = "2b2 (temp:$temp)";
239
 
230
 
240
			// if second term (only) is in round brackets, presume it is a subgenus or a comment and remove it
231
			// if second term (only) is in round brackets, presume it is a subgenus or a comment and remove it
241
			// examples: Barbatia (Mesocibota) bistrigata (Dunker, 1866) => Barbatia bistrigata (Dunker, 1866)
232
			// examples: Barbatia (Mesocibota) bistrigata (Dunker, 1866) => Barbatia bistrigata (Dunker, 1866)
242
			// Barbatia (?) bistrigata (Dunker, 1866) => Barbatia bistrigata (Dunker, 1866)
233
			// Barbatia (?) bistrigata (Dunker, 1866) => Barbatia bistrigata (Dunker, 1866)
243
			// (obviously this will not suit genus + author alone, where first part of authorname is in brackets,
234
			// (obviously this will not suit genus + author alone, where first part of authorname is in brackets,
244
			// however this is very rare?? and in any case we are not supporting genus+authority in this version)
235
			// however this is very rare?? and in any case we are not supporting genus+authority in this version)
245
			//if ( $temp like '% (%)%'
236
			//if ( $temp like '% (%)%'
Line 246... Line 237...
246
			$temp = preg_replace( "/ \(\w*\W*\)/", '', $temp, 1 );
237
			$temp = preg_replace( '/ \(\w*\W*\)/', '', $temp, 1 );
247
			//? Not sure if this will catch if				
238
			//? Not sure if this will catch if
248
			//$this->debug['parse'][] = "2b3 (temp:$temp)";
239
			//$this->debug['parse'][] = "2b3 (temp:$temp)";
249
 
240
 
250
			// if second term (only) is in square brackets, presume it is a comment and remove it
241
			// if second term (only) is in square brackets, presume it is a comment and remove it
251
			// example: Aphis [?] ficus Theobald, [1918] => Aphis ficus Theobald, [1918]		
242
			// example: Aphis [?] ficus Theobald, [1918] => Aphis ficus Theobald, [1918]
Line 252... Line 243...
252
			//if ( $temp like '% [%]%'
243
			//if ( $temp like '% [%]%'
253
			$temp = preg_replace( "/ \[\w*\W*\]/", '', $temp, 1 );
244
			$temp = preg_replace( '/ \[\w*\W*\]/', '', $temp, 1 );
254
			//? Not sure if this will catch if				
245
			//? Not sure if this will catch if
255
			//$this->debug['parse'][] = "2b4 (temp:$temp)";
246
			//$this->debug['parse'][] = "2b4 (temp:$temp)";
256
 
247
 
257
			// drop indicators of questionable id's - presume all are lowercase for now (could extend as needed)
248
			// drop indicators of questionable id's - presume all are lowercase for now (could extend as needed)
258
			$temp = preg_replace( "/ cf /", " ", $temp );
249
			$temp = preg_replace('/ cf /', ' ', $temp );
259
			$temp = preg_replace( "/ cf\. /", " ", $temp );
250
			$temp = preg_replace('/ cf\. /', ' ', $temp );
Line 260... Line 251...
260
			$temp = preg_replace( "/ near /", " ", $temp );
251
			$temp = preg_replace('/ near /', ' ', $temp );
Line 261... Line 252...
261
			$temp = preg_replace( "/ aff\. /", " ", $temp );
252
			$temp = preg_replace('/ aff\. /', ' ', $temp );
262
			$temp = preg_replace( "/ sp\. /", " ", $temp );
253
			$temp = preg_replace('/ sp\. /', ' ', $temp );
Line 271... Line 262...
271
			//$this->debug['parse'][] = "2b6 (temp:$temp)";
262
			//$this->debug['parse'][] = "2b6 (temp:$temp)";
Line 272... Line 263...
272
 
263
 
273
			// now presume first element is genus, second (if present) is species, remainder
264
			// now presume first element is genus, second (if present) is species, remainder
274
			//   (if present) is authority
265
			//   (if present) is authority
275
			// look for genus name
266
			// look for genus name
276
			$ar = explode( " ", $temp, 2);
267
			$ar = explode(' ', $temp, 2);
277
			if ( count( $ar ) ) {
268
			if ( count( $ar ) ) {
278
				$temp_genus = $ar[0];
269
				$temp_genus = $ar[0];
279
				$temp = @$ar[1];
270
				$temp = @$ar[1];
280
			} else {
271
			} else {
Line 283... Line 274...
283
			}
274
			}
Line 284... Line 275...
284
				
275
 
Line 285... Line 276...
285
			//$this->debug['parse'][] = "2b7 (temp_genus:$temp_genus) (temp:$temp)";
276
			//$this->debug['parse'][] = "2b7 (temp_genus:$temp_genus) (temp:$temp)";
286
 
277
 
287
			// look for species epithet and authority
278
			// look for species epithet and authority
288
			$ar = explode( " ", $temp, 2);
279
			$ar = explode(' ', $temp, 2);
289
			if ( count( $ar ) ) {
280
			if ( count( $ar ) ) {
290
				$temp_species = $ar[0];
281
				$temp_species = $ar[0];
291
				$temp_authority = @$ar[1];
282
				$temp_authority = @$ar[1];
Line 312... Line 303...
312
                	$temp_infra=substr($temp_authority,$pos+strlen($infra));
303
					$temp_infra=substr($temp_authority,$pos+strlen($infra));
313
                    $temp_authority=substr($temp_authority,0,$pos);
304
					$temp_authority=substr($temp_authority,0,$pos);
314
                    $temp_infra=trim($temp_infra);
305
					$temp_infra=trim($temp_infra);
315
                    $temp_infra_type=$infra;
306
					$temp_infra_type=$infra;
316
                    // look for infra epithet and authority
307
					// look for infra epithet and authority
317
                    $ar = explode(" ", $temp_infra, 2);
308
					$ar = explode(' ', $temp_infra, 2);
318
                    if ( count( $ar ) ) {
309
					if ( count( $ar ) ) {
319
                    	$temp_infra = $ar[0];
310
						$temp_infra = $ar[0];
320
                        $temp_infra_authority = @$ar[1];
311
						$temp_infra_authority = @$ar[1];
321
                    }
312
					}
322
                    break; // on s'arrete au premier trouve
313
					break; // on s'arrete au premier trouve
Line 351... Line 342...
351
            	$temp_infra_authority=$this->parse_auth($temp_infra_authority);
342
				$temp_infra_authority=$this->parse_auth($temp_infra_authority);
352
            }
343
			}
353
			//$this->debug['parse'][] = "2b11 (temp_genus:$temp_genus) (temp_species:$temp_species) (temp_authority:$temp_authority) (temp_infra:$temp_infra) (temp_infra_authority:$temp_infra_authority) (temp:$temp)";
344
			//$this->debug['parse'][] = "2b11 (temp_genus:$temp_genus) (temp_species:$temp_species) (temp_authority:$temp_authority) (temp_infra:$temp_infra) (temp_infra_authority:$temp_infra_authority) (temp:$temp)";
354
			return array("genus"=>$temp_genus, "species"=>$temp_species, "authority"=>$temp_authority, "infra"=>$temp_infra, "infra_authority"=>$temp_infra_authority, "infra_type"=>$temp_infra_type);	
345
			return array("genus"=>$temp_genus, "species"=>$temp_species, "authority"=>$temp_authority, "infra"=>$temp_infra, "infra_authority"=>$temp_infra_authority, "infra_type"=>$temp_infra_type);
355
		}	
346
		}
356
	} // End NameParser
-
 
357
} // End Class
-
 
358
?>
-
 
359
347
	}
-
 
348
}
-
 
349
360
350