diff --git a/mining/pom.xml b/mining/pom.xml index 2315c11..8c59112 100644 --- a/mining/pom.xml +++ b/mining/pom.xml @@ -15,12 +15,6 @@ UTF-8 - - junit - junit - 3.8.1 - test - commons-cli commons-cli @@ -31,6 +25,11 @@ rules 1.0 + + me.tongfei + progressbar + 0.8.1 + diff --git a/mining/src/main/java/amie/mining/AMIE.java b/mining/src/main/java/amie/mining/AMIE.java index 13bab9f..2e61fd1 100644 --- a/mining/src/main/java/amie/mining/AMIE.java +++ b/mining/src/main/java/amie/mining/AMIE.java @@ -230,7 +230,7 @@ public List mine() throws Exception { seedRules = assistant.getInitialAtomsFromSeeds(seeds, minInitialSupport); } - AMIEQueue queue = new AMIEQueue(seedRules, nThreads); + AMIEQueue queue = new AMIEQueue(seedRules, nThreads, isVerbose()); if (realTime) { consumerObj = new RuleConsumer(result, resultsLock, resultsCondVar); diff --git a/mining/src/main/java/amie/mining/AMIEQueue.java b/mining/src/main/java/amie/mining/AMIEQueue.java index 8017af6..0eb0e9d 100644 --- a/mining/src/main/java/amie/mining/AMIEQueue.java +++ b/mining/src/main/java/amie/mining/AMIEQueue.java @@ -11,6 +11,7 @@ import amie.rules.Rule; import it.unimi.dsi.fastutil.ints.Int2IntMap; import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; +import me.tongfei.progressbar.ProgressBar; /** * A queue implementation with barriers tailored for the AMIE mining system. @@ -31,6 +32,10 @@ public final class AMIEQueue { private LinkedHashSet next; + private ProgressBar progressBar; + + private boolean verbose; + private int generation; private int maxThreads; @@ -49,13 +54,15 @@ public void printStats() { } } - public AMIEQueue(Collection seeds, int maxThreads) { + public AMIEQueue(Collection seeds, int maxThreads, boolean verbose) { this.generation = 1; this.queueCalls.put(this.generation, 0); this.queueAdded.put(this.generation, 0); this.maxThreads = maxThreads; this.waitingThreads = 0; this.next = new LinkedHashSet<>(); + this.progressBar = null; + this.verbose = verbose; this.queueAll(seeds); this.nextGeneration(); this.done = false; @@ -139,6 +146,9 @@ public Rule dequeue() throws InterruptedException { --waitingThreads; } else { if (next.isEmpty()) { + if (this.verbose) { + this.progressBar.close(); + } done = true; } else { nextGeneration(); @@ -160,14 +170,27 @@ public Rule dequeue() throws InterruptedException { * @return */ private Rule poll() { - return current.next(); + if (this.verbose) { + this.progressBar.step(); + } + return current.next(); } private void nextGeneration() { + if (this.progressBar != null) { + this.progressBar.close(); + } + + if (this.verbose) { + // Heuristic for calculating updateIntervalMillis considering the queue's size and the number of consumers. + this.progressBar = new ProgressBar("Generation " + generation + ":", next.size(), Math.min(1000, next.size() * 1000 / 1000 / maxThreads)); + } + generation++; - this.queueCalls.put(this.generation, 0); - this.queueAdded.put(this.generation, 0); + this.queueCalls.put(this.generation, 0); + this.queueAdded.put(this.generation, 0); + current = next.iterator(); next = new LinkedHashSet<>(); }