Skip to content

Commit 6e463b8

Browse files
committed
♻️ (ClassificationHelpers.ps1): refactor classification ordering logic
Refactor the classification ordering logic to consolidate the functionality of `Get-FinalSelection` into `Get-ClassificationOrderedList`. Introduce a `byLevel` switch parameter to allow optional filtering by classification level. This change simplifies the code by removing redundant functions and enhances flexibility by allowing users to specify whether to filter classifications by level. 🔧 (Update-ReourcesFrontMatter.ps1): update classification ordering call Update the call to `Get-ClassificationOrderedList` to include the `byLevel` switch. This ensures that classifications are ordered by level, aligning with the intended logic for selecting top categories and tags. This change improves the accuracy of the classification selection process in the front matter update script.
1 parent aef375f commit 6e463b8

File tree

2 files changed

+19
-25
lines changed

2 files changed

+19
-25
lines changed

.powershell/_includes/ClassificationHelpers.ps1

+17-23
Original file line numberDiff line numberDiff line change
@@ -348,34 +348,28 @@ function Get-Classification {
348348
function Get-ClassificationOrderedList {
349349
param (
350350
[array]$Classifications,
351-
[int] $minScore = 70
351+
[int] $minScore = 30,
352+
[string[]]$levels = @("Primary", "Secondary", "Tertiary", "Quaternary", "Quinary"),
353+
[switch]$byLevel
352354
)
353-
return $Classifications |
354-
Where-Object { $_.final_score -gt $minScore } |
355-
Sort-Object -Property @{Expression = "final_score"; Descending = $true }, @{Expression = "ai_alignment"; Descending = $true }, @{Expression = "ai_depth"; Descending = $true }, @{Expression = "category"; Descending = $false }
356-
}
357-
358-
function Get-FinalSelection {
359-
param (
360-
[hashtable]$categoryScores,
361-
[string[]]$levels = @("Primary", "Secondary", "Tertiary", "Quaternary", "Quinary")
362-
)
363-
364-
$finalSelection = @()
365355

366-
foreach ($level in $levels) {
367-
$currentSelection = $categoryScores.Values | Where-Object { $_.final_score -gt 30 -and $_.level -eq $level } | Sort-Object final_score -Descending
368-
if ($currentSelection.Count -gt 0) {
369-
$finalSelection += $currentSelection
370-
break
371-
}
356+
$filtered = $Classifications | Where-Object { $_.final_score -gt $minScore }
357+
$selected = @()
358+
if ($byLevel) {
359+
foreach ($level in $levels) {
360+
$currentSelection = $filtered | Where-Object { $_.level -eq $level } | Sort-Object final_score -Descending
361+
if ($currentSelection.Count -gt 0) {
362+
$selected += $currentSelection
363+
break
364+
}
365+
}
372366
}
373-
374-
return $finalSelection | Sort-Object final_score -Descending
367+
else {
368+
$selected = $filtered | Sort-Object final_score -Descending
369+
}
370+
return $selected | Sort-Object -Property @{Expression = "final_score"; Descending = $true }, @{Expression = "ai_alignment"; Descending = $true }, @{Expression = "ai_depth"; Descending = $true }, @{Expression = "category"; Descending = $false }
375371
}
376372

377-
378-
379373
function Get-ComputedConfidence {
380374
param (
381375
[int]$aiConfidence,

.powershell/single-use/resources/Update-ReourcesFrontMatter.ps1

+2-2
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,13 @@ while ($hugoMarkdownQueue.Count -gt 0 -or $hugoMarkdownBatchQueue.Count -gt 0) {
208208
# Update-StringList -frontMatter $hugoMarkdown.FrontMatter -fieldName 'marketing' -values @($categories) -Overwrite
209209
#-----------------Categories-------------------
210210
$categoryClassification = Get-ClassificationsForType -updateMissing -ClassificationType "categories" -hugoMarkdown $hugoMarkdown
211-
$categoryClassificationOrdered = Get-ClassificationOrderedList -classifications $categoryClassification | Select-Object -First 3
211+
$categoryClassificationOrdered = Get-ClassificationOrderedList -byLevel -classifications $categoryClassification | Select-Object -First 3
212212
$categories = $categoryClassificationOrdered | ForEach-Object { $_.category }
213213

214214
Update-StringList -frontMatter $hugoMarkdown.FrontMatter -fieldName 'categories' -values @($categories) -Overwrite
215215
#-----------------Tags-------------------
216216
$tagClassification = Get-ClassificationsForType -updateMissing -ClassificationType "tags" -hugoMarkdown $hugoMarkdown
217-
$tagClassificationOrdered = Get-ClassificationOrderedList -classifications $tagClassification | Select-Object -First 10
217+
$tagClassificationOrdered = Get-ClassificationOrderedList -byLevel -classifications $tagClassification | Select-Object -First 10
218218
$tags = $tagClassificationOrdered | ForEach-Object { $_.category }
219219
Update-StringList -frontMatter $hugoMarkdown.FrontMatter -fieldName 'tags' -values @($tags) -Overwrite
220220
# =================COMPLETE===================

0 commit comments

Comments
 (0)