Skip to content

Commit

Permalink
corpus reader works with loader
Browse files Browse the repository at this point in the history
  • Loading branch information
bbengfort committed Aug 17, 2016
1 parent 4fce5b4 commit 61fca20
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions corpus/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,18 @@ def categories(self, fileids=None):
"""
# If fileids is None, return all categories
# HACK: use a unique query on the database
return list(set([
doc.label(self.user) for doc in self.query
]))
if fileids is None:
return list(set([
str(doc.label(self.user)) for doc in self.query
]))

# Convert to a list if a singleton is passed
if isinstance(fileids, int):
fileids = [fileids,]

return list(set([
doc.label(self.user) for doc in self.query.filter(id__in=fileids)
str(doc.label(self.user))
for doc in self.query.filter(id__in=fileids)
]))

def tagged(self, fileids=None, categories=None):
Expand All @@ -126,7 +128,9 @@ def tagged(self, fileids=None, categories=None):
if isinstance(fileids, int):
fileids = [fileids,]

return self.query.filter(id__in=fileids).values_list('content', flat=True)
for doc in self.query.filter(id__in=fileids).values_list('content', flat=True):
for para in doc:
yield para


##########################################################################
Expand Down

0 comments on commit 61fca20

Please sign in to comment.