From ba4fe74fed366d6e31ebe0664e98e2e65c162930 Mon Sep 17 00:00:00 2001 From: Daniel Loos Date: Thu, 12 Sep 2024 13:27:07 +0200 Subject: [PATCH] Add lambda function --- src/OpenEOClient.jl | 1 + src/ProcessGraph.jl | 18 ++++++++++++++++-- src/Processes.jl | 5 +++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/OpenEOClient.jl b/src/OpenEOClient.jl index a5a2e4e..9a08a73 100644 --- a/src/OpenEOClient.jl +++ b/src/OpenEOClient.jl @@ -15,6 +15,7 @@ export compute_result, connect, DataCube, + value, describe_collection, to_band, list_collections, diff --git a/src/ProcessGraph.jl b/src/ProcessGraph.jl index 126bf37..6b213a0 100644 --- a/src/ProcessGraph.jl +++ b/src/ProcessGraph.jl @@ -1,6 +1,6 @@ using OrderedCollections -function flatten!(g::AbstractProcessCall, root_id, nodes=OrderedSet{ProcessCall}()) +function flatten!(g::AbstractProcessCall, root_id, nodes=OrderedSet{AbstractProcessCall}()) has_parameter = x -> ProcessCallParameter in typeof.(values(x.arguments)) arguments_nodes = filter(((k, v),) -> v isa ProcessCall && !has_parameter(v), g.arguments) @@ -52,6 +52,8 @@ Base.getindex(g::ProcessGraph, i) = Base.getindex(g.process_graph, i) Base.length(g::ProcessGraph) = Base.length(g.process_graph) print_json(g::ProcessGraph) = g |> JSON3.write |> JSON3.pretty +ProcessGraph(value::ProcessCallParameter) = ProcessGraph(value * 1) # allow identity ProcessGraph + """ Create a ProcessGraph to reduce dimesnions """ @@ -95,4 +97,16 @@ end function compute_result(connection::AuthorizedCredentials, json_graph_path::String, kw...) process_graph = JSON3.read(json_graph_path) |> Dict return compute_result(connection, process_graph, kw...) -end \ No newline at end of file +end + + +# +# Build a ProcessGraph like a lambda function +# + +Base.isequal(x::ProcessCall, y::ProcessCall) = x.id == y.id # required to create OrderedDict for ProcessGraph + +Base.log(x::AbstractProcessCall, base::Number) = ProcessCall("log", Dict(:x => x, :base => base)) +Base.:(*)(x::AbstractProcessCall, y::Number) = ProcessCall("multiply", Dict(:x => x, :y => y)) +Base.:(*)(x::Number, y::AbstractProcessCall) = ProcessCall("multiply", Dict(:x => x, :y => y)) +Base.:(==)(x::AbstractProcessCall, y) = ProcessCall("eq", Dict(:x => x, :y => y)) \ No newline at end of file diff --git a/src/Processes.jl b/src/Processes.jl index 18d5bba..f73c2fd 100644 --- a/src/Processes.jl +++ b/src/Processes.jl @@ -76,6 +76,11 @@ struct ProcessCallParameter <: AbstractProcessCall from_parameter::String end +""" +Placeholder to define process graphs e.g. lambda functions +""" +const value = ProcessCallParameter("value") + mutable struct ProcessCall <: AbstractProcessCall const id::String const process_id::String