invenia / AxisSets.jl

Consistent operations over a collection of KeyedArrays
MIT License
5 stars 0 forks source link

Wildcard for 0-or-more in Pattern #63

Open morris25 opened 3 years ago

morris25 commented 3 years ago

Somewhat related to #48 . I have data containing training sets for several features. Some have a single KeyedArray and others have multiple sub-components. It would be nice to be able to get all :train data using a wildcard instead of merging (:_, :train, :__) and (:_, :train).

julia> data=KeyedDataset(
           (:f1, :train)=>KeyedArray([1], a=[1]), 
           (:f2, :train, :x)=>KeyedArray([1], b=[1]), 
           (:f2, :train, :y)=>KeyedArray([1], c=[1]),
       )
KeyedDataset with:
  3 components
    (:f1, :train) => 1 KeyedArray{Int64} with dimension a[1]
    (:f2, :train, :x) => 1 KeyedArray{Int64} with dimension b[2]
    (:f2, :train, :y) => 1 KeyedArray{Int64} with dimension c[3]
  3 constraints
    [1] (:__, :a) ∈ 1-element Vector{Int64}
    [2] (:__, :b) ∈ 1-element Vector{Int64}
    [3] (:__, :c) ∈ 1-element Vector{Int64}

julia> data(:_, :train, :__)
KeyedDataset with:
  2 components
    (:f2, :train, :x) => 1 KeyedArray{Int64} with dimension b[1]
    (:f2, :train, :y) => 1 KeyedArray{Int64} with dimension c[2]
  2 constraints
    [1] (:__, :b) ∈ 1-element Vector{Int64}
    [2] (:__, :c) ∈ 1-element Vector{Int64}

julia> data(:_, :train)
KeyedDataset with:
  1 components
    (:f1, :train) => 1 KeyedArray{Int64} with dimension a[1]
  1 constraints
    [1] (:__, :a) ∈ 1-element Vector{Int64}