def __init__(self, client, parent=None): # Setup some hints and options before calling the parent constructor # Some size hints self.__bw = 1 self.pos = { 'client': {'x': self.__bw, 'y': self.__bw, 'width': - (self.__bw * 2), 'height': - (self.__bw * 2)} } # Some colors... self.colors = { State.Active: { # active 'bg': config.get_option('frm_thinborder_clr'), 'thinborder': config.get_option('frm_thinborder_clr') }, State.Inactive: { # inactive 'bg': config.get_option('frm_thinborder_clr'), 'thinborder': config.get_option('frm_thinborder_clr') } } # Set the sizes of each side self.top = self.left = self.right = self.bottom = self.__bw _Frame.__init__(self, client, parent) self.configure_client(width=self.client.win.geom['width'], height=self.client.win.geom['height'])
def __init__(self, *args, **kwargs): super().__init__() vocabs = kwargs.pop('vocabs') self.vocab = {vocab.name: vocab for vocab in vocabs} self.dropout = config.get_option('dropout_rate') self.activate = nn.functional.__getattribute__( config.get_option('activate'))
def get_related_words(word): word1 = word dbname = 'cooccur' user = config.get_option(dbname,'user') passwd = config.get_option(dbname,'passwd') con = MySQLdb.connect(db=dbname,host='localhost',user=user,\ passwd=passwd,use_unicode=True,charset='utf8') cur = con.cursor() cur.execute('select id,df from word where name = "%s"' % (word1)) row = cur.fetchone() w1id = int(row[0]) w1f = int(row[1]) cur.execute(''' select c.word2_id,w.df,c.simpson,c.cosine,w.name from word w,co c where c.word1_id = %d and w.id = c.word2_id and c.simpson > 0 order by c.simpson desc limit 1000 ''' % (w1id)) ids = cur.fetchall() simpsons = [] cosines = [] words = {} for i in xrange(len(ids)): w2id = int(ids[i][0]) w2f = int(ids[i][1]) simpson = float(ids[i][2]) cosine = float(ids[i][3]) word2 = ids[i][4] words[word2] = w2f simpsons.append((word2,simpson)) cosines.append((word2,cosine)) simpsons.sort(lambda x,y:cmp(x[1],y[1]),reverse=True) cosines.sort(lambda x,y:cmp(x[1],y[1]),reverse=True) newresult = {} news = {} for i in xrange(len(simpsons)): newresult[simpsons[i][0]] = {'s1':0,'s2':0,'c1':0,'c2':0} news[simpsons[i][0]] = news.get(simpsons[i][0], 0) + simpsons[i][1]/float(simpsons[0][1]) newresult[simpsons[i][0]]['s1'] = i newresult[simpsons[i][0]]['s2'] = simpsons[i][1]/float(simpsons[0][1]) for i in xrange(len(cosines)): newresult[cosines[i][0]]['c1'] = i newresult[cosines[i][0]]['c2'] = cosines[i][1] newslist = [(k,v) for k,v in news.items() if v > 0.3] newslist.sort(lambda x,y:cmp(x[1],y[1]),reverse=True) return newslist, newresult
def __init__(self, *args, **kwargs): self._name = kwargs.pop('name', self.__class__.__name__) self._filename = os.path.join(config.get_option('save'), self._name + '.txt') self._complete = False self._str2idx = zip(self._special_tokens, range(len(self._special_tokens))) self._idx2str = zip(range(len(self._special_tokens)), self._special_tokens) self._tok2idx = self._str2idx self._counts = None recount = config.get_option('recount') if not recount and os.path.isfile( self.filename): # read file from existed vocab file. self.load()
def __init__(self,DEBUG=False): # 初期化 dbname = 'graduate' user = config.get_option(dbname,'user') passwd = config.get_option(dbname,'passwd') con = MySQLdb.connect(db=dbname,host='localhost',user=user, passwd=passwd,use_unicode=True,charset='utf8') self.cur = con.cursor() self.hutil = None self.hutil_ext = None self.simpson_threshold = 2.0 self.cosine_threshold = 0.056 self.DEBUG = DEBUG self.words = {}
def ConfigureNotifyEvent(self): win = Window.deep_lookup(self._event_data['window'].wid) mt_off = config.get_option( 'movetime_offset', *state.get_active_wsid_and_mid() ) if ( win and win.lives() and not win.floating and (time.time() - win.pytyle_moved_time) > mt_off ): if ( state.pointer_grab and win.width == self._event_data['width'] and win.height == self._event_data['height'] ): pointer = ptxcb.XROOT.query_pointer() if ptxcb.XROOT.button_pressed(): state.moving = win state.moving.moving = True win.set_geometry( self._event_data['x'], self._event_data['y'], self._event_data['width'], self._event_data['height'] )
def get_option(self, option): return config.get_option( option, self.workspace.id, self.monitor.id, self.get_name() )
def do_show(self, context, option=None): "usage: show [all | <option>]" if option is None or option == 'all': opts = None if option == 'all': opts = config.get_all_options() else: opts = config.get_configured_options() for opt in opts: parts = opt.split('.') print "%s = %s" % (opt, config.get_option(parts[0], parts[1], raw=True)) else: parts = option.split('.') if len(parts) != 2: context.fatal_error("Unknown option: " + option) val = config.get_option(parts[0], parts[1], raw=True) print "%s = %s" % (option, val)
def show_options(fn): s = '' for opt in opts: if fn(opt): parts = opt.split('.') val = (opt, config.get_option(parts[0], parts[1], raw=True)) s += "%s = %s\n" % val utils.page_string(s)
def do_show(self, context, option=None): "usage: show [all | <option>]" if option is None or option == 'all': opts = None if option == 'all': opts = config.get_all_options() else: opts = config.get_configured_options() for opt in opts: parts = opt.split('.') print "%s = %s" % ( opt, config.get_option(parts[0], parts[1], raw=True)) else: parts = option.split('.') if len(parts) != 2: context.fatal_error("Unknown option: " + option) val = config.get_option(parts[0], parts[1], raw=True) print "%s = %s" % (option, val)
def __init__(self, *args, **kwargs): super().__init__(self, *args, **kwargs) self.word_dim = config.get_option('word_dim') self.pos_dim = config.get_option('pos_dim') self.rnn_layers = config.get_option('rnn_layers') self.rnn_hidden = config.get_option('rnn_hidden') self.pred_hidden_dim = config.get_option('pred_hidden_dim') self.role_hidden_dim = config.get_option('role_hidden_dim') self.word_lookup = nn.Embedding(len(self.vocab['WordVocab']), self.word_dim) self.pos_lookup = nn.Embedding(len(self.vocab['TagVocab']), self.pos_dim) self.rnn_input_dim = self.word_dim + self.pos_dim self.rnn = nn.LSTM(input_size=self.rnn_input_dim, hidden_size=self.rnn_hidden // 2, num_layers=self.rnn_layers, batch_first=True, dropout=self.dropout, bidirectional=True) self.predicate_mlp = nn.Linear(self.rnn_hidden, self.pred_hidden_dim) self.role_mlp = nn.Linear(self.rnn_hidden, self.role_hidden_dim) self.bilinear = BiAffineModel(self.role_hidden_dim, self.pred_hidden_dim, len(self.vocab['SemTagVocab']))
def put_file(): md5_encoded, md5 = get_hash() client = boto3.client( 's3', aws_access_key_id=config.get_option('access_key', 'AWS'), aws_secret_access_key=config.get_option('secret_key', 'AWS'), ) metadata = {'md5': md5} with open(config.ENCRYPTED_FILE_PATH, 'rb') as encrypted_file: try: response = client.put_object(Body=encrypted_file, Bucket=config.get_option( 'bucket', 'AWS'), Key=config.ENCRYPTED_FILENAME, ContentMD5=md5_encoded, Metadata=metadata) except Exception: print('Error putting file in S3.') return False if response['ResponseMetadata']['HTTPStatusCode'] == 200: return True return False
def __init__(self, workspace, mid, x, y, width, height): self.workspace = workspace self.id = mid self.x = x self.y = y self.width = width self.height = height self.windows = set() self.active = None self.tiler = None self.auto = True self.tilers = [] # Attach tilers... for tile_name in config.get_option('tilers', self.workspace.id, self.id): if hasattr(tilers, tile_name): tiler = getattr(tilers, tile_name) self.add_tiler(tiler(self))
def apply_config(): Command.init() for mon in Workspace.iter_all_monitors(): if config.get_option("tile_on_startup", mon.workspace.id, mon.id): mon.tile(force_tiling=True)
def __init__(self, client, parent=None): # Setup some hints and options before calling the parent constructor # Some size hints self.__bw = config.get_option('frm_border_brdr_sz') self.__crnr_sz = self.__bw + 24 self.pos = { 'client': {'x': self.__bw, 'y': self.__bw, 'width': - (self.__bw * 2), 'height': - (self.__bw * 2)} } self.pos['top_side'] = { 'x': self.__crnr_sz, 'y': 0, 'width': - (self.__crnr_sz * 2), 'height': self.__bw } self.pos['top_left'] = { 'x': 0, 'y': 0, 'width': self.__crnr_sz, 'height': self.__bw } self.pos['top_right'] = { 'x': self.__crnr_sz, 'y': 0, 'width': self.__crnr_sz, 'height': self.__bw } self.pos['bottom_side'] = { 'x': self.__crnr_sz, 'y': self.__bw, 'width': - (self.__crnr_sz * 2), 'height': self.__bw } self.pos['bottom_left'] = { 'x': 0, 'y': 0, 'width': self.__crnr_sz, 'height': self.__bw } self.pos['bottom_right'] = { 'x': self.__crnr_sz, 'y': 0, 'width': self.__crnr_sz, 'height': self.__bw } self.pos['left_side'] = { 'x': 0, 'y': self.__crnr_sz, 'width': self.__bw, 'height': - (self.__crnr_sz * 2) } self.pos['left_top'] = { 'x': 0, 'y': 0, 'width': self.__bw, 'height': self.__crnr_sz } self.pos['left_bottom'] = { 'x': 0, 'y': self.__crnr_sz, 'width': self.__bw, 'height': self.__crnr_sz } self.pos['right_side'] = { 'x': self.__bw, 'y': self.__crnr_sz, 'width': self.__bw, 'height': - (self.__crnr_sz * 2) } self.pos['right_top'] = { 'x': self.__bw, 'y': 0, 'width': self.__bw, 'height': self.__crnr_sz } self.pos['right_bottom'] = { 'x': self.__bw, 'y': self.__crnr_sz, 'width': self.__bw, 'height': self.__crnr_sz } # Some colors... self.colors = { State.Active: { 'bg': config.get_option('frm_border_bg_a'), 'thinborder': config.get_option('frm_border_thin_clr'), 'bottomborder': config.get_option('frm_border_bg_a'), }, State.Inactive: { 'bg': config.get_option('frm_border_bg_i'), 'thinborder': config.get_option('frm_border_thin_clr'), 'bottomborder': config.get_option('frm_border_bg_i'), }, State.CatchAll: { 'bg': config.get_option('frm_border_bg_c'), 'thinborder': config.get_option('frm_border_thin_clr'), 'bottomborder': config.get_option('frm_border_bg_c'), } } # Set the sizes of each side self.top = self.pos['client']['y'] self.left = self.pos['client']['x'] self.right = self.pos['right_side']['width'] self.bottom = self.pos['bottom_side']['height'] _Frame.__init__(self, client, parent) # Add CatchAll to allowed states self.allowed_states.append(State.CatchAll) self.top_side = TopSide(self) self.top_left = TopLeft(self) self.top_right = TopRight(self) self.bottom_side = BottomSide(self) self.bottom_left = BottomLeft(self) self.bottom_right = BottomRight(self) self.left_side = LeftSide(self) self.left_top = LeftTop(self) self.left_bottom = LeftBottom(self) self.right_side = RightSide(self) self.right_top = RightTop(self) self.right_bottom = RightBottom(self) self.configure_client(width=self.client.win.geom['width'], height=self.client.win.geom['height'])
def __init__(self): section = "mecab" userdic = config.get_option(section, "userdic") rcfile = config.get_option(section, "rcfile") # self.mecab = MeCab.Tagger('--userdic=%s --rcfile=%s' % (userdic,rcfile)) self.mecab = MeCab.Tagger()
running_loss += loss.data[0] running_f.update(predict, sentence['targets'][0]) print('\n{} Loss: {:.4f} {}'.format(phase, running_loss, running_f), file=sys.stderr) if phase == 'dev' and running_f > best_f: best_f = running_f best_model_wts = copy.deepcopy(model.state_dict()) print('', file=sys.stderr) time_elapsed = time.time() - since print('Training complete in {:.0f}m {:.0f}s'.format( time_elapsed // 60, time_elapsed % 60), file=sys.stderr) print('Best val F: {}s'.format(best_f), file=sys.stderr) model.load_state_dict(best_model_wts) return model if __name__ == '__main__': config.parse_args() torch.manual_seed(config.get_option('seed')) mode = config.get_option('mode') if mode == 'train': train() else: NotImplementedError()
def __init__(self): self.train_file = config.get_option('train_file') self.dev_file = config.get_option('dev_file') self._train_set = DataSet(self.train_file) self._dev_set = DataSet(self.dev_file, self._train_set.vocabs)
for timestamp, task in tasks: if timestamp == target_timestamp: if len(task.strip()) > 0: return task return "Nothing scheduled! Proceed at will." if __name__ == '__main__': parser = argparse.ArgumentParser(description="Get the task for a time") parser.add_argument('--time', help="HH:MM-style time. If not provided, get task for current time.") args = parser.parse_args() tasksfilename = config.get_option('tasksfile') tasks = [] with open(tasksfilename) as tfile: for l in tfile.readlines(): toks = l.split(',', 1) if len(toks) > 1: tasks.append((toks[0], toks[1])) if args.time is not None: hours, mins = [int(tok) for tok in args.time.split(':')] else: now = datetime.datetime.now() hours, mins = now.hour, now.minute print get_task(tasks, hours, mins)
def __init__(self, *args, **kwargs): self.case = config.get_option('word_cased') super().__init__(*args, **kwargs)
def compress(): paths = config.get_option('Folders', 'Input', 'str_list') with tarfile.open(config.COMPRESSED_FILE_PATH, 'w:gz') as tar: for path in paths: tar.add(path)
def __init__(self, client, parent=None): # Setup some hints and options before calling the parent constructor # Some size hints self.__bw = 1 self.__bottom_bw = config.get_option('frm_full_bottom_brdr_sz') self.__titleheight = 26 # Dictionary that determines the relative layout of each # window in the frame # NOTE: The values here can be both static and dynamic. For example, # a static position might be "2" whereas a dynamic position might be # "1/2". Whether a value is static or dynamic depends on how it is # used. self.pos = { 'client': {'x': self.__bw, 'y': self.__bw + self.__titleheight, 'width': - (self.__bw * 2), 'height': - (self.__bw + self.__bottom_bw + self.__titleheight + 1)}, 'icon': {'x': self.__bw + 3, 'y': self.__bw + 3, 'width': 20, 'height': 20}, 'buttons': {'x': -75, 'y': 2, 'width': 75, 'height': 20}, } self.pos['close'] = { 'x': -22, 'y': self.__bw + 4, 'width': 17, 'height': 17 } self.pos['maximize'] = { 'x': self.pos['close']['x'] * 2, 'y': self.pos['close']['y'], 'width': self.pos['close']['width'], 'height': self.pos['close']['height'] } self.pos['restore'] = self.pos['maximize'] self.pos['minimize'] = { 'x': self.pos['close']['x'] * 3, 'y': self.pos['close']['y'], 'width': self.pos['close']['width'], 'height': self.pos['close']['height'] } self.pos['buttonbg'] = { 'x': self.pos['minimize']['x'], 'y': 0, 'width': - self.pos['minimize']['x'], 'height': self.__titleheight } self.pos['title_bar'] = { 'x': 0, 'y': 0, 'width': 0, 'height': self.__titleheight } self.pos['title'] = { 'x': self.pos['icon']['x'] + self.pos['icon']['width'] + 2, 'y': self.pos['icon']['y'] + 2, 'width': 800, # Max width 'height': 20 # Max height } self.pos['title_border'] = { 'x': 0, 'y': self.__titleheight, 'width': 0, 'height': 1 } self.pos['bottom_border'] = { 'x': 0, 'y': self.__bw + self.__titleheight, 'width': 0, 'height': 1 } self.pos['top_side'] = { 'x': self.pos['title']['x'], 'y': 0, 'width': - (self.pos['title']['x'] * 2), 'height': 5 } self.pos['top_left'] = { 'x': 0, 'y': 0, 'width': self.pos['title']['x'], 'height': 5 } self.pos['top_right'] = { 'x': self.pos['top_left']['width'], 'y': 0, 'width': self.pos['title']['x'], 'height': 5 } self.pos['bottom_side'] = { 'x': self.pos['title']['x'], 'y': self.__bw + self.__titleheight + 1, 'width': - (self.pos['title']['x'] * 2), 'height': self.__bottom_bw } self.pos['bottom_left'] = { 'x': 0, 'y': 0, 'width': self.pos['top_left']['width'], 'height': self.pos['bottom_side']['height'] } self.pos['bottom_right'] = { 'x': self.pos['bottom_left']['width'], 'y': 0, 'width': self.pos['top_right']['width'], 'height': self.pos['bottom_side']['height'] } self.pos['left_side'] = { 'x': 0, 'y': self.__bw + self.__titleheight, 'width': self.__bw, 'height': - (2 * (self.__bw + self.__titleheight)) } self.pos['left_top'] = { 'x': 0, 'y': 0, 'width': 5, 'height': self.pos['left_side']['y'] } self.pos['left_bottom'] = { 'x': 0, 'y': self.pos['left_top']['height'], 'width': self.__bw, 'height': self.pos['left_side']['y'] } self.pos['right_side'] = { 'x': self.__bw, 'y': self.__bw + self.__titleheight, 'width': self.__bw, 'height': - (2 * (self.__bw + self.__titleheight)) } self.pos['right_top'] = { 'x': self.__bw - 5, 'y': 0, 'width': 5, 'height': self.pos['right_side']['y'] } self.pos['right_bottom'] = { 'x': self.__bw, 'y': self.pos['right_top']['height'], 'width': self.__bw, 'height': self.pos['right_side']['y'] } # Some colors... self.colors = { State.Active: { # active 'bg': config.get_option('frm_full_bg_a'), 'title': config.get_option('frm_full_title_a'), 'thinborder': config.get_option('frm_thinborder_clr'), 'bottomborder': config.get_option('frm_full_bottom_brdr_a'), 'buttonbg': config.get_option('frm_full_button_bg_a'), 'buttonfg': config.get_option('frm_full_button_fg_a') }, State.Inactive: { # inactive 'bg': config.get_option('frm_full_bg_i'), 'title': config.get_option('frm_full_title_i'), 'thinborder': config.get_option('frm_thinborder_clr'), 'bottomborder': config.get_option('frm_full_bottom_brdr_i'), 'buttonbg': config.get_option('frm_full_button_bg_i'), 'buttonfg': config.get_option('frm_full_button_fg_i') } } # Set the sizes of each side self.top = self.pos['client']['y'] self.left = self.pos['client']['x'] self.right = self.pos['right_side']['width'] self.bottom = (self.pos['bottom_side']['height'] + self.pos['bottom_border']['height']) _Frame.__init__(self, client, parent) # Put all the goodies underneath the borders and stuff self.title_bar = TitleBar(self) self.title = Title(self) self.buttonbg = ButtonBG(self) # Hides title if the window is too small self.close = Close(self) self.minimize = Minimize(self) self.restore = Restore(self) self.maximize = Maximize(self) self.icon = Icon(self) self.top_side = TopSide(self) self.top_left = TopLeft(self) self.top_right = TopRight(self) self.bottom_side = BottomSide(self) self.bottom_left = BottomLeft(self) self.bottom_right = BottomRight(self) self.left_side = LeftSide(self) self.left_top = LeftTop(self) self.left_bottom = LeftBottom(self) self.right_side = RightSide(self) self.right_top = RightTop(self) self.right_bottom = RightBottom(self) self.title_border = ThinBorder(self) self.bottom_border = ThinBorder(self) self.choose_maximized() self.configure_client(width=self.client.win.geom['width'], height=self.client.win.geom['height'])
def add_tiler(self, tiler): if tiler.get_name() in config.get_option('all_tilers'): self.tilers.append(tiler)
def __init__(self): section = 'mecab' userdic = config.get_option(section,'userdic') rcfile = config.get_option(section,'rcfile') #self.mecab = MeCab.Tagger('--userdic=%s --rcfile=%s' %(userdic,rcfile)) self.mecab = MeCab.Tagger()
def calculate_workarea(self): self.wa_x = self.x self.wa_y = self.y self.wa_width = self.width self.wa_height = self.height if self.get_tiler(): margin = self.get_tiler().get_option('margin') else: margin = config.get_option('margin', self.workspace.id, self.id) if margin and len(margin) == 4: # margin = top(0) right(1) bottom(2) left(3) self.wa_x += margin[3] self.wa_y += margin[0] self.wa_width -= margin[1] + margin[3] self.wa_height -= margin[0] + margin[2] else: wids = ptxcb.XROOT.get_window_ids() # Keep track of what we've added... # If we come across a window with the same exact # size/position/struts, skip it! log = [] for wid in wids: win = ptxcb.Window(wid) # We're listening to _NET_WORKAREA, so a panel # might have died before _NET_CLIENT_LIST was updated... try: x, y, w, h = win.get_geometry() d = win.get_desktop_number() except: continue if self.workspace.contains(win.get_desktop_number()) and self.contains(x, y): struts = win.get_strut_partial() if not struts: struts = win.get_strut() key = (x, y, w, h, struts) if key in log: continue log.append(key) if struts and not all([struts[i] == 0 for i in struts]): if struts['left'] or struts['right']: if struts['left']: self.wa_x += w self.wa_width -= w if struts['top'] or struts['bottom']: if struts['top']: self.wa_y += h self.wa_height -= h elif struts: # When accounting for struts on left/right, and # struts are reported properly, x shouldn't be # zero. Similarly for top/bottom and y. if x > 0 and self.width == (x + w): self.wa_width -= w elif y > 0 and self.height == (y + h): self.wa_height -= h elif x > 0 and self.wa_x == x: self.wa_x += w self.wa_width -= w elif y > 0 and self.wa_y == y: self.wa_y += h self.wa_height -= h self.tile()
import xcb.xproto import xpybutil.image as image import xpybutil.event as event import state import events import focus import window import config import rendering import grab from popup import _PopupWindow c_brdr_sz = config.get_option('cycle_brdr_sz') c_brdr_clr = config.get_option('cycle_brdr_clr') c_bg = config.get_option('cycle_bg') c_icn_sz = config.get_option('cycle_icn_sz') class IconWindow(_PopupWindow): def __new__(cls, parent, client): self = _PopupWindow.__new__(cls) mask = xcb.xproto.CW.BackPixel values = [c_bg] self.id = window.create(parent.inner.id, mask, values) self.parent = parent self.client = client