def test_get_text_for_confrontation_with_undercut_for_en(self): user_arg = DBDiscussionSession.query(Argument).get(8) sys_arg = DBDiscussionSession.query(Argument).get(10) attack = Relations.UNDERCUT for combo in list(itertools.product([False, True], repeat=4)): color_html, supportive, reply_for_argument, user_is_attacking = combo text = '<span class="triangle-content-text">Other participants do not have any opinion regarding some premise text. But they do <span data-attitude="con">not</span> believe that this is <span data-attitude="con">a good ' if not color_html and not supportive: text += 'counter-argument for</span></span> some conclusion text<span>. Other participants think that</span> some confrontation text<span>.' elif not color_html and supportive: text += 'argument for</span></span> some conclusion text<span>. Other participants think that</span> some confrontation text<span>.' elif color_html and not supportive: text += 'counter-argument for</span></span> <span data-argumentation-type="argument">some conclusion text</span><span>. Other participants think that</span> <span data-argumentation-type="attack">some confrontation text</span><span>.' elif color_html and supportive: text += 'argument for</span></span> <span data-argumentation-type="argument">some conclusion text</span><span>. Other participants think that</span> <span data-argumentation-type="attack">some confrontation text</span><span>.' text += '<br><br>What do you think about that?</span>' sys_text, gender = tg.get_text_for_confrontation( 'en', 'Tobias', self.premise, self.conclusion, 'another conlcusion', supportive, attack, self.confrontation, reply_for_argument, user_is_attacking, user_arg, sys_arg, color_html) self.assertEqual(gender, '') self.assertEqual(sys_text, text)
def test_get_text_for_confrontation_with_undercut_for_de(self): user_arg = DBDiscussionSession.query(Argument).get(8) sys_arg = DBDiscussionSession.query(Argument).get(10) attack = Relations.UNDERCUT for combo in list(itertools.product([False, True], repeat=4)): color_html, supportive, reply_for_argument, user_is_attacking = combo text = '<span class="triangle-content-text">Andere Teilnehmer haben bisher keine Meinung dazu, dass some premise text. Aber sie glauben, dass es <span data-attitude="con">keine gute Begründung ' if not color_html and not supportive: text += 'dagegen</span> ist, <span data-attitude="con">dass</span></span> some conclusion text<span>. Die anderen Teilnehmer denken, dass</span> some confrontation text<span>.' elif not color_html and supportive: text += 'dafür</span> ist, <span data-attitude="con">dass</span></span> some conclusion text<span>. Die anderen Teilnehmer denken, dass</span> some confrontation text<span>.' elif color_html and not supportive: text += 'dagegen</span> ist, <span data-attitude="con">dass</span></span> <span data-argumentation-type="argument">some conclusion text</span><span>. Die anderen Teilnehmer denken, dass</span> <span data-argumentation-type="attack">some confrontation text</span><span>.' elif color_html and supportive: text += 'dafür</span> ist, <span data-attitude="con">dass</span></span> <span data-argumentation-type="argument">some conclusion text</span><span>. Die anderen Teilnehmer denken, dass</span> <span data-argumentation-type="attack">some confrontation text</span><span>.' text += '<br><br>Was denken Sie darüber?</span>' sys_text, gender = tg.get_text_for_confrontation( 'de', 'Tobias', self.premise, self.conclusion, 'another conlcusion', supportive, attack, self.confrontation, reply_for_argument, user_is_attacking, user_arg, sys_arg, color_html) self.assertEqual(gender, '') self.assertEqual(sys_text, text)
def test_get_text_for_confrontation_without_attack(self): user_arg = DBDiscussionSession.query(Argument).get(8) sys_arg = DBDiscussionSession.query(Argument).get(10) attack = '' color_html, supportive, reply_for_argument, user_is_attacking = False, False, False, False sys_text, gender = tg.get_text_for_confrontation('en', 'Tobias', self.premise, self.conclusion, 'another conclusion', supportive, attack, self.confrontation, reply_for_argument, user_is_attacking, user_arg, sys_arg, color_html) self.assertEqual(gender, '') self.assertEqual(sys_text, '')
def test_get_text_for_confrontation_with_rebut_for_de(self): user_arg = DBDiscussionSession.query(Argument).get(8) sys_arg = DBDiscussionSession.query(Argument).get(10) attack = Relations.REBUT for combo in list(itertools.product([False, True], repeat=4)): color_html, supportive, reply_for_argument, user_is_attacking = combo text = '<span class="triangle-content-text">' if not color_html and not reply_for_argument and not user_is_attacking: # valid for color_html, supportive, reply_for_argument, user_is_attacking = (False, False, False, False) # valid for color_html, supportive, reply_for_argument, user_is_attacking = (False, True, False, False) text += 'Andere Teilnehmer haben bisher keine Meinung dazu, dass some premise text. Aber sie nennen einen <span data-attitude="con">Grund dagegen, dass </span> some conclusion text. <span>Sie sagen, dass:</span> some confrontation text' elif not color_html and not reply_for_argument and user_is_attacking: # valid for color_html, supportive, reply_for_argument, user_is_attacking = (False, False, False, True) # valid for color_html, supportive, reply_for_argument, user_is_attacking = (False, True, False, True) text += 'Andere Teilnehmer haben bisher keine Meinung dazu, dass some premise text. Aber sie nennen einen <span data-attitude="pro">Grund dafür, dass </span> some conclusion text. <span>Sie sagen, dass:</span> some confrontation text' elif not color_html and reply_for_argument: # valid for color_html, supportive, reply_for_argument, user_is_attacking = (False, False, True, False) # valid for color_html, supportive, reply_for_argument, user_is_attacking = (False, False, True, True) # valid for color_html, supportive, reply_for_argument, user_is_attacking = (False, True, True, False) # valid for color_html, supportive, reply_for_argument, user_is_attacking = (False, True, True, True) text += '<span>Andere Teilnehmer haben eine stärkere Aussage zur Ablehnung davon, dass</span> some conclusion text. <span>Sie sagen, dass</span> some confrontation text' elif color_html and not reply_for_argument and not user_is_attacking: # valid for color_html, supportive, reply_for_argument, user_is_attacking = (True, False, False, False) # valid for color_html, supportive, reply_for_argument, user_is_attacking = (True, True, False, False) text += 'Andere Teilnehmer haben bisher keine Meinung dazu, dass some premise text. Aber sie nennen einen <span data-attitude="con">Grund <span data-argumentation-type="argument">dagegen</span>, dass </span> <span data-argumentation-type="argument">some conclusion text</span>. <span>Sie sagen, dass:</span> <span data-argumentation-type="attack">some confrontation text</span>' elif color_html and not reply_for_argument and user_is_attacking: # valid for color_html, supportive, reply_for_argument, user_is_attacking = (True, True, False, True) # valid for color_html, supportive, reply_for_argument, user_is_attacking = (True, False, False, True) text += 'Andere Teilnehmer haben bisher keine Meinung dazu, dass some premise text. Aber sie nennen einen <span data-attitude="pro">Grund <span data-argumentation-type="argument">dafür</span>, dass </span> <span data-argumentation-type="argument">some conclusion text</span>. <span>Sie sagen, dass:</span> <span data-argumentation-type="attack">some confrontation text</span>' elif color_html and reply_for_argument: # valid for color_html, supportive, reply_for_argument, user_is_attacking = (True, False, True, False) # valid for color_html, supportive, reply_for_argument, user_is_attacking = (True, False, True, True) # valid for color_html, supportive, reply_for_argument, user_is_attacking = (True, True, True, False) # valid for color_html, supportive, reply_for_argument, user_is_attacking = (True, True, True, True) text += '<span>Andere Teilnehmer haben eine stärkere Aussage zur <span data-argumentation-type="argument">Ablehnung</span> davon, dass</span> <span data-argumentation-type="argument">some conclusion text</span>. <span>Sie sagen, dass</span> <span data-argumentation-type="attack">some confrontation text</span>' text += '<span>.<br><br>Was denken Sie darüber?</span>' sys_text, gender = tg.get_text_for_confrontation( 'de', 'Tobias', self.premise, self.conclusion, 'another conclusion', supportive, attack, self.confrontation, reply_for_argument, user_is_attacking, user_arg, sys_arg, color_html) self.assertEqual(gender, 'n') self.assertEqual(sys_text, text)
def test_get_text_for_confrontation_with_rebut_for_en(self): user_arg = DBDiscussionSession.query(Argument).get(8) sys_arg = DBDiscussionSession.query(Argument).get(10) attack = Relations.REBUT for combo in list(itertools.product([False, True], repeat=4)): color_html, supportive, reply_for_argument, user_is_attacking = combo text = '' if not color_html and not reply_for_argument and not user_is_attacking: # valid for color_html, supportive, reply_for_argument, user_is_attacking = (False, False, False, False) # valid for color_html, supportive, reply_for_argument, user_is_attacking = (False, True, False, False) text = '<span class="triangle-content-text">Other participants do not have any opinion regarding some premise text. But they claim to have a stronger <span data-attitude="con">statement for rejecting </span> some conclusion text. <span>They say:</span> some confrontation text<span>.' elif not color_html and not reply_for_argument and user_is_attacking: # valid for color_html, supportive, reply_for_argument, user_is_attacking = (False, False, False, True) # valid for color_html, supportive, reply_for_argument, user_is_attacking = (False, True, False, True) text = '<span class="triangle-content-text">Other participants do not have any opinion regarding some premise text. But they claim to have a stronger <span data-attitude="pro">statement for accepting </span> some conclusion text. <span>They say:</span> some confrontation text<span>.' elif not color_html and reply_for_argument: # valid for color_html, supportive, reply_for_argument, user_is_attacking = (False, False, True, False) # valid for color_html, supportive, reply_for_argument, user_is_attacking = (False, False, True, True) # valid for color_html, supportive, reply_for_argument, user_is_attacking = (False, True, True, False) # valid for color_html, supportive, reply_for_argument, user_is_attacking = (False, True, True, True) text = '<span class="triangle-content-text"><span>Other participants claim to have a stronger statement to reject</span> some conclusion text. <span>They say:</span> some confrontation text<span>.' elif color_html and not reply_for_argument and not user_is_attacking: # valid for color_html, supportive, reply_for_argument, user_is_attacking = (True, False, False, False) # valid for color_html, supportive, reply_for_argument, user_is_attacking = (True, True, False, False) text = '<span class="triangle-content-text">Other participants do not have any opinion regarding some premise text. But they claim to have a stronger <span data-attitude="con">statement for <span data-argumentation-type="argument">rejecting</span> </span> <span data-argumentation-type="argument">some conclusion text</span>. <span>They say:</span> <span data-argumentation-type="attack">some confrontation text</span><span>.' elif color_html and not reply_for_argument and user_is_attacking: # valid for color_html, supportive, reply_for_argument, user_is_attacking = (True, True, False, True) # valid for color_html, supportive, reply_for_argument, user_is_attacking = (True, False, False, True) text = '<span class="triangle-content-text">Other participants do not have any opinion regarding some premise text. But they claim to have a stronger <span data-attitude="pro">statement for <span data-argumentation-type="argument">accepting</span> </span> <span data-argumentation-type="argument">some conclusion text</span>. <span>They say:</span> <span data-argumentation-type="attack">some confrontation text</span><span>.' elif color_html and reply_for_argument: # valid for color_html, supportive, reply_for_argument, user_is_attacking = (True, False, True, False) # valid for color_html, supportive, reply_for_argument, user_is_attacking = (True, False, True, True) # valid for color_html, supportive, reply_for_argument, user_is_attacking = (True, True, True, False) # valid for color_html, supportive, reply_for_argument, user_is_attacking = (True, True, True, True) text = '<span class="triangle-content-text"><span>Other participants claim to have a stronger statement to <span data-argumentation-type="argument">reject</span></span> <span data-argumentation-type="argument">some conclusion text</span>. <span>They say:</span> <span data-argumentation-type="attack">some confrontation text</span><span>.' text += '<br><br>What do you think about that?</span>' sys_text, gender = tg.get_text_for_confrontation( 'en', 'Tobias', self.premise, self.conclusion, 'another conlcusion', supportive, attack, self.confrontation, reply_for_argument, user_is_attacking, user_arg, sys_arg, color_html) self.assertEqual(gender, 'n') self.assertEqual(sys_text, text)
def test_get_text_for_confrontation_with_undermine_for_en(self): user_arg = DBDiscussionSession.query(Argument).get(8) sys_arg = DBDiscussionSession.query(Argument).get(10) attack = Relations.UNDERMINE for combo in list(itertools.product([False, True], repeat=4)): color_html, supportive, reply_for_argument, user_is_attacking = combo text = '<span class="triangle-content-text">Other participants think that</span> ' if color_html: text += '<span data-argumentation-type="argument">some premise text</span><span data-attitude="con"><span> <span data-argumentation-type="argument">does not hold</span></span></span><span>, because</span> <span data-argumentation-type="attack">' else: text += '<span>some premise text</span><span data-attitude="con"><span> does not hold</span><span>, because</span> <span>' text += 'some confrontation text</span><span>.<br><br>What do you think about that?</span>' sys_text, gender = tg.get_text_for_confrontation( 'en', 'Tobias', self.premise, self.conclusion, 'another conlcusion', supportive, attack, self.confrontation, reply_for_argument, user_is_attacking, user_arg, sys_arg, color_html) self.assertEqual(gender, '') self.assertEqual(sys_text, text)
def test_get_text_for_confrontation_with_undermine_for_de(self): user_arg = DBDiscussionSession.query(Argument).get(8) sys_arg = DBDiscussionSession.query(Argument).get(10) attack = Relations.UNDERMINE for combo in list(itertools.product([False, True], repeat=4)): color_html, supportive, reply_for_argument, user_is_attacking = combo text = '<span class="triangle-content-text">Andere Teilnehmer denken, dass</span> ' if color_html: text += '<span data-argumentation-type="argument">some premise text</span><span data-attitude="con"><span> <span data-argumentation-type="argument">keine gute Idee ist</span></span></span><span>, weil</span> <span data-argumentation-type="attack">some confrontation text</span>' else: text += '<span>some premise text</span><span data-attitude="con"><span> keine gute Idee ist</span><span>, weil</span> <span>some confrontation text</span>' text += '<span>.<br><br>Was denken Sie darüber?</span>' sys_text, gender = tg.get_text_for_confrontation( 'de', 'Tobias', self.premise, self.conclusion, 'another conlcusion', supportive, attack, self.confrontation, reply_for_argument, user_is_attacking, user_arg, sys_arg, color_html) self.assertEqual(gender, '') self.assertEqual(sys_text, text)
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 __create_reaction_history_bubbles(step: str, db_user: User, lang: str, split_history: list, url: str, color_steps: bool, uid: int, additional_uid: int, attack) -> list: is_supportive = DBDiscussionSession.query(Argument).get(uid).is_supportive last_relation = get_last_relation(split_history) user_changed_opinion = len( split_history) > 1 and '/undercut/' in split_history[-2] support_counter_argument = False if step in split_history: index = split_history.index(step) try: support_counter_argument = 'reaction' in split_history[index - 1] except IndexError: support_counter_argument = False color_steps = color_steps and attack != Relations.SUPPORT # special case for the support round current_arg = get_text_for_argument_uid( uid, user_changed_opinion=user_changed_opinion, support_counter_argument=support_counter_argument, colored_position=color_steps, nickname=db_user.nickname, with_html_tag=color_steps) db_argument = DBDiscussionSession.query(Argument).get(uid) db_confrontation = DBDiscussionSession.query(Argument).get(additional_uid) reply_for_argument = True if db_argument.conclusion_uid is not None: db_statement = DBDiscussionSession.query(Statement).get( db_argument.conclusion_uid) reply_for_argument = not (db_statement and db_statement.is_position) premise = db_argument.get_premisegroup_text() conclusion = get_text_for_conclusion(db_argument) sys_conclusion = get_text_for_conclusion(db_confrontation) confr = db_confrontation.get_premisegroup_text() user_is_attacking = not db_argument.is_supportive if lang != 'de': current_arg = start_with_capital(current_arg) if current_arg.startswith('<'): pos = current_arg.index('>') current_arg = current_arg[0:pos] + current_arg[pos:pos + 1].upper( ) + current_arg[pos + 1:] premise = start_with_small(premise) _tn = Translator(lang) user_text = '' if last_relation == Relations.SUPPORT: user_text = _tn.get(_.otherParticipantsConvincedYouThat) + ': ' user_text += '<{}>{}</{}>'.format( tag_type, current_arg if current_arg != '' else premise, tag_type) sys_text, tmp = get_text_for_confrontation(lang, db_user.nickname, premise, conclusion, sys_conclusion, is_supportive, attack, confr, reply_for_argument, user_is_attacking, db_argument, db_confrontation, color_html=False) bubble_user = create_speechbubble_dict(BubbleTypes.USER, bubble_url=url, content=user_text, omit_bubble_url=False, argument_uid=uid, is_supportive=is_supportive, db_user=db_user, lang=lang) db_tmp = DBDiscussionSession.query(User).get(db_confrontation.author_uid) if not attack: bubble_syst = create_speechbubble_dict(BubbleTypes.SYSTEM, content=sys_text, omit_bubble_url=True, db_user=db_user, lang=lang, other_author=db_tmp) else: bubble_syst = create_speechbubble_dict(BubbleTypes.SYSTEM, uid='question-bubble-' + str(additional_uid), content=sys_text, omit_bubble_url=True, db_user=db_user, lang=lang, other_author=db_tmp) return [bubble_user, bubble_syst]
def get_bubble_from_reaction_step(step, db_user, lang, splitted_history, url, color_steps=False): """ Creates bubbles for the reaction-keyword. :param step: String :param db_user: User :param lang: ui_locales :param splitted_history: [String].uid :param url: String :param color_steps: Boolean :return: [dict()] """ logger('history_handler', 'def: {}, {}'.format(step, splitted_history)) steps = step.split('/') uid = int(steps[1]) attack = Relations.SUPPORT if 'reaction' in step: additional_uid = int(steps[3]) attack = relation_mapper[steps[2]] else: additional_uid = int(steps[2]) if not check_reaction(uid, additional_uid, attack): logger('history_handler', 'wrong reaction') return None is_supportive = DBDiscussionSession.query(Argument).get(uid).is_supportive last_relation = splitted_history[-1].split('/')[2] if len(splitted_history) > 1 else '' user_changed_opinion = len(splitted_history) > 1 and '/undercut/' in splitted_history[-2] support_counter_argument = False if step in splitted_history: index = splitted_history.index(step) try: support_counter_argument = 'reaction' in splitted_history[index - 1] except IndexError: support_counter_argument = False color_steps = color_steps and attack != Relations.SUPPORT # special case for the support round current_arg = get_text_for_argument_uid(uid, user_changed_opinion=user_changed_opinion, support_counter_argument=support_counter_argument, colored_position=color_steps, nickname=db_user.nickname, with_html_tag=color_steps) db_argument = DBDiscussionSession.query(Argument).get(uid) db_confrontation = DBDiscussionSession.query(Argument).get(additional_uid) reply_for_argument = True if db_argument.conclusion_uid is not None: db_statement = DBDiscussionSession.query(Statement).get(db_argument.conclusion_uid) reply_for_argument = not (db_statement and db_statement.is_position) premise = db_argument.get_premisegroup_text() conclusion = get_text_for_conclusion(db_argument) sys_conclusion = get_text_for_conclusion(db_confrontation) confr = db_confrontation.get_premisegroup_text() user_is_attacking = not db_argument.is_supportive if lang != 'de': current_arg = current_arg[0:1].upper() + current_arg[1:] if current_arg.startswith('<'): pos = current_arg.index('>') current_arg = current_arg[0:pos] + current_arg[pos:pos + 1].upper() + current_arg[pos + 1:] premise = premise[0:1].lower() + premise[1:] _tn = Translator(lang) user_text = (_tn.get(_.otherParticipantsConvincedYouThat) + ': ') if last_relation == Relations.SUPPORT else '' user_text += '<{}>{}</{}>'.format(tag_type, current_arg if current_arg != '' else premise, tag_type) sys_text, tmp = get_text_for_confrontation(lang, db_user.nickname, premise, conclusion, sys_conclusion, is_supportive, attack, confr, reply_for_argument, user_is_attacking, db_argument, db_confrontation, color_html=False) bubble_user = create_speechbubble_dict(BubbleTypes.USER, content=user_text, omit_bubble_url=False, argument_uid=uid, is_supportive=is_supportive, nickname=db_user.nickname, lang=lang, bubble_url=url) db_tmp = DBDiscussionSession.query(User).get(db_confrontation.author_uid) if not attack: bubble_syst = create_speechbubble_dict(BubbleTypes.SYSTEM, content=sys_text, omit_bubble_url=True, nickname=db_user.nickname, lang=lang, other_author=db_tmp) else: bubble_syst = create_speechbubble_dict(BubbleTypes.SYSTEM, uid='question-bubble-' + str(additional_uid), content=sys_text, omit_bubble_url=True, nickname=db_user.nickname, lang=lang, other_author=db_tmp) return [bubble_user, bubble_syst]