human
I am working on the file "Gensim - Corpora and Vector.ipynb".
The first task is:
Corpus Streaming
在上面的作法中，整個corpus都放在記憶體裡。如果corpus太大，一種可行的作法是一次讀一部分，這時可以自定義corpus class
Can you write Python program for it?
assistant
#Here is the Python program you requested.

class MyCorpus(object):
    def __iter__(self):
        for line in open('mycorpus.txt'):
            # 假設每一行代表一個document，而且tokens以空白字元分隔
            yield dict.doc2bow(line.lower().split())
            # 這裡用yield會變成一個generator，因此可以將物件放在for裡面
            # 例如 for line in myCorpus:

myCorpus = MyCorpus()
myCorpus

for vec in myCorpus:
    print vec