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", "authoritative.csv")

AUTHORITATIVE_MARKERS = [
    "i decide", "you must", "this will be done",
    "required", "mandatory", "final decision",
    "authority", "directive"
]

COLLABORATIVE_MARKERS = [
    "we should", "let us", "let's",
    "together", "team", "collaborate",
    "discuss", "align", "consensus"
]


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 COLLABORATIVE_MARKERS:
        if m in t:
            return 0

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

    # default to collaborative (safer)
    return 0


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"Authoritative dataset written to {OUT_PATH}")


if __name__ == "__main__":
    main()
