deeplearning4j/deeplearning4j

View on GitHub
deeplearning4j/deeplearning4j-modelimport/src/main/java/org/deeplearning4j/nn/modelimport/keras/preprocessing/text/KerasTokenizer.java

Summary

Maintainability
F
3 days
Test Coverage

Method sequencesToMatrix has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
Open

    public INDArray sequencesToMatrix(Integer[][] sequences, TokenizerMode mode) {
        if (numWords == null) {
            if (!wordIndex.isEmpty()) {
                numWords = wordIndex.size();
            } else {

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

Method fitOnTexts has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
Open

    public void fitOnTexts(String[] texts) {
        String[] sequence;
        for (String text : texts) {
            if (documentCount == null)
                documentCount = 1;

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

Method textsToSequences has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
Open

    public Integer[][] textsToSequences(String[] texts) {
        Integer oovTokenIndex  = wordIndex.get(outOfVocabularyToken);
        String[] wordSequence;
        ArrayList<Integer[]> sequences = new ArrayList<>();
        for (String text: texts) {

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

Method sequencesToTexts has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
Open

    public String[] sequencesToTexts(Integer[][] sequences) {
        Integer oovTokenIndex  = wordIndex.get(outOfVocabularyToken);
        ArrayList<String> texts = new ArrayList<>();
        for (Integer[] sequence: sequences) {
            ArrayList<String> wordVector = new ArrayList<>();

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

File KerasTokenizer.java has 267 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*
 *  ******************************************************************************
 *  *
 *  *
 *  * This program and the accompanying materials are made available under the

    Method sequencesToMatrix has 48 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public INDArray sequencesToMatrix(Integer[][] sequences, TokenizerMode mode) {
            if (numWords == null) {
                if (!wordIndex.isEmpty()) {
                    numWords = wordIndex.size();
                } else {

      Method fitOnTexts has 41 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public void fitOnTexts(String[] texts) {
              String[] sequence;
              for (String text : texts) {
                  if (documentCount == null)
                      documentCount = 1;

        Method fromJson has 32 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static KerasTokenizer fromJson(String jsonFileName) throws IOException, InvalidKerasConfigurationException {
                String json = new String(Files.readAllBytes(Paths.get(jsonFileName)));
                Map<String, Object> tokenizerBaseConfig = KerasModelUtils.parseJsonString(json);
                Map<String, Object> tokenizerConfig;
                if (tokenizerBaseConfig.containsKey("config"))

          Method textsToSequences has 30 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public Integer[][] textsToSequences(String[] texts) {
                  Integer oovTokenIndex  = wordIndex.get(outOfVocabularyToken);
                  String[] wordSequence;
                  ArrayList<Integer[]> sequences = new ArrayList<>();
                  for (String text: texts) {

            Method sequencesToTexts has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public String[] sequencesToTexts(Integer[][] sequences) {
                    Integer oovTokenIndex  = wordIndex.get(outOfVocabularyToken);
                    ArrayList<String> texts = new ArrayList<>();
                    for (Integer[] sequence: sequences) {
                        ArrayList<String> wordVector = new ArrayList<>();

              Avoid deeply nested control flow statements.
              Open

                                      if (oovTokenIndex != null) {
                                          wordVector.add(indexWord.get(oovTokenIndex));
                                      } else {
                                          wordVector.add(word);
                                      }

                Avoid deeply nested control flow statements.
                Open

                                        if (oovTokenIndex != null)
                                            indexVector.add(oovTokenIndex);

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

                      public KerasTokenizer(Integer numWords, String filters, boolean lower, String split, boolean charLevel,
                                       String outOfVocabularyToken) {
                  
                          this.numWords = numWords;
                          this.filters = filters;
                  datavec/datavec-api/src/main/java/org/datavec/api/transform/transform/sequence/SequenceMovingWindowReduceTransform.java on lines 87..98
                  deeplearning4j/deeplearning4j-core/src/main/java/org/deeplearning4j/core/listener/SystemInfoFilePrintListener.java on lines 48..56

                  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 71.

                  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 3 locations. Consider refactoring.
                  Open

                              for (String word: sequenceSet) {
                                  if (wordDocs.containsKey(word))
                                      wordDocs.put(word, wordDocs.get(word) + 1);
                                  else
                                      wordDocs.put(word, 1);
                  deeplearning4j/deeplearning4j-modelimport/src/main/java/org/deeplearning4j/nn/modelimport/keras/preprocessing/text/KerasTokenizer.java on lines 187..192
                  nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/validation/OpValidation.java on lines 459..464

                  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 46.

                  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 3 locations. Consider refactoring.
                  Open

                              for (String word : sequence) {
                                  if (wordCounts.containsKey(word))
                                      wordCounts.put(word, wordCounts.get(word) + 1);
                                  else
                                      wordCounts.put(word, 1);
                  deeplearning4j/deeplearning4j-modelimport/src/main/java/org/deeplearning4j/nn/modelimport/keras/preprocessing/text/KerasTokenizer.java on lines 194..199
                  nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/validation/OpValidation.java on lines 459..464

                  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 46.

                  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

                  There are no issues that match your filters.

                  Category
                  Status