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
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=].
570
570
</div>
571
571
572
-
<!-- TODO: consider deduping this with writing assistance APIs, as it's very similar. (Not similar to translator though!) -->
573
572
<div algorithm>
574
573
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.
575
574
576
575
1. [=Assert=]: this algorithm is running [=in parallel=].
577
576
578
577
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.
579
578
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.
581
580
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|.
@@ -616,7 +595,6 @@ The <dfn attribute for="LanguageDetector">inputQuota</dfn> getter steps are to r
616
595
617
596
<hr>
618
597
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. -->
620
598
<div algorithm>
621
599
The <dfn method for="LanguageDetector">detect(|input|, |options|)</dfn> method steps are:
622
600
@@ -688,9 +666,9 @@ The <dfn attribute for="LanguageDetector">inputQuota</dfn> getter steps are to r
688
666
689
667
<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.
690
668
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.
692
670
693
-
1. Let |currentlyAvailableLanguages| be |availabilities|["{{Availability/available}}"].
671
+
1. Let |currentlyAvailableLanguages| be |partition|["{{Availability/available}}"].
694
672
695
673
1. In an [=implementation-defined=] manner, subject to the following guidelines, let |rawResult| and |unknown| be the result of detecting the languages of |input|.
0 commit comments