Repository: biolab/orange3-text

Issue:
Corpus Viewer Index Error
**Describe the bug**
```
Traceback (most recent call last):
  File "/Users/ajda/orange/orange-canvas-core/orangecanvas/scheme/signalmanager.py", line 936, in __process_next
    if self.__process_next_helper(use_max_active=True):
  File "/Users/ajda/orange/orange-canvas-core/orangecanvas/scheme/signalmanager.py", line 974, in __process_next_helper
    self.process_node(selected_node)
  File "/Users/ajda/orange/orange-canvas-core/orangecanvas/scheme/signalmanager.py", line 605, in process_node
    self.send_to_node(node, signals_in)
  File "/Users/ajda/orange/orange-widget-base/orangewidget/workflow/widgetsscheme.py", line 792, in send_to_node
    self.process_signals_for_widget(node, widget, signals)
  File "/Users/ajda/orange/orange-widget-base/orangewidget/workflow/widgetsscheme.py", line 826, in process_signals_for_widget
    handler(*args)
  File "/Users/ajda/orange/orange3-text/orangecontrib/text/widgets/owcorpusviewer.py", line 143, in set_data
    self.selected_documents = [corpus.titles[0]]
IndexError: index 0 is out of bounds for axis 0 with size 0
```

**To Reproduce**
No idea how. Thought it was related to clicking outside the words in word cloud. Apparently not. I had Corpus + Bag of Words, BoW weights in Word Cloud, selected a word in WC and output it to Corpus Viewer.

**Expected behavior**
No bug, obv.

I am putting this here to remember to reproduce it on Monday. If I won't be able to, I'll close.



Discussion:
I have managed to reproduce this.
Corpus (book-excerpts) - Word Cloud - Corpus Viewer

Resolving patch:
diff --git a/orangecontrib/text/widgets/owcorpusviewer.py b/orangecontrib/text/widgets/owcorpusviewer.py
--- a/orangecontrib/text/widgets/owcorpusviewer.py
+++ b/orangecontrib/text/widgets/owcorpusviewer.py
@@ -140,7 +140,8 @@ def set_data(self, corpus=None):
             self.display_features = list(filter_visible(chain(domain.variables, domain.metas)))
             self.search_indices = list(range(len(self.search_features)))
             self.display_indices = list(range(len(self.display_features)))
-            self.selected_documents = [corpus.titles[0]]
+            self.selected_documents = [corpus.titles[0]] if \
+                corpus.titles is not None and len(corpus.titles) else []
             self.openContext(self.corpus)
             self.display_list_indices = self.display_indices
             self.regenerate_docs()


Test patch:
diff --git a/orangecontrib/text/widgets/tests/test_owcorpusviewer.py b/orangecontrib/text/widgets/tests/test_owcorpusviewer.py
--- a/orangecontrib/text/widgets/tests/test_owcorpusviewer.py
+++ b/orangecontrib/text/widgets/tests/test_owcorpusviewer.py
@@ -110,6 +110,11 @@ def test_output(self):
         self.assertIsNone(self.get_output(self.widget.Outputs.matching_docs))
         self.assertIsNone(self.get_output(self.widget.Outputs.other_docs))
 
+    def test_empty_corpus(self):
+        self.send_signal(self.widget.Inputs.corpus, self.corpus[:0])
+        self.assertListEqual(self.widget.selected_documents, [])
+        self.assertEqual(self.widget.doc_list.model().rowCount(), 0)
+
     def test_report(self):
         self.widget.send_report()