Skip to content

Commit

Permalink
Merge pull request #375 from robertcv/fixes/viewer_highlight
Browse files Browse the repository at this point in the history
[FIX] OWCorpusViewer: fix search highlighting
  • Loading branch information
ajdapretnar authored Sep 12, 2018
2 parents 400859d + db6b27a commit 0d05ae3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
4 changes: 2 additions & 2 deletions orangecontrib/text/widgets/owcorpusviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,13 @@ def show_docs(self):
row_ind = index.data(Qt.UserRole).row_index
for ind in self.display_indices:
feature = self.display_features[ind]
mark = 'class="mark-area"' if feature in marked_search_features else ''
mark = ' mark-area' if feature in marked_search_features else ''
value = str(index.data(Qt.UserRole)[feature.name]).replace('\n', '<br/>')
is_image = feature.attributes.get('type', '') == 'image'
if is_image and value != '?':
value = '<img src="{}"></img>'.format(value)
html += '<tr><td class="variables"><strong>{}:</strong></td>' \
'<td class="content" {}>{}</td></tr>'.format(
'<td class="content{}">{}</td></tr>'.format(
feature.name, mark, value)

if self.show_tokens:
Expand Down
39 changes: 39 additions & 0 deletions orangecontrib/text/widgets/tests/test_owcorpusviewer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import unittest
from AnyQt.QtTest import QSignalSpy
from Orange.widgets.tests.base import WidgetTest

from orangecontrib.text.corpus import Corpus
from orangecontrib.text.widgets.owcorpusviewer import OWCorpusViewer


class TestCorpusViewerWidget(WidgetTest):
def setUp(self):
self.widget = self.create_widget(OWCorpusViewer)
self.corpus = Corpus.from_file('deerwester')

def test_data(self):
self.send_signal(self.widget.Inputs.corpus, self.corpus)
self.assertEqual(self.widget.n_documents, 9)
out_corpus = self.get_output(self.widget.Outputs.matching_docs)
self.assertEqual(out_corpus, self.corpus)

def test_search(self):
self.send_signal(self.widget.Inputs.corpus, self.corpus)
self.widget.regexp_filter = "graph"
self.process_events()
out_corpus = self.get_output(self.widget.Outputs.matching_docs)
self.assertEqual(len(out_corpus), 4)

def test_highlighting(self):
self.send_signal(self.widget.Inputs.corpus, self.corpus)
self.widget.regexp_filter = "graph"
self.process_events()
self.widget.doc_webview.html()
spy = QSignalSpy(self.widget.doc_webview.loadFinished)
spy.wait()
html = self.widget.doc_webview.html()
self.assertIn('<mark data-markjs="true">', html)


if __name__ == "__main__":
unittest.main()

0 comments on commit 0d05ae3

Please sign in to comment.