<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def check_negated_goals(self,safe_variables,query):
        ''' Create a list of variables which occur in negated goals. '''
        variables_in_negated_goals = \
            [y for x in query.relations for y in list(x.variables) if x.is_negated()]

        # And check them:
        for variable in variables_in_negated_goals:
            if not (variable in safe_variables):
                raise NotSafeException('Query not safe because ' + \
                    variable.name + \
                    ' from a negated goal does not occur in a positive goal')
                return False

        return True