Problem
Sprachmodelle arbeiten mit Tokens, nicht mit Rohtext. Ein einfacher Tokenizer schreibt den Text klein und behandelt jede Folge von Buchstaben a-z und Ziffern 0-9 als Wort; alles andere (Leerzeichen, Satzzeichen, andere Zeichen) trennt Wörter.
Baue das Vokabular: die verschiedenen Wörter, sortiert nach Häufigkeit (häufigste zuerst), bei Gleichstand alphabetisch. Die Position eines Worts in dieser Liste ist seine Token-ID.
Implementiere build_vocabulary(text).
Eingabe
text: Ein beliebiger Text.
Ausgabe
Gib das Vokabular als Liste von Wörtern zurück. Enthält der Text keine Wörter, gib eine leere Liste zurück.
Einschränkungen
0 ≤ Länge von text ≤ 100.000
Beispiele
Eingabe:
text = "The cat sat on the mat. The end!"
Erwartete Ausgabe:
expected = ["the", "cat", "end", "mat", "on", "sat"]
Eingabe:
std::string text = "The cat sat on the mat. The end!";
Erwartete Ausgabe:
std::vector<std::string> expected = {"the", "cat", "end", "mat", "on", "sat"};
Eingabe:
string text = "The cat sat on the mat. The end!";
Erwartete Ausgabe:
string[] expected = new string[] {"the", "cat", "end", "mat", "on", "sat"};
Erläuterung
Kleingeschrieben sind die Wörter the, cat, sat, on, the, mat, the, end. "the" kommt 3-mal vor; die anderen je einmal und werden alphabetisch sortiert: ["the", "cat", "end", "mat", "on", "sat"].
Eingabe:
text = "AI, ai and A.I. (2024)"
Erwartete Ausgabe:
expected = ["ai", "2024", "a", "and", "i"]
Eingabe:
std::string text = "AI, ai and A.I. (2024)";
Erwartete Ausgabe:
std::vector<std::string> expected = {"ai", "2024", "a", "and", "i"};
Eingabe:
string text = "AI, ai and A.I. (2024)";
Erwartete Ausgabe:
string[] expected = new string[] {"ai", "2024", "a", "and", "i"};
Erläuterung
Wörter: ai, ai, and, a, i, 2024. "ai" kommt zweimal vor; die anderen je einmal, alphabetisch sortiert mit Ziffern vor Buchstaben: ["ai", "2024", "a", "and", "i"].
Referenzen
Diese Aufgabe wurde für CodeUtility angepasst. Beachte die oben genannten Vorgaben und Einschränkungen.