Download process_proverbs.py from EzioDevio/iraqi_dialect_llm: direct link, hf CLI and curl.
- Browser
- Download file 1.83 kB
-
https://huggingface.co/EzioDevio/iraqi_dialect_llm/resolve/main/process_proverbs.py
- Command line
-
hf download hf://EzioDevio/iraqi_dialect_llm/process_proverbs.py
-
curl -L -o process_proverbs.py https://huggingface.co/EzioDevio/iraqi_dialect_llm/resolve/main/process_proverbs.py
1.83 kB
| import re | |
| def process_proverbs(input_path, output_path): | |
| try: | |
| # Attempt to open the input file and read lines | |
| with open(input_path, 'r', encoding='utf-8') as file: | |
| lines = file.readlines() | |
| print("Successfully read the input file.") | |
| except FileNotFoundError: | |
| print(f"File not found: {input_path}") | |
| return | |
| proverbs = [] | |
| current_proverb = "" | |
| for line in lines: | |
| # Clean the line by stripping leading/trailing whitespace | |
| line = line.strip() | |
| print(f"Processing line: {line}") # Debug output for each line | |
| # Identify proverbs or meanings based on specific patterns, e.g., numbers at the start | |
| if re.match(r'^\d+', line): # This line has a number, possibly a new entry | |
| if current_proverb: | |
| # Save the accumulated proverb/meaning pair | |
| proverbs.append(current_proverb.strip()) | |
| current_proverb = line | |
| else: | |
| # Continue accumulating lines for the current entry | |
| current_proverb += " " + line | |
| # Save any remaining proverb | |
| if current_proverb: | |
| proverbs.append(current_proverb.strip()) | |
| # Write formatted proverbs to the output file | |
| try: | |
| with open(output_path, 'w', encoding='utf-8') as f: | |
| for entry in proverbs: | |
| f.write(entry + '\n') | |
| print(f"Writing line to file: {entry}") # Debug print for each line written | |
| print(f"Data successfully saved to {output_path}") | |
| except Exception as e: | |
| print(f"Error writing to file: {e}") | |
| # Example usage | |
| input_path = "iraqi_proverbs.txt" # Replace with the path to your text file | |
| output_path = "data/raw_data/iraqi_data.txt" # Adjust this path if necessary | |
| process_proverbs(input_path, output_path) | |