Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add __getitem__ method to Sparse2Corpus to allow direct queries #1621

Merged
merged 3 commits into from
Oct 13, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions gensim/matutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,11 @@ def __iter__(self):
def __len__(self):
return self.sparse.shape[1]

def __getitem__(self, item):
Copy link
Owner

@piskvorky piskvorky Oct 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is item? Row index, column index, something else?

Missing docstring (method semantics, args, returns).

indprev = self.sparse.indptr[item]
indnow = self.sparse.indptr[item+1]
return list(zip(self.sparse.indices[indprev:indnow], self.sparse.data[indprev:indnow]))


def veclen(vec):
if len(vec) == 0:
Expand Down