
    /h$                     &    S SK JrJr   " S S\S9rg)    )ABCMetaabstractmethodc                       \ rS rSrSrSrSrSS jrS r\	S 5       r
S r\	SS	 j5       rS
 rS rS rS rS rS rS rS r\\S 5       5       rSrg)Feature   a  
An abstract base class for Features. A Feature is a combination of
a specific property-computing method and a list of relative positions
to apply that method to.

The property-computing method, M{extract_property(tokens, index)},
must be implemented by every subclass. It extracts or computes a specific
property for the token at the current index. Typical extract_property()
methods return features such as the token text or tag; but more involved
methods may consider the entire sequence M{tokens} and
for instance compute the length of the sentence the token belongs to.

In addition, the subclass may have a PROPERTY_NAME, which is how
it will be printed (in Rules and Templates, etc). If not given, defaults
to the classname.

znltk.tbl.FeatureNc           
         SU l         Uc4  [        [        U Vs1 s H  n[        U5      iM     sn5      5      U l         O( X:  a  [        e[        [        XS-   5      5      U l         U R                  R                  =(       d    U R                  R                  U l	        gs  snf ! [         a   n[        SR                  X5      5      UeSnAff = f)a|  
Construct a Feature which may apply at C{positions}.

>>> # For instance, importing some concrete subclasses (Feature is abstract)
>>> from nltk.tag.brill import Word, Pos

>>> # Feature Word, applying at one of [-2, -1]
>>> Word([-2,-1])
Word([-2, -1])

>>> # Positions need not be contiguous
>>> Word([-2,-1, 1])
Word([-2, -1, 1])

>>> # Contiguous ranges can alternatively be specified giving the
>>> # two endpoints (inclusive)
>>> Pos(-3, -1)
Pos([-3, -2, -1])

>>> # In two-arg form, start <= end is enforced
>>> Pos(2, 1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "nltk/tbl/template.py", line 306, in __init__
    raise TypeError
ValueError: illegal interval specification: (start=2, end=1)

:type positions: list of int
:param positions: the positions at which this features should apply
:raises ValueError: illegal position specifications

An alternative calling convention, for contiguous positions only,
is Feature(start, end):

:type start: int
:param start: start of range where this feature should apply
:type end: int
:param end: end of range (NOTE: inclusive!) where this feature should apply
N   z2illegal interval specification: (start={}, end={}))	positionstuplesortedint	TypeErrorrange
ValueErrorformat	__class__PROPERTY_NAME__name__)selfr
   endies        H/var/www/auris/envauris/lib/python3.13/site-packages/nltk/tbl/feature.py__init__Feature.__init__#   s    P ;"69*E9a3q69*E#FGDN
?#O!&uYa'@!A "^^99TT^^=T=T +F   HOO! 	s   B  'B% %
C/C

Cc                     U R                   $ N)r
   r   s    r   encode_json_objFeature.encode_json_obj^   s    ~~    c                     UnU " U5      $ r    )clsobjr
   s      r   decode_json_objFeature.decode_json_obja   s    	9~r!   c                 b    U R                   R                   S[        U R                  5      < S3$ )N())r   r   listr
   r   s    r   __repr__Feature.__repr__f   s*    ..))*!D,@+C1EEr!   c                    ^ [        S U 5       5      (       d  [        SU 35      eU4S jU 5       nU Vs/ s H  oS(       a  SU;   a  M  U " U5      PM     sn$ s  snf )a  
Return a list of features, one for each start point in starts
and for each window length in winlen. If excludezero is True,
no Features containing 0 in its positions will be generated
(many tbl trainers have a special representation for the
target feature at [0])

For instance, importing a concrete subclass (Feature is abstract)

>>> from nltk.tag.brill import Word

First argument gives the possible start positions, second the
possible window lengths

>>> Word.expand([-3,-2,-1], [1])
[Word([-3]), Word([-2]), Word([-1])]

>>> Word.expand([-2,-1], [1])
[Word([-2]), Word([-1])]

>>> Word.expand([-3,-2,-1], [1,2])
[Word([-3]), Word([-2]), Word([-1]), Word([-3, -2]), Word([-2, -1])]

>>> Word.expand([-2,-1], [1])
[Word([-2]), Word([-1])]

A third optional argument excludes all Features whose positions contain zero

>>> Word.expand([-2,-1,0], [1,2], excludezero=False)
[Word([-2]), Word([-1]), Word([0]), Word([-2, -1]), Word([-1, 0])]

>>> Word.expand([-2,-1,0], [1,2], excludezero=True)
[Word([-2]), Word([-1]), Word([-2, -1])]

All window lengths must be positive

>>> Word.expand([-2,-1], [0])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "nltk/tag/tbl/template.py", line 371, in expand
    :param starts: where to start looking for Feature
ValueError: non-positive window length in [0]

:param starts: where to start looking for Feature
:type starts: list of ints
:param winlens: window lengths where to look for Feature
:type starts: list of ints
:param excludezero: do not output any Feature with 0 in any of its positions.
:type excludezero: bool
:returns: list of Features
:raises ValueError: for non-positive window lengths
c              3   *   #    U  H	  oS :  v   M     g7f)r   Nr#   ).0xs     r   	<genexpr>!Feature.expand.<locals>.<genexpr>   s     *'Qq5's   znon-positive window length in c              3   v   >#    U  H.  n[        [        T5      U-
  S -   5        H  nTX"U-    v   M     M0     g7f)r	   N)r   len)r0   wr   startss      r   r2   r3      s7     UA%FaRS@S:TQfQQ:Ts   69r   )allr   )r$   r7   winlensexcludezeroxsr1   s    `    r   expandFeature.expandi   sZ    l *'***=gYGHHUU "C1;16ACCCs   AAc                     U R                   UR                   L =(       a+    [        U R                  5      [        UR                  5      :  $ )a  
Return True if this Feature always returns True when other does

More precisely, return True if this feature refers to the same property as other;
and this Feature looks at all positions that other does (and possibly
other positions in addition).

#For instance, importing a concrete subclass (Feature is abstract)
>>> from nltk.tag.brill import Word, Pos

>>> Word([-3,-2,-1]).issuperset(Word([-3,-2]))
True

>>> Word([-3,-2,-1]).issuperset(Word([-3,-2, 0]))
False

#Feature subclasses must agree
>>> Word([-3,-2,-1]).issuperset(Pos([-3,-2]))
False

:param other: feature with which to compare
:type other: (subclass of) Feature
:return: True if this feature is superset, otherwise False
:rtype: bool


)r   setr
   r   others     r   
issupersetFeature.issuperset   s=    8 ~~0 
S5HCOOM
 6
 	
r!   c                     [        U R                  UR                  L =(       a+    [        U R                  5      [        UR                  5      -  5      $ )a  
Return True if the positions of this Feature intersects with those of other

More precisely, return True if this feature refers to the same property as other;
and there is some overlap in the positions they look at.

#For instance, importing a concrete subclass (Feature is abstract)
>>> from nltk.tag.brill import Word, Pos

>>> Word([-3,-2,-1]).intersects(Word([-3,-2]))
True

>>> Word([-3,-2,-1]).intersects(Word([-3,-2, 0]))
True

>>> Word([-3,-2,-1]).intersects(Word([0]))
False

#Feature subclasses must agree
>>> Word([-3,-2,-1]).intersects(Pos([-3,-2]))
False

:param other: feature with which to compare
:type other: (subclass of) Feature
:return: True if feature classes agree and there is some overlap in the positions they look at
:rtype: bool
)boolr   r?   r
   r@   s     r   
intersectsFeature.intersects   s@    : NNeoo- ;DNN#c%//&::
 	
r!   c                 r    U R                   UR                   L =(       a    U R                  UR                  :H  $ r   )r   r
   r@   s     r   __eq__Feature.__eq__   s'    ~~0VT^^u5VVr!   c                     U R                   R                  UR                   R                  :  =(       d    U R                  UR                  :  $ r   )r   r   r
   r@   s     r   __lt__Feature.__lt__   s:    NN##eoo&>&>> - NNU__,		
r!   c                     X:X  + $ r   r#   r@   s     r   __ne__Feature.__ne__   s    ""r!   c                 
    X:  $ r   r#   r@   s     r   __gt__Feature.__gt__   s
    |r!   c                     X:  + $ r   r#   r@   s     r   __ge__Feature.__ge__   s    r!   c                      X:  =(       d    X:H  $ r   r#   r@   s     r   __le__Feature.__le__   s    |,t},r!   c                     g)a   
Any subclass of Feature must define static method extract_property(tokens, index)

:param tokens: the sequence of tokens
:type tokens: list of tokens
:param index: the current index
:type index: int
:return: feature value
:rtype: any (but usually scalar)
Nr#   )tokensindexs     r   extract_propertyFeature.extract_property   s    r!   )r   r
   r   )F)r   
__module____qualname____firstlineno____doc__json_tagr   r   r   classmethodr&   r,   r<   rB   rF   rI   rL   rO   rR   rU   rX   staticmethodr   r]   __static_attributes__r#   r!   r   r   r      s    $ "HM9Uv  F 8D 8Dt
@ 
HW
# - 
  
r!   r   )	metaclassN)abcr   r   r   r#   r!   r   <module>ri      s    (~ ~r!   