
jRc           @   s  d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l Z d  d l m Z d  d l m Z d  d l	 Z	 d  d l
 m
 Z
 d  d l m Z m Z i i e d 6d d 6d	 6i e d 6d
 d 6d 6i e d 6d d 6d 6i e d 6d d 6d 6i e d 6d d 6d 6i e d 6d d 6d 6i e d 6d d 6d 6i e d 6d d 6d 6i e d 6d d 6d 6i e d 6d d 6d 6i e d 6d d 6d 6i e d 6d d 6d 6i e d 6d  d 6d! 6i e d 6d" d 6d# 6i e d 6d$ d 6d% 6i e d 6d& d 6d' 6i e d 6d( d 6d) 6i e d 6d* d 6d+ 6i e d 6d, d 6d- 6i e d 6d. d 6d/ 6i e d 6d0 d 6d1 6i e d 6d2 d 6d3 6i e d 6d4 d 6d5 6i e d 6d6 d 6d7 6i e d 6d8 d 6d9 6Z d:   Z d; e f d<     YZ d= e f d>     YZ d? e f d@     YZ dA e f dB     YZ dC f  dD     YZ dE e f dF     YZ dG e f dH     YZ dI e f dJ     YZ dK e f dL     YZ dM e f dN     YZ d S(O   iN(   t   deepcopy(   t   ceil(   t   eon_date(   t   list_of_top_level_domainst   table_by_montht	   mandatoryi    t   ordert   MARKERi   t   TYPEi   t   AUTHORi   t   GEOLOCi   t   AFFILi   t   TITLEi   t   EDITORi   t   CTITLEi   t   SERIALi	   t   CHAPTERi
   t   VOLUMEi   t   PAGEi   t   ARTICLEi   t   YEARi   t   PUBLISHi   t   DOIi   t   URLi   t   TOPKEYi   t   FUNDINGi   t   FILEi   t   ABSi   t   REMARKi   t   REMARK0i    t   REMARK1i!   t   REMARK2c           C   s   t  j d  j j S(   Ni   (   t   syst	   _getframet   f_codet   co_name(    (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyt   whoamiM   s    t   ReferenceErrorc           B   s   e  Z d    Z d   Z RS(   c         C   s   | |  _  d  S(   N(   t   message(   t   selfR&   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyt   __init__R   s    c         C   s   |  j  S(   N(   R&   (   R'   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyt   __str__U   s    (   t   __name__t
   __module__R(   R)   (    (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyR%   P   s   	t   Authorc           B   s   e  Z d    Z RS(   c         C   s   i | d 6|  _  | |  _ d  S(   Nt   details(   t   featuret	   timestamp(   R'   R/   t   author(    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyR(   [   s    	(   R*   R+   R(   (    (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyR,   Y   s   t
   AuthorListc           B   s   e  Z d    Z RS(   c         C   sC   g  | j  D], } | j d D] } t | j |  ^ q q
 |  _  d  S(   NR0   (   t   atomsR.   R,   R/   (   R'   t   ref_listt   xR0   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyR(   g   s    ?(   R*   R+   R(   (    (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyR1   e   s   t	   Referencec           B   s}   e  Z d    Z d   Z d   Z e   d  Z d   Z d   Z d d  Z	 d   Z
 d e e d	  Z d
   Z d   Z RS(   c         C   s   | |  _  i |  j   d 6|  j d  d 6|  j   d 6|  j   d 6|  _ |  j   t | d  d k ov d | d k |  _ |  j r | d n | d d	 d
 !d } t | d d |  _	 d  |  _ d  S(   NR0   R   t   editort   topkeyt   remarkR   i   s   -00i    i   s   -01t   formats   YYYY-MM(   t   hasht   split_namest   split_topkeyt   all_remarksR.   t   validatet   lent	   has_monthR   R/   t   Nonet   bibtex(   R'   R:   t   year(    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyR(   q   s    	
)(	c         C   s   d } xS t  t j   d d   D]6 } |  j j |  r" | d | |  j | f 7} q" q" W|  j d  k r | d d |  j f 7} n  | S(   Nt    t   keyc         S   s   t  |  d S(   NR   (   t
   g_REF_KEYS(   t   k(    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyt   <lambda>   s    s	   %10s: %s
t   BIBTEX(   t   sortedRF   t   keysR:   t   has_keyRB   RA   (   R'   t   strRE   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyt   __repr__   s    ""c         C   s
   |  j    S(   N(   t   custom_print(   R'   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyR)      s    c      
   C   sj  | j  d  r | d n t } | j  d  r8 | d n t } | j  d  rW | d n d } |  j j d d d g  \ } } |  j } d } | r d }	 | r d	 |	 n |	 }
 | d
 |	 d | d d d | |  j r d | d n d f |	 7} n+ | rd }	 d }
 | d 7} n d }	 |	 }
 |  j d d | p9| } | | rRd | n | |
 7} | d } | | rv| n d | |
 7} t } t } | j  d  r| d 7} | j  d  r| |  j d d | p| d d d g t |  j d  d k d  7} n  | d } x` d! d" d# g D]O } | | k r| j	 |  t |  d } | d | !d$ | | d$ } qqW| | 7} | j  d%  r| d% } | d& d' | k r| j
 d'  n	 d( | f 7} n  | j  d)  r| |
 7} n  t } n  | j  d)  r| | d) 7} t } n  | j  d*  rO| d* } | | rAd+ | d, n d- | 7} n  | r| j  d.  ss| j  d/  r| j  d.  r| d. n | d/ } | | d d0 k rd1 n- | j  d*  rd n | j  d/  rd2 n d3 | 7} n  | d4 |  j rd | d n d5 | f |
 7} t } n  | j  d6  rR| | d6 7} | rR| |
 7} qRn  | s| d7 } | d4 |  j rd | d n d5 | f | j  d.  rd8 | | d. f n* | j  d/  rd8 | | d/ f n d9 | |
 7} n  | r]| d: d5 j |  j d;  |
 7} | j  d<  r2| d= | d< |
 7} n  | d k rt j j t j j | d> d? | d   r| d@ | d |	 7} n  t j j t j j | dA dB | d   r| dC | d |	 7} qt j j t j j | dD dB | d   r| dE | d |	 7} qn  | j  dF  r]| dG | dF | dF dH dI k rGdJ n dK dL |	 7} q]n  | j  dM  r| dM } | | rdN | dO n dP | |	 7} n  | r@| j  dQ  r@dR } t t dS t | dQ  |   } | dT dU | d dV |	 dW | d |	 dX | | f |	 | dQ |	 dY |	 dZ |	 7} q@n  | | rOd[ n | r[d\ n d 7} | |	 S(]   Nt   html_paragrapht	   html_listt	   html_rootRD   t   attrRC   t   months   
s   <br />s   <p>s;   <img src="../images/bullet_triangle_right.gif" name="%s" />R   s8   <img src="../images/clearsp.gif" width="7" height="1" />s   <font color="red">%s-%s</font>s   %02di    t   00s   , s   <li>R	   t   htmls	   <i>%s</i>R   s   "%s"R   s   in: R   s    (edt   sR6   i   s   .)s   Conf. ons   Workshop ons   Symp. ont   "R   s   , %s %st   =s   Ch.R   R   s    <b>s   </b>s    Vol. R   R   t   (t    s   , art. s   , p. s   %s %st   ,R   R   s   ; %s %ss   ; %ss   <i>Keys: %s</i>R7   R   s   <i>Funding: %s</i>t   abstracts   %s.htmlsN   <a href="abstract/%s.html"><img src="../images/abs_icon.png" border="0" /></a>t   pdf_privates   %s.pdfsT   <a href="pdf_private/%s.pdf"><img src="../images/pdf_red_icon.png" border="0" /></a>t
   pdf_publicsU   <a href="pdf_public/%s.pdf"><img src="../images/pdf_green_icon.png" border="0" /></a>R   s!   <a href="%s"><img src="../images/is   .pdft	   pdf_greent   htms   _icon.png" border="0" /></a>R   s   <a href="http://dx.doi.org/s5   "><img src="../images/doi_icon.png" border="0" /></a>s   doi: R   iP   g      ?sH   <input type="image" src="../images/abs_icon.png" onClick="TextareaOnOff(s   '%s's   )">s#   <div id="%s" style="display:none;">s   <textarea rows="%s" cols="%s">s   </textarea>s   </div>s   </p>s   </li>(   RL   t   FalseR/   t   getR:   R@   t
   join_namesR?   R.   t   findt   splitt   Truet   joint   ost   patht   isfilet   longR   (   R'   t   print_attributet   html_parRQ   RR   RC   RT   R:   RM   t
   soft_breakt
   hard_breakt   linet   page_and_year_neededt   page_and_year_usedt   cmarkt   cpost   colst   rows(    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyRO      s    !	<

K
$

2		
%#/	
r",,,>
)$_"c         C   s   g  |  j  D] } t j |  s
 | ^ q
 } | ra | GHt d t   d j |  |  j  f   n  g  t D] } t | d rh | ^ qh } d j g  | D] } |  j  j |  s | ^ q  } t |  d k r t d t   |  j  | f   n  d  S(   Ns   %s, invalid key(s) '%s'
%sR\   R   i    s   %s,
%s
missing types '%s'(   R:   RF   RL   R%   R$   Rh   R?   (   R'   RE   t   badR   t   missing(    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyR>   C  s    ++'4"c         C   s   g  } |  j  j d  r |  j  d j d  } x | D] } d | k rW i d d 6} n` | j d  } i | d j   d 6| d j   d 6} t |  d	 k r | d
 j   | d <n  | j |  q5 Wn  | S(   NR
   t   ;t   unknownt   countryR\   i    t   cityii   i   t   state(   R:   RL   Rf   t   stripR?   t   append(   R'   t   geolocRq   t   entryt   loct   pieces(    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyt   split_geolocm  s    (R	   c   	      C   s  g  } |  j  j |  rg  } x4 |  j  | j d  D] } | j | j d   q5 Wt |  d d k r t d t   t |  j  t f   n  g  t d t |  d  D]2 } i | | j	   d 6| | d j	   d 6^ q } | d	 k r|  j
   } t |  t |  k r]x t t |   D]1 } x( | | D] } | | | | | | <q6Wq%Wqt |  d k rxd t t |   D]1 } x( | d D] } | d | | | | <qWqWqt d
 t   |  j  f   qn  | S(   NRz   R\   i   i    s   %s, error in %s record
%st   lasti   t   firstR	   s)   %s,
%s
# geolocs does not match # authors(   R:   RL   Rf   t   extendR?   R%   R$   t   typet   rangeR   R   (	   R'   RE   R0   Rq   R4   t   iR   t   nRG   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyR;     s(    &Q!!"c         C   s`   g  } |  j  j d  r\ t t g  |  j  d j   j d  D] } | j   ^ q;   } n  | S(   NR   R\   (   R:   RL   t   listt   sett   lowerRf   R   (   R'   R7   R4   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyR<     s    Dc   	      C   s  |  j  |  } d } x| D]} | d k rQ | | | d k rG d n d 7} n  | d } | d } | r| r d | k r | j d d  } n  d	 | k r | j d	 d
  } n  d | k r | j d d  } n  d	 | k r | j d	 d
  } q n  | | d | 7} q d | k rkd	 | k rL| j d d  } | j d	 d
  } qk| j d d  } | d
 7} n  d	 | k rd | k r| j d d  } | j d	 d
  } q| j d	 d  } d | } n  | | d | 7} q W| S(   NRD   is    and s   , R   R   s   <<s   <u>s   >>s   </u>R[   (   R;   t   replace(	   R'   RE   t   reverseRV   t   authorsRq   R0   R   R   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyRd     s@    #

    c         C   s-   g  |  j  D] } d | k r
 |  j  | ^ q
 S(   NR   (   R:   (   R'   R4   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyR=     s    c         C   s   x | D] } | j    } | d k r | d k r |  j j |  sh t d t   | |  j   f   n  |  j | } t j | | |  } | s t S| d | j	   !d | | j	   | j
   !d | | j
   |  j | <q q Wt S(   Nt   KEYt   CATs   %s, ref has no key '%s'
%s'i    s   <<s   >>(   t   upperR:   RL   R%   R$   RN   t   ret   searchRb   t   startt   endRg   (   R'   t	   regex_mapRE   R   t   valt   m(    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyt   matches_regex  s    %N(   R*   R+   R(   RN   R)   t   dictRO   R>   R   R;   R<   Rb   Rd   R=   R   (    (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyR5   m   s   				*			-	t   ReferenceListc           B   s   e  Z d d d   Z d d d  Z d   Z d   Z d   Z e d  Z	 e d  Z
 d d  Z d d	  Z d d
  Z d d d  Z d   Z d d  Z d   Z d   Z d   Z d   Z d   Z RS(   c         C   s=  t  j d t  } t |  t d  k r | j d |  t |  } g  t j |  D] } t |  ^ qX |  _ | j	   | |  _
 t   |  _ t |  _ ng t | t  r t | j  |  _ | j
 |  _
 | j |  _ | j |  _ n t d t   t |  f   | j d t |  j   |  j   |  j | |  d  S(   Ns   ReferenceList.%sRM   s   read s   %s, cannot init from %ss   number of references is %s(   t	   tiny_bitst   sayR$   R   t   opent   yamlt   load_allR5   R2   t   closet	   yaml_fileR   Rm   Rb   t
   has_bibtext
   isinstanceR   R    R%   R?   RB   t   filter_times(   R'   t   inputt
   start_timet	   stop_timeR   t   handleR4   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyR(     s&    +
	
c         C   s  t  |  j  } | d  k r: t | t  r: t |  } n  | d  k re t | t  re t |  } n  g  |  j D]! } | j j | |  ro | ^ qo |  _ | d  k s | d  k rpt j d t	    } | j | d  k rd t  |  j  | | j
 d d  f nh | d  k r5d t  |  j  | | j
 d d  f n4 d t  |  j  | | j
 d d  | j
 d d  f  n  | d  k rt g  |  j D] } | j ^ q j d  n | |  _ | d  k rt g  |  j D] } | j ^ q j d  n | |  _ d  S(   Ns   ReferenceList.%ss   %s/%s references since %sR9   s   YYYY-MMs   %s/%s references before %ss"   %s/%s references between %s and %sRT   (   R?   R2   RA   R   R   R/   t   betweenR   R   R$   Rc   t   mint   bopR   t   maxt   eopR   (   R'   R   R   t   nrefsR4   R   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyR   
  s    444;CCc         C   s-   d j  g  |  j D] } d | j   ^ q  S(   Ns   
s   %s(   Rh   R2   RN   (   R'   R4   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyRN   &  s    c         C   s-   d j  g  |  j D] } d | j   ^ q  S(   Ns   
s   %s(   Rh   R2   R)   (   R'   R4   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyR)   )  s    c         C   s   t  |  j  S(   N(   R?   R2   (   R'   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyR?   ,  s    c         C   s   | |  j  d <d  S(   NRP   (   Rm   (   R'   t   value(    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyt   set_html_paragraph/  s    c         C   s   | |  j  d <d  S(   NRQ   (   Rm   (   R'   R   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyt   set_html_list3  s    RD   c         C   s   | |  j  d <d  S(   NRR   (   Rm   (   R'   R   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyt   set_html_root7  s    c         C   s   | |  j  d <d  S(   Nt	   html_mode(   Rm   (   R'   R   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyt   set_html_mode;  s    c         C   s    | d k r | |  j  d <n  d  S(   NRD   t   title(   Rm   (   R'   R   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyt	   set_title?  s    c      	   C   sW  |  j  j d  o" |  j  d d k } d } | r | | d k rF | n d d d d d	 d
 7} t |  d k r d | k r | j d  } | d k r t d t   | f   n  | d | !d d d d d d d d d | | } q n  | d j g  |  j D] } d | j |  j   ^ q 7} | rS| | d k rI| n d 7} n  | S(   NR   RV   RD   s   <html>
s   <head>
sQ   <link rel="StyleSheet" href="../css/publist.css" type="text/css" media="screen">
s2   <meta name="robots" content="noindex,nofollow" />
s   </head>
s   <body>
s   <div id="content">i    s   function TextareaOnOffs   </head>is   %s, </head> not found in '%s's    <script type="text/javascript">
s!   function TextareaOnOff(marker) {
s?     if (document.getElementById(marker).style.display=="none") {
s<       document.getElementById(marker).style.display="inline";
s     } else {
s:       document.getElementById(marker).style.display="none";
s     }
s   }
s
   </script>
s   
s   %ss   </div></body>
</html>s   <html>
<head>
(	   Rm   RL   R?   Re   R%   R$   Rh   R2   RO   (   R'   t	   html_headt	   html_tailt
   plain_htmlRM   t   posR4   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyRO   D  s     %.9c         C   sc  t  j d t    } |  j r# d  St |  j  } g  } xt |  D]} |  j | } d } x| | j d r{ | j d n
 | j d D]S } | d | d k r d n0 | d d d	 !d
 k r | d d n | d d 7} q W| d | j j	 d d  7} | j
 |  } | d k r1t d t   | f   n  | d k r| j
 | d  d k rvt d t   | d f   n  | j |  } | j d | | f d	  | | c d 7<| | |  j | _ n  | j
 | d  d k r<d }	 xT |	 D]- }
 | j
 | |
  d k r| |
 7} PqqWt d t   | |	 f   n  | j |  | | _ qE Wt |  _ d  S(   Ns   ReferenceList.%sRD   R0   R6   t   vestkaR   t   Si    i   s   van i   s   %sRS   RC   i   s)   %s, duplicate bibtex key '%s' constructedt   as"   %s, bibtex key '%s' already existss   duplicate key '%s' -> '%sa't   abcdefghijklmnopqrstuvwxyzs0   %s, unable to construct bibtex key from '%s[%s]'(   R   R   R$   R   R?   R2   R   R.   R/   Rc   t   countR%   t   indexR&   RB   R   Rg   (   R'   R   R   RB   t   ireft	   referenceRE   R0   R   t   alfabett   letter(    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyRB   l  sD    	.% 
	c         C   s   t  |   } | d  k r g  | _ xz |  j D]o } | j |  } | j   r+ t  |  } | j   } d j |  | j d <| | j d <| j j	 |  q+ q+ Wt
 j d t    } | j d t | j  t |  j  f  n  | S(   NR\   R   R7   s   ReferenceList.%ss   %s/%s references(   R    RA   R2   t   usedRK   t   category_by_featureRh   R:   R.   R   R   R   R$   R?   (   R'   t   keywordst   sublistt   refR   t   ref_copyRK   R   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyt   filter_keywords  s    	,c         C   s   t  |   } | r g  |  j D] } | j |  r | ^ q | _ t j d t    } | j d t | j  t |  j  f  n  | S(   Ns   ReferenceList.%ss   %s/%s references(   R    R2   R   R   R   R$   R?   (   R'   R   R   R4   R   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyt   filter_by_regex  s    .,c            s  t  |   } t |   } | j |  | j   d } | j |  } t t | g  | D] } | j | |  ^ qT     t |   } | j |  | j   d } | j |  } t t | g  | D] } | j | |  ^ q    t   d   f d   d t	 } t  d  f d   d t	 } t
 |  j  } t
 |  }	 t
 |  }
 |  j j d  rl|  j d n d } |  j j d  rd	 |  j d d
 n d } d | } d | } d | } t j d t j    d } | d k r2d d | d d d | |
 |	 f d t   j    t |  d d g } n | d k rd d d | d d d d d  d! d" d# d$ d% d | d d d& | d' d( d) d* d | |
 |	 f d t   j    t |  d d g } nL d+ | d | d d, d- d. | |
 |	 f d/ t   j    t |  d g	 } d0 } t |	 |  \ } } | | d k 7} t   } | d k rZd1 n d2 } x t |  D] } | d k rd n d3 } xX t |  D]J } | | | } | |	 k rqn  | | | | |   | | f 7} qW| | d k rd n d4 7} | j |  qmW| d k r5| j d5 d6 g  nQ| d k rh| j d5 d d& | d' d7 d g  n | j d | d g  d0 } d8 }
 t |
 |  \ } } | | d k 7} x t |  D] } | d k rd n d3 } xT t |  D]F } | | | } | |
 k rqn  | | | |  | | f 7} qW| | d k rFd n d4 7} | j |  qW| d k r| j d5 d9 d: d; g  n  d< j |  GHd  S(=   Ni    RE   c            s     |  S(   N(    (   t   abbrev(   t   count_by_country(    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyRH     s    R   c            s     |  S(   N(    (   R   (   t   count_by_author(    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyRH     s    R   RD   R   s    (t   )s?   External data papers: authors per country and papers per authors   Number of authors per countrys)   Number of papers by most prolific authorss   %Y-%b-%d %H:%M:%Ss    UTCt   xincs   <xhtmlcode>s   <b>Last updated on s   </b>s   <br />sC   There are %s papers with %s different authors in %s countries<br />s5   The average number of authors per paper is %.1f<br />s   <table border="1">RV   s   <html>s   <head>s   <title>s   </title>s   <style type="text/css">s   <!--s,   	table {border: purple solid 4px; width=975}sh   	th    {text-align: left; color: brown; padding-left:10; padding-right:10; border: blueviolet solid 1px}sd   	td    {color : navy; font-weight: bold; padding-left:10; padding-right:10; border: green solid 1px}s   -->s   </style>s   </head>s   <body>s   <h1>s   </h1>s   <div id="papers">sA   As determined from author affiliations specified in papers.<br />s/   The count includes authors and co-authors<br />s   Last updated on s:   As determined from author affiliations specified in paperss)   The count includes authors and co-authorss=   There are %s papers with %s different authors in %s countriess/   The average number of authors per paper is %.1fi   s
   %20s %5s |s-   <td width="180">%s</td><td width="50">%s</td>s   <tr>s   </tr>s   </table>s   </xhtmlcode>s   <div id="authors">i   s   </div>s   </body>s   </html>s   
(   t
   WorldStackR1   t   count_atomsRK   R   t   zipt   totalt   AuthorStackRJ   Rg   R?   R2   Rm   RL   t   timet   strftimet   gmtimet   sumt   valuest   floatt   divmodR   R   R   R   Rh   (   R'   t   worldt   author_listt   catt	   countriesR4   R   t   namest
   nr_of_pubst   nr_of_countriest   nr_of_authorsR   R   t
   title_maint   title_for_country_tablet   title_for_author_tablet   current_timet   contentt   nr_of_columnst
   nr_of_rowst   leftovert   country_nameR9   t   irowt   add_contentt   icolumnR   (    (   R   R   s2   /home/soft/smei/ucsd/gen/python/reference_class.pyt   authors_by_country_summary  s    44!!%-


		(
$c   	      C   s  | j  |   | j d } i | j d 6} i d d 6} |  j j d  rV |  j d n d } |  j j d  r d |  j d d n d } d | } t j d	 t j    d
 } | d k r d d | d d d | j   g } n | d k rAd d d | d d d d d d d d d d d | d d d | j   d g } n  d  | d d | j   d g } | j	 t
 | d! | d" | d k  | d k r| j	 d# g  n% | d k r| j	 d$ d% d& g  n  d' j |  GHd  S((   NR   t   all_datasetsRD   R   R   s    (R   s/   External data papers: papers per year and months   %Y-%b-%d %H:%M:%Ss    UTCR   s   <xhtmlcode>s   <b>Last updated on s   </b>s   <br />s   Total number of papers is %sRV   s   <html>s   <head>s   <title>s   </title>s   <style type="text/css">s   <!--s,   	table {border: purple solid 4px; width=975}sh   	th    {text-align: left; color: brown; padding-left:10; padding-right:10; border: blueviolet solid 1px}sd   	td    {color : navy; font-weight: bold; padding-left:10; padding-right:10; border: green solid 1px}s   -->s   </style>s   </head>s   <body>s   <table border="1">s   Last updated on t   key_replacementt   in_htmls   </xhtmlcode>s   </table>s   </body>s   </html>s   
(   R   t   stackt   calendarRm   RL   R   R   R   R   R   R   Rh   (	   R'   R   t	   top_countR   R   R   R   R   R   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyt   papers_summaryw  sb    %-
	c      
   C   s   t  |   } | j t |    | j   d } | j |  } | j   } t t | g  | D] } | j | | d j ^ qZ   } |  j	 j
 d  r |  j	 d n d } d j t | d | d t d | d	 g  d GHd  S(
   Ni    R   R   s   country of origin of authorss   
R   t   sort_by_countt   headers   nr of authors(   R   R   R1   RK   R|   R   R   R   R   Rm   RL   Rh   R   Rg   (   R'   R   R   R   R|   R4   R   R   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyt   authors_by_country_detail  s    :%c         C   s   | j  |   | j   } t t | g  | D] } | j | d j ^ q)   } |  j j d  rn |  j d n d } d j t	 t
 d t d | d g  d GHd  S(   NR   R   s   published paperss   
R   R   s   nr of papers(   R   RK   R   R   R   R   Rm   RL   Rh   R   R   Rg   (   R'   R   R   R4   t   count_by_catR   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyt   papers_by_category_detail  s    6%N(   R*   R+   RA   R(   R   RN   R)   R?   Rb   R   R   R   R   R   RO   RB   R   R   R   R   R  R  (    (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyR     s$   #			(	P			J	t   CountCalendarc           B   sG   e  Z e   d   Z d   Z d   Z d d d  Z d d d  Z RS(   c         C   s   t  |  |  _ d  S(   N(   R    R   (   R'   R   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyR(     s    c         C   s   x | j  D] } |  j  j |  s5 t   |  j  | <n  xa | j  | D]R } |  j  | j |  ss d |  j  | | <n  |  j  | | c | j  | | 7<qC Wq
 W|  S(   Ni    (   R   RL   R   (   R'   R   RC   RT   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyt   __iadd__  s    *c         C   s   d } xy |  j  D]n } | d | 7} d g d } x. |  j  | D] } |  j  | | | | d <q? W| d d d t |  7} q W| r | d d !} n  | S(	   NRD   s   %s |i    i   i   s    %5ds   
i(   R   t   tuple(   R'   RW   RC   R   RT   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyR)     s     c         C   s0  | d  k r$ | d  k r$ |  j } n| d  k r_ | |  j k rS i |  j | | 6n t   } n | d  k r t   } x |  j D]W } |  j | j |  r~ | j |  s t   | | <n  |  j | | | | | <q~ q~ WnJ |  j j |  r|  j | j |  r|  j | | n t   | | | <t |  S(   N(   RA   R   R   RL   R  (   R'   RC   RT   R   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyt   copy  s    /	#Jc         C   s?   t  g  |  j D]+ } |  j | D] } |  j | | ^ q q  S(   N(   R   R   (   R'   RC   RT   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyR   '  s    N(	   R*   R+   R   R(   R  R)   RA   R  R   (    (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyR    s
   		t   FeatureStackc           B   s   e  Z e   d   Z d   Z d   Z d d d  Z d   Z d   Z	 d   Z
 d d d  Z d d d d d  Z d	   Z d
   Z d   Z RS(   c   	      C   s  t  j d t    } t |  t d  k rp | j d |  t |  } t j |  } | j   | |  _ nC t |  t t	    k r | } n t
 d t   t |  f   d | k r t
 d t     n  i | j   d 6|  _ x | D] } d | | k rt
 d t     n  i | j   d 6|  j | <x | | D] } d | | | k rst
 d t     n  i | j   d 6|  j | | <x7 | | | D]' } | | | | |  j | | | <qWqCWq Wd  S(   Ns   FeatureStack.%sRM   s   read s   %s, cannot init from %sR   s    %s, 'count' is reserved hash key(   R   R   R$   R   R   R   t   loadR   R   R   R%   R  R   (	   R'   R   R   R   R   t   featuresR   RE   t   item(    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyR(   Q  s0    
	-c         C   s   |  j  d c | j  d 7<xz | j   D]l } |  j  | d c | j  | d 7<xA | j |  D]0 } |  j  | | d c | j  | | d 7<q_ Wq' W|  S(   NR   (   R   RK   (   R'   R.   R   RE   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyR    s    "2c      	   C   sR  t  |  d  r |  j n t } t  |  d  r6 |  j n d } t  |  d  rT |  j n t } |  j   } d | | d k r~ d n d | f } | d k s | rNx |  j   D] } |  j |  } | d k s | r | d | | f 7} | sGxU |  j |  D]A } |  j | |  } | d k s&| r | d	 | | f 7} q q WqGq q Wn  | S(
   Nt   category_onlyR   RD   t	   keep_zeros   Total count: %s%sR[   i    s   
    %-30s -->: %5ds   
        %-30s: %5d(   t   hasattrR  Rb   R   R  R   RK   (   R'   R  R   R  R   RW   R   RE   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyR)     s     &(c         C   s   t  |   } |  j d j | |  | j d <x | j   D]x } |  j | d j | |  | j | d <xG | j |  D]6 } |  j | | d j | |  | j | | d <qw Wq9 W| S(   NR   (   R    R   R  RK   (   R'   RC   RT   R
  R   RE   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyR    s     (8c         C   sH   t    } x8 |  j   D]* } x! |  j |  D] } | | | <q, Wq W| S(   N(   R   RK   (   R'   t   categoryR   RE   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyR     s
    	c         C   s  | d k r d  St    } xr | j d  D]a } d | k rJ | j d  n	 | t f \ } } | j   j   d	 k rz t n t | | j   <q) W| rt    } |  j d | d <t |  j    } t |  j	    } x |  j   D] }	 x |  j |	  D] }
 g  | D]E } |  j |	 |
 j
 |  r|  j |	 |
 | | | k r| ^ q} t |  t |  k r | j
 |	  si |  j |	 d d 6| |	 <n  |  j |	 |
 | |	 |
 <q q Wq W| |  _ t |  j    } t |  j	    } t j d t    } | j d | | | | f  n  d  S(
   NRD   R\   RY   t   truet   yesR   s   FeatureStack%ss"   %s/%s keywords in %s/%s categories(   R  R  (   R   Rf   Rg   R   R   Rb   R   R?   RK   R   RL   R   R   R$   (   R'   t
   attributest   attrsRS   t   nameR   t   filtered_stackt   n_cat_int   n_key_inR   RE   R4   t   matchest	   n_cat_outt	   n_key_outR   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyt   filter_attributes  s0    	-2	R$	 c   
      C   s  t  j d t    } | j d  s4 | j d  rt   } |  j d | d <t |  j    } t |  j    } x |  j   D] } | j d  s t	 j
 | d |  r x |  j |  D]v } | j d  s t	 j
 | d |  r | j |  si |  j | d d 6| | <n  |  j | | | | | <q q Wq q W| |  _ t |  j    } t |  j    }	 t  j d t    } | j d |	 | | | f  n  d  S(   Ns   FeatureStack.%sRE   R   R   s"   %s/%s keywords in %s/%s categories(   R   R   R$   RL   R   R   R?   RK   R   R   R   (
   R'   R   R   R  R  R  R   RE   R  R  (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyR     s&    	&&'	 c         C   sn   | d  k r |  j n' | d  k r. |  j | n |  j | | j   } t g  | D] } | d k rO | ^ qO  S(   NR   (   RA   R   RK   RJ   (   R'   R   RE   t   lstR4   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyRK   (  s    Ec         C   sM   | d  k r |  j n' | d  k r. |  j | n |  j | | d j | |  S(   NR   (   RA   R   R   (   R'   R   RE   RC   RT   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyR   ,  s    c         C   sq   t    |  j d <xZ |  j   D]L } t    |  j | d <x/ |  j |  D] } t    |  j | | d <qG Wq Wd  S(   NR   (   R  R   RK   (   R'   R   RE   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyt   erase_count/  s     c         C   s  |  j    } | j   } |  j |  } t t |  t |  @ } i  } | rMx | D] } | | } | j |  s t   | | <n  | | j |  s t   | | | <n  t t |  j | |  g  |  j | |  D] }	 |  j | | |	 ^ q   | | | | <qV W| j	 j
 d d d g  \ }
 } t i i d | d 6|
 6 } nE t   } t j d t    } | j d d j |  | j   f  t | d	 | S(
   NRS   RC   RT   i   i    s   FeatureStack.%ss   atom does not match '%s'
%sR\   R   (   R   RK   t   feature_listR   R   RL   R   R   R   R/   Rc   R  R   R   R$   t   debugRh   RN   R  (   R'   t   atomt   all_categoriest   all_featurest   atom_featurest   common_featuresR   RE   R   R4   RC   RT   R   R   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyR   J  s&    
_!!	&c         C   s5   |  j    x$ | j D] } |  |  j |  7}  q Wd  S(   N(   R  R2   R   (   R'   t   refsR   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyR   t  s    
N(   R*   R+   R  R(   R  R)   RA   R  R   R  R   RK   R   R  R   R   (    (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyR  +  s   &7	
		'	#	+		*t   KeywordStackc           B   s   e  Z d    Z RS(   c         C   s&   d   |  _  t t |   j |  d  S(   Nc         S   s   |  j  d S(   NR7   (   R.   (   R   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyRH     s    (   R  t   superR&  R(   (   R'   R   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyR(     s    (   R*   R+   R(   (    (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyR&  |  s   R   c           B   s   e  Z d    Z d   Z RS(   c         C   s   g  | j  D]4 } | j d D]  } | d d k r | d ^ q q
 } t t |   } i t t | g  t t |   D] } t   ^ qu   d 6} t t	 |   j
 |  t   |  _ d   |  _ d  S(   NR0   R|   R{   R   c         S   s/   |  j  d d d k r( |  j  d d n d g S(   NR-   R|   R{   RD   (   R.   (   R0   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyRH     s    (   R2   R.   R   R   R   R   R   R?   R'  R   R(   R   R   R  (   R'   R3   R   R0   R|   R4   R   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyR(     s    D>c         C   s<   |  j  d  } t t | g  | D] } |  j | ^ q   S(   NR   (   RK   R   R   R   (   R'   t   tldst   tld(    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyR|     s    (   R*   R+   R(   R|   (    (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyR     s   	R   c           B   s   e  Z d    Z RS(   c         C   s   g  t  |  j D]* } | j d d d | j d d ^ q } t t |   } i t t | g  t t |   D] } t   ^ qq   d 6} t	 t
 |   j |  d   |  _ d  S(   NR-   R   s   , R   R   c         S   s%   |  j  d d d |  j  d d g S(   NR-   R   s   , R   (   R.   (   R0   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyRH     s    (   R1   R2   R.   R   R   R   R   R   R?   R'  R   R(   R  (   R'   R3   R0   R  R4   R   (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyR(     s    @>(   R*   R+   R(   (    (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyR     s   (   R    Ri   R   R   R   R  R    t   mathR   R   R   t   general_listsR   R   Rg   Rb   RF   R$   t	   ExceptionR%   t   objectR,   R1   R5   R   R  R  R&  R   R   (    (    (    s2   /home/soft/smei/ucsd/gen/python/reference_class.pyt   <module>   s^   0&		 y  
> R