Skip to content

Commit

Permalink
minor code style changes
Browse files Browse the repository at this point in the history
  • Loading branch information
piskvorky committed Aug 11, 2012
1 parent be64a0f commit a9334e7
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions gensim/corpora/hashdictionary.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2010 Radim Rehurek <radimrehurek@seznam.cz>
# Copyright (C) 2012 Homer Strong, Radim Rehurek
# Licensed under the GNU LGPL v2.1 - http://www.gnu.org/licenses/lgpl.html


Expand All @@ -13,8 +13,7 @@

from __future__ import with_statement

import codecs # for unicode output
import zlib
import codecs
import logging
import itertools
import UserDict
Expand Down Expand Up @@ -66,7 +65,7 @@ def __getitem__(self, key):
self.reverse[h] = key
if self.debug:
if self.debug_reverse.get(h, None):
self.debug_reverse[h] = self.debug_reverse[h].add(key)
self.debug_reverse[h] = self.debug_reverse[h].add(key)
else:
self.debug_reverse[h] = set([key])
return h
Expand All @@ -75,7 +74,7 @@ def itervalues(self):
return self.reverse.keys()

def iteritems(self):
return dict((v,k) for k, v in self.reverse.iteritems())
return dict((v, k) for k, v in self.reverse.iteritems())

def values(self):
return self.reverse.keys()
Expand All @@ -84,7 +83,7 @@ def keys(self):
return self.reverse.values()

def subset(self, key_subset):
self.reverse = dict((k,v) for k, v in self.reverse.iteritems() if k in key_subset)
self.reverse = dict((k, v) for k, v in self.reverse.iteritems() if k in key_subset)

def restricted_hash(self, key):
"""Calculates the hash mod the range"""
Expand Down Expand Up @@ -239,7 +238,7 @@ def save_as_text(self, fname):
Note: use `save`/`load` to store in binary format instead (pickle).
"""
logger.info("saving hashdictionary mapping to %s" % fname)
with codecs.open(fname, 'wb',encoding='utf-8') as fout:
with codecs.open(fname, 'wb', encoding='utf-8') as fout:
for token, tokenid in sorted(self.token2id.iteritems()):
fout.write("%i\t%s\t%i\n" % (tokenid, token, self.dfs.get(tokenid, 0)))

Expand Down

0 comments on commit a9334e7

Please sign in to comment.