Download benchmarks/python/text_utils.py from SevdanurGenc/LLM-Automated-Test-Generation-Agent: direct link, hf CLI and curl.
- Browser
- Download file 1.72 kB
-
https://huggingface.co/SevdanurGenc/LLM-Automated-Test-Generation-Agent/resolve/main/benchmarks/python/text_utils.py
- Command line
-
hf download hf://SevdanurGenc/LLM-Automated-Test-Generation-Agent/benchmarks/python/text_utils.py
-
curl -L -o text_utils.py https://huggingface.co/SevdanurGenc/LLM-Automated-Test-Generation-Agent/resolve/main/benchmarks/python/text_utils.py
1.72 kB
| """Metin yardımcıları.""" | |
| import re | |
| from collections import Counter | |
| TR_LOWER = str.maketrans("İIÇĞÖŞÜ", "iıçğöşü") | |
| def tr_lower(text: str) -> str: | |
| """Türkçe kurallarına uygun küçük harfe çevirme (İ→i, I→ı).""" | |
| return text.translate(TR_LOWER).lower() | |
| def is_palindrome(text: str) -> bool: | |
| """Harf ve rakamlar dışındaki karakterleri ve büyük/küçük harf farkını yok sayar.""" | |
| cleaned = [c for c in tr_lower(text) if c.isalnum()] | |
| return len(cleaned) > 0 and cleaned == cleaned[::-1] | |
| def word_frequencies(text: str, top: int = 3) -> list[tuple[str, int]]: | |
| """En sık geçen `top` kelimeyi (eşitlikte alfabetik) döndürür.""" | |
| if top < 1: | |
| raise ValueError("top en az 1 olmalı") | |
| words = re.findall(r"\w+", tr_lower(text)) | |
| counts = Counter(words) | |
| return sorted(counts.items(), key=lambda kv: (-kv[1], kv[0]))[:top] | |
| def caesar(text: str, shift: int) -> str: | |
| """Yalnızca ASCII harfleri kaydırır, diğer karakterleri korur.""" | |
| out = [] | |
| for ch in text: | |
| if "a" <= ch <= "z": | |
| out.append(chr((ord(ch) - 97 + shift) % 26 + 97)) | |
| elif "A" <= ch <= "Z": | |
| out.append(chr((ord(ch) - 65 + shift) % 26 + 65)) | |
| else: | |
| out.append(ch) | |
| return "".join(out) | |
| def truncate(text: str, limit: int, suffix: str = "...") -> str: | |
| """Metni `limit` karakteri aşmayacak şekilde, kelime sınırında kısaltır.""" | |
| if limit <= len(suffix): | |
| raise ValueError("limit sonekten uzun olmalı") | |
| if len(text) <= limit: | |
| return text | |
| cut = text[: limit - len(suffix)] | |
| if " " in cut: | |
| cut = cut[: cut.rfind(" ")] | |
| return cut.rstrip() + suffix | |