Beispiel #1
0
 def switch(self):               
     if(utils.has_attribute(self._config, "switchable")):                        
         if("event" not in self._config):
              utils.print_message("Config Error: switch '{}' has no event in config.".format(
                 colour.red(location_name)
             ))
         event = self._config["event"]
         if(self.game.locations.is_valid_location_name(event[0])):
             location = self.game.locations.get_location(event[0])
             location.handle_event(event)
         if("switched" in self._config):
             utils.print_messages(self._config["switched"])
         else:
             utils.print_message("Config Error: switch '{}' has bad event location in config.".format(
                 colour.red(location_name)
             ))                
     else:
         utils.print_message("You cannot switch this item.")
    def open(self, context):
        if (utils.has_attribute(self._config, "openable")):
            if (utils.has_attribute(self._config, "locked")):
                utils.print_message("Item '{}' is locked.".format(
                    colour.red(self.name)))
                return
            if ("inside" in self._config):
                items = self._config.pop("inside", None)
                self._config["revealed"] = items
                item_name = sorted(items)[
                    0]  # only allow 1 item - inside stuff
                self.add_inventory_items(items)
                if (len(items) > 0):
                    #if(utils.has_attribute(self._config, "door")):
                    if ("opened" in self._config):
                        utils.print_messages(self._config["opened"])
                    ## remove doors after open
                    if (utils.has_attribute(self._config, "door")):
                        context.remove_inventory_item(self.name)

                    if (utils.has_attribute(self._config, "door")):
                        utils.print_message(
                            "You see the '{}' through the '{}'".format(
                                colour.green(item_name),
                                colour.green(self.name)))
                    else:
                        utils.print_message(
                            "You see the '{}' in the '{}'".format(
                                colour.green(item_name),
                                colour.green(self.name)))
                if (self.has_inventory()):
                    context.add_inventory_items(self.get_inventory_items())
        else:
            if ("taken" in self._config and "inside" in self._config["taken"]):
                utils.print_message("{}".format(
                    colour.red(
                        "You cannot open this item until it has been taken.")))
                utils.print_message("Hint: {}".format(
                    colour.green(
                        "Taking items show more details - You may see more detail when examined, and be able to open it!"
                    )))
            return
            utils.print_message("{}".format(
                colour.red("You cannot open this item.")))
 def move(self, context):
     if (utils.has_attribute(self._config, "moveable")):
         if ("inside" in self._config):
             items = self._config.pop("inside", None)
             self._config["revealed"] = items
             item_name = sorted(items)[
                 0]  # only allow 1 item - inside stuff
             self.add_inventory_items(items)
             if (len(items) > 0):
                 if ("moved" in self._config):
                     utils.print_messages(self._config["moved"])
                 utils.print_message(
                     "You see a '{}' after moving the '{}'".format(
                         colour.green(item_name), colour.green(self.name)))
             if (self.has_inventory()):
                 context.add_inventory_items(self.get_inventory_items())
         else:
             utils.print_message("You moved the '{}'".format(
                 colour.green(self.name)))
     else:
         utils.print_message("{}".format(
             colour.red("You cannot move this item.")))
 def _handle_quitting(self):
     if (self._quit):
         utils.print_messages(self._config["quitting-messages"])
 def _handle_completed(self):
     if (self.player.get_location_name() ==
             self._config["completed-location"]):
         self._completed = True
         utils.print_messages(self._config["completed-messages"])
Beispiel #6
0
#!/usr/bin/env python

import pandas as pd
import joblib

import model_parts
import utils

if __name__ == "__main__":
    output_twitter_df = pd.read_csv("data/trump_twitter_201601_201908.csv")
    print(f"Loaded {len(output_twitter_df)} rows")
    clf = joblib.load("models/trump_classifier.pkl")

    output_twitter_df = model_parts.preprocessing(output_twitter_df)
    is_trump = clf.predict(output_twitter_df)
    print(
        f"Predicted labels: not_trump:trump {sum(~is_trump)}:{sum(is_trump)}")

    print("\n# NOT_TRUMP Predictions\n")
    n = 5
    utils.print_messages(output_twitter_df[~is_trump].sample(n)["text"])
    print("\n# TRUMP Predictions\n")
    utils.print_messages(output_twitter_df[is_trump].sample(n)["text"])

    output_twitter_df[["text"
                       ]].to_csv("output/real_trump_twitter_201601_201908.csv",
                                 index=False)