Skip to content

Commit 4e18129

Browse files
committed
initial commit
0 parents  commit 4e18129

File tree

35 files changed

+720
-0
lines changed

35 files changed

+720
-0
lines changed

build.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
subprojects {
2+
afterEvaluate {
3+
repositories {
4+
jcenter()
5+
}
6+
}
7+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
plugins {
2+
id 'java-library'
3+
id 'org.gradle.java.experimental-jigsaw' version '0.1.1' // <1>
4+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package javamodularity.easytext.algorithm.api;
2+
3+
import java.util.List;
4+
5+
public interface Analyzer {
6+
7+
String getName();
8+
9+
double analyze(List<List<String>> text);
10+
11+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package javamodularity.easytext.algorithm.api;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class Preprocessing {
7+
8+
public static List<List<String>> toSentences(String text) {
9+
String removedBreaks = text.replaceAll("\\r?\\n", " ");
10+
ArrayList<List<String>> sentences = new ArrayList<>();
11+
for(String rawSentence: removedBreaks.split("[\\.\\?\\!]")) {
12+
List<String> words = toWords(rawSentence);
13+
if(words.size() > 0) {
14+
sentences.add(words);
15+
}
16+
}
17+
18+
return sentences;
19+
}
20+
21+
public static List<String> toWords(String sentence) {
22+
String[] rawWords = sentence.split("\\s+");
23+
List<String> words = new ArrayList<>();
24+
for(String rawWord: rawWords) {
25+
String word = rawWord.replaceAll("\\W", "");
26+
if(word.length() > 0) {
27+
words.add(word);
28+
}
29+
}
30+
31+
return words;
32+
}
33+
34+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package javamodularity.easytext.algorithm.api;
2+
3+
public interface SyllableCounter {
4+
int countSyllables(String word);
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module easytext.algorithm.api {
2+
3+
exports javamodularity.easytext.algorithm.api;
4+
5+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
plugins {
2+
id 'java-library'
3+
id 'org.gradle.java.experimental-jigsaw' version '0.1.1' // <1>
4+
}
5+
6+
dependencies {
7+
compile project(':easytext.algorithm.api')
8+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
<orderEntry type="module" module-name="easytext.algorithm.api" />
11+
</component>
12+
</module>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package javamodularity.easytext.algorithm.coleman;
2+
3+
import java.util.List;
4+
import java.util.concurrent.TimeUnit;
5+
6+
import javamodularity.easytext.algorithm.api.Analyzer;
7+
8+
public class ColemanAnalyzer implements Analyzer {
9+
10+
public String getName() {
11+
return "Coleman-Liau";
12+
}
13+
14+
public double analyze(List<List<String>> sentences) {
15+
float totalsentences = sentences.size();
16+
float words = sentences.stream().mapToInt(sentence -> sentence.size()).sum();
17+
float letters = sentences.stream().flatMapToInt(sentence -> sentence.stream().mapToInt(word -> word.length())).sum();
18+
try {
19+
TimeUnit.SECONDS.sleep(1);
20+
} catch (InterruptedException e) {
21+
e.printStackTrace();
22+
}
23+
return 0.0588 * (letters / (words / 100)) - 0.296 * (totalsentences / (words / 100)) - 15.8;
24+
}
25+
}

0 commit comments

Comments
 (0)