示例#1
0
def spellcheck(target, info, score):
    list_file, index_file = info["std_file"], info["ind_file"]
    item_suggest = intelligent_suggest(list_file, index_file)
    suggestions = item_suggest.suggest(target)
    if suggestions == {}:
        return "No Suggestions"
    top_sug, min_score = min(suggestions.iteritems(), key=lambda p: p[1])
    if min_score > score:
        return "Score Failure"
    else:
        return top_sug
def run(word_targets, list_file, index_file, csv_file):
    targets = openFile(word_targets, delimiter="\t")
    out_data = []
    item_suggest = intelligent_suggest(list_file, index_file)
    for target in targets.values():
        suggestions = item_suggest.suggest(target[1])
        if suggestions == {}:
            out_data.append([target[0], target[1], None, None])
            continue
        lowest_score, top_suggestion = 1000000, ""
        for suggest, score in suggestions.iteritems():
            if score < lowest_score:
                lowest_score = score
                top_suggestion = suggest
            # out_data.append([target[0], target[1], suggest, str(score)])
        out_data.append([target[0], target[1], top_suggestion, str(lowest_score)])
    write_to_csv(csv_file, out_data)
def run(word_targets, list_file, index_file, csv_file):
    targets = openFile(word_targets, delimiter="\t")
    out_data = []
    item_suggest = intelligent_suggest(list_file, index_file)
    for target in targets.values():
        suggestions = item_suggest.suggest(target[1])
        if suggestions == {}:
            out_data.append([target[0], target[1], None, None])
            continue
        lowest_score, top_suggestion = 1000000, ""
        for suggest, score in suggestions.iteritems():
            if score < lowest_score:
                lowest_score = score
                top_suggestion = suggest
            # out_data.append([target[0], target[1], suggest, str(score)])
        out_data.append(
            [target[0], target[1], top_suggestion,
             str(lowest_score)])
    write_to_csv(csv_file, out_data)
#!/usr/bin/env python

# Original Method: James Robertson as test.php
# Python Version: Remi Marchand - June 20, 2016
# Description: Simple test for the spellchecker

import sys
sys.path.append("..")

from intelligent_suggest import intelligent_suggest

word_size = 3
word_targets = "incorrect_coworkers.txt"
word_list_file = "coworkers.txt"
word_index_file = "coworkers_index_php.txt"
item_suggest = intelligent_suggest(word_list_file, word_index_file)


def openFile(filename):
    match_dict = {}
    with open(filename, "rU") as open_file:
        for i, line in enumerate(open_file):
            match_dict[i] = line.strip("\n")
    return match_dict

targets = openFile(word_targets)
for target in targets.values():
    suggestions = item_suggest.suggest(target)
    for suggest, score in suggestions.iteritems():
        if score > 34:
            continue