Skip to content

Commit beb012a

Browse files
committed
WORK IN PROGRESS
1 parent b089a6f commit beb012a

File tree

4 files changed

+143
-107
lines changed

4 files changed

+143
-107
lines changed

src/Common.jl

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ export lsTypes, lsfTypes
99
export lsWho, lsfWho
1010
export *
1111
export findClosestTimestamp, findVariableNearTimestamp
12-
export hasTags
12+
export addTags!
13+
export hasTags, hasTagsNeighbors
1314

1415
*(a::Symbol, b::AbstractString)::Symbol = Symbol(string(a,b))
1516

@@ -405,16 +406,42 @@ function findVariableNearTimestamp(dfg::AbstractDFG,
405406
return RET
406407
end
407408

409+
"""
410+
$SIGNATURES
411+
412+
Add tags to a variable or factor
413+
"""
414+
function addTags!(dfg::InMemoryDFGTypes, sym::Symbol, tags::Vector{Symbol})
415+
union!(getTags(getFactor(fg, sym)), tags)
416+
end
408417

409418
"""
410419
$SIGNATURES
411420
412-
Determine if a variable or factor has all the tags listed in `stags`.
421+
Determine if the variable or factor neighbors have the `tags:;Vector{Symbol}`, and `matchAll::Bool`.
413422
"""
414423
function hasTags(dfg::InMemoryDFGTypes,
415424
sym::Symbol,
416-
stags::Vector{Symbol})::Bool
425+
tags::Vector{Symbol};
426+
matchAll::Bool=true )::Bool
427+
#
428+
alltags = getTags(dfg, sym)
429+
length(filter(x->x in alltags, tags)) >= (matchAll ? length(tags) : 1)
430+
end
431+
432+
433+
"""
434+
$SIGNATURES
435+
436+
Determine if the variable or factor neighbors have the `tags:;Vector{Symbol}`, and `matchAll::Bool`.
437+
"""
438+
function hasTagsNeighbors(dfg::InMemoryDFGTypes,
439+
sym::Symbol,
440+
tags::Vector{Symbol};
441+
matchAll::Bool=true )::Bool
417442
#
418-
alltags = union( (ls(dfg, sym) .|> x->tags(getFactor(dfg,x)))...)
419-
length(filter(x->x in alltags, stags)) == length(stags)
443+
# assume only variables or factors are neighbors
444+
getNeiFnc = isVariable(dfg, sym) ? getFactor : getVariable
445+
alltags = union( (ls(dfg, sym) .|> x->DFG.tags(getNeiFnc(dfg,x)))... )
446+
length(filter(x->x in alltags, tags)) >= (matchAll ? length(tags) : 1)
420447
end

src/CommonAccessors.jl

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Common get and set methods
2+
3+
# NOTE this could be reduced with macros and function generation to even less code.
4+
5+
export getLabel, label
6+
export getTags, setTags!, tags
7+
export getTimestamp, setTimestamp!, timestamp
8+
export getInternalId, interalId
9+
10+
11+
const FactorDataLevel0 = Union{DFGFactor, DFGFactorSummary, SkeletonDFGFactor}
12+
const FactorDataLevel1 = Union{DFGFactor, DFGFactorSummary}
13+
# const FactorDataLevel2 = Union{DFGFactor}
14+
15+
const DataLevel0 = Union{VariableDataLevel0, FactorDataLevel0}
16+
const DataLevel1 = Union{VariableDataLevel1, FactorDataLevel1}
17+
const DataLevel2 = Union{VariableDataLevel2, FactorDataLevel2}
18+
19+
20+
"""
21+
$SIGNATURES
22+
23+
Return the label for a variable or factor.
24+
"""
25+
getLabel(v::DataLevel0) = v.label
26+
27+
"""
28+
$SIGNATURES
29+
30+
Return the label for a variable or factor.
31+
32+
DEPRECATED label -> getLabel
33+
"""
34+
function label(v::DataLevel0)
35+
@warn "Deprecated label, use getLabel instead."
36+
getLabel(v)
37+
end
38+
39+
40+
"""
41+
$SIGNATURES
42+
43+
Return the tags for a variable.
44+
"""
45+
getTags(v::DataLevel0) = v.tags
46+
47+
"""
48+
$SIGNATURES
49+
50+
Return the tags for a variable.
51+
52+
DEPRECATED, tags -> getTags
53+
"""
54+
function tags(v::DataLevel0)
55+
@warn "tags deprecated, use getTags instead"
56+
getTags
57+
end
58+
59+
"""
60+
$SIGNATURES
61+
62+
Set the tags for a factor.
63+
"""
64+
setTags!(f::DataLevel0, tags::Vector{Symbol}) = f.tags = tags
65+
66+
67+
"""
68+
$SIGNATURES
69+
70+
Get the timestamp from a DFGFactor object.
71+
"""
72+
getTimestamp(v::DataLevel1) = v.timestamp
73+
74+
"""
75+
$SIGNATURES
76+
77+
Get the timestamp from a DFGFactor object.
78+
79+
DEPRECATED -> use getTimestamp instead.
80+
"""
81+
function timestamp(v::DataLevel1)
82+
@warn "timestamp deprecated, use getTimestamp instead"
83+
getTimestamp(v)
84+
end
85+
86+
"""
87+
$SIGNATURES
88+
89+
Set the timestamp of a DFGFactor object.
90+
"""
91+
setTimestamp!(v::DataLevel1, ts::DateTime) = v.timestamp = ts
92+
93+
94+
"""
95+
$SIGNATURES
96+
97+
Return the internal ID for a variable.
98+
"""
99+
getInternalId(v::DataLevel1) = v._internalId
100+
101+
"""
102+
$SIGNATURES
103+
104+
Return the internal ID for a variable.
105+
106+
DEPRECATED, internalId -> getInternalId
107+
"""
108+
function internalId(v::DataLevel1)
109+
@warn "Deprecated interalId, use getInternalId instead."
110+
getInternalId(v)
111+
end

src/entities/DFGFactor.jl

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -88,63 +88,7 @@ SkeletonDFGFactor(label::Symbol, variableOrderSymbols::Vector{Symbol} = Symbol[]
8888

8989
# Accessors
9090

91-
const FactorDataLevel0 = Union{DFGFactor, DFGFactorSummary, SkeletonDFGFactor}
92-
const FactorDataLevel1 = Union{DFGFactor, DFGFactorSummary}
93-
# const FactorDataLevel2 = Union{DFGFactor}
9491

95-
"""
96-
$SIGNATURES
97-
98-
Return the label for a factor.
99-
"""
100-
label(f::FactorDataLevel0) = f.label
101-
102-
"""
103-
$SIGNATURES
104-
105-
Return the tags for a variable.
106-
"""
107-
tags(f::FactorDataLevel0) = f.tags
108-
109-
"""
110-
$SIGNATURES
111-
112-
Set the tags for a factor.
113-
"""
114-
setTags!(f::FactorDataLevel0, tags::Vector{Symbol}) = f.tags = tags
115-
116-
"""
117-
$SIGNATURES
118-
119-
Get the timestamp from a DFGFactor object.
120-
121-
DEPRECATED -> use getTimestamp instead.
122-
"""
123-
function timestamp(v::FactorDataLevel1)
124-
@warn "timestamp deprecated, use getTimestamp instead"
125-
v.timestamp
126-
end
127-
128-
"""
129-
$SIGNATURES
130-
131-
Get the timestamp from a DFGFactor object.
132-
"""
133-
getTimestamp(v::FactorDataLevel1) = v.timestamp
134-
135-
"""
136-
$SIGNATURES
137-
138-
Set the timestamp of a DFGFactor object.
139-
"""
140-
setTimestamp!(v::FactorDataLevel1, ts::DateTime) = v.timestamp = ts
141-
142-
"""
143-
$SIGNATURES
144-
145-
Return the internal ID for a variable.
146-
"""
147-
internalId(f::FactorDataLevel1) = f._internalId
14892

14993
"""
15094
$SIGNATURES

src/entities/DFGVariable.jl

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -190,52 +190,6 @@ SkeletonDFGVariable(label::Symbol) = SkeletonDFGVariable(label, Symbol[])
190190
const VariableDataLevel0 = Union{DFGVariable, DFGVariableSummary, SkeletonDFGVariable}
191191
const VariableDataLevel1 = Union{DFGVariable, DFGVariableSummary}
192192

193-
"""
194-
$SIGNATURES
195-
196-
Return the label for a variable.
197-
"""
198-
label(v::VariableDataLevel0) = v.label
199-
200-
"""
201-
$SIGNATURES
202-
203-
Return the tags for a variable.
204-
"""
205-
tags(v::VariableDataLevel0) = v.tags
206-
207-
"""
208-
$SIGNATURES
209-
210-
Set the tags for a variable.
211-
"""
212-
setTags!(v::VariableDataLevel0, tags::Vector{Symbol}) = v.tags = tags
213-
214-
"""
215-
$SIGNATURES
216-
217-
Return the timestamp for a variable.
218-
219-
DEPRECATED -> use getTimestamp instead.
220-
"""
221-
function timestamp(v::VariableDataLevel1)
222-
@warn "timestamp is deprecated, use getTimestamp instead"
223-
v.timestamp
224-
end
225-
226-
"""
227-
$SIGNATURES
228-
229-
Return the timestamp for a variable.
230-
"""
231-
getTimestamp(v::VariableDataLevel1) = v.timestamp
232-
233-
"""
234-
$SIGNATURES
235-
236-
Set the timestamp for a variable.
237-
"""
238-
setTimestamp!(v::VariableDataLevel1, timestamp::DateTime) = v.timestamp = timestamp
239193

240194
"""
241195
$SIGNATURES

0 commit comments

Comments
 (0)