You are given tokenized training sentences and queries of the form (word, r), where 0 <= r < 1 is a pre-generated random number. For each word, count how often each immediate follower appears. Keep the distinct followers in the order they were first seen after that word. If the follower counts are c1, c2, ..., ck with total T, then choose follower i when r falls in the interval [sum of previous counts / T, sum through i / T). Return None if the word never appears with a follower. This deterministic interface simulates random prediction according to empirical frequencies.
Examples
Input: ([['I', 'am', 'Sam'], ['Sam', 'I', 'am'], ['I', 'like', 'green', 'eggs', 'and', 'ham']], [('I', 0.0), ('I', 0.8), ('Sam', 0.2), ('ham', 0.3), ('missing', 0.1)])
Expected Output: ['am', 'like', 'I', None, None]
Explanation: For I, the follower counts are am: 2 and like: 1, in that order. So [0, 2/3) maps to am and [2/3, 1) maps to like.
Input: ([['a', 'x'], ['a', 'y'], ['a', 'y'], ['a', 'x']], [('a', 0.49), ('a', 0.5), ('x', 0.1)])
Expected Output: ['x', 'y', None]
Explanation: After a, x and y both have count 2. Because x appeared first, the intervals are x on [0, 0.5) and y on [0.5, 1).
Input: ([[], ['solo']], [('solo', 0.2), ('anything', 0.9)])
Expected Output: [None, None]
Explanation: No adjacent pairs exist, so every query returns None.
Input: ([['go', 'left', 'go', 'right', 'go', 'left']], [('go', 0.2), ('go', 0.9), ('left', 0.0), ('right', 0.0)])
Expected Output: ['left', 'right', 'go', 'go']
Explanation: For go, left has count 2 and right has count 1, so left covers the first two thirds of the interval and right covers the last third.