Repository: biolab/orange3-text

Issue:
OWPreprocessText: load Stanford tagger
<!--
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.4.0

##### Orange version
<!-- From menu _Help→About→Version_ or code `Orange.version.full_version` -->
3.21.dev

##### Expected behavior
One can load Stanford tagger in the POS tag section of Preprocess Text.


##### Actual behavior
Loading a tagger doesn't seem possible.


##### Steps to reproduce the behavior
Load taggers as described in the documentation.


##### Additional info (worksheets, data, screenshots, ...)
Either fix a bug that prevents loading the taggers or update the documentation to explain better how to load one.




Discussion:

Resolving patch:
diff --git a/orangecontrib/text/widgets/owpreprocess.py b/orangecontrib/text/widgets/owpreprocess.py
--- a/orangecontrib/text/widgets/owpreprocess.py
+++ b/orangecontrib/text/widgets/owpreprocess.py
@@ -546,7 +546,7 @@ def setup_method_layout(self):
         super().setup_method_layout()
         # initialize all methods except StanfordPOSTagger
         # cannot be done in superclass due to StanfordPOSTagger
-        self.methods = [method() for method in self.methods[:self.STANFORD]]
+        self.methods = [method() for method in self.methods[:self.STANFORD]] + [self.methods[self.STANFORD]]
 
         self.stanford = ResourceLoader(widget=self.master, model_format='Stanford model (*.model *.tagger)',
                                        provider_format='Java file (*.jar)',
@@ -567,7 +567,14 @@ def set_stanford_tagger(self, model_path, stanford_path, silent=False):
                 self.update_value()
             except ValueError as e:
                 if not silent:
-                    self.master.Error.stanford(str(e))
+                    self.master.Error.stanford_tagger(str(e))
+
+        # if stanford fails to load data, change saved index to default
+        if self.method_index == self.STANFORD and not valid:
+            self.method_index = 0
+            self.group.button(self.method_index).setChecked(True)
+            self.group.button(self.method_index).setEnabled(True)
+            self.master.Error.stanford_tagger("Changing to Averaged Perceptron Tagger")
 
         self.group.button(self.STANFORD).setChecked(valid)
         self.group.button(self.STANFORD).setEnabled(valid)
diff --git a/orangecontrib/text/widgets/utils/widgets.py b/orangecontrib/text/widgets/utils/widgets.py
--- a/orangecontrib/text/widgets/utils/widgets.py
+++ b/orangecontrib/text/widgets/utils/widgets.py
@@ -531,6 +531,7 @@ class ResourceLoader(QWidget, OWComponent):
     valueChanged = pyqtSignal(str, str)
 
     recent_files = settings.Setting([])
+    recent_provider = settings.Setting([])
     resource_path = settings.Setting('')
 
     def __init__(self, widget, model_format, provider_format,
@@ -539,7 +540,7 @@ def __init__(self, widget, model_format, provider_format,
         OWComponent.__init__(self, widget)
 
         self.model_path = None
-        layout = QHBoxLayout(self, spacing=0)
+        layout = QHBoxLayout(self)
         layout.setContentsMargins(0, 0, 0, 0)
 
         self.model_widget = FileWidget(recent_files=self.recent_files, dialog_title='Load model',
@@ -550,7 +551,7 @@ def __init__(self, widget, model_format, provider_format,
 
         layout.addWidget(self.model_widget)
 
-        self.provider_widget = FileWidget(recent_files=None, dialog_title='Load provider',
+        self.provider_widget = FileWidget(recent_files=self.recent_provider, dialog_title='Load provider',
                                           dialog_format=provider_format, start_dir=None,
                                           on_open=self.load_provider, allow_empty=False,
                                           reload_button=False, browse_label=provider_button_label)


Test patch: