-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f82f04
commit cabf93f
Showing
1 changed file
with
47 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import re | ||
|
||
def parse_atf(atf_file, output_file): | ||
with open(atf_file, 'r') as file: | ||
lines = file.readlines() | ||
|
||
parsed_lines = [] | ||
current_text = None | ||
current_surface = None | ||
current_column = None | ||
|
||
surfaces = ['obverse', 'reverse', 'left edge', 'right edge', 'bottom edge', 'edge', 'surface a'] | ||
|
||
for line in lines: | ||
if line.startswith('&'): | ||
# New text | ||
current_text = line.split('=')[0].strip('& ') | ||
current_column = None # Clear the column variable when encountering a new text | ||
elif any(line.startswith(f'@{surface}') for surface in surfaces): | ||
# Set current surface | ||
for surface in surfaces: | ||
if line.startswith(f'@{surface}'): | ||
current_surface = surface | ||
current_column = None # Clear the column variable when changing the surface | ||
break | ||
elif line.startswith('@column'): | ||
# Set current column | ||
current_column = line.split()[1] | ||
elif not line.startswith(('#', '$', '>', '@')): | ||
# Process text lines | ||
cleaned_line = re.sub(r'(\$|\@)[^\s]+', '', line).strip() | ||
if current_text is not None and current_surface is not None and cleaned_line: | ||
if current_column: | ||
parsed_line = f'{current_text} {current_surface} col. {current_column} {cleaned_line}' | ||
else: | ||
parsed_line = f'{current_text} {current_surface} {cleaned_line}' | ||
parsed_lines.append(parsed_line) | ||
|
||
with open(output_file, 'w') as file: | ||
file.write('\n'.join(parsed_lines)) | ||
|
||
# Specify the input ATF file and output file name | ||
atf_file = 'inscriptions.atf' | ||
output_file = 'output.txt' | ||
|
||
# Call the function to parse ATF and write to file | ||
parse_atf(atf_file, output_file) |