本文整理汇总了Python中Preprocess.checkInput方法的典型用法代码示例。如果您正苦于以下问题:Python Preprocess.checkInput方法的具体用法?Python Preprocess.checkInput怎么用?Python Preprocess.checkInput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Preprocess
的用法示例。
在下文中一共展示了Preprocess.checkInput方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import Preprocess [as 别名]
# 或者: from Preprocess import checkInput [as 别名]
def main():
#define new objects
preprocess = Preprocess()
process = Process()
points = Points()
postprocess = Postprocess()
#declare and initialize variables
search_string = ''
option = 0
count2 = 0 #delete this
reordered_search_string = ''
permutation_set = set()
temp_permutation_set = set()
permutation_list = [] #2D list
blank_permutation_list = []
filtered_content = []
sorted_results = []
final_results = []
sorted_final_results = []
#menu options
print "\nSearch options:\n"
print "1. Search for words"
print "2. Search for words starting with"
print "3. Search for words ending with"
print "4. Search for words containing"
print "5. Search with blank tiles (use the underscore character to represent blanks)\n"
#option = int(raw_input("Choose option:"))
option = 1
#search_string = raw_input('Please input tiles for search: ').lower()
search_string = "andrew"
#basic input check
if (preprocess.checkInput(search_string)):
reordered_search_string = preprocess.reorderString(search_string) #alphabetize tiles
else:
sys.exit()
t1 = time.time() #diagnostics
#Input(search_string, option) #turned into function for testing purposes
if (option == 0): #no option chosen
print "ERROR: No option chosen, exiting."
sys.exit()
elif(option == 1):
print "Searching for words...\n"
permutation_list = process.stringPermutations(reordered_search_string)
filtered_content = process.collectDictionarySegments(reordered_search_string)
sorted_results = process.findWords(permutation_list, filtered_content)
final_results = points.associatePointScore(sorted_results)
elif(option == 2):
print "Searching for words starting with: ", search_string, "\n"
filtered_content = process.collectDictionarySegments(search_string[0]) #get first letter int he word being searched
sorted_results = process.findWordsContaining(search_string, filtered_content, option)
final_results = points.associatePointScore(sorted_results)
elif(option == 3):
print "Searching for words ending in: ", search_string, "\n"
alphabet = 'abcdefghijklmnopqrstuvwxyz'
filtered_content = process.collectDictionarySegments(alphabet)
sorted_results = process.findWordsContaining(search_string, filtered_content, option)
final_results = points.associatePointScore(sorted_results)
elif(option == 4):
print "Searching for words containing: ", search_string, "\n"
alphabet = 'abcdefghijklmnopqrstuvwxyz'
filtered_content = process.collectDictionarySegments(alphabet)
sorted_results = process.findWordsContaining(search_string, filtered_content, option)
final_results = points.associatePointScore(sorted_results)
elif(option == 5):
print "Searching with blank tiles...\n"
alphabet = 'abcdefghijklmnopqrstuvwxyz'
blank_permutation_list = process.blankTileProcessing(reordered_search_string)
filtered_content = process.collectDictionarySegments(alphabet)
#TO DO: Creates a 2D list, gotta convert to 1D list - DONE
#TO DO: find way to use union keyword to take out duplicates, it will take care of one nested for loop in findWords function - DONE
#TO DO: Do another union - DONE
# time vs duplication trade off. Takes longer to take out the duplicates with the union
for blank_permutation_string in blank_permutation_list:
#permutation_list.extend(process.stringPermutations(blank_permutation_string))
temp_permutation_set = set(process.stringPermutations(blank_permutation_string))
permutation_set = permutation_set.union(temp_permutation_set)
permutation_list = list(permutation_set)
sorted_results = process.findWords(permutation_list, filtered_content)
final_results = points.associatePointScore(sorted_results)
else:
print "ERROR: Please choose an option between 1-5"
sys.exit()
t2 = time.time() - t1 #diagnostics
sorted_option = 0
print "Results found and processed. Sort results by...\n"
print "1. Points - lowest to highest"
print "2. Points - highest to lowest"
print "3. Length - longest to shortest"
print "4. Length - shortest to longest"
sorted_option = int(raw_input("choose option: "))
print "Option", sorted_option, "chosen"
#.........这里部分代码省略.........