Added classifier parameters

pull/191/head
M66B 4 years ago
parent 088cf57ede
commit d5ccaf41d1

@ -44,6 +44,7 @@ import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.ImageButton;
import android.widget.SeekBar;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
@ -61,6 +62,7 @@ import androidx.preference.PreferenceManager;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@ -82,6 +84,10 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private SwitchCompat swShortcuts;
private SwitchCompat swFts;
private SwitchCompat swClassification;
private TextView tvClassMinChance;
private SeekBar sbClassMinChance;
private TextView tvClassMinDifference;
private SeekBar sbClassMinDifference;
private ImageButton ibClassification;
private TextView tvFtsIndexed;
private TextView tvFtsPro;
@ -117,10 +123,14 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private Group grpDebug;
private NumberFormat NF = NumberFormat.getNumberInstance();
private final static long MIN_FILE_SIZE = 1024 * 1024L;
private final static String[] RESET_OPTIONS = new String[]{
"shortcuts", "fts", "classification", "language", "watchdog", "updates",
"shortcuts", "fts",
"classification", "class_min_chance", "class_min_difference",
"language", "watchdog", "updates",
"experiments", "query_threads", "crash_reports", "cleanup_attachments",
"protocol", "debug", "auth_plain", "auth_login", "auth_sasl"
};
@ -165,6 +175,10 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
swFts = view.findViewById(R.id.swFts);
swClassification = view.findViewById(R.id.swClassification);
ibClassification = view.findViewById(R.id.ibClassification);
tvClassMinChance = view.findViewById(R.id.tvClassMinChance);
sbClassMinChance = view.findViewById(R.id.sbClassMinChance);
tvClassMinDifference = view.findViewById(R.id.tvClassMinDifference);
sbClassMinDifference = view.findViewById(R.id.sbClassMinDifference);
tvFtsIndexed = view.findViewById(R.id.tvFtsIndexed);
tvFtsPro = view.findViewById(R.id.tvFtsPro);
spLanguage = view.findViewById(R.id.spLanguage);
@ -282,6 +296,40 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
}
});
sbClassMinChance.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
prefs.edit().putInt("class_min_chance", progress).apply();
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// Do nothing
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// Do nothing
}
});
sbClassMinDifference.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
prefs.edit().putInt("class_min_difference", progress).apply();
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// Do nothing
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// Do nothing
}
});
spLanguage.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
@ -749,8 +797,17 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
swExternalSearch.setChecked(Helper.isComponentEnabled(getContext(), ActivitySearch.class));
swShortcuts.setChecked(prefs.getBoolean("shortcuts", true));
swFts.setChecked(prefs.getBoolean("fts", false));
swClassification.setChecked(prefs.getBoolean("classification", false));
int class_min_chance = prefs.getInt("class_min_chance", 20);
tvClassMinChance.setText(getString(R.string.title_advanced_class_min_chance, NF.format(class_min_chance)));
sbClassMinChance.setProgress(class_min_chance);
int class_min_difference = prefs.getInt("class_min_difference", 50);
tvClassMinDifference.setText(getString(R.string.title_advanced_class_min_difference, NF.format(class_min_difference)));
sbClassMinDifference.setProgress(class_min_difference);
int selected = -1;
String language = prefs.getString("language", null);
List<String> display = new ArrayList<>();

@ -249,13 +249,22 @@ public class MessageClassifier {
}
});
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
double class_min_chance = prefs.getInt("class_min_chance", 20) / 100.0;
double class_min_difference = prefs.getInt("class_min_difference", 50) / 100.0;
// Select best class
String classification = null;
if (chances.get(0).chance > CHANCE_MINIMUM &&
chances.get(0).chance / chances.get(1).chance >= CHANCE_THRESHOLD)
double c0 = chances.get(0).chance;
double c1 = chances.get(1).chance;
if (c0 > class_min_chance && c1 < c0 * class_min_difference)
classification = chances.get(0).clazz;
Log.i("Classifier current=" + currentClass + " classified=" + classification);
Log.i("Classifier current=" + currentClass +
" c0=" + Math.round(c0 * 100 * 100) / 100.0 + ">" + Math.round(class_min_chance * 100 * 100) / 100.0 + "%" +
" c1=" + Math.round(c1 * 100 * 100) / 100.0 + "<" + Math.round(c0 * class_min_difference * 100 * 100) / 100.0 + "%" +
" (" + class_min_difference + "%)" +
" classified=" + classification);
return classification;
}

@ -133,6 +133,52 @@
app:layout_constraintTop_toBottomOf="@id/swClassification"
app:srcCompat="@drawable/twotone_info_24" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvClassMinChance"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_marginEnd="48dp"
android:text="@string/title_advanced_class_min_chance"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/ibClassification" />
<SeekBar
android:id="@+id/sbClassMinChance"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:max="100"
android:min="0"
android:progress="20"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvClassMinChance" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvClassMinDifference"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_marginEnd="48dp"
android:text="@string/title_advanced_class_min_difference"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/sbClassMinChance" />
<SeekBar
android:id="@+id/sbClassMinDifference"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:max="100"
android:min="0"
android:progress="50"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvClassMinDifference" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvLanguage"
android:layout_width="0dp"
@ -144,7 +190,7 @@
android:textColor="?android:attr/textColorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/ibClassification" />
app:layout_constraintTop_toBottomOf="@id/sbClassMinDifference" />
<Spinner
android:id="@+id/spLanguage"

@ -520,6 +520,8 @@
<string name="title_advanced_fts">Build search index</string>
<string name="title_advanced_fts_indexed">%1$d / %2$d messages indexed (%3$s)</string>
<string name="title_advanced_classification">Classify messages</string>
<string name="title_advanced_class_min_chance">Minimum class chance: %1$s %%</string>
<string name="title_advanced_class_min_difference">Minimum class difference: %1$s %%</string>
<string name="title_advanced_language">Language</string>
<string name="title_advanced_language_system">System</string>
<string name="title_advanced_watchdog">Periodically check if FairEmail is still active</string>

Loading…
Cancel
Save