Skip to content

Commit 2e78642

Browse files
committed
Update language availability handling
This follows webmachinelearning/writing-assistance-apis@5e2230e.
1 parent 300eec8 commit 2e78642

1 file changed

Lines changed: 4 additions & 26 deletions

File tree

index.bs

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -569,37 +569,16 @@ dictionary LanguageDetectionResult {
569569
1. Return the result of [=computing AI model availability=] given |options|, "{{language-detector}}", [=validate and canonicalize language detector options=], and [=compute language detector options availability=].
570570
</div>
571571

572-
<!-- TODO: consider deduping this with writing assistance APIs, as it's very similar. (Not similar to translator though!) -->
573572
<div algorithm>
574573
To <dfn>compute language detector options availability</dfn> given a {{LanguageDetectorCreateCoreOptions}} |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.
575574

576575
1. [=Assert=]: this algorithm is running [=in parallel=].
577576

578577
1. If there is some error attempting to determine what languages the user agent supports detecting, which the user agent believes to be transient (such that re-querying could stop producing such an error), then return null.
579578

580-
1. Let |availabilities| be the result of [=getting language availabilities=] given the purpose of detecting text written in that language.
579+
1. Let |partition| be the result of [=getting the language availabilities partition=] given the purpose of detecting text written in that language.
581580

582-
1. Let |availability| be "{{Availability/available}}".
583-
584-
1. [=set/For each=] |language| in |options|["{{LanguageDetectorCreateCoreOptions/expectedInputLanguages}}"]:
585-
586-
1. [=list/For each=] |availabilityToCheck| in « "{{Availability/available}}", "{{Availability/downloading}}", "{{Availability/downloadable}}" »:
587-
588-
1. Let |languagesWithThisAvailability| be |availabilities|[|availabilityToCheck|].
589-
590-
1. Let |bestMatch| be [$LookupMatchingLocaleByBestFit$](|languagesWithThisAvailability|, « |language| »).
591-
592-
1. If |bestMatch| is not undefined, then:
593-
594-
1. [=list/Replace=] |language| with |bestMatch|.\[[locale]] in |options|["{{LanguageDetectorCreateCoreOptions/expectedInputLanguages}}"].
595-
596-
1. Set |availability| to the [=Availability/minimum availability=] given |availability| and |availabilityToCheck|.
597-
598-
1. [=iteration/Break=].
599-
600-
1. Return "{{Availability/unavailable}}".
601-
602-
1. Return |availability|.
581+
1. Return the result of [=computing language availability=] given |options|["{{LanguageDetectorCreateCoreOptions/expectedInputLanguages}}"] and |partition|.
603582
</div>
604583

605584
<h3 id="the-LanguageDetector-class">The {{LanguageDetector}} class</h3>
@@ -616,7 +595,6 @@ The <dfn attribute for="LanguageDetector">inputQuota</dfn> getter steps are to r
616595

617596
<hr>
618597

619-
<!-- TODO: consider deduping *SOME* of this with "get an aggregated AI model result", as it's similar. But this case is fundamentally less streaming, so the cut will be tricky. -->
620598
<div algorithm>
621599
The <dfn method for="LanguageDetector">detect(|input|, |options|)</dfn> method steps are:
622600

@@ -688,9 +666,9 @@ The <dfn attribute for="LanguageDetector">inputQuota</dfn> getter steps are to r
688666

689667
<p class="note">In reality, we expect that implementations will check the input usage against the quota as part of the same call into the model as the language detection itself. The steps are only separated in the specification for ease of understanding.
690668

691-
1. Let |availabilities| be the result of [=getting language availabilities=] given the purpose of detecting text written in that language.
669+
1. Let |partition| be the result of [=getting the language availabilities partition=] given the purpose of detecting text written in that language.
692670

693-
1. Let |currentlyAvailableLanguages| be |availabilities|["{{Availability/available}}"].
671+
1. Let |currentlyAvailableLanguages| be |partition|["{{Availability/available}}"].
694672

695673
1. In an [=implementation-defined=] manner, subject to the following guidelines, let |rawResult| and |unknown| be the result of detecting the languages of |input|.
696674

0 commit comments

Comments
 (0)