HazyResearch/fonduer

View on GitHub

Showing 134 of 224 total issues

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

def tokens_to_ngrams(
Severity: Minor
Found in src/fonduer/utils/utils.py - About 35 mins to fix

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

    def get_between_ngrams(
    Severity: Minor
    Found in src/fonduer/utils/data_model_utils/textual.py - About 35 mins to fix

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

          def apply(  # type: ignore
      Severity: Minor
      Found in src/fonduer/supervision/labeler.py - About 35 mins to fix

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

            def apply(
                self,
                doc_loader: Collection[
                    Document
                ],  # doc_loader has __len__, but Iterable doesn't.
        Severity: Minor
        Found in src/fonduer/utils/udf.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 _f has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def _f(self, m: TemporaryContext) -> bool:
                if not isinstance(m, TemporarySpanMention):
                    raise ValueError(
                        f"{self.__class__.__name__} only supports TemporarySpanMention"
                    )
        Severity: Minor
        Found in src/fonduer/candidates/matchers.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 upsert_keys has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

        def upsert_keys(session: Session, key_table: Table, keys: Dict) -> None:
            """Bulk add annotation keys to the specified table.
        
            :param key_table: The sqlalchemy class to insert into.
            :param keys: A map of {name: [candidate_classes]}.
        Severity: Minor
        Found in src/fonduer/utils/utils_udf.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 display_boxes has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def display_boxes(
                self,
                pdf_file: str,
                boxes: List[Bbox],
                alternate_colors: bool = False,
        Severity: Minor
        Found in src/fonduer/utils/visualizer.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 apply has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def apply(self, mentions: Iterator[TemporaryContext]) -> Iterator[TemporaryContext]:
                """Apply the Matcher to a **generator** of mentions.
        
                Optionally only takes the longest match (NOTE: assumes this is the
                *first* match)
        Severity: Minor
        Found in src/fonduer/candidates/matchers.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 False
        Severity: Major
        Found in src/fonduer/candidates/matchers.py - About 30 mins to fix

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

              def _map_to_id(self) -> None:
                  self.X_dict.update(
                      dict([(f"m{i}", []) for i in range(len(self.candidates[0]))])
                  )
          
          
          Severity: Minor
          Found in src/fonduer/learning/dataset.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 _after_apply has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def _after_apply(self, train: bool = False, **kwargs: Any) -> None:
                  # Insert all Feature Keys
                  if train:
                      key_map: DefaultDict[str, set] = defaultdict(set)
                      for feature in self.session.query(Feature).all():
          Severity: Minor
          Found in src/fonduer/features/featurizer.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 forward has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def forward(self, input: Tensor, target: Tensor) -> Tensor:
                  """Calculate the loss.
          
                  :param input: prediction logits
                  :param target: target probabilities
          Severity: Minor
          Found in src/fonduer/learning/modules/soft_cross_entropy_loss.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 _get_ddlib_feats has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

          def _get_ddlib_feats(
              span: SpanMention, context: Dict[str, Any], idxs: List[int]
          ) -> Iterator[str]:
              """Minimalist port of generic mention features from ddlib."""
              if span.stable_id not in unary_ddlib_feats:
          Severity: Minor
          Found in src/fonduer/features/feature_libs/textual_features.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 _generate has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def _generate(self) -> Iterator[Document]:
                  """Parse a file or directory of files into a set of ``Document`` objects."""
                  doc_count = 0
                  for fp in self.all_files:
                      for doc in self._get_docs_for_path(fp):
          Severity: Minor
          Found in src/fonduer/parser/preprocessors/doc_preprocessor.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