Repository: piskvorky/gensim

Issue:
ZeroDivisionError: float division by zero in pagerank_weighted.py
Got ZeroDivisionError: float division by zero in **pagerank_weighted.py**

Input Text: BYAnonymousArabe

Error thrown at:  `summarize(text_to_sum, word_count=50)`

![gensim error](https://cloud.githubusercontent.com/assets/5749350/18311490/44da660a-7522-11e6-8812-7390ebca8ef6.png)

I know word_count is 50 and I'm just giving a word. But ideally it should output that single word instead of throwing an error isn't it?

Please throw some light



Discussion:
@tmylk for changes to be made what should be the expected output should it raise an error saying "not enough text to summarize", or just output the single word as it is(if its length is > 10 i.e. INPUT_MIN_LENGTH)?

Output less than word_count should be allowed 

@tmylk Yes. I agree with you

Fixed in #887 


Resolving patch:
diff --git a/gensim/summarization/summarizer.py b/gensim/summarization/summarizer.py
--- a/gensim/summarization/summarizer.py
+++ b/gensim/summarization/summarizer.py
@@ -193,10 +193,9 @@ def summarize(text, ratio=0.2, word_count=None, split=False):
         logger.warning("Input text is empty.")
         return
 
-    # If only one sentence is present, the function return the input text (Avoids ZeroDivisionError). 
+    # If only one sentence is present, the function raises an error (Avoids ZeroDivisionError). 
     if len(sentences) == 1:
-        logger.warning("Summarization not performed since the document has only one sentence.")
-        return text
+        raise ValueError("input must have more than one sentence")
     
     # Warns if the text is too short.
     if len(sentences) < INPUT_MIN_LENGTH:


Test patch:
diff --git a/gensim/test/test_summarization.py b/gensim/test/test_summarization.py
--- a/gensim/test/test_summarization.py
+++ b/gensim/test/test_summarization.py
@@ -87,7 +87,7 @@ def test_text_summarization_raises_exception_on_short_input_text(self):
         text = "\n".join(text.split('\n')[:8])
 
         self.assertTrue(summarize(text) is not None)
-
+        
     def test_text_summarization_returns_input_on_single_input_sentence(self):
         pre_path = os.path.join(os.path.dirname(__file__), 'test_data')
 
@@ -97,7 +97,7 @@ def test_text_summarization_returns_input_on_single_input_sentence(self):
         # Keeps the first sentence only.
         text = text.split('\n')[0]
 
-        self.assertEqual(summarize(text),text)
+        self.assertRaises(ValueError,summarize,text)
 
     def test_corpus_summarization_raises_exception_on_short_input_text(self):
         pre_path = os.path.join(os.path.dirname(__file__), 'test_data')
diff --git a/gensim/test/test_wikicorpus.py b/gensim/test/test_wikicorpus.py
--- a/gensim/test/test_wikicorpus.py
+++ b/gensim/test/test_wikicorpus.py
@@ -12,17 +12,17 @@
 import os
 import sys
 import types
-
+import logging
 import unittest
 
 from gensim.corpora.wikicorpus import WikiCorpus
 
 
-
 module_path = os.path.dirname(__file__) # needed because sample data files are located in the same folder
 datapath = lambda fname: os.path.join(module_path, 'test_data', fname)
 FILENAME = 'enwiki-latest-pages-articles1.xml-p000000010p000030302-shortened.bz2'
 
+logger = logging.getLogger(__name__)
 
 class TestWikiCorpus(unittest.TestCase):
 
@@ -31,7 +31,7 @@ def setUp(self):
 
 
     def test_get_texts_returns_generator_of_lists(self):
-        
+        logger.debug("Current Python Version is "+str(sys.version_info))
         if sys.version_info < (2, 7, 0):
             return
         wc = WikiCorpus(datapath(FILENAME))