# POS (Export)

**POS-Daten exportieren**

1. Export der Daten (CSV & xlsx)

```{code-block} python
:emphasize-lines: 2
:lineno-start: 1

# Export der Zusammenfassung als Tabelle (CSV)
df.to_csv("results/latin_pos_summary.csv", index=False)

# Export der Zusammenfassung als Tabelle (Excel, xlsx) (benötigt openpyxl)
# !pip install openpyxl  # Run this if you get an error
df.to_excel("results/latin_pos_summary.xlsx", index=False)

print("Summary tables exported as 'latin_pos_summary.csv' and '.xlsx'")
```

````{admonition} Tip!
:class: tip
Alle Daten sollten aus Gründen der Übersichtlichkeit in einem separaten Ordner 'results' gespeichert werden.
````

2. Export der POS-Daten Wort für Wort

```{code-block} python
:emphasize-lines: 2,4
:lineno-start: 1

# Anlegen einer detaillierten Liste für jedes Wort + Tag (ohne Satzzeichen & White Space)
detailed_data = []
for token in doc:
    if not token.is_punct and not token.is_space:
        detailed_data.append({
            "Word": token.text,
            "Lemma": token.lemma_, 
            "POS": token.pos_,
            "Morphology": token.morph # Kasus, Numerus, Genus etc.
        })

# DataFrame (Tabelle) konvertieren und exportieren
detailed_df = pd.DataFrame(detailed_data)
detailed_df.to_csv("results/latin_text_annotated.csv", index=False)

print("Detailierte Annotation exportiert als 'latin_text_annotated.csv'")
```


3. Export der Visualisierungen

```{code-block} python
:emphasize-lines: 4,7

# Re-run des Balkendiagramms und Abspeichern
plt.figure(figsize=(10, 6))
sns.barplot(data=df, x="Count", y="Description", palette="viridis", hue="Description", legend=False)
plt.title("Häufigkeit der einzelnen POS")

# Als PNG speichern
plt.savefig("results/pos_bar_chart.png", dpi=300, bbox_inches='tight')
#plt.show()

# Re-run des Donut-Diagramms und Abspeichern
plt.figure(figsize=(8, 8))
plt.pie(df["Count"], labels=df["Description"], autopct='%1.1f%%', startangle=140)
centre_circle = plt.Circle((0,0), 0.70, fc='white')
fig = plt.gcf()
fig.gca().add_artist(centre_circle)
plt.title("POS Verteilung")

# Als PDF speichern (VeKtorformat, am besten für Vergrößern)
plt.savefig("results/pos_donut_chart.pdf", bbox_inches='tight')
#plt.show()

print("Diagramme exportiert als 'pos_bar_chart.png' und 'pos_donut_chart.pdf'")
```
