e-mental-health/data-processing

View on GitHub
egofy.py

Summary

Maintainability
F
3 days
Test Coverage

Function egofy has a Cognitive Complexity of 50 (exceeds 5 allowed). Consider refactoring.
Open

def egofy(processedText,names,gender):
    text = ""
    textInitial = True
    for paragraph in processedText:
        sentenceInitial = True
Severity: Minor
Found in egofy.py - About 7 hrs 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

Consider simplifying this complex logical expression.
Open

                    if token in names and names[token] == COMPLETE:
                        if re.search(r"VZ",lastPOS): 
                            text += METOKEN[sentenceInitial]+" "
                        else: 
                            text += ITOKEN[sentenceInitial]+" "
Severity: Critical
Found in egofy.py - About 5 hrs to fix

    File egofy.py has 279 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    #!/usr/bin/env python3
    """
        egofy.py: change Dutch biographic text to autobiographic text
        usage: egofy.py [-t file.txt ] [-p file.txt.pos] [-n name] [-s]
        notes: 
    Severity: Minor
    Found in egofy.py - About 2 hrs to fix

      Function nameMatch has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

      def nameMatch(targetNames,sourceNames,suffix=""):
          for targetName in targetNames:
              for sourceName in sourceNames:
                  targetName = targetName.lower()
                  sourceName = sourceName.lower()
      Severity: Minor
      Found in egofy.py - About 2 hrs 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 nameCheckForMinusOneToken has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

      def nameCheckForMinusOneToken(targetName,sourceName,suffix):
          targetNameTokens = targetName.split()
          for i in range(0,len(targetNameTokens)):
              name = ""
              for j in range(0,len(targetNameTokens)):
      Severity: Minor
      Found in egofy.py - About 1 hr 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 savePosFile has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

      def savePosFile(processedOptions,outFileName):
          outFileName += ".pos"
          try: outFile = open(outFileName,"w")
          except Exception as e: sys.exit(COMMAND+": cannot write file "+outFileName)
          for paragraph in processedOptions:
      Severity: Minor
      Found in egofy.py - About 1 hr 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 getGenderDataFromVNW has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

      def getGenderDataFromVNW(processedText):
          genderData = {}
          for paragraph in processedText:
              for tokenData in paragraph:
                  if re.match(r"^VNW\(",str(tokenData[POS])):
      Severity: Minor
      Found in egofy.py - About 1 hr 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 deeply nested control flow statements.
      Open

                          if not sentenceInitial:
                              text += "\n"
                              sentenceInitial = True
                              lastPOS = ""
                      else:
      Severity: Major
      Found in egofy.py - About 45 mins to fix

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

        def main(argv):
            options,files,names = processOptions(argv)
            if "-p" in options: processedText = readPosFile(options["-p"])
            elif "-t" in options: processedText = processTextWithFrog(options["-t"])
            else: sys.exit(USAGE)
        Severity: Minor
        Found in egofy.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 processOptions has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

        def processOptions(argv):
            try:
                names = {}
                optionList, files = getopt.getopt(argv,"n:p:t:s",[])
                options = {}
        Severity: Minor
        Found in egofy.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

        Avoid deeply nested control flow statements.
        Open

                            if token in names and names[token] == COMPLETE:
                                if re.search(r"VZ",lastPOS): 
                                    text += METOKEN[sentenceInitial]+" "
                                else: 
                                    text += ITOKEN[sentenceInitial]+" "
        Severity: Major
        Found in egofy.py - About 45 mins to fix

          Avoid too many return statements within this function.
          Open

                          return(True)
          Severity: Major
          Found in egofy.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                return(False)
            Severity: Major
            Found in egofy.py - About 30 mins to fix

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

              def matchTokenToNames(paragraph,start,names):
                  if not paragraph[start][TOKEN] in names: return(paragraph[start][TOKEN],start,start)
                  end = start
                  token = paragraph[start][TOKEN]
                  while end+1 < len(paragraph) and token+" "+paragraph[end+1][TOKEN] in names:
              Severity: Minor
              Found in egofy.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 readPosFile has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

              def readPosFile(inFileName):
                  try: inFile = open(inFileName,"r")
                  except Exception as e: sys.exit(COMMAND+": cannot read from file "+inFileName)
                  paragraph,processedText = [],[]
                  for line in inFile:
              Severity: Minor
              Found in egofy.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

              There are no issues that match your filters.

              Category
              Status