(doc)
| 31 | num_docs = [0] |
| 32 | |
| 33 | def update_sample(doc): |
| 34 | if len(sample) < args.k: |
| 35 | sample.append(doc.copy()) |
| 36 | else: |
| 37 | i = num_docs[0] |
| 38 | j = random.randrange(i + 1) |
| 39 | if j < args.k: |
| 40 | remainder.append(sample[j]) |
| 41 | sample[j] = doc.copy() |
| 42 | else: |
| 43 | remainder.append(doc.copy()) |
| 44 | num_docs[0] += 1 |
| 45 | doc.clear() |
| 46 | |
| 47 | with open(args.input, "r", encoding="utf-8") as h: |
| 48 | doc = [] |