本文整理汇总了Python中dictionary.Dictionary.load方法的典型用法代码示例。如果您正苦于以下问题:Python Dictionary.load方法的具体用法?Python Dictionary.load怎么用?Python Dictionary.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dictionary.Dictionary
的用法示例。
在下文中一共展示了Dictionary.load方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main0
# 需要导入模块: from dictionary import Dictionary [as 别名]
# 或者: from dictionary.Dictionary import load [as 别名]
def main0(self):
#gui = ScrabbleGUI.UserInterface()
# Load the dictionary.
self.dictionary = Dictionary.load(DICTIONARY_FILENAME)
self.board = Board()
# Keep track of the winning solution at each round.
self.winners = []
# List of letters we can still pick from.
self.bag = get_full_bag()
# Rack starts out empty. Keep track of current and last rack state.
self.rack = ""
self.old_rack = ""
self.count = 0
# Keep track of current and last board state,
self.update_board = None
self.old_board = Board()
# Baxter's score
self.my_score = 0
#Create classifier
self.classify = CNN_Model()
# set Baxter's mode.
# mode = 0: skill level tapers off and stays low
# mode = 1: skill level tapers off and increases after reaching lowest point
# mode = 2: highest skill level for whole game
self.mode = 0
festival.setStretchFactor(1)
festival.sayText("Hello, it is Baxter here, I hope we do well")
示例2: PinyinLookup
# 需要导入模块: from dictionary import Dictionary [as 别名]
# 或者: from dictionary.Dictionary import load [as 别名]
class PinyinLookup() :
def __init__( self ) :
self.dict = Dictionary()
self.spliter = PinyinSpliter()
self.fitter = Fitter()
self.picker = Picker( self.dict )
#self.picker.set( [], [], True )
self.cache = [ [ 0, [], "" ] ]
self.candCacheIndex = 0
self.candStartIndex = 0
self.candList = []
def load( self, filePath ) :
newKeys = self.dict.load( filePath )
print "start build index"
newPinyinSet = set()
for key in newKeys :
if key.count( "'" ) <= 0 :
self.fitter.pinyinSet.add( key )
newPinyinSet.add( key )
self.fitter.dictTree.addKey( key )
for pinyin in newPinyinSet :
self.spliter.beginCharSet.add( pinyin[0] )
self.spliter.pinyinTree.addPath( pinyin )
print "built"
def update( self, key, word, freq ) :
newKey = self.dict.update( key, word, freq )
if newKey :
if newKey.count( "'" ) <= 0 :
self.fitter.pinyinSet.add( newKey )
self.spliter.beginCharSet.add( newKey[0] )
self.spliter.pinyinTree.addPath( newKey )
self.fitter.dictTree.addKey( newKey )
def subFit( self, fitList, pinyinStringList ) :
subFitPoint = -999
#for key in fitList :
for i in range( len( fitList ) ) :
key = fitList[i]
#currentSubFitPoint = len( key ) - key.count( "'" ) - len( self.spliter.code )
currentSubFitPoint = key.count( "'" ) + 1 - len( pinyinStringList[i].string )
#print key, pinyinStringList[i].string, currentSubFitPoint
if currentSubFitPoint > 0 :
currentSubFitPoint = -998
if currentSubFitPoint > subFitPoint :
subFitPoint = currentSubFitPoint
#print key, currentSubFitPoint, subFitPoint
newFitList = []
preeditList = []
for i in range( len( fitList ) ) :
key = fitList[i]
currentSubFitPoint = key.count( "'" ) + 1 - len( pinyinStringList[i].string )
if currentSubFitPoint >= subFitPoint :
newFitList.append( key )
preeditList.append( str( pinyinStringList[i] ) )
#print newFitList, newPreeditList
return newFitList, preeditList
def append( self, code ) :
#print "append", code
self.spliter.append( code )
fitList = []
#preeditList = []
pinyinStringList = []
fitPoint = -999
for pinyinString in self.spliter.stack :
#print pinyinString
if pinyinString.length < len( self.spliter.code ) :
pass
else :
currentFitPoint, keys = self.fitter.fit( pinyinString.string )
#print currentFitPoint, keys
if currentFitPoint > fitPoint :
fitPoint = currentFitPoint
fitList = []
preeditList = []
fitList.extend( keys )
#preeditList.extend( [ str( pinyinString ) ] * len( keys ) )
pinyinStringList.extend( [ pinyinString ] * len( keys ) )
elif currentFitPoint == fitPoint :
fitList.extend( keys )
#preeditList.extend( [ str( pinyinString ) ] * len( keys ) )
pinyinStringList.extend( [ pinyinString ] * len( keys ) )
fitList, preeditList = self.subFit( fitList, pinyinStringList )
#print fitList
self.picker.set( fitList, preeditList, True )
cache = [ fitPoint, fitList, preeditList ]
self.cache.append( cache )
self.candList = []
self.candCacheIndex = len( self.cache ) - 1
self.candStartIndex = 0
def pop( self ) :
if len( self.cache ) > 1 :
self.spliter.pop()
self.cache = self.cache[:-1]
cache = self.cache[-1]
fitList = cache[1]
preeditList = cache[2]
self.picker.set( fitList, preeditList, True )
self.candList = []
self.candCacheIndex = len( self.cache ) - 1
self.candStartIndex = 0
#.........这里部分代码省略.........
示例3: main
# 需要导入模块: from dictionary import Dictionary [as 别名]
# 或者: from dictionary.Dictionary import load [as 别名]
def main():
# Load the dictionary.
dictionary = Dictionary.load(DICTIONARY_FILENAME)
board = Board()
# Keep track of the winning solution at each round.
winners = []
# List of letters we can still pick from.
bag = get_full_bag()
# Rack starts out empty. Keep track of current and last rack state.
rack = ""
old_rack = ""
count = 0
# Keep track of current and last board state,
update_board = None
old_board = None
# Baxter's score
my_score = 0
#Create classifier
classify = CNN_Model()
# Create video feeds
# cam = cv2.VideoCapture(1)
# print cam.isOpened()
# Keep playing until we're out of tiles or solutions.
while count < 8:
count+=1
# Fill up our rack.
print "Bag: %s" % "".join(bag)
old_rack = rack
# Updates rack with current rack from video feed.
# cam1 = cv2.VideoCapture(1)
# print cam1.isOpened()
cam1 = 1
rack = get_rack(classify,cam1)
# cam1.release()
cv2.destroyAllWindows()
# Get a list of possible solutions. These aren't all necessarily legal.
solutions = board.generate_solutions(rack, dictionary)
solution = board.find_best_solution(solutions, dictionary)
if solution:
print "Winner: %s" % solution
# Play the winning solution.
board.create_board()
print("I suggest you play the word:"+solution.word)
#speech.speak(solution)
else:
# Should put letters back in bag.
break
print board
# Wait for "Enter" press, signifying the player has completed his/her turn.
#wait = raw_input("Press enter when finished with move")
# Get word that was just played on the board by fetching the new board state.
# cam1.release()
# del cam1
# cam1 = cv2.VideoCapture(0)
# while not cam1.isOpened():
# cam1.release()
# del cam1
# cam1 = cv2.VideoCapture(0)
update_board = get_board(classify,cam1)
# cam1.release()
move,letter_placed_on_board = board.get_played_word(update_board,old_board,dictionary)
print ("The word"+move+"was just played")
if (move == solution.word):
print("Player listened to Baxter")
else:
print("defied Baxter")
print "Baxter's Score: %d" % my_score
generate_rack(rack,old_rack,bag)
for char in letter_placed_on_board:
rack = rack.replace(char,"")
print "Baxter's Score: %d" % my_score
print "Baxter's Words:"
for rack, winner in winners:
print " %s: %s" % (rack, winner)
示例4: Dictionary
# 需要导入模块: from dictionary import Dictionary [as 别名]
# 或者: from dictionary.Dictionary import load [as 别名]
asset.register('main_css', scss)
asset.register('main_coffee', coffee)
# http://stackoverflow.com/a/9511655
extra_dirs = ['templates',]
extra_files = extra_dirs[:]
for extra_dir in extra_dirs:
for dirname, dirs, files in os.walk(extra_dir):
for filename in files:
filename = os.path.join(dirname, filename)
if os.path.isfile(filename):
extra_files.append(filename)
d = Dictionary()
try:
d.load()
except:
pass
def allowed_file(filename):
return (
'.' in filename and
filename.rsplit('.', 1)[1] in app.config['ALLOWED_EXTENSIONS']
)
@app.route('/')
@app.route('/index')
def index():
return render_template('layout.html',
示例5: main
# 需要导入模块: from dictionary import Dictionary [as 别名]
# 或者: from dictionary.Dictionary import load [as 别名]
def main():
# Load the dictionary.
dictionary = Dictionary.load(DICTIONARY_FILENAME)
board = Board()
# Keep track of the winning solution at each round.
winners = []
# List of letters we can still pick from.
bag = get_full_bag()
# Rack starts out empty.
rack = ""
old_rack = ""
count = 0
# Baxter's score
my_score = 0
# Opponent's score
opp_score = 0
# Parameter setting the minimum point defiticit of Baxter's opponent\
# before Baxter attempts to manipulate his teammate to play low-scoring words
manip_threshold = 50
# Keep playing until we're out of tiles or solutions.
while count < 8:
count = count +1
# Fill up our rack.
print "Bag: %s" % "".join(bag)
update_board = None
old_board = None
# rack = get_rack()
#if not rack:
# break
old_rack = rack
rack = scrabblerack.boardtrainer('')
print rack
# start_time = 0
# elapsed_time = 0
# wait_time = 8*60
# while (elapsed_time < wait_time)
#old_board = updated_board
#updated_board = board.create_board()
#rack = get_rack()
# if rack:
# generate_rack(rack,old_rack,bag)
# break
#opp_score = opp_score + board.opponent_word_score(update_board,old_board,dictionary)
# opp_score = opp_score + board.opponent_word_score(dictionary)
# elapsed_time = time.time() - start_time
#generate_rack(rack,old_rack,bag)
# Get a list of possible solutions. These aren't all necessarily legal.
solutions = board.generate_solutions(rack, dictionary)
#rack = generate_rack(rack,old_rack,bag)
# Weed out the illegal solutions and score the rest, returning the
# highest-scoring solution.
# sets the percentile of the word's score
low_score_param = 1/2
if (my_score > (opp_score + manip_threshold) or my_score > 500):
solution = board.find_suboptimal_solution(solutions, dictionary, low_score_param)
else: solution = board.find_best_solution(solutions, dictionary)
if solution:
print "Winner: %s" % solution
# Play the winning solution.
board.add_solution(solution)
winners.append((rack, solution))
my_score = my_score + solution.score
# Deplete the rack of the used tiles.
rack = solution.get_new_rack(rack)
else:
# Should put letters back in bag.
break
print board
board.create_board()
speech.speak(solution)
word = raw_input("What word would you like to play? ")
row = raw_input("What row does it start at? ")
col = raw_input("What column does it start at? ")
direc = raw_input("Is it oriented vertically or horizontally? ")
#indices = raw_input("indices? ")
# if (dir == 'horizontally'): dir = direction.Direction(0,1)
# else: direction.Direction(1,0)
#opp_score = opp_score + board.opponent_word_score(row,col,dir,word,dictionary,indices)
row = int(row)
col = int(col)
opp_score = opp_score + board.opponent_word_score(row,col,word,direc,dictionary)
print "Baxter's Score: %d" % my_score
print "Opponent's Score: %d" % opp_score
#.........这里部分代码省略.........