Repository: biolab/orange3-text

Issue:
Concordance: slow on large corpora
<!--
This is an issue template. Please fill in the relevant details in the
sections below.
-->

##### Text version
<!-- From menu _Options→Add-ons→Orange3-Text_ or code `orangecontrib.text.version.full_version` -->
0.9.0

##### Orange version
<!-- From menu _Help→About→Version_ or code `Orange.version.full_version` -->
3.26.0.dev

##### Expected behavior
Concordance doesn't block Orange.


##### Actual behavior
Concordance on large corpora (say friends-transcripts) blocks entire Orange and makes it useless for eternity.


##### Steps to reproduce the behavior
Corpus (friends-transcripts) - Concordance (search for a term).


##### Additional info (worksheets, data, screenshots, ...)
Probably Concordance search should be reimplemented in some smart way. And written in treads at least, so the user can kill it and continue with the analysis.




Discussion:

Resolving patch:
diff --git a/orangecontrib/text/corpus.py b/orangecontrib/text/corpus.py
--- a/orangecontrib/text/corpus.py
+++ b/orangecontrib/text/corpus.py
@@ -265,7 +265,7 @@ def documents(self):
     def titles(self):
         """ Returns a list of titles. """
         assert self._titles is not None
-        return self._titles.tolist()
+        return self._titles
 
     def documents_from_features(self, feats):
         """
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
@@ -192,7 +192,7 @@ def is_match(x):
                                                       self.corpus_docs)):
             if is_match(content):
                 item = QStandardItem()
-                item.setData(title, Qt.DisplayRole)
+                item.setData(str(title), Qt.DisplayRole)
                 item.setData(doc, Qt.UserRole)
                 self.doc_list_model.appendRow(item)
                 self.output_mask.append(i)


Test patch:
diff --git a/orangecontrib/text/tests/test_corpus.py b/orangecontrib/text/tests/test_corpus.py
--- a/orangecontrib/text/tests/test_corpus.py
+++ b/orangecontrib/text/tests/test_corpus.py
@@ -3,6 +3,7 @@
 from distutils.version import LooseVersion
 
 import numpy as np
+from numpy.testing import assert_array_equal
 from scipy.sparse import csr_matrix, issparse
 
 import Orange
@@ -432,13 +433,13 @@ def test_set_title_from_domain(self):
         corpus = Corpus.from_numpy(
             domain, X=np.empty((2, 0)), metas=np.array(metas)
         )
-        self.assertListEqual(["Document 1", "Document 2"], corpus.titles)
+        assert_array_equal(["Document 1", "Document 2"], corpus.titles)
 
         domain["title"].attributes["title"] = True
         corpus = Corpus.from_numpy(
             domain, X=np.empty((2, 0)), metas=np.array(metas)
         )
-        self.assertListEqual(["title1", "title2"], corpus.titles)
+        assert_array_equal(["title1", "title2"], corpus.titles)
 
     def test_titles_from_rows(self):
         domain = Domain([],
@@ -449,7 +450,7 @@ def test_titles_from_rows(self):
             domain, X=np.empty((3, 0)), metas=np.array(metas)
         )
         corpus = Corpus.from_table_rows(corpus, [0, 2])
-        self.assertListEqual(["Document 1", "Document 3"], corpus.titles)
+        assert_array_equal(["Document 1", "Document 3"], corpus.titles)
 
     def test_titles_from_list(self):
         domain = Domain(
@@ -457,12 +458,12 @@ def test_titles_from_list(self):
         )
         corpus = Corpus.from_list(
             domain, [["title1", "a"], ["title2", "b"]])
-        self.assertListEqual(["Document 1", "Document 2"], corpus.titles)
+        assert_array_equal(["Document 1", "Document 2"], corpus.titles)
 
         domain["title"].attributes["title"] = True
         corpus = Corpus.from_list(
             domain, [["title1", "a"], ["title2", "b"]])
-        self.assertListEqual(["title1", "title2"], corpus.titles)
+        assert_array_equal(["title1", "title2"], corpus.titles)
 
 
 if __name__ == "__main__":