Skip to content

Commit

Permalink
[bfcache]Add new AILanguageDetector* classes and functions
Browse files Browse the repository at this point in the history
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
rubberyuzu authored and chromium-wpt-export-bot committed Oct 7, 2024
1 parent 3c28f7d commit f0df204
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ai/language_detection/capabilities.tentative.window.js
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.
});
14 changes: 14 additions & 0 deletions ai/language_detection/detector.tentative.window.js
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);
}
});

0 comments on commit f0df204

Please sign in to comment.