用JAVA语言设计一个类,统计一篇英文文章的词频,并按照词频由高到低输出.修改下面代码就行了.
public class Article {
//保存文章的内容
String content;
//保存分割后的单词集合
String[] rawWords;
//保存统计后的单词集合
String[] words;
//保存单词对应的词频
int[] wordFreqs;
//构造函数,输入文章内容
//提高部分:从文件中读取
public Article()
{
content="kolya is one of the richest films i've seen in some time .zdenek sverak plays a confirmed old bachelor ( who's likely to remain so ) ,who finds his life as a czech cellist increasingly impacted by the five-year old boy that he's taking care of .though it ends rather abruptly-- and i'm whining ,'cause i wanted to spend more time with these characters-- the acting ,writing ,and production values are as high as ,if not higher than ,comparable american dramas .this father-and-son delight-- sverak also wrote the script ,while his son ,jan ,directed-- won a golden globe for best foreign language film and ,a couple days after i saw it ,walked away an oscar .in czech and russian ,with english subtitles .";
}
//对文章根据分隔符进行分词,将结果保存到rawWords数组中
public void splitWord()
{
}
//统计词,遍历数组
public void countWordFreq()
{
}
//根据词频,将词数组和词频数组进行降序排序
public void sort()
{
}
//将排序结果输出
public void printResult()
{
}
public static void main(String[] args)
{
//测试类的功能
}
}
(2)在上面的基础上完成从文件夹中读取所有文章,输出每篇文章词频最高的10个词.
作业帮用户2017-09-27举报