Я пытался написать программу tfidf, которая считывает четыре текстовых файла и предоставляет значения tfidf для биграмм, то есть пар слов. При этом я сталкиваюсь со следующей ошибкой
PhaseOne.java:23: error: cannot find symbol
String docName = ((FileSplit) context.getInputSplit()).getPath().getName().toString();
^
symbol: class FileSplit
location: class Map
Note: PhaseOne.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error
Вот код, который я пытаюсь скомпилировать:
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 PhaseOne
{
public static class Map extends Mapper<LongWritable, Text, Text, IntWritable>
{
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException
{
String doc = value.toString();
String docName = ((FileSplit) context.getInputSplit()).getPath().getName().toString();
StringTokenizer tokenizer = new StringTokenizer(doc);
String tempStr="", tempStr2="";
//loop to collect all the words
while(tokenizer.hasMoreTokens())
{
tempStr = tokenizer.nextToken().replaceAll("\\p{P}", ""); //formatting the word
if(tempStr.equals("")) continue; //ignoring null words (all special character words become null)
while(tokenizer.hasMoreTokens())
{tempStr2 = tokenizer.nextToken().replaceAll("\\p{P}", ""); if(!tempStr2.equals("")) break;}
tempStr = tempStr + " " + tempStr2 + "," + docName;
word.set(tempStr);//converting string to text writable
context.write(word,one);
}
}
public static class Reduce extends Reducer<Text, IntWritable, Text, IntWritable>
{
public void reduce(Text key, Iterable<IntWritable> 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, "PhaseOne");
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
job.setJarByClass(PhaseOne.class);
job.setMapperClass(Map.class);
job.setReducerClass(Reduce.class);
job.setInputFormatClass(TextInputFormat.class);
job.setOutputFormatClass(TextOutputFormat.class);
//FileInputFormat.setInputDirRecursive(job, true);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
job.waitForCompletion(true);
}
}
}
Может кто-нибудь помочь мне разобраться, пожалуйста!