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] OWPreprocess: fix Stanford tagger loading #419

Merged
merged 2 commits into from
Mar 25, 2019
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
2 changes: 1 addition & 1 deletion doc/widgets/preprocesstext.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Outputs
7. **POS Tagger** runs part-of-speech tagging on tokens.
- `Averaged Perceptron Tagger <https://spacy.io/blog/part-of-speech-pos-tagger-in-python>`_ runs POS tagging with Matthew Honnibal's averaged perceptron tagger.
- `Treebank POS Tagger (MaxEnt) <http://web.mit.edu/6.863/www/fall2012/projects/writeups/max-entropy-nltk.pdf>`_ runs POS tagging with a trained Penn Treebank model.
- `Stanford POS Tagger <http://nlp.stanford.edu/software/tagger.shtml#Download>`_ runs a log-linear part-of-speech tagger designed by Toutanova et al. Please download it from the provided website and load it in Orange.
- `Stanford POS Tagger <http://nlp.stanford.edu/software/tagger.shtml#Download>`_ runs a log-linear part-of-speech tagger designed by Toutanova et al. Please download it from the provided website and load it in Orange. You have to load the language-specific model in Model and load *stanford-postagger.jar* in the Tagger section.
8. Produce a report.
9. If *Commit Automatically* is on, changes are communicated automatically. Alternatively press *Commit*.

Expand Down
11 changes: 9 additions & 2 deletions orangecontrib/text/widgets/owpreprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)',
Expand All @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions orangecontrib/text/widgets/utils/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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',
Expand All @@ -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)
Expand Down