a
    èÝEbL  ã                   @   sP   d Z G dd„ deƒZd
dd„ZedkrLddlZddlZe ejej	d	�j
¡ dS )zB fontTools.misc.classifyTools.py -- tools for classifying things.
c                   @   sJ   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dS )Ú
ClassifierzF
	Main Classifier object, used to classify things into similar sets.
	Tc                 C   s$   t ƒ | _g | _i | _d| _|| _d S )NF)ÚsetÚ_thingsÚ_setsÚ_mappingÚ_dirtyÚ_sort)ÚselfÚsort© r
   ú\/home/ja/django-apps/lartica_env/lib/python3.9/site-packages/fontTools/misc/classifyTools.pyÚ__init__   s
    zClassifier.__init__c                 C   sÈ   |sdS d| _ | j| j| j  }}}t|ƒ}| |¡}| |¡ |}~|rp| |¡ | |¡ |D ]}|||< qb~|rÄ|t	t
|ƒƒ }	|	 |¡}
|	 |
¡ | |
¡ | |
¡ |
D ]}|
||< q²~
qrdS )z=
		Add a set to the classifier.  Any iterable is accepted.
		NT)r   r   r   r   r   ÚintersectionÚdifference_updateÚupdateÚappendÚnextÚiter)r   Zset_of_thingsZthingsÚsetsÚmappingÚsr   Ú
differenceÚthingZ	old_classZold_class_intersectionr
   r
   r   Úadd   s0    









zClassifier.addc                 C   s   |D ]}|   |¡ qdS )zU
		Add a a list of sets to the classifier.  Any iterable of iterables is accepted.
		N)r   )r   Úlist_of_setsr   r
   r
   r   r   =   s    zClassifier.updatec                 C   sD   | j s
d S | j}dd„ |D ƒ| _| jr:t| jdd„ d�| _d| _ d S )Nc                 S   s   g | ]}|r|‘qS r
   r
   )Ú.0r   r
   r
   r   Ú
<listcomp>J   ó    z'Classifier._process.<locals>.<listcomp>c                 S   s   t | ƒ t| ƒfS )N)ÚlenÚsorted)r   r
   r
   r   Ú<lambda>M   r   z%Classifier._process.<locals>.<lambda>)ÚkeyF)r   r   r   r   )r   r   r
   r
   r   Ú_processD   s    zClassifier._processc                 C   s   |   ¡  | jS )z¦Returns 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   r
   r
   r   Ú	getThingsS   s    zClassifier.getThingsc                 C   s   |   ¡  | jS )z®Returns 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   r"   r
   r
   r   Ú
getMapping\   s    zClassifier.getMappingc                 C   s   |   ¡  | jS )zšReturns 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   r"   r
   r
   r   Ú
getClassese   s    zClassifier.getClassesN)T)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r!   r#   r$   r%   r
   r
   r
   r   r      s   
*		r   Tc                 C   s$   t |d�}| | ¡ | ¡ | ¡ fS )ac  
	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   r%   r$   )r   r	   Ú
classifierr
   r
   r   Úclassifyo   s    5

r+   Ú__main__é    N)Zoptionflags)T)r)   Úobjectr   r+   r&   ÚsysÚdoctestÚexitÚtestmodÚELLIPSISÚfailedr
   r
   r
   r   Ú<module>   s
   j
: