Java BufferedReader Read loadModel(String fileName, Hashtable dictionary, Hashtable> modelPairs)

Here you can find the source of loadModel(String fileName, Hashtable dictionary, Hashtable> modelPairs)

Description

load Model

License

Apache License

Declaration

public static void loadModel(String fileName,
            Hashtable<String, String> dictionary,
            Hashtable<String, ArrayList<String>> modelPairs) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.BufferedReader;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Hashtable;

public class Main {
    public static void loadModel(String fileName,
            Hashtable<String, String> dictionary,
            Hashtable<String, ArrayList<String>> modelPairs) {
        //Open the model file
        BufferedReader reader = null;
        try {// w  w  w  .  j a v  a2s  . c o  m
            reader = new BufferedReader(new InputStreamReader(
                    new FileInputStream(fileName), "UTF-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        //Read each line
        String line = null;
        try {
            while ((line = reader.readLine()) != null) {
                // Comments, empty lines
                line = line.trim();
                if (line.length() == 0 || line.charAt(0) == '#')
                    continue;

                // Assign a word to our dictionary
                String[] halves = line.split("=");
                String mm = halves[0].trim();
                String roman = halves[1].trim();
                dictionary.put(mm, roman);

                if (modelPairs != null) {
                    if (!modelPairs.containsKey(roman))
                        modelPairs.put(roman, new ArrayList<String>());
                    modelPairs.get(roman).add(mm);
                }
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        }

        try {
            reader.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}

Related

  1. loadListFromTextFile(String filename, String defaultitem, String linePrefix, String lineSuffix)
  2. loadLongArray(BufferedReader in)
  3. loadMetadata(File file)
  4. loadMetaFile(File metaFile)
  5. loadMimeTypes(Reader in, Map extMap, Map mimeMap)
  6. loadNameMap(String mapName, boolean reverseMap)
  7. loadNumUsers(String fileName)
  8. loadPartitions(String fileName)
  9. loadPathPreferencesFromFile(File inputFile)