示例#1
0
def check_words(combinations):
    """Go through all the combinations of words and find their definitions using
    food_words and the dictionary."""
    translations = []
    for c in combinations:
        translation = []
        found_def = True
        for char in c:
            food_word = Food_Word.find_match(char)
            if food_word:
                translation.append(food_word.get_json())
            else:
                entries = Dict_Entry.find_matches(char)
                if entries != []:
                    for entry in entries:
                        translation.append(entry.get_json())
                elif len(char) == 1:
                    # If the character isn't in the dictionary (usually punctuation)
                    d = {
                        "char": char,
                        "pinyin": "",
                        "english": "" 
                    }
                    translation.append(d)
                else:
                    found_def = False
                    break
        if found_def:
            return translation
示例#2
0
def check_words(combinations):
    """Go through all the combinations of words and find their definitions using
    food_words and the dictionary."""
    translations = []
    for c in combinations:
        translation = []
        found_def = True
        for char in c:
            food_word = Food_Word.find_match(char)
            if food_word:
                translation.append(food_word.get_json())
            else:
                entries = Dict_Entry.find_matches(char)
                if entries != []:
                    for entry in entries:
                        translation.append(entry.get_json())
                elif len(char) == 1:
                    # If the character isn't in the dictionary (usually punctuation)
                    d = {"char": char, "pinyin": "", "english": ""}
                    translation.append(d)
                else:
                    found_def = False
                    break
        if found_def:
            return translation
示例#3
0
def generate_food_chains():
    words = []
    food_words = Food_Word.get_all_words()
    dishes = Dish.get_all_dishes()
    words.extend(food_words)
    words.extend(dishes)

    # Generate Markov chains. 
    # Since dish names are short, I'm using an n-gram size of 1.
    for i in range(len(words)):
        word = words[i]
        for j in range(len(word) - 1):
            char = word[j]
            next = word[j + 1]
            if CHAINS.get(char):
                CHAINS[char].append(next)
            else:
                CHAINS[char] = [next]
示例#4
0
def generate_food_chains():
    words = []
    food_words = Food_Word.get_all_words()
    dishes = Dish.get_all_dishes()
    words.extend(food_words)
    words.extend(dishes)

    # Generate Markov chains.
    # Since dish names are short, I'm using an n-gram size of 1.
    for i in range(len(words)):
        word = words[i]
        for j in range(len(word) - 1):
            char = word[j]
            next = word[j + 1]
            if CHAINS.get(char):
                CHAINS[char].append(next)
            else:
                CHAINS[char] = [next]