Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
# in one or both list.
for (label, value) in allLabels:
if label in llist1.keys() and \
label in llist2.keys():
llist1[ label ] = \
combfn( llist1[label], weight1,\
llist2[label], weight2 )
elif label in llist2.keys():
llist1[ label ] = \
weight2 * llist2[label]
else:
llist1[ label ] = \
weight1 * llist1[label]
def mergeMaps(map1, weight1, map2, weight2, combfn):
"""Combine values in two maps according to the passed combfn
function, and passed weights for each map."""
# Odds are good that there are built-in function for this
# operation.
objects1 = map1.keys()
objects2 = map2.keys()
allObjects = set(objects1).union(set(objects2))
for object in allObjects:
if object in objects1 and object in objects2:
# Combine values for each label in lg2 already in self.
mergeLabelLists(map1[object],weight1, map2[object], weight2, combfn )
# DEBUG: no relationship ('missing') edges should
# be taken as certain (value 1.0 * weight) where not explicit.
elif object in objects2:
# Use copy to avoid aliasing problems.
# Use appropriate weight to update value.
map1[ object ] = copy.deepcopy( map2[ object ] )
for (label, value) in map1[object].items():
map1[object][label] = weight2 * value
map1[object]['_'] = weight1
else:
# Only in current map: weight value appropriately.
for (label, value) in map1[object].items():
map1[object][label] = weight1 * value
map1[object]['_'] = weight2