class_docstr: Test the text utilities for creating and cleaning features.
class_docstr_tok: ["Test","the","text","utilities","for","creating","and","cleaning","features","."]
code: def test_count_ngrams(self):
      # Testing word n-gram functionality
      result = text_analytics.count_ngrams(self.sa_word, 3)
      result2 = text_analytics.count_ngrams(self.sa_word, 2)
      result3 = text_analytics.count_ngrams(
          self.sa_word, 3, "word", to_lower=False
      )
      result4 = text_analytics.count_ngrams(
          self.sa_word, 2, "word", to_lower=False
      )
      expected = [
          {
              "fun i like": 1,
              "i like big": 2,
              "they are fun": 1,
              "big dogs they": 1,
              "like big dogs": 2,
              "are fun i": 1,
              "dogs they are": 1,
          },
          {},
          {"i like big": 1},
      ]
      expected2 = [
          {
              "i like": 2,
              "dogs they": 1,
              "big dogs": 2,
              "are fun": 1,
              "like big": 2,
              "they are": 1,
              "fun i": 1,
          },
          {"i like": 1},
          {"i like": 1, "like big": 1},
      ]
      expected3 = [
          {
              "I like big": 1,
              "fun I LIKE": 1,
              "I LIKE BIG": 1,
              "LIKE BIG DOGS": 1,
              "They are fun": 1,
              "big dogs They": 1,
              "like big dogs": 1,
              "are fun I": 1,
              "dogs They are": 1,
          },
          {},
          {"I like big": 1},
      ]
      expected4 = [
          {
              "I like": 1,
              "like big": 1,
              "I LIKE": 1,
              "BIG DOGS": 1,
              "are fun": 1,
              "LIKE BIG": 1,
              "big dogs": 1,
              "They are": 1,
              "dogs They": 1,
              "fun I": 1,
          },
          {"I like": 1},
          {"I like": 1, "like big": 1},
      ]
  
      self.assertEqual(result.dtype, dict)
      self.sframe_comparer._assert_sarray_equal(result, expected)
      self.assertEqual(result2.dtype, dict)
      self.sframe_comparer._assert_sarray_equal(result2, expected2)
      self.assertEqual(result3.dtype, dict)
      self.sframe_comparer._assert_sarray_equal(result3, expected3)
      self.assertEqual(result4.dtype, dict)
      self.sframe_comparer._assert_sarray_equal(result4, expected4)
  
      # Testing character n-gram functionality
      result5 = text_analytics.count_ngrams(
          self.sa_char, 3, "character"
      )
      result6 = text_analytics.count_ngrams(
          self.sa_char, 2, "character"
      )
      result7 = text_analytics.count_ngrams(
          self.sa_char, 3, "character", to_lower=False
      )
      result8 = text_analytics.count_ngrams(
          self.sa_char, 2, "character", to_lower=False
      )
      result9 = text_analytics.count_ngrams(
          self.sa_char,
          3,
          "character",
          to_lower=False,
          ignore_space=False,
      )
      result10 = text_analytics.count_ngrams(
          self.sa_char,
          2,
          "character",
          to_lower=False,
          ignore_space=False,
      )
      result11 = text_analytics.count_ngrams(
          self.sa_char,
          3,
          "character",
          to_lower=True,
          ignore_space=False,
      )
      result12 = text_analytics.count_ngrams(
          self.sa_char,
          2,
          "character",
          to_lower=True,
          ignore_space=False,
      )
      result13 = text_analytics.count_ngrams(
          self.sa_char,
          3,
          "character",
          to_lower=False,
          ignore_punct=False,
          ignore_space=False,
      )
      result14 = text_analytics.count_ngrams(
          self.sa_char,
          2,
          "character",
          to_lower=False,
          ignore_punct=False,
          ignore_space=False,
      )
      result15 = text_analytics.count_ngrams(
          self.sa_char,
          3,
          "character",
          to_lower=False,
          ignore_punct=False,
          ignore_space=True,
      )
      result16 = text_analytics.count_ngrams(
          self.sa_char,
          2,
          "character",
          to_lower=False,
          ignore_punct=False,
          ignore_space=True,
      )
      expected5 = [
          {"fun": 2, "nis": 1, "sfu": 1, "isf": 1, "uni": 1},
          {"fun": 2, "nis": 1, "sfu": 1, "isf": 1, "uni": 1},
          {},
          {"fun": 1},
      ]
      expected6 = [
          {"ni": 1, "is": 1, "un": 2, "sf": 1, "fu": 2},
          {"ni": 1, "is": 1, "un": 2, "sf": 1, "fu": 2},
          {"fu": 1},
          {"un": 1, "fu": 1},
      ]
      expected7 = [
          {"sfu": 1, "Fun": 1, "uni": 1, "fun": 1, "nis": 1, "isf": 1},
          {"sfu": 1, "Fun": 1, "uni": 1, "fun": 1, "nis": 1, "isf": 1},
          {},
          {"fun": 1},
      ]
      expected8 = [
          {"ni": 1, "Fu": 1, "is": 1, "un": 2, "sf": 1, "fu": 1},
          {"ni": 1, "Fu": 1, "is": 1, "un": 2, "sf": 1, "fu": 1},
          {"fu": 1},
          {"un": 1, "fu": 1},
      ]
      expected9 = [
          {
              " fu": 1,
              " is": 1,
              "s f": 1,
              "un ": 1,
              "Fun": 1,
              "n i": 1,
              "fun": 1,
              "is ": 1,
          },
          {
              " fu": 1,
              " is": 1,
              "s f": 1,
              "un ": 1,
              "Fun": 1,
              "n i": 1,
              "fun": 1,
              "is ": 1,
          },
          {},
          {"fun": 1},
      ]
      expected10 = [
          {
              " f": 1,
              "fu": 1,
              "n ": 1,
              "is": 1,
              " i": 1,
              "un": 2,
              "s ": 1,
              "Fu": 1,
          },
          {
              " f": 1,
              "fu": 1,
              "n ": 1,
              "is": 1,
              " i": 1,
              "un": 2,
              "s ": 1,
              "Fu": 1,
          },
          {"fu": 1},
          {"un": 1, "fu": 1},
      ]
      expected11 = [
          {
              " fu": 1,
              " is": 1,
              "s f": 1,
              "un ": 1,
              "n i": 1,
              "fun": 2,
              "is ": 1,
          },
          {
              " fu": 1,
              " is": 1,
              "s f": 1,
              "un ": 1,
              "n i": 1,
              "fun": 2,
              "is ": 1,
          },
          {},
          {"fun": 1},
      ]
      expected12 = [
          {
              " f": 1,
              "fu": 2,
              "n ": 1,
              "is": 1,
              " i": 1,
              "un": 2,
              "s ": 1,
          },
          {
              " f": 1,
              "fu": 2,
              "n ": 1,
              "is": 1,
              " i": 1,
              "un": 2,
              "s ": 1,
          },
          {"fu": 1},
          {"un": 1, "fu": 1},
      ]
      expected13 = [
          {
              " fu": 1,
              "s. ": 1,
              " is": 1,
              "n. ": 1,
              "Fun": 1,
              ". i": 1,
              "is.": 1,
              "fun": 1,
              ". f": 1,
              "un.": 1,
          },
          {
              " fu": 1,
              " is": 1,
              "s f": 1,
              "un ": 1,
              "Fun": 1,
              "n i": 1,
              "fun": 1,
              "is ": 1,
              "un.": 1,
          },
          {},
          {"fun": 1},
      ]
      expected14 = [
          {
              " f": 1,
              "fu": 1,
              "n.": 1,
              ". ": 2,
              "is": 1,
              " i": 1,
              "un": 2,
              "s.": 1,
              "Fu": 1,
          },
          {
              " f": 1,
              "fu": 1,
              "n.": 1,
              "n ": 1,
              "is": 1,
              " i": 1,
              "un": 2,
              "s ": 1,
              "Fu": 1,
          },
          {"fu": 1},
          {"un": 1, "fu": 1},
      ]
      expected15 = [
          {
              "s.f": 1,
              "n.i": 1,
              "Fun": 1,
              ".fu": 1,
              "is.": 1,
              "fun": 1,
              ".is": 1,
              "un.": 1,
          },
          {
              "sfu": 1,
              "Fun": 1,
              "uni": 1,
              "fun": 1,
              "nis": 1,
              "isf": 1,
              "un.": 1,
          },
          {},
          {"fun": 1},
      ]
      expected16 = [
          {
              ".i": 1,
              "fu": 1,
              "n.": 1,
              "is": 1,
              ".f": 1,
              "un": 2,
              "s.": 1,
              "Fu": 1,
          },
          {
              "ni": 1,
              "fu": 1,
              "n.": 1,
              "is": 1,
              "un": 2,
              "sf": 1,
              "Fu": 1,
          },
          {"fu": 1},
          {"un": 1, "fu": 1},
      ]
  
      self.assertEqual(result5.dtype, dict)
      self.sframe_comparer._assert_sarray_equal(result5, expected5)
      self.assertEqual(result6.dtype, dict)
      self.sframe_comparer._assert_sarray_equal(result6, expected6)
      self.assertEqual(result7.dtype, dict)
      self.sframe_comparer._assert_sarray_equal(result7, expected7)
      self.assertEqual(result8.dtype, dict)
      self.sframe_comparer._assert_sarray_equal(result8, expected8)
      self.assertEqual(result9.dtype, dict)
      self.sframe_comparer._assert_sarray_equal(result9, expected9)
      self.assertEqual(result10.dtype, dict)
      self.sframe_comparer._assert_sarray_equal(result10, expected10)
      self.assertEqual(result11.dtype, dict)
      self.sframe_comparer._assert_sarray_equal(result11, expected11)
      self.assertEqual(result12.dtype, dict)
      self.sframe_comparer._assert_sarray_equal(result12, expected12)
      self.assertEqual(result13.dtype, dict)
      self.sframe_comparer._assert_sarray_equal(result13, expected13)
      self.assertEqual(result14.dtype, dict)
      self.sframe_comparer._assert_sarray_equal(result14, expected14)
      self.assertEqual(result15.dtype, dict)
      self.sframe_comparer._assert_sarray_equal(result15, expected15)
      self.assertEqual(result16.dtype, dict)
      self.sframe_comparer._assert_sarray_equal(result16, expected16)
  
      ## Bogus input types and values
      sa = tc.SArray([1, 2, 3])
      with self.assertRaises(RuntimeError):
          text_analytics.count_ngrams(sa)
  
      with self.assertRaises(TypeError):
          text_analytics.count_ngrams(self.sa_word, n=1.01)
  
      with self.assertRaises(ValueError):
          text_analytics.count_ngrams(self.sa_word, n=0)
  
      with self.assertRaises(ValueError):
          text_analytics.count_ngrams(self.sa_char, n=3, method="bla")
  
      with warnings.catch_warnings(record=True) as context:
          warnings.simplefilter("always")
          text_analytics.count_ngrams(self.sa_word, n=10, method="word")
          assert len(context) == 1
  
imports: from __future__ import print_function
  from __future__ import division
  from __future__ import absolute_import
  import math
  import unittest
  import warnings
  import turicreate
  import turicreate.toolkits.text_analytics
  from .None import util
label_desc: Use image node_id 3 for calling the FeatureEngineeringTest obj's underlying member method code with example usage: obj.test_count_ngrams() without return types