Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] OWCorpusViewer: fix search highlighting #375

Merged
merged 2 commits into from
Sep 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions orangecontrib/text/widgets/owcorpusviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,13 +322,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()