Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

To gain experience with string objects. To gain experience with generic algorith

ID: 3784261 • Letter: T

Question

To gain experience with string objects. To gain experience with generic algorithms. To gain experience with files-opening for input and output. Explain the purpose of the program as detail as possible -8%. Develop a solution for the problem and mention algorithms to be used -12% List data structures to be used in solution.-5%. Give a description of how to use the program and expected input/output -5% Explain the purpose of each class you develop in the program. -5%. Program execution according to the requirements given 60% Naming of program as required 5% You are to write a program name wordcount.java that prompt the user for a user input file name, reads the input words and do the following with those words: Count the amount of words in the file. A word can end with any of the following: space (single or multiple), an EOLN character or a punctuation mark (which will be part of the word). Count the amount of lines in the file. Count the amount of alphanumeric characters in the file. Count the number of sentences in the file. Count the amount of vowels in the file-only a, e, i, o, u (lower and upper case) are vowels. Count the amount of punctuations in the file. You must output the above information both on the screen as well as an output file name "output.txt". The program must work even if the input file is empty. If this is the case print a message saying that "the input file is empty" and then terminate the program. Use as many generic algorithm as possible so that the size of the program can be reduced.

Explanation / Answer

import java.io.IOException;

import java.util.*;

       

import org.apache.hadoop.fs.Path;

import org.apache.hadoop.conf.*;

import org.apache.hadoop.io.*;

import org.apache.hadoop.mapreduce.*;

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;

       

public class WordCount {

       

public static class Map extends Mapper {

    private final static IntWritable IntWritable(1);

    private Text word = new Text();

       

    public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {

        String line = value.toString();

        StringTokenizer tokenizer = new StringTokenizer(line);

        while (tokenizer.hasMoreTokens()) {

            word.set(tokenizer.nextToken());

            context.write(word, one);

        }

    }

}

       

public static class Reduce extends Reducer {

    public void reduce(Text key, Iterable values, Context context)

      throws IOException, InterruptedException {

        int sum = 0;

        for (IntWritable val : values) {

            sum += val.get();

        }

        context.write(key, new IntWritable(sum));

    }

}

       

public static void main(String[] args) throws Exception {

    Configuration conf = new Configuration();

       

        Job job = new Job(conf, "wordcount");

   

    job.setOutputKeyClass(Text.class);

    job.setOutputValueClass(IntWritable.class);

       

    job.setMapperClass(Map.class);

    job.setReducerClass(Reduce.class);

       

    job.setInputFormatClass(TextInputFormat.class);

    job.setOutputFormatClass(TextOutputFormat.class);

       

    FileInputFormat.addInputPath(job, new Path(args[0]));

    FileOutputFormat.setOutputPath(job, new Path(args[1]));

       

    job.waitForCompletion(true);

}

       

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote