Added classifier version

pull/209/head
M66B 2 years ago
parent 67fa8ca8e2
commit 26d7fe4269

@ -48,6 +48,7 @@ import javax.mail.Address;
import javax.mail.internet.InternetAddress; import javax.mail.internet.InternetAddress;
public class MessageClassifier { public class MessageClassifier {
private static int version = 3;
private static boolean loaded = false; private static boolean loaded = false;
private static boolean dirty = false; private static boolean dirty = false;
private static final Map<Long, List<String>> accountMsgIds = new HashMap<>(); private static final Map<Long, List<String>> accountMsgIds = new HashMap<>();
@ -425,7 +426,8 @@ public class MessageClassifier {
try (JsonWriter writer = new JsonWriter(new BufferedWriter(new FileWriter(file)))) { try (JsonWriter writer = new JsonWriter(new BufferedWriter(new FileWriter(file)))) {
writer.beginObject(); writer.beginObject();
writer.name("version").value(2); Log.i("Classifier write version=" + version);
writer.name("version").value(version);
writer.name("messages"); writer.name("messages");
writer.beginArray(); writer.beginArray();
@ -517,13 +519,15 @@ public class MessageClassifier {
private static synchronized void _load(File file) throws IOException { private static synchronized void _load(File file) throws IOException {
Log.i("Classifier read " + file); Log.i("Classifier read " + file);
long start = new Date().getTime(); long start = new Date().getTime();
version = 0;
if (file.exists()) if (file.exists())
try (JsonReader reader = new JsonReader(new BufferedReader(new FileReader(file)))) { try (JsonReader reader = new JsonReader(new BufferedReader(new FileReader(file)))) {
reader.beginObject(); reader.beginObject();
while (reader.hasNext()) while (reader.hasNext())
switch (reader.nextName()) { switch (reader.nextName()) {
case "version": case "version":
reader.nextInt(); version = reader.nextInt();
Log.i("Classifier read version=" + version);
break; break;
case "messages": case "messages":
@ -684,7 +688,7 @@ public class MessageClassifier {
Log.i("Classifier dropping account=" + account + Log.i("Classifier dropping account=" + account +
" word=" + word + " class=" + clazz + " freq=" + freq.count + " avg=" + avg); " word=" + word + " class=" + clazz + " freq=" + freq.count + " avg=" + avg);
wordClassFrequency.get(account).get(word).remove(clazz); wordClassFrequency.get(account).get(word).remove(clazz);
} else if (false) { } else if (version >= 3) {
for (String b : new ArrayList<>(freq.before.keySet())) for (String b : new ArrayList<>(freq.before.keySet()))
if (freq.before.get(b) < freq.count / 20) if (freq.before.get(b) < freq.count / 20)
freq.before.remove(b); freq.before.remove(b);

Loading…
Cancel
Save