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 missing limit parameter in STWFSA backend #718

Merged
merged 2 commits into from
Jul 31, 2023

Conversation

juhoinkinen
Copy link
Member

@juhoinkinen juhoinkinen commented Jul 5, 2023

I noticed that if a STWFSA project configuration did not set the limit paramter, the operations based on suggest functionality (CLI commands suggest, eval, index...) were crashing:

echo kissa | annif suggest stwfsa-fi  
Traceback (most recent call last):
  File "/home/local/jmminkin/.cache/pypoetry/virtualenvs/annif-ul-EXdhi-py3.10/bin/annif", line 6, in <module>
    sys.exit(cli())
  File "/home/jmminkin/.cache/pypoetry/virtualenvs/annif-ul-EXdhi-py3.10/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/jmminkin/.cache/pypoetry/virtualenvs/annif-ul-EXdhi-py3.10/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/jmminkin/.cache/pypoetry/virtualenvs/annif-ul-EXdhi-py3.10/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/jmminkin/.cache/pypoetry/virtualenvs/annif-ul-EXdhi-py3.10/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/jmminkin/.cache/pypoetry/virtualenvs/annif-ul-EXdhi-py3.10/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/jmminkin/.cache/pypoetry/virtualenvs/annif-ul-EXdhi-py3.10/lib/python3.10/site-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/jmminkin/.cache/pypoetry/virtualenvs/annif-ul-EXdhi-py3.10/lib/python3.10/site-packages/flask/cli.py", line 357, in decorator
    return __ctx.invoke(f, *args, **kwargs)
  File "/home/jmminkin/.cache/pypoetry/virtualenvs/annif-ul-EXdhi-py3.10/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/local/jmminkin/git/Annif/annif/cli.py", line 284, in run_suggest
    suggestions = project.suggest([text], backend_params).filter(limit, threshold)[
  File "/home/local/jmminkin/git/Annif/annif/project.py", line 253, in suggest
    return self._suggest_with_backend(texts, backend_params)
  File "/home/local/jmminkin/git/Annif/annif/project.py", line 143, in _suggest_with_backend
    return self.backend.suggest(texts, beparams)
  File "/home/local/jmminkin/git/Annif/annif/backend/backend.py", line 130, in suggest
    return self._suggest_batch(texts, params=beparams)
  File "/home/local/jmminkin/git/Annif/annif/backend/backend.py", line 118, in _suggest_batch
    limit=int(params.get("limit")),
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'

The default limit parameter was not obtainable from AnnifBackend.DEFAULT_PARAMETERS, because StwfsaBackend class defined its own DEFAULT_PARAMETERS field (without the limit parameter), but not a default_params() method. Other backends having their own DEFAULT_PARAMETERS field had that method to include the AnnifBackend.DEFAULT_PARAMETERS in the parameters.

I changed the AnnifBackend.default_params() method to include both DEFAULT_PARAMETERS from AnnifBackend (base) class and from the instances of the concrete backend (derived) classes, like most backends were already doing. This way there is no need to duplicate the method in so many backend classes.

In the fasttext backend the default_params() method includes also DEFAULT_PARAMETERS from mixins.ChunkingBackend, so it is needed to be retained to override the new AnnifBackend.default_params() method.

@juhoinkinen juhoinkinen added the bug label Jul 5, 2023
@juhoinkinen juhoinkinen added this to the 1.0 milestone Jul 5, 2023
@sonarcloud
Copy link

sonarcloud bot commented Jul 5, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@codecov
Copy link

codecov bot commented Jul 5, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.01 ⚠️

Comparison is base (320af2b) 99.67% compared to head (bf5f844) 99.66%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #718      +/-   ##
==========================================
- Coverage   99.67%   99.66%   -0.01%     
==========================================
  Files          89       89              
  Lines        6380     6356      -24     
==========================================
- Hits         6359     6335      -24     
  Misses         21       21              
Impacted Files Coverage Δ
annif/backend/dummy.py 100.00% <ø> (ø)
annif/backend/nn_ensemble.py 100.00% <ø> (ø)
annif/backend/omikuji.py 97.46% <ø> (-0.13%) ⬇️
annif/backend/svc.py 100.00% <ø> (ø)
annif/backend/yake.py 98.18% <ø> (-0.07%) ⬇️
tests/test_backend_stwfsa.py 100.00% <ø> (ø)
annif/backend/backend.py 100.00% <100.00%> (ø)
annif/backend/mllm.py 100.00% <100.00%> (ø)
annif/backend/pav.py 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@juhoinkinen juhoinkinen marked this pull request as ready for review July 5, 2023 12:32
@juhoinkinen juhoinkinen requested a review from osma July 5, 2023 12:33
Copy link
Member

@osma osma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good, this fixes the problem and makes the code cleaner.

@juhoinkinen juhoinkinen merged commit 02233ab into main Jul 31, 2023
13 of 14 checks passed
@juhoinkinen juhoinkinen deleted the fix-missing-limit-default-param-in-stwfsa branch July 31, 2023 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants