This code seemed to work (though I was surprised my generator needed to parse the string into words vs using LineSentence data which seems to operate on a sentence as a single string input).
Gordon, I looked at some of your other messages related to this topic and tried to incorporate them into this short code. Does anything look like it could fail in some obvious usage?
class Sentences(list):
def __init__(self,cursor,SQL,params):
self.cursor=cursor
self.SQL=SQL
self.params=params
def __iter__(self):
self.cursor.execute(self.SQL,self.params)
return self.MyGenerator()
def MyGenerator(self):
row=self.cursor.fetchone()
while row is not None:
yield row[0].lower().split()
row=self.cursor.fetchone()
import pyodbc
DB = pyodbc.connect(r'Driver={SQL Server};Server=(local);Database=Corpora;Trusted_Connection=yes;',autocommit=True)
DB_Link=DB.cursor()
params=(42)
SQL='Select Sentence From Sentence Where Corpus_Id=? Order By Sentence_Number'
myiterable=Sentences(DB_Link,SQL,params)
model = gensim.models.Word2Vec(sentences=myiterable, vector_size=300, sg=1, window=10, min_count=5, workers=4, epochs=10)
db.close()