Given a text string and a glossary, insert spaces to generate all possible sentences where every segment matches a glossary entry.
In Part 2, both the input text and glossary entries may already contain spaces, which must also be handled correctly.
This problem is a sentence-generation variant of Word Break: given a text string and a glossary, you must insert spaces so that every produced segment matches a glossary entry, returning all valid sentences. A practical solution uses a hash set for fast lookup, DFS/backtracking to enumerate all segmentations, and memoization to avoid recomputing the same suffix states. In Part 2, because both the text and glossary entries may already contain spaces, the matcher must handle multi-word phrases as valid tokens rather than assuming single-word boundaries.