group together 'other' category with more specific categories (#1026)
This commit is contained in:
parent
5f8c9439b0
commit
25ddceac7b
6 changed files with 74 additions and 27 deletions
|
|
@ -63,14 +63,49 @@ class ConstructListModel {
|
|||
/// key = lemmma + constructType.string, value = ConstructUses
|
||||
void _updateConstructMap(final List<OneConstructUse> newUses) {
|
||||
for (final use in newUses) {
|
||||
final currentUses = _constructMap[use.identifier.string] ??
|
||||
ConstructUses(
|
||||
ConstructUses? currentUses;
|
||||
if (use.category.toLowerCase() == "other") {
|
||||
final specificKey = _constructMap.keys.firstWhereOrNull(
|
||||
(key) => key.startsWith(use.identifier.partialString),
|
||||
);
|
||||
|
||||
if (specificKey != null) {
|
||||
currentUses = _constructMap[specificKey];
|
||||
use.category = currentUses!.category;
|
||||
} else if (_constructMap.containsKey(use.identifier.string)) {
|
||||
currentUses = _constructMap[use.identifier.string];
|
||||
} else {
|
||||
currentUses = ConstructUses(
|
||||
uses: [],
|
||||
constructType: use.constructType,
|
||||
lemma: use.lemma,
|
||||
category: use.category,
|
||||
);
|
||||
currentUses.uses.add(use);
|
||||
}
|
||||
} else {
|
||||
final broadKey = _constructMap.keys.firstWhereOrNull(
|
||||
(key) =>
|
||||
key.startsWith(use.identifier.partialString) &&
|
||||
key.toLowerCase().endsWith("other"),
|
||||
);
|
||||
|
||||
if (broadKey != null) {
|
||||
currentUses = _constructMap[broadKey];
|
||||
for (final broadUse in currentUses!.uses) {
|
||||
broadUse.category = use.category;
|
||||
}
|
||||
_constructMap.remove(broadKey);
|
||||
} else {
|
||||
currentUses = _constructMap[use.identifier.string] ??
|
||||
ConstructUses(
|
||||
uses: [],
|
||||
constructType: use.constructType,
|
||||
lemma: use.lemma,
|
||||
category: use.category,
|
||||
);
|
||||
}
|
||||
}
|
||||
currentUses!.uses.add(use);
|
||||
currentUses.setLastUsed(use.timeStamp);
|
||||
_constructMap[use.identifier.string] = currentUses;
|
||||
}
|
||||
|
|
@ -127,28 +162,38 @@ class ConstructListModel {
|
|||
}
|
||||
}
|
||||
|
||||
ConstructUses? getConstructUses(ConstructIdentifier identifier) {
|
||||
final partialKey = "${identifier.lemma}-${identifier.type.string}";
|
||||
ConstructUses? _getPartialSpecificMatch(ConstructIdentifier identifier) {
|
||||
return _constructMap.entries
|
||||
.firstWhereOrNull(
|
||||
(entry) =>
|
||||
entry.key.startsWith(identifier.partialString) &&
|
||||
!entry.key.toLowerCase().endsWith("other"),
|
||||
)
|
||||
?.value;
|
||||
}
|
||||
|
||||
ConstructUses? _getPartialBroadMatch(ConstructIdentifier identifier) {
|
||||
return _constructMap.entries
|
||||
.firstWhereOrNull(
|
||||
(entry) =>
|
||||
entry.key.startsWith(identifier.partialString) &&
|
||||
entry.key.toLowerCase().endsWith("other"),
|
||||
)
|
||||
?.value;
|
||||
}
|
||||
|
||||
ConstructUses? getConstructUses(ConstructIdentifier identifier) {
|
||||
if (_constructMap.containsKey(identifier.string)) {
|
||||
// try to get construct use entry with full ID key
|
||||
return _constructMap[identifier.string];
|
||||
} else if (identifier.category.toLowerCase() == "other") {
|
||||
} else if (identifier.isOther) {
|
||||
// if the category passed to this function is "other", return the first
|
||||
// construct use entry that starts with the partial key
|
||||
return _constructMap.entries
|
||||
.firstWhereOrNull((entry) => entry.key.startsWith(partialKey))
|
||||
?.value;
|
||||
return _getPartialSpecificMatch(identifier);
|
||||
} else {
|
||||
// if the category passed to this function is not "other", return the first
|
||||
// construct use entry that starts with the partial key and ends with "other"
|
||||
return _constructMap.entries
|
||||
.firstWhereOrNull(
|
||||
(entry) =>
|
||||
entry.key.startsWith(partialKey) &&
|
||||
entry.key.toLowerCase().endsWith("other"),
|
||||
)
|
||||
?.value;
|
||||
return _getPartialBroadMatch(identifier);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ class ConstructUses {
|
|||
_lastUsed = time;
|
||||
}
|
||||
|
||||
String get category => _category ?? "Other";
|
||||
String get category => _category ?? "other";
|
||||
|
||||
ConstructIdentifier get id => ConstructIdentifier(
|
||||
lemma: lemma,
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ class OneConstructUse {
|
|||
: categoryEntry is List && categoryEntry.isNotEmpty
|
||||
? categoryEntry.first
|
||||
: null;
|
||||
return category ?? "Other";
|
||||
return category ?? "other";
|
||||
}
|
||||
|
||||
if (categoryEntry == null) {
|
||||
|
|
@ -168,7 +168,7 @@ class OneConstructUse {
|
|||
ErrorHandler.logError(
|
||||
m: "Morph construct lemma $morphLemma not found in morph categories and labels",
|
||||
);
|
||||
return "Other";
|
||||
return "other";
|
||||
}
|
||||
|
||||
Room? getRoom(Client client) {
|
||||
|
|
|
|||
|
|
@ -62,9 +62,7 @@ class ConstructIdentifier {
|
|||
return other is ConstructIdentifier &&
|
||||
other.lemma == lemma &&
|
||||
other.type == type &&
|
||||
(category == other.category ||
|
||||
category.toLowerCase() == "other" ||
|
||||
other.category.toLowerCase() == "other");
|
||||
(category == other.category || isOther || other.isOther);
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
@ -73,7 +71,11 @@ class ConstructIdentifier {
|
|||
}
|
||||
|
||||
String get string =>
|
||||
"$lemma-${type.string}${category != "" ? "-$category" : "-other"}";
|
||||
"$partialString${category != "" ? "-$category" : "-other"}".toLowerCase();
|
||||
|
||||
String get partialString => "$lemma:${type.string}".toLowerCase();
|
||||
|
||||
bool get isOther => category.toLowerCase() == "other";
|
||||
}
|
||||
|
||||
class CandidateMessage {
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ String? getGrammarCopy({
|
|||
required String lemma,
|
||||
required BuildContext context,
|
||||
}) {
|
||||
if (category.toLowerCase() == 'other') {
|
||||
if (category.toLowerCase() == "other") {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,8 +34,8 @@ class AnalyticsPopupState extends State<AnalyticsPopup> {
|
|||
// Sort the list with custom logic
|
||||
entries.sort((a, b) {
|
||||
// Check if one of the keys is 'Other'
|
||||
if (a.key == 'Other') return 1;
|
||||
if (b.key == 'Other') return -1;
|
||||
if (a.key.toLowerCase() == "other") return 1;
|
||||
if (b.key.toLowerCase() == "other") return -1;
|
||||
|
||||
// Sort by the length of the list in descending order
|
||||
final aTotalPoints = a.value.fold<int>(
|
||||
|
|
@ -73,7 +73,7 @@ class AnalyticsPopupState extends State<AnalyticsPopup> {
|
|||
final bool hasNoData =
|
||||
_constructsModel.constructList(type: widget.type).isEmpty;
|
||||
final bool hasNoCategories = _categoriesToUses.length == 1 &&
|
||||
_categoriesToUses.entries.first.key == "Other";
|
||||
_categoriesToUses.entries.first.key.toLowerCase() == "other";
|
||||
|
||||
if (selectedCategory != null) {
|
||||
dialogContent = Column(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue