lemmatizer: implement equality for AllomorphPattern/LemmatizationRule

This commit is contained in:
2026-03-02 11:47:46 +09:00
parent 1f8bc8bac5
commit dcf5c8ebe7

View File

@@ -1,3 +1,4 @@
import 'package:collection/collection.dart';
import 'package:jadb/util/lemmatizer/rules.dart';
enum WordClass {
@@ -10,6 +11,8 @@ enum WordClass {
adverb,
particle,
input,
// TODO: add toString and fromString so it can be parsed by the cli
}
enum LemmatizationRuleType { prefix, suffix }
@@ -55,6 +58,27 @@ class LemmatizationRule {
terminal: terminal,
wordClass: wordClass,
);
@override
int get hashCode => Object.hash(
name,
pattern,
wordClass,
validChildClasses,
terminal,
SetEquality().hash(validChildClasses),
);
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is LemmatizationRule &&
other.name == name &&
other.pattern == pattern &&
other.wordClass == wordClass &&
other.terminal == terminal &&
SetEquality().equals(validChildClasses, other.validChildClasses);
}
}
/// Represents a set of patterns for matching allomorphs in a word.
@@ -162,6 +186,22 @@ class AllomorphPattern {
}
return null;
}
@override
int get hashCode => Object.hash(
type,
ListEquality().hash(lookAheadBehind),
MapEquality().hash(patterns),
);
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is AllomorphPattern &&
other.type == type &&
ListEquality().equals(other.lookAheadBehind, lookAheadBehind) &&
MapEquality().equals(other.patterns, patterns);
}
}
class Lemmatized {