def breakinWords(word = "slumdog"):
	'''breaks/decomposes a word in meaningful constituent words which can be performed'''
	global debugging;
	debugger('''trying to break down the words''');
	split_word_list = []
	
	#Deepak - single words ki bhi ahmiyat hoti hai

	i = 0	# i - traverses from begining to end
	k = 0	# k - used to extract all characters k characters from ith position ahead
	j = len(word) # j - used for termination condition


	while (i<=j):
		k = i+1
		while (k<=j):
			word_part = word[i:k]
			if debugging: print word_part," ==> ",len(nltk.corpus.wordnet.synsets(word_part))
			if (len(nltk.corpus.wordnet.synsets(word_part)) > 0):
				split_word_list.append(word_part)
			k = k+1
			
		i = i+1

	i=0
	total = len(split_word_list) #total number of words

	while (i<total):
		split_word_list[i] = [split_word_list[i],len(split_word_list[i])]
		if debugging: print split_word_list[i]
		i = i + 1
	
	#word conjoiner and finder of the original word 
	#which two words actually makeup the original word ?
	new_split_word_list = [];
		
	for w in split_word_list:
		i = split_word_list.index(w)+1;
		while (i < total):
			if debugging: print w[0] + split_word_list[i][0]; #take the constituent words from the returned synsets
			if w[0] + split_word_list[i][0] == word:
				new_split_word_list = [w,split_word_list[i]];
			i = i + 1;
		#while loop ends
	#for loop ends
	
	#if new_split_word_list == None:
	#	for w in split_word_list:
	#		i = split_word_list.index(w)+1;
	#		j = i + 1;
	#		while (j < total):
	#			if w + split_word_list[i] + split_word_list[j] == word:
	#					new_split_word_list = [w,split_word_list[i],split_word_list[j]];
	
	print("the split word list is --> %s " % str(new_split_word_list));
	
	return new_split_word_list; 
def checkWord(w):
	'''check whether we know this word already and if yes, how do we perform it ?'''
	'''will return the total plan for the word'''
	debugger('''checking for the word in Knowledge Base''');
	
	action_plan = queryKB("select word from words where word like '%s'" % (w))
	if action_plan:
		return action_plan;
	else:
		return None;
def determineActionSeq(passedWord):
	'''checks whether the action sequence for a particular word exists in the KB and if yes which one is the best'''
	debugger("Trying to determine an action sequence for %s " (passedWord))
	#import accessDb
	#openConnection
	strTags = executeQuery("Select tags from words where word like passedWord")
	lstTags = strTags.split(',')
	for i in range(len(lstTags)):
		query="Select action_sequence from action_sequence where tags like 'lstTags[i]'" 
		strActionSeq = executeQuery(query)
		if( strActionSeq != ""):
			return None;
		else:
			return strActionSeq
def determineOrder(word_list):
	'''determines the order in which the words in a movie title are to be performed'''
	'''	we assign weights to words so that we know how 'easy' or 'difficult' they are to perform.
		the heavier a word, the easier it is to perform.
		-1 means very difficult.
	'''
	
	debugger('Determining order of performance of the words')
	#IDEA --> this needs to be converted into a try-catch-except chain
	for w in word_list:
		#first check whether the word exists in the KB
		complete_plan = checkWord(w);
		if complete_plan == None: #this is a NEW word!
			debugger('''%s is a NEW word''' % (w))
			#okay, whether we can determine an action sequence for this word using NLP ?
			action_sequence = determineActionSeq(w);
			if action_sequence == None: #we can't determine an action sequence for this word using NLP
				#the word doesn't have an action sequence directly...maybe we need a better idea -- break into two words and perform
				action_sequence = breakinWordsandDetermine(w);
				if action_sequence == None:#we can't determine an action sequence even after breaking it
					print ("I give up! I can't enact %s :(" % w)
					#we can't act, so lets try to get Pictures to display and make the user guess
					image_sequence = determineImages(w) 
					if image_sequence == None:
						print ("Can't show any photo for this word");
						word_info = getWordInfo();
						if word_info == None:
							print ("Can't DO ANYTHING FOR THIS word!");
							debugger("How the hell do I perform %s ?" % w); 
							points = -1; 
						else:#we found word info for this word
							debugger("Using word info...");
							complete_plan = word_info;
							points = 2;
					else:#we found images for this word
						debugger("Using images...");
						complete_plan = image_sequence;
						points = 3;
				else:#we determined action sequence by breaking into constituent words.
					debugger("Using decomposed-words action-sequences...");
					complete_plan = action_sequence
					points = 4;
			else:
				#we got an action sequence directly for this word using synonyms and tags
				debugger("Using direct(synonym and tags) action sequence...");
				complete_plan = action_sequence;
				points = 5;
		else:#we KNOW this word!
			points = 6;
			return complete_plan;
def determineImages(w):
	'''determine the right images(courtesy: Google Image Search) to be displayed for the word'''
	debugger("determining the right images to be displayed for %s" % w)
	getImages(w);