def load_fdist_from_str(line):
    """
    Load a frequency dictionary from a line of identifier, frequecy pairs,
    e.g. S 10 NP 5 VP 5 ...
    """
    fdist = {}
    tokens = line.strip().split()
    nPair = int(len(tokens)/2)
    assert len(tokens) % 2 == 0
    for i in range(nPair):
        identifier = tokens[i*2]
        freq = float(tokens[i*2+1])
        fdist[identifier] = freq
    return fdist