(
self,
tokens: Sequence[int],
preferred_sequences: Optional[Any] = None,
*,
exact_only: bool = False,
)
| 999 | return values[:target_len] |
| 1000 | |
| 1001 | def longest_prefix( |
| 1002 | self, |
| 1003 | tokens: Sequence[int], |
| 1004 | preferred_sequences: Optional[Any] = None, |
| 1005 | *, |
| 1006 | exact_only: bool = False, |
| 1007 | ) -> Tuple[int, int]: |
| 1008 | node = self.root |
| 1009 | longest_sequence_id = -1 |
| 1010 | longest_length = 0 |
| 1011 | index = 0 |
| 1012 | while index < len(tokens): |
| 1013 | child = node.children.get(tokens[index]) |
| 1014 | if child is None: |
| 1015 | break |
| 1016 | match_len = self._common_prefix_len(child.label, tokens, index) |
| 1017 | if match_len < len(child.label): |
| 1018 | break |
| 1019 | node = child |
| 1020 | index += match_len |
| 1021 | candidates = node.tails if exact_only else node.sequences |
| 1022 | if candidates: |
| 1023 | longest_sequence_id = self._pick_sequence(candidates, preferred_sequences) |
| 1024 | longest_length = index |
| 1025 | return longest_sequence_id, longest_length |
| 1026 | |
| 1027 | |
| 1028 | class SequenceHistory: |
no test coverage detected