-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pass absolute paths to corpus. The corpus needs to be single files with one sample each. Add a Python script that converts files with multiple samples into single files.
- Loading branch information
Showing
3 changed files
with
64 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/env python | ||
|
||
import os | ||
import sys | ||
|
||
|
||
def get_samples(input_files): | ||
for file_name in input_files: | ||
if not os.path.isfile(file_name): | ||
raise RuntimeError("Not a file: " + file_name) | ||
with open(file_name, 'r') as input_file: | ||
yield from input_file | ||
|
||
|
||
def process_files(output_folder, input_files): | ||
if not os.path.exists(output_folder): | ||
os.makedirs(output_folder) | ||
|
||
for i, sample in enumerate(get_samples(input_files)): | ||
with open(os.path.join(output_folder, str(i) + ".txt"), 'w') as output_file: | ||
output_file.write(sample) | ||
|
||
|
||
if __name__ == "__main__": | ||
if len(sys.argv) < 3: | ||
print("Usage: python script.py <output_folder> <input_file1> [<input_file2> ...]") | ||
sys.exit(1) | ||
|
||
process_files(output_folder=sys.argv[1], input_files=sys.argv[2:]) |
File renamed without changes.