/** * Genera i files di testo degli atti * $prefix/$atto_id */ function run_nltk_genera_files($task, $args, $options) { static $loaded; // load application context if (!$loaded) { _loader(); } $files_path = sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR . "nltk"; $act_types = array(); $prefix = null; // usato per differenziare training, test e dev, è aggiunto prima dell'id $offset = null; $limit = null; if (array_key_exists('offset', $options)) { $offset = $options['offset']; } if (array_key_exists('limit', $options)) { $limit = $options['limit']; } if (array_key_exists('path', $options)) { $files_path = strtolower($options['path']); } if (array_key_exists('types', $options)) { $act_types = explode(",", $options['types']); } if (array_key_exists('prefix', $options)) { $prefix = strtolower($options['prefix']); } if (count($args) > 0) { try { $atti_rs = OppAttoPeer::getRSFromIDArray($args); } catch (Exception $e) { throw new Exception("Specificare degli ID validi. \n" . $e); } } else { $atti_rs = OppAttoPeer::getAttiTipoRS($act_types, $offset, $limit); } echo "memory usage: " . memory_get_usage() . "\n"; $start_time = time(); $msg = sprintf("generazione files dei testi degli atti\n"); echo pakeColor::colorize($msg, array('fg' => 'cyan', 'bold' => true)); // loop principale $n_atti = $atti_rs->getRecordCount(); $cnt = 0; while ($atti_rs->next()) { $a = $atti_rs->getRow(); $atto_id = $a['id']; $tipo_atto_id = $a['tipo_atto_id']; $atto = OppAttoPeer::retrieveByPK($atto_id); if ($n_docs = $atto->countOppDocumentos()) { $docs = $atto->getOppDocumentos(); // path di tutti i testi dei doc relativi all'atto $atto_txt = ""; foreach ($docs as $doc) { $atto_txt .= $doc->getTesto(); } unset($docs); $fh = fopen($files_path . "/" . $atto_id, 'w'); fwrite($fh, $atto_txt); fclose($fh); } printf(" %d %d docs - ok (%d)\n", $atto_id, $n_docs, memory_get_usage()); unset($atto); $cnt++; } $msg = sprintf("%d atti elaborati\n", $cnt); echo pakeColor::colorize($msg, array('fg' => 'cyan', 'bold' => true)); $msg = sprintf(" [%4d sec] [%10d bytes]\n", time() - $start_time, memory_get_usage()); echo pakeColor::colorize($msg, array('fg' => 'red', 'bold' => false)); }