NatLibFi/Annif

View on GitHub

Showing 34 of 71 total issues

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 _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

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

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

    Function open_text_documents has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

    def open_text_documents(paths: tuple[str, ...], docs_limit: int | None) -> DocumentList:
        """
        Helper function to read text documents from the given file paths. Returns a
        DocumentList object with Documents having no subjects. If a path is "-", the
        document text is read from standard input. The maximum number of documents to read
    Severity: Minor
    Found in annif/cli_util.py - About 25 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 transform_fn has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def transform_fn(self, text: str) -> str:
            if len(text) < self.text_min_length:
                return text
    
            retained_sentences = []
    Severity: Minor
    Found in annif/transform/langfilter.py - About 25 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 open_documents has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

    def open_documents(
        paths: tuple[str, ...],
        subject_index: SubjectIndex,
        vocab_lang: str,
        docs_limit: int | None,
    Severity: Minor
    Found in annif/cli_util.py - About 25 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 __init__ has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def __init__(
            self, projects_config_path: str, datadir: str, init_projects: bool
        ) -> None:
            self._rid = id(self)
            self._projects_config_path = projects_config_path
    Severity: Minor
    Found in annif/registry.py - About 25 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 _parse_line has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def _parse_line(
            line: str,
        ) -> tuple[str | None, str | None]:
            uri = label = None
            vals = line.split("\t")
    Severity: Minor
    Found in annif/corpus/subject.py - About 25 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_index has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

    def run_index(
        project_id, directory, suffix, force, limit, threshold, language, backend_param
    ):
        """
        Index a directory with documents, suggesting subjects for each document.
    Severity: Minor
    Found in annif/cli.py - About 25 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 parse_config has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

    def parse_config(
        projects_config_path: str,
    ) -> AnnifConfigDirectory | AnnifConfigCFG | AnnifConfigTOML | None:
        if projects_config_path:
            projects_config_path = check_config(projects_config_path)
    Severity: Minor
    Found in annif/config.py - About 25 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 skos has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def skos(self) -> SubjectFileSKOS:
            """return the subject vocabulary from SKOS file"""
            if self._skos_vocab is not None:
                return self._skos_vocab
    
    
    Severity: Minor
    Found in annif/vocab.py - About 25 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 _suggest has a Cognitive Complexity of 6 (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"]
    
    
    Severity: Minor
    Found in annif/backend/http.py - About 25 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 _write_train_file has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def _write_train_file(self, corpus: DocumentCorpus, filename: str) -> None:
            with open(filename, "w", encoding="utf-8") as trainfile:
                for doc in corpus.documents:
                    text = self._normalize_text(doc.text)
                    if text == "":
    Severity: Minor
    Found in annif/backend/fasttext.py - About 25 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

    Severity
    Category
    Status
    Source
    Language