Skip to content

Commit

Permalink
Pos - remove unsupported and unused StanfordPOSTagger
Browse files Browse the repository at this point in the history
  • Loading branch information
PrimozGodec committed Nov 6, 2023
1 parent 3ebeaea commit ecde9ab
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 48 deletions.
38 changes: 1 addition & 37 deletions orangecontrib/text/tag/pos.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import nltk
import numpy as np

from Orange.util import wrap_callback, dummy_callback

from orangecontrib.text import Corpus
Expand All @@ -11,7 +10,7 @@
from orangecontrib.text.util import chunkable


__all__ = ['POSTagger', 'StanfordPOSTagger', 'AveragedPerceptronTagger', 'MaxEntTagger']
__all__ = ["POSTagger", "AveragedPerceptronTagger", "MaxEntTagger"]


class POSTagger(TokenizedPreprocessor):
Expand All @@ -38,41 +37,6 @@ def _preprocess(self, tokens: List[List[str]]) -> List[List[str]]:
self.tagger(tokens)))


class StanfordPOSTaggerError(Exception):
pass


class StanfordPOSTagger(nltk.StanfordPOSTagger, POSTagger):
name = 'Stanford POS Tagger'

@classmethod
def check(cls, path_to_model, path_to_jar):
""" Checks whether provided `path_to_model` and `path_to_jar` are valid.
Raises:
ValueError: in case at least one of the paths is invalid.
Notes:
Can raise an exception if Java Development Kit is not installed or not properly configured.
Examples:
>>> try:
... StanfordPOSTagger.check('path/to/model', 'path/to/stanford.jar')
... except ValueError as e:
... print(e)
Could not find stanford-postagger.jar jar file at path/to/stanford.jar
"""
try:
cls(path_to_model, path_to_jar).tag(())
except OSError as e:
raise StanfordPOSTaggerError(
'Either Java SDK not installed or some of the '
'files are invalid.\n' + str(e))
except LookupError as e:
raise StanfordPOSTaggerError(str(e).strip(' =\n'))


class AveragedPerceptronTagger(POSTagger):
name = 'Averaged Perceptron Tagger'

Expand Down
11 changes: 0 additions & 11 deletions orangecontrib/text/tests/test_tags.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import pickle
import copy
import tempfile
import unittest

from orangecontrib.text import tag
from orangecontrib.text.corpus import Corpus
from orangecontrib.text.tag.pos import StanfordPOSTaggerError


class POSTaggerTests(unittest.TestCase):
Expand All @@ -19,15 +17,6 @@ def test_POSTagger(self):
for tokens, tags in zip(result.tokens, result.pos_tags):
self.assertEqual(len(tokens), len(tags))

def test_Stanford_check(self):
model = tempfile.NamedTemporaryFile()
resource = tempfile.NamedTemporaryFile()
with self.assertRaises(StanfordPOSTaggerError):
tag.StanfordPOSTagger.check(model.name, resource.name)

with self.assertRaises(StanfordPOSTaggerError):
tag.StanfordPOSTagger.check('model', resource.name)

def test_str(self):
self.assertEqual('Averaged Perceptron Tagger', str(self.tagger))

Expand Down

0 comments on commit ecde9ab

Please sign in to comment.