From dcf5c8ebe7880d4a7e64082eed9bdebc66bc290a Mon Sep 17 00:00:00 2001 From: h7x4 Date: Mon, 2 Mar 2026 11:47:46 +0900 Subject: [PATCH] lemmatizer: implement equality for `AllomorphPattern`/`LemmatizationRule` --- lib/util/lemmatizer/lemmatizer.dart | 40 +++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/lib/util/lemmatizer/lemmatizer.dart b/lib/util/lemmatizer/lemmatizer.dart index d516981..612369e 100644 --- a/lib/util/lemmatizer/lemmatizer.dart +++ b/lib/util/lemmatizer/lemmatizer.dart @@ -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 {