Exemple #1
0
def dict_by_dict(r, dict, table):
    total_words = []
    for key, value in dict.iteritems():
        total_words += utility.get_file_words(value.split('\n'))
    dict = utility.unique(total_words)
    utility.write_dict_file(dict, table + '.dict')
    return dict
Exemple #2
0
def dict_by_dict(r, dict, table):
    total_words = []
    for key, value in dict.iteritems():
        total_words += utility.get_file_words(value.split('\n'))
    dict = utility.unique(total_words)
    utility.write_dict_file(dict, table + '.dict')
    return dict
Exemple #3
0
def game_state(id):
    game = g.db.game_info.find_one({"_id": id})
    board_info = g.db.board_info.find().sort("_id", -1).limit(1)[0]
    board = board_info["board"]
    can_open = []
    can_open.append({
        "x": 2,
        "y": 2,
        "id": game["problems_board"][2][2],
    })
    for y in range(1, BOARD_SIZE - 1):
        for x in range(1, BOARD_SIZE - 1):
            if (board[y][x] != ""):
                for d in range(-1, 2):
                    can_open.append({
                        "x": (x + d),
                        "y": (y),
                        "id": game["problems_board"][y][x + d],
                    })
                    can_open.append({
                        "x": (x),
                        "y": (y + d),
                        "id": game["problems_board"][y + d][x],
                    })
    can_open = unique(can_open, lambda a, b: int(a["id"]) - int(b["id"]),
                      lambda a, b: a["id"] == b["id"])

    result = {
        "board": board,
        "can_open": can_open,
    }
    print json.dumps(result)
    return (json.dumps(result))
Exemple #4
0
def game_state(id):
    game = g.db.game_info.find_one({"_id": id});
    board_info = g.db.board_info.find().sort("_id", -1).limit(1)[0];
    board = board_info["board"];
    can_open = [];
    can_open.append({
        "x": 2,
        "y": 2,
        "id": game["problems_board"][2][2],
    });
    for y in range(1, BOARD_SIZE - 1):
        for x in range(1, BOARD_SIZE - 1):
            if (board[y][x] != ""):
                for d in range(-1, 2):
                    can_open.append({
                        "x": (x + d),
                        "y": (y),
                        "id": game["problems_board"][y][x + d],
                    });
                    can_open.append({
                        "x": (x),
                        "y": (y + d),
                        "id": game["problems_board"][y + d][x],
                    });
    can_open = unique(can_open, 
        lambda a, b: int(a["id"]) - int(b["id"]), lambda a, b: a["id"] == b["id"]);

    result = {
        "board": board,
        "can_open": can_open,
    };
    print json.dumps(result)
    return (json.dumps(result));
Exemple #5
0
def dict_by_file(r, table, parse_method=None):
    file_path_list, file_name_list = utility.get_file_list(r)
    total_words = []
    for file_path in file_path_list:
        if file_path.startswith('all'):
            total_words += open(file_path, 'r').readlines()
    dict = utility.unique(total_words)
    utility.write_dict_file(dict, r.split('/')[-1] + '.dict')
    return dict
Exemple #6
0
def dict_by_text(r, table, parse_method=None):
    file_path_list, file_name_list = utility.get_file_list(r)
    total_words = []
    for file_path in file_path_list:
        lines = parse_method(file_path)
        total_words += utility.get_file_words(lines)
    dict = utility.unique(total_words)
    utility.write_dict_file(dict, table + '.dict')
    return dict
Exemple #7
0
def dict_by_file(r, table, parse_method = None):
    file_path_list, file_name_list = utility.get_file_list(r)
    total_words = []
    for file_path in file_path_list:
        if file_path.startswith('all'):
            total_words += open(file_path, 'r').readlines()
    dict = utility.unique(total_words)
    utility.write_dict_file(dict, r.split('/')[-1] + '.dict')
    return dict
Exemple #8
0
def dict_by_text(r, table, parse_method = None):
    file_path_list, file_name_list = utility.get_file_list(r)
    total_words = []
    for file_path in file_path_list:
        lines = parse_method(file_path)
        total_words += utility.get_file_words(lines)
    dict = utility.unique(total_words)
    utility.write_dict_file(dict, table + '.dict')
    return dict