def __get_text_for_justification_or_reaction_bubble( stmt_or_arg: Union[Statement, Argument], is_supportive, db_user, step, history, _tn): """ Returns text for an justification or reaction bubble of the user :param stmt_or_arg: Argument.uid / Statement.uid :param is_supportive: Boolean :param db_user: User :param step: String :param history: String :param _tn: Translator :return: String """ if isinstance(stmt_or_arg, Argument): splitted_history = split(history) bubbles = get_bubble_from_reaction_step(step, db_user, _tn.get_lang(), splitted_history, '', color_steps=True) text = bubbles[0]['message'] if bubbles else '' else: text, tmp = get_user_bubble_text_for_justify_statement( stmt_or_arg.uid, db_user, is_supportive, _tn) text = pretty_print_options(text) return text
def test_jump_at_end(self): split_history = split( '/attitude/2-/justify/2/agree-/jump/11-/reaction/11/undermine/23-/justify/14/agree-/jump/24' ) last_relation = get_last_relation(split_history) self.assertEqual(last_relation, '')
def test_histry_empty(self): split_history = split('/') last_relation = get_last_relation(split_history) self.assertEqual(last_relation, '')
def test_get_splitted_history(self): hist = history.split(self.history) self.assertGreater(len(hist), 0)
def __get_dict_for_argumentation(self, user_arg: Argument, confrontation_arg_uid: int, history: str, attack: Relations, nickname: str, is_supportive: bool) -> dict: """ Returns dict() for the reaction step :param user_arg: Argument :param confrontation_arg_uid: Argument.uid :param history: String :param attack: String :param nickname: User.nickname :param is_supportive: Boolean :return: dict() """ premise = user_arg.get_premisegroup_text() conclusion = get_text_for_conclusion(user_arg) db_confrontation = DBDiscussionSession.query(Argument).get( confrontation_arg_uid) confr = db_confrontation.get_premisegroup_text() sys_conclusion = (db_confrontation.get_conclusion_text()) if attack == Relations.UNDERMINE: if db_confrontation.conclusion_uid != 0: premise = db_confrontation.get_conclusion_text() else: premise = get_text_for_argument_uid( db_confrontation.argument_uid, True, colored_position=True, attack_type=attack) # did the user changed his opinion? history = history_handler.split(history) user_changed_opinion = len(history) > 1 and '/undercut/' in history[-2] # argumentation is a reply for an argument, if the arguments conclusion of the user is no position conclusion_uid = user_arg.conclusion_uid tmp_arg = user_arg while not conclusion_uid: tmp_arg = DBDiscussionSession.query(Argument).get( tmp_arg.argument_uid) conclusion_uid = tmp_arg.conclusion_uid db_statement = DBDiscussionSession.query(Statement).get(conclusion_uid) reply_for_argument = not (db_statement and db_statement.is_position) support_counter_argument = 'reaction' in self.history.split('-')[-1] current_argument = get_text_for_argument_uid( user_arg.uid, nickname=nickname, with_html_tag=True, colored_position=True, user_changed_opinion=user_changed_opinion, attack_type=attack, minimize_on_undercut=True, support_counter_argument=support_counter_argument) current_argument = start_with_capital(current_argument) if self.lang != 'de': premise = start_with_small(premise) # check for support and build text _tn = Translator(self.lang) user_text = (_tn.get(_.otherParticipantsConvincedYouThat) + ': ') if user_changed_opinion else '' user_text += current_argument if current_argument != '' else premise sys_text, gender = get_text_for_confrontation( self.lang, nickname, premise, conclusion, sys_conclusion, is_supportive, attack, confr, reply_for_argument, not user_arg.is_supportive, user_arg, db_confrontation) gender_of_counter_arg = gender return { 'user': user_text, 'sys': sys_text, 'gender': gender_of_counter_arg, 'confrontation': db_confrontation }
def get_dict_for_argumentation(self, db_user_argument: Argument, arg_sys_id: Optional[int], attack: Optional[Relations], history: str, db_user: User) -> dict: """ Prepares the discussion dict with all bubbles for the argumentation window. :param db_user_argument: Argument :param arg_sys_id: Argument.uid / not necessary if attack=end :param attack: String (undermine, support, undercut, rebut, ...) :param history: History :param db_user: User :return: dict() """ LOG.debug("At_argumentation about %s", db_user_argument.uid) nickname = db_user.nickname if db_user.nickname == nick_of_anonymous_user: db_user = None nickname = None bubbles_array = history_handler.create_bubbles(self.history, nickname, self.lang, self.slug) add_premise_text = '' save_statement_url = 'set_new_start_statement' bubble_mid = '' splitted_history = history_handler.split(self.history) user_changed_opinion = splitted_history[-1].endswith( str(db_user_argument.uid)) statement_list = list() db_argument = DBDiscussionSession.query(Argument).get( db_user_argument.uid) gender_of_counter_arg = '' db_enemy = None if arg_sys_id is not None: db_tmp_arg = DBDiscussionSession.query(Argument).get(arg_sys_id) data = get_name_link_of_arguments_author(db_tmp_arg, nickname) db_enemy = data['user'] if not attack: prep_dict = self.__get_dict_for_argumentation_end( db_user_argument.uid, user_changed_opinion, db_user) bubble_sys = create_speechbubble_dict(BubbleTypes.SYSTEM, content=prep_dict['sys'], omit_bubble_url=True, lang=self.lang, other_author=db_enemy) bubble_mid = create_speechbubble_dict(BubbleTypes.INFO, content=prep_dict['mid'], omit_bubble_url=True, lang=self.lang) else: prep_dict = self.__get_dict_for_argumentation( db_argument, arg_sys_id, history, attack, nickname, db_user_argument.is_supportive) quid = 'question-bubble-' + str(arg_sys_id) if int( arg_sys_id) > 0 else '' is_author = is_author_of_argument(db_user, prep_dict['confrontation'].uid) bubble_sys = create_speechbubble_dict(BubbleTypes.SYSTEM, is_markable=True, is_author=is_author, uid=quid, content=prep_dict['sys'], omit_bubble_url=True, lang=self.lang, other_author=db_enemy) statement_list = self.__get_all_statement_texts_by_argument( prep_dict['confrontation']) gender_of_counter_arg = prep_dict['gender'] bubble_user = create_speechbubble_dict( BubbleTypes.USER, content=prep_dict['user'], omit_bubble_url=True, argument_uid=db_user_argument.uid, is_supportive=db_user_argument.is_supportive, db_user=db_user, lang=self.lang, other_author=db_enemy) # dirty fixes if len(bubbles_array) > 0 and bubbles_array[-1][ 'message'] == bubble_user['message']: bubbles_array.remove(bubbles_array[-1]) self.__append_now_bubble(bubbles_array) if not bubbles_already_last_in_list(bubbles_array, bubble_user): bubbles_array.append(bubble_user) if not bubbles_already_last_in_list(bubbles_array, bubble_sys): bubbles_array.append(bubble_sys) if not attack: bubbles_array.append(bubble_mid) return { 'bubbles': bubbles_array, 'add_premise_text': add_premise_text, 'save_statement_url': save_statement_url, 'mode': '', 'extras': statement_list, 'gender': gender_of_counter_arg, 'broke_limit': self.broke_limit }