Example #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
Example #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