
    HR-e~                     T    d Z ddlZddlmZ ddgZ G d d          Zdadd	Zdd
ZdS )zG
This file contains routines to verify the correctness of UCD strings.
    N)data	parse_ucd	check_ucdc                   0    e Zd ZdZd Zd Zd Zd Zd ZdS )UCDWordsz
    Manages a list of acceptable UCD words.

    Works by reading in a data file exactly as provided by IVOA.  This
    file resides in data/ucd1p-words.txt.
    c                 6   t                      | _        t                      | _        i | _        i | _        t          j        dd          5 }|                                D ]}|                    d          rd |	                    d          D             \  }}}|
                                }|dv r| j                            |           |dv r| j                            |           || j        |<   || j        |<   	 d d d            d S # 1 swxY w Y   d S )	Nzdata/ucd1p-words.txtascii)encoding#c              3   >   K   | ]}|                                 V  d S )N)strip).0xs     6lib/python3.11/site-packages/astropy/io/votable/ucd.py	<genexpr>z$UCDWords.__init__.<locals>.<genexpr>#   s*      $H$H1QWWYY$H$H$H$H$H$H    |QPEVCQSEVC)set_primary
_secondary_descriptions_capitalizationr   get_pkg_data_fileobj	readlines
startswithsplitloweradd)selffdlinetypenamedescr
name_lowers          r   __init__zUCDWords.__init__   s`   %%!&'=PPP 	8TV 8 8??3'' $H$H

3$H$H$H!dE!ZZ\\
7??M%%j1117??O''
33316":.37$Z008	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8s   B5DDDc                 8    |                                 | j        v S )zA
        Returns True if *name* is a valid primary name.
        )r   r   r!   r%   s     r   
is_primaryzUCDWords.is_primary,   s     zz||t},,r   c                 8    |                                 | j        v S )zC
        Returns True if *name* is a valid secondary name.
        )r   r   r*   s     r   is_secondaryzUCDWords.is_secondary2   s     zz||t..r   c                 @    | j         |                                         S )z[
        Returns the official English description of the given UCD
        *name*.
        )r   r   r*   s     r   get_descriptionzUCDWords.get_description8   s    
 !$**,,//r   c                 @    | j         |                                         S )zM
        Returns the standard capitalization form of the given name.
        )r   r   r*   s     r   normalize_capitalizationz!UCDWords.normalize_capitalization?   s     #DJJLL11r   N)	__name__
__module____qualname____doc__r(   r+   r-   r/   r1    r   r   r   r      si         8 8 8(- - -/ / /0 0 02 2 2 2 2r   r   Fc                    t           t                      a |rt          j        d|           }nt          j        d|           }|)t	          d|                    d           d|  d          d}| d	| d
}|                     d          }g }t          |          D ]\  }}	|	                    d          }
|
dk    rV|	                    dd          \  }}	t          j	        ||          st	          d| d          |
                                }n|
dk    rt	          d|	 d          d}t          j	        ||	          st	          d|	 d          |dk    r|r|dk    r[t                               |	          s@t                               |	          rt	          d|	 d          t	          d|	 d          nZt                               |	          s@t                               |	          rt	          d|	 d          t	          d|	 d          	 t                               |	          }n# t          $ r |	}Y nw xY w|                    ||f           |S )a6  
    Parse the UCD into its component parts.

    Parameters
    ----------
    ucd : str
        The UCD string

    check_controlled_vocabulary : bool, optional
        If `True`, then each word in the UCD will be verified against
        the UCD1+ controlled vocabulary, (as required by the VOTable
        specification version 1.2), otherwise not.

    has_colon : bool, optional
        If `True`, the UCD may contain a colon (as defined in earlier
        versions of the standard).

    Returns
    -------
    parts : list
        The result is a list of tuples of the form:

            (*namespace*, *word*)

        If no namespace was explicitly specified, *namespace* will be
        returned as ``'ivoa'`` (i.e., the default namespace).

    Raises
    ------
    ValueError
        if *ucd* is invalid
    Nz[^A-Za-z0-9_.:;\-]z[^A-Za-z0-9_.;\-]zUCD has invalid character 'r   z' in ''z[A-Za-z0-9][A-Za-z0-9\-_]*z(\.z)*;:   zInvalid namespace 'zToo many colons in 'ivoazInvalid word 'zSecondary word 'z ' is not valid as a primary wordzUnknown word 'zPrimary word 'z"' is not valid as a secondary word)_ucd_singletonr   research
ValueErrorgroupr   	enumeratecountmatchr   r+   r-   r1   KeyErrorappend)ucdcheck_controlled_vocabulary	has_colonmword_component_reword_repartswordsiwordcolon_countnsnormalized_words                r   r   r   I   s   D ! 1I+S11I*C00}OqwwqzzOOOOOPPP5#==(9===GIIcNNEEU## %, %,4jjoo!zz#q))HB8-r22 > !<r!<!<!<===BB1__;D;;;<<<Bx&& 	75d555666<<7<Avv%0066 C%22488 C(UtUUU   ))A$)A)A)ABBBC &22488 C%0066 C(UTUUU   ))A$)A)A)ABBB	#,EEdKKOO 	# 	# 	#"OOO	#b/*++++Ls   H77IIc                 X    | dS 	 t          | ||           n# t          $ r Y dS w xY wdS )a5  
    Returns False if *ucd* is not a valid `unified content descriptor`_.

    Parameters
    ----------
    ucd : str
        The UCD string

    check_controlled_vocabulary : bool, optional
        If `True`, then each word in the UCD will be verified against
        the UCD1+ controlled vocabulary, (as required by the VOTable
        specification version 1.2), otherwise not.

    has_colon : bool, optional
        If `True`, the UCD may contain a colon (as defined in earlier
        versions of the standard).

    Returns
    -------
    valid : bool
    NT)rH   rI   F)r   r@   )rG   rH   rI   s      r   r   r      sa    , {t(C	
 	
 	
 	
 	

    uu4s    
'')FF)	r5   r>   astropy.utilsr   __all__r   r=   r   r   r6   r   r   <module>rW      s     
			      
$32 32 32 32 32 32 32 32l X X X Xv! ! ! ! ! !r   