Neculai Fântânaru

Everything Depends On The Leader

Test To Analyze The Person In Psychology

On August 24, 2023
, in
Python Scripts Examples by Neculai Fantanaru

You can view the full code here: https://pastebin.com/kiEfMCt5

diacritice

import tkinter as tk
from textblob import TextBlob
from googletrans import Translator
import re
from unidecode import unidecode


# Funcție pentru analiza sentimentului și subiectivității
def analyze_sentiment(text):
    translator = Translator()
    translated_text = translator.translate(text, src='ro', dest='en').text
    blob = TextBlob(translated_text)
    sentiment = blob.sentiment.polarity
    subjectivity = blob.sentiment.subjectivity
    return sentiment, subjectivity

# Dicționar cu cuvinte pozitive și negative
positive_words = [
    "da", "iubesc", "admir", "bunătate", "de acord", "fericit", "încrezător", "optimist", "satisfăcut",
    "energic", "vital", "plin de viață", "entuziasmat", "mulțumit", "recunoscător", "liniștit", "relaxat",
    "calm", "echilibrat", "armonios", "inspirat", "motivat", "curajos", "puternic", "rezistent", "înțelegător",
    "empatic", "generos", "amabil", "prietenos", "sincronizat", "conectat", "unit", "împăcat", "acceptant",
    "tolerant", "deschis", "onest", "autentic", "real", "veridic", "sincer", "franc", "direct", "clar",
    "luminos", "stralucitor", "radiant", "sclipitor", "măreț", "splendid", "magnific", "glorios", "sublim",
    "nobil", "onorabil", "demn", "respectuos", "politos", "curtenitor", "elegant", "rafinat", "distins",
    "înalt", "superior", "excelent", "perfect", "impecabil", "ireproșabil", "fără greșeală", "corect",
    "drept", "just", "echitabil", "imparțial", "necondiționat", "absolut", "complet", "integral", "total",
    "universal", "global", "general", "cuprinzător", "inclusiv", "extensiv", "larg", "vast", "imens",
    "profund", "intens", "puternic", "putere", "energie", "vigoare", "forță", "rezistență", "stabilitate",
    "splendidă", "liber", "calm"
]

negative_words = [
    "nu", "nu sunt", "neplăcere", "disconfort", "nasol", "urăsc", "nu vreau", "obosit", "stresat",
    "frustrat", "dezamăgit", "furios", "trist", "bolnav", "plictisit", "nervos", "gelos", "invidios",
    "dezgustat", "rușinat", "vinovat", "nefericit", "nemulțumit", "neîncrezător", "pesimist", "copleșit",
    "panicat", "îngrijorat", "speriat", "timorat", "neajutorat", "slăbit", "defetist", "dezorientat",
    "confuz", "neputincios", "iritat", "agitat", "furie", "ura", "invidie", "gelozie", "dispreț",
    "mânie", "răzbunare", "frică", "teamă", "anxietate", "depresie", "tristețe", "melancolie", "apatie",
    "plictiseală", "dezinteres", "nepăsare", "indiferență", "neîncredere", "suspiciune", "îndoială",
    "necredință", "neînțelegere", "conflict", "tensiune", "presiune", "stres", "nervozitate", "iritare",
    "agresivitate", "violenta", "ostilitate", "răutate", "cruel", "malițios", "vătămător", "distructiv",
    "nociv", "periculos", "amenințător", "sinistru", "fatal", "letal", "mortal", "dăunător", "murdar", "nesatisfacut",
    "dificil", "confuz", "neliniștit", "bou", "vaca"
]


# Funcție pentru a prelua textul și a efectua analiza
def analyze():

    # Afișează mesajul de încărcare
    loading_label = tk.Label(root, text="Analiza în curs... Vă rugăm așteptați.")
    loading_label.pack(padx=10, pady=10)
    root.update_idletasks()  # Actualizează interfața pentru a afișa mesajul de încărcare

    text = text_entry.get("1.0", tk.END)
    journal_entries = re.split(r'[.!?]', text)

    positive_count = 0
    negative_count = 0

     # Ascunde mesajul de încărcare
    loading_label.destroy()

    # Afisare rezultate într-o fereastră nouă
    results_window = tk.Toplevel(root)
    results_window.title("Rezultate Analiză")
    results_text = tk.Text(results_window, wrap=tk.WORD, width=80, height=20)
    results_text.pack(padx=10, pady=10)
    results_text.insert(tk.END, "Valoare Sentiment        |        Subiectivitate\n")
    results_text.insert(tk.END, "--------------------------------------------\n\n")
    for entry in journal_entries:
        entry = entry.strip()
        if entry:
            sentiment, subjectivity = analyze_sentiment(entry)
            results_text.insert(tk.END, entry + '\n')
            results_text.insert(tk.END, str(sentiment) + "                    |         " + str(subjectivity) + '\n\n')

            # Contorizarea cuvintelor pozitive și negative
            for word in entry.split():
                word_without_diacritics = unidecode(word.lower())
                if any(word_without_diacritics.startswith(unidecode(w)) for w in positive_words):
                    positive_count += 1
                if any(word_without_diacritics.startswith(unidecode(w)) for w in negative_words):
                    negative_count += 1

     # Caracterizare persoană
    characterization = "Caracterizare persoană:\n------------------------\n"
    if positive_count > negative_count:
        characterization += "Persoana pare a fi optimistă și are o atitudine pozitivă.\n"
    elif negative_count > positive_count:
        characterization += "Persoana pare a fi pesimistă și are o atitudine negativă.\n"
    else:
        characterization += "Persoana pare a avea o atitudine echilibrată.\n"

    results_text.insert(tk.END, characterization)

    # Permiterea copierii și lipirii
    results_text.bind("<Control-c>", copy)
    results_text.bind("<Control-v>", paste)

# Funcții pentru copiere
def copy(event):
    widget = event.widget
    widget.clipboard_clear()
    widget.clipboard_append(widget.selection_get())

def paste(event):
    widget = event.widget
    widget.insert(tk.INSERT, widget.clipboard_get())

# Interfața grafică
root = tk.Tk()
root.title("Analiza Sentimentelor în Psihiatrie")

text_entry = tk.Text(root, wrap=tk.WORD, width=50, height=10)
text_entry.pack(padx=10, pady=10)

# Permiterea copierii
text_entry.bind("<Control-c>", copy)

analyze_button = tk.Button(root, text="Analizează", command=analyze)
analyze_button.pack(padx=10, pady=10)

root.mainloop()


That's all folks.


Also, see my other Python Scripts ---HERE---

Alatura-te Comunitatii Neculai Fantanaru
The 63 Greatest Qualities of a Leader
Cele 63 de calităţi ale liderului

Why read this book? Because it is critical to optimizing your performance. Because it reveals the main coordinates after that are build the character and skills of the leaders, highlighting what it is important for them to increase their influence.

Leadership - Magic of Mastery
Atingerea maestrului

The essential characteristic of this book in comparison with others on the market in the same domain is that it describes through examples the ideal competences of a leader. I never claimed that it's easy to become a good leader, but if people will...

The Master Touch
Leadership - Magia măiestriei

For some leaders, "leading" resembles more to a chess game, a game of cleverness and perspicacity; for others it means a game of chance, a game they think they can win every time risking and betting everything on a single card.

Leadership Puzzle
Leadership Puzzle

I wrote this book that conjoins in a simple way personal development with leadership, just like a puzzle, where you have to match all the given pieces in order to recompose the general image.

Performance in Leading
Leadership - Pe înţelesul tuturor

The aim of this book is to offer you information through concrete examples and to show you how to obtain the capacity to make others see things from the same angle as you.

Leadership for Dummies
Leadership - Pe înţelesul tuturor

Without considering it a concord, the book is representing the try of an ordinary man - the author - who through simple words, facts and usual examples instills to the ordinary man courage and optimism in his own quest to be his own master and who knows... maybe even a leader.