which-dialect 0.1.0
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 +28 -0
- package/README.md +205 -0
- package/dist/index.d.ts +76 -0
- package/dist/index.js +130 -0
- package/dist/pos.d.ts +16 -0
- package/dist/pos.js +70 -0
- package/dist/translate.d.ts +153 -0
- package/dist/translate.js +731 -0
- package/dist/types.d.ts +227 -0
- package/dist/types.js +96 -0
- package/package.json +38 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { type Example, type Hit, type PronounChoice, type PronounPerson, type TableTranslation } from './types.ts';
|
|
2
|
+
import { type Dictionary, type LoadJson } from './index.ts';
|
|
3
|
+
/** One meaning of the source word, with its own part of speech and definitions. */
|
|
4
|
+
export type SourceSense = {
|
|
5
|
+
/** The word as given. */
|
|
6
|
+
word: string;
|
|
7
|
+
/** The word this sense belongs to: the base form or standard spelling ("say" for "said", "không" for "hông"). */
|
|
8
|
+
lemma: string;
|
|
9
|
+
pos: string;
|
|
10
|
+
/** English definitions of this sense. */
|
|
11
|
+
glosses: string[];
|
|
12
|
+
regions: string[];
|
|
13
|
+
regionTagged: boolean;
|
|
14
|
+
labels: string[];
|
|
15
|
+
/** How `word` leads to `lemma` when they differ, e.g. "simple past of say" or "Southern Vietnam form of không". */
|
|
16
|
+
via?: string;
|
|
17
|
+
/** Same-language words with this meaning (often other dialects' words). */
|
|
18
|
+
synonyms?: string[];
|
|
19
|
+
/** Example sentences for this meaning. */
|
|
20
|
+
examples?: Example[];
|
|
21
|
+
/** English senses only: Wiktionary's translation table for this meaning (see Sense.translations). */
|
|
22
|
+
translations?: Record<string, TableTranslation[]>;
|
|
23
|
+
};
|
|
24
|
+
/** A target-language word for a source sense. */
|
|
25
|
+
export type Translation = Hit & {
|
|
26
|
+
/** Higher is better. Comparable within one group. */
|
|
27
|
+
score: number;
|
|
28
|
+
/**
|
|
29
|
+
* How this word was found: the English term that linked it, "synonym" for a same-language synonym,
|
|
30
|
+
* "table" for Wiktionary's translation table, or "pronouns" for a pronoun-table row's words (the
|
|
31
|
+
* `listener`'s or `about`'s row, or the default row).
|
|
32
|
+
*/
|
|
33
|
+
bridge: string;
|
|
34
|
+
/** Example sentences for this word in the matched sense, when the dictionary has them. */
|
|
35
|
+
examples?: Example[];
|
|
36
|
+
/** For pronoun-table words: the relationship it's for, e.g. "Your parents". */
|
|
37
|
+
relationship?: string;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* A relationship the source word is used in as "I", "you", "he/she", "we", plural "you" or "they", from the
|
|
41
|
+
* source language's pronoun table (Vietnamese "em": I, talking to someone a bit older; you, talking to
|
|
42
|
+
* someone younger).
|
|
43
|
+
*/
|
|
44
|
+
export type PronounUse = {
|
|
45
|
+
/** Row id, e.g. "older-male". */
|
|
46
|
+
id: string;
|
|
47
|
+
/** Who you're talking to (or about), e.g. "Someone a bit older (man)". */
|
|
48
|
+
label: string;
|
|
49
|
+
/** The table column: 'self' ("I"), 'addressee' ("you"), 'third' ("he/she"), or their plurals. */
|
|
50
|
+
person: PronounPerson;
|
|
51
|
+
/** Only said by a male or female speaker. */
|
|
52
|
+
speaker?: 'male' | 'female';
|
|
53
|
+
/** The gender of the person the word refers to, when it has one. */
|
|
54
|
+
gender?: 'male' | 'female';
|
|
55
|
+
regions: string[];
|
|
56
|
+
regionTagged: boolean;
|
|
57
|
+
note?: string;
|
|
58
|
+
warning?: string;
|
|
59
|
+
};
|
|
60
|
+
/** The words for one person ("I", "you", "he"…) in one relationship, from the target's pronoun table. */
|
|
61
|
+
export type RelationshipWords = {
|
|
62
|
+
/** Row id, usable as `listener` (I/you/we) or `about` (he/she/they). */
|
|
63
|
+
id: string;
|
|
64
|
+
/** Who you're talking to, e.g. "Your parents". */
|
|
65
|
+
label: string;
|
|
66
|
+
words: PronounChoice[];
|
|
67
|
+
warning?: string;
|
|
68
|
+
};
|
|
69
|
+
export type TranslationGroup = {
|
|
70
|
+
source: SourceSense;
|
|
71
|
+
/** English terms used to bridge this sense, main meaning first. */
|
|
72
|
+
bridge: string[];
|
|
73
|
+
/** Best first. */
|
|
74
|
+
translations: Translation[];
|
|
75
|
+
/**
|
|
76
|
+
* For personal-pronoun senses ("I", "you", "he/she", "we", "they"), when the target language has a
|
|
77
|
+
* pronoun table (Vietnamese): the word to use for each relationship, filtered by `toRegion`, `speaker`,
|
|
78
|
+
* `exclude`, and the pronoun's gender (he/she) or inclusiveness (we). Pass one's `id` as `listener`
|
|
79
|
+
* (I/you/we) or `about` (he/she/they) to put its words first.
|
|
80
|
+
*/
|
|
81
|
+
relationships?: RelationshipWords[];
|
|
82
|
+
/**
|
|
83
|
+
* When the source word is in the source language's pronoun table: the relationships it's used in with
|
|
84
|
+
* this meaning. Uses no definition covers get a group of their own, translated as "I", "you", "he"…
|
|
85
|
+
* (Vietnamese "em" is only defined as "younger sibling" and "refers to any person described by em").
|
|
86
|
+
*/
|
|
87
|
+
pronounUses?: PronounUse[];
|
|
88
|
+
};
|
|
89
|
+
export type TranslateOptions = {
|
|
90
|
+
/** Source language code, e.g. "vi". */
|
|
91
|
+
from: string;
|
|
92
|
+
/** Target language code, e.g. "en". Can equal `from` to translate between dialects of one language. */
|
|
93
|
+
to: string;
|
|
94
|
+
/** Region or region group the source word is from, e.g. "Northern". Keeps only senses used there. */
|
|
95
|
+
fromRegion?: string;
|
|
96
|
+
/** Region or region group to translate into, e.g. "Southern". Words tagged for it rank first. */
|
|
97
|
+
toRegion?: string;
|
|
98
|
+
/** Only source senses with this part of speech. */
|
|
99
|
+
pos?: string;
|
|
100
|
+
/** Words describing the meaning you want, e.g. "awesome" for "cool". Matching senses and words rank first. */
|
|
101
|
+
meaning?: string;
|
|
102
|
+
/**
|
|
103
|
+
* The register you want translations in, instead of the source sense's own: 'casual' prefers
|
|
104
|
+
* colloquial words (Southern "tui" for "I"), 'polite' polite/formal ones, 'neutral' plain ones.
|
|
105
|
+
*/
|
|
106
|
+
register?: 'casual' | 'neutral' | 'polite';
|
|
107
|
+
/**
|
|
108
|
+
* Who you're talking to, as a pronoun-table row id of the target language (e.g. Vietnamese "parent",
|
|
109
|
+
* "older-male", "friend"; see Dictionary.pronouns). For "I", "you", "we" and plural "you", that
|
|
110
|
+
* relationship's words come first. Without it, the table's default row's words do (Vietnamese "tôi",
|
|
111
|
+
* "bạn"). Ignored for targets without a pronoun table; unknown ids throw, listing the valid ones.
|
|
112
|
+
*/
|
|
113
|
+
listener?: string;
|
|
114
|
+
/** Who you're talking about, as a row id like `listener`: for "he", "she", "him", "her", "they", "them". */
|
|
115
|
+
about?: string;
|
|
116
|
+
/** The speaker's gender, for pronoun-table words that depend on it ("anh" vs "chị" toward someone younger). */
|
|
117
|
+
speaker?: 'male' | 'female';
|
|
118
|
+
/** Labels to leave out of translations (default DEFAULT_EXCLUDED_LABELS). */
|
|
119
|
+
exclude?: string[];
|
|
120
|
+
/** Maximum translations per source sense (default 5). */
|
|
121
|
+
limit?: number;
|
|
122
|
+
/**
|
|
123
|
+
* Return every sense, including ones with no translation (empty `translations`) and ones whose
|
|
124
|
+
* translations repeat another sense's. Default false. Useful for letting users pick a meaning.
|
|
125
|
+
*/
|
|
126
|
+
allSenses?: boolean;
|
|
127
|
+
};
|
|
128
|
+
export type Translator = {
|
|
129
|
+
/** The senses of a word, following forms and variant spellings to the words they belong to. */
|
|
130
|
+
senses(word: string, options: {
|
|
131
|
+
from: string;
|
|
132
|
+
fromRegion?: string;
|
|
133
|
+
pos?: string;
|
|
134
|
+
}): Promise<SourceSense[]>;
|
|
135
|
+
/** Translations grouped by source sense, most relevant sense first. */
|
|
136
|
+
translate(word: string, options: TranslateOptions): Promise<TranslationGroup[]>;
|
|
137
|
+
};
|
|
138
|
+
export type TranslatorOptions = {
|
|
139
|
+
/** Returns the dictionary for a language. Defaults to createDictionary with the options below. */
|
|
140
|
+
dictionary?: (lang: string) => Dictionary;
|
|
141
|
+
/** Where each language's data is served (see DictionaryOptions.baseUrl). */
|
|
142
|
+
baseUrl?: (lang: string) => string;
|
|
143
|
+
/** Custom loader per language (see DictionaryOptions.load). */
|
|
144
|
+
load?: (lang: string) => LoadJson;
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* Possible base words for a regularly inflected English word, most likely first: "walked" -> walk,
|
|
148
|
+
* "cities" -> city, "making" -> make, "stopped" -> stop. The English data package only stores irregular
|
|
149
|
+
* forms ("said", "went"), so regular ones are undone here.
|
|
150
|
+
*/
|
|
151
|
+
export declare function regularBaseForms(word: string): string[];
|
|
152
|
+
export declare const FREQUENCY_WEIGHT = 1.2;
|
|
153
|
+
export declare function createTranslator(options?: TranslatorOptions): Translator;
|