î
Àd£Y(  ã               @   sâ   d  Z  d d l m Z d d l Z d d l Z d d l m Z m Z d d „  Z e	 e j
 ƒ d Z i d d 6d d	 6d d
 6d d 6Z d Z e e e ƒ \ Z Z d Z e d k rÂ e j
 d Z n e d ƒ Z e e e e ƒ d S)aª  
File "heatindex.py" by KWR for CSE199, Fall 2017.  Activity support file.
Requires: "heatlib.py" in same directory or peer project file.

Usage: python3 heatindex.py [optional URL]   

Or within python3 environment, can call loadDict, heatScore, and
processUserInput at will.  Can skip "http://" in URL if next comes "www".

Computes a "heat index" for a given webpage from a given dictionary of
"intense" words and their intensity values in several categories.
Tailored to the Canadian National Research Council Affect Intensity Lexicon
http://saifmohammad.com/WebPages/AffectIntensity.htm
by Saif Mohammad, used with his permission (and request not to redistribute).
However, works with any file of lines of the form

word    #.###   category

where NRCAIL's categories 'anger', 'fear', 'sadness', 'joy' are not treated
specially, so that clients can define any categories they wish.
Dictionary file can be local or loaded from a URL.
é    )ÚdivisionN)ÚloadDictÚ	heatScorec             C   sŠ  xƒ|  d k r…|  d k r” i  } t  t d ƒ ƒ } t  t d ƒ ƒ } t  t d ƒ ƒ } t  t d ƒ ƒ } | | d <| | d <| | d	 <| | d
 <nÞ |  j d ƒ r° d |  }  n  t |  | | ƒ \ } } }	 }
 } xZ t | ƒ D]L } t d | d d d ƒx- t | | ƒ D] } t | | | | ƒ qWqÞ Wt d t | ƒ d |  d t | d ƒ d | d |	 d |
 d d d ƒt d d ƒ }  q Wd  S)NÚquitZmulzAnger multiplier: zFear multiplier: zSadness multiplier: zJoy multiplier: ÚangerÚfearÚsadnessÚjoyZwwwzhttp://z
Words under 'z ' and number of times occurring:ÚsepÚ z
Heat index with multipliers z
of z :
é   z from z intense words (z category hits) out of z words read.z3
Paste a URL, or enter 'mul' to change multipliers,z 'quit' to quit: )ÚfloatÚinputÚ
startswithr   ÚsortedÚprintÚreprÚround)ÚurlÚheatDictÚmulDictZangerMulZfearMulZ
sadnessMulZjoyMulZ	heatIndexZintenseCountUniqueZintenseCountZ	wordCountZcatDictZcategoryÚword© r   ú-/shared/web/faculty/regan/cse199/heatindex.pyÚprocessUserInput   s2    


!	r   é   r   r   r   r	   zQhttps://www.cse.buffalo.edu/~regan/cse199/deepweb/NRC-AffectIntensity-Lexicon.txtr   zPaste a URL: éÿÿÿÿ)Ú__doc__Z
__future__r   ÚsysÚreZheatlibr   r   r   ÚlenÚargvZnumArgsr   Úlocationr   r   r   r   r   r   r   Ú<module>   s   #"