Skip to content

Commit 2fd63a7

Browse files
committed
ls getVarIds now search tags too
1 parent 8878102 commit 2fd63a7

File tree

1 file changed

+52
-4
lines changed

1 file changed

+52
-4
lines changed

src/services/GraphsDFG.jl

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,16 @@ deleteFactor!(dfg::GraphsDFG, factor::DFGFactor)::DFGFactor = deleteFactor!(dfg,
273273
List the DFGVariables in the DFG.
274274
Optionally specify a label regular expression to retrieves a subset of the variables.
275275
"""
276-
function ls(dfg::GraphsDFG, regexFilter::Union{Nothing, Regex}=nothing)::Vector{DFGVariable}
276+
function ls(dfg::GraphsDFG, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[])::Vector{DFGVariable}
277277
variables = map(v -> v.dfgNode, filter(n -> n.dfgNode isa DFGVariable, vertices(dfg.g)))
278278
if regexFilter != nothing
279279
variables = filter(v -> occursin(regexFilter, String(v.label)), variables)
280280
end
281-
return variables
281+
if length(tags) > 0
282+
mask = map(v -> length(intersect(v.tags, tags)) > 0, variables )
283+
return variables[mask]
284+
end
285+
return variables
282286
end
283287

284288
# Alias
@@ -287,14 +291,28 @@ end
287291
List the DFGVariables in the DFG.
288292
Optionally specify a label regular expression to retrieves a subset of the variables.
289293
"""
290-
getVariables(dfg::GraphsDFG, regexFilter::Union{Nothing, Regex}=nothing)::Vector{DFGVariable} = ls(dfg, regexFilter)
294+
getVariables(dfg::GraphsDFG, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[])::Vector{DFGVariable} = ls(dfg, regexFilter, tags=tags)
291295

292296
"""
293297
$(SIGNATURES)
294298
Get a list of IDs of the DFGVariables in the DFG.
295299
Optionally specify a label regular expression to retrieves a subset of the variables.
300+
301+
Example
302+
```julia
303+
getVariableIds(dfg, r"l", tags=[:APRILTAG;])
304+
```
305+
306+
Related
307+
308+
ls
296309
"""
297-
getVariableIds(dfg::GraphsDFG, regexFilter::Union{Nothing, Regex}=nothing)::Vector{Symbol} = map(v -> v.label, ls(dfg, regexFilter))
310+
function getVariableIds(dfg::GraphsDFG, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[])::Vector{Symbol}
311+
vars = ls(dfg, regexFilter, tags=tags)
312+
# mask = map(v -> length(intersect(v.tags, tags)) > 0, vars )
313+
map(v -> v.label, vars)
314+
end
315+
298316

299317
"""
300318
$(SIGNATURES)
@@ -342,6 +360,36 @@ Checks if the graph is not fully connected, returns true if it is not contiguous
342360
"""
343361
hasOrphans(dfg::GraphsDFG)::Bool = !isFullyConnected(dfg)
344362

363+
364+
"""
365+
$(SIGNATURES)
366+
Test if all elements of the string is a number: Ex, "123" is true, "1_2" is false.
367+
"""
368+
allnums(str::S) where {S <: AbstractString} = occursin(Regex(string(["[0-9]" for j in 1:length(str)]...)), str)
369+
# occursin(r"_+|,+|-+", node_idx)
370+
371+
isnestednum(str::S; delim='_') where {S <: AbstractString} = occursin(Regex("[0-9]+$(delim)[0-9]+"), str)
372+
373+
function sortnestedperm(strs::Vector{<:AbstractString}; delim='_')
374+
str12 = split.(strs, delim)
375+
sp1 = sortperm(parse.(Int,getindex.(str12,2)))
376+
sp2 = sortperm(parse.(Int,getindex.(str12,1)[sp1]))
377+
return sp1[sp2]
378+
end
379+
380+
# function sortVariableLabels(usl::Vector{Symbol})::Vector{Symbol}
381+
# # x, l = String[], String[]
382+
# # xval = Int[]
383+
# # xstr = String[]
384+
# # xvalnested = String[]
385+
# # xstrnested = String[]
386+
# # canparse1 = true
387+
# # nestedparse1 = true
388+
# # idx = 0
389+
#
390+
# end
391+
392+
345393
"""
346394
$(SIGNATURES)
347395
Retrieve a list of labels of the immediate neighbors around a given variable or factor.

0 commit comments

Comments
 (0)