Cache and sample classification results

This commit is contained in:
Cohee
2023-09-09 17:31:27 +03:00
parent 180dcefe40
commit 4cf6a1f7da
4 changed files with 67 additions and 7 deletions

View File

@ -438,9 +438,9 @@ export function sortByCssOrder(a, b) {
* @param {boolean} include_newline Whether to include a newline character in the trimmed string.
* @returns {string} The trimmed string.
* @example
* end_trim_to_sentence('Hello, world! I am from'); // 'Hello, world!'
* trimToEndSentence('Hello, world! I am from'); // 'Hello, world!'
*/
export function end_trim_to_sentence(input, include_newline = false) {
export function trimToEndSentence(input, include_newline = false) {
const punctuation = new Set(['.', '!', '?', '*', '"', ')', '}', '`', ']', '$', '。', '', '', '”', '', '】', '】', '', '」', '】']); // extend this as you see fit
let last = -1;
@ -465,6 +465,26 @@ export function end_trim_to_sentence(input, include_newline = false) {
return input.substring(0, last + 1).trimEnd();
}
export function trimToStartSentence(input) {
let p1 = input.indexOf(".");
let p2 = input.indexOf("!");
let p3 = input.indexOf("?");
let p4 = input.indexOf("\n");
let first = p1;
let skip1 = false;
if (p2 > 0 && p2 < first) { first = p2; }
if (p3 > 0 && p3 < first) { first = p3; }
if (p4 > 0 && p4 < first) { first = p4; skip1 = true; }
if (first > 0) {
if (skip1) {
return input.substring(first + 1);
} else {
return input.substring(first + 2);
}
}
return input;
}
/**
* Counts the number of occurrences of a character in a string.
* @param {string} string The string to count occurrences in.