如何计算印地语单词?

时间:2017-07-21 19:19:40

标签: java word-count hindi

所以我试图为印地语制作一个词频图。我制作了一个程序来计算文本文件中的单词,然后显示某个单词出现的次数。但是,当我使用印地语时,它不起作用。我该如何处理?

import java.util.*;
import java.io.*;


public class WordCount {
    public static void main(String[] args) throws FileNotFoundException {
       // open the file
    Scanner console = new Scanner(System.in);
    System.out.print("What is the name of the text file? ");
    String fileName = console.nextLine();
    Scanner input = new Scanner(new File(fileName));

    // count occurrences
    Map<String, Integer> wordCounts = new TreeMap<String, Integer>();
    while (input.hasNext()) {
        String next = input.next().toLowerCase();
        if (!wordCounts.containsKey(next)) {
            wordCounts.put(next, 1);
        } else {
            wordCounts.put(next, wordCounts.get(next) + 1);
        }
    }

    // get cutoff and report frequencies
    System.out.println("Total words = " + wordCounts.size());
    System.out.print("Minimum number of occurrences for printing? ");
    int min = console.nextInt();
    for (String word : wordCounts.keySet()) {
        int count = wordCounts.get(word);
        if (count >= min)
            System.out.println(count + "\t" + word);
    }
}
}


input text file: dad mom world
Output
What is the name of the text file? practice.txt
Total words = 3
Minimum number of occurrences for printing? 1
1   mom
1   world
1   dad

1 个答案:

答案 0 :(得分:0)

您需要指定编码。只需改变你的行

Fragment fragment = getFragmentManager().findFragmentById(R.id.fragment_id);

    if(fragment!=null)
    {
        getFragmentManager()
                .beginTransaction()
                .addToBackStack(null)
                .commit();
    }

Scanner input = new Scanner(new File(fileName));