
    h
                        S r SSKrSSKJr   " S S5      r\S:X  a  \" S5        \" 5       r\" S5        S	r\R                  \5      r
\" S
\ S35        \" S\
S    S\
S   S S35        \" S5        Sr\R                  \5      r
\" S\
S    V s/ s H  o S   PM	     sn  35        \" S5        \" S5        \" S5        \" S5        \" S5        \" S5        ggs  sn f )z0
NLP Processor - Natural language understanding
    N)Counterc                   4    \ rS rSrS rS rSS jrS	S jrSrg)
NLPProcessor   c                     / U l         g )Nprocessed_texts)selfs    C/home/james-whalen/eden-agi-project/core/reasoning/nlp_processor.py__init__NLPProcessor.__init__   s
    !    c                    ^ / SQn/ SQnUR                  5       m[        U4S jU 5       5      n[        U4S jU 5       5      nXE:  a  SnXDU-   S-   -  nOXT:  a  SnXTU-   S-   -  nOSnS	nUUUUS
.$ )zBasic sentiment analysis)goodgreat	excellentamazing	wonderful	fantasticlovebestperfecthappysuccess)badterribleawfulhorriblehateworstfailfailuresadangrypoorc              3   6   >#    U  H  oT;   d  M
  S v   M     g7f   N .0word
text_lowers     r   	<genexpr>1NLPProcessor.analyze_sentiment.<locals>.<genexpr>        P>4Z=OQQ>   		c              3   6   >#    U  H  oT;   d  M
  S v   M     g7fr'   r)   r*   s     r   r.   r/      r0   r1   positiver(   negativeneutralg      ?)	sentiment
confidencepositive_signalsnegative_signals)lowersum)	r
   textpositive_wordsnegative_wordspositive_countnegative_countr6   scorer-   s	           @r   analyze_sentimentNLPProcessor.analyze_sentiment   s    HD ZZ\
P>PPP>PP*"I"~&E&IJE,"I"~&E&IJE!IE # . .	
 	
r   c                    1 Skn[         R                  " SUR                  5       5      nU Vs/ s H  oUU;  d  M
  [        U5      S:  d  M  UPM     nn[	        U5      nUR                  U5      nU[        U5      S.$ s  snf )zExtract key words from text>   aanatinisofonortoandarebutforthewaswerewithz\b\w+\b   )keywordstotal_words)refindallr:   lenr   most_common)	r
   r<   top_n
stop_wordswordswfilteredcounterrW   s	            r   extract_keywordsNLPProcessor.extract_keywords'   sv    L
 

:tzz|4$Ku!(;AA
AuK(#&&u-$SZ@@ Ls   	A>A>A>c                 Z   [         R                  " SU5      nU Vs/ s H)  oDR                  5       (       d  M  UR                  5       PM+     nn[        U5      U::  a  U[        U5      S.$ US   U[        U5      S-     US   /nSR	                  U5      S-   nU[        U5      US.$ s  snf )	zBasic text summarizationz[.!?]+)summaryoriginal_sentencesr      z. .)rf   rg   summary_sentences)rY   splitstripr[   join)r
   r<   max_sentences	sentencessrk   rf   s          r   summarize_textNLPProcessor.summarize_text5   s    HHY-	(1?	1WWYYQWWY		?y>]*#3y>JJ aLc)na'(bM
 ))-.4 "%i.!.
 	
 @s
   B(B(r   N)   )rV   )	__name__
__module____qualname____firstlineno__r   rB   rc   rr   __static_attributes__r)   r   r   r   r      s    "
8A
r   r   __main__zNLP PROCESSOR TESTu   
😊 Sentiment Analysis:z0This is an amazing and wonderful day! I love it!z
   Text: ''z   Sentiment: r6   z (r7   z.0%z confidence)u   
🔑 Keyword Extraction:zHMachine learning and artificial intelligence are transforming technologyz   Keywords: rW   u   
📝 Eden can now:z   - Analyze sentimentz   - Extract keywordsz   - Summarize textz   - Process natural languageu   
✅ NLP PROCESSOR OPERATIONAL)__doc__rY   collectionsr   r   ru   printnlpr<   rB   resultrc   )ks   0r   <module>r      s   
 C
 C
J z	

.C 

&'=D""4(F	JtfA
	N6+./r&2Fs1K<
XY 

&'UD!!$'F	M
);<);AQ4);<=
>?	
 !	
"#	
!"	
 	
)*	
+,1   =s   C
