<jupyter_start><jupyter_text>This notebook downloads and processes the gender data from the Vienna catalog. The data comes from a [gendering add-in for Microsoft Word 2010](https://web.archive.org/web/20210629142645/https:/archive.codeplex.com/?p=gendering) that has been developed by Microsoft. The data includes two styles (double notation and inner I).Some more manual normalization would be necessary to make this data useful for our project. For example, the inner I and double notation forms can both be derived from just the female form (in addition to the male form, which is already given by the replaced word), and entries for the same word but with different cases could be reduced to a single entry. The data is highly relevant for this project, because it has been created in a government context as well, and includes many government-specific words.<jupyter_code>import io
import pandas as pd
import re
import requests
from typing import *
import sys

sys.path.insert(0, "..")
from helpers import add_to_dict, log
from helpers_csv import csvs_to_list, dict_to_csvs
csv = requests.get(
    "https://www.data.gv.at/katalog/dataset/15d6ede8-f128-4fcd-aa3a-4479e828f477/resource/804f6db1-add7-4480-b4d0-e52e61c48534/download/worttabelle.csv"
).content
text = re.sub(";;\r\n", "\n", csv.decode("utf-8"))
df = pd.read_csv(io.StringIO(text))
df.head()
df.to_csv(
    "vienna_catalog_raw.csv",
    index=False,
)<jupyter_output><empty_output><jupyter_text>We change Binnen-I to gender star to have one simple style, and we try to attribute singular and plural as well as possible:<jupyter_code>dic: Dict[str, Dict[str, List[str]]] = {"sg": {}, "pl": {}}
for (_, _, ungendered, gendered, binnenI) in df.to_records():
    if binnenI == "Y":
        gendered = re.sub(r"([a-zäöüß])I", r"\1*i", gendered)
    if type(gendered) == str:  # skip ill-formatted rows
        if (
            re.findall(r"[iI]n( .*)?$", gendered) != []
            or re.findall(r" bzw\.? ", gendered) != []
        ):
            add_to_dict(ungendered, [gendered], dic["sg"])
        elif (
            re.findall(r"[iI]nnen( .*)?$", gendered) != []
            or re.findall(r" und ", gendered) != []
        ):
            add_to_dict(ungendered, [gendered], dic["pl"])
        else:
            add_to_dict(ungendered, [gendered], dic["sg"])
            add_to_dict(ungendered, [gendered], dic["pl"])
dict_to_csvs(dic, "vienna_catalog")<jupyter_output><empty_output><jupyter_text>We can read this CSV back to a Python dictionary with the following method:<jupyter_code>list_ = csvs_to_list("vienna_catalog")
list_[:5]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12462006079027356, 'fraction_numerical': 0.023556231003039513, 'mean_word_length': 4.0248091603053435, 'pattern_counts': {'":': 3, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '4564', 'license': 'MIT', 'n_tokens_mistral': 928, 'n_tokens_neox': 864, 'n_words': 256, 'path': 'data/vienna_catalog/main.ipynb', 'repo_name': 'tech4germany/bam-inclusify', 'size': '2632'}