File size: 1,622 Bytes
27101d4
 
ebc2d42
 
27101d4
ebc2d42
d9c6f6b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
license: cc0-1.0
language:
- ja
---

OSCOR-2301-jaのcontent部分だけをテキスト化したもの

データセットからcontentのvalueだけ取得する際には、以下のコードで実行しました

```python
import json
import os
import sys

# コマンドライン引数からフォルダ名を取得する
if len(sys.argv) < 2:
    print("使用法: python script.py folder_name")
    sys.exit(1)

folder_name = sys.argv[1]

# フォルダ内のすべての .json ファイルを処理する
for filename in os.listdir(folder_name):
    if filename.endswith(".txt"):
        input_file = os.path.join(folder_name, filename)
        output_file = os.path.splitext(filename)[0] + "_convert.txt"
        output_path = os.path.join(folder_name, output_file)

        # 出力テキストファイルを開く
        with open(output_path, "w", encoding="utf-8") as outfile:
            # 入力JSONファイルを1行ずつ読み込む
            with open(input_file, "r", encoding="utf-8") as infile:
                for line in infile:
                    # JSONを解析する
                    data = json.loads(line)

                    # "content" フィールドが存在する場合のみ処理する
                    if "content" in data:
                        content = data["content"]

                        # "content" の内容をテキストファイルに書き込む
                        outfile.write(content + "\n")

        print(f"変換が完了しました。出力ファイル: {output_file}")

print("すべてのファイルの変換が完了しました。")
```