コード例 #1
0
 def test_get_relation_between_arguments(self):
     self.assertEqual(iv.get_relation_between_arguments(3, 20),
                      Relations.UNDERMINE)
     self.assertEqual(iv.get_relation_between_arguments(42, 43),
                      Relations.UNDERCUT)
     self.assertEqual(iv.get_relation_between_arguments(58, 51),
                      Relations.REBUT)
     self.assertEqual(iv.get_relation_between_arguments(11, 12),
                      Relations.SUPPORT)
     self.assertIsNone(iv.get_relation_between_arguments(11, 28))
コード例 #2
0
ファイル: arguments.py プロジェクト: tbsschroeder/dbas
def __process_input_premises_for_arguments_and_receive_url(
        langs: dict, arg_infos: dict, db_issue: Issue, db_user: User,
        mailer) -> Tuple[Optional[str], Optional[List[int]], str]:
    """
    Inserts given text in premisegroups as new arguments in dependence of the parameters and returns a URL

    :param langs: dict with default_locale_name and discussion_lang
    :param arg_infos: dict with arg_id, attack_type, premisegroups and the history
    :param db_issue: Issue
    :param db_user: User
    :return: URL, [Statement.uids], String
    """
    discussion_lang = langs['discussion_lang']
    arg_id: int = arg_infos['arg_id']
    attack_type: str = arg_infos['attack_type']
    premisegroups = arg_infos['premisegroups']
    history = arg_infos['history']

    LOG.debug("Count of new pgroups: %s", len(premisegroups))
    _tn = Translator(discussion_lang)

    slug = db_issue.slug
    error = ''

    # insert all premise groups into our database
    # all new arguments are collected in a list
    new_argument_uids = []
    for premisegroup in premisegroups:  # premise groups is a list of lists
        new_argument = insert_new_premises_for_argument(
            premisegroup, attack_type, arg_id, db_issue, db_user)
        if not isinstance(new_argument, Argument):  # break on error
            a = _tn.get(_.notInsertedErrorBecauseEmpty)
            b = _tn.get(_.minLength)
            c = environ.get('MIN_LENGTH_OF_STATEMENT', 10)
            d = _tn.get(_.eachStatement)
            if isinstance(new_argument, str):
                error = new_argument
            else:
                error = '{} ({}: {} {})'.format(a, b, c, d)
            return None, None, error

        new_argument_uids.append(new_argument.uid)

    statement_uids = []
    # @OPTIMIZE
    # Query all recently stored premises (internally: statements) and collect their ids
    # This is a bad workaround, let's just think about it in future.
    for uid in new_argument_uids:
        current_pgroup = DBDiscussionSession.query(Argument).get(
            uid).premisegroup_uid
        current_premises = DBDiscussionSession.query(Premise).filter_by(
            premisegroup_uid=current_pgroup).all()
        for premise in current_premises:
            statement_uids.append(premise.statement_uid)

    # #arguments=0: empty input
    # #arguments=1: deliver new url
    # #arguments>1: deliver url where the nickname has to choose between her inputs
    _um = url = UrlManager(slug, history)
    if len(new_argument_uids) == 0:
        a = _tn.get(_.notInsertedErrorBecauseEmpty)
        b = _tn.get(_.minLength)
        c = environ.get('MIN_LENGTH_OF_STATEMENT', 10)
        error = '{} ({}: {})'.format(a, b, c)

    elif len(new_argument_uids) == 1:
        url = _um.get_url_for_new_argument(new_argument_uids)

    else:
        url = __receive_url_for_processing_input_of_multiple_premises_for_arguments(
            new_argument_uids, _um)

    # send notifications and mails
    if len(new_argument_uids) > 0:
        # add marked arguments
        DBDiscussionSession.add_all([
            MarkedArgument(argument=uid, user=db_user.uid)
            for uid in new_argument_uids
        ])
        DBDiscussionSession.flush()
        transaction.commit()

        new_uid = random.choice(new_argument_uids)  # TODO eliminate random
        attack = get_relation_between_arguments(arg_id, new_uid)

        tmp_url = _um.get_url_for_reaction_on_argument(arg_id, attack, new_uid)

        nh.send_add_argument_notification(tmp_url, arg_id, db_user.nickname,
                                          mailer)

    return url, statement_uids, error