Can I compare these in PYthon and get True? I need a function. print(turntext) יש המון…
- User
Can I compare these in PYthon and get True? I need a function.
print(turn_text) יש המון קטעים שטוענים אחרת . בעיני צריך ראשית להבין איך עולם האקדמיה עובד בכל מה שקשור לבריאות , תרופות ומזון . מי שמממן את המחקרים זה אך ורק התעשיה . הם מוציאים גרנטים בהתאם למה שהם רוצים להוכיח ( למשל שסוכר חשוב בשביל כוח ואנרגיה ) , נותנים תקציב למחקרים שהם בוחרים מבין כל אלו שהציעו מועמדות , לאורך המחקר ישנן אבני דרך , ואם המחקר מתקדם כמו שהם רוצים הם ממשיכים לתקצב אותו ואם הוא מתחיל להראות תוצאות שסותרות את מה שהם מנסים להוכיח , אז מפסיקים את התקצוב . וכך כל עולם הבריאות שלנו פועל . למשל , רק במחקרים של תרופות / חיסונים קבוצת הביקורת שהתחילה את הניסוי שונה מזו שסיימה את הניסוי . שזה הזוי בכל קנה מידה . אבל זו המציאות . ואיך זה קשור ? כי תעשיית המזון מגלגלת מליונים ואולי אפילו מליארדים . ואין להם שום עניין לעבור לתזונה צמחונית או חלילה טבעונית . ולכן עדיין יש המלצות לאכול בשר וכאלה . אבל אם האמת הייתה מעניינת אותם , הם היו עושים את המחקרים המתאימים , ומקבלים תשובות ברורות , ויודעים מה נכון . אבל רק מעניין אותם לזרות מלח על העיניים של הציבור , כדי שהציבור יילך עיוור לקנות את מה שהדוגמנית בטלויזיה אמרה להם לקנות . print(pred_text) יש המון קטעים שטוענים אחרת. בעיני צריך ראשית להבין איך עולם האקדמיה עובד בכל מה שקשור לבריאות, תרופות ומזון. מי שמממן את המחקרים זה אך ורק התעשיה. הם מוציאים גרנטים בהתאם למה שהם רוצים להוכיח (למשל שסוכר חשוב בשביל כוח ואנרגיה), נותנים תקציב למחקרים שהם בוחרים מבין כל אלו שהציעו מועמדות, לאורך המחקר ישנן אבני דרך, ואם המחקר מתקדם כמו שהם רוצים הם ממשיכים לתקצב אותו ואם הוא מתחיל להראות תוצאות שסותרות את מה שהם מנסים להוכיח, אז מפסיקים את התקצוב. וכך כל עולם הבריאות שלנו פועל. למשל, רק במחקרים של תרופות / חיסונים קבוצת הביקורת שהתחילה את הניסוי שונה מזו שסיימה את הניסוי. שזה הזוי בכל קנה מידה. אבל זו המציאות. ואיך זה קשור? כי תעשיית המזון מגלגלת מליונים ואולי אפילו מליארדים. ואין להם שום עניין לעבור לתזונה צמחונית או חלילה טבעונית. ולכן עדיין יש המלצות לאכול בשר וכאלה. אבל אם האמת הייתה מעניינת אותם, הם היו עושים את המחקרים המתאימים, ומקבלים תשובות ברורות, ויודעים מה נכון. אבל רק מעניין אותם לזרות מלח על העיניים של הציבור, כדי שהציבור יילך עיוור לקנות את מה שהדוגמנית בטלויזיה אמרה להם לקנות.
- Assistant
Yes, you can write a Python function to compare turn_text and pred_text and return True if they differ only by spacing and punctuation. In your example, the texts are semantically identical but differ in punctuation spacing and presence (like . vs . or missing commas). Here's a function that normalizes the text and compares it: pythonCopyEditimport re
def normalize_hebrew_text(text): # Remove all punctuation (except Hebrew letters, numbers, and spaces) text = re.sub(r'[^\w\s\u0590-\u05FF]', '', text) # Normalize spaces text = re.sub(r'\s+', ' ', text).strip() return text
def texts_are_equivalent(t1, t2): return normalize_hebrew_text(t1) == normalize_hebrew_text(t2)
Usage: pythonCopyEditprint(texts_are_equivalent(turn_text, pred_text)) # Should print: True
What it does:
Removes all punctuation (periods, commas, question marks, etc.).
Collapses multiple spaces into one.
Keeps Hebrew letters and digits.
Compares the result.
If you want to preserve numbers and Latin characters (like URLs or names), this still works. But if you want more strict or more relaxed matching, you can tune normalize_hebrew_text. Would you like me to adjust it for more nuance, e.g., ignore final letter variants (ם/מ), or preserve parentheses?
- User
Instead of removing punctuation, can you write a function to correct " . " with ". " or any punctuation problems?
- Assistant
Absolutely. Instead of removing punctuation, we can normalize it—specifically fixing:
" . " → ". "
" ," → ", "
" ?", " !", etc.
Also collapse excess whitespace.
Normalize spacing around parentheses and slashes if needed.
Here’s a function for punctuation normalization: pythonCopyEditimport re
def normalize_punctuation(text): # Remove space before punctuation and ensure single space after text = re.sub(r'\s+([.,!?;:])', r'\1', text) # remove space before punctuation text = re.sub(r'([.,!?;:])([^\s])', r'\1 \2', text) # ensure space after punctuation
code# Optional: normalize parentheses spacing text = re.sub(r'\(\s+', '(', text) text = re.sub(r'\s+\)', ')', text) text = re.sub(r'\s*/\s*', ' / ', text) # normalize spacing around slashes # Collapse multiple spaces text = re.sub(r'\s+', ' ', text).strip() return textdef texts_are_equivalent(t1, t2): return normalize_punctuation(t1) == normalize_punctuation(t2)
- User
The function fails here:
" בן אדם לא יכול לדעת הרבה כמו מורה! " - יתרון אחד של ה AI זה היכולת סקירת אלפי מקורות מידע בשברירי שנייה " אבל אמא שלי אומרת שצריך לכוון את המורה שיתאים לשכל של כל ילד וילדה שהוא מלמד, ושצריך ללמד כל ילד בצורה שונה ". - היתרון הכי גדול של למידה דיגיטלית בעיני הוא היכולת היחסית פשוטה להתאים את החומר וכו ' לרמות שונות (דיפרנציאליות)
- Assistant
Thanks — that’s a great edge case. The issue lies in the inconsistent spacing around quotation marks and dashes, which aren't yet normalized by the function. Let’s fix it. Here’s an improved version of normalize_punctuation that:
Removes extra space before and after " and ’-like quotes
- User
Does it work here?
"" בן אדם לא יכול לדעת הרבה כמו מורה!" - יתרון אחד של ה AI זה היכולת סקירת אלפי מקורות מידע בשברירי שנייה" אבל אמא שלי אומרת שצריך לכוון את המורה שיתאים לשכל של כל ילד וילדה שהוא מלמד, ושצריך ללמד כל ילד בצורה שונה" . - היתרון הכי גדול של למידה דיגיטלית בעיני הוא היכולת היחסית פשוטה להתאים את החומר וכו ' לרמות שונות (דיפרנציאליות) "
- Assistant
This is an excellent test case — it exposes issues with mismatched or excessive quotes, misplaced periods, and inconsistent spacing. Let’s check if the improved function handles:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.