mirror of https://github.com/M66B/FairEmail.git
Limit sample size for conversation actions
This commit is contained in:
parent
0c23517e38
commit
faa2a334f0
|
@ -44,9 +44,10 @@ import java.util.Locale;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class TextHelper {
|
public class TextHelper {
|
||||||
private static final int MAX_SAMPLE_SIZE = 8192;
|
private static final int MAX_DETECT_SAMPLE_SIZE = 8192;
|
||||||
private static final float MIN_PROBABILITY = 0.80f;
|
private static final float MIN_DETECT_PROBABILITY = 0.80f;
|
||||||
private static final String TRANSLITERATOR = "Any-Latin; Latin-ASCII";
|
private static final String TRANSLITERATOR = "Any-Latin; Latin-ASCII";
|
||||||
|
private static final int MAX_CONVERSATION_SAMPLE_SIZE = 8192;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
System.loadLibrary("fairemail");
|
System.loadLibrary("fairemail");
|
||||||
|
@ -63,11 +64,11 @@ public class TextHelper {
|
||||||
|
|
||||||
byte[] octets = text.getBytes();
|
byte[] octets = text.getBytes();
|
||||||
byte[] sample;
|
byte[] sample;
|
||||||
if (octets.length < MAX_SAMPLE_SIZE)
|
if (octets.length < MAX_DETECT_SAMPLE_SIZE)
|
||||||
sample = octets;
|
sample = octets;
|
||||||
else {
|
else {
|
||||||
sample = new byte[MAX_SAMPLE_SIZE];
|
sample = new byte[MAX_DETECT_SAMPLE_SIZE];
|
||||||
System.arraycopy(octets, 0, sample, 0, MAX_SAMPLE_SIZE);
|
System.arraycopy(octets, 0, sample, 0, MAX_DETECT_SAMPLE_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
long start = new Date().getTime();
|
long start = new Date().getTime();
|
||||||
|
@ -76,7 +77,7 @@ public class TextHelper {
|
||||||
long elapse = new Date().getTime() - start;
|
long elapse = new Date().getTime() - start;
|
||||||
Log.i("cld3 language=" + result + " elapse=" + elapse);
|
Log.i("cld3 language=" + result + " elapse=" + elapse);
|
||||||
|
|
||||||
if (result.probability < MIN_PROBABILITY)
|
if (result.probability < MIN_DETECT_PROBABILITY)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -139,10 +140,14 @@ public class TextHelper {
|
||||||
.atZone(ZoneId.systemDefault());
|
.atZone(ZoneId.systemDefault());
|
||||||
List<ConversationActions.Message> input = new ArrayList<>();
|
List<ConversationActions.Message> input = new ArrayList<>();
|
||||||
for (String text : texts)
|
for (String text : texts)
|
||||||
|
if (!TextUtils.isEmpty(text)) {
|
||||||
|
if (text.length() > MAX_CONVERSATION_SAMPLE_SIZE)
|
||||||
|
text = text.substring(0, MAX_CONVERSATION_SAMPLE_SIZE);
|
||||||
input.add(new ConversationActions.Message.Builder(author)
|
input.add(new ConversationActions.Message.Builder(author)
|
||||||
.setReferenceTime(dt)
|
.setReferenceTime(dt)
|
||||||
.setText(text)
|
.setText(text)
|
||||||
.build());
|
.build());
|
||||||
|
}
|
||||||
|
|
||||||
Set<String> excluded = new HashSet<>(Arrays.asList(
|
Set<String> excluded = new HashSet<>(Arrays.asList(
|
||||||
ConversationAction.TYPE_OPEN_URL,
|
ConversationAction.TYPE_OPEN_URL,
|
||||||
|
|
Loading…
Reference in New Issue