-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend the
validate
command to validate JSONL datasets (#131)
Signed-off-by: Juan Cruz Viotti <[email protected]>
- Loading branch information
Showing
13 changed files
with
343 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
if(NOT JSONToolkit_FOUND) | ||
set(JSONTOOLKIT_INSTALL OFF CACHE BOOL "disable installation") | ||
set(JSONTOOLKIT_JSONL OFF CACHE BOOL "disable JSONL support") | ||
add_subdirectory("${PROJECT_SOURCE_DIR}/vendor/jsontoolkit") | ||
set(JSONToolkit_FOUND ON) | ||
endif() |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/bin/sh | ||
|
||
set -o errexit | ||
set -o nounset | ||
|
||
TMP="$(mktemp -d)" | ||
clean() { rm -rf "$TMP"; } | ||
trap clean EXIT | ||
|
||
cat << 'EOF' > "$TMP/schema.json" | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"type": "array" | ||
} | ||
EOF | ||
|
||
cat << 'EOF' > "$TMP/instance.jsonl" | ||
{ "foo": 1 } | ||
{ "foo": 2 } | ||
{ "foo": 3 } | ||
EOF | ||
|
||
"$1" validate "$TMP/schema.json" "$TMP/instance.jsonl" 2>"$TMP/stderr.txt" \ | ||
&& CODE="$?" || CODE="$?" | ||
test "$CODE" = "1" || exit 1 | ||
|
||
cat << EOF > "$TMP/expected.txt" | ||
fail: $(realpath "$TMP")/instance.jsonl (entry #0) | ||
{ | ||
"foo": 1 | ||
} | ||
error: Schema validation failure | ||
The target document is expected to be of the given type | ||
at instance location "" | ||
at evaluate path "/type" | ||
EOF | ||
|
||
diff "$TMP/stderr.txt" "$TMP/expected.txt" |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/bin/sh | ||
|
||
set -o errexit | ||
set -o nounset | ||
|
||
TMP="$(mktemp -d)" | ||
clean() { rm -rf "$TMP"; } | ||
trap clean EXIT | ||
|
||
cat << 'EOF' > "$TMP/schema.json" | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"type": "array" | ||
} | ||
EOF | ||
|
||
cat << 'EOF' > "$TMP/instance.jsonl" | ||
{ "foo": 1 } | ||
{ "foo": 2 } | ||
{ "foo": 3 } | ||
EOF | ||
|
||
"$1" validate "$TMP/schema.json" "$TMP/instance.jsonl" --verbose 2>"$TMP/stderr.txt" \ | ||
&& CODE="$?" || CODE="$?" | ||
test "$CODE" = "1" || exit 1 | ||
|
||
cat << EOF > "$TMP/expected.txt" | ||
Interpreting input as JSONL | ||
fail: $(realpath "$TMP")/instance.jsonl (entry #0) | ||
{ | ||
"foo": 1 | ||
} | ||
error: Schema validation failure | ||
The target document is expected to be of the given type | ||
at instance location "" | ||
at evaluate path "/type" | ||
EOF | ||
|
||
diff "$TMP/stderr.txt" "$TMP/expected.txt" |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/bin/sh | ||
|
||
set -o errexit | ||
set -o nounset | ||
|
||
TMP="$(mktemp -d)" | ||
clean() { rm -rf "$TMP"; } | ||
trap clean EXIT | ||
|
||
cat << 'EOF' > "$TMP/schema.json" | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"type": "object" | ||
} | ||
EOF | ||
|
||
cat << 'EOF' > "$TMP/instance.jsonl" | ||
{ "foo": "first" } | ||
{ "foo" "second" } | ||
{ "foo": "third" } | ||
EOF | ||
|
||
"$1" validate "$TMP/schema.json" "$TMP/instance.jsonl" 2>"$TMP/stderr.txt" \ | ||
&& CODE="$?" || CODE="$?" | ||
test "$CODE" = "1" || exit 1 | ||
|
||
cat << EOF > "$TMP/expected.txt" | ||
error: Failed to parse the JSON document at line 2 and column 10 | ||
$(realpath "$TMP")/instance.jsonl | ||
EOF | ||
|
||
diff "$TMP/stderr.txt" "$TMP/expected.txt" |
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/bin/sh | ||
|
||
set -o errexit | ||
set -o nounset | ||
|
||
TMP="$(mktemp -d)" | ||
clean() { rm -rf "$TMP"; } | ||
trap clean EXIT | ||
|
||
cat << 'EOF' > "$TMP/schema.json" | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"type": "object" | ||
} | ||
EOF | ||
|
||
cat << 'EOF' > "$TMP/instance.jsonl" | ||
{ "foo": 1 } | ||
[ { "foo": 2 } ] | ||
{ "foo": 3 } | ||
EOF | ||
|
||
"$1" validate "$TMP/schema.json" "$TMP/instance.jsonl" 2>"$TMP/stderr.txt" \ | ||
&& CODE="$?" || CODE="$?" | ||
test "$CODE" = "1" || exit 1 | ||
|
||
cat << EOF > "$TMP/expected.txt" | ||
fail: $(realpath "$TMP")/instance.jsonl (entry #1) | ||
[ | ||
{ | ||
"foo": 2 | ||
} | ||
] | ||
error: Schema validation failure | ||
The target document is expected to be of the given type | ||
at instance location "" | ||
at evaluate path "/type" | ||
EOF | ||
|
||
diff "$TMP/stderr.txt" "$TMP/expected.txt" |
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/bin/sh | ||
|
||
set -o errexit | ||
set -o nounset | ||
|
||
TMP="$(mktemp -d)" | ||
clean() { rm -rf "$TMP"; } | ||
trap clean EXIT | ||
|
||
cat << 'EOF' > "$TMP/schema.json" | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"type": "object" | ||
} | ||
EOF | ||
|
||
cat << 'EOF' > "$TMP/instance.jsonl" | ||
{ "foo": 1 } | ||
[ { "foo": 2 } ] | ||
{ "foo": 3 } | ||
EOF | ||
|
||
"$1" validate "$TMP/schema.json" "$TMP/instance.jsonl" --verbose 2>"$TMP/stderr.txt" \ | ||
&& CODE="$?" || CODE="$?" | ||
test "$CODE" = "1" || exit 1 | ||
|
||
cat << EOF > "$TMP/expected.txt" | ||
Interpreting input as JSONL | ||
ok: $(realpath "$TMP")/instance.jsonl (entry #0) | ||
matches $(realpath "$TMP")/schema.json | ||
fail: $(realpath "$TMP")/instance.jsonl (entry #1) | ||
[ | ||
{ | ||
"foo": 2 | ||
} | ||
] | ||
error: Schema validation failure | ||
The target document is expected to be of the given type | ||
at instance location "" | ||
at evaluate path "/type" | ||
EOF | ||
|
||
diff "$TMP/stderr.txt" "$TMP/expected.txt" |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/bin/sh | ||
|
||
set -o errexit | ||
set -o nounset | ||
|
||
TMP="$(mktemp -d)" | ||
clean() { rm -rf "$TMP"; } | ||
trap clean EXIT | ||
|
||
cat << 'EOF' > "$TMP/schema.json" | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"properties": { | ||
"foo": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
EOF | ||
|
||
cat << 'EOF' > "$TMP/instance.jsonl" | ||
{ "foo": "first" } | ||
{ "foo": "second" } | ||
{ "foo": "third" } | ||
EOF | ||
|
||
"$1" validate "$TMP/schema.json" "$TMP/instance.jsonl" 2> "$TMP/output.txt" 1>&2 | ||
|
||
cat << EOF > "$TMP/expected.txt" | ||
EOF | ||
|
||
diff "$TMP/output.txt" "$TMP/expected.txt" |
Oops, something went wrong.