Exemple #1
0
class Dappy():
    canvas = None
    filename = None
    path = None
    FileHandler = None

    def __init__(self, path, image_filename=None):

        # Initialize canvas
        self.canvas = Canvas()
        self.FileHandler = FileIO()
        # Load image information
        if image_filename != None:
            info = self.FileHandler.read(os.path.abspath(image_filename))
            self.set_current_info(info)
        else:
            self.filename = None
            self.path = path
        self.canvas.clear_overlay()
        self.canvas.print_tool()

    def set_current_info(self, image_info):
        if image_info == None:
            return
        canonical_filename = image_info[0]
        self.canvas.set_image(image_info[1])
        self.fix_image_info(canonical_filename)

    def fix_image_info(self, canonical_filename):
        if canonical_filename == None:
            return

        self.filename = os.path.basename(canonical_filename)
        self.path = os.path.dirname(canonical_filename)
def main(file_name):
    file_io = FileIO(file_name)
    corpus = file_io.read()
    tc = TextCleanser()

    corpus_words = tc.clean_text(corpus)  # Get a list of every words in corpus
    text_gen = TextGenerator(corpus_words)

    ui = UserInterface(text_gen)
    ui.runProgram()  # Starts the program
Exemple #3
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--sentences', help='path to sentences file', type=str)

    args = parser.parse_args()
    sentences_file = args.sentences

    try:
        db = Db(FileIO.read(sentences_file))
    except Exception:
        Display.error('Error occurred while processing sentences file.')
        sys.exit()

    wa = WordAssociation(FileIO.read_optional(WORD_ASSOCIATION_DEFAULT_FILE))

    error_lines = db.get_error_lines()
    if len(error_lines) > 0:
        Display.error(
            'Keyword was not properly marked in the following line(s):')
        for line in error_lines:
            Display.display(line)
        sys.exit()

    twc = db.get_total_word_count()
    kwc = db.get_known_word_count()

    Display.display_header(twc, kwc)

    try:
        error = False
        next_word = True

        k, v = None, None
        prompt = InputMapper.get_main_prompt()

        while True:
            if not error and next_word:
                k, v = db.get_next_key_value()

            disp = k
            associations = wa.get_associations_for_word(Db.strip_key(k))
            if len(associations) > 0:
                disp = Db.mark_key(k, EmojiMapper.get(EmojiTypes.EYES))

            Display.display(disp, True)

            error = False
            next_word = False

            inp = raw_input(prompt).lower()
            commands = InputMapper.get_commands(inp)
            word = Db.strip_key(k)

            for command in commands:
                if command == Command.KNOW_IT:
                    db.mark(k, EmojiMapper.get(EmojiTypes.THUMBS_UP))
                    next_word = True
                elif command == Command.SKIP:
                    db.unmark(k)
                    next_word = True
                elif command == Command.OPEN_DICTIONARY:
                    Display.info('Opening dictionary for ' +
                                 Display.bold_replace(word))
                    os.system('open dict://{}'.format(word))
                elif command == Command.SHOW_CONTEXT:
                    Display.display(v)
                elif command == Command.DISPLAY_ALL_WORDS:
                    Display.display_all_words(db.get_data(),
                                              db.get_total_word_count(),
                                              db.get_known_word_count())
                elif command == Command.ASSOCIATE:
                    word_prompt = Display.get_association_prompt(word)
                    associations = raw_input(word_prompt).split()
                    associations = [w.lower() for w in associations]
                    associations.append(word)
                    wa.associate(associations)
                elif command == Command.DISPLAY_ASSOCIATED_WORDS:
                    Display.display_associated_words(associations)
                elif command == Command.DISPLAY_ALL_ASSOCIATIONS:
                    Display.display_all_associations(wa.get_all_associations(),
                                                     wa.get_num_associations())
                elif command == Command.CONFLICTING:
                    Display.error('Conflicting command')
                    error = True
                else:
                    Display.error('Unknown command')
                    error = True
            Display.new_line()

    except KeyboardInterrupt:
        pass
    finally:
        FileIO.write_db(sentences_file, db.get_data())
        FileIO.write_associations(WORD_ASSOCIATION_DEFAULT_FILE,
                                  wa.get_all_associations())