File size: 1,472 Bytes
c3e7fcf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
param(
    [string]$Root = (Split-Path -Parent $PSScriptRoot)
)

$ErrorActionPreference = "Stop"

$sourceDir = Join-Path $Root "data\datasets\v1.2"
$outputDir = Join-Path $Root "data\jsonl\v1.2"

New-Item -ItemType Directory -Force -Path $outputDir | Out-Null

$jsonFiles = Get-ChildItem "$sourceDir\*.json" | Sort-Object Name

$totalRecords = 0
$fileCount = 0

foreach ($file in $jsonFiles) {

    $data = Get-Content $file.FullName -Raw | ConvertFrom-Json

    if ($data -is [System.Array]) {
        $records = @($data)
    }
    elseif ($null -ne $data.records) {
        $records = @($data.records)
    }
    else {
        throw "No record array found in $($file.Name)"
    }

    $outputName = [System.IO.Path]::GetFileNameWithoutExtension($file.Name) + ".jsonl"
    $outputPath = Join-Path $outputDir $outputName

    $lines = foreach ($record in $records) {
        $record | ConvertTo-Json -Depth 100 -Compress
    }

    $text = if ($lines.Count -gt 0) {
        ($lines -join "`n") + "`n"
    }
    else {
        ""
    }

    [System.IO.File]::WriteAllText(
        $outputPath,
        $text,
        [System.Text.UTF8Encoding]::new($false)
    )

    $fileCount++
    $totalRecords += $records.Count

    Write-Host "$outputName -> $($records.Count) records"
}

Write-Host ""
Write-Host "JSONL GENERATION PASSED"
Write-Host "-----------------------"
Write-Host "Files:" $fileCount
Write-Host "Total records:" $totalRecords
Write-Host "Output:" $outputDir