Exemplo n.º 1
0
while (($field = fgetcsv($handle, 1000, ",")) !== FALSE) {
    if (!isset($field[0]) || $field[0] == '') {
        continue;
    }
    $ta = new TnrsAggregator($db);
    $tm = new Taxamatch($db);
    $tm->set('debug_flag', '');
    $tm->set('output_type', '');
    $tm->set('cache_flag', false);
    $tm->set('cache_path', CACHE_PATH);
    $tm->set('name_parser', NAME_PARSER);
    $tm->set('chop_overload', CHOP_OVERLOAD);
    $tm->set('parse_only', $parse_only);
    $name = escapeshellarg($field[0]);
    if ($tm->process($name, $search_mode, $cache) && !$parse_only) {
        $tm->generateResponse($cache);
    }
    $ta->aggregate($tm);
    $result = $ta->getData();
    foreach ($result as $re) {
        if (isset($count)) {
            array_unshift($re, $count);
        }
        fputcsv($outfh, $re);
    }
    unset($result);
    $count++;
}
fclose($outfh);
?>
Exemplo n.º 2
0
 /**
  * This is the function that process the input csv file and does the work.
  * @param string $output_type : output type
  */
 public function process($output_type = 'file')
 {
     // Assign File
     if (file_exists($this->data['input_file'])) {
         $this->handle_input = fopen($this->data['input_file'], "r");
     } else {
         return false;
     }
     $this->handle_output = fopen($this->data['output_file'], "w");
     // Build Header
     $this->build_new_header();
     // Writes column header in 1st row of output.
     $this->write_header();
     /**
      *	This will run through the whole data and build the Higer Taxa with
      * parentID relationship to be used in the final species list.
      */
     $db = select_source($this->data['source']);
     $search_mode = 'normal';
     while (($row = fgetcsv($this->handle_input, 100000, $this->file_delimiter)) !== FALSE) {
         // Call taxamatch and process row
         $tm = new Taxamatch($db);
         if ($tm->process($row[$this->scientificNameIndex], $search_mode)) {
             $tm->generateResponse($cache);
         }
         $data = $tm->getData('flat');
         if (is_array($data)) {
             foreach ($data as $r) {
                 fputcsv($this->handle_output, array_merge($row, $r), $this->file_delimiter);
             }
         }
     }
     fclose($this->handle_output);
     fclose($this->handle_input);
 }