Java 映射函数输出记录为零-无错误,但映射器仍不提供任何输出。(地图缩小)

Java 映射函数输出记录为零-无错误,但映射器仍不提供任何输出。(地图缩小),java,hadoop,mapreduce,computer-science,bigdata,Java,Hadoop,Mapreduce,Computer Science,Bigdata,尝试使用hadoop map reduce处理文本以获取词性。没有错误,但仍然映射函数不提供任何输出 public class POSCount { public static class TokenizerMapper extends Mapper<LongWritable, Text, IntWritable, Text>{ //private final static IntWritable one = new IntWritable(1); private T

尝试使用hadoop map reduce处理文本以获取词性。没有错误,但仍然映射函数不提供任何输出

public class POSCount {
  public static class TokenizerMapper
   extends Mapper<LongWritable, Text, IntWritable, Text>{
//private final static IntWritable one = new IntWritable(1);
   private Text word = new Text();
   private  Map<String, String> wordList = null;


@Override
public void setup(Context context) {
    Configuration conf = context.getConfiguration();
    Path pt = new Path("/user/gokul/hw1b/mobyposi.i");
    //Path pt = new Path("/user/gxs161530/mobyposi.i");
    BufferedReader br;
    try {
    //FileSystem fs = FileSystem.get(new Configuration());
    FileSystem fs = FileSystem.get(conf);
    br=new BufferedReader(new InputStreamReader(fs.open(pt)));
    wordList = new HashMap<String, String>();
    String line, word, type;
    char ch;
      while ((line=br.readLine())!= null){
          word = line.substring(0,line.indexOf("×"));
          type = line.substring(line.indexOf("×")+1);
          for(int i=0;i<type.length();i++){
              ch = type.charAt(i);
              switch (ch){
                case 'N' :  wordList.put(word, "noun");
                            break;
                case 'p' :  wordList.put(word, "plural");
                            break;
                case 'V' :  wordList.put(word, "verb");
                            break;
                case 't' :  wordList.put(word, "verb");
                            break;
                case 'i' :  wordList.put(word, "verb");
                            break;
                case 'A' :  wordList.put(word, "adjective");
                            break;
                case 'v' :  wordList.put(word, "adverb");
                            break;
                case 'C' :  wordList.put(word, "conjunction");
                            break;
                case 'P' :  wordList.put(word, "preposition");
                            break;
                case 'r' :  wordList.put(word, "pronoun");
                            break;
                case 'D' :  wordList.put(word, "definite article");
                            break;
                case 'I' :  wordList.put(word, "indefinite article");
                            break;
                case 'o' :  wordList.put(word, "nominative");
                            break;
              }
         }
       }
    } catch(Exception e) {
      e.printStackTrace();
    }
//  return map;
}
public void map(LongWritable key, Text value, Context context
                ) throws IOException, InterruptedException {
  StringTokenizer itr = new StringTokenizer(value.toString());
  String token;
  int len=0;
  try {
     while (itr.hasMoreTokens()) {
         token = itr.nextToken().trim().toLowerCase();   
         len = token.length();
         if(wordList.containsKey(token) && len>=5){ 
            word.set(wordList.get(token));
            //context.write(new Text(Integer.toString(len)), word);
            context.write(new IntWritable(len), word);
            }
      }
} catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }     
 }
公共类POSCount{
公共静态类令牌映射器
扩展映射器{
//私有最终静态IntWritable one=新的IntWritable(1);
私有文本字=新文本();
私有映射wordList=null;
@凌驾
公共无效设置(上下文){
conf=context.getConfiguration();
路径pt=新路径(“/user/gokul/hw1b/mobyposi.i”);
//路径pt=新路径(“/user/gxs161530/mobyposi.i”);
缓冲剂;
试一试{
//FileSystem fs=FileSystem.get(新配置());
FileSystem fs=FileSystem.get(conf);
br=新的BufferedReader(新的InputStreamReader(fs.open(pt));
wordList=newhashmap();
字符串行、字、类型;
char ch;
而((line=br.readLine())!=null){
word=行.子字符串(0,行.索引为(“×”);
类型=行子字符串(行索引(“×”)+1);
对于(int i=0;i=5){
set(wordList.get(token));
//write(新文本(Integer.toString(len)),word);
context.write(新的IntWritable(len),word);
}
}
}捕获(例外e){
//TODO自动生成的捕捉块
e、 printStackTrace();
}     
}

上面的程序将地图输出记录返回为0。我需要(长度、词性)作为map的输出。请指出我的错误所在。

您的程序很好,我对您在评论中提到的文件中的一些示例进行了重新运行,它给了我预期的输出。但是,当我对整个文件运行相同的程序时,我发现由于一些符号问题,它给了我错误。它无法获得“x”o输入文件的ut格式是java支持的。所以我将该文件中的所有数据复制到新文件(stack.txt)中,然后再次运行该程序,它给了我输出

我使用了和你问题中给出的相同的映射器,这是我使用的减速器

// Do not go on logic it was just for testing
public void reduce(IntWritable key, Iterable<Text> values,Context context) throws IOException, InterruptedException {
Text t = new Text();
for(Text i : values)
{
t=i;
}   
    context.write(t, key);
}

如果您仍然面临一些问题,请告诉我

您在设置中到底想做什么?您能提供运行该设置所针对的输入吗?在我看来,您的映射方法逻辑中似乎有一些错误。但如果没有输入文件示例,我无法确定您是否使用了表示词性的单词列表:地上×A、地上×PvNA、abox×A,Abo×N,Abo×NA,这对单词中的每一个都在单独的行中,或者它们都在同一行中。请给出您输入的确切格式,以便我可以在我的系统上进行测试。它们是用不带逗号的行分隔的。无法将其逐行粘贴到此处。仅当我在映射器中使用以下命令时才能获取o/p:context.write(word,new Intwriteable(len));如果使用了context.write(new IntWritable(len),word)。我也遇到了同样的问题。获得了输出。现在更新了job.setMapOutputKeyClass。非常感谢您的帮助!!
verb    5
verb    6
noun    7
noun    8
noun    9
adjective       10
noun    11
noun    12
noun    13
adjective       14
adjective       15
adjective       16
noun    17
noun    18
adjective       19