@@ -0,0 +1,40 @@
|
||||
export const ASR_CONTENT_TAGS = [
|
||||
"美女",
|
||||
"游戏",
|
||||
"时政",
|
||||
"美食",
|
||||
"旅行",
|
||||
"体育",
|
||||
"科技",
|
||||
"教育",
|
||||
"宠物",
|
||||
"音乐",
|
||||
"影视",
|
||||
"财经",
|
||||
"生活",
|
||||
"其他",
|
||||
] as const;
|
||||
|
||||
export type AsrContentTag = (typeof ASR_CONTENT_TAGS)[number];
|
||||
|
||||
const asrContentTagSet = new Set<string>(ASR_CONTENT_TAGS);
|
||||
|
||||
export function isAsrContentTag(value: string): value is AsrContentTag {
|
||||
return asrContentTagSet.has(value);
|
||||
}
|
||||
|
||||
export function normalizeAsrContentTags(tags: unknown): AsrContentTag[] {
|
||||
const rawTags = Array.isArray(tags)
|
||||
? tags
|
||||
: typeof tags === "string"
|
||||
? tags.split(/[、,,\s]+/).filter(Boolean)
|
||||
: [];
|
||||
|
||||
const normalized = rawTags.filter(
|
||||
(tag): tag is AsrContentTag =>
|
||||
typeof tag === "string" && isAsrContentTag(tag),
|
||||
);
|
||||
|
||||
const uniqueTags = [...new Set(normalized)].slice(0, 3);
|
||||
return uniqueTags.length > 0 ? uniqueTags : ["其他"];
|
||||
}
|
||||
Reference in New Issue
Block a user