refactor csv dataset definition

This commit is contained in:
Arkadiusz Kondas 2016-04-07 22:19:04 +02:00
parent d3247ebccb
commit a20f474324
3 changed files with 13 additions and 32 deletions

View File

@ -11,12 +11,12 @@ class ArrayDataset implements Dataset
/** /**
* @var array * @var array
*/ */
private $samples = []; protected $samples = [];
/** /**
* @var array * @var array
*/ */
private $labels = []; protected $labels = [];
/** /**
* @param array $samples * @param array $samples

View File

@ -6,7 +6,7 @@ namespace Phpml\Dataset;
use Phpml\Exception\DatasetException; use Phpml\Exception\DatasetException;
abstract class CsvDataset implements Dataset class CsvDataset extends ArrayDataset
{ {
/** /**
* @var string * @var string
@ -14,19 +14,12 @@ abstract class CsvDataset implements Dataset
protected $filepath; protected $filepath;
/** /**
* @var array * @param string|null $filepath
*
* @throws DatasetException
*/ */
private $samples = []; public function __construct(string $filepath = null)
/**
* @var array
*/
private $labels = [];
public function __construct()
{ {
$filepath = dirname(__FILE__).'/../../../data/'.$this->filepath;
if (!file_exists($filepath)) { if (!file_exists($filepath)) {
throw DatasetException::missingFile(basename($filepath)); throw DatasetException::missingFile(basename($filepath));
} }
@ -46,20 +39,4 @@ abstract class CsvDataset implements Dataset
throw DatasetException::cantOpenFile(basename($filepath)); throw DatasetException::cantOpenFile(basename($filepath));
} }
} }
/**
* @return array
*/
public function getSamples(): array
{
return $this->samples;
}
/**
* @return array
*/
public function getLabels(): array
{
return $this->labels;
}
} }

View File

@ -15,7 +15,11 @@ use Phpml\Dataset\CsvDataset;
class Iris extends CsvDataset class Iris extends CsvDataset
{ {
/** /**
* @var string * @param string|null $filepath
*/ */
protected $filepath = 'iris.csv'; public function __construct(string $filepath = null)
{
$filepath = dirname(__FILE__).'/../../../../data/iris.csv';
parent::__construct($filepath);
}
} }