Sei sulla pagina 1di 2

Listings

1 Sample program in Matlab . . . . . . . . . . . . . . . . . . . . . 1


2 Sample program in SQL . . . . . . . . . . . . . . . . . . . . . . . 2
3 Another program in java . . . . . . . . . . . . . . . . . . . . . . . 3

1
Listing 1: Another program in java
package wcmr.hadoop.training.it.bec;

import java.io.IOException;
import java.util.StringTokenizer;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;

public class WCMR {

public static class WordCountMapper extends


Mapper<LongWritable, Text, Text, IntWritable> {
protected String delimeters = " ,
.;:\"&!?-_\n\t12345678910[]{}<>\\~|=^()@#$%^*/+-";
protected static boolean caseSensitive = false;

public void map(LongWritable recadd, Text rec, Context con)


throws IOException, InterruptedException {
String line = (caseSensitive) ? rec.toString() :
rec.toString().toLowerCase();
StringTokenizer tokenizer = new StringTokenizer(line,
delimeters);
while (tokenizer.hasMoreTokens()) {
con.write(new Text(tokenizer.nextToken()), new
IntWritable(1));

Potrebbero piacerti anche