|
| 1 | +package apriori.example; |
| 2 | + |
| 3 | +import apriori.Itemset; |
| 4 | +import apriori.Transaction; |
| 5 | +import apriori.Transactions; |
| 6 | +import common.utils.FileUtils; |
| 7 | +import common.utils.StringUtils; |
| 8 | + |
| 9 | +import java.io.File; |
| 10 | +import java.util.*; |
| 11 | + |
| 12 | +/** |
| 13 | + * Created with IntelliJ IDEA. |
| 14 | + * User: Boyce |
| 15 | + * Date: 7/12/15 |
| 16 | + * Time: 14:37 |
| 17 | + * To change this template use File | Settings | File Templates. |
| 18 | + */ |
| 19 | +public class Calculator { |
| 20 | + private final static String BASE_PATH = "/Users/Boyce/GitProjects/Algorithm/src/apriori/example/"; |
| 21 | + |
| 22 | + public static void main(String[] args) { |
| 23 | + Transactions transactions = new Transactions(0.9, 0.4); |
| 24 | + |
| 25 | + File file = new File(BASE_PATH + "data/accidents.dat"); |
| 26 | + List<String> lines = FileUtils.readLines(file); |
| 27 | + |
| 28 | + Transaction t; |
| 29 | + for (int i=0;i<lines.size(); i++) { |
| 30 | + String line = lines.get(i); |
| 31 | + if (StringUtils.isNotEmpty(line)) { |
| 32 | + t = new Transaction("t" + i, transactions); |
| 33 | + |
| 34 | + String[] items = line.split(" "); |
| 35 | + int length = items.length; |
| 36 | + |
| 37 | + for (int j=0; j<length; j++) { |
| 38 | + t.addItem(items[j]); |
| 39 | + } |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + System.out.println(transactions); |
| 44 | + System.out.println(transactions.n()); |
| 45 | + |
| 46 | + // for |
| 47 | + Itemset c = Itemset.init(transactions); |
| 48 | + System.out.println(c); |
| 49 | + |
| 50 | + Itemset f = c.frequent_gen(transactions); |
| 51 | + System.out.println(f); |
| 52 | + |
| 53 | + while (!c.isEmpty()) { |
| 54 | + c = f.candidate_gen(); |
| 55 | + System.out.println("candidate set: " + c); |
| 56 | + |
| 57 | + if (!c.isEmpty()) { |
| 58 | + f = c.frequent_gen(transactions); |
| 59 | + System.out.println("frequent set: " + f); |
| 60 | + } |
| 61 | + } |
| 62 | + } |
| 63 | +} |
0 commit comments