@@ -0,0 +1,2465 @@
+/**%0A* WordCounter example%0A*%0A* @author Eleftherios Anagnostopoulos%0A* @since 2014-12-15%0A*%0A*/%0A%0Aimport java.io.File;%0Aimport java.io.FileNotFoundException;%0Aimport java.util.ArrayList;%0Aimport java.util.Map;%0Aimport java.util.Scanner;%0A%0Apublic class WordCounter extends MapReduceFramework %7B%0A%0A    public void map(final File fileEntry, Map%3CString, ArrayList%3CString%3E%3E map) %7B%0A        Scanner sc = null;%0A        String key = null;%0A%0A        try %7B%0A            if (fileEntry.isFile()) %7B%0A                sc = new Scanner(fileEntry);%0A%0A                while (sc.hasNext()) %7B%0A                    key = stemEntry(sc.next().toLowerCase());%0A                    mapHelp(map, key, %221%22);%0A                %7D%0A                sc.close();%0A            %7D%0A        %7D%0A        catch (FileNotFoundException e) %7B%0A            e.printStackTrace();%0A        %7D%0A        finally %7B%0A            if (sc != null) %7B%0A                sc.close();%0A            %7D%0A        %7D%0A    %7D%0A%0A    public void mapHelp(Map%3CString, ArrayList%3CString%3E%3E map, String key, String value) %7B%0A%0A        ArrayList%3CString%3E values = map.get(key);%0A%0A        if (values == null) %7B%0A            values = new ArrayList%3CString%3E();%0A            values.add(value);%0A            map.put(key, values);%0A        %7D%0A        else %7B%0A            values.add(value);%0A        %7D%0A    %7D%0A%0A    /* Removes characters that are not included in %5Ba..z%5D or %5B0..9%5D */%0A    public String stemEntry(String word) %7B%0A        String new_word = %22%22;%0A        Character c;%0A%0A        for (int i = 0; i %3C word.length(); i++) %7B%0A            c = word.charAt(i);%0A%0A            if ((c %3E= 'a' && c %3C= 'z') %7C%7C (c %3E= '0' && c %3C= '9')) %7B%0A                new_word = new_word + c;%0A            %7D%0A        %7D%0A        return new_word;%0A    %7D%0A%0A    public void reduce(String key, ArrayList%3CString%3E value) %7B%0A        Integer new_value = 0;%0A%0A        for (int i = 0; i %3C value.size(); i++) %7B%0A            new_value = new_value + Integer.parseInt(value.get(i));%0A        %7D%0A        synchronized (reducing_output) %7B%0A            reducing_output.put(key, new_value.toString());%0A        %7D%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A%0A        if (args.length != 4) %7B%0A            System.err.println(%22Usage: java WordCounter input_directory output_directory %22%0A                             + %22number_of_mapper_threads number_of_reducer_threads%22);%0A            System.exit(1);%0A        %7D%0A        WordCounter wc = new WordCounter();%0A        wc.driver(args%5B0%5D, args%5B1%5D, Integer.parseInt(args%5B2%5D), Integer.parseInt(args%5B3%5D));%0A    %7D%0A%7D%0A

Create WordCounter.java