Package org.apache.mahout.common.iterator

Examples of org.apache.mahout.common.iterator.FileLineIterator


     * <pre>
     * term DocFreq Index
     * </pre>
     */
    static String[] loadTermDictionary(InputStream is) throws IOException {
      FileLineIterator it = new FileLineIterator(is);

      int numEntries = Integer.parseInt(it.next());
      // System.out.println(numEntries);
      String[] result = new String[numEntries];

      while (it.hasNext()) {
        String line = it.next();
        if (line.startsWith("#")) {
          continue;
        }
        String[] tokens = ClusterUtil.TAB_PATTERN.split(line);
        if (tokens.length < 3) {
View Full Code Here


   * <pre>
   * term DocFreq Index
   * </pre>
   */
  private static String[] loadTermDictionary(InputStream is) throws IOException {
    FileLineIterator it = new FileLineIterator(is);
   
    int numEntries = Integer.parseInt(it.next());
    String[] result = new String[numEntries];
   
    while (it.hasNext()) {
      String line = it.next();
      if (line.startsWith("#")) {
        continue;
      }
      String[] tokens = TAB_PATTERN.split(line);
      if (tokens.length < 3) {
View Full Code Here

    files = out.listFiles();
    assertEquals("files Size: " + files.length + " is not: " + WORDS.length, files.length, WORDS.length);
    for (File file : files) {
      //should only be one line in the file, and it should be label label
      Iterator<String> it = new FileLineIterator(file);
      String line = it.next().trim();
      assertFalse(it.hasNext());
      String label = "animal" + '\t' + file.getName();
      assertEquals(line + ":::: is not equal to " + label + "::::", line, label);
    }
  }
View Full Code Here

   
    StringBuilder content = new StringBuilder();
    content.append(header);
    NumberFormat decimalFormatter = new DecimalFormat("0000");
    File dumpFile = new File(dumpFilePath);
    FileLineIterator it;
    if (dumpFilePath.endsWith(".bz2")) {
      // default compression format from http://download.wikimedia.org
      CompressionCodec codec = new BZip2Codec();
      it = new FileLineIterator(codec.createInputStream(new FileInputStream(dumpFile)));
    } else {
      // assume the user has previously de-compressed the dump file
      it = new FileLineIterator(dumpFile);
    }
    int filenumber = 0;
    while (it.hasNext()) {
      String thisLine = it.next();
      if (thisLine.trim().startsWith("<page>")) {
        boolean end = false;
        while (!thisLine.trim().startsWith("</page>")) {
          content.append(thisLine).append('\n');
          if (it.hasNext()) {
            thisLine = it.next();
          } else {
            end = true;
            break;
          }
        }
View Full Code Here

   * <pre>
   * term DocFreq Index
   * </pre>
   */
  private static String[] loadTermDictionary(InputStream is) throws IOException {
    FileLineIterator it = new FileLineIterator(is);

    int numEntries = Integer.parseInt(it.next());
    String[] result = new String[numEntries];

    while (it.hasNext()) {
      String line = it.next();
      if (line.startsWith("#")) {
        continue;
      }
      String[] tokens = TAB_PATTERN.split(line);
      if (tokens.length < 3) {
View Full Code Here

    log.info("Creating FileDataModel for file {}", dataFile);

    this.lastModified = dataFile.lastModified();
    this.lastUpdateFileModified = readLastUpdateFileModified();

    FileLineIterator iterator = new FileLineIterator(dataFile, false);
    String firstLine = iterator.peek();
    while (firstLine.isEmpty() || firstLine.charAt(0) == COMMENT_CHAR) {
      iterator.next();
      firstLine = iterator.peek();
    }
    Closeables.close(iterator, true);

    delimiter = determineDelimiter(firstLine);
    delimiterPattern = Splitter.on(delimiter);
View Full Code Here

    if (hasPrefValues) {

      if (loadFreshData) {

        FastByIDMap<Collection<Preference>> data = new FastByIDMap<Collection<Preference>>();
        FileLineIterator iterator = new FileLineIterator(dataFile, false);
        processFile(iterator, data, timestamps, false);

        for (File updateFile : findUpdateFilesAfter(newLastModified)) {
          processFile(new FileLineIterator(updateFile, false), data, timestamps, false);
        }

        return new GenericDataModel(GenericDataModel.toDataMap(data, true), timestamps);

      } else {

        FastByIDMap<PreferenceArray> rawData = ((GenericDataModel) delegate).getRawUserData();

        for (File updateFile : findUpdateFilesAfter(Math.max(oldLastUpdateFileModifieid, newLastModified))) {
          processFile(new FileLineIterator(updateFile, false), rawData, timestamps, true);
        }

        return new GenericDataModel(rawData, timestamps);

      }

    } else {

      if (loadFreshData) {

        FastByIDMap<FastIDSet> data = new FastByIDMap<FastIDSet>();
        FileLineIterator iterator = new FileLineIterator(dataFile, false);
        processFileWithoutID(iterator, data, timestamps);

        for (File updateFile : findUpdateFilesAfter(newLastModified)) {
          processFileWithoutID(new FileLineIterator(updateFile, false), data, timestamps);
        }

        return new GenericBooleanPrefDataModel(data, timestamps);

      } else {

        FastByIDMap<FastIDSet> rawData = ((GenericBooleanPrefDataModel) delegate).getRawUserData();

        for (File updateFile : findUpdateFilesAfter(Math.max(oldLastUpdateFileModifieid, newLastModified))) {
          processFileWithoutID(new FileLineIterator(updateFile, false), rawData, timestamps);
        }

        return new GenericBooleanPrefDataModel(rawData, timestamps);

      }
View Full Code Here

  }
 
  @Override
  protected DataModel buildModel() throws IOException {
    FastByIDMap<Collection<Preference>> data = new FastByIDMap<Collection<Preference>>();
    FileLineIterator iterator = new FileLineIterator(getDataFile(), false);
    FastByIDMap<FastByIDMap<Long>> timestamps = new FastByIDMap<FastByIDMap<Long>>();
    processFile(iterator, data, timestamps, false);
    return new GenericDataModel(GenericDataModel.toDataMap(data, true));
  }
View Full Code Here

  private final Iterator<GenericItemSimilarity.ItemItemSimilarity> delegate;

  FileItemItemSimilarityIterator(File similaritiesFile) throws IOException {
    delegate = Iterators.transform(
        new FileLineIterator(similaritiesFile),
        new Function<String, GenericItemSimilarity.ItemItemSimilarity>() {
          @Override
          public GenericItemSimilarity.ItemItemSimilarity apply(String from) {
            String[] tokens = SEPARATOR.split(from);
            return new GenericItemSimilarity.ItemItemSimilarity(Long.parseLong(tokens[0]),
View Full Code Here

      try {

        averageDiffs.clear();
        allRecommendableItemIDs.clear();
       
        FileLineIterator iterator = new FileLineIterator(dataFile, false);
        String firstLine = iterator.peek();
        while (firstLine.isEmpty() || firstLine.charAt(0) == COMMENT_CHAR) {
          iterator.next();
          firstLine = iterator.peek();
        }
        long averageCount = 0L;
        while (iterator.hasNext()) {
          averageCount = processLine(iterator.next(), averageCount);
        }
       
        pruneInconsequentialDiffs();
        updateAllRecommendableItems();
       
View Full Code Here

TOP

Related Classes of org.apache.mahout.common.iterator.FileLineIterator

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.