Skip to content

Commit 13f7221

Browse files
authored
Add Creation and Availability section
1 parent f9adf49 commit 13f7221

File tree

1 file changed

+105
-14
lines changed

1 file changed

+105
-14
lines changed

index.bs

Lines changed: 105 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ interface Proofreader {
5757
readonly attribute boolean includeCorrectionExplanations;
5858

5959
readonly attribute FrozenArray<DOMString>? expectedInputLanguages;
60-
readonly attribute DOMString? outputLanguage;
60+
readonly attribute DOMString? correctionExplanationLanguage;
6161
};
6262

6363
dictionary ProofreaderCreateCoreOptions {
6464
boolean includeCorrectionTypes = false;
6565
boolean includeCorrectionExplanations = false;
6666

6767
sequence<DOMString> expectedInputLanguages;
68-
DOMString outputLanguage;
68+
DOMString correctionExplanationLanguage;
6969
};
7070

7171
dictionary ProofreaderCreateOptions : ProofreaderCreateCoreOptions {
@@ -98,16 +98,16 @@ enum CorrectionType { "spelling", "punctuation", "capitalization", "grammar" };
9898
<div algorithm>
9999
The static <dfn method for="Proofreader">create(|options|)</dfn> method steps are:
100100

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>
103103

104104
<div algorithm>
105105
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.
106106

107107
1. [=Validate and canonicalize language tags=] given |options| and "{{ProofreaderCreateCoreOptions/expectedInputLanguages}}".
108108

109109
1. [=Validate and canonicalize language tags=] given |options| and "{{ProofreaderCreateCoreOptions/correctionExplanationLanguage}}".
110-
</div>
110+
</div>
111111

112112
<div algorithm>
113113
To <dfn>download the proofreader model</dfn>, given a {{ProofreaderCreateCoreOptions}} |options|:
@@ -119,7 +119,7 @@ enum CorrectionType { "spelling", "punctuation", "capitalization", "grammar" };
119119
1. If the download process cannot be started for any reason, then return false.
120120

121121
1. Return true.
122-
</div>
122+
</div>
123123

124124
<div algorithm>
125125
To <dfn>initialize the proofreader model</dfn>, given a {{ProofreaderCreateOptions}} |options|:
@@ -133,32 +133,123 @@ enum CorrectionType { "spelling", "punctuation", "capitalization", "grammar" };
133133
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.
134134

135135
1. Return null.
136-
</div>
136+
</div>
137137

138138
<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|:
140140

141141
1. [=Assert=]: these steps are running on |realm|'s [=ECMAScript/surrounding agent=]'s [=agent/event loop=].
142142

143143
1. Return a new {{Proofreader}} object, created in |realm|, with
144144

145145
<dl class="props">
146-
boolean includeCorrectionTypes = false;
146+
boolean includeCorrectionTypes = false;
147147
boolean includeCorrectionExplanations = false;
148-
: [=Proofreader/whether to include correction types=]
148+
: whether to include correction types
149149
:: |options|["{{ProofreaderCreateCoreOptions/includeCorrectionTypes}}"] default to false
150150

151-
: [=Proofreader/whether to include correction explanations=]
151+
: Proofreader/whether to include correction explanations
152152
:: |options|["{{ProofreaderCreateCoreOptions/includeCorrectionExplanations}}"] default to false
153153

154-
: [=Proofreader/expected input languages=]
154+
: expected input languages
155155
:: the result of [=creating a frozen array=] given |options|["{{ProofreaderCreateCoreOptions/expectedInputLanguages}}"] if it [=set/is empty|is not empty=]; otherwise null
156156

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
159+
</dl>
160+
</div>
161+
162+
<h3 id="proofreader-availability">Availability</h3>
163+
164+
<div algorithm>
165+
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}}".
204+
205+
1. Otherwise, return "{{Availability/unavailable}}".
206+
</div>
207+
208+
<div algorithm>
209+
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:
216+
217+
<dl class="props">
218+
: [=language availabilities double/input languages=]
219+
:: the result of [=getting the language availabilities partition=] given the purpose of proofreading text written in that language
220+
221+
: [=language availabilities double/correction explanation languages=]
222+
:: the result of [=getting the language availabilities partition=] given the purpose of producing text explanations of proofreading corrections in that language
159223
</dl>
160224
</div>
161225

226+
<div class="example" id="example-subtags-chinese">
227+
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
250+
</xmp>
251+
</div>
252+
162253
<h2 id="supporting">Shared infrastructure</h2>
163254

164255
<h3 id="shared-apis">Common APIs</h3>

0 commit comments

Comments
 (0)