-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
gferraro
committed
Dec 10, 2024
1 parent
53c9c75
commit 43c3bb8
Showing
5 changed files
with
80 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,33 @@ | ||
import Classifications from "@/classifications/classification.json" assert { type: "json" }; | ||
const flattenNodes = (acc, node, parentPath) => { | ||
for (const child of node.children || []) { | ||
acc[child.label] = { | ||
label: child.label, | ||
display: child.display || child.label, | ||
path: `${parentPath}.${child.label}`, | ||
}; | ||
flattenNodes(acc, child, acc[child.label].path); | ||
} | ||
return acc; | ||
for (const child of node.children || []) { | ||
acc[child.label] = { | ||
label: child.label, | ||
display: child.display || child.label, | ||
path: `${parentPath}.${child.label}`, | ||
}; | ||
flattenNodes(acc, child, acc[child.label].path); | ||
} | ||
return acc; | ||
}; | ||
export const flatClassifications = (() => { | ||
const nodes = flattenNodes({}, Classifications, "all"); | ||
if (nodes.unknown) { | ||
nodes["unidentified"] = nodes["unknown"]; | ||
} | ||
return nodes; | ||
const nodes = flattenNodes({}, Classifications, "all"); | ||
if (nodes.unknown) { | ||
nodes["unidentified"] = nodes["unknown"]; | ||
} | ||
return nodes; | ||
})(); | ||
export const displayLabelForClassificationLabel = ( | ||
label, | ||
aiTag = false, | ||
isAudioContext = false | ||
) => { | ||
label = label.toLowerCase(); | ||
if (label === "unclassified") { | ||
return "AI Queued"; | ||
} | ||
if (label === "unidentified" && aiTag) { | ||
return "Unidentified"; | ||
} | ||
const classifications = flatClassifications; | ||
if ((label === "human" || label === "person") && !isAudioContext) { | ||
return "human"; | ||
} | ||
return (classifications[label] && classifications[label].display) || label; | ||
export const displayLabelForClassificationLabel = (label, aiTag = false, isAudioContext = false) => { | ||
label = label.toLowerCase(); | ||
if (label === "unclassified") { | ||
return "AI Queued"; | ||
} | ||
if (label === "unidentified" && aiTag) { | ||
return "Unidentified"; | ||
} | ||
const classifications = flatClassifications; | ||
if ((label === "human" || label === "person") && !isAudioContext) { | ||
return "human"; | ||
} | ||
return (classifications[label] && classifications[label].display) || label; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters