code: def test_compact(self):
      hamlet = get_hamlet_term_doc_matrix()
      domains = np.arange(hamlet.get_num_docs()) % 3
      with self.assertRaises(NeedsMaxOrMinDomainCountException):
          hamlet_compact = hamlet.compact(DomainCompactor(domains))
  
      hamlet_compact = hamlet.compact(
          DomainCompactor(domains, min_domain_count=2)
      )
      self.assertLess(
          hamlet_compact.get_num_terms(), hamlet.get_num_terms()
      )
      self.assertEqual(
          hamlet_compact.get_num_docs(), hamlet.get_num_docs()
      )
  
      hamlet_compact = hamlet.compact(
          DomainCompactor(domains, max_domain_count=2)
      )
      self.assertLess(
          hamlet_compact.get_num_terms(), hamlet.get_num_terms()
      )
      self.assertEqual(
          hamlet_compact.get_num_docs(), hamlet.get_num_docs()
      )
  
      hamlet_compact = hamlet.compact(
          DomainCompactor(
              domains, max_domain_count=2, min_domain_count=2
          )
      )
      self.assertLess(
          hamlet_compact.get_num_terms(), hamlet.get_num_terms()
      )
      self.assertEqual(
          hamlet_compact.get_num_docs(), hamlet.get_num_docs()
      )
  
imports: from unittest import TestCase
  import numpy
  from scattertext import DomainCompactor
  from scattertext.termcompaction.DomainCompactor import NeedsMaxOrMinDomainCountException
  from scattertext.test.test_TermDocMat import get_hamlet_term_doc_matrix
label_desc: Use image node_id 1 for calling the TestDomainCompactor obj's underlying member method code with example usage: obj.test_compact() without return types