Skip to content

Commit

Permalink
Merge pull request #924 from PrimozGodec/langdedect-create-corpus
Browse files Browse the repository at this point in the history
[ENH] Create Corpus - add language to corpus
  • Loading branch information
VesnaT authored Jan 11, 2023
2 parents 25952ea + 83e0446 commit 971969e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
17 changes: 16 additions & 1 deletion orangecontrib/text/widgets/owcreatecorpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from orangewidget.settings import Setting

from orangecontrib.text import Corpus
from orangecontrib.text.language import LANG2ISO, DEFAULT_LANGUAGE, LanguageModel


class EditorsVerticalScrollArea(gui.VerticalScrollArea):
Expand Down Expand Up @@ -76,13 +77,26 @@ class Outputs:

want_main_area = False

language: str = Setting(DEFAULT_LANGUAGE)
texts: List[Tuple[str, str]] = Setting([("", "")] * 3)
auto_commit: bool = Setting(True)

def __init__(self):
super().__init__()
self.editors = []

gui.comboBox(
self.controlArea,
self,
"language",
model=LanguageModel(),
box="Language",
orientation=Qt.Horizontal,
callback=self.commit.deferred,
sendSelectedValue=True,
searchable=True,
)

scroll_area = EditorsVerticalScrollArea()
self.editor_vbox = gui.vBox(self.controlArea, spacing=0)
self.editor_vbox.layout().setSpacing(10)
Expand Down Expand Up @@ -142,12 +156,13 @@ def commit(self):
np.empty((len(self.texts), 0)),
metas=np.array(self.texts),
text_features=[doc_var],
language=LANG2ISO[self.language],
)
corpus.set_title_variable(title_var)
self.Outputs.corpus.send(corpus)

def sizeHint(self) -> QSize:
return QSize(600, 600)
return QSize(600, 650)


if __name__ == "__main__":
Expand Down
12 changes: 11 additions & 1 deletion orangecontrib/text/widgets/tests/test_owcreatecorpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import numpy as np
from Orange.data import StringVariable
from Orange.widgets.tests.base import WidgetTest
from AnyQt.QtWidgets import QPushButton
from AnyQt.QtWidgets import QPushButton, QComboBox
from orangewidget.tests.utils import simulate

from orangecontrib.text.widgets.owcreatecorpus import OWCreateCorpus

Expand Down Expand Up @@ -197,6 +198,15 @@ def test_output(self):
self.assertListEqual(["Test 3"], corpus.documents)
np.testing.assert_array_equal([["Document 3", "Test 3"]], corpus.metas)

def test_language(self):
corpus = self.get_output(self.widget.Outputs.corpus)
self.assertEqual("en", corpus.language)

combo = self.widget.controlArea.findChild(QComboBox)
simulate.combobox_activate_index(combo, 2)
corpus = self.get_output(self.widget.Outputs.corpus)
self.assertEqual("am", corpus.language)


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

0 comments on commit 971969e

Please sign in to comment.