halkyon/halkyon_learn_flutter/test/feature/dictionary/japanese_deinflection_test.dart
Tizian 「ティツィアーン」 da51ef73cb
feat(jellyfin): watch from one's own Jellyfin server and learn the words of its subtitles
Animelon's way of learning from video, from the person's own Jellyfin
server: connected per device (Settings, or a studyset's Add material ›
Watch from Jellyfin) with a name and password or a Quick Connect code,
over HTTPS only (plain HTTP only to a server on the same machine); the
token stays in the system's keyring. Shows, films and videos tied to a
studyset follow the person in their settings as the server's and the
item's ids alone (settings schema 9), named by the server when shown.

The Watch screen plays the video (video_player on Android, media_kit's
libmpv on Linux and Windows) with the line in the studyset's front
language cut into the dictionary's words with furigana, and the back
language's line beneath; a word tapped pauses the video and becomes a
card with the line and its translation as its first hint, tagged with
the show. The video's words are listed, most frequent first. The sound is
the track in the studyset's language, whichever the file marks default,
and the menu switches it; the subtitles read are a whole track, never a
forced one (which only covers what the sound doesn't say), and captions
for the hard of hearing only without plain ones. The line and its
translation take the video's width in a box of a fixed height, so the
video keeps its size; in the dark theme the video's colours glow around
it, as YouTube's ambient mode, and the words' panel takes the colour of
the episode's picture under the pointer.

A line is cut into words with one request: DictionaryEndpoint.withKeys
looks up every stretch of it that may be a word, as it stands and as
every word it may be a conjugation of, in the new dictionary_key table
(one row per key, indexed; migration dictionary-keys adds the table and
its index, nothing else), which the loader fills beside the entries.
The instance gets the text of each line looked up and keeps none of it,
as the Watch screen says.

Linux builds need libmpv-dev, and the app links libmpv: the snap stages
Ubuntu's libmpv2, makes the update-alternatives links for BLAS and LAPACK
that ffmpeg's speech recognition needs (staging never runs install
scripts), and removes what the GNOME runtime and core24 already hold, as
older copies of cairo, pango and librsvg hid the runtime's from its GTK.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
2026-10-13 21:21:48 +02:00

69 lines
3 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:halkyon_learn_flutter/src/feature/dictionary/model/japanese_deinflection.dart';
/// The words [text] deinflects to that a dictionary entry of [pos] fits.
Set<String> wordsOf(String text, List<String> pos) => {
for (final each in deinflect(text))
if (each.fits(pos)) each.text,
};
void main() {
test('the text as it stands comes first, and fits any word', () {
final first = deinflect('天気').first;
expect(first.text, '天気');
expect(first.steps, isEmpty);
expect(first.form, isNull);
expect(first.fits(const ['n']), isTrue);
});
test('verbs come back to their dictionary form', () {
expect(wordsOf('会いました', ['v5u']), contains('会う'));
expect(wordsOf('読んだ', ['v5m']), contains('読む'));
expect(wordsOf('読んでいない', ['v5m']), contains('読む'));
expect(wordsOf('食べられなかった', ['v1']), contains('食べる'));
expect(wordsOf('出ていった', ['v1']), contains('出る'));
expect(wordsOf('残っている', ['v5r']), contains('残る'));
expect(wordsOf('続けよう', ['v1']), contains('続ける'));
expect(wordsOf('行かなければ', ['v5k-s']), contains('行く'));
expect(wordsOf('なりたい', ['v5r']), contains('なる'));
expect(wordsOf('使える', ['v5u']), contains('使う'));
expect(wordsOf('食べちゃった', ['v1']), contains('食べる'));
expect(wordsOf('読まれた', ['v5m']), contains('読む'));
expect(wordsOf('来ない', ['vk']), contains('来る'));
expect(wordsOf('きました', ['vk']), contains('くる'));
});
test('adjectives and nouns taking する come back too', () {
expect(wordsOf('面白そう', ['adj-i']), contains('面白い'));
expect(wordsOf('早く', ['adj-i']), contains('早い'));
expect(wordsOf('高くなかった', ['adj-i']), contains('高い'));
expect(wordsOf('高すぎた', ['adj-i']), contains('高い'));
expect(wordsOf('勉強した', ['n', 'vs']), contains('勉強'));
});
test('a form only counts for a word of its class', () {
// 読んだ as the past of an ichidan verb 読んる doesn't exist; as the
// past of a godan verb in ぬ or ぶ it would, were there such a word.
expect(wordsOf('読んだ', ['v1']), isNot(contains('読む')));
expect(wordsOf('食べた', ['v5r']), isNot(contains('食べる')));
expect(wordsOf('早く', ['v1']), isNot(contains('早い')));
});
test('stems and forms that only lead on are never offered as words', () {
expect(
deinflect('食べて').map((each) => each.form),
isNot(contains(JapaneseForm.te)),
);
expect(
deinflect('会いました').map((each) => each.form),
isNot(contains(JapaneseForm.masuStem)),
);
});
test('says how it got there, the last step first', () {
final cake = deinflect('食べられなかった').firstWhere(
(each) => each.text == '食べる' && each.form == JapaneseForm.ichidan,
);
expect(cake.steps, ['passive or potential', 'negative', 'past']);
});
}