forked from web-platform-tests/wpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[bfcache]Add new AILanguageDetector* classes and functions
This CL adds new AILanguageDetector/AILanguageDetectorFactory/ AILanguageDetectorCapabilities classes to match the new version of API proposal[1]. Functions are mostly copied and pasted from the old version of the code. [1] https://github.com/WICG/translation-api?tab=readme-ov-file#full-api-surface-in-web-idl Bug: 349927087 Change-Id: I1eed4cb0d54e8388398aef642943c0d6a76857f1 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5892958 Reviewed-by: Fergal Daly <[email protected]> Commit-Queue: Yuzu Saijo <[email protected]> Cr-Commit-Position: refs/heads/main@{#1364800}
- Loading branch information
1 parent
3c28f7d
commit f0df204
Showing
4 changed files
with
24 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// META: title=capabilities test | ||
|
||
'use strict'; | ||
|
||
promise_test(async t => { | ||
const languageDetectorCapabilities = await ai.languageDetector.capabilities(); | ||
const availability = languageDetectorCapabilities.available; | ||
assert_not_equals(availability, "no"); | ||
// TODO(crbug.com/349927087): Add languageDetectorCapabilities.canDetect("en") once implemented. | ||
}); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// META: title=Detect english | ||
|
||
'use strict'; | ||
|
||
promise_test(async t => { | ||
const detector = await ai.languageDetector.create(); | ||
const results = await detector.detect("this string is in English"); | ||
// "en" should be highest confidence. | ||
assert_equals(results[0].detectedLanguage, "en"); | ||
// Results should be from high to low confidence. | ||
for (let i = 0; i < results.length - 1; i++) { | ||
assert_greater_than_equal(results[i].confidence, results[i + 1].confidence); | ||
} | ||
}); |