kennycason / kumo

Kumo - Java Word Cloud
http://kennycason.com/posts/2014-07-03-kumo-wordcloud.html
MIT License
617 stars 156 forks source link

chinese word can't be supported #73

Open bestchenwu opened 5 years ago

bestchenwu commented 5 years ago

I want to make a chinese word cloud,and the code is

public class ChineseAnalyzeTask {

public static void main(String[] args) throws IOException{
    final FrequencyAnalyzer frequencyAnalyzer = new FrequencyAnalyzer();
    frequencyAnalyzer.setWordFrequenciesToReturn(600);
    frequencyAnalyzer.setMinWordLength(2);
    frequencyAnalyzer.setWordTokenizer(new ChineseWordTokenizer());

    final List<WordFrequency> wordFrequencies = frequencyAnalyzer.load("D:\\test.txt");
    final Dimension dimension = new Dimension(600, 600);
    final WordCloud wordCloud = new WordCloud(dimension, CollisionMode.PIXEL_PERFECT);
    wordCloud.setPadding(2);
    wordCloud.setBackgroundColor(new Color(0x000000FF, true));
    wordCloud.setBackground(new CircleBackground(300));
    wordCloud.setColorPalette(new ColorPalette(new Color(0xD5CFFA), new Color(0xBBB1FA), new Color(0x9A8CF5), new Color(0x806EF5)));
    wordCloud.setFontScalar(new SqrtFontScalar(12, 45));
    wordCloud.build(wordFrequencies);
    //Font font = new java.awt.Font("STSong-Light", 2, 20);
    //wordCloud.setKumoFont(new KumoFont(font));
    wordCloud.setKumoFont(new KumoFont("simsun",FontWeight.PLAIN));
    wordCloud.writeToFile("D:\\kumo\\output\\chinese_language_circle.png");
}

}

When I run the program,The result is the underlying picture--chinese_language_circle.png

And I am sure,I have moved simsun.ttf to /jre/lib/fonts directory,like this:

kennycason commented 5 years ago

@bestchenwu could you upload the font file?

csmake commented 5 years ago
       final FrequencyAnalyzer frequencyAnalyzer = new FrequencyAnalyzer();
        frequencyAnalyzer.setWordFrequenciesToReturn(600);
        frequencyAnalyzer.setMinWordLength(2);
        frequencyAnalyzer.setWordTokenizer(new ChineseWordTokenizer());

        final List<WordFrequency> wordFrequencies = frequencyAnalyzer.load("词频汇总.txt");
        final Dimension dimension = new Dimension(600, 600);
        final WordCloud wordCloud = new WordCloud(dimension, CollisionMode.PIXEL_PERFECT);
        wordCloud.setPadding(2);
            KumoFont kumoFont = new KumoFont("simsun",FontWeight.PLAIN);
            wordCloud.setKumoFont(kumoFont);
        wordCloud.setBackground(new CircleBackground(300));
        wordCloud.setColorPalette(new ColorPalette(new Color(0xD5CFFA), new Color(0xBBB1FA), new Color(0x9A8CF5), new Color(0x806EF5)));
        wordCloud.setFontScalar(new SqrtFontScalar(12, 45));
        wordCloud.build(wordFrequencies);
        wordCloud.writeToFile("chinese_language_circle.png");