Updated code
This commit is contained in:
parent
716dc46804
commit
5d7991c2d3
|
@ -1,30 +1,49 @@
|
||||||
import json
|
import json
|
||||||
|
|
||||||
input_file_path = '' #path
|
input_file_path = "D:/Hamtaaproject/json/qanon.json" # path
|
||||||
with open(input_file_path, 'r', encoding='utf-8') as file:
|
with open(input_file_path, 'r', encoding='utf-8') as file:
|
||||||
data = json.load(file)
|
data = json.load(file)
|
||||||
|
|
||||||
|
id_content = {}
|
||||||
|
parent_map = {}
|
||||||
for item in data:
|
for item in data:
|
||||||
if isinstance(item, dict):
|
if isinstance(item, dict):
|
||||||
name = item.get("qanon_title", "")
|
item_id = item.get("id")
|
||||||
item.update({
|
id_content[item_id] = item.get("content")
|
||||||
"context": {
|
parent_map[item_id] = item.get("parent_id")
|
||||||
"qanon_name": name,
|
|
||||||
"parents_content": "parent_content_value",
|
for item in data:
|
||||||
"meaning_change": [{
|
if isinstance(item, dict):
|
||||||
"term": "str1",
|
name = item.get("qanon_title")
|
||||||
"meaning" : "def"
|
current_id = item.get("parent_id")
|
||||||
}],
|
parents_content = []
|
||||||
"referential term" : [{
|
|
||||||
"term": "this",
|
while current_id != "0":
|
||||||
"referent" : "that"
|
parent_content = id_content.get(current_id)
|
||||||
}]
|
parents_content.append(parent_content)
|
||||||
}
|
current_id = parent_map.get(current_id, "0")
|
||||||
})
|
|
||||||
|
item.update({
|
||||||
|
"context": {
|
||||||
|
"qanon_name": name,
|
||||||
|
"parents_content": parents_content,
|
||||||
|
"meaning_change": [{
|
||||||
|
"term": "str1",
|
||||||
|
"meaning": "def",
|
||||||
|
"Confidence_level": "0"
|
||||||
|
}],
|
||||||
|
"referential term": [{
|
||||||
|
"term": "this",
|
||||||
|
"referent": "that"
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
print("done")
|
print("done")
|
||||||
|
|
||||||
output_file_path = 'output_data.json'
|
output_file_path = 'output_data.json'
|
||||||
with open(output_file_path, 'w', encoding='utf-8') as file:
|
with open(output_file_path, 'w', encoding='utf-8') as file:
|
||||||
json.dump(data, file, indent=4, ensure_ascii=False)
|
json.dump(data, file, indent=4, ensure_ascii=False)
|
||||||
print(f"Modified data has been saved to {output_file_path}")
|
print(f"Modified data has been saved to {output_file_path}")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user