@@ -54,7 +54,7 @@ function _getDuplicatedEmptyDFG(dfg::CloudGraphsDFG)::CloudGraphsDFG
54
54
length (_getLabelsFromCyphonQuery (dfg. neo4jInstance, " (node:$(dfg. userId) :$(dfg. robotId) :$(sessionId) )" )) == 0 && break
55
55
end
56
56
@debug " Unique+empty copy session name: $sessionId "
57
- return CloudGraphsDFG {typeof(dfg.solverParams)} (dfg. neo4jInstance. connection, dfg. userId, dfg. robotId, sessionId, dfg. encodePackedTypeFunc, dfg. getPackedTypeFunc, dfg. decodePackedTypeFunc, solverParams= deepcopy (dfg. solverParams), description= " (Copy of) $(dfg. description) " , useCache= dfg. useCache)
57
+ return CloudGraphsDFG {typeof(dfg.solverParams)} (dfg. neo4jInstance. connection, dfg. userId, dfg. robotId, sessionId, dfg. encodePackedTypeFunc, dfg. getPackedTypeFunc, dfg. decodePackedTypeFunc, dfg . rebuildFactorMetadata!, solverParams= deepcopy (dfg. solverParams), description= " (Copy of) $(dfg. description) " , useCache= dfg. useCache)
58
58
end
59
59
60
60
# Accessors
@@ -67,6 +67,11 @@ function setSolverParams(dfg::CloudGraphsDFG, solverParams::T)::T where T <: Abs
67
67
return dfg. solverParams = solverParams
68
68
end
69
69
70
+ function getSerializationModule (dfg:: CloudGraphsDFG ):: Module where G <: AbstractDFG
71
+ # TODO : If we need to specialize this for RoME etc, here is where we'll change it.
72
+ return Main
73
+ end
74
+
70
75
"""
71
76
$(SIGNATURES)
72
77
True if the variable or factor exists in the graph.
@@ -158,9 +163,7 @@ Add a DFGVariable to a DFG.
158
163
"""
159
164
function addVariable! (dfg:: CloudGraphsDFG , variable:: DFGVariable ):: Bool
160
165
if exists (dfg, variable)
161
- @warn " Variable '$(variable. label) ' already exists in the graph, so updating it."
162
- updateVariable! (dfg, variable)
163
- return true
166
+ error (" Variable '$(variable. label) ' already exists in the factor graph" )
164
167
end
165
168
props = Dict {String, Any} ()
166
169
props[" label" ] = string (variable. label)
@@ -192,9 +195,7 @@ Add a DFGFactor to a DFG.
192
195
"""
193
196
function addFactor! (dfg:: CloudGraphsDFG , variables:: Vector{DFGVariable} , factor:: DFGFactor ):: Bool
194
197
if exists (dfg, factor)
195
- @warn " Factor '$(factor. label) ' already exist in the graph, so updating it."
196
- updateFactor! (dfg, variables, factor)
197
- return true
198
+ error (" Factor '$(factor. label) ' already exists in the factor graph" )
198
199
end
199
200
200
201
# Update the variable ordering
@@ -363,9 +364,7 @@ Update a complete DFGVariable in the DFG.
363
364
"""
364
365
function updateVariable! (dfg:: CloudGraphsDFG , variable:: DFGVariable ):: DFGVariable
365
366
if ! exists (dfg, variable)
366
- @warn " Variable '$(variable. label) ' doesn't exist in the graph, so adding it."
367
- addVariable! (dfg, variable)
368
- return variable
367
+ error (" Variable label '$(variable. label) ' does not exist in the factor graph" )
369
368
end
370
369
nodeId = _tryGetNeoNodeIdFromNodeLabel (dfg. neo4jInstance, dfg. userId, dfg. robotId, dfg. sessionId, variable. label)
371
370
# Update the node ID
@@ -409,9 +408,7 @@ Update a complete DFGFactor in the DFG.
409
408
"""
410
409
function updateFactor! (dfg:: CloudGraphsDFG , factor:: DFGFactor ):: DFGFactor
411
410
if ! exists (dfg, factor)
412
- @warn " Factor '$(factor. label) ' doesn't exist in the graph, so adding it."
413
- addFactor! (dfg, factor)
414
- return factor
411
+ error (" Factor label '$(factor. label) ' does not exist in the factor graph" )
415
412
end
416
413
nodeId = _tryGetNeoNodeIdFromNodeLabel (dfg. neo4jInstance, dfg. userId, dfg. robotId, dfg. sessionId, factor. label)
417
414
# Update the _internalId
@@ -552,9 +549,15 @@ deleteFactor!(dfg::CloudGraphsDFG, factor::DFGFactor)::DFGFactor = deleteFactor!
552
549
List the DFGVariables in the DFG.
553
550
Optionally specify a label regular expression to retrieves a subset of the variables.
554
551
"""
555
- function getVariables (dfg:: CloudGraphsDFG , regexFilter:: Union{Nothing, Regex} = nothing ):: Vector{DFGVariable}
552
+ function getVariables (dfg:: CloudGraphsDFG , regexFilter:: Union{Nothing, Regex} = nothing ; tags :: Vector{Symbol} = Symbol[] ):: Vector{DFGVariable}
556
553
variableIds = getVariableIds (dfg, regexFilter)
557
- return map (vId-> getVariable (dfg, vId), variableIds)
554
+ # TODO : Optimize to use tags in query here!
555
+ variables = map (vId-> getVariable (dfg, vId), variableIds)
556
+ if length (tags) > 0
557
+ mask = map (v -> length (intersect (v. tags, tags)) > 0 , variables )
558
+ return variables[mask]
559
+ end
560
+ return variables
558
561
end
559
562
560
563
"""
@@ -629,15 +632,19 @@ function isFullyConnected(dfg::CloudGraphsDFG)::Bool
629
632
# Total nodes
630
633
varIds = getVariableIds (dfg)
631
634
factIds = getFactorIds (dfg)
632
- totalNodes = length (varIds) + length (factIds)
633
- if length (varIds) == 0
634
- return false
635
- end
635
+ length (varIds) + length (factIds) == 0 && return false
636
636
637
637
# Total connected nodes - thank you Neo4j for 0..* awesomeness!!
638
- connectedList = _getLabelsFromCyphonQuery (dfg. neo4jInstance, " (n:$(dfg. userId) :$(dfg. robotId) :$(dfg. sessionId) :$(varIds[1 ]) )-[FACTORGRAPH*]-(node:$(dfg. userId) :$(dfg. robotId) :$(dfg. sessionId) )" )
639
-
640
- return length (connectedList) == totalNodes
638
+ query = """
639
+ match (n:$(dfg. userId) :$(dfg. robotId) :$(dfg. sessionId) :$(varIds[1 ]) )-[FACTORGRAPH*]-(node:$(dfg. userId) :$(dfg. robotId) :$(dfg. sessionId) )
640
+ WHERE n:VARIABLE OR n:FACTOR OR node:VARIABLE OR node:FACTOR
641
+ WITH collect(n)+collect(node) as nodelist
642
+ unwind nodelist as nodes
643
+ return count(distinct nodes)"""
644
+ @debug " [Querying] $query "
645
+ result = _queryNeo4j (dfg. neo4jInstance, query)
646
+ # Neo4j.jl data structure sometimes feels brittle... like below
647
+ return result. results[1 ][" data" ][1 ][" row" ][1 ] == length (varIds) + length (factIds)
641
648
end
642
649
643
650
# Alias
@@ -655,10 +662,10 @@ function getNeighbors(dfg::CloudGraphsDFG, node::T; ready::Union{Nothing, Int}=n
655
662
query = " (n:$(dfg. userId) :$(dfg. robotId) :$(dfg. sessionId) :$(node. label) )--(node) where node:VARIABLE or node:FACTOR "
656
663
if ready != nothing || backendset != nothing
657
664
if ready != nothing
658
- query = query + " and node.ready = $(ready) "
665
+ query = query * " and node.ready = $(ready) "
659
666
end
660
667
if backendset != nothing
661
- query = query + " and node.backendset = $(backendset) "
668
+ query = query * " and node.backendset = $(backendset) "
662
669
end
663
670
end
664
671
neighbors = _getLabelsFromCyphonQuery (dfg. neo4jInstance, query)
@@ -677,10 +684,10 @@ function getNeighbors(dfg::CloudGraphsDFG, label::Symbol; ready::Union{Nothing,
677
684
query = " (n:$(dfg. userId) :$(dfg. robotId) :$(dfg. sessionId) :$(label) )--(node) where node:VARIABLE or node:FACTOR "
678
685
if ready != nothing || backendset != nothing
679
686
if ready != nothing
680
- query = query + " and node.ready = $(ready) "
687
+ query = query * " and node.ready = $(ready) "
681
688
end
682
689
if backendset != nothing
683
- query = query + " and node.backendset = $(backendset) "
690
+ query = query * " and node.backendset = $(backendset) "
684
691
end
685
692
end
686
693
neighbors = _getLabelsFromCyphonQuery (dfg. neo4jInstance, query)
0 commit comments