Ejemplo n.º 1
0
def init_db(chunk=50000, reset=False, include_plural=True):
    logging.info("start insert...")

    if reset:
        db.drop_tables([EngWords])

    db.create_tables([EngWords, ], safe=True)

    all_words = []
    words_freq = words.load_words_frequencies()

    for word in words.load_words():
        similar_words = [word]
        freq = words_freq.get(word, 0)

        if include_plural:
            similar_words.append(inf_engine.plural(word))

        for w in list(set(similar_words)):
            all_words.append({'word': w, 'frequency': freq})

    if not reset and len(all_words) == EngWords.select().count():
        logging.info("Already up to date")
        return

    with db.atomic():
        for idx in range(0, len(all_words), chunk):
            words_chunk = all_words[idx:idx + chunk]
            EngWords.insert_many(words_chunk).execute()

    logging.info("Done.")
Ejemplo n.º 2
0
 def run():
     word_list = words.load_words(*self.paths)
     word_list.set_def(self.definition)
     word_list.set_idx(self.index)
     if self.shuffle:
         word_list.shuffle()
     if self.redundancy:
         word_list.solve_redundancy()
     jobs = [gevent.spawn(word.get_definition) for word in word_list]
     gevent.joinall(jobs)
     output_dir = [os.path.dirname(os.path.abspath(path)) for path in self.paths][0]
     output = os.path.join(output_dir, "output.txt")
     with open(output, mode="wt") as f:
         f.write(repr(word_list))
         f.flush()
Ejemplo n.º 3
0
#! /usr/bin/env python
"""
@author: dell
"""

import users
users.load_users('data/users.pkl')

import words
words.load_words('data/words.pkl')

from collections import defaultdict

def indicator(cat_id, dim):
    v = [0] * dim
    if cat_id >= 0:
        v[cat_id] = 1
    return v

def binary(w):
    if w == -1:
        return 0
    if w == 0:
        return -1
    if w == 1:
        return 1

def represent(example):
    vector = []
    artist_id = example['artist']
    track_id  = example['track']
Ejemplo n.º 4
0
Archivo: test.py Proyecto: DataDog/dpn
 def test_load_words_exception(self):
     with self.assertRaises(words.WordsException):
         test_words = words.load_words("I_d0_NOT_ex157.fudge")
Ejemplo n.º 5
0
Archivo: test.py Proyecto: DataDog/dpn
 def test_load_words(self):
     test_words = words.load_words("testwords.json")
     self.assertEqual(10, len(test_words))
Ejemplo n.º 6
0
'''
Created on Nov 9, 2014

@author: Jinali Jhaveri
'''

import users
users.load_users('data_pkl/users.pkl')

import words
words.load_words('data_pkl/words.pkl')

from collections import defaultdict

def indicator(cat_id, dim):
    v = [0] * dim
    if cat_id >= 0:
        v[cat_id] = 1
    return v

def binary(w):
    if w == -1:
        return 0
    if w == 0:
        return -1
    if w == 1:
        return 1

def represent(example):
    vector = []
    artist_id = example['artist']
Ejemplo n.º 7
0
from flask import Flask, render_template, jsonify
from words import load_words, Word, Node, Tree
import collections
app = Flask(__name__)

TERMS, DEFS = "terms", "definitions"
AVAILABLE_COMMANDS = {'Terms': TERMS, 'Definitions': DEFS}
WORD_LIST = load_words()


def search_terms(word_list, search):
    new_word_list = []

    for word in word_list:
        if search.lower() in word.term.lower():
            entry = {}
            entry['term'] = word.term
            entry['definition'] = word.definition
            entry['greek_latin'] = word.greek_latin
            entry['pos'] = word.pos
            new_word_list.append(entry)

    return sorted(new_word_list, key=lambda w: w['term'])


def search_defs(word_list, search):
    new_word_list = []

    for word in word_list:
        if search.lower() in word.definition.lower():
            entry = {}
Ejemplo n.º 8
0
from words import load_words

SCENE_START = 'SCENE_START'
SCENE_GAME = 'SCENE_GAME'

WORD_COUNT = 10

ALL_WORDS = load_words('words.txt')
Ejemplo n.º 9
0
            hint = False
            print(display_hint(letters_guessed))
        elif (len(guess) > 1 or ord(letter) < ord('a')
              or ord(letter) > ord('z')):
            print(letter)
            remaining_lives -= 1
        else:
            if letter in secret_word:
                letters_guessed.append(letter)
                print("Good guess: {} ".format(
                    get_guessed_word(secret_word, letters_guessed)))
                if is_word_guessed(secret_word, letters_guessed) == True:
                    print(" * * Congratulations, you won! * * ", end='\n\n')
                    return

            else:
                print("Oops! That letter is not in my word: {} ".format(
                    get_guessed_word(secret_word, letters_guessed)))
                letters_guessed.append(letter)
                remaining_lives -= 1
                print(IMAGES[7 - remaining_lives])


# Load the list of words into the variable wordlist
# So that it can be accessed from anywhere in the program
word_list = load_words()
secret_word = choose_word()
#secret_word='distort'
hangman(secret_word)
#print(secret_word)