diff --git a/.classpath b/.classpath
index 4af86cd..636c508 100644
--- a/.classpath
+++ b/.classpath
@@ -6,19 +6,19 @@
-
+
+
-
+
-
+
-
+
-
diff --git a/src/main/java/slp/core/modeling/runners/Completion.java b/src/main/java/slp/core/modeling/runners/Completion.java
new file mode 100644
index 0000000..8a50c31
--- /dev/null
+++ b/src/main/java/slp/core/modeling/runners/Completion.java
@@ -0,0 +1,40 @@
+package slp.core.modeling.runners;
+
+import java.util.List;
+
+import slp.core.util.Pair;
+
+public class Completion {
+ private final Integer realIx;
+ private final List> completions;
+
+ public Completion(Integer realIx, List> predictions) {
+ this.realIx = realIx;
+ this.completions = predictions;
+ }
+
+ public Completion(List> predictions) {
+ this.realIx = null;
+ this.completions = predictions;
+ }
+
+ public List> getPredictions() {
+ return completions;
+ }
+
+ public Integer getRealIx() {
+ return realIx;
+ }
+
+ public int getRank() {
+ if (this.realIx == null) return -1;
+ else {
+ for (int i = 0; i < this.completions.size(); i++) {
+ if (this.completions.get(i).left.equals(this.realIx)) {
+ return i;
+ }
+ }
+ return -1;
+ }
+ }
+}
diff --git a/src/main/java/slp/core/modeling/runners/ModelRunner.java b/src/main/java/slp/core/modeling/runners/ModelRunner.java
index 45ad45b..3fc31a0 100644
--- a/src/main/java/slp/core/modeling/runners/ModelRunner.java
+++ b/src/main/java/slp/core/modeling/runners/ModelRunner.java
@@ -312,6 +312,80 @@ private void logPredictionProgress(List modeled) {
}
}
+ public Stream>>> completeDirectory(File file) {
+ this.modelStats = new long[] { 0, -System.currentTimeMillis() };
+ this.mrr = 0.0;
+ return this.lexerRunner.lexDirectory(file)
+ .map(p -> {
+ this.model.notify(p.left);
+ return Pair.of(p.left, this.completeTokens(p.right));
+ });
+ }
+
+ public List> completeFile(File f) {
+ if (!this.lexerRunner.willLexFile(f)) return null;
+ this.model.notify(f);
+ return completeTokens(this.lexerRunner.lexFile(f));
+ }
+
+ public List> completeContent(String content) {
+ return completeTokens(this.lexerRunner.lexText(content));
+ }
+
+ public List> completeTokens(Stream> lexed) {
+ List> lineCompletions;
+ if (this.lexerRunner.isPerLine()) {
+ lineCompletions = lexed
+ .map(this.getVocabulary()::toIndices)
+ .map(l -> l.collect(Collectors.toList()))
+ .map(l -> completeSequence(l))
+ .peek(this::logCompletionProgress)
+ .collect(Collectors.toList());
+ } else {
+ List lineLengths = new ArrayList<>();
+ List commpletions = completeSequence(lexed
+ .map(this.getVocabulary()::toIndices)
+ .map(l -> l.collect(Collectors.toList()))
+ .peek(l -> lineLengths.add(l.size()))
+ .flatMap(l -> l.stream()).collect(Collectors.toList()));
+ lineCompletions = toLines(commpletions, lineLengths);
+ logCompletionProgress(commpletions);
+ }
+ return lineCompletions;
+ }
+
+ protected List completeSequence(List tokens) {
+ if (this.selfTesting) this.model.forget(tokens);
+ List