From fea3aec6bd0ef0ff9290c07657099c8eb305657d Mon Sep 17 00:00:00 2001 From: Lin Date: Fri, 5 Dec 2014 17:13:12 +0800 Subject: [PATCH] Fix divided by zero issue in case of words are not found in dict. --- jieba/analyse/textrank.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jieba/analyse/textrank.py b/jieba/analyse/textrank.py index 739c60e..ad91fa0 100644 --- a/jieba/analyse/textrank.py +++ b/jieba/analyse/textrank.py @@ -21,7 +21,7 @@ class UndirectWeightedGraph: ws = 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(): ws[n] = wsdef outSum[n] = sum((e[2] for e in out), 0.0)