Exemple #1
0
def __get_bubble_from_support_step(arg_uid_user: int, uid_system: int, db_user: User, lang: str) \
        -> Optional[List[list]]:
    """
    Creates bubbles for the support-keyword for an statement.

    :param arg_uid_user: User.uid
    :param uid_system: Argument.uid
    :param db_user: User
    :param lang: Language.ui_locales
    :return: [dict()]
    """
    db_arg_user = DBDiscussionSession.query(Argument).get(arg_uid_user)
    db_arg_system = DBDiscussionSession.query(Argument).get(uid_system)

    if not db_arg_user or not db_arg_system:
        return None

    user_text = get_text_for_argument_uid(arg_uid_user)
    bubble_user = create_speechbubble_dict(BubbleTypes.USER, content=user_text, omit_bubble_url=True,
                                           argument_uid=arg_uid_user, is_supportive=db_arg_user.is_supportive,
                                           db_user=db_user, lang=lang)

    argument_text = get_text_for_argument_uid(uid_system, colored_position=True, with_html_tag=True, attack_type='jump')
    offset = len('</' + tag_type + '>') if argument_text.endswith('</' + tag_type + '>') else 1

    while argument_text[:-offset].endswith(('.', '?', '!')):
        argument_text = argument_text[:-offset - 1] + argument_text[-offset:]

    text = get_text_for_support(db_arg_system, argument_text, db_user.nickname, Translator(lang))
    db_other_author = DBDiscussionSession.query(User).get(db_arg_system.author_uid)
    bubble_system = create_speechbubble_dict(BubbleTypes.SYSTEM, content=text, omit_bubble_url=True, lang=lang,
                                             other_author=db_other_author)

    return [bubble_user, bubble_system]
Exemple #2
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]
Exemple #3
0
    def get_dict_for_supporting_each_other(self, uid_system_arg, uid_user_arg,
                                           nickname) -> dict:
        """
        Returns the dictionary during the supporting step

        :param uid_system_arg: Argument.uid
        :param uid_user_arg: Argument.uid
        :param nickname: User.nickname
        :return: dict()
        """
        logger('DictionaryHelper', str(uid_system_arg))
        _tn = Translator(self.lang)
        bubbles_array = history_helper.create_bubbles_from_history(
            self.history, nickname, self.lang, self.slug)
        db_arg_system = DBDiscussionSession.query(Argument).get(uid_system_arg)
        db_arg_user = DBDiscussionSession.query(Argument).get(uid_user_arg)

        argument_text = get_text_for_argument_uid(uid_system_arg,
                                                  colored_position=True,
                                                  with_html_tag=True,
                                                  attack_type='jump')

        offset = len('</' + tag_type +
                     '>') if argument_text.endswith('</' + tag_type +
                                                    '>') else 1
        while argument_text[:-offset].endswith(('.', '?', '!')):
            argument_text = argument_text[:-offset -
                                          1] + argument_text[-offset:]

        sys_text = get_text_for_support(db_arg_system, argument_text, nickname,
                                        _tn)

        self.__append_now_bubble(bubbles_array)

        user_text = get_text_for_argument_uid(uid_user_arg, nickname=nickname)
        bubble_user = create_speechbubble_dict(
            BubbleTypes.USER,
            content=user_text,
            omit_bubble_url=True,
            argument_uid=uid_user_arg,
            is_supportive=db_arg_user.is_supportive,
            lang=self.lang,
            nickname=nickname)
        bubbles_array.append(bubble_user)

        bubble = create_speechbubble_dict(
            BubbleTypes.SYSTEM,
            uid='question-bubble-{}'.format(uid_system_arg),
            content=sys_text,
            omit_bubble_url=True,
            lang=self.lang)
        bubbles_array.append(bubble)

        return {
            'bubbles': bubbles_array,
            'add_premise_text': '',
            'save_statement_url': '',
            'mode': '',
            'broke_limit': self.broke_limit
        }
Exemple #4
0
    def __add_discussion_end_text_at_justify_argumentation(
            self, discussion_dict, extras_dict, nickname, gender, _tn):
        """
        Replaced some text parts in the discussion dict() when the discussion ends during the justification

        :param discussion_dict: dict()
        :param extras_dict: dict()
        :param nickname: User.nickname
        :param gender: User.gender
        :param _tn: Translator
        :return: None
        """
        discussion_dict['mode'] = 'justify_argumentation'
        db_user = DBDiscussionSession.query(User).filter_by(
            nickname=nickname).first()

        is_read_only = DBDiscussionSession.query(Issue).filter_by(
            slug=extras_dict['slug']).first().is_read_only
        if nickname and not is_read_only:
            extras_dict[
                'add_premise_container_style'] = ''  # this will remove the 'display: none;'-style
        extras_dict['close_premise_container'] = False
        extras_dict['show_display_style'] = False
        if is_read_only:
            mid_text = _tn.get(_.discussionEndAndReadOnly)
            sdict = create_speechbubble_dict(BubbleTypes.INFO,
                                             content=mid_text,
                                             db_user=db_user,
                                             lang=self.system_lang)
            discussion_dict['bubbles'].append(sdict)

        elif nickname:
            if gender == 'f':
                mid_text = _tn.get(_.firstOneReasonF)
            elif gender == 'm':
                mid_text = _tn.get(_.firstOneReasonM)
            else:
                mid_text = _tn.get(_.firstOneReason)
            sdict = create_speechbubble_dict(BubbleTypes.INFO,
                                             content=mid_text,
                                             db_user=db_user,
                                             lang=self.system_lang)
            discussion_dict['bubbles'].append(sdict)
        else:
            mid_text = _tn.get(_.discussionEnd) + ' ' + _tn.get(
                _.feelFreeToLogin)
            sdict = create_speechbubble_dict(BubbleTypes.INFO,
                                             content=mid_text,
                                             db_user=db_user,
                                             lang=self.system_lang)
            discussion_dict['bubbles'].append(sdict)
    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
        }
Exemple #6
0
def __get_bubble_from_justify_statement_step(step: str, db_user: User,
                                             lang: str,
                                             url: str) -> List[dict]:
    """
    Creates bubbles for the justify-keyword for an statement.

    :param step: String
    :param db_user: User
    :param lang: ui_locales
    :param url: String
    :return: [dict()]
    """
    steps = step.split('/')
    uid = int(steps[1])
    is_supportive = steps[2] == Attitudes.AGREE.value or steps[
        2] == Attitudes.DONT_KNOW.value

    _tn = Translator(lang)
    msg, tmp = get_user_bubble_text_for_justify_statement(
        uid, db_user, is_supportive, _tn)

    bubble_user = create_speechbubble_dict(BubbleTypes.USER,
                                           bubble_url=url,
                                           content=msg,
                                           omit_bubble_url=False,
                                           statement_uid=uid,
                                           is_supportive=is_supportive,
                                           db_user=db_user,
                                           lang=lang)
    return [bubble_user]
Exemple #7
0
def discussion_init(request):
    """
    Given a slug, show its positions.

    :param request: Request
    :return:
    """
    db_issue = request.validated['issue']
    intro = get_translation(_.initialPositionInterest, db_issue.lang)

    bubbles = [
        create_speechbubble_dict(BubbleTypes.SYSTEM,
                                 uid='start',
                                 content=intro,
                                 omit_bubble_url=True,
                                 lang=db_issue.lang)
    ]

    db_positions = DBDiscussionSession.query(Statement).filter(
        Statement.is_disabled == False, Statement.issue_uid == db_issue.uid,
        Statement.is_position == True).all()

    items = [
        Item([pos.get_textversion().content],
             "{}/attitude/{}".format(db_issue.slug, pos.uid))
        for pos in db_positions
    ]

    return {'bubbles': [Bubble(bubble) for bubble in bubbles], 'items': items}
Exemple #8
0
def discussion_init(request):
    """
    Given a slug, show its positions.

    :param request: Request
    :return:
    """
    db_issue: Issue = request.validated['issue']
    intro = get_translation(_.initialPositionInterest, db_issue.lang)

    bubbles: List[DataBubble] = [
        create_speechbubble_dict(BubbleTypes.SYSTEM, uid='start', content=intro, omit_bubble_url=True,
                                 lang=db_issue.lang)
    ]

    issues_statements = [el.statement_uid for el in
                         DBDiscussionSession.query(StatementToIssue).filter_by(issue_uid=db_issue.uid).all()]
    db_positions = DBDiscussionSession.query(Statement).filter(Statement.is_disabled == False,
                                                               Statement.uid.in_(issues_statements),
                                                               Statement.is_position == True).all()

    positions = [DataItem([pos.get_textversion().content], "/{}/attitude/{}".format(db_issue.slug, pos.uid))
                 for pos in db_positions]

    return {
        'bubbles': [DataBubble(bubble) for bubble in bubbles],
        'positions': positions
    }
    def get_dict_for_start(self, position_count):
        """
        Prepares the discussion dict with all bubbles for the first step in discussion,
        where the user chooses a position.

        :position_count: int
        :return: dict()
        """
        LOG.debug("At_start with positions: %s", position_count)
        _tn = Translator(self.lang)
        add_premise_text = _tn.get(_.whatIsYourIdea)
        intro = _tn.get(_.initialPositionInterest) + ' ...'
        save_statement_url = 'set_new_start_premise'

        start_bubble = create_speechbubble_dict(BubbleTypes.USER,
                                                uid='start',
                                                content=intro,
                                                omit_bubble_url=True,
                                                lang=self.lang)
        bubbles_array = [] if position_count == 1 else [start_bubble]

        return {
            'bubbles': bubbles_array,
            'add_premise_text': add_premise_text,
            'save_statement_url': save_statement_url,
            'mode': '',
            'broke_limit': self.broke_limit
        }
Exemple #10
0
    def get_dict_for_jump(self, uid) -> dict:
        """
        Prepares the discussion dict with all bubbles for the jump step

        :param uid: Argument.uid
        :return: dict()
        """
        logger('DictionaryHelper', 'argument ' + str(uid))
        _tn = Translator(self.lang)
        argument_text = get_text_for_argument_uid(uid,
                                                  colored_position=True,
                                                  with_html_tag=True,
                                                  attack_type='jump')
        bubbles_array = history_helper.create_bubbles_from_history(
            self.history, self.nickname, self.lang, self.slug)

        coming_from_jump = False
        if self.history:
            splitted_history = self.history.split('-')
            coming_from_jump = '/jump' in self.history[:-1] if len(
                splitted_history) > 0 else False
        intro = (_tn.get(_.canYouBeMorePrecise) +
                 '<br><br>') if coming_from_jump else ''

        db_argument = DBDiscussionSession.query(Argument).get(uid)
        if db_argument.conclusion_uid is not None:
            intro += _tn.get(_.whatDoYouThinkArgument).strip() + ': '
        else:
            bind = ', ' if self.lang == 'de' else ' '
            intro += _tn.get(_.whatDoYouThinkAboutThat) + bind + _tn.get(
                _.that) + ' '

        offset = len('</' + tag_type +
                     '>') if argument_text.endswith('</' + tag_type +
                                                    '>') else 1
        while argument_text[:-offset].endswith(('.', '?', '!')):
            argument_text = argument_text[:-offset -
                                          1] + argument_text[-offset:]

        text = intro + argument_text + '?'
        bubble = create_speechbubble_dict(BubbleTypes.SYSTEM,
                                          content=text,
                                          omit_bubble_url=True,
                                          lang=self.lang,
                                          uid='question-bubble-{}'.format(uid),
                                          is_markable=True)
        bubbles_array.append(bubble)

        # 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': '',
            'save_statement_url': '',
            'mode': '',
            'extras': statement_list,
            'broke_limit': self.broke_limit
        }
    def get_dict_for_choosing(self, uid, is_uid_argument,
                              is_supportive) -> dict:
        """
        Prepares the discussion dict with all bubbles for the choosing an premise,
        when the user inserted more than one new premise.

        :param uid: Argument.uid
        :param is_uid_argument: Boolean
        :param is_supportive: Boolean
        :return:
        """
        _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'

        LOG.debug("Choosing dictionary for bubbles.")
        a = _tn.get(_.soYouEnteredMultipleReasons)
        if is_uid_argument:
            c = get_text_for_argument_uid(uid)
        else:
            statement = DBDiscussionSession.query(Statement).get(uid)
            c = statement.get_text()

        if is_supportive:
            if is_uid_argument:
                b = _tn.get(_.whatIsYourMostImportantReasonForArgument)
            else:
                b = _tn.get(_.whatIsYourMostImportantReasonForStatement)
        else:
            if is_uid_argument:
                b = _tn.get(_.whatIsYourMostImportantReasonAgainstArgument)
            else:
                b = _tn.get(_.whatIsYourMostImportantReasonAgainstStatement)
        b = b.replace('{}', '')

        text = '{}. {}: {}?<br>{}...'.format(a, b, c, _tn.get(_.because))

        self.__append_now_bubble(bubbles_array)

        question_bubble = create_speechbubble_dict(BubbleTypes.SYSTEM,
                                                   uid='question-bubble',
                                                   content=text,
                                                   omit_bubble_url=True,
                                                   lang=self.lang)
        if not bubbles_already_last_in_list(bubbles_array, question_bubble):
            bubbles_array.append(question_bubble)

        return {
            'bubbles': bubbles_array,
            'add_premise_text': add_premise_text,
            'save_statement_url': save_statement_url,
            'mode': '',
            'broke_limit': self.broke_limit
        }
Exemple #12
0
    def __add_discussion_end_text_at_dont_know(self, discussion_dict,
                                               current_premise, gender, _tn,
                                               nickname):
        """
        Replaced some text parts in the discussion dict() when the discussion ends during the don't know step

        :param discussion_dict: dict()
        :param current_premise: String
        :param gender: User.gender
        :param _tn: Translator
        :param nickname: User.nickname
        :return: None
        """
        discussion_dict['mode'] = 'dont_know'
        endtext = _tn.get(_.discussionEndLinkTextRestartDiscussion)

        if len(current_premise) != 0:
            if gender == 'f':
                sys_text = _tn.get(_.firstOneInformationTextF)
            elif gender == 'm':
                sys_text = _tn.get(_.firstOneInformationTextM)
            else:
                sys_text = _tn.get(_.firstOneInformationText)
            sys_text = sys_text.format('<em>' + current_premise +
                                       ' </em>') + ' '
            sys_text += _tn.get(_.untilNowThereAreNoMoreInformation)
            mid_text = _tn.get(_.discussionEnd) + ' ' + endtext
        else:
            sys_text = _tn.get(_.untilNowThereAreNoMoreInformation)
            mid_text = _tn.get(_.discussionEnd) + ' ' + endtext

        db_user = DBDiscussionSession.query(User).filter_by(
            nickname=nickname).first()
        discussion_dict['bubbles'].append(
            create_speechbubble_dict(BubbleTypes.SYSTEM,
                                     content=sys_text,
                                     db_user=db_user,
                                     lang=self.system_lang))
        discussion_dict['bubbles'].append(
            create_speechbubble_dict(BubbleTypes.INFO,
                                     content=mid_text,
                                     db_user=db_user,
                                     lang=self.system_lang))
Exemple #13
0
    def __add_discussion_end_text_at_justify_statement(self, discussion_dict,
                                                       extras_dict, nickname,
                                                       current_premise,
                                                       supportive, gender,
                                                       _tn):
        """
        Replaced some text parts in the discussion dict() when the discussion ends during the justification

        :param discussion_dict: dict()
        :param extras_dict: dict()
        :param nickname: User.nickname
        :param current_premise: String
        :param supportive: Boolean
        :param gender: User.gender
        :param _tn: Translator
        :return: None
        """
        discussion_dict['mode'] = 'justify'
        if gender == 'f':
            mid_text = _tn.get(_.firstPremiseText1F)
        elif gender == 'm':
            mid_text = _tn.get(_.firstPremiseText1M)
        else:
            mid_text = _tn.get(_.firstOneInformationText)
        mid_text = mid_text.format('<em>{}</em>'.format(current_premise))

        if not supportive:
            mid_text += ' ' + _tn.get(_.doesNotHold)
        mid_text += '. '

        is_read_only = DBDiscussionSession.query(Issue).filter_by(
            slug=extras_dict['slug']).first().is_read_only
        if nickname and not is_read_only:
            extras_dict[
                'add_premise_container_style'] = ''  # this will remove the 'display: none;'-style
            mid_text += _tn.get(_.firstPremiseText2)
        else:
            endtext = _tn.get(_.discussionEndLinkTextRestartDiscussion)
            mid_text += _tn.get(_.discussionEnd) + ' ' + endtext

        db_user = DBDiscussionSession.query(User).filter_by(
            nickname=nickname).first()
        discussion_dict['bubbles'].append(
            create_speechbubble_dict(BubbleTypes.INFO,
                                     content=mid_text,
                                     db_user=db_user,
                                     lang=self.system_lang))
        extras_dict['close_premise_container'] = False
        extras_dict['show_display_style'] = False
        extras_dict['show_bar_icon'] = False
        extras_dict['is_editable'] = False
        extras_dict['is_reportable'] = False
    def __append_now_bubble(self, bubbles_array) -> None:
        """
        Appends the "now" bubble to the bubble array

        :param bubbles_array:
        :return:
        """
        if len(bubbles_array) > 0:
            _tn = Translator(self.lang)
            bubble = create_speechbubble_dict(BubbleTypes.STATUS,
                                              uid='now',
                                              content=_tn.get(_.now),
                                              omit_bubble_url=True,
                                              lang=self.lang)
            bubbles_array.append(bubble)
Exemple #15
0
    def __add_discussion_end_text_at_start(self, discussion_dict, extras_dict,
                                           nickname, gender, _tn):
        """
        Replaced some text parts in the discussion dict() when the discussion ends in the beginning

        :param discussion_dict: dict()
        :param extras_dict: dict()
        :param nickname: User.nickname
        :param gender: User.gender
        :param _tn: Translator
        :return: None
        """
        discussion_dict['mode'] = 'start'
        if gender == 'f':
            user_text = _tn.get(_.firstPositionTextF)
        elif gender == 'm':
            user_text = _tn.get(_.firstPositionTextM)
        else:
            user_text = _tn.get(_.firstPositionText)
        user_text += '<br>' + (_tn.get(
            _.pleaseAddYourSuggestion if nickname else _.feelFreeToLogin))

        db_user = DBDiscussionSession.query(User).filter_by(
            nickname=nickname).first()
        discussion_dict['bubbles'].append(
            create_speechbubble_dict(BubbleTypes.STATUS,
                                     content=user_text,
                                     db_user=db_user,
                                     lang=self.system_lang))

        is_read_only = DBDiscussionSession.query(Issue).filter_by(
            slug=extras_dict['slug']).first().is_read_only
        if nickname and not is_read_only:
            extras_dict[
                'add_statement_container_style'] = ''  # this will remove the 'display: none;'-style
            extras_dict['close_statement_container'] = False

        extras_dict['show_display_style'] = False
        extras_dict['show_bar_icon'] = False
        extras_dict['is_editable'] = False
        extras_dict['is_reportable'] = False
Exemple #16
0
def __get_bubble_from_justify_statement_step(step, db_user, lang, url):
    """
    Creates bubbles for the justify-keyword for an statement.

    :param step: String
    :param db_user: User
    :param lang: ui_locales
    :param url: String
    :return: [dict()]
    """
    logger('history_handler', 'def')
    steps = step.split('/')
    uid = int(steps[1])
    is_supportive = steps[2] == Attitudes.AGREE or steps[2] == Attitudes.DONT_KNOW

    _tn = Translator(lang)
    msg, tmp = get_user_bubble_text_for_justify_statement(uid, db_user, is_supportive, _tn)

    bubble_user = create_speechbubble_dict(BubbleTypes.USER, content=msg, omit_bubble_url=False, statement_uid=uid,
                                           is_supportive=is_supportive, nickname=db_user.nickname, lang=lang, bubble_url=url)
    return [bubble_user]
Exemple #17
0
def __get_bubble_from_attitude_step(step, nickname, lang, url):
    """
    Creates bubbles for the attitude-keyword for an statement.

    :param step: String
    :param nickname: User.nickname
    :param lang: ui_locales
    :param url: String
    :return: [dict()]
    """
    logger('history_handler', 'def')
    steps = step.split('/')
    uid = int(steps[1])
    text = get_text_for_statement_uid(uid)
    if lang != 'de':
        text = text[0:1].upper() + text[1:]
    bubble = create_speechbubble_dict(BubbleTypes.USER, content=text, omit_bubble_url=False, statement_uid=uid,
                                      nickname=nickname,
                                      lang=lang, bubble_url=url)

    return [bubble]
Exemple #18
0
    def get_dict_for_attitude(self, db_position: Statement) -> dict:
        """
        Prepares the discussion dict with all bubbles for the second step in discussion,
        where the user chooses her attitude.

        :param uid: Argument.uid
        :param db_position: Statement
        :return: dict()
        """
        logger('DictionaryHelper', 'at_attitude')
        _tn = Translator(self.lang)
        add_premise_text = ''
        save_statement_url = 'set_new_start_statement'
        statement_text = db_position.get_html()

        if self.lang != 'de':
            pos = len('<' + tag_type + ' data-argumentation-type="position">')
            statement_text = statement_text[0:pos +
                                            1].lower() + statement_text[pos +
                                                                        1:]

        text = _tn.get(_.whatDoYouThinkAbout)
        text += ' ' + statement_text + '?'
        bubble = create_speechbubble_dict(BubbleTypes.SYSTEM,
                                          content=text,
                                          omit_bubble_url=True,
                                          lang=self.lang)

        bubbles_array = [bubble]

        return {
            'bubbles': bubbles_array,
            'add_premise_text': add_premise_text,
            'save_statement_url': save_statement_url,
            'mode': '',
            'broke_limit': self.broke_limit
        }
    def get_dict_for_jump_decision(self, uid) -> dict:
        """
        Prepares the discussion dict with all bubbles for the jump decision step

        :param uid: Argument.uid
        :return: dict()
        """
        LOG.debug("Entering get_dict_got_jump_decision")
        _tn = Translator(self.lang)

        db_argument = DBDiscussionSession.query(Argument).get(uid)
        tag_premise = '<' + tag_type + ' data-argumentation-type="argument">'
        tag_conclusion = '<' + tag_type + ' data-argumentation-type="attack">'
        tag_end = '</' + tag_type + '>'
        premise = db_argument.get_premisegroup_text()
        premise = tag_premise + premise + tag_end
        conclusion = tag_conclusion + get_text_for_conclusion(
            db_argument) + tag_end
        aand = ' ' + _tn.get(_.aand) + ' '

        text = _tn.get(_.whatDoYouThinkAbout)
        text += ' ' + premise + aand + conclusion + '?'
        bubble = create_speechbubble_dict(BubbleTypes.SYSTEM,
                                          content=text,
                                          omit_bubble_url=True,
                                          lang=self.lang)

        bubbles_array = [bubble]

        return {
            'bubbles': bubbles_array,
            'add_premise_text': '',
            'save_statement_url': '',
            'mode': '',
            'broke_limit': self.broke_limit
        }
    def get_dict_for_justify_statement(self, db_statement: Statement, slug,
                                       is_supportive, count_of_items,
                                       db_user: User):
        """
        Prepares the discussion dict with all bubbles for the third step in discussion,
        where the user justifies his position.

        :param db_statement: Statement
        :param db_user: User
        :param slug: Issue.slug
        :param is_supportive: Boolean
        :param count_of_items: Integer
        :return: dict()
        """
        LOG.debug("Entering get_dict_for_justify_statement")
        _tn = Translator(self.lang)

        bubbles_array = history_handler.create_bubbles(self.history,
                                                       self.nickname,
                                                       self.lang, self.slug)

        save_statement_url = 'set_new_start_statement'
        text = db_statement.get_text()
        if not text:
            return None

        tag_start = '<{} data-argumentation-type="position">'.format(tag_type)
        tag_end = '</{}>'.format(tag_type)

        # system bubble
        system_question = get_system_bubble_text_for_justify_statement(
            is_supportive, _tn, tag_start, text, tag_end)

        # user bubble
        nickname = db_user.nickname if db_user and db_user.nickname != nick_of_anonymous_user else None
        user_text, add_premise_text = get_user_bubble_text_for_justify_statement(
            db_statement.uid, db_user, is_supportive, _tn)

        question_bubble = create_speechbubble_dict(BubbleTypes.SYSTEM,
                                                   content=system_question,
                                                   omit_bubble_url=True,
                                                   lang=self.lang)
        url = UrlManager(slug).get_url_for_statement_attitude(db_statement.uid)
        select_bubble = create_speechbubble_dict(
            BubbleTypes.USER,
            bubble_url=url,
            content=user_text,
            omit_bubble_url=False,
            statement_uid=db_statement.uid,
            is_supportive=is_supportive,
            db_user=db_user,
            lang=self.lang)

        if not bubbles_already_last_in_list(bubbles_array, select_bubble):
            bubbles_array.append(select_bubble)

        self.__append_now_bubble(bubbles_array)

        if not bubbles_already_last_in_list(bubbles_array, question_bubble):
            bubbles_array.append(question_bubble)

        if not self.nickname and count_of_items == 1:
            _t = Translator(self.lang)
            db_user = DBDiscussionSession.query(User).filter_by(
                nickname=nickname).first()
            msg_dict = {
                'm': _.voteCountTextFirstM,
                'f': _.voteCountTextFirstF,
                'n': _.voteCountTextFirst,
            }

            if db_user:
                msg = msg_dict[db_user.gender]
            else:
                msg = _.voteCountTextFirst

            msg = _t.get(msg) + '.'

            bubbles_array.append(
                create_speechbubble_dict(BubbleTypes.INFO,
                                         uid='now_first',
                                         content=msg +
                                         _tn.get(_.onlyOneItemWithLink),
                                         omit_bubble_url=True,
                                         lang=self.lang))
        return {
            'bubbles': bubbles_array,
            'add_premise_text': add_premise_text,
            'save_statement_url': save_statement_url,
            'mode': '',
            'is_supportive': is_supportive,
            'broke_limit': self.broke_limit
        }
Exemple #21
0
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]
    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
        }
Exemple #23
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]
    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
        }