running = True;
print("Welcome to the Articano Adaptable Dictionary");
while(running):
    dictfile = open("Dict.txt","r");
    entries = dictfile.read().split("|");
    entered = raw_input("Please enter the word you are looking for. \n");
    x = 0;
    heldstring = "";
    wordandattributes = [];
    inputstring = "";
    synonyms = [];
    found = False;
    index =0;
    #HERE IS THE MAIN SEARCH, THIS WILL CREATE THE "wordandattributes" LIST. PLEASE NOTE THAT ADJECTIVES WILL HAVE ANOTHER SPACE FOR THEIR ADVERB FORM IF AVAILABLE
    #REFLEXIVE VERBS WILL ALSO HAVE THEIR OWN CATEGORY AND WILL NOT BE LUMPED IN WITH NORMAL VERBS!
    while(x<len(entries)):
        heldstring = entries[x];
        wordandattributes = heldstring.split("/");
        if(entered==wordandattributes[0]):
            print("Your word \"{}\" translates to \"{}\". \nIt is a {} and is synonymous with {}.".format(wordandattributes[0],wordandattributes[1],wordandattributes[2],wordandattributes[3]));
            synonyms = wordandattributes[3].split(",");#Splits up all the synonyms into a readable list
            found = True;
            index = x;#Keeps the index of the word in case you wish to edit the entry.
            break;
        x+=1;
    conj = "";
    x = 0;
    existingword = ""; #This is used in the "enter a translation" search
    already = True; #This is used in the "enter a translation" search
    success = False; #This is used in the Synonyms search
    numbsyn = 0; #This is used to figure out whether a comma is necessary in the synonym search
    synfound = False;#This is used in the Synonyms search to suggest other Synonyms
    if(found):
        if(wordandattributes[2]=="Verb"):
            conj = raw_input("Do you wish to have this verb conjugated?(Yes/No)\n");
            if(conj!="No" and conj!="Yes"):
                while (conj!="No" and conj!="Yes"):
                    conj = raw_input("Do you wish to have this verb conjugated?(Yes/No)\n");
            if(conj == "Yes"):#When conjugating it takes all of the verb form up until the "re" and then adds an ending or another word
                print("PRESENT TENSE: \nIo {}o \nTu {}as \nElo/Ela {}a \nNio {}edo \nVio {}esos \nEles {}an".format(wordandattributes[1][0:len(wordandattributes[1])-2],wordandattributes[1][0:len(wordandattributes[1])-2],wordandattributes[1][0:len(wordandattributes[1])-2],wordandattributes[1][0:len(wordandattributes[1])-2],wordandattributes[1][0:len(wordandattributes[1])-2],wordandattributes[1][0:len(wordandattributes[1])-2]));
                print("PAST TENSE: \nIo {}to \nTu {}tas \nElo/Ela {}ta \nNio {}tedo \nVio {}tesos \nEles {}tan".format(wordandattributes[1][0:len(wordandattributes[1])-2],wordandattributes[1][0:len(wordandattributes[1])-2],wordandattributes[1][0:len(wordandattributes[1])-2],wordandattributes[1][0:len(wordandattributes[1])-2],wordandattributes[1][0:len(wordandattributes[1])-2],wordandattributes[1][0:len(wordandattributes[1])-2]));
                print("IMPERFECT: \nIo ojo {} \nTu ojas {} \nElo/Ela oja {} \nNio ojedo {}es \nVio ojesos {}es \nEles ojan {}es".format(wordandattributes[1][0:len(wordandattributes[1])-2],wordandattributes[1][0:len(wordandattributes[1])-2],wordandattributes[1][0:len(wordandattributes[1])-2],wordandattributes[1][0:len(wordandattributes[1])-2],wordandattributes[1][0:len(wordandattributes[1])-2],wordandattributes[1][0:len(wordandattributes[1])-2]));
                print("CONDITIONAL: \nIo sejo {} \nTu sejas {} \nElo/Ela seja {} \nNio sejedo {}es \nVio sejesos {}es \nEles sejan {}es".format(wordandattributes[1][0:len(wordandattributes[1])-2],wordandattributes[1][0:len(wordandattributes[1])-2],wordandattributes[1][0:len(wordandattributes[1])-2],wordandattributes[1][0:len(wordandattributes[1])-2],wordandattributes[1][0:len(wordandattributes[1])-2],wordandattributes[1][0:len(wordandattributes[1])-2]));
                print("FUTURE: \nIo jo {} \nTu jas {} \nElo/Ela ja {} \nNio jedo {}es \nVio jesos {}es \nEles jan {}es".format(wordandattributes[1][0:len(wordandattributes[1])-2],wordandattributes[1][0:len(wordandattributes[1])-2],wordandattributes[1][0:len(wordandattributes[1])-2],wordandattributes[1][0:len(wordandattributes[1])-2],wordandattributes[1][0:len(wordandattributes[1])-2],wordandattributes[1][0:len(wordandattributes[1])-2]));
        elif(wordandattributes[2]=="Reflexive Verb"):
            conj = raw_input("Do you wish to have this verb conjugated?(Yes/No)\n");
            if(conj!="No" and conj!="Yes"):
                while (conj!="No" and conj!="Yes"):
                    conj = raw_input("Do you wish to have this verb conjugated?(Yes/No)\n");
            if(conj=="Yes"):
                print("PRESENT TENSE: \nIo me {}o \nTu te {}as \nElo/Ela len {}a \nNio nos {}edo \nVio vos {}esos \nEles se {}an".format(wordandattributes[1][0:len(wordandattributes[1])-4],wordandattributes[1][0:len(wordandattributes[1])-4],wordandattributes[1][0:len(wordandattributes[1])-4],wordandattributes[1][0:len(wordandattributes[1])-4],wordandattributes[1][0:len(wordandattributes[1])-4],wordandattributes[1][0:len(wordandattributes[1])-4]));
                print("PAST TENSE: \nIo me {}to \nTu te {}tas \nElo/Ela len {}ta \nNio nos {}tedo \nVio vos {}tesos \nEles se {}tan".format(wordandattributes[1][0:len(wordandattributes[1])-4],wordandattributes[1][0:len(wordandattributes[1])-4],wordandattributes[1][0:len(wordandattributes[1])-4],wordandattributes[1][0:len(wordandattributes[1])-4],wordandattributes[1][0:len(wordandattributes[1])-4],wordandattributes[1][0:len(wordandattributes[1])-4]));
                print("IMPERFECT: \nIo me ojo {} \nTu te ojas {} \nElo/Ela len oja {} \nNio nos ojedo {}es \nVio vos ojesos {}es \nEles se ojan {}es".format(wordandattributes[1][0:len(wordandattributes[1])-4],wordandattributes[1][0:len(wordandattributes[1])-4],wordandattributes[1][0:len(wordandattributes[1])-4],wordandattributes[1][0:len(wordandattributes[1])-4],wordandattributes[1][0:len(wordandattributes[1])-4],wordandattributes[1][0:len(wordandattributes[1])-4]));
                print("CONDITIONAL: \nIo me sejo {} \nTu te sejas {} \nElo/Ela len seja {} \nNio nos sejedo {}es \nVio vos sejesos {}es \nEles se sejan {}es".format(wordandattributes[1][0:len(wordandattributes[1])-4],wordandattributes[1][0:len(wordandattributes[1])-4],wordandattributes[1][0:len(wordandattributes[1])-4],wordandattributes[1][0:len(wordandattributes[1])-4],wordandattributes[1][0:len(wordandattributes[1])-4],wordandattributes[1][0:len(wordandattributes[1])-4]));
                print("FUTURE: \nIo me jo {} \nTu te jas {} \nElo/Ela len ja {} \nNio nos jedo {}es \nVio vos jesos {}es \nEles se jan {}es".format(wordandattributes[1][0:len(wordandattributes[1])-4],wordandattributes[1][0:len(wordandattributes[1])-4],wordandattributes[1][0:len(wordandattributes[1])-4],wordandattributes[1][0:len(wordandattributes[1])-4],wordandattributes[1][0:len(wordandattributes[1])-4],wordandattributes[1][0:len(wordandattributes[1])-4]));
        
    if(found == False):       #Just like in English, the conditional, imperfect, and future tenses use another word rather than a separate conjugation.
        z = raw_input("You have entered {}. Is this correct?(Yes/No)\n".format(entered));
        cont=True;
        if(z!="No" and z!="Yes"):
            while (z!="No" and z!="Yes"):
                z = raw_input("You have entered {}. Is this correct? (Yes/No)\n".format(entered));
        if(z=="No"):
            cont=False;
        else:
            inputstring += entered;
            #print(inputstring)
            while(already):
                z = raw_input("What is the desired translation of this word? \n");#We have to search everything again just to make sure that the desired translation doesn't already mean something else.
                while(x<len(entries)):
                    heldstring = entries[x];
                   # print(entries[x])
                    existingword = heldstring.split("/")[1];
                    if(existingword==z):
                       print("Sorry, that word already exists. \n");
                       x=0;
                       break;
                    x+=1;
                if(x==len(entries)):
                    already=False;
            inputstring+="/";
            inputstring+=z;
            x=0;
           # print(inputstring);
            inputstring+="/";
            z = raw_input("What type of word is this? (Verb, Reflexive Verb, Noun, Adjective, Preposition, Other [please note that Adverbs are automatically created])\n")
            if(z!="Verb" and z!="Reflexive Verb" and z!="Noun" and z!="Adjective" and z!="Preposition"and z!="Other"):
                while (z!="Verb" and z!="Reflexive Verb" and z!="Noun" and z!="Adjective" and z!="Preposition"and z!="Other"):
                    z = raw_input("What type of word is this? (Verb, Reflexive Verb, Noun, Adjective, Preposition, Other)\n");
            inputstring+=z;
            inputstring+="/";
            #Here comes the hardest part. We will search have to search for all words with shared synonyms and add them to the list. RIGHT NOW WE HAVE NOT ADDED THIS FUNCTION
            z = raw_input("Does your word have any synonyms? (Yes/No)\n");
            if(z!="No" and z!="Yes"):
                while (z!="No" and z!="Yes"):
                    z = raw_input("Does your word have any synonyms? (Yes/No)\n");
            while(z=="Yes"):
                z = raw_input("Please enter a synonym in English, and we will see if we have it. \n")
                while(x<len(entries)):
                    heldstring = entries[x];
                    existingword = heldstring.split("/")[0];
                    if(z==existingword):
                        print("We have this word! Huzzah!\n");
                        synfound = True;
                        index=x;
                        if (entries[x].split("/")[3]==""):
                            entries[x]+=inputstring.split("/")[1];
                        else:
                            entries[x]+=",";
                            entries[x]+=inputstring.split("/")[1];
                        if (numbsyn==0):
                            inputstring+=entries[x].split("/")[1];
                            print(inputstring);#I dunno, a whole bunch o' bullshit had to happen to get the synonyms to work.
                            numbsyn+=1;
                        else:
                            inputstring+=",";
                            inputstring+=entries[x].split("/")[1];
                            print(inputstring);
                    x+=1;
                if (x==len(entries)-1):
                    print("Sorry, we did not find that word.")
                if(synfound):
                    print("These are the known synonyms of the word you just added: {}".format(entries[index].split("/")[3]));
                z = raw_input("Does your word have any other synonyms? (Yes/No)\n");
                if(z!="No" and z!="Yes"):
                    while (z!="No" and z!="Yes"):
                        z = raw_input("Does your word have any other synonyms? (Yes/No)\n");
    x = 1;
    finalstring = entries[0];
    while(x<len(entries)):
        finalstring+="|";
        finalstring+=entries[x];
        x+=1;
    if (found==False and cont==True):
        finalstring+="|";
        finalstring+=inputstring;
    with open("Dict.txt", "w") as myfile:
        myfile.write(finalstring);
    z = raw_input("Anything else? (Yes/No)\n");
    if(z!="No" and z!="Yes"):
         while (z!="No" and z!="Yes"):
             z = raw_input("Anything else? (Yes/No)\n");
    if(z=="No"):
        running = False;

