本文整理汇总了Python中space.Space类的典型用法代码示例。如果您正苦于以下问题:Python Space类的具体用法?Python Space怎么用?Python Space使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Space类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: build_src_wrapper
def build_src_wrapper(self, source_file, test_wpairs):
"""
In the _source_ space, we only need to load vectors for the words in
test. Semantic spaces may contain additional words.
All words in the _target_ space are used as the search space
"""
source_words = set(test_wpairs.iterkeys())
if self.additional:
#read all the words in the space
lexicon = set(np.loadtxt(source_file, skiprows=1, dtype=str,
comments=None, usecols=(0,)).flatten())
#the max number of additional+test elements is bounded by the size
#of the lexicon
self.additional = min(self.additional, len(lexicon) - len(source_words))
random.seed(100)
logging.info("Sampling {} additional elements".format(self.additional))
# additional lexicon:
lexicon = random.sample(list(lexicon.difference(source_words)),
self.additional)
#load the source space
source_sp = Space.build(source_file,
lexicon=source_words.union(set(lexicon)),
max_rows=1000)
else:
source_sp = Space.build(source_file, lexicon=source_words,
max_rows=1000)
source_sp.normalize()
return source_sp
开发者ID:makrai,项目名称:dinu15,代码行数:29,代码来源:test_tm.py
示例2: post_space_handler
def post_space_handler(environ, start_response):
"""
entry point for posting a new space name to TiddlyWeb
"""
space_name = environ['tiddlyweb.query']['name'][0]
space = Space(environ)
try:
space.create_space(space_name, environ['tiddlyweb.config']['space'])
except (RecipeExistsError, BagExistsError):
raise HTTP409('Space already Exists: %s' % space_name)
host = environ['tiddlyweb.config']['server_host']
if 'port' in host:
port = ':%s' % host['port']
else:
port = ''
recipe = Recipe('%s_public' % space_name)
new_space_uri = '%s/tiddlers.wiki' % recipe_url(environ, recipe)
start_response('201 Created', [
('Location', new_space_uri),
('Content-type', 'text/plain')])
return new_space_uri
开发者ID:FND,项目名称:tiddlyspace.old,代码行数:26,代码来源:handler.py
示例3: testExecute
def testExecute(self):
from space import Space
from player import Player
from items.weapon import Weapon
from commands.drop_command import DropCommand
space = Space("Shire", "Home of the Hobbits.")
player = Player("Frodo", space)
dropCmd = DropCommand("drop", "Drops an object from inventory to space", player)
weapon = Weapon("Dagger", "A trusty blade", 2, 2, 2)
player.addToInventory(weapon)
player.equip(weapon)
#Asserts item in player inventory but not in space
self.assertFalse(space.containsItem(weapon), "Space should not have item but does.")
inventory = player.getInventory()
self.assertTrue(inventory.containsItem(weapon), "Inventory should have item but does not.")
#Assert item in space but not in player inventory and not in equipment
rawInputMock = MagicMock(return_value="Dagger")
with patch('commands.drop_command.raw_input', create=True, new=rawInputMock):
dropCmd.execute()
self.assertTrue(space.containsItemString("Dagger"), "Space should have item but does not.")
inventory = player.getInventory()
self.assertFalse(inventory.containsItem(weapon), "Inventory should not have item but does.")
equipped = player.getEquipped()
self.assertFalse(equipped.containsItem(weapon), "Equipment should not have item but does.")
开发者ID:dchukhin,项目名称:lord-of-the-rings,代码行数:34,代码来源:test.py
示例4: __init__
def __init__(self):
self.name = 'World'
Space.__init__(self)
if farm_config.DEBUG_WIN:
debug_console.get()._print("World created.")
self.house = House(1, 1, HOUSE_GRAPHIC, self)
self.ship_box = Shipbox(4, 12, SHIP_BOX_GRAPHIC, self)
self.pond = Pond(GAME_WIN_SIZE_Y - 5,
GAME_WIN_SIZE_X - 16,
POND_GRAPHIC,
self
)
self.seed(Cave_Entrance, CAVE_GRAPHICS_DIR + 'entrance_external', 1)
self.seed(Tree, 'GRAPHICS/tree', NUMBER_TREES)
self.seed(Rock, 'GRAPHICS/rock', NUMBER_ROCKS)
self.seed(Bush, 'GRAPHICS/bush', NUMBER_BUSHES)
if farm_config.DEBUG_WIN:
debug_console.get()._print("World populated.")
self.sort_contents()
if farm_config.DEBUG_WIN:
debug_console.get()._print("World contents sorted.")
开发者ID:jvasilakes,项目名称:farm-game,代码行数:29,代码来源:environment.py
示例5: train_wrapper
def train_wrapper(seed_fn, source_fn, target_fn, reverse=False, mx_path=None,
train_size=5000):
logging.info("Training...")
seed_trans = read_dict(seed_fn, reverse=reverse)
#we only need to load the vectors for the words in the training data
#semantic spaces contain additional words
source_words = set(seed_trans.iterkeys())
target_words = set().union(*seed_trans.itervalues())
source_sp = Space.build(source_fn, lexicon=source_words)
source_sp.normalize()
target_sp = Space.build(target_fn, lexicon=target_words)
target_sp.normalize()
logging.info("Learning the translation matrix")
tm, used_for_train = train_tm(source_sp, target_sp, seed_trans, train_size)
mx_path = default_output_fn(mx_path, seed_fn, source_fn, target_fn,)
logging.info("Saving the translation matrix to {}".format(mx_path))
np.save('{}.npy'.format(mx_path), tm)
pickle.dump(used_for_train, open('{}.train_wds'.format(mx_path),
mode='w'))
return tm, used_for_train
开发者ID:makrai,项目名称:dinu15,代码行数:26,代码来源:train_tm.py
示例6: test_on_off
def test_on_off(self):
space = Space('hello world')
test_fun = lambda: 'test'
space.on('test', test_fun)
self.assertIn('test', space._Space__events)
space.off('test', test_fun)
self.assertEqual(space._Space__events['test'], [])
开发者ID:jyxt,项目名称:spacepython,代码行数:7,代码来源:test_space.py
示例7: train_translation_matrix
def train_translation_matrix(source_file, target_file, dict_file, out_file):
"""Trains a transltion matrix between the source and target languages, using the words in dict_file as anchor
points and writing the translation matrix to out_file
Note that the source language file and target language file must be in the word2vec C ASCII format
:param source_file: The name of the source language file
:param target_file: The name of the target language file
:param dict_file: The name of the file with the bilingual dictionary
:param out_file: The name of the file to write the translation matrix to
"""
log.info("Reading the training data")
train_data = read_dict(dict_file)
#we only need to load the vectors for the words in the training data
#semantic spaces contain additional words
source_words, target_words = zip(*train_data)
log.info("Reading: %s" % source_file)
source_sp = Space.build(source_file, set(source_words))
source_sp.normalize()
log.info("Reading: %s" % target_file)
target_sp = Space.build(target_file, set(target_words))
target_sp.normalize()
log.debug('Words in the source space: %s' % source_sp.row2id)
log.debug('Words in the target space: %s' % target_sp.row2id)
log.info("Learning the translation matrix")
log.info("Training data: %s" % str(train_data))
tm = train_tm(source_sp, target_sp, train_data)
log.info("Printing the translation matrix")
np.savetxt(out_file, tm)
开发者ID:DethRaid,项目名称:voynich-translation,代码行数:35,代码来源:train_tm.py
示例8: create_room_elements
def create_room_elements(room_name):
room_space = Space({'tiddlyweb.store': store})
this_room = ROOM.replace('ROOMNAME', room_name)
this_room = json.loads(this_room)
room_space.create_space(this_room)
开发者ID:FND,项目名称:tiddlywiki-svn-mirror,代码行数:8,代码来源:room_script.py
示例9: test_append
def test_append(self):
space = Space('hello world')
space.append('foo', 'bar')
space.set('foo2', 'bar')
space.append('foo', 'two')
self.assertEqual(space.get('foo'), 'bar')
self.assertEqual(space.length(), 4)
开发者ID:jyxt,项目名称:spacepython,代码行数:7,代码来源:test_space.py
示例10: addproject
def addproject(args):
"""make a project space. <project_name>"""
if len(args) != 1:
print >> sys.stderr, ('usage: twanager addproject <project_name>')
#replace PROJECT_NAME with the actual name of the project
this_project = PROJECT.replace('PROJECT_NAME', args[0])
this_project = json.loads(this_project)
#create the space
project_space = Space({'tiddlyweb.store': get_store(config)})
project_space.create_space(this_project)
开发者ID:bengillies,项目名称:TiddlyWeb-Plugins,代码行数:12,代码来源:project_space.py
示例11: test_trigger
def test_trigger(self):
space = Space('hello world')
class Count():
def __init__(self):
self.count = 0
def incr(self):
self.count += 1
c = Count()
space.on('change', c.incr)
space.trigger('change')
self.assertEqual(c.count, 1)
开发者ID:jyxt,项目名称:spacepython,代码行数:13,代码来源:test_space.py
示例12: eval_js_vm
def eval_js_vm(js):
a = ByteCodeGenerator(Code())
s = Space()
a.exe.space = s
s.exe = a.exe
d = pyjsparser.parse(js)
a.emit(d)
fill_space.fill_space(s, a)
# print a.exe.tape
a.exe.compile()
return a.exe.run(a.exe.space.GlobalObj)
开发者ID:JackDandy,项目名称:SickGear,代码行数:14,代码来源:seval.py
示例13: build
def build(cls, core_space, **kwargs):
"""
Reads in data files and extracts the data to construct a semantic space.
If the data is read in dense format and no columns are provided,
the column indexing structures are set to empty.
Args:
data: file containing the counts
format: format on the input data file: one of sm/dm
rows: file containing the row elements. Optional, if not provided,
extracted from the data file.
cols: file containing the column elements
Returns:
A semantic space build from the input data files.
Raises:
ValueError: if one of data/format arguments is missing.
if cols is missing and format is "sm"
if the input columns provided are not consistent with
the shape of the matrix (for "dm" format)
"""
sp = Space.build(**kwargs)
mat = sp._cooccurrence_matrix
id2row = sp.id2row
row2id = sp.row2id
return PeripheralSpace(core_space, mat, id2row, row2id)
开发者ID:Aliases,项目名称:dissect,代码行数:31,代码来源:peripheral_space.py
示例14: test_wrapper
def test_wrapper(self):
self.load_tr_mx()
logging.info('The denominator of precision {} OOV words'.format(
'includes' if self.args.coverage
else "doesn't include"))
test_wpairs = read_dict(self.args.seed_fn, reverse=self.args.reverse,
needed=1000 if self.args.coverage else -1,
exclude=self.exclude_from_test)
source_sp = self.build_src_wrapper(self.args.source_fn, test_wpairs)
target_sp = Space.build(self.args.target_fn)
target_sp.normalize()
test_wpairs, _ = get_invocab_trans(source_sp, target_sp,
test_wpairs, needed=1000)
"""
#turn test data into a dictionary (a word can have mutiple translation)
gold = collections.defaultdict(set, test_wpairs)
for sr, tg in test_wpairs:
gold[sr].add(tg)
"""
logging.info(
"Mapping all the elements loaded in the source space")
mapped_source_sp = apply_tm(source_sp, self.tr_mx)
if hasattr(self.args, 'mapped_vecs') and self.args.mapped_vecs:
logging.info("Printing mapped vectors: %s" % self.args.mapped_vecs)
np.savetxt("%s.vecs.txt" % self.args.mapped_vecs, mapped_source_sp.mat)
np.savetxt("%s.wds.txt" %
self.args.mapped_vecs, mapped_source_sp.id2word, fmt="%s")
return score(mapped_source_sp, target_sp, test_wpairs, self.additional)
开发者ID:makrai,项目名称:dinu15,代码行数:35,代码来源:test_tm.py
示例15: main
def main():
from space import Space
import fill_space
from pyjsparser import parse
import json
a = ByteCodeGenerator(Code())
s = Space()
fill_space.fill_space(s, a)
a.exe.space = s
s.exe = a.exe
con = get_file_contents('internals/esprima.js')
d = parse(con+(''';JSON.stringify(exports.parse(%s), 4, 4)''' % json.dumps(con)))
# d = parse('''
# function x(n) {
# log(n)
# return x(n+1)
# }
# x(0)
# ''')
# var v = 333333;
# while (v) {
# v--
#
# }
a.emit(d)
print a.declared_vars
print a.exe.tape
print len(a.exe.tape)
a.exe.compile()
def log(this, args):
print args[0]
return 999
print a.exe.run(a.exe.space.GlobalObj)
开发者ID:pymedusa,项目名称:SickRage,代码行数:42,代码来源:byte_trans.py
示例16: test_multiline
def test_multiline(self):
space = Space('my multiline\n string')
self.assertEqual(space.get('my'), 'multiline\nstring')
space2 = Space('my \n \n multiline\n string')
self.assertEqual(space2.get('my'), '\n\nmultiline\nstring')
space3 = Space('brave new\n world')
self.assertEqual(space3.get('brave'), 'new\nworld', 'ml value correct')
self.assertEqual(str(space3), 'brave new\n world\n', 'multiline does not begin with nl')
space4 = Space('brave \n new\n world')
self.assertEqual(space4.get('brave'), '\nnew\nworld', 'ml begin with nl value correct')
开发者ID:jyxt,项目名称:spacepython,代码行数:13,代码来源:test_space.py
示例17: __init__
def __init__(self, clear):
self.clear_term = clear
self.space = Space()
enterprise = Ship("Enterprise", "Cpt. Pickard")
enterprise.weapons = [
Weapon(name="Burst Laser II", dmg=(4, 6), acc=60),
Weapon(name="Burst Laser II", dmg=(4, 6), acc=60),
]
self.space.ships.append(enterprise)
self.space.ships.append(Ship("Orion", "Cpt. Clark"))
self.space.ships.append(Ship("Deathstar", "Darth Vader"))
print self.space.ships
开发者ID:4nu81,项目名称:python_trainee,代码行数:12,代码来源:start.py
示例18: store
def store(key, message, in_path, out_path):
epub = Epub()
epub.expand(in_path)
space = Space(epub)
binary_message = ''.join([format(ord(x), '0'+str(CHAR_BIT_SIZE)+'b') for x in message])
message_size = format(len(binary_message), 'b')
header_size = format(len(message_size), '0'+str(HEADER_BIT_SIZE)+'b')
bits_to_write = header_size + message_size + binary_message
if (len(space)) < len(bits_to_write):
print 'Error, not enough space on the epub file'
line_order = LineOrder(key, len(space))
add_noise(space)
for bit in bits_to_write:
space[line_order.next()] = (bit == '1')
space.commit()
epub.contract(out_path)
开发者ID:dantas,项目名称:steganography-epub,代码行数:23,代码来源:__init__.py
示例19: testMultiLine
def testMultiLine(self):
string = 'user\n\
name Aristotle\n\
admin false\n\
stage\n\
name home\n\
domain test.test.com\n\
pro false\n\
domains\n\
test.test.com\n\
images\n\
blocks\n\
users\n\
stage home\n\
pages\n\
home\n\
settings\n\
data\n\
title Hello, World\n\
block1\n\
content Hello world\n'
space = Space(string)
self.assertEqual(space.get('domains test.test.com pages home settings data title'), 'Hello, World', 'Multiline creation shuold be OK')
开发者ID:breck7,项目名称:spacepython,代码行数:24,代码来源:test_space.py
示例20: __init__
def __init__(self):
if farm_config.DEBUG_WIN:
debug_console.get()._print("Cave created.")
self.name = 'Cave'
Space.__init__(self)
# Used only by Astar
self.closed_list = []
self.seed(Room, CAVE_GRAPHICS_DIR + 'room', 5)
if farm_config.DEBUG_WIN:
debug_console.get()._print("Rooms seeded.")
entrance = Entrance(0,
10,
CAVE_GRAPHICS_DIR + 'entrance_internal',
self)
rooms = self.contents['Room']
self.Astar = RoomWrapper(Astar)
halls = self.Astar(rooms, self.closed_list)
if farm_config.DEBUG_WIN:
debug_console.get()._print("%d halls found." % len(halls))
for coor in halls:
Hall.create(coor[0], coor[1], CAVE_GRAPHICS_DIR + 'hall', self)
if farm_config.DEBUG_WIN:
debug_console.get()._print("Halls created.")
开发者ID:jvasilakes,项目名称:farm-game,代码行数:36,代码来源:cave_system.py
注:本文中的space.Space类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论