NatLibFi/Annif

View on GitHub

Showing 69 of 74 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

        new_params = {
            key: self.STWFSA_PARAMETERS[key](val)
            for key, val in params.items()
            if key in self.STWFSA_PARAMETERS
Severity: Minor
Found in annif/backend/stwfsa.py and 1 other location - About 50 mins to fix
annif/backend/fasttext.py on lines 127..130

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 44.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Function run_suggest has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

def run_suggest(
    project_id, paths, limit, threshold, language, backend_param, docs_limit
):
    """
    Suggest subjects for a single document from standard input or for one or more
Severity: Minor
Found in annif/cli.py - About 45 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function run_train has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

def run_train(project_id, paths, cached, docs_limit, jobs, backend_param):
Severity: Minor
Found in annif/cli.py - About 45 mins to fix

    Function _find_subj_tsets has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def _find_subj_tsets(self, tset: TokenSet) -> dict[int | None, TokenSet]:
            """return a dict (subject_id : TokenSet) of matches contained in the
            given TokenSet"""
    
            subj_tsets = {}
    Severity: Minor
    Found in annif/lexical/tokenset.py - About 45 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Identical blocks of code found in 2 locations. Consider refactoring.
    Open

                vecparams = {
                    "min_df": int(params["min_df"]),
                    "tokenizer": self.project.analyzer.tokenize_words,
                    "ngram_range": (1, int(params["ngram"])),
    Severity: Minor
    Found in annif/backend/omikuji.py and 1 other location - About 40 mins to fix
    annif/backend/svc.py on lines 87..90

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 42.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

                for label in get_subject_labels(
                    graph, subject.uri, pref_label_props, params["language"]
                ):
                    terms.append(Term(subject_id=subj_id, label=label, is_pref=True))
    Severity: Minor
    Found in annif/lexical/mllm.py and 1 other location - About 40 mins to fix
    annif/lexical/mllm.py on lines 203..206

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 42.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Identical blocks of code found in 2 locations. Consider refactoring.
    Open

            vecparams = {
                "min_df": int(params["min_df"]),
                "tokenizer": self.project.analyzer.tokenize_words,
                "ngram_range": (1, int(params["ngram"])),
    Severity: Minor
    Found in annif/backend/svc.py and 1 other location - About 40 mins to fix
    annif/backend/omikuji.py on lines 122..125

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 42.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

                for label in get_subject_labels(
                    graph, subject.uri, nonpref_label_props, params["language"]
                ):
                    terms.append(Term(subject_id=subj_id, label=label, is_pref=False))
    Severity: Minor
    Found in annif/lexical/mllm.py and 1 other location - About 40 mins to fix
    annif/lexical/mllm.py on lines 198..201

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 42.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Function __init__ has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def __init__(
    Severity: Minor
    Found in annif/parallel.py - About 35 mins to fix

      Function hyperopt has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def hyperopt(
      Severity: Minor
      Found in annif/project.py - About 35 mins to fix

        Function prepare_train has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def prepare_train(
        Severity: Minor
        Found in annif/lexical/mllm.py - About 35 mins to fix

          Function run_optimize has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          def run_optimize(project_id, paths, jobs, docs_limit, backend_param):
          Severity: Minor
          Found in annif/cli.py - About 35 mins to fix

            Function _initialize_model has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def _initialize_model(self) -> None:
                    if self._model is None:
                        path = os.path.join(self.datadir, self.MODEL_FILE)
                        self.debug("loading model from {}".format(path))
                        if os.path.exists(path):
            Severity: Minor
            Found in annif/backend/omikuji.py - About 35 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                    if os.path.exists(path):
                        return MLLMModel.load(path)
                    else:
                        raise NotInitializedException(
                            "model {} not found".format(path), backend_id=self.backend_id
            Severity: Minor
            Found in annif/backend/mllm.py and 1 other location - About 35 mins to fix
            annif/backend/mllm.py on lines 111..115

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 41.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Function _suggest has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def _suggest(self, text: str, params: dict[str, Any]) -> list[SubjectSuggestion]:
                    data = {"text": text}
                    if "project" in params:
                        data["project"] = params["project"]
                    if "limit" in params:
            Severity: Minor
            Found in annif/backend/http.py - About 35 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Function save has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def save(self, path: str) -> None:
                    """Save this subject index into a file with the given path name."""
            
                    fieldnames = ["uri", "notation"] + [f"label_{lang}" for lang in self._languages]
            
            
            Severity: Minor
            Found in annif/corpus/subject.py - About 35 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Function from_sequence has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def from_sequence(
                    cls,
                    suggestion_results: Sequence[Iterable[SubjectSuggestion]],
                    subject_index: SubjectIndex,
                    limit: int | None = None,
            Severity: Minor
            Found in annif/suggestion.py - About 35 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Function _update_subject_index has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def _update_subject_index(self, subject_corpus: SubjectCorpus) -> SubjectIndex:
                    old_subjects = self.subjects
                    new_subjects = annif.corpus.SubjectIndex()
                    new_subjects.load_subjects(subject_corpus)
                    updated_subjects = annif.corpus.SubjectIndex()
            Severity: Minor
            Found in annif/vocab.py - About 35 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                    if os.path.exists(path):
                        return joblib.load(path)
                    else:
                        raise NotInitializedException(
                            "train data file {} not found".format(path), backend_id=self.backend_id
            Severity: Minor
            Found in annif/backend/mllm.py and 1 other location - About 35 mins to fix
            annif/backend/mllm.py on lines 102..106

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 41.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Avoid too many return statements within this function.
            Open

                return _hit_sets_to_list(hit_sets, project.subjects, lang)
            Severity: Major
            Found in annif/rest.py - About 30 mins to fix
              Severity
              Category
              Status
              Source
              Language