code: def fromstring(lex_str, include_semantics=False):
      """
      Convert string representation into a lexicon for CCGs.
      """
      CCGVar.reset_id()
      primitives = []
      families = {}
      entries = defaultdict(list)
      for line in lex_str.splitlines():
          # Strip comments and leading/trailing whitespace.
          line = COMMENTS_RE.match(line).groups()[0].strip()
          if line == "":
              continue
  
          if line.startswith(":-"):
              # A line of primitive categories.
              # The first one is the target category
              # ie, :- S, N, NP, VP
              primitives = primitives + [
                  prim.strip() for prim in line[2:].strip().split(",")
              ]
          else:
              # Either a family definition, or a word definition
              (ident, sep, rhs) = LEX_RE.match(line).groups()
              (catstr, semantics_str) = RHS_RE.match(rhs).groups()
              (cat, var) = augParseCategory(
                  catstr, primitives, families
              )
  
              if sep == "::":
                  # Family definition
                  # ie, Det :: NP/N
                  families[ident] = (cat, var)
              else:
                  semantics = None
                  if include_semantics is True:
                      if semantics_str is None:
                          raise AssertionError(
                              line
                              + " must contain semantics because include_semantics is set to True"
                          )
                      else:
                          semantics = Expression.fromstring(
                              SEMANTICS_RE.match(
                                  semantics_str
                              ).groups()[0]
                          )
                  # Word definition
                  # ie, which => (N\N)/(S/NP)
                  entries[ident].append(Token(ident, cat, semantics))
      return CCGLexicon(primitives[0], primitives, families, entries)
  
imports: import re
  from collections import defaultdict
  from nltk.ccg.api import CCGVar, Direction, FunctionalCategory, PrimitiveCategory
  from nltk.internals import deprecated
  from nltk.sem.logic import Expression
label_desc: Use image node_id 7 for calling a global function with example usage: fromstring(lex_str, include_semantics) and returns: CCGLexicon