- pos = 0
- force_space = False
- while pos < len(baseform):
- full, repl = self.replacements.longest_prefix_item(baseform[pos:],
- (None, None))
- if full is not None:
- done = baseform[startpos:pos]
- partials = [v + done + r
- for v, r in itertools.product(partials, repl)
- if not force_space or r.startswith(' ')]
- if len(partials) > 128:
- # If too many variants are produced, they are unlikely
- # to be helpful. Only use the original term.
- startpos = 0
- break
- startpos = pos + len(full)
- if full[-1] == ' ':
- startpos -= 1
- force_space = True
- pos = startpos
- else:
- pos += 1
- force_space = False
+ if self.replacements is not None:
+ pos = 0
+ force_space = False
+ while pos < len(baseform):
+ full, repl = self.replacements.longest_prefix_item(baseform[pos:],
+ (None, None))
+ if full is not None:
+ done = baseform[startpos:pos]
+ partials = [v + done + r
+ for v, r in itertools.product(partials, repl)
+ if not force_space or r.startswith(' ')]
+ if len(partials) > 128:
+ # If too many variants are produced, they are unlikely
+ # to be helpful. Only use the original term.
+ startpos = 0
+ break
+ startpos = pos + len(full)
+ if full[-1] == ' ':
+ startpos -= 1
+ force_space = True
+ pos = startpos
+ else:
+ pos += 1
+ force_space = False