import csv
import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
RAW_PATH = os.path.join(BASE_DIR, "raw.txt")
OUT_PATH = os.path.join(BASE_DIR, "data", "formal.csv")

FORMAL_MARKERS = [
    "please", "kindly", "therefore", "however",
    "furthermore", "regarding", "respectfully",
    "cannot", "do not", "does not"
]

INFORMAL_MARKERS = [
    "hey", "hi", "yeah", "ok", "okay",
    "gonna", "wanna", "dont", "can't",
    "cool", "lol"
]


def load_raw_text(path):
    with open(path, "r", encoding="utf-8") as f:
        return [line.strip() for line in f if line.strip()]


def label_text(text):
    t = text.lower()

    for m in INFORMAL_MARKERS:
        if m in t:
            return 0

    for m in FORMAL_MARKERS:
        if m in t:
            return 1

    # default to formal (safer)
    return 1


def main():
    texts = load_raw_text(RAW_PATH)

    with open(OUT_PATH, "w", newline="", encoding="utf-8") as f:
        writer = csv.writer(f)
        writer.writerow(["text", "label"])

        for text in texts:
            writer.writerow([text, label_text(text)])

    print(f"Formal dataset written to {OUT_PATH}")


if __name__ == "__main__":
    main()
