|
32 | 32 | loadfile(file::AbstractPath) = loadfile(string(file))
|
33 | 33 |
|
34 | 34 | """
|
35 |
| - FileDataset(paths) |
36 |
| - FileDataset(dir, pattern = "*", depth = 4) |
| 35 | + FileDataset([loadfn = loadfile,] paths) |
| 36 | + FileDataset([loadfn = loadfile,] dir, pattern = "*", depth = 4) |
37 | 37 |
|
38 | 38 | Wrap a set of file `paths` as a dataset (traversed in the same order as `paths`).
|
39 | 39 | Alternatively, specify a `dir` and collect all paths that match a glob `pattern`
|
40 | 40 | (recursively globbing by `depth`). The glob order determines the traversal order.
|
41 | 41 | """
|
42 |
| -struct FileDataset{T<:Union{AbstractPath, AbstractString}} <: AbstractDataContainer |
| 42 | +struct FileDataset{F, T<:Union{AbstractPath, AbstractString}} <: AbstractDataContainer |
| 43 | + loadfn::F |
43 | 44 | paths::Vector{T}
|
44 | 45 | end
|
45 | 46 |
|
46 |
| -FileDataset(dir, pattern = "*", depth = 4) = FileDataset(rglob(pattern, string(dir), depth)) |
| 47 | +FileDataset(paths) = FileDataset(loadfile, paths) |
| 48 | +FileDataset(loadfn, |
| 49 | + dir::Union{AbstractPath, AbstractString}, |
| 50 | + pattern::AbstractString = "*", |
| 51 | + depth = 4) = FileDataset(loadfn, rglob(pattern, string(dir), depth)) |
| 52 | +FileDataset(dir::Union{AbstractPath, AbstractString}, pattern::AbstractString = "*", depth = 4) = |
| 53 | + FileDataset(loadfile, dir, pattern, depth) |
47 | 54 |
|
48 | 55 | MLUtils.getobs(dataset::FileDataset, i) = loadfile(dataset.paths[i])
|
49 | 56 | MLUtils.numobs(dataset::FileDataset) = length(dataset.paths)
|
0 commit comments