lemmatizer: implement equality for AllomorphPattern/LemmatizationRule
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user