def diff(old_html, new_html, cutoff=0.0, plaintext=False, pretty=False): """Show the differences between the old and new html document, as html. Return the document html with extra tags added to show changes. Add <ins> tags around newly added sections, and <del> tags to show sections that have been deleted. """ if plaintext: old_dom = parse_text(old_html) new_dom = parse_text(new_html) else: old_dom = parse_minidom(old_html) new_dom = parse_minidom(new_html) # If the two documents are not similar enough, don't show the changes. if not check_text_similarity(old_dom, new_dom, cutoff): return '<h2>The differences from the previous version are too large to show concisely.</h2>' dom = dom_diff(old_dom, new_dom) # HTML-specific cleanup. if not plaintext: fix_lists(dom) fix_tables(dom) # Only return html for the document body contents. # body_elements = dom.getElementsByTagName('body') # if len(body_elements) == 1: # dom = body_elements[0] return minidom_tostring(dom, pretty=pretty)
def diff(old_html, new_html, cutoff=0.0, plaintext=False, pretty=False): """Show the differences between the old and new html document, as html. Return the document html with extra tags added to show changes. Add <ins> tags around newly added sections, and <del> tags to show sections that have been deleted. """ if plaintext: old_dom = parse_text(old_html) new_dom = parse_text(new_html) else: old_dom = parse_minidom(old_html) new_dom = parse_minidom(new_html) # If the two documents are not similar enough, don't show the changes. if not check_text_similarity(old_dom, new_dom, cutoff): return '<h2>The differences from the previous version are too large to show concisely.</h2>' dom = dom_diff(old_dom, new_dom) # HTML-specific cleanup. if not plaintext: fix_lists(dom) fix_tables(dom) # Only return html for the document body contents. body_elements = dom.getElementsByTagName('body') if len(body_elements) == 1: dom = body_elements[0] return minidom_tostring(dom, pretty=pretty)
def index(): if request.method == 'POST': response = request.get_json() chat_id = response['message']['chat']['id'] text = response['message']['text'] symbol = parse_text(text) # Commands not found if symbol is None: return jsonify(response) # Check global commands if GLOBAL_COMMANDS.get(symbol): send_message(chat_id, GLOBAL_COMMANDS[symbol]) return jsonify(response) # Get quote obj = get_quote(symbol, API_KEY) if obj is not None: send_message(chat_id, format_message(obj)) else: send_message(chat_id, f'Command "{symbol}" is missing.') return jsonify(response)
def log_bytes(self): result = [] for entry in self.log: lentry = [item for sublist in [(x,) if type(x) is not tuple else x for x in entry] for item in sublist] if lentry[0] == BATTLE_ACTION_MESSAGE: lentry[0] = BATTLE_ACTION_MESSAGE + len(lentry) - 1 result += lentry result.append(0xff) result = [len(result) % 256, len(result) // 256] + result for entry in self.stringbuf: result += util.parse_text(entry) return bytes(result)
def battle_packet_handler(data, player_data): if data[0] == 1: q = storage.sql("select battle_data from last_battle where id=?", (player_data["id"], )) return bytearray(q[0]["battle_data"]) print(data) rnd_items_1 = [] rnd_items_2 = [] for i in range(0, 8): rnd_items_1.append(random.choice(list(items.ITEM_CLASSES.keys()))) for i in range(0, 8): rnd_items_2.append(random.choice(list(items.ITEM_CLASSES.keys()))) rnd_state = { "species": random.choice(list(resources.MON_DATA.keys())), "mon_name": "Shadow", "moves": ["SCRATCH"], "name": "X", "items": rnd_items_1 } attacking_player = json.loads(player_data["mon"]) defending_player = trainerloader.load_trainer(data[2] * 256 + data[1]) b = battle.battle(attacking_player, defending_player) r = bytearray( bytes(defending_player["items"]) + # attacker items bytes(attacking_player["items"]) + # defender items bytes([defending_player["class_id"]]) + # trainer class id bytes(util.bcd(defending_player["bp_reward"])) + # bp reward bytes(util.bcd(defending_player["credits_reward"])) + # credit reward bytes([ resources.MON_DATA[attacking_player["species"]]["mon_numeric_id"] ]) + # attacker species id bytes([ resources.MON_DATA[defending_player["species"]]["mon_numeric_id"] ]) + # defender species id bytes(util.parse_text(defending_player["name"], 21)) + # defender name b.log_bytes() # offset to stringbuf, battle data, stringbuf ) print(r) storage.sql( """ update last_battle set battle_data=? where id=? """, (r, player_data["id"])) return r
def handle_question(): image = util.take_screenshot() image = image[ TOP_LEFT[1] : TOP_LEFT[1] + HEIGHT, TOP_LEFT[0] : TOP_LEFT[0] + WIDTH ] """ cv2.imshow("Image", image) cv2.waitKey(0) """ text = util.image_to_text(image) parsed = util.parse_text(text) if parsed is not None: quest, options = parsed qt = trivia.TriviaQuestion(quest, options) answer_index = qt.answer() util.do_click((800, 315 + answer_index * 60))
model = kenlm.Model(bin_file) print(model.score('this is a sentence .', bos=True, eos=True)) # 其中, 每个句子通过语言模型都会得到一个概率(0-1),然后对概率值取log得到分数(-\propto ,0], # 得分值越接近于0越好。 score函数输出的是对数概率,即log10(p('微 信')),其中字符串可以是gbk,也可以是utf-8 # bos=False, eos=False意思是不自动添加句首和句末标记符,得分值越接近于0越好。 # 一般都要对计算的概率值做log变换,不然连乘值太小了,在程序里会出现 inf 值。 #该模块,可以用来测试词条与句子的通顺度:,注意这里需要空格分割下: text = '再 心 每 天也 不 会 担 个 大 油 饼 到 了 下 午 顶 着 一 了 ' print(model.score(text, bos=True, eos=True)) #3.2 model.full_scores函数 #score是full_scores是精简版,full_scores会返回: (prob, ngram length, oov) 包括:概率,ngram长度,是否为oov # Show scores and n-gram matches sentence = '盘点不怕被税的海淘网站❗️海淘向来便宜又保真,比旗舰店、专柜和代购好太多!' words = ['<s>'] + parse_text(sentence).split() + ['</s>'] print(words) for i, (prob, length, oov) in enumerate(model.full_scores(sentence)): print('{0} {1}: {2}'.format('prob: ', prob, ' length : ', length, ' '.join(words[i + 2 - length:i + 2]))) if oov: print('\t"{0}" is an OOV'.format(words[i + 1])) # Find out-of-vocabulary words for w in words: if not w in model: print('"{0}" is an OOV'.format(w)) #3.3 kenlm.State()状态转移概率 ''' 状态的累加
def gift_packet_handler(data, player_data): r = bytearray(b"\x02" + bytes(util.parse_text("Star For Effort")) + bytes(util.parse_text("Shadowek"))) print(r) return r