sentencex-ts 0.1.13-ts
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +24 -0
- package/README.md +16 -0
- package/dist/chunk-text.d.ts +1 -0
- package/dist/constants.d.ts +11 -0
- package/dist/fallbacks.d.ts +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/language.d.ts +33 -0
- package/dist/languages/am.d.ts +4 -0
- package/dist/languages/ar.d.ts +4 -0
- package/dist/languages/bg.d.ts +4 -0
- package/dist/languages/bn.d.ts +4 -0
- package/dist/languages/ca.d.ts +5 -0
- package/dist/languages/da.d.ts +5 -0
- package/dist/languages/de.d.ts +5 -0
- package/dist/languages/el.d.ts +5 -0
- package/dist/languages/en.d.ts +4 -0
- package/dist/languages/es.d.ts +4 -0
- package/dist/languages/fi.d.ts +5 -0
- package/dist/languages/fr.d.ts +4 -0
- package/dist/languages/gu.d.ts +4 -0
- package/dist/languages/hi.d.ts +4 -0
- package/dist/languages/hy.d.ts +5 -0
- package/dist/languages/index.d.ts +3 -0
- package/dist/languages/it.d.ts +6 -0
- package/dist/languages/ja.d.ts +4 -0
- package/dist/languages/kk.d.ts +6 -0
- package/dist/languages/kn.d.ts +4 -0
- package/dist/languages/ml.d.ts +4 -0
- package/dist/languages/mr.d.ts +4 -0
- package/dist/languages/my.d.ts +5 -0
- package/dist/languages/nl.d.ts +4 -0
- package/dist/languages/pa.d.ts +4 -0
- package/dist/languages/pl.d.ts +4 -0
- package/dist/languages/pt.d.ts +4 -0
- package/dist/languages/ru.d.ts +5 -0
- package/dist/languages/sk.d.ts +5 -0
- package/dist/languages/ta.d.ts +4 -0
- package/dist/languages/te.d.ts +4 -0
- package/dist/sentencex.cjs +6225 -0
- package/dist/sentencex.js +7568 -0
- package/package.json +33 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Abe Jellinek
|
|
4
|
+
|
|
5
|
+
Based on sentencex
|
|
6
|
+
Copyright (c) 2025 Santhosh Thottingal
|
|
7
|
+
|
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
in the Software without restriction, including without limitation the rights
|
|
11
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
furnished to do so, subject to the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be included in all
|
|
16
|
+
copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Sentence segmenter
|
|
2
|
+
|
|
3
|
+
[sentencex](https://github.com/wikimedia/sentencex), but ported (back) from Rust to TypeScript, so it can be used on the
|
|
4
|
+
web in environments where bundle size matters.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```shell
|
|
9
|
+
npm install sentencex-ts
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Build
|
|
13
|
+
|
|
14
|
+
```shell
|
|
15
|
+
npm run build
|
|
16
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function chunkText(text: string, chunkSize: number): string[];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const ROMAN_NUMERALS: readonly string[];
|
|
2
|
+
export declare function getQuotePairs(): Map<string, string>;
|
|
3
|
+
export declare const PARENS_REGEX: RegExp;
|
|
4
|
+
export declare const EMAIL_REGEX: RegExp;
|
|
5
|
+
export declare const NUMBERED_REFERENCE_REGEX: RegExp;
|
|
6
|
+
export declare const SPACE_AFTER_SEPARATOR: RegExp;
|
|
7
|
+
export declare const QUOTES_REGEX: RegExp;
|
|
8
|
+
export declare const EXCLAMATION_WORDS: readonly string[];
|
|
9
|
+
export declare const GLOBAL_SENTENCE_TERMINATORS: readonly string[];
|
|
10
|
+
export declare const SENTENCE_TERMINATOR_SET: Set<string>;
|
|
11
|
+
export declare const TERMINATORS_PATTERN: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const LANGUAGE_FALLBACKS: ReadonlyMap<string, readonly string[]>;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { Language, parseAbbreviations } from './language';
|
|
2
|
+
export type { SentenceBoundary } from './language';
|
|
3
|
+
export { chunkText } from './chunk-text';
|
|
4
|
+
export { LANGUAGE_FALLBACKS } from './fallbacks';
|
|
5
|
+
export { LANGUAGE_REGISTRY } from './languages';
|
|
6
|
+
import type { SentenceBoundary } from './language';
|
|
7
|
+
import { Language } from './language';
|
|
8
|
+
export declare function languageFactory(languageCode: string): Language;
|
|
9
|
+
export declare function segment(languageCode: string, text: string): string[];
|
|
10
|
+
export declare function getSentenceBoundaries(languageCode: string, text: string): SentenceBoundary[];
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export interface SentenceBoundary {
|
|
2
|
+
startIndex: number;
|
|
3
|
+
endIndex: number;
|
|
4
|
+
text: string;
|
|
5
|
+
boundarySymbol: string | null;
|
|
6
|
+
isParagraphBreak: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare enum SkippableRangeType {
|
|
9
|
+
Quote = "Quote",
|
|
10
|
+
Parentheses = "Parentheses",
|
|
11
|
+
Email = "Email"
|
|
12
|
+
}
|
|
13
|
+
export interface SkippableRange {
|
|
14
|
+
start: number;
|
|
15
|
+
end: number;
|
|
16
|
+
rangeType: SkippableRangeType;
|
|
17
|
+
}
|
|
18
|
+
export declare function parseAbbreviations(...texts: string[]): string[];
|
|
19
|
+
export declare abstract class Language {
|
|
20
|
+
abstract getAbbreviations(): readonly string[];
|
|
21
|
+
getAbbreviationChar(): string;
|
|
22
|
+
getSentenceBreakRegex(): RegExp;
|
|
23
|
+
getSentenceBoundaries(text: string): SentenceBoundary[];
|
|
24
|
+
segment(text: string): string[];
|
|
25
|
+
getBoundaryExtend(word: string): number;
|
|
26
|
+
isAbbreviation(head: string, _tail: string, separator: string): boolean;
|
|
27
|
+
getLastWord(text: string): string;
|
|
28
|
+
isExclamation(head: string, _tail: string): boolean;
|
|
29
|
+
getNextWordApprox(text: string, start: number): string;
|
|
30
|
+
findBoundary(text: string, start: number, end: number): number | null;
|
|
31
|
+
continueInNextWord(textAfterBoundary: string): boolean;
|
|
32
|
+
getSkippableRanges(text: string): SkippableRange[];
|
|
33
|
+
}
|