Esempio n. 1
0
def get_header_for_users_confrontation_response(db_argument, lang, premise, attack_type, conclusion, start_lower_case,
                                                is_supportive, is_logged_in, redirect_from_jump=False):
    """
    Based on the users reaction, text will be build. This text can be used for the speech bubbles where users
    justify an argument they have chosen.

    :param db_argument: Argument
    :param lang: ui_locales
    :param premise: current premise
    :param attack_type: type of the attack
    :param conclusion: current conclusion
    :param start_lower_case: boolean
    :param is_supportive: boolean
    :param is_logged_in: boolean
    :param redirect_from_jump: boolean
    :return: string
    """
    _t = Translator(lang)

    if premise[-1] == '.':
        premise = premise[:-1]

    if conclusion[-1] == '.':
        conclusion = conclusion[:-1]

    # pretty print
    r = _t.get(_.right)[0:1].upper()
    f = _t.get(_.itIsFalseThat)[0:1].upper()
    t = _t.get(_.itIsTrueThat)[0:1].upper()
    if start_lower_case:
        r = _t.get(_.right)[0:1].lower()
        f = _t.get(_.itIsFalseThat)[0:1].lower()
        t = _t.get(_.itIsTrueThat)[0:1].lower()

    r += _t.get(_.right)[1:] + ', '
    f += _t.get(_.itIsFalseThat)[1:]
    t += _t.get(_.itIsTrueThat)[1:]

    if lang == 'de':
        r += start_with_small(_t.get(_.itIsTrueThat)) + ' '
        f = _t.get(_.wrong) + ', ' + start_with_small(_t.get(_.itIsFalseThat)) + ' '

    if redirect_from_jump:
        r = _t.get(_.maybeItIsTrueThat) + ' '

    # different cases
    user_msg = __get_user_msg_for_users_confrontation_response(db_argument, attack_type, premise, conclusion, f, t, r,
                                                               is_supportive, _t)
    if not user_msg:
        user_msg = ''

    # is logged in?
    if is_logged_in:
        return user_msg, _t.get(_.canYouGiveAReasonForThat)
    else:
        return user_msg, ''
Esempio n. 2
0
    def get_dict_for_dont_know_reaction(self, uid, nickname) -> dict:
        """
        Prepares the discussion dict with all bubbles for the third step,
        where an supportive argument will be presented.

        :param uid: Argument.uid
        :param nickname:
        :return: dict()
        """
        LOG.debug("Entering get_dict_for_dont_know_reaction")
        _tn = Translator(self.lang)
        bubbles_array = history_handler.create_bubbles(self.history,
                                                       self.nickname,
                                                       self.lang, self.slug)
        add_premise_text = ''
        save_statement_url = 'set_new_start_statement'
        gender = ''
        b = '<' + tag_type + '>'
        e = '</' + tag_type + '>'
        statement_list = list()

        if int(uid) != 0:
            text = get_text_for_argument_uid(uid,
                                             rearrange_intro=True,
                                             attack_type='dont_know',
                                             with_html_tag=True,
                                             start_with_intro=True)
            db_argument = DBDiscussionSession.query(Argument).get(uid)
            if not db_argument:
                text = ''
            data = get_name_link_of_arguments_author(db_argument, nickname)
            gender = data['gender']
            if data['is_valid']:
                intro = data['link'] + ' ' + b + _tn.get(_.thinksThat) + e
            else:
                intro = b + _tn.get(_.otherParticipantsThinkThat) + e
            sys_text = intro + ' ' + start_with_small(text) + '. '
            sys_text += '<br><br> ' + b + _tn.get(
                _.whatDoYouThinkAboutThat) + '?' + e
            bubble_sys = create_speechbubble_dict(BubbleTypes.SYSTEM,
                                                  is_markable=True,
                                                  uid=uid,
                                                  content=sys_text,
                                                  other_author=data['user'])
            if not bubbles_already_last_in_list(bubbles_array, bubble_sys):
                bubbles_array.append(bubble_sys)

            # add statements of discussion to report them
            statement_list = self.__get_all_statement_texts_by_argument(
                db_argument)

        return {
            'bubbles': bubbles_array,
            'add_premise_text': add_premise_text,
            'save_statement_url': save_statement_url,
            'mode': '',
            'extras': statement_list,
            'gender': gender,
            'broke_limit': self.broke_limit
        }
Esempio n. 3
0
def __get_bubble_from_dont_know_step(step: str, db_user: User, lang: str) -> List[dict]:
    """
    Creates bubbles for the don't-know-reaction for a statement.

    :param step: String
    :param db_user: User
    :param lang: ui_locales
    :return: [dict()]
    """
    steps = step.split('/')
    uid = int(steps[1])

    text = get_text_for_argument_uid(uid, rearrange_intro=True, attack_type='dont_know', with_html_tag=False,
                                     start_with_intro=True)
    db_argument = DBDiscussionSession.query(Argument).get(uid)
    if not db_argument:
        text = ''

    from dbas.strings.text_generator import get_name_link_of_arguments_author
    _tn = Translator(lang)

    data = get_name_link_of_arguments_author(db_argument, db_user.nickname, False)
    if data['is_valid']:
        intro = data['link'] + ' ' + _tn.get(_.thinksThat)
    else:
        intro = _tn.get(_.otherParticipantsThinkThat)
    sys_text = intro + ' ' + start_with_small(text) + '. '
    sys_text += '<br><br>' + _tn.get(_.whatDoYouThinkAboutThat) + '?'
    sys_bubble = create_speechbubble_dict(BubbleTypes.SYSTEM, content=sys_text, db_user=db_user,
                                          other_author=data['user'])

    text = _tn.get(_.showMeAnArgumentFor) + (' ' if lang == 'de' else ': ') + get_text_for_conclusion(db_argument)
    user_bubble = create_speechbubble_dict(BubbleTypes.USER, content=text, db_user=db_user)

    return [user_bubble, sys_bubble]
Esempio n. 4
0
def __build_single_argument(db_argument: Argument, rearrange_intro: bool, with_html_tag: bool, colored_position: bool,
                            attack_type: str, _t: Translator, start_with_intro: bool, is_users_opinion: bool,
                            anonymous_style: bool, support_counter_argument: bool = False, author_uid=None):
    """
    Build up argument text for a single argument

    Please, do not touch this!

    :param rearrange_intro: Boolean
    :param with_html_tag: Boolean
    :param colored_position: Boolean
    :param attack_type: String
    :param _t: Translator
    :param start_with_intro: Boolean
    :param is_users_opinion: Boolean
    :param anonymous_style: Boolean
    :param support_counter_argument: Boolean
    :param author_uid: User.uid
    :return: String
    """
    premises_text = db_argument.get_premisegroup_text()
    conclusion_text = db_argument.get_conclusion_text()
    lang = db_argument.lang

    if lang != 'de':
        premises_text = start_with_small(premises_text)

    tag_dict = __get_tags_for_building_single_argument(with_html_tag, attack_type, colored_position, premises_text,
                                                       conclusion_text)
    premises_text = tag_dict['premise']
    conclusion_text = tag_dict['conclusion']
    sb = tag_dict['tag_begin']
    sb_none = tag_dict['tag_none']
    se = tag_dict['tag_end']

    marked_element = False
    if author_uid:
        db_marked = DBDiscussionSession.query(MarkedArgument).filter(MarkedArgument.argument_uid == db_argument.uid,
                                                                     MarkedArgument.author_uid == author_uid).first()
        marked_element = db_marked is not None

    you_have_the_opinion_that = _t.get(_.youHaveTheOpinionThat).format('').strip()

    if lang == 'de':
        ret_value = __build_single_argument_for_de(_t, sb, se, you_have_the_opinion_that, start_with_intro,
                                                   anonymous_style, rearrange_intro, db_argument, attack_type, sb_none,
                                                   marked_element, lang, premises_text, conclusion_text,
                                                   is_users_opinion,
                                                   support_counter_argument)
    else:
        ret_value = __build_single_argument_for_en(_t, sb, se, you_have_the_opinion_that, marked_element,
                                                   conclusion_text,
                                                   premises_text, db_argument)
    return ret_value.replace('  ', ' ')
Esempio n. 5
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
        }
Esempio n. 6
0
    def get_dict_for_justify_argument(self, uid, is_supportive, attack):
        """
        Prepares the discussion dict with all bubbles for a step in discussion,
        where the user justifies his attack she has done.

        :param uid: Argument.uid
        :param is_supportive: Boolean
        :param attack: String (undermine, support, undercut, rebut, ...)
        :return: dict()
        """
        LOG.debug("Entering get_dict_for_justify_argument")
        _tn = Translator(self.lang)
        bubbles_array = history_handler.create_bubbles(self.history,
                                                       self.nickname,
                                                       self.lang, self.slug)
        add_premise_text = ''
        save_statement_url = 'set_new_premises_for_argument'

        db_argument = DBDiscussionSession.query(Argument).get(uid)
        if not db_argument:
            return {
                'bubbles': bubbles_array,
                'add_premise_text': add_premise_text,
                'save_statement_url': save_statement_url,
                'mode': '',
                'broke_limit': self.broke_limit
            }

        confrontation = get_text_for_argument_uid(uid)
        premise = db_argument.get_premisegroup_text()
        conclusion = get_text_for_conclusion(db_argument,
                                             is_users_opinion=False)

        if db_argument.conclusion_uid is None:
            conclusion = start_with_small(conclusion)

        while premise.endswith(('.', '?', '!')):
            premise = premise[:-1]
        while conclusion.endswith(('.', '?', '!')):
            conclusion = premise[:-1]

        redirect_from_jump = 'jump/' in self.history.split('-')[-1]
        user_msg, sys_msg = get_header_for_users_confrontation_response(
            db_argument,
            self.lang,
            premise,
            attack,
            conclusion,
            False,
            is_supportive,
            self.nickname,
            redirect_from_jump=redirect_from_jump)

        add_premise_text = self.__get_add_premise_text_for_justify_argument(
            confrontation, premise, attack, conclusion, db_argument,
            is_supportive, user_msg)
        start = '<{} data-argumentation-type="position">'.format(tag_type)
        end = '</{}>'.format(tag_type)
        user_msg = user_msg.format(start, end)

        pro_tag = '<{} class="text-success">'.format(tag_type)
        con_tag = '<{} class="text-danger">'.format(tag_type)
        end_tag = '</{}>'.format(tag_type)

        if attack == Relations.UNDERCUT:
            sys_msg = _tn.get(
                _.whatIsYourMostImportantReasonForArgument).rstrip().format(
                    pro_tag, end_tag) + ': '
            dot = '.'
        else:
            dot = '?'
            if attack == Relations.UNDERMINE:
                sys_msg = _tn.get(
                    _.whatIsYourMostImportantReasonAgainstStatement).rstrip(
                    ).format(con_tag, end_tag)
                sys_msg += ', ' if self.lang == 'de' else ' '
            else:
                sys_msg = _tn.get(_.whatIsYourMostImportantReasonForStatement
                                  ).rstrip().format(pro_tag, end_tag) + ': '

        sys_msg += user_msg + dot + '<br>' + _tn.get(_.because) + '...'

        self.__append_now_bubble(bubbles_array)
        sys_bubble = create_speechbubble_dict(BubbleTypes.SYSTEM,
                                              content=sys_msg,
                                              omit_bubble_url=True,
                                              lang=self.lang)
        if not bubbles_already_last_in_list(bubbles_array, sys_bubble):
            bubbles_array.append(sys_bubble)

        return {
            'bubbles': bubbles_array,
            'add_premise_text': add_premise_text,
            'save_statement_url': save_statement_url,
            'mode': '',
            'attack_type': attack,
            'arg_uid': uid,
            'broke_limit': self.broke_limit
        }
Esempio n. 7
0
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]
Esempio n. 8
0
 def test_start_with_small(self):
     self.assertEqual(start_with_small(''), '')
     self.assertEqual(start_with_small('asd'), 'asd')
     self.assertEqual(start_with_small('aSD'), 'aSD')
     self.assertEqual(start_with_small('Asd'), 'asd')
     self.assertEqual(start_with_small('ASD'), 'aSD')