Exemple #1
0
 private function generate($task_id, $filepath = false)
 {
     $task = $this->Task->getById($task_id);
     if ($task === false || in_array($task->ttid, $this->task_types) === false) {
         die('Task not providing datasplits.');
     }
     $values = $this->Task_inputs->getTaskValuesAssoc($task_id);
     $estimation_procedure = null;
     if (array_key_exists('estimation_procedure', $values)) {
         $estimation_procedure = $this->Estimation_procedure->getById($values['estimation_procedure']);
     }
     if ($estimation_procedure == false) {
         die('estimation procedure not found');
     }
     $dataset = $this->Dataset->getById($values['source_data']);
     $epstr = $this->Estimation_procedure->toString($estimation_procedure);
     $target_feature = $task->ttid == 7 ? $values['target_feature_event'] : $values['target_feature'];
     // TODO: very important. sanity check input
     $testset_str = array_key_exists('custom_testset', $values) && is_cs_natural_numbers($values['custom_testset']) ? '-test "' . $values['custom_testset'] . '"' : '';
     $command = 'java -jar ' . $this->evaluation . ' -f "generate_folds" -d "' . $dataset->url . '" -e "' . $epstr . '" -c "' . $target_feature . '" -r "' . safe($dataset->row_id_attribute) . '" ' . $testset_str . $this->config;
     if (array_key_exists('custom_testset', $values)) {
         $command .= '-test "' . $values['custom_testset'] . '" ';
     }
     if ($filepath) {
         $command .= ' -o ' . $filepath;
     }
     //if( $md5 ) $command .= ' -m';
     $this->Log->cmd('API Splits::get(' . $task_id . ')', $command);
     if (function_enabled('system')) {
         header('Content-type: text/plain');
         system(CMD_PREFIX . $command);
     } else {
         die('failed to generate arff file: php "system" function disabled. ');
     }
 }
Exemple #2
0
 /**
  * given a file, return the mime type
  *
  * @param string $pExtension is the extension of the file or the complete file name
  * @return mime type of entry and populates $this->mMimeTypes with existing mime types
  * @access public
  */
 function verifyMimeType($pFile)
 {
     $mime = NULL;
     if (file_exists($pFile)) {
         if (function_exists('finfo_open')) {
             if (is_windows() && defined('PHP_MAGIC_PATH') && is_readable(PHP_MAGIC_PATH)) {
                 $finfo = finfo_open(FILEINFO_MIME, PHP_MAGIC_PATH);
             } else {
                 $finfo = finfo_open(FILEINFO_MIME);
             }
             $mime = finfo_file($finfo, $pFile);
             finfo_close($finfo);
         } else {
             if (function_enabled("escapeshellarg") && function_enabled("exec")) {
                 $mime = exec(trim('file -bi ' . escapeshellarg($pFile)));
             }
         }
         if (empty($mime)) {
             $mime = $this->lookupMimeType(substr($pFile, strrpos($pFile, '.') + 1));
         }
         if ($len = strpos($mime, ';')) {
             $mime = substr($mime, 0, $len);
         }
     }
     return $mime;
 }
Exemple #3
0
function validate_arff($to_folder, $filepath, $name, $did)
{
    $ci =& get_instance();
    $weka = PATH . APPPATH . 'third_party/OpenML/Java/weka.jar';
    $res = array();
    $code = 0;
    $oldUrl = DATA_PATH . $filepath;
    $newpath = strrev(implode(strrev('/openml_'), explode('/', strrev($filepath), 2)));
    $newUrl = DATA_PATH . $newpath;
    $heap = '-Xmx' . ($ci->input->is_cli_request() ? $ci->config->item('java_heap_space_cli') : $ci->config->item('java_heap_space_web'));
    $command = "java {$heap} -cp {$weka} weka.core.converters.ArffLoader {$oldUrl} > {$newUrl}";
    $ci->Log->cmd('ARFF Validation', $command);
    if (function_enabled('exec') === false) {
        return false;
    }
    exec(CMD_PREFIX . $command, $res, $code);
    //Guess the id of the dataset and add it to the top of the file
    $info = '% Data set "' . $name . '". For more information, see http:\\/\\/openml.org\\/d\\/' . $did;
    $string = '1s/^/' . $info . '\\n/';
    $command2 = "sed -i -e '{$string}' {$newUrl}";
    exec(CMD_PREFIX . $command2, $res, $code);
    if ($code == 0) {
        return $newpath;
    } else {
        return false;
    }
}
Exemple #4
0
function owner($path)
{
    $user = fileowner($path);
    $group = filegroup($path);
    $data = $user;
    if (function_enabled('posix_getpwuid')) {
        $u = posix_getpwuid($user);
        $data .= " (" . $u["name"] . ")";
    }
    $data .= " <br> " . $group;
    if (function_enabled('posix_getgrgid')) {
        $g = posix_getgrgid($group);
        $data .= " (" . $g["name"] . ")&nbsp;";
    }
    return $data;
}