Skip to content

Commit

Permalink
Extract normalize tag prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
violet-dev committed Dec 30, 2024
1 parent 91a7339 commit b526f76
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions violet/lib/component/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,34 +140,6 @@ class HentaiIndex {
return tagCount![classification][name];
}

static String normalizeTagPrefix(String pp) {
switch (pp) {
case 'tags':
return 'tag';

case 'language':
case 'languages':
return 'lang';

case 'artists':
return 'artist';

case 'groups':
return 'group';

case 'types':
return 'type';

case 'characters':
return 'character';

case 'classes':
return 'class';
}

return pp;
}

static Future<List<(DisplayedTag, int)>> queryAutoComplete(String prefix,
[bool useTranslated = false]) async {
await loadCountMapIfRequired();
Expand All @@ -184,7 +156,7 @@ class HentaiIndex {
static List<(DisplayedTag, int)> _queryAutoCompleteWithTagmap(
String prefix, bool useTranslated) {
final groupOrig = prefix.split(':')[0];
final group = normalizeTagPrefix(groupOrig);
final group = _normalizeTagPrefix(groupOrig);
final name = prefix.split(':').last;

final results = <(DisplayedTag, int)>[];
Expand Down Expand Up @@ -250,7 +222,7 @@ class HentaiIndex {

if (prefix.contains(':')) {
final groupOrig = prefix.split(':')[0];
final group = normalizeTagPrefix(groupOrig);
final group = _normalizeTagPrefix(groupOrig);
final name = prefix.split(':').last;

// <Tag, Similarity, Count>
Expand Down Expand Up @@ -424,3 +396,31 @@ class HentaiIndex {
return ll;
}
}

String _normalizeTagPrefix(String pp) {
switch (pp) {
case 'tags':
return 'tag';

case 'language':
case 'languages':
return 'lang';

case 'artists':
return 'artist';

case 'groups':
return 'group';

case 'types':
return 'type';

case 'characters':
return 'character';

case 'classes':
return 'class';
}

return pp;
}

0 comments on commit b526f76

Please sign in to comment.