-
Notifications
You must be signed in to change notification settings - Fork 1
/
AutorunFolder.py
48 lines (35 loc) · 1.49 KB
/
AutorunFolder.py
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
from rhyme import Poem_func
import os
from keras.models import load_model
from network import Corpus, Network
from changeToABC import seqIdent
import json
if __name__ == '__main__':
language = 'english'
input_folder = 'testfolder/'
output_folder = 'result/'
output_file = 'seqdata.txt'
if not os.path.exists(output_folder):
os.makedirs(output_folder)
if not os.path.exists(input_folder):
os.makedirs(input_folder)
for filename in os.listdir(input_folder):
if filename.endswith('.txt'):
name=os.path.splitext(filename)[0]
poem = Poem_func(language, input_folder+filename, output_folder)
patterns = seqIdent(poem)
if os.path.exists(output_file):
with open(output_file, 'r') as file:
try:
existing_data = json.load(file)
except json.JSONDecodeError:
existing_data = {}
else:
existing_data = {}
if name in existing_data:
existing_data[name].extend(patterns)
else:
existing_data[name] = patterns
with open(output_file, 'w') as file:
file.write(json.dumps(existing_data, indent=4))
print(f"Results have been saved to {output_file}")