Subversion Repositories eFlore/Applications.cel

Rev

Rev 1080 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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