Beispiel #1
0
def clean():
    logger.info("Cleaning...")

    # Escalate permissions to root (sudo) if not ran as root
    # This is required for creating the chroot jails and running the solutions.
    escalate_permissions()

    # Clean and delete the sandbox directories for each of the workers
    Workers.clean()
Beispiel #2
0
 def __init__(self, input_data):
     self.input = input_data
     self.Worker = Workers()
     encoders = [
         load('processing/binaries/part_of_speech_encoder.joblib'),
         load('processing/binaries/gender_encoder.joblib'),
         load('processing/binaries/quantity_encoder.joblib'),
         load('processing/binaries/case_encoder.joblib')
     ]
     self.encoders = encoders
Beispiel #3
0
class DataPreprocessor():
    def __init__(self, input_data):
        self.input = input_data
        self.Worker = Workers()
        encoders = [
            load('processing/binaries/part_of_speech_encoder.joblib'),
            load('processing/binaries/gender_encoder.joblib'),
            load('processing/binaries/quantity_encoder.joblib'),
            load('processing/binaries/case_encoder.joblib')
        ]
        self.encoders = encoders

    def _to_df(self, string):
        lasts = np.array([
            0 if word[-1] in ['.', '!', '?'] else 1 for word in string.split()
        ])
        lasts = (lasts == 0).astype('int64')
        words = pd.DataFrame(string.split(), columns=['word'])
        lasts = pd.DataFrame(lasts, columns=['last_in_sentence'])
        self.df_for_model = pd.concat([words, lasts], axis=1)
        self.words = df_words

    def _prepare_for_model(self, df):
        w2v_columns = [f'w2v_{i}' for i in range(1, 301)]

        df['first_in_sentence'] = self.Worker.is_first(df['word'].tolist())
        df['is_capital'] = df['word'].apply(self.Worker.is_capital)
        df['part_of_speech'] = df['word'].apply(self.Worker.get_pos)
        df['gender'] = df['word'].apply(self.Worker.get_gender)
        df['number'] = df['word'].apply(self.Worker.get_number)
        df['case'] = df['word'].apply(self.Worker.get_case)
        df['len'] = df['word'].apply(len)

        df['word'] = df['word'].apply(self.Worker.normalize_text)
        df = df.join(
            pd.DataFrame(df['word'].apply(self.Worker.vectorize).tolist(),
                         columns=w2v_columns))
        df = df.drop(columns=['word'])

        new_columns = ['part_of_speech', 'gender', 'number', 'case']

        for encoder, name in zip(self.encoders, new_columns):
            df[name] = encoder.transform(df[name])

        df = self.Worker.create_neighbours(df.values)

    def prepare(self):
        if string[-1] != '.':
            string = string + '.'

        self._to_df(self.input)
        self._prepare_for_model(self.df_for_model)
        return self.df_for_model, self.df_words
Beispiel #4
0
class PlayerSide:
    def __init__(self, GS):
        self.workers = Workers(GS)
        
        self.resources = {"Rock" : 50,
                          "Metal" : 75,
                          "Crystal" : 5}
    
    def tick(self):
        self.workers.tick()
    
    def blit(self, screen):
        self.workers.blit(screen)
Beispiel #5
0
def init():
    logger.info("Initializing...")

    # Escalate permissions to root (sudo) if not ran as root
    # This is required for creating the chroot jails and running the solutions.
    escalate_permissions()

    # Set the current working dir to the root of the grader
    # not matter when we run the script from
    root_dir = os.path.dirname(os.path.abspath(__file__))
    if os.getcwd() != root_dir:
        logger.info("Setting working directory to '{}'.".format(root_dir))
        os.chdir(root_dir)

    # Create the sandbox directories for each of the workers and prepare them
    # to be chrooted (mounting /bin, /dev, /lib and similar directories inside)
    Workers.init()

    logger.info("Initialization completed successfully!")
    people = People('人类', '未知', 10, '中国')

    print('以下为People类的数据')
    people.eat()
    people.sleep()
    people.work()
    print(people)

    print('---------------我是一条分隔线------------------')
    student = Student('学生', '未知', 18, '中国', '城西银泰', 1)

    print('以下为Student类的数据')
    student.work()
    print(student)

    print('---------------我是一条分隔线------------------')
    worker = Workers('工人', '男', 30, '中国', '小码王', 3)

    print('以下是Workers类的数据')
    worker.work()
    print(worker)

    print('---------------我是一条分隔线------------------')

    studentlead = StudentLead('学生干部', '女', 18, '中国', '城西银泰', 10, '学生会主席')

    print('以下是StudentLead类的数据')
    studentlead.meet()
    print(studentlead)
Beispiel #7
0
 def __init__(self, GS):
     self.workers = Workers(GS)
     
     self.resources = {"Rock" : 50,
                       "Metal" : 75,
                       "Crystal" : 5}