def updateRep(self): if not hasattr(self, "frozen"): self.frozen = False for key, values in self: for value in values: if self.entireText == None: self.entireText = value.entireText else: assert self.entireText == value.entireText, ( self.entireText, value.entireText, key, str(value), [str(x) for x in values]) self.fields[key] = sorted(values, key=lambda x: x.range[0]) minRange = len(self.entireText) maxRange = 0 for key, values in self: for value in values: minValueRange, maxValueRange = value.range if minValueRange < minRange: minRange = minValueRange if maxValueRange > maxRange: maxRange = maxValueRange self.range = minRange, maxRange self.startIdx = minRange self.endIdx = maxRange self.text = self.entireText[self.startIdx:self.endIdx] self.flattenedEsdcs = flattenedEsdcs([self]) self.checkRep() self._repr = self.recomputeRepr() self._hash = hash(self._repr) self.hash_string = fasthash(self._repr) self.standoff = TextStandoff(self.entireText, self.range)
def update_rep(self): self.centroid3d = na.zeros(3) count = 0.0 self.start_t = None self.end_t = None for g in self.groundings: if hasattr(g, "centroid3d"): self.centroid3d += g.centroid3d count += 1 if hasattr(g, "start_t"): if self.start_t == None or g.start_t < self.start_t and g.start_t != 0: self.start_t = g.start_t if self.end_t == None or g.end_t > self.end_t: self.end_t = g.end_t if self.start_t == None or self.end_t == None: assert self.start_t == None assert self.end_t == None self.start_t = 0 self.end_t = 0 self.length_seconds = (self.end_t - self.start_t) / 1000000.0 self.centroid3d = self.centroid3d / count self.repr = ("Context(%s, %s)" % tuple(repr(x) for x in (self.objects, self.places))) self.hash_string = fasthash(self.repr)
def updateRep(self): self.centroid2d = self.prism.centroid2d() self.centroid3d = self.prism.centroid3d() self.X = self.prism.X self.Y = self.prism.Y if self.path == None: f_xyzth = tp([self.centroid3d + (0, )]) f_xyzth[2] = self.prism.zStart self.path = Path.from_xyztheta([0], f_xyzth) self.timestamps = self.path.timestamps self.start_t = self.path.start_t self.end_t = self.path.end_t self.points_xy = self.prism.points_xy self.points_pts = self.prism.points_pts self.repr = ("PhysicalObject(%s, %s, %s, %s)" % tuple( repr(x) for x in (self.prism, self.tags, self.path, self.id))) self.hash = 13 * hash(self.tags) + 17 * hash(self.prism) + 23 * hash( self.path) self.hash_string = fasthash(self.repr)
def __init__(self, factor_id, factor_type, link_name_to_node_ids): self.id = factor_id self.type = factor_type self.link_name_to_node_ids = link_name_to_node_ids self.nodes = [] for l in Factor.link_names: self.link_name_to_node_ids.setdefault(l, []) self.graph = None self._repr = ("Factor(%s, %s, %s)" % tuple( repr(x) for x in (self.id, self.type, self.link_name_to_node_ids))) self.hash_string = fasthash(self._repr)
def updateRep(self): self.X = self.prism.X self.Y = self.prism.Y self.points_xy = self.prism.points_xy self.points_pts = self.prism.points_pts self.start_t = 0 self.end_t = 0 self.repr = "Place(%s, %s)" % tuple( repr(x) for x in [self.prism, self.tags]) self.hash_string = fasthash(self.repr) self.id = self.hash_string f_xyzth = tp([self.centroid3d + (0, )]) f_xyzth[2] = self.prism.zStart self.path = Path.from_xyztheta([0], f_xyzth)
def factor_cost_key(self, factor, ggg): words = ggg.evidence_for_node(factor.lambda_node) txt = " ".join(w.text for w in words) groundings = {} for ln in Factor.link_names: gnodes = [n for n in factor.nodes_for_link(ln) if n.is_gamma] if len(gnodes) != 0: groundings[ln] = sorted( [[e.hash_string for e in ggg.evidence_for_node(n)] for n in gnodes]) key = " ".join( [factor.hash_string, ggg.context.hash_string, repr(groundings)]) key += txt key = key.replace(" ", "") self.last_bigkey = key return "cf_" + fasthash(key)
def updateRep(self): self.X, self.Y, self.Z, self.theta = self.points_xyztheta self.points_xy = self.points_xyztheta[0:2] self.points_xytheta = self.points_xyztheta[[0, 1, 3]] self.points_xyz = self.points_xyztheta[0:3] self.points_pts = self.points_xy.transpose() self.points_ptsztheta = self.points_xyztheta.transpose() self.start_t = self.timestamps[0] self.end_t = self.timestamps[-1] self.range = self.start_t, self.end_t self.length_seconds = (self.end_t - self.start_t) / Path.ONE_SECOND_IN_MICROS self.repr = "Path(%s, %s)" % tuple( repr(x) for x in (self.timestamps, self.points_xyztheta)) self.hash_string = fasthash(self.repr) self.id = self.hash_string
def __init__(self, context, new_objects): self.context = context self.new_objects = new_objects self.new_object_ids = set(o.id for o in new_objects) self.objects = unique_groundings(o for o in context.objects if not o in self.new_object_ids) self.places = context.places self.objects.extend(new_objects) self.grounding_id_to_grounding = dict(self.context.grounding_id_to_grounding) for o in self.objects: self.grounding_id_to_grounding[o.id] = o self.agent = self.grounding_id_to_grounding.get(self.getAgentId()) self.hash_string = fasthash(context.hash_string + " ".join(o.hash_string for o in new_objects))