michaelmior
commited on
Commit
·
65d80b0
verified
·
0
Parent(s):
Add data and generation script
Browse files- get_definitions.py +48 -0
- train.jsonl.gz +3 -0
- validation.jsonl.gz +3 -0
get_definitions.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import glob
|
2 |
+
import json
|
3 |
+
import os
|
4 |
+
import sys
|
5 |
+
|
6 |
+
DEFN_KEYWORDS = [
|
7 |
+
"definitions",
|
8 |
+
"$defs",
|
9 |
+
]
|
10 |
+
|
11 |
+
REMOVE_KEYS = [
|
12 |
+
"$comment",
|
13 |
+
"description",
|
14 |
+
"title",
|
15 |
+
]
|
16 |
+
|
17 |
+
dict_values = type({}.values())
|
18 |
+
|
19 |
+
|
20 |
+
def clean_object(obj):
|
21 |
+
if isinstance(obj, dict):
|
22 |
+
return {k: clean_object(v) for k, v in obj.items() if k not in REMOVE_KEYS}
|
23 |
+
elif isinstance(obj, list):
|
24 |
+
return [clean_object(v) for v in obj]
|
25 |
+
else:
|
26 |
+
return obj
|
27 |
+
|
28 |
+
def get_definitions(obj):
|
29 |
+
for key in DEFN_KEYWORDS:
|
30 |
+
for name, defn in obj.get(key, {}).items():
|
31 |
+
if '"$ref"' not in json.dumps(defn):
|
32 |
+
yield name, defn
|
33 |
+
|
34 |
+
|
35 |
+
for line in sys.stdin:
|
36 |
+
obj = json.loads(line)
|
37 |
+
schema = obj["name"]
|
38 |
+
obj = json.loads(obj["content"])
|
39 |
+
for key, defn in get_definitions(obj):
|
40 |
+
json.dump(
|
41 |
+
{
|
42 |
+
"schema": os.path.basename(schema),
|
43 |
+
"key": key,
|
44 |
+
"definition": json.dumps(defn)
|
45 |
+
},
|
46 |
+
sys.stdout,
|
47 |
+
)
|
48 |
+
sys.stdout.write("\n")
|
train.jsonl.gz
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:42a4753ca62c54e69ebccbb179ab3f7b01b0c5b1f42426783d1424b08c798350
|
3 |
+
size 558371
|
validation.jsonl.gz
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:72fc082a74ff5c2b6a5a56b1a3da65f98b5e86e7e9a121cb489537f41c8844a7
|
3 |
+
size 134710
|