Skip to content

Commit

Permalink
Merge pull request #718 from NatLibFi/fix-missing-limit-default-param…
Browse files Browse the repository at this point in the history
…-in-stwfsa

Fix missing limit parameter in STWFSA backend
  • Loading branch information
juhoinkinen authored Jul 31, 2023
2 parents 320af2b + bf5f844 commit 02233ab
Show file tree
Hide file tree
Showing 9 changed files with 6 additions and 36 deletions.
4 changes: 3 additions & 1 deletion annif/backend/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ def __init__(
self.datadir = project.datadir

def default_params(self) -> dict[str, Any]:
return self.DEFAULT_PARAMETERS
params = AnnifBackend.DEFAULT_PARAMETERS.copy()
params.update(self.DEFAULT_PARAMETERS) # Optional backend specific parameters
return params

@property
def params(self) -> dict[str, Any]:
Expand Down
3 changes: 0 additions & 3 deletions annif/backend/dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ class DummyBackend(backend.AnnifLearningBackend):
is_trained = True
modification_time = None

def default_params(self) -> dict[str, int]:
return backend.AnnifBackend.DEFAULT_PARAMETERS

def initialize(self, parallel: bool = False) -> None:
self.initialized = True

Expand Down
7 changes: 1 addition & 6 deletions annif/backend/mllm.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from annif.lexical.mllm import MLLMModel
from annif.suggestion import vector_to_suggestions

from . import backend, hyperopt
from . import hyperopt

if TYPE_CHECKING:
from collections.abc import Iterator
Expand Down Expand Up @@ -95,11 +95,6 @@ class MLLMBackend(hyperopt.AnnifHyperoptBackend):
def get_hp_optimizer(self, corpus: DocumentCorpus, metric: str) -> MLLMOptimizer:
return MLLMOptimizer(self, corpus, metric)

def default_params(self) -> dict[str, Any]:
params = backend.AnnifBackend.DEFAULT_PARAMETERS.copy()
params.update(self.DEFAULT_PARAMETERS)
return params

def _load_model(self) -> MLLMModel:
path = os.path.join(self.datadir, self.MODEL_FILE)
self.debug("loading model from {}".format(path))
Expand Down
5 changes: 0 additions & 5 deletions annif/backend/nn_ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,6 @@ class NNEnsembleBackend(backend.AnnifLearningBackend, ensemble.BaseEnsembleBacke
# defaults for uninitialized instances
_model = None

def default_params(self) -> dict[str, Any]:
params = backend.AnnifBackend.DEFAULT_PARAMETERS.copy()
params.update(self.DEFAULT_PARAMETERS)
return params

def initialize(self, parallel: bool = False) -> None:
super().initialize(parallel)
if self._model is not None:
Expand Down
5 changes: 0 additions & 5 deletions annif/backend/omikuji.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ class OmikujiBackend(mixins.TfidfVectorizerMixin, backend.AnnifBackend):
"collapse_every_n_layers": 0,
}

def default_params(self) -> dict[str, Any]:
params = backend.AnnifBackend.DEFAULT_PARAMETERS.copy()
params.update(self.DEFAULT_PARAMETERS)
return params

def _initialize_model(self) -> None:
if self._model is None:
path = os.path.join(self.datadir, self.MODEL_FILE)
Expand Down
7 changes: 1 addition & 6 deletions annif/backend/pav.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from annif.exception import NotInitializedException, NotSupportedException
from annif.suggestion import SubjectSuggestion, SuggestionBatch

from . import backend, ensemble
from . import ensemble

if TYPE_CHECKING:
from annif.corpus.document import DocumentCorpus
Expand All @@ -36,11 +36,6 @@ class PAVBackend(ensemble.BaseEnsembleBackend):

DEFAULT_PARAMETERS = {"min-docs": 10}

def default_params(self) -> dict[str, Any]:
params = backend.AnnifBackend.DEFAULT_PARAMETERS.copy()
params.update(self.DEFAULT_PARAMETERS)
return params

def initialize(self, parallel: bool = False) -> None:
super().initialize(parallel)
if self._models is not None:
Expand Down
5 changes: 0 additions & 5 deletions annif/backend/svc.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ class SVCBackend(mixins.TfidfVectorizerMixin, backend.AnnifBackend):

DEFAULT_PARAMETERS = {"min_df": 1, "ngram": 1}

def default_params(self) -> dict[str, Any]:
params = backend.AnnifBackend.DEFAULT_PARAMETERS.copy()
params.update(self.DEFAULT_PARAMETERS)
return params

def _initialize_model(self) -> None:
if self._model is None:
path = os.path.join(self.datadir, self.MODEL_FILE)
Expand Down
5 changes: 0 additions & 5 deletions annif/backend/yake.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ class YakeBackend(backend.AnnifBackend):
"remove_parentheses": False,
}

def default_params(self) -> dict[str, Any]:
params = backend.AnnifBackend.DEFAULT_PARAMETERS.copy()
params.update(self.DEFAULT_PARAMETERS)
return params

@property
def is_trained(self):
return True
Expand Down
1 change: 1 addition & 0 deletions tests/test_backend_stwfsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def test_stwfsa_default_params(project):
backend_id=stwfsa_backend_name, config_params={}, project=project
)
expected_default_params = {
"limit": 100,
"concept_type_uri": "http://www.w3.org/2004/02/skos/core#Concept",
"sub_thesaurus_type_uri": "http://www.w3.org/2004/02/skos/core#Collection",
"thesaurus_relation_type_uri": "http://www.w3.org/2004/02/skos/core#member",
Expand Down

0 comments on commit 02233ab

Please sign in to comment.