Skip to content

Commit

Permalink
further refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
kennycason committed Jun 2, 2017
1 parent 147116c commit 812f659
Show file tree
Hide file tree
Showing 35 changed files with 1,608 additions and 225 deletions.
1,420 changes: 1,420 additions & 0 deletions KumoIntelliJInspections.xml

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion README.md
Expand Up @@ -4,6 +4,8 @@ Kumo's goal is to create a powerful and user friendly Word Cloud API in Java. Ku

Please feel free to jump in and help improve Kumo! There are many places for performance optimization in Kumo!

[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.kennycason/kumo/badge.svg?style=flat)](https://maven-badges.herokuapp.com/maven-central/com.kennycason/kumo)<br/>

### Current Features

- Draw Rectangle, Circle or Image Overlay word clouds. Image Overlay will draw words over all non-transparent pixels.
Expand All @@ -26,7 +28,7 @@ Please feel free to jump in and help improve Kumo! There are many places for per
<dependency>
<groupId>com.kennycason</groupId>
<artifactId>kumo</artifactId>
<version>1.8</version>
<version>1.9</version>
</dependency>
```

Expand Down Expand Up @@ -382,3 +384,8 @@ Create a layered word cloud
```
kumo --input "https://www.haskell.org/, https://en.wikipedia.org/wiki/Haskell_(programming_language)" --output "/tmp/nintendo_vs_playstation.png" --type layered --background "https://raw.githubusercontent.com/kennycason/kumo/master/src/test/resources/backgrounds/haskell_1.bmp,https://raw.githubusercontent.com/kennycason/kumo/master/src/test/resources/backgrounds/haskell_2.bmp" --color "(0xFA6C07),(0xFF7614),(0xFF8936)|(0x080706),(0x3B3029),(0x47362A)"
```


### Contributing

My primary IDE of choice is IntelliJ due to their robust tooling as well as code analysis/inspections. If using [IntelliJ IDEA](https://www.jetbrains.com/idea/), I recommend importing `KumoIntelliJInspections.xml`. I am also consiering adding Checkstyle support.

This file was deleted.

43 changes: 35 additions & 8 deletions kumo-cli/pom.xml
Expand Up @@ -11,21 +11,27 @@

<artifactId>kumo-cli</artifactId>

<properties>
<cli.main.class>com.kennycason.kumo.cli.KumoCli</cli.main.class>
</properties>

<dependencies>
<dependency>
<groupId>com.kennycason</groupId>
<artifactId>kumo-api</artifactId>
<version>1.9</version>
<artifactId>kumo-core</artifactId>
</dependency>
<dependency>
<groupId>com.kennycason</groupId>
<artifactId>kumo-nlp</artifactId>
<version>1.9</version>
</dependency> <dependency>
<groupId>com.kennycason</groupId>
<artifactId>kumo-core</artifactId>
<version>1.9</version>
<artifactId>kumo-tokenizers</artifactId>
</dependency>

<!-- third party -->
<dependency>
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
</dependency>

<!-- test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand All @@ -51,9 +57,30 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>

<!-- for cli executable -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>${cli.main.class}</Main-Class>
</manifestEntries>
</transformer>
</transformers>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand Down
4 changes: 2 additions & 2 deletions kumo-cli/src/main/java/com/kennycason/kumo/cli/KumoCli.java
Expand Up @@ -18,10 +18,10 @@
import com.kennycason.kumo.font.scale.SqrtFontScalar;
import com.kennycason.kumo.nlp.FrequencyAnalyzer;
import com.kennycason.kumo.nlp.normalize.*;
import com.kennycason.kumo.nlp.tokenizer.ChineseWordTokenizer;
import com.kennycason.kumo.nlp.tokenizer.EnglishWordTokenizer;
import com.kennycason.kumo.nlp.tokenizer.WhiteSpaceWordTokenizer;
import com.kennycason.kumo.nlp.tokenizer.WordTokenizer;
import com.kennycason.kumo.nlp.tokenizers.ChineseWordTokenizer;
import com.kennycason.kumo.nlp.tokenizers.EnglishWordTokenizer;
import com.kennycason.kumo.palette.ColorPalette;
import com.kennycason.kumo.wordstart.CenterWordStart;
import com.kennycason.kumo.wordstart.RandomWordStart;
Expand Down
Expand Up @@ -19,11 +19,11 @@ public class ParenthesisSerializer {
public static <T> String serialize(final Collection<T> collection) {
if (collection.isEmpty()) { return ""; }

String joined = collection.stream()
.map(i -> i.toString())
.collect(Collectors.joining("),("));
final String joined = collection.stream()
.map(i -> i.toString())
.collect(Collectors.joining("),("));

return "(" + joined + ")";
return '(' + joined + ')';
}

public static List<String> deserialize(final String value) {
Expand Down
28 changes: 15 additions & 13 deletions kumo-cli/src/test/java/com/kennycason/kumo/cli/KumoCliITest.java
@@ -1,23 +1,21 @@
package com.kennycason.kumo.cli;

import com.kennycason.kumo.IntegrationTest;
import org.junit.Ignore;
import org.junit.experimental.categories.Category;
import org.junit.Test;

/**
* Created by kenny on 6/12/16.
*/
@Category(IntegrationTest.class)
@Ignore
public class KumoCliITest {

@Test
public void simple() {
KumoCli.main(new String[] {
"--input", "https://en.wikipedia.org/wiki/Nintendo",
"--output", "/tmp/nintendo.png"
});
}

@Test
public void stopwords() {
KumoCli.main(new String[] {
"--input", "https://en.wikipedia.org/wiki/Nintendo",
Expand All @@ -26,6 +24,7 @@ public void stopwords() {
});
}

@Test
public void wordCount() {
KumoCli.main(new String[] {
"--input", "https://en.wikipedia.org/wiki/Nintendo",
Expand All @@ -34,6 +33,7 @@ public void wordCount() {
});
}

@Test
public void widthAndHeight() {
KumoCli.main(new String[] {
"--input", "https://en.wikipedia.org/wiki/Nintendo",
Expand All @@ -43,6 +43,7 @@ public void widthAndHeight() {
});
}

@Test
public void randomWordStart() {
KumoCli.main(new String[] {
"--input", "https://en.wikipedia.org/wiki/Nintendo",
Expand All @@ -51,6 +52,7 @@ public void randomWordStart() {
});
}

@Test
public void font() {
KumoCli.main(new String[] {
"--input", "https://en.wikipedia.org/wiki/Nintendo",
Expand All @@ -63,7 +65,7 @@ public void font() {
});
}


@Test
public void normalizer() {
KumoCli.main(new String[] {
"--input", "https://en.wikipedia.org/wiki/Nintendo",
Expand All @@ -72,7 +74,7 @@ public void normalizer() {
});
}


@Test
public void backgroundImage() {
KumoCli.main(new String[] {
"--input", "https://en.wikipedia.org/wiki/Nintendo",
Expand All @@ -83,7 +85,7 @@ public void backgroundImage() {
});
}


@Test
public void colorRgb() {
KumoCli.main(new String[] {
"--input", "https://en.wikipedia.org/wiki/Nintendo",
Expand All @@ -92,7 +94,7 @@ public void colorRgb() {
});
}


@Test
public void colorRgbHex() {
KumoCli.main(new String[] {
"--input", "https://en.wikipedia.org/wiki/Nintendo",
Expand All @@ -101,7 +103,7 @@ public void colorRgbHex() {
});
}


@Test
public void colorHex() {
KumoCli.main(new String[] {
"--input", "https://en.wikipedia.org/wiki/Nintendo",
Expand All @@ -110,7 +112,7 @@ public void colorHex() {
});
}


@Test
public void chinese() {
KumoCli.main(new String[] {
"--input", "https://zh.wikipedia.org/wiki/%E4%BB%BB%E5%A4%A9%E5%A0%82",
Expand All @@ -119,7 +121,7 @@ public void chinese() {
});
}


@Test
public void polar() {
KumoCli.main(new String[] {
"--input", "https://en.wikipedia.org/wiki/Nintendo, https://en.wikipedia.org/wiki/PlayStation",
Expand All @@ -129,7 +131,7 @@ public void polar() {
});
}


@Test
public void layered() {
KumoCli.main(new String[] {
"--input", "https://www.haskell.org/, https://en.wikipedia.org/wiki/Haskell_(programming_language)",
Expand Down
22 changes: 7 additions & 15 deletions kumo-core/pom.xml
Expand Up @@ -15,19 +15,17 @@
<dependency>
<groupId>com.kennycason</groupId>
<artifactId>kumo-api</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>com.kennycason</groupId>
<artifactId>kumo-nlp</artifactId>
<version>1.9</version>
<scope>test</scope>
</dependency>

<!--3rd party -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
Expand All @@ -36,14 +34,12 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
</dependency>
<dependency>
<groupId>com.github.davidmoten</groupId>
<artifactId>rtree</artifactId>
</dependency>

<!-- test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand All @@ -65,10 +61,6 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Expand Up @@ -12,8 +12,6 @@
import com.kennycason.kumo.font.scale.LinearFontScalar;
import com.kennycason.kumo.font.scale.SqrtFontScalar;
import com.kennycason.kumo.nlp.FrequencyAnalyzer;
import com.kennycason.kumo.nlp.tokenizer.ChineseWordTokenizer;
import com.kennycason.kumo.palette.ColorPalette;
import org.apache.commons.io.IOUtils;
import org.apache.log4j.Logger;
import org.junit.Test;
Expand Down Expand Up @@ -98,36 +96,6 @@ public void newyorkPolarRectangle() throws IOException {
}

@Test
public void chineseVsEnglishTideComments() throws IOException {
final FrequencyAnalyzer frequencyAnalyzer = new FrequencyAnalyzer();
frequencyAnalyzer.setWordFrequenciesToReturn(750);
frequencyAnalyzer.setMinWordLength(3);
frequencyAnalyzer.setStopWords(loadStopWords());
final List<WordFrequency> wordFrequencies = frequencyAnalyzer.load(getInputStream("text/english_tide.txt"));

final FrequencyAnalyzer chineseFrequencyAnalyzer = new FrequencyAnalyzer();
chineseFrequencyAnalyzer.setWordFrequenciesToReturn(750);
chineseFrequencyAnalyzer.setMinWordLength(2);
chineseFrequencyAnalyzer.setWordTokenizer(new ChineseWordTokenizer());
final List<WordFrequency> wordFrequencies2 = chineseFrequencyAnalyzer.load(getInputStream("text/chinese_tide.txt"));

final Dimension dimension = new Dimension(800, 600);
final PolarWordCloud wordCloud = new PolarWordCloud(dimension, CollisionMode.PIXEL_PERFECT, PolarBlendMode.BLUR);
wordCloud.setPadding(2);
wordCloud.setBackground(new RectangleBackground(dimension));
wordCloud.setFontScalar(new SqrtFontScalar(10, 70));

final ColorPalette colorPalette = new ColorPalette(new Color(0xD5CFFA), new Color(0xBBB1FA), new Color(0x9A8CF5), new Color(0x806EF5));
final ColorPalette colorPalette2 = new ColorPalette(new Color(0xFA8E8E), new Color(0xF77979), new Color(0xF55F5F), new Color(0xF24949));
wordCloud.setColorPalette(colorPalette);
wordCloud.setColorPalette2(colorPalette2);

final long startTime = System.currentTimeMillis();
wordCloud.build(wordFrequencies, wordFrequencies2);
LOGGER.info("Took " + (System.currentTimeMillis() - startTime) + "ms to build");
wordCloud.writeToFile("output/polar_tide_chinese_vs_english2.png");
}

public void tidyCatLitter() throws IOException {
final FrequencyAnalyzer frequencyAnalyzer = new FrequencyAnalyzer();
frequencyAnalyzer.setWordFrequenciesToReturn(400);
Expand Down

0 comments on commit 812f659

Please sign in to comment.