| Param() |
|
|
| $ErrorActionPreference = 'Stop' |
|
|
| $root = Split-Path $PSScriptRoot -Parent |
| $src = Join-Path $root 'data' 'toeic_vocabulary.json' |
| $dst = Join-Path $root 'data' 'toeic_vocabulary_view.json' |
|
|
| if (!(Test-Path $src)) { throw "找不到資料檔:$src" } |
|
|
| $obj = Get-Content -Path $src -Raw -Encoding UTF8 | ConvertFrom-Json |
|
|
| |
| |
| |
|
|
| $items = @() |
| if ($obj -is [System.Array]) { |
| $items = $obj |
| } else { |
| $groups = $obj.vocabulary_by_importance.PSObject.Properties |
| foreach ($prop in $groups) { |
| $importance = $prop.Name |
| foreach ($it in $prop.Value) { |
| |
| $it | Add-Member -NotePropertyName importance_group -NotePropertyValue $importance -Force |
| $items += $it |
| } |
| } |
| } |
|
|
| $out = @() |
| foreach ($r in $items) { |
| |
| $pos = $r.parts_of_speech |
| if ($null -eq $pos) { $pos = @() } |
| if ($pos -isnot [System.Array]) { $pos = @($pos) } |
| $out += [pscustomobject]@{ |
| english_word = [string]$r.english_word |
| chinese_definition = [string]$r.chinese_definition |
| star_rating = [int]$r.star_rating |
| category = [string]$r.category |
| parts_of_speech = ($pos -join '|') |
| word_forms_json = if ($r.word_forms) { ($r.word_forms | ConvertTo-Json -Depth 20 -Compress) } else { $null } |
| examples_json = if ($r.examples) { ($r.examples | ConvertTo-Json -Depth 20 -Compress) } else { $null } |
| importance_group = [string]$r.importance_group |
| } |
| } |
|
|
| $out | ConvertTo-Json -Depth 5 | Set-Content -Path $dst -Encoding UTF8 |
| Write-Host "已輸出 Viewer 友善 JSON -> $dst" -ForegroundColor Green |
|
|