diff --git a/2017-big-data.iml b/2017-big-data.iml
new file mode 100644
index 0000000..e1dd04d
--- /dev/null
+++ b/2017-big-data.iml
@@ -0,0 +1,79 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/answers.txt b/answers.txt
index 00fa802..6659395 100644
--- a/answers.txt
+++ b/answers.txt
@@ -1,3 +1,3 @@
-2. is 126420
-3. 41.602
-4. french 5742
+2. was 18391755
+3. 37.164249490179486
+4. October 1072615
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 16acaa5..fc61ac2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,7 +1,7 @@
4.0.0
- pritykovskaya
+ tFNiYaFF
2017-big-data
jar
1.0-SNAPSHOT
@@ -29,7 +29,7 @@
- pritykovskaya.WordCount
+ tFNiYaFF.Main
@@ -38,8 +38,8 @@
org.apache.maven.plugins
maven-compiler-plugin
- 1.6
- 1.6
+ 1.7
+ 1.7
diff --git a/report.txt b/report.txt
new file mode 100644
index 0000000..3509248
--- /dev/null
+++ b/report.txt
@@ -0,0 +1,14 @@
+ 1
+2900,292s - wordcount
+
+ 2
+36,356s -
+6,076s - 7-
+
+ 3
+78,431s - -
+
+ 4
+78,385s -
+6,072s -
+1,048s - 5- (5 => 0 to 4)
\ No newline at end of file
diff --git a/src/main/java/pritykovskaya/WordCount.java b/src/main/java/pritykovskaya/WordCount.java
deleted file mode 100644
index b047511..0000000
--- a/src/main/java/pritykovskaya/WordCount.java
+++ /dev/null
@@ -1,80 +0,0 @@
-package pritykovskaya;
-
-
-import java.io.IOException;
-import java.util.StringTokenizer;
-
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.conf.Configured;
-import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.io.IntWritable;
-import org.apache.hadoop.io.LongWritable;
-import org.apache.hadoop.io.Text;
-import org.apache.hadoop.mapreduce.Job;
-import org.apache.hadoop.mapreduce.Mapper;
-import org.apache.hadoop.mapreduce.Reducer;
-import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
-import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
-import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
-import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
-import org.apache.hadoop.util.Tool;
-import org.apache.hadoop.util.ToolRunner;
-
-
-public class WordCount extends Configured implements Tool {
-
- public static class MyMapper extends Mapper {
- private static final IntWritable ONE = new IntWritable(1);
- private final transient Text word = new Text();
-
- @Override public void map(final LongWritable key, final Text value, final Context context)
- throws IOException, InterruptedException {
- final String line = value.toString();
- final StringTokenizer tokenizer = new StringTokenizer(line);
- while (tokenizer.hasMoreTokens()) {
- word.set(tokenizer.nextToken());
- context.write(word, ONE);
- }
- }
- }
-
-
- public static class MyReducer extends Reducer {
-
- @Override
- public void reduce(final Text key, final Iterable values, final Context context)
- throws IOException, InterruptedException {
- int sum = 0;
- for (final IntWritable val : values) {
- sum += val.get();
- }
- context.write(key, new IntWritable(sum));
- }
- }
-
-
- @Override public int run(final String[] args) throws Exception {
- final Configuration conf = this.getConf();
- final Job job = Job.getInstance(conf, "Word Count");
- job.setJarByClass(WordCount.class);
-
- job.setMapperClass(MyMapper.class);
- job.setReducerClass(MyReducer.class);
-
- job.setOutputKeyClass(Text.class);
- job.setOutputValueClass(IntWritable.class);
-
- job.setInputFormatClass(TextInputFormat.class);
- job.setOutputFormatClass(TextOutputFormat.class);
-
- FileInputFormat.addInputPath(job, new Path(args[0]));
- FileOutputFormat.setOutputPath(job, new Path(args[1]));
-
- return job.waitForCompletion(true) ? 0 : 1;
- }
-
- public static void main(final String[] args) throws Exception {
- final int returnCode = ToolRunner.run(new Configuration(), new WordCount(), args);
- System.exit(returnCode);
- }
-}
diff --git a/src/main/java/tFNiYaFF/Main.java b/src/main/java/tFNiYaFF/Main.java
new file mode 100644
index 0000000..3a8f8fb
--- /dev/null
+++ b/src/main/java/tFNiYaFF/Main.java
@@ -0,0 +1,105 @@
+package tFNiYaFF;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.util.Tool;
+import org.apache.hadoop.util.ToolRunner;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
+
+public class Main {
+ private static final String FILE_REPORT = "report.txt";
+
+ public static void main(String[] args) throws Exception {
+ String inputDirectory = "input";
+ String wordcountDirectory = "output-wordcount";
+ String orderedDirectory = "output-ordered";
+ String task2OutputDirectory = "output-7-word";
+ String task3OutputDirectory = "output-stopwordscount";
+ String namesDirectory = "output-names";
+ String namesOrderedDirectory = "output-ordered-names";
+ String task4OutputDirectory = "output-5-name";
+
+ Report task1 = new Report("Задание 1")
+ .addAction(
+ "Считаем wordcount",
+ calculateTaskTime(new WordCount(), inputDirectory, wordcountDirectory)
+ );
+
+ Report task2 = new Report("Задание 2")
+ .addAction(
+ "Сортируем слова",
+ calculateTaskTime(new WordsOrder(), wordcountDirectory, orderedDirectory)
+ )
+ .addAction(
+ "Вывод только 7-го слова",
+ calculateTaskTime(new NValue(), orderedDirectory, task2OutputDirectory, "6")
+ );
+
+ Report task3 = new Report("Задание 3")
+ .addAction(
+ "Считаем процент стоп-слов",
+ calculateTaskTime(new StopWordsCount(), wordcountDirectory, task3OutputDirectory, "stop_words_en.txt")
+ );
+ Report task4 = new Report("Задание 4")
+ .addAction(
+ "Находим имена и кладем их в папку",
+ calculateTaskTime(new NamesPercent(), wordcountDirectory, namesDirectory)
+ )
+ .addAction(
+ "Сортируем имена по убыванию частоты",
+ calculateTaskTime(new WordsOrder(), namesDirectory, namesOrderedDirectory)
+ )
+ .addAction(
+ "Выводим только 5-е имя (5 => 0 to 4)",
+ calculateTaskTime(new NValue(), namesOrderedDirectory, task4OutputDirectory, "4")
+ );
+
+
+ Files.write(
+ Paths.get(FILE_REPORT),
+ String.join(
+ "\r\n\r\n",
+ task1.getString(),
+ task2.getString(),
+ task3.getString(),
+ task4.getString()
+ ).getBytes()
+ );
+ }
+
+ private static double calculateTaskTime(Tool tool, String... parameters) throws Exception{
+ long from = System.currentTimeMillis();
+
+ ToolRunner.run(new Configuration(), tool, parameters);
+
+ long to = System.currentTimeMillis();
+ return (to - from)/(double)1000;
+ }
+
+ private static class Report {
+ private List stringList;
+
+ Report(String name) {
+ stringList = new ArrayList<>();
+ stringList.add(name);
+ }
+
+ Report addAction(String description, double time){
+ stringList.add(formatTimeWithText(time, description));
+
+ return this;
+ }
+
+ private String formatTimeWithText(double time, String text){
+ return String.format("%.3f", time) + "s" + " - " + text;
+ }
+
+ public String getString() throws IOException {
+ return String.join("\r\n", stringList);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/tFNiYaFF/NValue.java b/src/main/java/tFNiYaFF/NValue.java
new file mode 100644
index 0000000..c838b22
--- /dev/null
+++ b/src/main/java/tFNiYaFF/NValue.java
@@ -0,0 +1,117 @@
+package tFNiYaFF;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.conf.Configured;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.io.IntWritable;
+import org.apache.hadoop.io.Text;
+import org.apache.hadoop.mapreduce.Job;
+import org.apache.hadoop.mapreduce.Mapper;
+import org.apache.hadoop.mapreduce.Reducer;
+import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
+import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
+import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
+import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
+import org.apache.hadoop.util.Tool;
+import org.apache.hadoop.util.ToolRunner;
+
+import java.io.IOException;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+public class NValue extends Configured implements Tool {
+ private static int valueNumber;
+ private static IntWritable ONE = new IntWritable(1);
+
+ static class MyMapper extends Mapper