How to use running_count method in lisa

Best Python code snippet using lisa_python

encode_string.py

Source:encode_string.py Github

copy

Full Screen

1import re2import string3import unicodedata4from pathlib import Path5from collections import Counter6from articlenizer import sentenize7def handle_unicode_characters(s):8 """Handle unicode characters appearing in string. Some do actually contain valuable information for NLP applications. But there is also a lot of "unnecessary" unicode in scientific texts (at least from an Software-NER perspective). It can either be dropped, or different codes can be summarized by one characters. 9 Args:10 s (string): string to transform11 Returns:12 string: unicode 'normalized' string13 """14 dropped_char_indices = []15 running_count = 016 out_s = ''17 for char in s:18 if re.match(r"[A-Za-z0-9\s]", char) is not None or char in string.punctuation:19 # keep "normal" chars20 out_s += char21 running_count += 122 else:23 # here we will deal with unicode24 if char in ['©', '™', '®']:25 # 'TradeMarks' are tricky but often used to indicate external equipment in studies26 out_s += '™'27 running_count += 128 continue29 if char == '°':30 # Temperatures are almost always indicated by °31 out_s += char32 running_count += 133 continue34 # some unicodes are combined and based on 'normal' characters -> we want to keep the base characters, e.g. á -> a35 unicode_matched = False36 #char_37 u_map = unicodedata.decomposition(char)38 if u_map and len(u_map) > 1:39 split_codes = [code for code in u_map.split() if not re.match(r'<.*>', code)]40 for code in split_codes:41 code_char = chr(int(code, 16))42 if re.match(r'[a-zA-Z]', code_char):43 out_s += code_char # TODO44 unicode_matched = True45 running_count += 146 break47 if unicode_matched: 48 continue49 # normalized unicode for everything else just to be save.. 50 char = unicodedata.normalize('NFC', char)51 if len(char) > 1:52 print(RuntimeWarning("Unkown unicode character with length > 1: {} -- ignored".format(char)))53 continue54 # we want to keep basic greek letters no matter what55 if char == 'µ': # yes, they are actually different: this is the 'micro sign'56 char = 'μ' # this the greek letter..57 if ( ord(char) >= 945 and ord(char) <= 970 ) or ( ord(char) >= 913 and ord(char) <= 938 ):58 out_s += char59 running_count += 160 continue61 # the rest is based on unicode categories some of which are considered important and others are not62 category = unicodedata.category(char)63 if category == 'Pi':64 if ord(char) == 8216 or ord(char) == 8219:65 out_s += char66 else:67 out_s += '“'68 running_count += 169 elif category == 'Pf':70 if ord(char) == 8217:71 out_s += '’'72 else:73 out_s += '”'74 running_count += 175 elif category == 'Pd':76 char = '-'77 out_s += char78 running_count += 179 elif category == 'Sc':80 out_s += char81 running_count += 182 elif category in ['Pe', 'Cf', 'Ps', 'So', 'Sk', 'No']:83 dropped_char_indices.append([running_count, char])84 running_count += 185 elif category == 'Lm':86 if ord(char) >= 697 and ord(char) <= 719:87 char ="'"88 running_count += 189 out_s += char90 elif category in ['Lu', 'Ll', 'Po']:91 # keep92 out_s += char93 running_count += 194 elif category == 'Sm':95 # Mathsymbols, TODO: handle them better?96 out_s += char97 running_count += 198 unicode_in_sent = True99 else:100 #print("Encountered an unhandled unicode character: {} - DROPPED".format(char))101 dropped_char_indices.append([running_count, char])102 running_count += 1103 ...

Full Screen

Full Screen

counting.py

Source:counting.py Github

copy

Full Screen

1from kairotic.elements import DECK_SIZE, SUITS, CARD_VALUES2class Count:3 def __init__(self):4 self.cards_seen = 05 self._n_decks = None6 @property7 def n_decks(self):8 if self._n_decks is None:9 raise UnboundLocalError("Count not attached to a Shoe")10 else:11 return self._n_decks12 def reset(self):13 self.cards_seen = 014 def update(self, card):15 self.cards_seen += 116 @property17 def half_decks_seen(self):18 return round(self.cards_seen / (DECK_SIZE / 2))19 @property20 def decks_rem(self):21 return max(self.n_decks - self.half_decks_seen / 2, .5)22class ScalarCount(Count):23 def __init__(self):24 super().__init__()25 self.running_count = 026 def reset(self):27 super().reset()28 self.running_count = 029 @property30 def true_count(self):31 return round(self.running_count / self.decks_rem)32class HiLo(ScalarCount):33 name = 'HiLo'34 def update(self, card):35 super().update(card)36 if card.value in ['2', '3', '4', '5', '6']:37 self.running_count += 138 elif card.value in ['10', 'J', 'Q', 'K', 'A']:39 self.running_count -= 140class VectorCount(Count):41 def __init__(self):42 super().__init__()43 self.running_count = dict()44 def reset(self):45 self.running_count = {key: 0 for key in self.running_count}46 @property47 def true_count(self):48 return {key: round(count / self.decks_rem) for key, count in self.running_count.items()}49class PerfectValueCount(VectorCount):50 name = 'Perfect Value Count'51 def __init__(self):52 super().__init__()53 self.running_count = {v: 0 for v in CARD_VALUES}54 def update(self, card):55 super().update(card)...

Full Screen

Full Screen

reducer_stat.py

Source:reducer_stat.py Github

copy

Full Screen

1#!/usr/bin/python32import sys3def update_mean(running_mean, running_count, batch_mean, batch_count):4 batch_mean = (running_mean * running_count + batch_mean * batch_count) / (running_count + batch_count)5 batch_count = running_count + batch_count6 return batch_mean, batch_count7def update_var(running_mean, running_var, running_count, batch_mean, batch_var, batch_count):8 var = (running_var * running_count + batch_var * batch_count) / (running_count + batch_count)9 var += running_count * ((running_mean - batch_mean) / (running_count + batch_count)) ** 210 return var11if __name__ == '__main__':12 global_mean = 013 global_count = 014 global_var = 015 for i, raw_line in enumerate(sys.stdin):16 line = raw_line.strip()17 loc_mean, loc_var, loc_count = list(map(float, line.split('\t')))18 new_mean, new_count = update_mean(global_mean, global_count, loc_mean, loc_count)19 global_var = update_var(global_mean, global_var, global_count, loc_mean, loc_var, loc_count)20 global_mean, global_count = new_mean, new_count21 print('map_reduce mean: {}'.format(global_mean))...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lisa automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful