)EjdZGddeZd dZedkr3ddlZddlZejejej j dSdS) zB fontTools.misc.classifyTools.py -- tools for classifying things. c>eZdZdZd dZdZdZdZdZdZ d Z d S) ClassifierzL Main Classifier object, used to classify things into similar sets. Tcdt|_g|_i|_d|_||_dS)NF)set_things_sets_mapping_dirty_sort)selfsorts NC:\PYTHON\MyICR_Suite\python\Lib\site-packages\fontTools/misc/classifyTools.py__init__zClassifier.__init__ s-uu     c:|sdSd|_|j|j|j}}}t |}||}|||}~|r4|||||D]}|||<~|r|tt|} | |} | | || || | D]}| ||<~ |dSdS)zI Add a set to the classifier. Any iterable is accepted. NT) r rrrr intersectiondifference_updateupdateappendnextiter) r set_of_thingsthingssetsmappingsr differencething old_classold_class_intersections r addzClassifier.addsd  F $ dj$-g   ~~f--  L)))   , MM* % % % KK # # ## , ,!+  'T,%7%7 8 89I%.%;%;L%I%I "  ' '(> ? ? ?  * *+A B B B KK. / / // 8 8!7& ' ' ' ' 'rc:|D]}||dS)za Add a a list of sets to the classifier. Any iterable of iterables is accepted. N)r )r list_of_setsrs r rzClassifier.update;s.  A HHQKKKK  rc|jsdS|j}d|D|_|jrt|jd|_d|_dS)Ncg|]}||Sr%).0rs r z'Classifier._process..Hs+++A+a+++rc@t| t|fS)N)lensorted)rs r z%Classifier._process..KsCFF7F1II:Nr)keyF)r rr r*)r rs r _processzClassifier._processBs_{  Fz+++++ : P 0N0NOOODJ rc8||jS)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-rr s r getThingszClassifier.getThingsQs |rc8||jS)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-rr/s r getMappingzClassifier.getMappingZs }rc8||jS)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-rr/s r getClasseszClassifier.getClassescs zrNT) __name__ __module__ __qualname____doc__rr rr-r0r2r4r%rr rrs('('('T   rrTct|}||||fS)a 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 )rrr4r2)r"r classifiers r classifyr<msLj&&&Jl###  " "J$9$9$;$; ;;r__main__N) optionflagsr5) r9objectrr<r6sysdoctestexittestmodELLIPSISfailedr%rr rGseeeeeeeeP7<7<7<7