@@ -142,6 +142,7 @@ function process(){
142
142
143
143
$ features = $ this ->retrieveSections ("FEATURES " , $ sectionsRaw );
144
144
$ parsed_features_arr = $ this ->parseFeatures ($ features );
145
+ print_r ($ parsed_features_arr );exit ;
145
146
146
147
//get the source section
147
148
$ source = $ this ->retrieveSections ("SOURCE " , $ sectionsRaw );
@@ -232,33 +233,33 @@ function process(){
232
233
* http://www.insdc.org/documents/feature-table
233
234
*/
234
235
function parseFeatures ($ feature_arr ){
235
- $ rm = array ();
236
+
237
+ $ out = array ();
236
238
//get a copy of the features array
237
239
$ features = $ this ->getFeatures ();
238
240
$ feat_keys = array_keys ($ features );
239
241
foreach ($ feature_arr as $ feat ){
240
242
$ feature_raw = utf8_encode (trim ($ feat ['value ' ]));
241
- echo "\n\n" .$ feature_raw ."\n\n" ;
242
243
243
244
$ arr = explode ("\n" , $ feature_raw );
244
- print_r ( $ arr ); exit ;
245
- if ( strlen ( $ feature_raw ) ){
246
- //remove multiple spaces and newlines
247
- $ feature_raw = preg_replace ( ' /\s\s*/ ' , ' ' , $ feature_raw ) ;
248
- //now construct a regex for every section
249
- $ regex_string = " (.*) " ;
250
- $ regex_groups = array ();
251
- foreach ( $ feat_keys as $ aKey ){
252
- if ( strpos ( $ feature_raw , $ aKey )){
253
- $ regex_string .= " \s+ " . $ aKey . " \s+(.*) " ;
254
- $ regex_groups [] = $ aKey ;
255
- }
256
- } //foreach
257
- $ regex = " / " . $ regex_string . " / " ;
258
- echo "\n" . $ feature_raw . "\n" . $ regex . "\n" ; exit ;
245
+ $ count = 0 ;
246
+ foreach ( $ arr as $ aLine ){
247
+ $ p1 = " /^\s{5}(\S+)\s+(.*)/ " ;
248
+ $ p2 = " /^\s{20,}(.*)/ " ;
249
+ preg_match ( $ p1 , $ aLine , $ m1 );
250
+ preg_match ( $ p2 , $ aLine , $ m2 ) ;
251
+ if ( count ( $ m1 )){
252
+ $ out [ $ count ] = array ( ' type ' => $ m1 [ 1 ], ' value ' => $ m1 [ 2 ]);
253
+ $ count ++;
254
+ continue ;
255
+ }
256
+ if ( count ( $ m2 )){
257
+ $ value = $ out [ $ count - 1 ][ ' value ' ];
258
+ $ out [ $ count - 1 ][ ' value ' ] = $ value . PHP_EOL . $ m2 [ 1 ] ;
259
+ }
259
260
}
260
261
}
261
- return $ rm ;
262
+ return $ out ;
262
263
}
263
264
264
265
/**
0 commit comments