单词频率分布 [英] Frequency distribution of words

查看:234
本文介绍了单词频率分布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看了两个TXT文件的话。

I have read in two txt files with words.

现在我想知道如何计算这两个字符串的频率分布。我的想法是把它们放进一个数组,并将它们分割; 。然而,如何计算出的频率分布?

Now I was wondering how to calculate the frequency distribution of these two Strings. My idea is to put them into an array and split them by ;. However, how to calculated the frequency distribution?

我AP preciate您的答复!

I appreciate your reply!

推荐答案

样品code是这样的:

Sample code is something like this:

    String str1 = "java;python;javascript;programming;Hello;World;Hello";
    String str2 = "java;python;javascript;programming;Hello;World;Hello";

    List<String> list = new ArrayList<String>();
    list.addAll(Arrays.asList(str1.split(";")));
    list.addAll(Arrays.asList(str2.split(";")));

    for (String word : list) 
        System.out.println(word + " --> " + Collections.frequency(list,word));

这篇关于单词频率分布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆