Dataset scanning
This commit is contained in:
parent
3e4db35a47
commit
0542c7e844
@ -5,11 +5,14 @@ namespace NoccyLabs\Dataset;
|
||||
|
||||
class Dataset
|
||||
{
|
||||
protected string $identfier;
|
||||
protected string $identifier;
|
||||
|
||||
protected array $options;
|
||||
|
||||
public function __construct(string $identifier, string $filename, array $metadata)
|
||||
public function __construct(string $identifier, array $options)
|
||||
{
|
||||
$this->identifier = $identifier;
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
public function getIdentifier(): string
|
||||
|
@ -22,6 +22,16 @@ class DatasetManager
|
||||
}
|
||||
}
|
||||
|
||||
public function getAvailableDatasets(): array
|
||||
{
|
||||
return self::$datasets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the vendor directory and try to locate all bundled datasets
|
||||
*
|
||||
*
|
||||
*/
|
||||
private function scanForDatasets()
|
||||
{
|
||||
$root = $this->determineVendorPath();
|
||||
@ -33,9 +43,47 @@ class DatasetManager
|
||||
$glob = glob($root."/*/*/dataset.json");
|
||||
|
||||
foreach ($glob as $match) {
|
||||
$path = dirname($glob);
|
||||
$path = dirname($match);
|
||||
$package = basename(dirname($path))."/".basename($path);
|
||||
printf("found: %s\n", $package);
|
||||
$this->scanPackageDatasets($package, $path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param string The package name (org/package)
|
||||
* @param string The full path to the package (..../vendor/org/package)
|
||||
*/
|
||||
private function scanPackageDatasets(string $package, string $path)
|
||||
{
|
||||
$file = $path."/dataset.json";
|
||||
$json = @json_decode(
|
||||
@file_get_contents($file),
|
||||
true
|
||||
);
|
||||
|
||||
if (!$json) {
|
||||
trigger_error("Unable to parse dataset.json in {$package}");
|
||||
return;
|
||||
}
|
||||
|
||||
$this->loadDatasets($json['datasets'], null, $package, $path);
|
||||
//printf("found %d sets in %s\n", count($json['datasets']), $package);
|
||||
|
||||
}
|
||||
|
||||
private function loadDatasets(array $datasets, ?string $prefix, string $package, string $path)
|
||||
{
|
||||
foreach ($datasets as $name=>$info) {
|
||||
if (!array_key_exists('filename', $info)) {
|
||||
$this->loadDatasets($info, ltrim($prefix . "." . $name, "."), $package, $path);
|
||||
return;
|
||||
}
|
||||
$pn = sprintf("%s#%s", $package, ltrim($prefix.".".$name,"."));
|
||||
$ds = new Dataset($pn, $info);
|
||||
$this->registerDataset($ds);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user