def push_telegram_interloc(ctx: rs.ContextWrapper, telegram_node: Node, name: str): """ Push the telegram_node into interloc:all:name """ if ctx.push(parent_property_or_path=interloc.prop_all, child=rs.Property(name=name, default_value=telegram_node)): logger.debug(f"Pushed {telegram_node} to interloc:all")
def recognize_faces(ctx: rs.ContextWrapper): """ Activates with each incoming face data served by face oracle. Responsible for synchronizing the node of person in vision with the anonymous interlocutor node. Uses face oracle filter to organize the incoming data and find out the right person. """ face_filter: FaceOracleFilter = ctx[prop_face_filter] faces: Faces = ctx[prop_subscribe_faces] # Push faces to face filter best_guess_changed = face_filter.push_message(faces) if best_guess_changed: current_best_guess: Person = face_filter.current_best_guess onto: Ontology = mem.get_ontology() sess: Session = mem.get_session() person_node = Node(metatype=onto.get_type("Person")) best_guess_id = current_best_guess.id face_vector = current_best_guess.face_vector if current_best_guess.is_known: person_node_query = sess.retrieve(node_id=best_guess_id) if person_node_query: person_node = person_node_query[0] else: err_msg = "Person with id %s is not found in memory." % best_guess_id logger.error(err_msg) return else: person_node.set_properties({ 'face_vector': face_vector, 'name': interloc.ANON_INTERLOC_ID }) push = False # Check if there is any interlocutor. If necessary and pop the current node and push person node # instead. if any(ctx.enum(interloc.prop_all)): interloc_node: Node = ctx[ f'interloc:all:{interloc.ANON_INTERLOC_ID}'] # If interloc and the person nodes are not same pop and push person node. if not (interloc_node.get_id() == person_node.get_id() ) or interloc_node.get_id() < 0: # Remove the current interloc logger.info('Popping current interlocutor') popped_node = ctx.pop( f'interloc:all:{interloc.ANON_INTERLOC_ID}') assert popped_node == True push = True else: # Update the face vector of the person already familiar with save_face(ctx, interloc_node.get_id(), current_best_guess.face_vector) else: push = True if push: # Push the new interlocutor ctx.push(parent_property_or_path=interloc.prop_all, child=rs.Property(name=interloc.ANON_INTERLOC_ID, default_value=person_node)) logger.info( f"Pushed node with id {person_node.id} to interloc:all" )