Exemple #1
0
    def add_how(self, text, premise):
        """
        adds a source to an premise of this argument

        premise will be created or modified

        source may be a string or list of strings
        """

        txt = self._validate_premise(premise)
        if not txt:
            raise MissingAssertionException("tried to add statement to non "
                                            "existing Premise")

        if not isinstance(text, list):
            text = [text]
        for s in text:
            if not isinstance(s, str):
                raise UnrecognizedSourceFormat
            self._premises[txt].add_how_statement(s)
Exemple #2
0
    def add_premise(self, premise):
        """ add an premise to this argument

        premise should be an Premise object

        if premise is a string, an premise will be created from it

        if premise is a dictionary, an premise will be created from data

        if premise is a list, an premise will be created with list as statements

        """

        if isinstance(premise, dict):
            premise = Premise("dummy").from_json(premise)
            if premise.description == "dummy":
                raise BadAssertionJson("no premise text given")
        elif isinstance(premise, str):
            premise = Premise(premise)
        elif isinstance(premise, list):
            if len(premise):
                for s in premise:
                    if not isinstance(s, str) and not isinstance(s, Statement):
                        raise UnrecognizedStatementFormat(
                            "Tried to create "
                            "an premise from invalid statements list")
                text = premise[0]
                statements = premise[1:]
                premise = Premise(text, statements)
            else:
                raise MissingStatementException("Empty Statements list "
                                                "provided")
        if not isinstance(premise, Premise):
            raise MissingAssertionException("Tried to add a non Premise "
                                            "object")

        if premise.description.text not in self._premises:
            self._premises[premise.description.text] = premise
        else:
            self._premises[premise.description.text].update(premise)
        return self._premises[premise.description.text]
Exemple #3
0
    def add_statement(self, statement, premise):
        """
        adds a statement to an premise of this argument

        premise will be created or modified

        statement may be a string, Statement, list of strings or list of Statements
        """

        txt = self._validate_premise(premise)
        if not txt:
            raise MissingAssertionException("tried to add statement to non "
                                            "existing Premise")

        if not isinstance(statement, list):
            statement = [statement]
        for s in statement:
            if not isinstance(s, Statement) and not isinstance(s, str):
                raise UnrecognizedStatementFormat("Tried to create a "
                                                  "statement from bad input "
                                                  "type: " + str(type(s)))
            self._premises[txt].add_statement(s)