| import json |
| import argparse |
|
|
| def jsonl_to_list(filename): |
| """ |
| Read a JSONL file and return it as a list. |
| """ |
| with open(filename, 'r') as f: |
| return [json.loads(line) for line in f] |
|
|
| def combine_and_write_to_single_line_jsonl(entities_file, relations_file, output_file): |
| """ |
| Combine data from two JSONL files and write to a single line in a JSONL file. |
| """ |
| entities = jsonl_to_list(entities_file) |
| relations = jsonl_to_list(relations_file) |
|
|
| combined_data = { |
| "entities": entities, |
| "relations": relations |
| } |
|
|
| with open(output_file, 'w') as f: |
| f.write(json.dumps(combined_data)) |
|
|
| def main(): |
| parser = argparse.ArgumentParser(description="Combine two JSONL files into one JSONL file with a single line.") |
| parser.add_argument("entities_file", help="Path to the entities.jsonl file.") |
| parser.add_argument("relations_file", help="Path to the relations.jsonl file.") |
| parser.add_argument("output_file", help="Path to the output JSONL file.") |
|
|
| args = parser.parse_args() |
|
|
| combine_and_write_to_single_line_jsonl(args.entities_file, args.relations_file, args.output_file) |
|
|
| if __name__ == "__main__": |
| main() |
|
|