Ë
    €ÏP  ã                   ód   — d Z ddlmZ ddlmZ ddlmZ ddlmZ  G d„ de«      Z G d„ d	e«      Z	y
)z5Contains a class to rate commands based on relevance.é    )Úabsolute_import)Údivision)Úunicode_literals)Úlookupc                   ó<   — e Zd ZdZdZdZdZdZdZd„ Z	d„ Z
d„ Zd	„ Zy
)ÚCommandRaterz3A class to rate the results of searching a command.ç      ð?g      à?g      Ð?gš™™™™™¹?c                 óJ   — || _         |j                  «       | _        || _        y)zÙCreate a CommandRater.

    Args:
      results: googlecloudsdk.command_lib.search_help.search_util
        .CommandSearchResult, class that holds results.
      command: dict, a json representation of a command.
    N)Ú_commandÚAllTermsÚ_termsÚ_results)ÚselfÚresultsÚcommands      ú3lib/googlecloudsdk/command_lib/help_search/rater.pyÚ__init__zCommandRater.__init__'   s"   € ð €D„MØ×"Ñ"Ó$€D„KØ€D…Mó    c                 óV   — d}|| j                  «       z  }|| j                  «       z  }|S )a"  Produce a simple relevance rating for a set of command search results.

    Returns a float in the range (0, 1]. For each term that's found, the rating
    is multiplied by a number reflecting how "important" its location is, with
    command name being the most and flag or positional names being the second
    most important, as well as by how many of the search terms were found.

    Commands are also penalized if duplicate results in a higher release track
    were found.

    Returns:
      rating: float, the rating of the results.
    r	   )Ú_RateForLocationÚ_RateForTermsFound)r   Úratings     r   ÚRatezCommandRater.Rate3   s4   € ð €FØ
ˆd×#Ñ#Ó%Ñ%€FØ
ˆd×%Ñ%Ó'Ñ'€FØ€Mr   c                 ó  — d}| j                   j                  «       j                  «       }|D ]Ü  }|t        j                  k(  r|| j
                  z  }Œ&|t        j                  k(  r|| j                  z  }ŒI|j                  t        j                  «      d   t        j                  t        j                  fv rC|j                  t        j                  «      d   t        j                  k(  r|| j                  z  }ŒÎ|| j                  z  }ŒÞ |S )z+Get a rating based on locations of results.r	   r   éÿÿÿÿ)r   ÚFoundTermsMapÚvaluesr   ÚNAMEÚ_COMMAND_NAME_MULTIPLIERÚPATHÚ_PATH_MULTIPLIERÚsplitÚDOTÚFLAGSÚPOSITIONALSÚ_ARG_NAME_MULTIPLIERÚ_DEFAULT_MULTIPLIER)r   r   Ú	locationsÚlocations       r   r   zCommandRater._RateForLocationF   sÒ   € à€FØ—‘×+Ñ+Ó-×4Ñ4Ó6€IÛˆØ	”V—[‘[Ò	 Ø$×/Ñ/Ñ/‰Ø”v—{‘{Ò"Ø$×'Ñ'Ñ'‰ØN‰Nœ6Ÿ:™:Ó& qÑ)¬f¯l©l¼F×<NÑ<NÐ-OÑOØ—‘œvŸz™zÓ*¨2Ñ.´&·+±+Ò=Ø$×+Ñ+Ñ+‰à$×*Ñ*Ñ*‰ð ð €Mr   c                 óˆ   — d}| j                   j                  «       }| j                  D ]  }||vsŒ|| j                  z  }Œ |S )z@Get a rating based on how many of the searched terms were found.r	   )r   r   r   Ú_NOT_FOUND_MULTIPLIER)r   r   r   Úterms       r   r   zCommandRater._RateForTermsFoundV   sF   € à€FØm‰m×)Ñ)Ó+€GØ—”ˆØ	WÒ	Ø$×,Ñ,Ñ,‰ð ð €Mr   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r&   r!   r'   r+   r   r   r   r   © r   r   r   r      s;   „ Ù;ð !ÐØÐØÐØÐð Ðò
òò&ó r   r   c                   ó"   — e Zd ZdZd„ Zd„ Zd„ Zy)ÚCumulativeRaterz'Rates all found commands for relevance.c                 ó   — g | _         y)z Creates a cumulative rater.
    N)Ú_found_commands_and_results)r   s    r   r   zCumulativeRater.__init__c   s   € ð (*€DÕ$r   c                 ó>   — | j                   j                  ||f«       y)a	  Add a command that is a result.

    Args:
      command: dict, a json representation of a command. MUST already be updated
        with the search results.
      result: search_util.CommandSearchResults, the results object that goes
        with this command.
    N)r5   Úappend)r   r   Úresults      r   ÚAddFoundCommandzCumulativeRater.AddFoundCommandh   s   € ð 	×$Ñ$×+Ñ+¨W°fÐ,=Õ>r   c                 ó†   — | j                   D ]2  \  }}t        ||«      j                  «       }||t        j                  <   Œ4 y)z#Adds rating to every command found.N)r5   r   r   r   Ú	RELEVANCE)r   r   r   r   s       r   ÚRateAllzCumulativeRater.RateAlls   s<   € à ×<Ô<ÑˆÜ˜G WÓ-×2Ñ2Ó4€fØ"(€gŒf×ÑÒñ =r   N)r-   r.   r/   r0   r   r9   r<   r1   r   r   r3   r3   `   s   „ Ù/ò*ò
	?ó)r   r3   N)
r0   Ú
__future__r   r   r   Ú&googlecloudsdk.command_lib.help_searchr   Úobjectr   r3   r1   r   r   Ú<module>r@      s1   ðñ  <å &Ý Ý 'å 9ôD6ô DôN)fõ )r   