+
    0j"	                     2    R t ^ RIt^ RIHt  ! R R4      tR# )zSimple filter ranker.NFinalc                      a  ] tR t^t o Rt]P                  ! R4      tRV 3R lR lltV 3R lR lt	V 3R lR lt
V 3R	 lR
 ltV 3R ltRtV tR# )SimpleFilterRankera!  Simple filter ranker.

1) Pull any doc with 'wikipedia.org' in its href to the top.
2) Bucket the rest according to where query tokens appear:
   - both title & body/description
   - title only
   - body only
   - neither
3) Return wikipedia-top + both + title-only + body-only + neither.
z\W+c                $   < V ^8  d   QhRS[ RR/# )   min_token_lengthreturnN)int)format__classdict__s   "d/Users/mitch_tango/dev/rabbit-r1-livekit/agent/.venv/lib/python3.14/site-packages/ddgs/similarity.py__annotate__SimpleFilterRanker.__annotate__   s     1 1 1T 1    c                    Wn         R # Nr   )selfr   s   &&r   __init__SimpleFilterRanker.__init__   s     0r   c                6   < V ^8  d   QhRS[ RS[S[ ,          /# )r   queryr	   )strset)r   r   s   "r   r   r      s#     o oS oSX or   c                    V P                   P                  VP                  4       4       Uu0 uF!  p\        V4      V P                  8  g   K  VkK#  	  up# u upi )z7Split on non-word characters & filter out short tokens.)	_splittersplitlowerlenr   )r   r   tokens   && r   _extract_tokens"SimpleFilterRanker._extract_tokens   sE    #'>>#7#7#Fn#F%#e*X\XmXmJm#Fnnns   AAc                <   < V ^8  d   QhRS[ RS[S[ ,          RS[/# )r   texttokensr	   )r   r   bool)r   r   s   "r   r   r      s&     8 83 8C 8T 8r   c                   a VP                  4       o\        ;QJ d    V3R lV 4       F  '       g   K   R# 	  R# ! V3R lV 4       4      # )z:Check if any token is a substring of the lower-cased text.c              3   ,   <"   T F	  qS9   x  K  	  R # 5ir    ).0tok
lower_texts   & r   	<genexpr>4SimpleFilterRanker._has_any_token.<locals>.<genexpr>   s     7*$   TF)r   any)r   r$   r%   r,   s   &&&@r   _has_any_token!SimpleFilterRanker._has_any_token   s7    ZZ\
s77ss7s7s7777r   c          	      x   < V ^8  d   QhRS[ S[S[S[3,          ,          RS[RS[ S[S[S[3,          ,          /# )r   docsr   r	   )listdictr   )r   r   s   "r   r   r   !   sA     'C 'Cd38n- 'Cc 'Cd4S>>R 'Cr   c                  a V P                  V4      p. p. p. p. p. pV EF5  p	V	P                  RR4      p
V	P                  RR4      oV	P                  RV	P                  RR4      4      p\        ;QJ d    V3R lR
 4       F  '       d   K   RM	  RM! V3R lR
 4       4      '       d   K  R	V
9   d   VP                  V	4       K  V P	                  SV4      pV P	                  W4      pV'       d   V'       d   VP                  V	4       K  V'       d   VP                  V	4       EK  V'       d   VP                  V	4       EK$  VP                  V	4       EK8  	  WE,           V,           V,           V,           # )z,Rank a list of docs based on a query string.href titlebodydescriptionc              3   ,   <"   T F	  qS9   x  K  	  R # 5ir   r)   )r*   xr:   s   & r   r-   *SimpleFilterRanker.rank.<locals>.<genexpr>2   s     B'A!:'Ar/   FTzwikipedia.org)z	Category:	Wikimedia)r!   getallappendr1   )r   r4   r   r%   	wiki_hitsboth
title_only	body_onlyneitherdocr8   r;   	hit_titlehit_bodyr:   s   &&&           @r   rankSimpleFilterRanker.rank!   s1   %%e,	
	C7762&DGGGR(E776377="#=>D sB'ABsssB'ABBB $&  % ++E6:I**48HXC !!#&  %s#5 : *,y87BBr   c                &   < V ^8  d   Qh/ S[ ;R&   # )r   r   r   )r   r   s   "r   r   r      s      ) r   r   N)   )__name__
__module____qualname____firstlineno____doc__recompiler   r   r!   r1   rL   __annotate_func____static_attributes____classdictcell__)r   s   @r   r   r      sM     	 zz&)I1 1o o8 8
'C 'C5  r   r   )rT   rU   typingr   r   r)   r   r   <module>r[      s     	 AC ACr   