@@ -4,23 +4,6 @@ export copySession!
4
4
# With great power comes great "Oh crap, I deleted everything..."
5
5
export clearSession!!, clearRobot!!, clearUser!!
6
6
7
- function _getNodeType (dfg:: CloudGraphsDFG , nodeLabel:: Symbol ):: Symbol
8
- dfg. useCache && haskey (dfg. variableDict, nodeLabel) && return :VARIABLE
9
- dfg. useCache && haskey (dfg. factorDict, nodeLabel) && return :FACTOR
10
- nodeId = nothing
11
- if dfg. useCache && haskey (dfg. labelDict)
12
- nodeId = dfg. labelDict[nodeLabel]
13
- else
14
- nodeId = _tryGetNeoNodeIdFromNodeLabel (dfg. neo4jInstance, dfg. userId, dfg. robotId, dfg. sessionId, nodeLabel)
15
- end
16
- # Erk, little expensive to do this...
17
- nodeId == nothing && error (" Cannot find node with label '$nodeLabel '!" )
18
- labels = getnodelabels (getnode (dfg. neo4jInstance. graph, nodeId))
19
- " VARIABLE" in labels && return :VARIABLE
20
- " FACTOR" in labels && return :FACTOR
21
- error (" Node with label '$nodeLabel ' has neither FACTOR nor VARIABLE labels" )
22
- end
23
-
24
7
# # End
25
8
26
9
"""
@@ -157,6 +140,22 @@ DANGER: Copies the source to a new unique destination.
157
140
"""
158
141
copySession! (sourceDFG:: CloudGraphsDFG ):: CloudGraphsDFG = copySession! (sourceDFG, nothing )
159
142
143
+ """
144
+ $SIGNATURES
145
+
146
+ Return whether `sym::Symbol` represents a variable vertex in the graph.
147
+ """
148
+ isVariable (dfg:: CloudGraphsDFG , sym:: Symbol ):: Bool =
149
+ " VARIABLE" in _getNodeTags (dfg. neo4jInstance, dfg. userId, dfg. robotId, dfg. sessionId, sym)
150
+
151
+ """
152
+ $SIGNATURES
153
+
154
+ Return whether `sym::Symbol` represents a factor vertex in the graph.
155
+ """
156
+ isFactor (dfg:: CloudGraphsDFG , sym:: Symbol ):: Bool =
157
+ " FACTOR" in _getNodeTags (dfg. neo4jInstance, dfg. userId, dfg. robotId, dfg. sessionId, sym)
158
+
160
159
"""
161
160
$(SIGNATURES)
162
161
Add a DFGVariable to a DFG.
@@ -659,15 +658,16 @@ hasOrphans(dfg::CloudGraphsDFG)::Bool = !isFullyConnected(dfg)
659
658
Retrieve a list of labels of the immediate neighbors around a given variable or factor.
660
659
"""
661
660
function getNeighbors (dfg:: CloudGraphsDFG , node:: T ; ready:: Union{Nothing, Int} = nothing , backendset:: Union{Nothing, Int} = nothing ):: Vector{Symbol} where T <: DFGNode
662
- query = " (n:$(dfg. userId) :$(dfg. robotId) :$(dfg. sessionId) :$(node. label) )--(node) where node:VARIABLE or node:FACTOR "
661
+ query = " (n:$(dfg. userId) :$(dfg. robotId) :$(dfg. sessionId) :$(node. label) )--(node) where ( node:VARIABLE or node:FACTOR) "
663
662
if ready != nothing || backendset != nothing
664
663
if ready != nothing
665
- query = query * " and node.ready = $(ready) "
664
+ query = query * " and node.ready = $(ready) "
666
665
end
667
666
if backendset != nothing
668
- query = query * " and node.backendset = $(backendset) "
667
+ query = query * " and node.backendset = $(backendset) "
669
668
end
670
669
end
670
+ @debug " [Query] $query "
671
671
neighbors = _getLabelsFromCyphonQuery (dfg. neo4jInstance, query)
672
672
# If factor, need to do variable ordering
673
673
if T <: DFGFactor
@@ -681,21 +681,22 @@ end
681
681
Retrieve a list of labels of the immediate neighbors around a given variable or factor specified by its label.
682
682
"""
683
683
function getNeighbors (dfg:: CloudGraphsDFG , label:: Symbol ; ready:: Union{Nothing, Int} = nothing , backendset:: Union{Nothing, Int} = nothing ):: Vector{Symbol}
684
- query = " (n:$(dfg. userId) :$(dfg. robotId) :$(dfg. sessionId) :$(label) )--(node) where node:VARIABLE or node:FACTOR "
684
+ query = " (n:$(dfg. userId) :$(dfg. robotId) :$(dfg. sessionId) :$(label) )--(node) where ( node:VARIABLE or node:FACTOR) "
685
685
if ready != nothing || backendset != nothing
686
686
if ready != nothing
687
- query = query * " and node.ready = $(ready) "
687
+ query = query * " and node.ready = $(ready) "
688
688
end
689
689
if backendset != nothing
690
- query = query * " and node.backendset = $(backendset) "
690
+ query = query * " and node.backendset = $(backendset) "
691
691
end
692
692
end
693
+ @debug " [Query] $query "
693
694
neighbors = _getLabelsFromCyphonQuery (dfg. neo4jInstance, query)
694
695
# If factor, need to do variable ordering
695
- if _getNodeType (dfg, label) == :FACTOR
696
- # TODO : Implement shortcut for this.
697
- factor = getFactor ( dfg, label)
698
- neighbors = intersect (factor . _variableOrderSymbols , neighbors)
696
+ if isFactor (dfg, label)
697
+ # Server is authority
698
+ serverOrder = Symbol .(JSON2 . read ( _getNodeProperty ( dfg. neo4jInstance, dfg . userId, dfg . robotId, dfg . sessionId, label, " _variableOrderSymbols " )) )
699
+ neighbors = intersect (serverOrder , neighbors)
699
700
end
700
701
return neighbors
701
702
end
0 commit comments