
    h                         S r  " S S\5      rSS jr\S:X  a=  SSKrSSKr\R                  " \R                  " \R                  S9R                  5        gg)	zAfontTools.misc.classifyTools.py -- tools for classifying things.
c                   F    \ rS rSrSrSS jrS rS rS rS r	S r
S	 rS
rg)
Classifier   zD
Main Classifier object, used to classify things into similar sets.
c                 X    [        5       U l        / U l        0 U l        SU l        Xl        g )NF)set_things_sets_mapping_dirty_sort)selfsorts     N/var/www/html/env/lib/python3.13/site-packages/fontTools/misc/classifyTools.py__init__Classifier.__init__
   s%    u

    c                 *   U(       d  gSU l         U R                  U R                  U R                  pCn[	        U5      nUR                  U5      nUR                  U5        UnAU(       a/  UR                  U5        UR                  U5        U H  nXtU'   M	     AU(       as  U[        [        U5      5         n	U	R                  U5      n
U	R                  U
5        UR                  U
5        UR                  U
5        U
 H  nXU'   M	     A
U(       a  Mr  gg)z9
Add a set to the classifier.  Any iterable is accepted.
NT)r
   r   r   r	   r   intersectiondifference_updateupdateappendnextiter)r   set_of_thingsthingssetsmappingsr   
differencething	old_classold_class_intersections              r   addClassifier.add   s      $djj$--g~~f-	L)
 MM*%KK
##!+ $T,%7 89I%.%;%;L%I" ''(>? **+AB KK.//!7 0& lr   c                 8    U H  nU R                  U5        M     g)zQ
Add a a list of sets to the classifier.  Any iterable of iterables is accepted.
N)r"   )r   list_of_setsr   s      r   r   Classifier.update;   s     AHHQK r   c                     U R                   (       d  g U R                  nU Vs/ s H  o"(       d  M  UPM     snU l        U R                  (       a  [        U R                  S S9U l        SU l         g s  snf )Nc                 0    [        U 5      * [        U 5      4$ )N)lensorted)r   s    r   <lambda>%Classifier._process.<locals>.<lambda>K   s    CF7F1I:Nr   )keyF)r
   r   r   r*   )r   r   r   s      r   _processClassifier._processB   sU    {{ zz!%+Aa+
::

0NODJ ,s
   
A2A2c                 :    U R                  5         U R                  $ )zReturns the set of all things known so far.

The return value belongs to the Classifier object and should NOT
be modified while the classifier is still in use.
)r.   r   r   s    r   	getThingsClassifier.getThingsQ   s     	||r   c                 :    U R                  5         U R                  $ )zReturns the mapping from things to their class set.

The return value belongs to the Classifier object and should NOT
be modified while the classifier is still in use.
)r.   r	   r1   s    r   
getMappingClassifier.getMappingZ   s     	}}r   c                 :    U R                  5         U R                  $ )zReturns the list of class sets.

The return value belongs to the Classifier object and should NOT
be modified while the classifier is still in use.
)r.   r   r1   s    r   
getClassesClassifier.getClassesc   s     	zzr   )r
   r	   r   r   r   NT)__name__
__module____qualname____firstlineno____doc__r   r"   r   r.   r2   r5   r8   __static_attributes__ r   r   r   r      s+    ('Tr   r   c                 v    [        US9nUR                  U 5        UR                  5       UR                  5       4$ )a3  
Takes a iterable of iterables (list of sets from here on; but any
iterable works.), and returns the smallest list of sets such that
each set, is either a subset, or is disjoint from, each of the input
sets.

In other words, this function classifies all the things present in
any of the input sets, into similar classes, based on which sets
things are a member of.

If sort=True, return class sets are sorted by decreasing size and
their natural sort order within each class size.  Otherwise, class
sets are returned in the order that they were identified, which is
generally not significant.

>>> classify([]) == ([], {})
True
>>> classify([[]]) == ([], {})
True
>>> classify([[], []]) == ([], {})
True
>>> classify([[1]]) == ([{1}], {1: {1}})
True
>>> classify([[1,2]]) == ([{1, 2}], {1: {1, 2}, 2: {1, 2}})
True
>>> classify([[1],[2]]) == ([{1}, {2}], {1: {1}, 2: {2}})
True
>>> classify([[1,2],[2]]) == ([{1}, {2}], {1: {1}, 2: {2}})
True
>>> classify([[1,2],[2,4]]) == ([{1}, {2}, {4}], {1: {1}, 2: {2}, 4: {4}})
True
>>> classify([[1,2],[2,4,5]]) == (
...     [{4, 5}, {1}, {2}], {1: {1}, 2: {2}, 4: {4, 5}, 5: {4, 5}})
True
>>> classify([[1,2],[2,4,5]], sort=False) == (
...     [{1}, {4, 5}, {2}], {1: {1}, 2: {2}, 4: {4, 5}, 5: {4, 5}})
True
>>> classify([[1,2,9],[2,4,5]], sort=False) == (
...     [{1, 9}, {4, 5}, {2}], {1: {1, 9}, 2: {2}, 4: {4, 5}, 5: {4, 5},
...     9: {1, 9}})
True
>>> classify([[1,2,9,15],[2,4,5]], sort=False) == (
...     [{1, 9, 15}, {4, 5}, {2}], {1: {1, 9, 15}, 2: {2}, 4: {4, 5},
...     5: {4, 5}, 9: {1, 9, 15}, 15: {1, 9, 15}})
True
>>> classes, mapping = classify([[1,2,9,15],[2,4,5],[15,5]], sort=False)
>>> set([frozenset(c) for c in classes]) == set(
...     [frozenset(s) for s in ({1, 9}, {4}, {2}, {5}, {15})])
True
>>> mapping == {1: {1, 9}, 2: {2}, 4: {4}, 5: {5}, 9: {1, 9}, 15: {15}}
True
)r   )r   r   r8   r5   )r%   r   
classifiers      r   classifyrD   m   s:    j &Jl#  "J$9$9$;;;r   __main__    N)optionflagsr:   )r?   objectr   rD   r;   sysdoctestexittestmodELLIPSISfailedrA   r   r   <module>rO      sR   e eP7<t zHHW__)9)9:AAB r   