Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need to adjust the code for the PCY Algorithm in order to: Implement Multistage (3 Passes) version of PCY, using one extra hash table. Implement

Need to adjust the code for the PCY Algorithm in order to:

Implement Multistage (3 Passes) version of PCY, using one extra hash table. Implement Multihash version of PCY, using one extra hash table.

/////////////////////////////////////////////////////////////////PCY Code//////////////////////////////////////////////////////////////////////////

package project;

import java.io.*; import java.util.*; public final class PCY { //Variables private static int limit,maxSize = 131072;// set the size to 2^17 private static BitSet bit; //Setters public static void setBucketSize(int bSize) { maxSize = bSize; } public static void setLimit(int p ) { limit = p ; } //Link the hash maps public static LinkedHashMap toFindPair(String retail) throws NumberFormatException, IOException { HashMap ItemFrequent = PCYPassOne(retail); LinkedHashMap canBeSet = new LinkedHashMap<>(); String _line,numberOfLines[]; Integer key; ArrayList myList = new ArrayList<>(); FileReader toReadFile = new FileReader(retail); BufferedReader reader = new BufferedReader(toReadFile); while ((_line = reader.readLine()) != null) { numberOfLines = _line.split("\\s+"); for (String toNum : numberOfLines) { /*convert to integer*/ key = Integer.parseInt(toNum); if (ItemFrequent.containsKey(key) && !myList.contains(key)) { myList.add(key); } } /*sort myList*/ Collections.sort(myList); for (int n = 0; n < myList.size(); n++) { /*create pairs*/ for (int k = n + 1; k < myList.size(); k++) { Set1 val = new Set1<>(myList.get(n), myList.get(k)); if (!bit.get(Math.abs(val.hashCode()) % maxSize)) { continue; } if (canBeSet.containsKey(val)) { canBeSet.put(val, canBeSet.get(val) + 1); } else { canBeSet.put(val, 1); } } } myList.clear(); } reader.close(); removeNotFrequent(canBeSet); /*return frequent pairs and number of support*/ return canBeSet; } /* first pass -- to find freq Item Counts */ private static HashMap PCYPassOne(String fileName) throws NumberFormatException, IOException { //Decelerations HashMap pass1 = new HashMap<>(); Bucket firstBucket = new Bucket(maxSize); String totalLine[], _lin = ""; Integer value; ArrayList myList = new ArrayList<>(); FileReader readFile = new FileReader(fileName); BufferedReader reader = new BufferedReader(readFile); while ((_lin = reader.readLine()) != null) { totalLine = _lin.split("\\s+"); for (String num : totalLine) { value = Integer.parseInt(num); if (pass1.containsKey(value)) { pass1.put(value, pass1.get(value) + 1); } else { pass1.put(value, 1); } if (!myList.contains(value)) { myList.add(value); } } Collections.sort(myList); for (int n = 0; n < myList.size(); n++) { for (int k = n + 1; k < myList.size(); k++) { Set1 val = new Set1 < >(myList.get(n), myList.get(k)); if (firstBucket.haveKey(val)) { firstBucket.input(val, firstBucket.get(val) + 1); } else { firstBucket.input(val, 1); } } } myList.clear(); } reader.close(); removeNotFrequent(pass1); bit = firstBucket.toBit(limit); firstBucket = null; return pass1; } private static boolean checkFrequancy(int num) { return num >= limit; } /*To remove none freq. Pair*/ private static void removeNotFrequent(HashMap map) { Iterator> check = map.entrySet().iterator(); while (check.hasNext()) { Map.Entry entry = check.next(); if (!checkFrequancy(entry.getValue())) { check.remove(); } } } /*To remove none freq. Pair*/ private static void removeNotFrequent(LinkedHashMap map) { Iterator> check = map.entrySet().iterator(); while (check.hasNext()) { Map.Entry entry = check.next(); if (!checkFrequancy(entry.getValue())) { check.remove(); } } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What does stickiest refer to in regard to social media

Answered: 1 week ago

Question

Provide examples of KPIs in Human Capital Management.

Answered: 1 week ago

Question

What are OLAP Cubes?

Answered: 1 week ago