-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support analysis of big text. Add retries if 0 words were found…
… from text.
- Loading branch information
1 parent
6b84ad4
commit dda31af
Showing
11 changed files
with
373 additions
and
271 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
function equalsIgnoringCase(text: string, other: string) { | ||
return text.localeCompare(other, undefined, { sensitivity: "base" }) === 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
export const splitText = (text: string, chunkSize: number = 3000): string[] => { | ||
const sentences = text.match(/[^.!?]+[^.!?]+/g) || [] | ||
const chunks: string[] = [] | ||
|
||
let currentChunk = "" | ||
|
||
function add(chunk: string) { | ||
if (chunk.length > 0) chunks.push(chunk) | ||
} | ||
|
||
for (const sentence of sentences) { | ||
if ((currentChunk + sentence).length <= chunkSize) { | ||
currentChunk += sentence | ||
} else { | ||
add(currentChunk) | ||
currentChunk = sentence | ||
} | ||
} | ||
|
||
add(currentChunk) | ||
|
||
return chunks | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function waitFor(ms: number) { | ||
return new Promise((resolve) => setTimeout(resolve, ms)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { expect, test } from "vitest" | ||
import { splitText } from "../src/splitText" | ||
|
||
test("splitText", () => { | ||
const text = | ||
"This is sentence one. This is sentence two. This is sentence three." | ||
const result = splitText(text, 25) | ||
|
||
expect(result).toHaveLength(3) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.