예제 #1
0
    def __get_text_parts_of_argument(self, db_argument: Argument):
        """
        Get all parts of an argument as string

        :param db_argument: Argument.uid
        :return: list of strings
        """
        LOG.debug("Get all parts of an argument as string")
        ret_list = list()

        # get premise of current argument
        db_premises = DBDiscussionSession.query(Premise).filter_by(
            premisegroup_uid=db_argument.premisegroup_uid).all()
        premises_uids = [premise.uid for premise in db_premises]
        for uid in premises_uids:
            LOG.debug("Add premise of argument %s", db_argument.uid)
            statement = DBDiscussionSession.query(Statement).get(uid)
            ret_list.append(
                self.__get_part_dict('premise', statement.get_text(),
                                     db_argument.uid, uid))

        if db_argument.argument_uid is None:  # get conclusion of current argument
            conclusion = db_argument.get_conclusion_text()
            LOG.debug("Add statement of argument %s", db_argument.uid)
            ret_list.append(
                self.__get_part_dict('conclusion', conclusion, db_argument.uid,
                                     db_argument.conclusion_uid))
        else:  # or get the conclusions argument
            db_conclusions_argument = DBDiscussionSession.query(Argument).get(
                db_argument.argument_uid)

            while db_conclusions_argument.argument_uid is not None:  # get further conclusions arguments

                # get premise of conclusions arguments
                db_premises = DBDiscussionSession.query(Premise).filter_by(
                    premisegroup_uid=db_argument.premisegroup_uid).all()
                premises_uids = [premise.uid for premise in db_premises]
                for uid in premises_uids:
                    statement = DBDiscussionSession.query(Statement).get(uid)
                    LOG.debug("Add premise of argument %s",
                              db_conclusions_argument.uid)
                    ret_list.append(
                        self.__get_part_dict('premise', statement.get_text(),
                                             db_conclusions_argument.uid, uid))

                db_conclusions_argument = DBDiscussionSession.query(
                    Argument).get(db_conclusions_argument.argument_uid)

            # get the last conclusion of the chain
            conclusion = db_conclusions_argument.get_conclusion_text()
            LOG.debug("Add statement of argument %s",
                      db_conclusions_argument.uid)
            ret_list.append(
                self.__get_part_dict('conclusion', conclusion,
                                     db_conclusions_argument.uid,
                                     db_conclusions_argument.conclusion_uid))

        return ret_list[::-1]
예제 #2
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('  ', ' ')
예제 #3
0
def __build_val_for_jump(db_argument: Argument, tag_premise, tag_conclusion,
                         tag_end, _t) -> str:
    premises = db_argument.get_premisegroup_text()
    if premises[-1] != '.':
        premises += '.'
    conclusion = db_argument.get_conclusion_text()

    because = _t.get(_.because).lower()
    conclusion = tag_conclusion + conclusion + tag_end
    premises = tag_premise + premises + tag_end

    intro = (start_con + _t.get(_.isNotRight).lower() +
             end_tag) if not db_argument.is_supportive else ''
    ret_value = '{} {} {} {}'.format(conclusion, intro, because, premises)
    if _t.get_lang() == 'de':
        intro = _t.get(
            _.itIsTrueThatAnonymous) if db_argument.is_supportive else _t.get(
                _.itIsFalseThatAnonymous)
        intro = start_with_capital(intro)
        intro = (start_pro
                 if db_argument.is_supportive else start_con) + intro + end_tag
        ret_value = '{} {}, {} {}'.format(intro, conclusion, because, premises)

    return ret_value