code: def test_word_segments():
      wordset = set(u("alfa bravo charlie delta").split())
  
      cwf = analysis.CompoundWordFilter(wordset, keep_compound=True)
      ana = analysis.RegexTokenizer(r"\S+") | cwf
      target = u("alfacharlie bravodelta delto bravo subalfa")
      tokens = [t.text for t in ana(target)]
      assert tokens == [
          "alfacharlie",
          "alfa",
          "charlie",
          "bravodelta",
          "bravo",
          "delta",
          "delto",
          "bravo",
          "subalfa",
      ]
  
      cwf = analysis.CompoundWordFilter(wordset, keep_compound=False)
      ana = analysis.RegexTokenizer(r"\S+") | cwf
      target = u("alfacharlie bravodelta delto bravo subalfa")
      tokens = [t.text for t in ana(target)]
      assert tokens == [
          "alfa",
          "charlie",
          "bravo",
          "delta",
          "delto",
          "bravo",
          "subalfa",
      ]
  
imports: from __future__ import with_statement
  import pytest
  from whoosh import analysis, fields, qparser
  from whoosh.compat import b, u, unichr
  from whoosh.compat import dumps
  from whoosh.filedb.filestore import RamStorage
label_desc: Use image node_id 14 for calling a global function with example usage: test_word_segments() without return types