MCPcopy Create free account
hub / github.com/MiniMax-AI/OpenRoom / matchScriptToApp

Function matchScriptToApp

apps/webuiapps/src/lib/cardExtractor.ts:567–588  ·  view source on GitHub ↗
(
  regexTags: string[],
  tagAppMap: Record<string, string[]>,
)

Source from the content-addressed store, hash-verified

565}
566
567function matchScriptToApp(
568 regexTags: string[],
569 tagAppMap: Record<string, string[]>,
570): string | string[] | null {
571 const scores: Record<string, number> = {};
572
573 for (const tag of regexTags) {
574 const appIds = tagAppMap[tag];
575 if (!appIds) continue;
576 for (const appId of appIds) {
577 scores[appId] = (scores[appId] || 0) + 1;
578 }
579 }
580
581 const entries = Object.entries(scores);
582 if (entries.length === 0) return null;
583
584 entries.sort((a, b) => b[1] - a[1]);
585 const topScore = entries[0][1];
586 const topApps = entries.filter(([, s]) => s === topScore).map(([id]) => id);
587 return topApps.length === 1 ? topApps[0] : topApps;
588}
589
590function classifyScript(script: InternalScript, regexTags: string[]): string {
591 const replaceStr = script.replaceString || '';

Callers 1

normalizeScriptsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected