Package org.apache.hadoop.io

Examples of org.apache.hadoop.io.IntWritable


    Path path = new Path(outputPath);
    Configuration conf = getConf();
    FileSystem fs = FileSystem.get(conf);
    SequenceFile.Writer seqWriter = new SequenceFile.Writer(fs, conf, path, IntWritable.class, VectorWritable.class);
    VectorWritable vw = new VectorWritable();
    IntWritable iw = new IntWritable();
    for(int i=0; i<eigenVectors.numRows() - 1; i++) {
      Vector v = eigenVectors.getRow(i);
      v.setName("eigenVector" + i + ", eigenvalue = " + eigenValues.get(i));
      vw.set(v);
      iw.set(i);
      seqWriter.append(iw, vw);
    }
    seqWriter.close();
  }
View Full Code Here


    Vector vector = value.get();
    Iterator<Element> it = vector.iterateNonZero();
   
    while (it.hasNext()) {
      Element e = it.next();
      output.collect(new IntWritable(e.index()), ONE);
    }
    output.collect(TOTAL_COUNT, ONE);
  }
View Full Code Here

      }
      Path dictionaryFile = new Path(localFiles[0].getPath());
      FileSystem fs = dictionaryFile.getFileSystem(job);
      SequenceFile.Reader reader = new SequenceFile.Reader(fs, dictionaryFile, job);
      Text key = new Text();
      IntWritable value = new IntWritable();
     
      // key is word value is id
      while (reader.next(key, value)) {
        dictionary.put(key.toString(), value.get());
      }
    } catch (IOException e) {
      throw new IllegalStateException(e);
    }
  }
View Full Code Here

        InMemInputSplit split = (InMemInputSplit) splits[index];
        InMemRecordReader reader = (InMemRecordReader) inputFormat.getRecordReader(
            split, conf, null);

        for (int tree = 0; tree < split.getNbTrees(); tree++) {
          IntWritable key = reader.createKey();
          NullWritable value = reader.createValue();

          // reader.next() should return true until there is no tree left
          assertEquals(tree < split.getNbTrees(), reader.next(key, value));
         
          assertEquals(split.getFirstId() + tree, key.get());
        }
      }
    }
  }
View Full Code Here

        }
       
        int fieldSize = DICTIONARY_BYTE_OVERHEAD + key.toString().length() * 2
                        + Integer.SIZE / 8;
        currentChunkSize += fieldSize;
        dictWriter.append(key, new IntWritable(i++));
      }
    }
    maxTermDimension[0] = i;
    dictWriter.close();
   
View Full Code Here

    Iterator<Vector.Element> it = userVector.get().iterateNonZero();
    while (it.hasNext()) {
      Vector.Element next1 = it.next();
      int index1 = next1.index();
      Iterator<Vector.Element> it2 = userVector.get().iterateNonZero();
      IntWritable itemWritable1 = new IntWritable(index1);
      while (it2.hasNext()) {
        Vector.Element next2 = it2.next();
        int index2 = next2.index();
        if (index1 != index2) {
          output.collect(itemWritable1, new IntWritable(index2));
        }
      }
    }
  }
View Full Code Here

      Vector.Element element = userVectorIterator.next();
      int index = element.index();
      double value = element.get();
      Vector columnVector;
      try {
        columnVector = cooccurrenceColumnCache.get(new IntWritable(index));
      } catch (TasteException te) {
        if (te.getCause() instanceof IOException) {
          throw (IOException) te.getCause();
        } else {
          throw new IOException(te.getCause());
        }
      }
      columnVector.times(value).addTo(recommendationVector);
    }
   
    Queue<RecommendedItem> topItems = new PriorityQueue<RecommendedItem>(recommendationsPerUser + 1,
        Collections.reverseOrder());
   
    Iterator<Vector.Element> recommendationVectorIterator = recommendationVector.iterateNonZero();
    LongWritable itemID = new LongWritable();
    while (recommendationVectorIterator.hasNext()) {
      Vector.Element element = recommendationVectorIterator.next();
      int index = element.index();
      if (userVector.get(index) == 0.0) {
        if (topItems.size() < recommendationsPerUser) {
          indexItemIDMap.get(new IntWritable(index), itemID);
          topItems.add(new GenericRecommendedItem(itemID.get(), (float) element.get()));
        } else if (element.get() > topItems.peek().getValue()) {
          indexItemIDMap.get(new IntWritable(index), itemID);
          topItems.add(new GenericRecommendedItem(itemID.get(), (float) element.get()));
          topItems.poll();
        }
      }
    }
View Full Code Here

                  OutputCollector<IntWritable,LongWritable> output,
                  Reporter reporter) throws IOException {
    String[] tokens = ItemIDIndexMapper.COMMA.split(value.toString());
    long itemID = Long.parseLong(tokens[1]);
    int index = idToIndex(itemID);
    output.collect(new IntWritable(index), new LongWritable(itemID));
  }
View Full Code Here

   */
  public static String[] loadTermDictionary(Configuration conf, FileSystem fs, String filePattern) throws IOException {
    FileStatus[] dictionaryFiles = fs.globStatus(new Path(filePattern));
    OpenObjectIntHashMap<String> dict = new OpenObjectIntHashMap<String>();
    Text key = new Text();
    IntWritable value = new IntWritable();
    for (FileStatus fileStatus : dictionaryFiles) {
      Path path = fileStatus.getPath();
      SequenceFile.Reader reader = new SequenceFile.Reader(fs, path, conf);
      // key is term value is id
      while (reader.next(key, value)) {
        dict.put(key.toString(), value.get());
      }
    }
    String[] dictionary = new String[dict.size()];
    for (String feature : dict.keys()) {
      dictionary[dict.get(feature)] = feature;
View Full Code Here

    SequenceFile.Writer matrixWriter = SequenceFile.createWriter(fs,
                                                                 conf,
                                                                 matrixPath,
                                                                 IntWritable.class,
                                                                 VectorWritable.class);
    IntWritable docId = new IntWritable();
    Text inputKey = new Text();
    VectorWritable v = new VectorWritable();

    int i = 0;
    for(FileStatus status : fs.listStatus(inputPath)) {
      SequenceFile.Reader reader = new SequenceFile.Reader(fs, status.getPath(), conf);
      while(reader.next(inputKey, v)) {
        docId.set(i);
        indexWriter.append(docId, inputKey);
        matrixWriter.append(docId, v);
        i++;
      }
      reader.close();
View Full Code Here

TOP

Related Classes of org.apache.hadoop.io.IntWritable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.