@@ -273,12 +273,16 @@ deleteFactor!(dfg::GraphsDFG, factor::DFGFactor)::DFGFactor = deleteFactor!(dfg,
273
273
List the DFGVariables in the DFG.
274
274
Optionally specify a label regular expression to retrieves a subset of the variables.
275
275
"""
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}
277
277
variables = map (v -> v. dfgNode, filter (n -> n. dfgNode isa DFGVariable, vertices (dfg. g)))
278
278
if regexFilter != nothing
279
279
variables = filter (v -> occursin (regexFilter, String (v. label)), variables)
280
280
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
282
286
end
283
287
284
288
# Alias
@@ -287,14 +291,28 @@ end
287
291
List the DFGVariables in the DFG.
288
292
Optionally specify a label regular expression to retrieves a subset of the variables.
289
293
"""
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 )
291
295
292
296
"""
293
297
$(SIGNATURES)
294
298
Get a list of IDs of the DFGVariables in the DFG.
295
299
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
296
309
"""
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
+
298
316
299
317
"""
300
318
$(SIGNATURES)
@@ -342,6 +360,36 @@ Checks if the graph is not fully connected, returns true if it is not contiguous
342
360
"""
343
361
hasOrphans (dfg:: GraphsDFG ):: Bool = ! isFullyConnected (dfg)
344
362
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
+
345
393
"""
346
394
$(SIGNATURES)
347
395
Retrieve a list of labels of the immediate neighbors around a given variable or factor.
0 commit comments