async def windback(network, shard, header, availability_cache): assert WINDBACK_LENGTH > 0 def add_parent_header(headers): parent_header = shard.headers_by_hash[headers[-1].parent_hash] return headers + [parent_header] header_chain = iterate(add_parent_header, [header]) n_parents = min(WINDBACK_LENGTH - 1, header.number) headers_to_check = reversed(nth(n_parents, header_chain)) # from root to leaf availabilities = {} # {hash: available, ...} for all headers checked here for header in headers_to_check: if header.hash in availabilities: available = availability_cache[header.hash] else: available = check_availability(header) availabilities[header.hash] = available if not available: # don't check children of unavailable collations break # remaining collations are unavailable as one of their ancestors is unavailable for header in headers_to_check: availabilities[header.hash] = False return availabilities
def get(ind, coll, lazy=False): """ >>> get(0, 'Hello') 'H' >>> get([1, 0], 'Hello') ('e', 'H') >>> get(slice(1, 4), 'Hello') ('e', 'l', 'l') >>> get(slice(1, 4), 'Hello', lazy=True) <itertools.islice object at ...> """ if isinstance(ind, list): result = nth_list(ind, coll) elif isinstance(ind, slice): result = islice(coll, ind.start, ind.stop, ind.step) else: if isinstance(coll, Iterator): result = nth(ind, coll) else: result = coll[ind] if not lazy and isinstance(result, Iterator): result = tuple(result) return result
def compute_up(expr, seq, **kwargs): index = expr.index if isinstance(index, tuple) and len(index) == 1: index = index[0] if isinstance(index, _inttypes): return nth(index, seq) if isinstance(index, slice): return itertools.islice(seq, index.start, index.stop, index.step) raise NotImplementedError("Only 1d slices supported")
def compute_up(expr, seq, **kwargs): index = expr.index if isinstance(index, tuple) and len(index) == 1: index = index[0] if isinstance(index, _inttypes): try: return seq[index] except: if index >= 0: return nth(index, seq) else: return tail(-index, seq)[0] if isinstance(index, slice): if index.start and index.start < 0 and index.stop is None and index.step in (1, None): return tail(-index.start, seq) else: return itertools.islice(seq, index.start, index.stop, index.step) raise NotImplementedError("Only 1d slices supported")
def compute_up(expr, seq, **kwargs): index = expr.index if isinstance(index, tuple) and len(index) == 1: index = index[0] if isinstance(index, _inttypes): try: return seq[index] except: if index >= 0: return nth(index, seq) else: return tail(-index, seq)[0] if isinstance(index, slice): if (index.start and index.start < 0 and index.stop is None and index.step in (1, None)): return tail(-index.start, seq) else: return itertools.islice(seq, index.start, index.stop, index.step) raise NotImplementedError("Only 1d slices supported")
def make_pathes_list(line_index): neko = parse() pathes = [[chunk for chunk in chunk_list if len(chunk_list) > 1] for chunk_list in noun_to_root(nth(line_index, neko))] return pathes
def main(): make_tree(nth(3, parse()))
def main(): for sent in nth(7, Chunk.make_chunk_object_list()): print('係り先 {:2d}\t係り元 {}\t{}'.format(sent.dst, sent.srcs, sent))
def nth(self, n): return cytoolz.nth(n, self)
def main(): neko = parse() for morph in nth(3, neko): print(morph)
def main(): neko = parse() for chunk in nth(7, neko): print(chunk.details())
def main(): for sent in nth(3, Morph.make_sent_morph_list()): print(sent)