// Path: src/main/java/de/mpii/gsm/utils/PrimitiveUtils.java
// public final class PrimitiveUtils {
// 
//     /**
//      * Combines the two given int values into a single long value.
//      * 
//      * @param l
//      * @param r
//      * @return 
//      */
//     public static long combine(int l, int r) {
//         return ((long) l << 32) | ((long) r & 0xFFFFFFFFL);
//     }
// 
//     /**
//      * Extracts int value corresponding to left-most 32 bits of given long value.
//      * 
//      * @param c
//      * @return 
//      */
//     public static int getLeft(long c) {
//         return (int) (c >> 32);
//     }
// 
//     /**
//      * Extracts int value corresponding to right-most 32 bits of given long value.
//      * 
//      * @param c
//      * @return 
//      */
//     public static int getRight(long c) {
//         return (int) c;
//     }
// }


import de.mpii.gsm.utils.PrimitiveUtils;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.mahout.math.list.IntArrayList;
import org.apache.mahout.math.map.OpenIntIntHashMap;
import org.apache.mahout.math.map.OpenIntObjectHashMap;
package de.mpii.gsm.utils;





public class Dictionary {
	
	//Combines itemId and support value in a long value
	protected ArrayList<Long> items = new ArrayList<Long>();
	
	protected int[] parentIds;
	
	OpenIntObjectHashMap<String> itemIdToItemMap = new OpenIntObjectHashMap<String>();
	
	public void load(Configuration conf, String fileName, int minSupport) throws IOException {
		
		BufferedReader br = null;
		if (conf == null) {
			@SuppressWarnings("resource")
			FileInputStream fstream = new FileInputStream(fileName);
			// Get the object of DataInputStream
			DataInputStream in = new DataInputStream(fstream);
			br = new BufferedReader(new InputStreamReader(in));
		} else {
			FileSystem fs = FileSystem.get(conf);
			FSDataInputStream dis = fs.open(new Path(fileName));
			br = new BufferedReader(new InputStreamReader(dis));
		}
		
		OpenIntIntHashMap parentMap = new OpenIntIntHashMap();
		
		String line = null;

		while ((line = br.readLine()) != null) {
			String[] splits = line.split("\t");
			int itemId = Integer.parseInt(splits[3]);
			int itemSupport = Integer.parseInt(splits[2]);
			
			int parentId = Integer.parseInt(splits[4]);
			
			parentMap.put(itemId, parentId);

			if (itemSupport >= minSupport) {
// Path: src/main/java/de/mpii/gsm/utils/PrimitiveUtils.java
// public final class PrimitiveUtils {
// 
//     /**
//      * Combines the two given int values into a single long value.
//      * 
//      * @param l
//      * @param r
//      * @return 
//      */
//     public static long combine(int l, int r) {
//         return ((long) l << 32) | ((long) r & 0xFFFFFFFFL);
//     }
// 
//     /**
//      * Extracts int value corresponding to left-most 32 bits of given long value.
//      * 
//      * @param c
//      * @return 
//      */
//     public static int getLeft(long c) {
//         return (int) (c >> 32);
//     }
// 
//     /**
//      * Extracts int value corresponding to right-most 32 bits of given long value.
//      * 
//      * @param c
//      * @return 
//      */
//     public static int getRight(long c) {
//         return (int) c;
//     }
// }


// Path: src/main/java/de/mpii/gsm/utils/Dictionary.java
import de.mpii.gsm.utils.PrimitiveUtils;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.mahout.math.list.IntArrayList;
import org.apache.mahout.math.map.OpenIntIntHashMap;
import org.apache.mahout.math.map.OpenIntObjectHashMap;

package de.mpii.gsm.utils;





public class Dictionary {
	
	//Combines itemId and support value in a long value
	protected ArrayList<Long> items = new ArrayList<Long>();
	
	protected int[] parentIds;
	
	OpenIntObjectHashMap<String> itemIdToItemMap = new OpenIntObjectHashMap<String>();
	
	public void load(Configuration conf, String fileName, int minSupport) throws IOException {
		
		BufferedReader br = null;
		if (conf == null) {
			@SuppressWarnings("resource")
			FileInputStream fstream = new FileInputStream(fileName);
			// Get the object of DataInputStream
			DataInputStream in = new DataInputStream(fstream);
			br = new BufferedReader(new InputStreamReader(in));
		} else {
			FileSystem fs = FileSystem.get(conf);
			FSDataInputStream dis = fs.open(new Path(fileName));
			br = new BufferedReader(new InputStreamReader(dis));
		}
		
		OpenIntIntHashMap parentMap = new OpenIntIntHashMap();
		
		String line = null;

		while ((line = br.readLine()) != null) {
			String[] splits = line.split("\t");
			int itemId = Integer.parseInt(splits[3]);
			int itemSupport = Integer.parseInt(splits[2]);
			
			int parentId = Integer.parseInt(splits[4]);
			
			parentMap.put(itemId, parentId);

			if (itemSupport >= minSupport) {
				items.add(PrimitiveUtils.combine(itemId, itemSupport));