-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
129 lines (103 loc) · 4.75 KB
/
Copy pathMain.java
File metadata and controls
129 lines (103 loc) · 4.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//STEPS - STAGE 2
//Separate into sentences
//Find no of words in each sentence
//Find average
//output
//STEPS - STAGE 3
//Read a text file from command line
//Calculate number of characters,words,sentences
//Calculate score
//Calculate age
//STEPS - STAGE 4
// Count number of syllables
// Flesch test
// SMOG
// Coleman
// User interface
package read;
import java.io.*;
import java.text.BreakIterator;
import java.util.*;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class Main {
public static int no_syllables = 0;
public static int no_poly = 0;
public static int total_words = 0;
public static int total_characters = 0;
public static int no_sentences = 0;
public static void main(String[] args) {
File file = new File(args[0]);
try {
Scanner in = new Scanner(file);
Scanner uin = new Scanner(System.in);
System.out.println("The text is");
while(in.hasNext())
{
String txt = in.nextLine();
System.out.print(txt);
BreakIterator bi = BreakIterator.getSentenceInstance();
bi.setText(txt);
int index = 0;
while (bi.next() != BreakIterator.DONE) {
String sentence = txt.substring(index, bi.current());
total_words += analyzeData.num_words(sentence);
total_characters += analyzeData.num_char(sentence);
++no_sentences;
index = bi.current();
}
}
System.out.println("");
System.out.println("Words: " + total_words);
System.out.println("Sentences: " + no_sentences);
System.out.println("Characters: "+ total_characters);
System.out.println("Syllables: "+ no_syllables);
System.out.println("Poly syllables: "+ no_poly);
System.out.println("Enter the score you want to calculate(ARI, FK, SMOG, CL, all): ");
String user_ip = uin.nextLine();
double score=0;
double tot_age = 0;
if(user_ip.equalsIgnoreCase("ARI"))
{
score = ReadabilityMethods.ari();
System.out.println("Automated Readability Index: "+String.format("%.2f",score)+"(about "+analyzeData.agefind((int)score)+ " year olds).");
}
else if(user_ip.equalsIgnoreCase("FK"))
{
score = ReadabilityMethods.fk();
System.out.println("Flesch-Kincaid readability tests: "+String.format("%.2f",score)+"(about "+analyzeData.agefind((int)score)+ " year olds).");
}
else if(user_ip.equalsIgnoreCase("SMOG"))
{
score = ReadabilityMethods.smog();
System.out.println("Simple Measure of Gobbledygook: "+String.format("%.2f",score)+"(about "+analyzeData.agefind((int)score)+ " year olds).");
}
else if(user_ip.equalsIgnoreCase("CL"))
{
score = ReadabilityMethods.cl();
System.out.println("Coleman-Liau index: "+String.format("%.2f",score)+"(about "+analyzeData.agefind((int)score)+ " year olds).");
}
else if(user_ip.equalsIgnoreCase("all"))
{
score = ReadabilityMethods.ari();
tot_age = tot_age+Integer.parseInt(analyzeData.agefind((int)score));
System.out.println("Automated Readability Index: "+String.format("%.2f",score)+"(about "+analyzeData.agefind((int)score)+ " year olds).");
score = ReadabilityMethods.fk();
tot_age = tot_age+Integer.parseInt(analyzeData.agefind((int)score));
System.out.println("Flesch–Kincaid readability tests: "+String.format("%.2f",score)+"(about "+analyzeData.agefind((int)score)+ " year olds).");
score = ReadabilityMethods.smog();
tot_age = tot_age+Integer.parseInt(analyzeData.agefind((int)score));
System.out.println("Simple Measure of Gobbledygook: "+String.format("%.2f",score)+"(about "+analyzeData.agefind((int)score)+ " year olds).");
score = ReadabilityMethods.cl();
tot_age = tot_age+Integer.parseInt(analyzeData.agefind((int)score));
System.out.println("Coleman–Liau index: "+String.format("%.2f",score)+"(about "+analyzeData.agefind((int)score)+ " year olds).");
double avg_age = tot_age/4;
System.out.println("This text should be understood by "+ String.format("%.2f",avg_age) +" year olds.");
}
}
catch (FileNotFoundException f)
{
System.out.println("File not found");
}
}
}