Skip to content

Commit 89185b3

Browse files
authored
Merge pull request #48 from JuliaRobotics/bug/40_lssymbols
ls() and lsf() return symbols rather than full variables/factors
2 parents 9f685b2 + 317fb01 commit 89185b3

File tree

5 files changed

+64
-71
lines changed

5 files changed

+64
-71
lines changed

src/CloudGraphsDFG/services/CloudGraphsDFG.jl

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function _getname(t::T) where T
1212
T.name.name
1313
end
1414

15-
# Simply for convenience -don't export
15+
# Simply for convenience - don't export
1616
const PackedFunctionNodeData{T} = GenericFunctionNodeData{T, <: AbstractString}
1717
PackedFunctionNodeData(x1, x2, x3, x4, x5::S, x6::T, x7::String="", x8::Vector{Int}=Int[]) where {T <: PackedInferenceType, S <: AbstractString} = GenericFunctionNodeData(x1, x2, x3, x4, x5, x6, x7, x8)
1818
const FunctionNodeData{T} = GenericFunctionNodeData{T, Symbol}
@@ -541,26 +541,16 @@ Delete the referened DFGFactor from the DFG.
541541
"""
542542
deleteFactor!(dfg::CloudGraphsDFG, factor::DFGFactor)::DFGFactor = deleteFactor!(dfg, factor.label)
543543

544-
# Returns a flat vector of the vertices, keyed by ID.
545-
# Assuming only variables here for now - think maybe not, should be variables+factors?
546544
"""
547545
$(SIGNATURES)
548546
List the DFGVariables in the DFG.
549547
Optionally specify a label regular expression to retrieves a subset of the variables.
550548
"""
551-
function ls(dfg::CloudGraphsDFG, regexFilter::Union{Nothing, Regex}=nothing)::Vector{DFGVariable}
549+
function getVariables(dfg::CloudGraphsDFG, regexFilter::Union{Nothing, Regex}=nothing)::Vector{DFGVariable}
552550
variableIds = getVariableIds(dfg, regexFilter)
553551
return map(vId->getVariable(dfg, vId), variableIds)
554552
end
555553

556-
# Alias
557-
"""
558-
$(SIGNATURES)
559-
List the DFGVariables in the DFG.
560-
Optionally specify a label regular expression to retrieves a subset of the variables.
561-
"""
562-
getVariables(dfg::CloudGraphsDFG, regexFilter::Union{Nothing, Regex}=nothing)::Vector{DFGVariable} = ls(dfg, regexFilter)
563-
564554
"""
565555
$(SIGNATURES)
566556
Get a list of IDs of the DFGVariables in the DFG.
@@ -575,32 +565,22 @@ function getVariableIds(dfg::CloudGraphsDFG, regexFilter::Union{Nothing, Regex}=
575565
end
576566
end
577567

568+
# Alias
578569
"""
579570
$(SIGNATURES)
580-
List the DFGFactors in the DFG.
581-
Optionally specify a label regular expression to retrieves a subset of the factors.
571+
List the DFGVariables in the DFG.
572+
Optionally specify a label regular expression to retrieves a subset of the variables.
582573
"""
583-
function lsf(dfg::CloudGraphsDFG, regexFilter::Union{Nothing, Regex}=nothing)::Vector{DFGFactor}
584-
factorIds = getFactorIds(dfg, regexFilter)
585-
return map(vId->getFactor(dfg, vId), factorIds)
586-
end
574+
ls(dfg::CloudGraphsDFG, regexFilter::Union{Nothing, Regex}=nothing)::Vector{Symbol} = getVariableIds(dfg, regexFilter)
587575

588-
# Alias
589576
"""
590577
$(SIGNATURES)
591578
List the DFGFactors in the DFG.
592579
Optionally specify a label regular expression to retrieves a subset of the factors.
593580
"""
594-
getFactors(dfg::CloudGraphsDFG, regexFilter::Union{Nothing, Regex}=nothing)::Vector{DFGFactor} = lsf(dfg, regexFilter)
595-
596-
# Alias - getNeighbors
597-
#TODO: Refactor this
598-
"""
599-
$(SIGNATURES)
600-
Get neighbors around a given node. TODO: Refactor this
601-
"""
602-
function lsf(dfg::CloudGraphsDFG, label::Symbol)::Vector{Symbol}
603-
return getNeighbors(dfg, label)
581+
function getFactors(dfg::CloudGraphsDFG, regexFilter::Union{Nothing, Regex}=nothing)::Vector{DFGFactor}
582+
factorIds = getFactorIds(dfg, regexFilter)
583+
return map(vId->getFactor(dfg, vId), factorIds)
604584
end
605585

606586
"""
@@ -617,6 +597,23 @@ function getFactorIds(dfg::CloudGraphsDFG, regexFilter::Union{Nothing, Regex}=no
617597
end
618598
end
619599

600+
# Alias
601+
"""
602+
$(SIGNATURES)
603+
List the DFGFactors in the DFG.
604+
Optionally specify a label regular expression to retrieves a subset of the factors.
605+
"""
606+
lsf(dfg::CloudGraphsDFG, regexFilter::Union{Nothing, Regex}=nothing)::Vector{Symbol} = getFactorIds(dfg, regexFilter)
607+
608+
# Alias - getNeighbors
609+
"""
610+
$(SIGNATURES)
611+
Get neighbors around a given node. TODO: Refactor this
612+
"""
613+
function lsf(dfg::CloudGraphsDFG, label::Symbol)::Vector{Symbol}
614+
return getNeighbors(dfg, label)
615+
end
616+
620617
"""
621618
$(SIGNATURES)
622619
Checks if the graph is fully connected, returns true if so.

src/GraphsDFG/services/GraphsDFG.jl

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,12 @@ Delete the referened DFGFactor from the DFG.
209209
"""
210210
deleteFactor!(dfg::GraphsDFG, factor::DFGFactor)::DFGFactor = deleteFactor!(dfg, factor.label)
211211

212-
# # Returns a flat vector of the vertices, keyed by ID.
213-
# # Assuming only variables here for now - think maybe not, should be variables+factors?
214212
"""
215213
$(SIGNATURES)
216214
List the DFGVariables in the DFG.
217215
Optionally specify a label regular expression to retrieves a subset of the variables.
218216
"""
219-
function ls(dfg::GraphsDFG, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[])::Vector{DFGVariable}
217+
function getVariables(dfg::GraphsDFG, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[])::Vector{DFGVariable}
220218
variables = map(v -> v.dfgNode, filter(n -> n.dfgNode isa DFGVariable, vertices(dfg.g)))
221219
if regexFilter != nothing
222220
variables = filter(v -> occursin(regexFilter, String(v.label)), variables)
@@ -228,14 +226,6 @@ function ls(dfg::GraphsDFG, regexFilter::Union{Nothing, Regex}=nothing; tags::Ve
228226
return variables
229227
end
230228

231-
# Alias
232-
"""
233-
$(SIGNATURES)
234-
List the DFGVariables in the DFG.
235-
Optionally specify a label regular expression to retrieves a subset of the variables.
236-
"""
237-
getVariables(dfg::GraphsDFG, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[])::Vector{DFGVariable} = ls(dfg, regexFilter, tags=tags)
238-
239229
"""
240230
$(SIGNATURES)
241231
Get a list of IDs of the DFGVariables in the DFG.
@@ -251,42 +241,54 @@ Related
251241
ls
252242
"""
253243
function getVariableIds(dfg::GraphsDFG, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[])::Vector{Symbol}
254-
vars = ls(dfg, regexFilter, tags=tags)
244+
vars = getVariables(dfg, regexFilter, tags=tags)
255245
# mask = map(v -> length(intersect(v.tags, tags)) > 0, vars )
256246
map(v -> v.label, vars)
257247
end
258248

249+
# Alias
250+
"""
251+
$(SIGNATURES)
252+
List the DFGVariables in the DFG.
253+
Optionally specify a label regular expression to retrieves a subset of the variables.
254+
"""
255+
ls(dfg::GraphsDFG, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[])::Vector{Symbol} = getVariableIds(dfg, regexFilter, tags=tags)
259256

260257
"""
261258
$(SIGNATURES)
262259
List the DFGFactors in the DFG.
263260
Optionally specify a label regular expression to retrieves a subset of the factors.
264261
"""
265-
function lsf(dfg::GraphsDFG, regexFilter::Union{Nothing, Regex}=nothing)::Vector{DFGFactor}
266-
factors = map(v -> v.dfgNode, filter(n -> n.dfgNode isa DFGFactor, vertices(dfg.g)))
267-
if regexFilter != nothing
268-
factors = filter(f -> occursin(regexFilter, String(f.label)), factors)
269-
end
270-
return factors
271-
end
272-
function lsf(dfg::GraphsDFG, label::Symbol)::Vector{Symbol}
273-
return getNeighbors(dfg, label)
262+
function getFactors(dfg::GraphsDFG, regexFilter::Union{Nothing, Regex}=nothing)::Vector{DFGFactor}
263+
factors = map(v -> v.dfgNode, filter(n -> n.dfgNode isa DFGFactor, vertices(dfg.g)))
264+
if regexFilter != nothing
265+
factors = filter(f -> occursin(regexFilter, String(f.label)), factors)
266+
end
267+
return factors
274268
end
275269

276-
# Alias
277270
"""
278271
$(SIGNATURES)
279-
List the DFGFactors in the DFG.
272+
Get a list of the IDs of the DFGFactors in the DFG.
280273
Optionally specify a label regular expression to retrieves a subset of the factors.
281274
"""
282-
getFactors(dfg::GraphsDFG, regexFilter::Union{Nothing, Regex}=nothing)::Vector{DFGFactor} = lsf(dfg, regexFilter)
275+
getFactorIds(dfg::GraphsDFG, regexFilter::Union{Nothing, Regex}=nothing)::Vector{Symbol} = map(f -> f.label, getFactors(dfg, regexFilter))
283276

284277
"""
285278
$(SIGNATURES)
286-
Get a list of the IDs of the DFGFactors in the DFG.
279+
List the DFGFactors in the DFG.
287280
Optionally specify a label regular expression to retrieves a subset of the factors.
288281
"""
289-
getFactorIds(dfg::GraphsDFG, regexFilter::Union{Nothing, Regex}=nothing)::Vector{Symbol} = map(f -> f.label, lsf(dfg, regexFilter))
282+
# Alias
283+
lsf(dfg::GraphsDFG, regexFilter::Union{Nothing, Regex}=nothing)::Vector{Symbol} = getFactorIds(dfg, regexFilter)
284+
285+
"""
286+
$(SIGNATURES)
287+
Alias for getNeighbors - returns neighbors around a given node label.
288+
"""
289+
function lsf(dfg::GraphsDFG, label::Symbol)::Vector{Symbol}
290+
return getNeighbors(dfg, label)
291+
end
290292

291293
"""
292294
$(SIGNATURES)

test/cloudGraphsDFGTests.jl

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# Run: sudo docker run --publish=7474:7474 --publish=7687:7687 --env NEO4J_AUTH=neo4j/test neo4j
77

88
using Revise
9+
using Neo4j
910
using DistributedFactorGraphs
1011
using IncrementalInference
1112
using Test
@@ -15,7 +16,7 @@ using RoME
1516
@testset "Setup and clearing the existing graph" begin
1617
# Create connection
1718
# Caching: Off
18-
global cgDFG = CloudGraphsDFG("localhost", 7474, "neo4j", "test",
19+
global cgDFG = CloudGraphsDFG{NoSolverParams}("localhost", 7474, "neo4j", "test",
1920
"testUser", "testRobot", "testSession",
2021
nothing,
2122
nothing,
@@ -92,12 +93,12 @@ end
9293
# Not fast though, TODO: https://github.com/JuliaRobotics/DistributedFactorGraphs.jl/issues/39
9394
vars = getVariables(cgDFG)
9495
vars2 = ls(cgDFG)
95-
@test map(v->v.label, vars) == map(v->v.label, vars2)
96+
@test map(v->v.label, vars) == vars2
9697
@test symdiff(map(v->v.label, vars), [:x1, :x2, :x3, :l1, :l2]) == []
9798

9899
facts = getFactors(cgDFG)
99100
facts2 = lsf(cgDFG)
100-
@test map(v->v.label, facts) == map(v->v.label, facts2)
101+
@test map(v->v.label, facts) == facts2
101102
@test symdiff(map(f->f.label, facts), [:x1x2f1, :x1f1, :x2l1f1, :x2x3f1, :x3l2f1, :x1l1f1]) == []
102103

103104
@test symdiff(getNeighbors(cgDFG, :x2), [:x2l1f1, :x2x3f1, :x1x2f1]) == []
@@ -168,13 +169,6 @@ end
168169
# clearSession!!(cgDFGCopy)
169170
end
170171

171-
global cgDFG = CloudGraphsDFG("localhost", 7474, "neo4j", "test",
172-
"testUser", "testRobot", "testSession",
173-
nothing,
174-
nothing,
175-
IncrementalInference.decodePackedType)
176-
177-
178172
@testset "getAdjacencyMatrix test" begin
179173
adjMat = getAdjacencyMatrix(cgDFG)
180174
# Note that by this point, :x3 is bound to :x1x2f1, which is counterintuitive but that's tests for you

test/interfaceTests.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ addFactor!(dfg, [v1, v2], f1)
1717
@test symdiff([:a, :b], getVariableIds(dfg)) == []
1818
@test getFactorIds(dfg) == [:f1]
1919
# Regexes
20-
@test ls(dfg, r"a") == [v1]
21-
@test lsf(dfg, r"f*") == [f1]
20+
@test ls(dfg, r"a") == [v1.label]
21+
@test lsf(dfg, r"f*") == [f1.label]
2222
# Accessors
2323
@test getAddHistory(dfg) == [:a, :b] #, :f1
2424
@test getDescription(dfg) != nothing
@@ -118,13 +118,13 @@ end
118118
# Subgraphs
119119
dfgSubgraph = getSubgraphAroundNode(dfg, verts[1], 2)
120120
# Only returns x1 and x2
121-
@test symdiff([:x1, :x1x2f1, :x2], map(n -> n.label, [ls(dfgSubgraph)..., lsf(dfgSubgraph)...])) == []
121+
@test symdiff([:x1, :x1x2f1, :x2], [ls(dfgSubgraph)..., lsf(dfgSubgraph)...]) == []
122122
# Test include orphan factorsVoid
123123
dfgSubgraph = getSubgraphAroundNode(dfg, verts[1], 1, true)
124-
@test symdiff([:x1, :x1x2f1], map(n -> n.label, [ls(dfgSubgraph)..., lsf(dfgSubgraph)...])) == []
124+
@test symdiff([:x1, :x1x2f1], [ls(dfgSubgraph)..., lsf(dfgSubgraph)...]) == []
125125
# Test adding to the dfg
126126
dfgSubgraph = getSubgraphAroundNode(dfg, verts[1], 2, true, dfgSubgraph)
127-
@test symdiff([:x1, :x1x2f1, :x2], map(n -> n.label, [ls(dfgSubgraph)..., lsf(dfgSubgraph)...])) == []
127+
@test symdiff([:x1, :x1x2f1, :x2], [ls(dfgSubgraph)..., lsf(dfgSubgraph)...]) == []
128128
end
129129

130130
@testset "Producing Dot Files" begin

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ using DistributedFactorGraphs
66
apis = [GraphsDFG]
77
# apis = [graphsDFG, cgDFG]
88
for api in apis
9-
@testset "Testing Driver: $(typeof(api))" begin
9+
@testset "Testing Driver: $(api)" begin
1010
global testDFGAPI = api
1111
include("interfaceTests.jl")
1212
end

0 commit comments

Comments
 (0)