Skip to content

Commit

Permalink
refactor code to avoid flake8 warning
Browse files Browse the repository at this point in the history
  • Loading branch information
osma committed Nov 22, 2024
1 parent 35b8955 commit 66f577d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
12 changes: 9 additions & 3 deletions annif/analyzer/estnltk.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@

from __future__ import annotations

import importlib

from . import analyzer


class EstNLTKAnalyzer(analyzer.Analyzer):
name = "estnltk"

@staticmethod
def is_available() -> bool:
# return True iff EstNLTK is installed
return importlib.util.find_spec("estnltk") is not None

def __init__(self, param: str, **kwargs) -> None:
self.param = param
super().__init__(**kwargs)

Check warning on line 20 in annif/analyzer/estnltk.py

View check run for this annotation

Codecov / codecov/patch

annif/analyzer/estnltk.py#L19-L20

Added lines #L19 - L20 were not covered by tests
Expand All @@ -17,9 +24,8 @@ def tokenize_words(self, text: str, filter: bool = True) -> list[str]:

txt = estnltk.Text(text.strip())
txt.tag_layer()
lemmas = [
return [

Check warning on line 27 in annif/analyzer/estnltk.py

View check run for this annotation

Codecov / codecov/patch

annif/analyzer/estnltk.py#L25-L27

Added lines #L25 - L27 were not covered by tests
lemma
for lemma in [l[0] for l in txt.lemma]
for lemma in [lemmas[0] for lemmas in txt.lemma]
if (not filter or self.is_valid_token(lemma))
]
return lemmas
6 changes: 5 additions & 1 deletion tests/test_analyzer_estnltk.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
import pytest

import annif.analyzer
import annif.analyzer.estnltk

estnltk = pytest.importorskip("estnltk")
pytestmark = pytest.mark.skipif(
not annif.analyzer.estnltk.EstNLTKAnalyzer.is_available(),
reason="EstNLTK is required",
)


def test_estnltk_tokenize_words():
Expand Down

0 comments on commit 66f577d

Please sign in to comment.