lemmatizer: add some basic tests
This commit is contained in:
51
test/util/lemmatizer/lemmatizer_test.dart
Normal file
51
test/util/lemmatizer/lemmatizer_test.dart
Normal file
@@ -0,0 +1,51 @@
|
||||
import 'package:jadb/util/lemmatizer/lemmatizer.dart';
|
||||
import 'package:jadb/util/lemmatizer/rules/godan_verbs.dart';
|
||||
import 'package:jadb/util/lemmatizer/rules/ichidan_verbs.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
const List<String> ichidanVerbs = [
|
||||
'食べる',
|
||||
'食べた',
|
||||
'食べさせられた',
|
||||
'食べたい',
|
||||
'食べたくない',
|
||||
'食べたくなかった',
|
||||
];
|
||||
const List<String> godanVerbs = [
|
||||
'泳ぐ',
|
||||
'泳いだ',
|
||||
'泳げる',
|
||||
// '泳げれた',
|
||||
];
|
||||
|
||||
bool findRuleRecursively(Lemmatized result, LemmatizationRule expectedRule) {
|
||||
if (result.rule == expectedRule) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (final c in result.children) {
|
||||
if (findRuleRecursively(c, expectedRule)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void main() {
|
||||
group('Lemmatize Ichidan Verbs', () {
|
||||
for (final v in ichidanVerbs) {
|
||||
test('Lemmatize Ichidan Verb $v', () {
|
||||
expect(findRuleRecursively(lemmatize(v), ichidanVerbBase), true);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
group('Lemmatize Godan Verbs', () {
|
||||
for (final v in godanVerbs) {
|
||||
test('Lemmatize Godan Verb $v', () {
|
||||
expect(findRuleRecursively(lemmatize(v), godanVerbBase), true);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
14
test/util/lemmatizer/rules/godan_verbs_test.dart
Normal file
14
test/util/lemmatizer/rules/godan_verbs_test.dart
Normal file
@@ -0,0 +1,14 @@
|
||||
import 'package:jadb/util/lemmatizer/rules/godan_verbs.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
test('Test Godan Verb Base Rule', () {
|
||||
expect(godanVerbBase.matches('泳ぐ'), true);
|
||||
expect(godanVerbBase.apply('泳ぐ'), ['泳ぐ']);
|
||||
});
|
||||
|
||||
test('Test Godan Verb Negative Rule', () {
|
||||
expect(godanVerbNegative.matches('泳がない'), true);
|
||||
expect(godanVerbNegative.apply('泳がない'), ['泳ぐ']);
|
||||
});
|
||||
}
|
||||
15
test/util/lemmatizer/rules/i_adjectives_test.dart
Normal file
15
test/util/lemmatizer/rules/i_adjectives_test.dart
Normal file
@@ -0,0 +1,15 @@
|
||||
import 'package:jadb/util/lemmatizer/rules/i_adjectives.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
test('Test i-adjective Base Rule', () {
|
||||
expect(iAdjectiveBase.matches('怪しい'), true);
|
||||
expect(iAdjectiveBase.apply('怪しい'), ['怪しい']);
|
||||
});
|
||||
|
||||
|
||||
test('Test i-adjective Negative Rule', () {
|
||||
expect(iAdjectiveNegative.matches('怪しくない'), true);
|
||||
expect(iAdjectiveNegative.apply('怪しくない'), ['怪しい']);
|
||||
});
|
||||
}
|
||||
14
test/util/lemmatizer/rules/ichidan_verbs_test.dart
Normal file
14
test/util/lemmatizer/rules/ichidan_verbs_test.dart
Normal file
@@ -0,0 +1,14 @@
|
||||
import 'package:jadb/util/lemmatizer/rules/ichidan_verbs.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
test('Test Ichidan Verb Base Rule', () {
|
||||
expect(ichidanVerbBase.matches('食べる'), true);
|
||||
expect(ichidanVerbBase.apply('食べる'), ['食べる']);
|
||||
});
|
||||
|
||||
test('Test Ichidan Verb Negative Rule', () {
|
||||
expect(ichidanVerbNegative.matches('食べない'), true);
|
||||
expect(ichidanVerbNegative.apply('食べない'), ['食べる']);
|
||||
});
|
||||
}
|
||||
15
test/util/lemmatizer/rules_test.dart
Normal file
15
test/util/lemmatizer/rules_test.dart
Normal file
@@ -0,0 +1,15 @@
|
||||
import 'package:jadb/util/lemmatizer/lemmatizer.dart';
|
||||
import 'package:jadb/util/lemmatizer/rules.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
test('Assert lemmatizerRulesByWordClass is correct', () {
|
||||
for (final entry in lemmatizationRulesByWordClass.entries) {
|
||||
final WordClass wordClass = entry.key;
|
||||
final List<LemmatizationRule> rules = entry.value;
|
||||
for (final LemmatizationRule rule in rules) {
|
||||
expect(wordClass, rule.wordClass);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user