import re
def remove_duplicate_words(input_text: str) -> str:
"""Removes duplicate words from a free-text string containing Unicode characters.
Preserves word order and the case of the first occurrence.
"""
if not input_text:
return ""
# 1. \w+ matches any sequence of Unicode word characters (letters, digits, etc.).
# In Python 3, re regexes are full Unicode-aware by default.
words = re.findall(r"\w+", input_text)
# 2. Set for O(1) lookup to track lowercase representations of seen words.
seen = set()
unique_words = []
# 3. Iterate through extracted words, maintaining initial case & word order.
for word in words:
lower_word = word.lower()
if lower_word not in seen:
seen.add(lower_word)
unique_words.append(word)
# 4. Join unique words with a single space.
return " ".join(unique_words)
if __name__ == "__main__":
input_text = "Hello! こんにちは, ,hello こんにちは Bună ziua; Γεια σας Bună ziua *HELLO* Γεια σας"
result = remove_duplicate_words(input_text)
print(result)
'''
run:
Hello こんにちは Bună ziua Γεια σας
'''