-
Notifications
You must be signed in to change notification settings - Fork 11
/
queryresult.py
35 lines (24 loc) · 953 Bytes
/
queryresult.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import queryable
class queryresult(queryable.queryable):
def __init__(self, source, results, resultiter=None):
self.source = source
self.results = results
self.resultiter = results if resultiter is None else resultiter
def __iter__(self):
for result in self.resultiter:
yield result
def __getitem__(self, item):
return self.results[item]
def __len__(self):
return sum(1 for i in self)
def itokens(self, range=None):
count = 0
for result in self.resultiter:
for token in result:
if range is not None and range <= count: break
yield token
count += 1
def each(self, *args, **kwargs):
kwargs['output'] = kwargs.get('output', tokenlist.tokenlist)
return queryable.queryable.each(self, *args, **kwargs)
import tokenlist