'''
Name: Sebastian Lloret
Recitation TA: Brennan Mcconnell
Assignment #: 8
'''
# Used to properly break the file into rows
import csv

def CreateDictionary(fileName):
    slangDictionary = {}
    # With just ensures a resource is cleaned even if exceptions are thrown.
    # I had to use "rU" for universal newline support since textToEnglish is
    # formatted with /r and not /n
    with open(fileName, "rU") as f:
        reader = csv.reader(f)
        for row in reader:
            # Row is a n-element list where n is the number of columns in each row
            # ex. Row = [slang, translation]
            slangDictionary[row[0]] = row[1]
        return slangDictionary

if __name__ == "__main__":
    # Call the function above
    slangDictionary = CreateDictionary("textToEnglish.csv")
    playing = True
    # Grab user input(s)
    while playing == True:
        userInput = raw_input("Enter text abbreviations separated by spaces, or q to quit.\n")
        if userInput == "q":
            raise SystemExit
        # Split the userInput at every space
        arrayInputs = userInput.split()
        # For every element in the array of inputs, check if we have the translation
        for element in arrayInputs:
            if element in slangDictionary:
                print slangDictionary[element]
            else:
                print "NF"
