Java BufferedReader Read loadVocab(String vocabFilePath, double factor)

Here you can find the source of loadVocab(String vocabFilePath, double factor)

Description

load Vocab

License

Open Source License

Declaration

public static Map<String, Integer> loadVocab(String vocabFilePath, double factor) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.*;

public class Main {
    public static Map<String, Integer> loadVocab(String vocabFilePath, double factor) {
        if (factor < 0)
            factor = 1.0;//from  ww w  . ja v  a2s  .  c o  m
        Map<String, Integer> counts = new LinkedHashMap<>();
        try {
            BufferedReader reader = new BufferedReader(new FileReader(vocabFilePath));
            String line;
            while ((line = reader.readLine()) != null) {
                if (line.isEmpty())
                    continue;
                String[] tokens = line.trim().split("\t");
                String word = tokens[0].trim();
                int count = Integer.parseInt(tokens[1].trim());
                if (factor != 1.0)
                    count = (int) (count * factor);
                counts.put(word, count);
            }
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return counts;
    }
}

Related

  1. loadTrustSet(String trustSet)
  2. loadTwoColumnResource(InputStream resource)
  3. loadTxnDescriptions(String filename)
  4. loadTXTList(String listFile, int size)
  5. loadUnicodeStringFromFile(final File file)
  6. loadWaypoints(File inFile)
  7. loadXML(String fileName)
  8. loadXMLDocumentFromClasspath(String resourcePath)
  9. loadY(InputStream filePath)