fix textrank divided by zero; fix posseg.pair.__repr__

This commit is contained in:
Dingyuan Wang 2014-12-20 00:12:42 +08:00
parent 8be082017a
commit 7bcb128f5f
2 changed files with 2 additions and 2 deletions

View File

@ -21,7 +21,7 @@ class UndirectWeightedGraph:
ws = collections.defaultdict(float) ws = collections.defaultdict(float)
outSum = collections.defaultdict(float) outSum = collections.defaultdict(float)
wsdef = 1.0 / len(self.graph) wsdef = 1.0 / (len(self.graph) or 1.0)
for n, out in self.graph.items(): for n, out in self.graph.items():
ws[n] = wsdef ws[n] = wsdef
outSum[n] = sum((e[2] for e in out), 0.0) outSum[n] = sum((e[2] for e in out), 0.0)

View File

@ -81,7 +81,7 @@ class pair(object):
return self.__str__() return self.__str__()
def __str__(self): def __str__(self):
return self.__unicode__().encode(default_encoding) return self.__unicode__()
def encode(self,arg): def encode(self,arg):
return self.__unicode__().encode(arg) return self.__unicode__().encode(arg)