Subversion Repositories eFlore/Applications.cel

Rev

Rev 995 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 995 Rev 1318
1
<?php
1
<?php
2
 
2
 
3
/**
3
/**
4
 * Taxamatch-Webservice PHP v1.0.0
4
 * Taxamatch-Webservice PHP v1.0.0
5
 * @author Michael Giddens
5
 * @author Michael Giddens
6
 * @link http://www.silverbiology.com
6
 * @link http://www.silverbiology.com
7
 */
7
 */
8
 
8
 
9
 /* Adapation par David Delon Decembre 2010 : gestion sous espece
9
 /* Adapation par David Delon Decembre 2010 : gestion sous espece
10
 */
10
 */
11
 
11
 
12
 
12
 
13
	/**
13
/**
14
	 * Class NameParser
14
 * Class NameParser
15
	 * Used to convert a string to a standarized format.
15
 * Used to convert a string to a standarized format.
16
	 */
16
 */
17
	class NameParser {
17
class NameParser {
18
 
18
 
19
		/**
19
	/**
20
		 * Whether to debug or nor
20
	 * Whether to debug or nor
21
		 * @var bool|integer
21
	 * @var bool|integer
22
		 */
22
	 */
23
		public $debug_flag;
23
	public $debug_flag;
24
 
24
 
25
 
25
 
26
 
26
 
27
		/**
27
	/**
28
		 * Constructor 
28
	 * Constructor 
29
		 */
29
	 */
30
		public function __construct( ) {
30
	public function __construct( ) {
31
		}
31
	}
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
36
		 * @param mixed $value class property value
36
	 * @param mixed $value class property value
37
		 */
37
	 */
38
		public function set($name,$value) {
38
	public function set($name,$value) {
39
			$this->$name = $value;
39
		$this->$name = $value;
40
		}
40
	}
41
 
-
 
42
 
41
 
43
		/**
42
	/**
44
		 * Reduce Spaces
43
	 * Reduce Spaces
45
		 * 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
46
		 * @param string $str : string to reduce space
45
	 * @param string $str : string to reduce space
47
		 * @return string : string with only once space between characters
46
	 * @return string : string with only once space between characters
48
		 */
47
	 */
49
		private function reduce_spaces( $str ) {
48
	private function reduce_spaces( $str ) {
50
		
49
	
51
			$str = preg_replace("/ {2,}/", ' ', $str );
50
		$str = preg_replace("/ {2,}/", ' ', $str );
52
			$str = trim( $str );
51
		$str = trim( $str );
53
			
52
		
54
			return( $str );
53
		return( $str );
55
		}
54
	}
56
 
-
 
57
 
55
 
58
		/**
56
	/**
59
		 * Function: parse_auth
57
	 * Function: parse_auth
60
		 * Purpose: Produce a parsed version of authority of a taxon name
58
	 * Purpose: Produce a parsed version of authority of a taxon name
61
		 * @author Tony Rees (Tony.Rees@csiro.au)
59
	 * @author Tony Rees (Tony.Rees@csiro.au)
62
		 * Date created: March 2008
60
	 * Date created: March 2008
63
		 * Inputs: authority string as str
61
	 * Inputs: authority string as str
64
		 * Remarks:
62
	 * Remarks:
65
		 *  (1) Performs authority expension of known abbreviated authornames using
63
	 *  (1) Performs authority expension of known abbreviated authornames using
66
		 *   table "auth_abbrev_test1" (must be available and populated with relevant content)
64
	 *   table "auth_abbrev_test1" (must be available and populated with relevant content)
67
		 *  (2) Recognises "and", "et", "&" as equivalents (special case for "et al.") - all parsed to ampersand
65
	 *  (2) Recognises "and", "et", "&" as equivalents (special case for "et al.") - all parsed to ampersand
68
		 *  (3) Recognises (e.g.) "Smith 1980" and "Smith, 1980" as equivalents - comma is removed in these cases
66
	 *  (3) Recognises (e.g.) "Smith 1980" and "Smith, 1980" as equivalents - comma is removed in these cases
69
		 *  (4) Recognises (e.g.) "F. J. R. Taylor, 1980" and "F.J.R. Taylor, 1980" as equivalents -
67
	 *  (4) Recognises (e.g.) "F. J. R. Taylor, 1980" and "F.J.R. Taylor, 1980" as equivalents -
70
		 *      extra space after full stops is ignored in these cases
68
	 *      extra space after full stops is ignored in these cases
71
		 *  (5) Returns uppercase string, diacritical marks intact
69
	 *  (5) Returns uppercase string, diacritical marks intact
72
		 *
70
	 *
73
		 * @param string $str : authority string
71
	 * @param string $str : authority string
74
		 * @param integer $upcase : convert to uppercase if $upcase = 1
72
	 * @param integer $upcase : convert to uppercase if $upcase = 1
75
		 * @return string : parsed author string
73
	 * @return string : parsed author string
76
		 */
74
	 */
77
		public function parse_auth( $str, $upcase=1 ) {
75
	public function parse_auth( $str, $upcase=1 ) {
78
 
76
 
79
			$this->debug['parse_auth'][] = "1";
77
		$this->debug['parse_auth'][] = "1";
80
			$temp = $str = trim($str);
78
		$temp = $str = trim($str);
81
			
79
			
82
  		if ( ($str == NULL) || ($str == '') ) {
80
  		if ( ($str == NULL) || ($str == '') ) {
83
				$this->debug['parse_auth'][] = "1a";
81
				$this->debug['parse_auth'][] = "1a";
84
		    return '';
82
		    return '';
85
			}
83
		}
86
 
84
 
87
			if ( ( $temp == null ) || ( $temp == '') ) {
85
		if ( ( $temp == null ) || ( $temp == '') ) {
88
				$this->debug['parse_auth'][] = "2a";
86
			$this->debug['parse_auth'][] = "2a";
89
				return('');
87
			return('');
90
			} else {
88
		} else {
91
 
89
 
92
				$this->debug['parse_auth'][] = "2b";
90
			$this->debug['parse_auth'][] = "2b";
93
			
91
		
94
				// add space after full stops, except at end (NB, will also add spece before some close brackets)
92
			// add space after full stops, except at end (NB, will also add spece before some close brackets)
95
				$temp = rtrim( str_replace('.', '. ', $temp) );
93
			$temp = rtrim( str_replace('.', '. ', $temp) );
96
				$this->debug['parse_auth'][] = "4 (temp:$temp)";
94
			$this->debug['parse_auth'][] = "4 (temp:$temp)";
97
				
95
				
98
				//normalise "et", "and" to ampersand (et al. is a special case)
96
			//normalise "et", "and" to ampersand (et al. is a special case)
99
//				if ( $temp like '% et al%' ) {
97
			// if ( $temp like '% et al%' ) {
100
				if ( preg_match('/ et al/', $temp) ) {
98
			if ( preg_match('/ et al/', $temp) ) {
101
					$temp = str_replace(' et al','zzzzz', $temp);
99
				$temp = str_replace(' et al','zzzzz', $temp);
102
					$this->debug['parse_auth'][] = "4a (temp:$temp)";
100
				$this->debug['parse_auth'][] = "4a (temp:$temp)";
103
				}
101
			}
104
				
102
				
105
				$temp = str_replace(' et ',' & ', $temp );
103
			$temp = str_replace(' et ',' & ', $temp );
106
				$temp = str_replace(' and ',' & ', $temp );
104
			$temp = str_replace(' and ',' & ', $temp );
107
 
105
 
108
				$temp = str_replace('zzzzz',' et al', $temp);
106
			$temp = str_replace('zzzzz',' et al', $temp);
109
 
107
 
110
				$this->debug['parse_auth'][] = "5 (temp:$temp)";
108
			$this->debug['parse_auth'][] = "5 (temp:$temp)";
111
				
109
				
112
				//remove commas before dates (only)
110
			//remove commas before dates (only)
113
				//	like '%, 17%'
111
			//	like '%, 17%'
114
				if ( preg_match('/, 17/', $temp) ) {
112
			if ( preg_match('/, 17/', $temp) ) {
115
					$temp = str_replace(', 17',' 17', $temp);
113
				$temp = str_replace(', 17',' 17', $temp);
116
					$this->debug['parse_auth'][] = "5a (temp:$temp)";
114
				$this->debug['parse_auth'][] = "5a (temp:$temp)";
117
				}
115
			}
118
				
116
			
119
				//	like '%, 18%'
117
			//	like '%, 18%'
120
				if ( preg_match('/, 18/', $temp) ) {
118
			if ( preg_match('/, 18/', $temp) ) {
121
					$temp = str_replace(', 18',' 18', $temp);
119
				$temp = str_replace(', 18',' 18', $temp);
122
					$this->debug['parse_auth'][] = "5b (temp:$temp)";
120
				$this->debug['parse_auth'][] = "5b (temp:$temp)";
123
				}
121
			}
124
				
122
				
125
				//	like '%, 19%'
123
			//	like '%, 19%'
126
				if ( preg_match('/, 19/', $temp) ) {
124
			if ( preg_match('/, 19/', $temp) ) {
127
					$temp = str_replace(', 19',' 19', $temp);
125
				$temp = str_replace(', 19',' 19', $temp);
128
					$this->debug['parse_auth'][] = "5c (temp:$temp)";
126
				$this->debug['parse_auth'][] = "5c (temp:$temp)";
129
				}
127
			}
130
				
128
			
131
				//	like '%, 20%'
129
			//	like '%, 20%'
132
				if ( preg_match('/, 20/', $temp) ) {
130
			if ( preg_match('/, 20/', $temp) ) {
133
					$temp = str_replace(', 20',' 20', $temp);
131
				$temp = str_replace(', 20',' 20', $temp);
134
					$this->debug['parse_auth'][] = "5d (temp:$temp)";
132
				$this->debug['parse_auth'][] = "5d (temp:$temp)";
135
				}
133
			}
136
				
134
				
137
				// reduce multiple internal spaces to single space
135
			// reduce multiple internal spaces to single space
138
				$temp = $this->reduce_spaces( $temp );
136
			$temp = $this->reduce_spaces( $temp );
139
				
137
			
140
				//	like '% -%'
138
			//	like '% -%'
141
				$temp = str_replace(' -', '-', $temp);
139
			$temp = str_replace(' -', '-', $temp);
142
 
140
 
143
				$this->debug['parse_auth'][] = "6 (temp:$temp)";
141
			$this->debug['parse_auth'][] = "6 (temp:$temp)";
144
				
142
			
145
				foreach( explode(' ', $temp) as $this_word ) {
143
			foreach( explode(' ', $temp) as $this_word ) {
146
				
144
			
147
					$this->debug['parse_auth'][] = "7 (this_word:$this_word)";
-
 
-
 
145
				//$this->debug['parse_auth'][] = "7 (this_word:$this_word)";
148
					
146
				$elapsed_chars = '';
149
					//	like '(%'
147
				//	like '(%'
150
					if ( preg_match('/^\(/', $this_word) ) {
148
				if ( preg_match('/^\(/', $this_word) ) {
151
						$elapsed_chars .= '(';
149
					$elapsed_chars .= '(';
152
						$this_word = substr( $this_word, 1 );
150
					$this_word = substr( $this_word, 1 );
153
						$this->debug['parse_auth'][] = "7a (this_word:$this_word) (elapsed_chars:$elapsed_chars)";
151
					//$this->debug['parse_auth'][] = "7a (this_word:$this_word) (elapsed_chars:$elapsed_chars)";
154
					}
152
				}
155
 
153
 
156
					// Add back the word to the final translation
154
				// Add back the word to the final translation
157
					$elapsed_chars .= $this_word . ' ';
155
				$elapsed_chars .= $this_word . ' ';
158
					$this->debug['parse_auth'][] = "7c (this_word:$this_word) (elapsed_chars:$elapsed_chars)";
156
				//$this->debug['parse_auth'][] = "7c (this_word:$this_word) (elapsed_chars:$elapsed_chars)";
159
				}
157
			}
160
				
158
			
161
				$elapsed_chars = $this->reduce_spaces( str_replace(' )', ')', $elapsed_chars) );
159
			$elapsed_chars = $this->reduce_spaces( str_replace(' )', ')', $elapsed_chars) );
162
				
160
			
163
				return trim( $elapsed_chars ) ;
161
			return trim( $elapsed_chars ) ;
164
			}
162
		}
165
 
163
 
166
		}
164
	}
167
		
165
		
168
		/**
166
	/**
169
		 * Function: parse
167
	 * Function: parse
170
		 * Purpose: Produces parsed version of an input string (scientific name components)
168
	 * Purpose: Produces parsed version of an input string (scientific name components)
171
		 * @author Tony Rees (Tony.Rees@csiro.au)
169
	 * @author Tony Rees (Tony.Rees@csiro.au)
172
		 * Date created: June 2007-November 2008
170
	 * Date created: June 2007-November 2008
173
		 * Inputs: input string as str (this version presumes genus, genus+species, or
171
	 * Inputs: input string as str (this version presumes genus, genus+species, or
174
		 * genus+species+authority)
172
	 * genus+species+authority)
175
		 * Outputs: parsed version of input string, for match purposes
173
	 * Outputs: parsed version of input string, for match purposes
176
		 * Remarks:
174
	 * Remarks:
177
		 *    (1) Removes known text elements e.g.
175
	 *    (1) Removes known text elements e.g.
178
		 *      'aff.', 'cf.', 'subsp.', subgenera if enclosed in brackets, etc. as desired
176
	 *      'aff.', 'cf.', 'subsp.', subgenera if enclosed in brackets, etc. as desired
179
		 *    (2) Removes accented and non A-Z characters other than full stops 
177
	 *    (2) Removes accented and non A-Z characters other than full stops 
180
		 *       (in scientific name portions)
178
	 *       (in scientific name portions)
181
		 *    (3) Returns uppercase scientific name (genus + species only) 
179
	 *    (3) Returns uppercase scientific name (genus + species only) 
182
		 *       plus unaltered (presumed) authority
180
	 *       plus unaltered (presumed) authority
183
		 *     examples;
181
	 *     examples;
184
		 *       Anabaena cf. flos-aquae Ralfs ex Born. et Flah. => ANABAENA FLOSAQUAE Ralfs 
182
	 *       Anabaena cf. flos-aquae Ralfs ex Born. et Flah. => ANABAENA FLOSAQUAE Ralfs 
185
		 *       ex Born. et Flah.
183
	 *       ex Born. et Flah.
186
		 *       Abisara lemÈe-pauli => ABISARA LEMEEPAULI
184
	 *       Abisara lemÈe-pauli => ABISARA LEMEEPAULI
187
		 *       Fuc/us Vesiculos2us => FUCUS VESICULOSUS
185
	 *       Fuc/us Vesiculos2us => FUCUS VESICULOSUS
188
		 *       Buffo ignicolor LacÈpËde, 1788 => BUFFO IGNICOLOR LacÈpËde, 1788
186
	 *       Buffo ignicolor LacÈpËde, 1788 => BUFFO IGNICOLOR LacÈpËde, 1788
189
		 *       Barbatia (Mesocibota) bistrigata (Dunker, 1866) => BARBATIA BISTRIGATA (Dunker, 1866)
187
	 *       Barbatia (Mesocibota) bistrigata (Dunker, 1866) => BARBATIA BISTRIGATA (Dunker, 1866)
190
		 *    (4) Thus version does not handle genus+author, or genus+species+infraspecies
188
	 *    (4) Thus version does not handle genus+author, or genus+species+infraspecies
191
		 *       (second" good" term is presumed to be species epithet, anything after is 
189
	 *       (second" good" term is presumed to be species epithet, anything after is 
192
		 *       considered to be start of the authority), however could be adapted further as required
190
	 *       considered to be start of the authority), however could be adapted further as required
193
         *         and actually it was done in this version for Tela Botanica
191
     *         and actually it was done in this version for Tela Botanica
194
		 *    (5) There is a separate function "parse_auth" for normalizing authorities when required
192
	 *    (5) There is a separate function "parse_auth" for normalizing authorities when required
195
		 *      (e.g. for authority comparisons)
193
	 *      (e.g. for authority comparisons)
196
		 *
194
	 *
197
		 * @param string $str : input string ( genus, genus+species, or genus+species+authority )
195
	 * @param string $str : input string ( genus, genus+species, or genus+species+authority )
198
		 * @return string : parsed string
196
	 * @return string : parsed string
199
		 */
197
	 */
200
		public function parse( $str = NULL ) {
198
	public function parse( $str = NULL ) {
201
			
199
		
202
			unset($this->debug['parse']);
200
		unset($this->debug['parse']);
203
 
-
 
204
 
201
 
205
			$temp = '';
202
		$temp = '';
206
			$first_str_part = NULL;
203
		$first_str_part = NULL;
207
			$second_str_part = NULL;
204
		$second_str_part = NULL;
208
			$temp_genus = '';
205
		$temp_genus = '';
209
			$temp_species = '';
206
		$temp_species = '';
210
			$temp_genus_species = '';
207
		$temp_genus_species = '';
211
			$temp_authority = '';
208
		$temp_authority = '';
212
			$temp_infra = '';
209
		$temp_infra = '';
213
			
210
			
214
			$this->debug['parse'][] = "1";
211
		//$this->debug['parse'][] = "1";
215
 
212
 
216
			if ( ($str == NULL) || ( trim($str) == '') ) {
213
		if ( ($str == NULL) || ( trim($str) == '') ) {
217
				$this->debug[] = "N1a<br>";
214
			//$this->debug[] = "N1a<br>";
218
				return '';
215
			return '';
219
			} else {
216
		} else {
220
				//	trim any leading, trailing spaces or line feeds
217
			//	trim any leading, trailing spaces or line feeds
221
				$temp = trim( $str );
218
			$temp = trim( $str );
222
				$this->debug['parse'][] = "1b";
219
			//$this->debug['parse'][] = "1b";
223
			}
220
		}
224
 
221
 
225
			if ( $temp == NULL || $temp == '') {
222
		if ( $temp == NULL || $temp == '') {
226
				$this->debug['parse'][] = "2a";
223
			//$this->debug['parse'][] = "2a";
227
				return '';
224
			return '';
228
			} else {
225
		} else {
229
				$this->debug['parse'][] = "2b";
226
			//$this->debug['parse'][] = "2b";
230
 
227
 
231
				// replace any HTML ampersands
228
			// replace any HTML ampersands
232
				$set = array('%', '&', 'amp;%', 'AMP;%');
229
			$set = array('%', '&', 'amp;%', 'AMP;%');
233
				$temp = str_replace( $set, '&', $temp );
230
			$temp = str_replace( $set, '&', $temp );
234
 
231
 
235
				$this->debug['parse'][] = "2b1 (temp:$temp)";
232
			//$this->debug['parse'][] = "2b1 (temp:$temp)";
236
 
233
 
237
				// remove any content in angle brackets (e.g. html tags - <i>, </i>, etc.)
234
			// remove any content in angle brackets (e.g. html tags - <i>, </i>, etc.)
238
				$html_pattern = "(\<(/?[^\>]+)\>)";
235
			$html_pattern = "(\<(/?[^\>]+)\>)";
239
//? This should not just handle html tags but all <*>				
236
			//? This should not just handle html tags but all <*>				
240
				$temp = preg_replace( $html_pattern, '', $temp);
237
			$temp = preg_replace( $html_pattern, '', $temp);
241
				$this->debug['parse'][] = "2b2 (temp:$temp)";
238
			//$this->debug['parse'][] = "2b2 (temp:$temp)";
242
 
239
 
243
				// if second term (only) is in round brackets, presume it is a subgenus or a comment and remove it
240
			// if second term (only) is in round brackets, presume it is a subgenus or a comment and remove it
244
				// examples: Barbatia (Mesocibota) bistrigata (Dunker, 1866) => Barbatia bistrigata (Dunker, 1866)
241
			// examples: Barbatia (Mesocibota) bistrigata (Dunker, 1866) => Barbatia bistrigata (Dunker, 1866)
245
				// Barbatia (?) bistrigata (Dunker, 1866) => Barbatia bistrigata (Dunker, 1866)
242
			// Barbatia (?) bistrigata (Dunker, 1866) => Barbatia bistrigata (Dunker, 1866)
246
				// (obviously this will not suit genus + author alone, where first part of authorname is in brackets,
243
			// (obviously this will not suit genus + author alone, where first part of authorname is in brackets,
247
				// however this is very rare?? and in any case we are not supporting genus+authority in this version)
244
			// however this is very rare?? and in any case we are not supporting genus+authority in this version)
248
//if ( $temp like '% (%)%'
245
			//if ( $temp like '% (%)%'
249
				$temp = preg_replace( "/ \(\w*\W*\)/", '', $temp, 1 );
246
			$temp = preg_replace( "/ \(\w*\W*\)/", '', $temp, 1 );
250
//? Not sure if this will catch if				
247
			//? Not sure if this will catch if				
251
				$this->debug['parse'][] = "2b3 (temp:$temp)";
248
			//$this->debug['parse'][] = "2b3 (temp:$temp)";
252
 
249
 
253
				// if second term (only) is in square brackets, presume it is a comment and remove it
250
			// if second term (only) is in square brackets, presume it is a comment and remove it
254
				// example: Aphis [?] ficus Theobald, [1918] => Aphis ficus Theobald, [1918]		
251
			// example: Aphis [?] ficus Theobald, [1918] => Aphis ficus Theobald, [1918]		
255
//if ( $temp like '% [%]%'
252
			//if ( $temp like '% [%]%'
256
				$temp = preg_replace( "/ \[\w*\W*\]/", '', $temp, 1 );
253
			$temp = preg_replace( "/ \[\w*\W*\]/", '', $temp, 1 );
257
//? Not sure if this will catch if				
254
			//? Not sure if this will catch if				
258
				$this->debug['parse'][] = "2b4 (temp:$temp)";
255
			//$this->debug['parse'][] = "2b4 (temp:$temp)";
259
 
256
 
260
				// drop indicators of questionable id's - presume all are lowercase for now (could extend as needed)
257
			// drop indicators of questionable id's - presume all are lowercase for now (could extend as needed)
261
				$temp = preg_replace( "/ cf /", " ", $temp );
258
			$temp = preg_replace( "/ cf /", " ", $temp );
262
				$temp = preg_replace( "/ cf\. /", " ", $temp );
259
			$temp = preg_replace( "/ cf\. /", " ", $temp );
263
				$temp = preg_replace( "/ near /", " ", $temp );
260
			$temp = preg_replace( "/ near /", " ", $temp );
264
				$temp = preg_replace( "/ aff\. /", " ", $temp );
261
			$temp = preg_replace( "/ aff\. /", " ", $temp );
265
				$temp = preg_replace( "/ sp\. /", " ", $temp );
262
			$temp = preg_replace( "/ sp\. /", " ", $temp );
266
				$temp = preg_replace( "/ spp\. /", " ", $temp );
263
			$temp = preg_replace( "/ spp\. /", " ", $temp );
267
				$temp = preg_replace( "/ spp /", " ", $temp );
264
			$temp = preg_replace( "/ spp /", " ", $temp );
268
 
265
 
269
				$this->debug['parse'][] = "2b5 (temp:$temp)";
266
			//$this->debug['parse'][] = "2b5 (temp:$temp)";
270
 
267
 
271
				// eliminate or close up any stray spaces introduced by the above
268
			// eliminate or close up any stray spaces introduced by the above
272
				$temp = $this->reduce_spaces( $temp );
269
			$temp = $this->reduce_spaces( $temp );
273
 
270
 
274
				$this->debug['parse'][] = "2b6 (temp:$temp)";
271
			//$this->debug['parse'][] = "2b6 (temp:$temp)";
275
 
272
 
276
				// now presume first element is genus, second (if present) is species, remainder
273
			// now presume first element is genus, second (if present) is species, remainder
277
				//   (if present) is authority
274
			//   (if present) is authority
278
				// look for genus name
275
			// look for genus name
279
				$ar = explode( " ", $temp, 2);
276
			$ar = explode( " ", $temp, 2);
280
				if ( count( $ar ) ) {
277
			if ( count( $ar ) ) {
281
					$temp_genus = $ar[0];
278
				$temp_genus = $ar[0];
282
					$temp = @$ar[1];
279
				$temp = @$ar[1];
283
				} else {
280
			} else {
284
					$temp_genus = $temp;
281
				$temp_genus = $temp;
285
					$temp = '';
282
				$temp = '';
286
				}
283
			}
287
				
284
				
288
				$this->debug['parse'][] = "2b7 (temp_genus:$temp_genus) (temp:$temp)";
285
			//$this->debug['parse'][] = "2b7 (temp_genus:$temp_genus) (temp:$temp)";
289
 
286
 
290
				// look for species epithet and authority
287
			// look for species epithet and authority
291
				$ar = explode( " ", $temp, 2);
288
			$ar = explode( " ", $temp, 2);
292
				if ( count( $ar ) ) {
289
			if ( count( $ar ) ) {
293
					$temp_species = $ar[0];
290
				$temp_species = $ar[0];
294
					$temp_authority = @$ar[1];
291
				$temp_authority = @$ar[1];
295
				} else {
292
			} else {
296
					$temp_species = $temp;
293
				$temp_species = $temp;
297
					$temp_authority = '';
294
				$temp_authority = '';
298
				}
295
			}
299
               	// look for subspecies
296
            // look for subspecies
300
 
297
 
301
                $infras =array('subsp.','var.');
298
            $infras =array('subsp.','var.');
302
 
299
 
303
                $temp_authority = preg_replace( "/ssp./", "subsp.", $temp_authority);
300
            $temp_authority = preg_replace( "/ssp./", "subsp.", $temp_authority);
304
                $temp_authority = preg_replace( "/ssp /", "subsp.", $temp_authority);
301
            $temp_authority = preg_replace( "/ssp /", "subsp.", $temp_authority);
305
                $temp_authority = preg_replace( "/subsp /", "subsp.", $temp_authority);
302
            $temp_authority = preg_replace( "/subsp /", "subsp.", $temp_authority);
306
                $temp_authority = preg_replace( "/var /", "var.", $temp_authority);
303
            $temp_authority = preg_replace( "/var /", "var.", $temp_authority);
-
 
304
 
-
 
305
            $temp_infra_authority = '';
307
 
306
            $temp_infra_type = '';
308
                foreach ($infras as $infra) {
307
            foreach ($infras as $infra) {
309
                    $pos = strpos($temp_authority, $infra);
308
            	$pos = strpos($temp_authority, $infra);
310
                    if ($pos === false) {
309
                if ($pos === false) {
311
                        continue;
310
                	continue;
312
                    }
-
 
313
                    else {
311
                } else {
314
                        $temp_infra=substr($temp_authority,$pos+strlen($infra));
312
                	$temp_infra=substr($temp_authority,$pos+strlen($infra));
315
                        $temp_authority=substr($temp_authority,0,$pos);
313
                    $temp_authority=substr($temp_authority,0,$pos);
316
                        $temp_infra=trim($temp_infra);
314
                    $temp_infra=trim($temp_infra);
317
                        $temp_infra_type=$infra;
315
                    $temp_infra_type=$infra;
318
                        // look for infra epithet and authority
316
                    // look for infra epithet and authority
319
                        $ar = explode(" ", $temp_infra, 2);
317
                    $ar = explode(" ", $temp_infra, 2);
320
                        if ( count( $ar ) ) {
318
                    if ( count( $ar ) ) {
321
                            $temp_infra = $ar[0];
319
                    	$temp_infra = $ar[0];
322
                            $temp_infra_authority = @$ar[1];
320
                        $temp_infra_authority = @$ar[1];
323
                        }
321
                    }
324
                        break; // on s'arrete au premier trouve
322
                    break; // on s'arrete au premier trouve
325
                    }
323
                }
326
                }
324
			}
327
 
325
 
328
				$this->debug['parse'][] = "2b8 (temp_genus:$temp_genus) (temp_species:$temp_species) (temp_authority:$temp_authority) (temp_infra:$temp_infra) (temp_infra_authority:$temp_infra_authority) (temp:$temp)";
-
 
329
 
326
			//$this->debug['parse'][] = "2b8 (temp_genus:$temp_genus) (temp_species:$temp_species) (temp_authority:$temp_authority) (temp_infra:$temp_infra) (temp_infra_authority:$temp_infra_authority) (temp:$temp)";
330
 
327
 
331
				// replace selected ligatures here (Genus names can contain Æ, OE ligature)
328
			// replace selected ligatures here (Genus names can contain Æ, OE ligature)
332
				$temp_genus = str_replace( 'Æ', 'AE', $temp_genus);
329
			$temp_genus = str_replace( 'Æ', 'AE', $temp_genus);
333
				$temp_species = str_replace( 'Æ', 'AE', $temp_species);
330
			$temp_species = str_replace( 'Æ', 'AE', $temp_species);
334
				$temp_infra = str_replace( 'Æ', 'AE', $temp_infra );
331
			$temp_infra = str_replace( 'Æ', 'AE', $temp_infra );
335
				
-
 
336
 
332
 
337
				$this->debug['parse'][] = "2b9 (temp_genus:$temp_genus) (temp_species:$temp_species) (temp_authority:$temp_authority) (temp_infra:$temp_infra) (temp_infra_authority:$temp_infra_authority) (temp:$temp)";
333
			//$this->debug['parse'][] = "2b9 (temp_genus:$temp_genus) (temp_species:$temp_species) (temp_authority:$temp_authority) (temp_infra:$temp_infra) (temp_infra_authority:$temp_infra_authority) (temp:$temp)";
338
 
334
 
339
                $temp_genus= trim($temp_genus);
335
            $temp_genus= trim($temp_genus);
340
				$temp_species= trim($temp_species);
336
			$temp_species= trim($temp_species);
341
				$temp_infra= trim($temp_infra );
337
			$temp_infra= trim($temp_infra );
342
 
338
 
343
				// reduce any new multiple internal spaces to single space, if present
339
			// reduce any new multiple internal spaces to single space, if present
344
                $temp_genus= $this->reduce_spaces( $temp_genus );
340
            $temp_genus= $this->reduce_spaces( $temp_genus );
345
				$temp_species= $this->reduce_spaces( $temp_species );
341
			$temp_species= $this->reduce_spaces( $temp_species );
346
				$temp_infra= $this->reduce_spaces( $temp_infra );
342
			$temp_infra= $this->reduce_spaces( $temp_infra );
347
 
343
 
348
				$this->debug['parse'][] = "2b10 (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'][] = "2b10 (temp_genus:$temp_genus) (temp_species:$temp_species) (temp_authority:$temp_authority) (temp_infra:$temp_infra) (temp_infra_authority:$temp_infra_authority) (temp:$temp)";
349
 
345
 
350
                if (isset($temp_authority) && ($temp_authority!='') ) {
346
            if (isset($temp_authority) && ($temp_authority!='') ) {
351
                    $temp_authority=$this->parse_auth($temp_authority);
347
            	$temp_authority=$this->parse_auth($temp_authority);
352
                }
348
            }
353
 
349
 
354
                if (isset($temp_infra_authority) && ($temp_infra_authority!='') ) {
350
            if (isset($temp_infra_authority) && ($temp_infra_authority!='') ) {
355
                    $temp_infra_authority=$this->parse_auth($temp_infra_authority);
351
            	$temp_infra_authority=$this->parse_auth($temp_infra_authority);
356
                }
352
            }
357
 
-
 
358
 
-
 
359
				$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)";
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)";
360
 
-
 
361
				return array("genus"=>$temp_genus, "species"=>$temp_species, "authority"=>$temp_authority, "infra"=>$temp_infra, "infra_authority"=>$temp_infra_authority, "infra_type"=>$temp_infra_type);
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);	
362
				
-
 
363
			}
355
		}	
364
			
-
 
365
		} // End NameParser
356
	} // End NameParser
366
 
-
 
367
		
-
 
368
		
-
 
369
	} // End Class
357
} // End Class
370
 
-
 
371
?>
358
?>