请实现一个程序统计文本内的单词词频,同时提供一个sample方法,对文本内的单词进行采样。采样应符合一个离散分布,该分布的概率密度函数即为文本内的单词词频分布。假设输入为一个文本文件,文件内单词之间由空格分隔。
测试样例
输入:
make america great again
donald trump is the new president of the united states of america
输出:
sample方法应以1/8的概率返回单词"america", 'the', 'of', 以1/16的概率返回其他单词
给定API,可产生sample:rand(a, b) -> [a, b)
测试样例
输入:
make america great again
donald trump is the new president of the united states of america
输出:
sample方法应以1/8的概率返回单词"america", 'the', 'of', 以1/16的概率返回其他单词
给定API,可产生sample:rand(a, b) -> [a, b)