You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The static <dfn method for="Proofreader">create(|options|)</dfn> method steps are:
100
100
101
-
1. Return the result of [=creating an AI model object=] given |options|, "{{proofreader}}", [=validate and canonicalize proofreader options=], [=computing proofreader options availability=], [=download the proofreader model=], [=initialize the proofreader model=], [=create a proofreader object=], and false.
102
-
</div>
101
+
1. Return the result of [=creating an AI model object=] given |options|, "{{Proofreader}}", [=validate and canonicalize proofreader options=], [=compute proofreader options availability=], [=download the proofreader model=], [=initialize the proofreader model=], [=create a proofreader object=], and false.
102
+
</div>
103
103
104
104
<div algorithm>
105
105
To <dfn>validate and canonicalize proofreader options</dfn> given a {{ProofreaderCreateCoreOptions}} |options|, perform the following steps. They mutate |options| in place to canonicalize and deduplicate language tags, and throw an exception if any are invalid.
106
106
107
107
1. [=Validate and canonicalize language tags=] given |options| and "{{ProofreaderCreateCoreOptions/expectedInputLanguages}}".
108
108
109
109
1. [=Validate and canonicalize language tags=] given |options| and "{{ProofreaderCreateCoreOptions/correctionExplanationLanguage}}".
110
-
</div>
110
+
</div>
111
111
112
112
<div algorithm>
113
113
To <dfn>download the proofreader model</dfn>, given a {{ProofreaderCreateCoreOptions}} |options|:
1. If initialization failed for any other reason, then return a [=DOMException error information=] whose [=DOMException error information/name=] is "{{OperationError}}" and whose [=DOMException error information/details=] contain appropriate detail.
134
134
135
135
1. Return null.
136
-
</div>
136
+
</div>
137
137
138
138
<div algorithm>
139
-
To <dfn>create a proofreader object</dfn>, given a [=ECMAScript/realm=] |realm| and a {{ProofreadererCreateOptions}} |options|:
139
+
To <dfn>create a proofreader object</dfn>, given a [=ECMAScript/realm=] |realm| and a {{ProofreaderCreateOptions}} |options|:
140
140
141
141
1. [=Assert=]: these steps are running on |realm|'s [=ECMAScript/surrounding agent=]'s [=agent/event loop=].
142
142
143
143
1. Return a new {{Proofreader}} object, created in |realm|, with
144
144
145
145
<dl class="props">
146
-
boolean includeCorrectionTypes = false;
146
+
boolean includeCorrectionTypes = false;
147
147
boolean includeCorrectionExplanations = false;
148
-
: [=Proofreader/whether to include correction types=]
148
+
: whether to include correction types
149
149
:: |options|["{{ProofreaderCreateCoreOptions/includeCorrectionTypes}}"] default to false
150
150
151
-
: [=Proofreader/whether to include correction explanations=]
151
+
: Proofreader/whether to include correction explanations
152
152
:: |options|["{{ProofreaderCreateCoreOptions/includeCorrectionExplanations}}"] default to false
153
153
154
-
: [=Proofreader/expected input languages=]
154
+
: expected input languages
155
155
:: the result of [=creating a frozen array=] given |options|["{{ProofreaderCreateCoreOptions/expectedInputLanguages}}"] if it [=set/is empty|is not empty=]; otherwise null
156
156
157
-
: [=Proofreader/output language=]
158
-
:: |options|["{{ProofreaderCreateCoreOptions/outputLanguage}}"] if it [=map/exists=]; otherwise null
157
+
: correction explanation language
158
+
:: |options|["{{ProofreaderCreateCoreOptions/correctionExplanationLanguage}}"] if it [=map/exists=]; otherwise null
The static <dfn method for="Proofreader">availability(|options|)</dfn> method steps are:
166
+
167
+
1. Return the result of [=computing AI model availability=] given |options|, "{{Proofreader}}", [=validate and canonicalize proofreader options=], and [=compute proofreader options availability=].
168
+
</div>
169
+
170
+
<div algorithm>
171
+
To <dfn>compute proofreader options availability</dfn> given a {{ProofreaderCreateCoreOptions}} |options|, perform the following steps. They return either an {{Availability}} value or null, and they mutate |options| in place to update language tags to their best-fit matches.
172
+
173
+
1. [=Assert=]: this algorithm is running [=in parallel=].
174
+
175
+
1. Let |availability| be the [=proofreader non-language options availability=] given |options|["{{ProofreaderCreateCoreOptions/includeCorrectionTypes}}"], |options|["{{ProofreaderCreateCoreOptions/includeCorrectionExplanations}}"].
176
+
177
+
1. Let |double| be the [=proofreader language availabilities double=].
178
+
179
+
1. If |double| is null, then return null.
180
+
181
+
1. Let |inputLanguageAvailability| be the result of [=computing language availability=] given |options|["{{ProofreaderCreateCoreOptions/expectedInputLanguages}}"] and |double|'s [=language availabilities double/input languages=].
182
+
183
+
1. Let |correctionExplanationLanguagesList| be « |options|["{{ProofreaderCreateCoreOptions/correctionExplanationLanguage}}"] ».
184
+
185
+
1. Let |correctionExplanationLanguageAvailability| be the result of [=computing language availability=] given |correctionExplanationLanguagesList| and |double|'s [=language availabilities double/correction explanation languages=].
186
+
187
+
1. Set |options|["{{ProofreaderCreateCoreOptions/correctionExplanationLanguage}}"] to |correctionExplanationLanguagesList|[0].
188
+
189
+
1. Return the [=Availability/minimum availability=] given « |availability|, |inputLanguageAvailability|, |contextLanguagesAvailability|, |correctionExplanationLanguageAvailability| ».
190
+
</div>
191
+
192
+
<div algorithm>
193
+
The <dfn>proofreader non-language options availability</dfn>, given a boolean |includeCorrectionTypes| and a boolean |includeCorrectionExplanations|, is given by the following steps. They return an {{Availability}} value or null.
194
+
195
+
1. [=Assert=]: this algorithm is running [=in parallel=].
196
+
197
+
1. If there is some error attempting to determine whether the user agent [=model availability/can support=] proofreading text, which the user agent believes to be transient (such that re-querying could stop producing such an error), then return null.
198
+
199
+
1. If the user agent [=model availability/currently supports=] proofreading text with/without correction types as described by |includeCorrectionTypes| and with/without correction explanations as described by |includeCorrectionExplanations|, then return "{{Availability/available}}".
200
+
201
+
1. If the user agent believes it will be able to [=model availability/support=] proofreading text according to |includeCorrectionTypes| and |includeCorrectionExplanations|, but only after finishing a download that is already ongoing, then return "{{Availability/downloading}}".
202
+
203
+
1. If the user agent believes it will be able to [=model availability/support=] proofreading text according to |includeCorrectionTypes| and |includeCorrectionExplanations|, but only after performing a not-currently-ongoing download, then return "{{Availability/downloadable}}".
The <dfn>proofreader language availabilities double</dfn> is given by the following steps. They return a [=language availabilities double=] or null.
210
+
211
+
1. [=Assert=]: this algorithm is running [=in parallel=].
212
+
213
+
1. If there is some error attempting to determine whether the user agent [=model availability/can support=] proofreading text, which the user agent believes to be transient (such that re-querying could stop producing such an error), then return null.
214
+
215
+
1. Return a [=language availabilities double=] with:
:: the result of [=getting the language availabilities partition=] given the purpose of producing text explanations of proofreading corrections in that language
A common setup seen in today's software is to support two types of written Chinese: "traditional Chinese" and "simplified Chinese". Let's suppose that the user agent supports summarizing text written in traditional Chinese with no downloads, and simplified Chinese after a download.
228
+
229
+
One way this could be implemented would be for [=proofreader language availabilities double=] to return that "`zh-Hant`" is in the [=language availabilities double/input languages=]["{{Availability/available}}"] set, and "`zh`" and "`zh-Hans`" are in the [=language availabilities double/input languages=]["{{Availability/downloadable}}"] set. This return value conforms to the requirements of the [=language tag set completeness rules=], in ensuring that "`zh`" is present. Per <a class="allow-2119" href="#language-tag-completeness-implementation-defined">the "should"-level guidance</a>, the implementation has determined that "`zh`" belongs in the set of downloadable input languages, with "`zh-Hans`", instead of in the set of available input languages, with "`zh-Hant`".
230
+
231
+
Combined with the use of [$LookupMatchingLocaleByBestFit$], this means {{Proofreader/availability()}} will give the following answers:
232
+
233
+
<xmp class="language-js">
234
+
function a(languageTag) {
235
+
return Proofreader.availability({
236
+
expectedInputLanguages: [languageTag]
237
+
});
238
+
}
239
+
240
+
await a("zh") === "downloadable";
241
+
await a("zh-Hant") === "available";
242
+
await a("zh-Hans") === "downloadable";
243
+
244
+
await a("zh-TW") === "available"; // zh-TW will best-fit to zh-Hant
245
+
await a("zh-HK") === "available"; // zh-HK will best-fit to zh-Hant
246
+
await a("zh-CN") === "downloadable"; // zh-CN will best-fit to zh-Hans
247
+
248
+
await a("zh-BR") === "downloadable"; // zh-BR will best-fit to zh
249
+
await a("zh-Kana") === "downloadable"; // zh-Kana will best-fit to zh
0 commit comments