async def _rank_text(self, choices):
tl = self.request.get_layer(l.RawText)<EOL>best = <NUM_LIT:0.0><EOL>for slug, params in choices.items():<EOL><INDENT>strings = []<EOL>if params['<STR_LIT>']:<EOL><INDENT>intent = getattr(intents, params['<STR_LIT>'])<EOL>strings += await intent.strings(self.request)<EOL><DEDENT>if params['<STR_LIT:text>']:<EOL><INDENT>strings.append((params['<STR_LIT:text>'],))<EOL><DEDENT>matcher = Matcher([tuple(Trigram(y) for y in x) for x in strings])<EOL>score = matcher % Trigram(await render(tl.text, self.request))<EOL>if score > best:<EOL><INDENT>self.chosen = params<EOL>self.slug = slug<EOL>best = score<EOL><DEDENT><DEDENT>if self.when is None or self.slug == self.when:<EOL><INDENT>return best<EOL><DEDENT>
Try to match the TextLayer with choice's intents.