
    $HJjQ@                        d Z ddlZddlZddlZddlZddlZddlZddlZddlm	Z	 ddl
Z
ddlmZmZmZmZ ddlmZ ddlmZmZ erddlmZ g d	Zeeeej4                  f   Zi d
dddddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+i d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZZd[j;                         Zdtd\ed]ed^e e!ef   fd_Z"d`e!d^ee!   fdaZ#dbede!e$f   d^ede!e$f   fdcZ%dd Z&e
jN                   G de df             Z(dge e!ef   d^e fdhZ)die!d^ee!   fdjZ*dudkdldmed^e!fdnZ+dudoZ,dvdpZ-dq Z.dr Z/ds Z0y)wz0
Helpers to model CSVW metadata as dataclasses.
    N)	Generator)AnyOptionalUnionTYPE_CHECKING)tags   )is_urlslug)
TableGroup)valid_common_propertyvalid_id_propertyvalid_context_propertyDescriptionBasedataclass_asdict
NAMESPACESdialect_propscsvwzhttp://www.w3.org/ns/csvw#rdfz+http://www.w3.org/1999/02/22-rdf-syntax-ns#rdfsz%http://www.w3.org/2000/01/rdf-schema#xsdz!http://www.w3.org/2001/XMLSchema#dczhttp://purl.org/dc/terms/dcatzhttp://www.w3.org/ns/dcat#provzhttp://www.w3.org/ns/prov#schemazhttp://schema.org/asz&https://www.w3.org/ns/activitystreams#cczhttp://creativecommons.org/ns#ctagzhttp://commontag.org/ns#dc11z http://purl.org/dc/elements/1.1/dctypeszhttp://purl.org/dc/dcmitype/dqvzhttp://www.w3.org/ns/dqv#duvzhttps://www.w3.org/ns/duv#foafzhttp://xmlns.com/foaf/0.1/grz!http://purl.org/goodrelations/v1#grddlz#http://www.w3.org/2003/g/data-view#icalz&http://www.w3.org/2002/12/cal/icaltzd#jsonldzhttp://www.w3.org/ns/json-ld#ldpzhttp://www.w3.org/ns/ldp#mazhttp://www.w3.org/ns/ma-ont#oazhttp://www.w3.org/ns/oa#odrlzhttp://www.w3.org/ns/odrl/2/ogzhttp://ogp.me/ns#orgzhttp://www.w3.org/ns/org#owlzhttp://www.w3.org/2002/07/owl#qbz!http://purl.org/linked-data/cube#rdfazhttp://www.w3.org/ns/rdfa#revzhttp://purl.org/stuff/rev#rifzhttp://www.w3.org/2007/rif#rrzhttp://www.w3.org/ns/r2rml#sdz0http://www.w3.org/ns/sparql-service-description#sioczhttp://rdfs.org/sioc/ns#z$http://www.w3.org/2004/02/skos/core#z"http://www.w3.org/2008/05/skos-xl#zhttp://www.w3.org/ns/sosa/zhttp://www.w3.org/ns/ssn/zhttp://www.w3.org/2006/time#z http://rdf.data-vocabulary.org/#z http://www.w3.org/2006/vcard/ns#zhttp://rdfs.org/ns/void#z!http://www.w3.org/2007/05/powder#z#http://www.w3.org/2007/05/powder-s#z#http://www.w3.org/1999/xhtml/vocab#z$http://www.w3.org/XML/1998/namespace)skosskosxlsosassntimevvcardvoidwdrwrdsxhvxmla  Cell
Column
Datatype
Dialect
Direction
ForeignKey
JSON
NumericFormat
Row
Schema
Table
TableGroup
TableReference
Transformation
aboutUrl
base
columnReference
columns
commentPrefix
datatype
decimalChar
default
delimiter
describes
dialect
doubleQuote
encoding
foreignKeys
format
groupChar
header
headerRowCount
json
lang
length
lineTerminators
maxExclusive
maxInclusive
maxLength
maximum
minExclusive
minInclusive
minLength
minimum
name
notes
null
ordered
pattern
primaryKey
propertyUrl
quoteChar
reference
referencedRows
required
resource
row
rowTitles
rownum
schemaReference
scriptFormat
separator
skipBlankRows
skipColumns
skipInitialSpace
skipRows
source
suppressOutput
tableDirection
tableSchema
tables
targetFormat
textDirection
titles
transformations
trim
uriTemplate
url
valueUrl
virtualomit_defaultsomit_privatereturnc                    t        j                         }t        j                  |       D ]  }t	        |j
                        r|j                         n|j                  }|r|j                  j                  d      rRt        | |j                        }|r||k(  rpt        |d      r|j                  d      }|||j                  <    |S )z5Enhanced conversion of dataclass instances to a dict._asdictTrB   )collectionsOrderedDictdataclassesfieldscallabledefault_factorydefaultname
startswithgetattrhasattrrG   )objrB   rC   resfieldrO   values          ]/Users/ahmed/devFolder/claude-voice/.venv/lib/python3.12/site-packages/csvw/metadata_utils.pyr   r      s    

!
!
#C##C(-5e6K6K-L%'')RWR_R_!6!6s!;C,E!ew&65(+!LLtL<E"'EJJ ) J    r;   c                     t        | t              st        j                  d       y| j	                  d      rt        d|        | S )zValidator for the @id property.zInconsistent link propertyNrF   zInvalid @id property: )
isinstancestrwarningswarnrQ   
ValueError)r;   s    rX   r   r      s@    a23||C1!566HrY   ctxc                    t         d   j                  dd      }| | S t        | t              r	| |k(  sJ | S t        | t              sJ |        | D ]  }t        t        |t              xr+ t        |j                               j                  ddh       t        |t              xr ||k7  f      rt        d| d      t        |t              sd|v st        j                  |d         rt        j                  d       |d=  | S )	z|
    Make sure the requirements for @context objects in CSVW are met.
    If not, warn or raise exceptions accordingly.
    r   # z@base	@languagez}The @context MUST have one of the following values: An array composed of a string followed by an object, where the string is z| and the object represents a local context definition, which is restricted to contain either or both of @base and @language.z$Invalid value for @language property)r   replacer[   r\   listanydictsetkeysissubsetr_   r   checkr]   r^   )r`   nsurlrT   s      rX   r   r      s   
 v&&sB/E
{
#se||
c4 %#% 
3%^c#((*o.F.FQ\G].^*^3$57 8EEJG L9:; ;
 c4 [C%7

3{K[@\MM@AK   JrY   c                 z   t        | t        t        f      s| S t        | t              r| D cg c]  }t        |       c}S | D ch c]  }|j	                  d      s|dd  c}j                  h d      st        d      d| v rut        t        |       dkD  t        | j                               ddhdd	hfvt        | d   t        t        t        t        t        j                   f       f      rt        d
      d| v rd| vrt        d      d| v rt#        | d         | d<   d| v rCt        | d   t              rt%        j&                  | d         st)        j*                  d       | d= d	| v r| d	   t        t              rZj	                  d      rt        d      t        t-              t        fdt.        D              t0        v f      s,t        d      t        t        t        f      st        d      | j3                         D ci c]  \  }}|t        |       c}}S c c}w c c}w c c}}w )z*Validator for values of common properties.@r	   N>   idtyperW   languagezeAside from @value, @type, @language, and @id, the properties used on an object MUST NOT start with @.z@value   rd   @typea  If a @value property is used on an object, that object MUST NOT have any other properties aside from either @type or @language, and MUST NOT have both @type and @language as properties. The value of the @value property MUST be a string, number, or boolean value.zXA @language property MUST NOT be used on an object unless it also has a @value property.@idzInvalid language tagz_:z\The value of any @id or @type contained within a metadata document MUST NOT be a blank node.c              3   T   K   | ]  }|k(  xs j                  |d z          ! yw):N)rQ   ).0nsvvs     rX   	<genexpr>z(valid_common_property.<locals>.<genexpr>   s+     M*BB"H7b3h 77*s   %(zThe value of any member of @type MUST be either a term defined in [csvw-context], a prefixed name where the prefix is a term defined in [csvw-context], or an absolute URL.zInvalid datatype for @type)r[   rh   rf   r   rQ   rk   r_   rg   lenri   rj   r\   boolintfloatdecimalDecimalr   r   rl   r]   r^   r
   r   
CSVW_TERMSitems)r;   rz   ks    ` rX   r   r      s7   a$&!T456Ab%b)A6621aS 1AabE12;;<_`%& 	& 1}FQJM8["9Hg;N!OO1X;dC(PQQ
 
 ,- -
 aHA- 	 z$QuX.%a1[>3/DJJq~4NMM01+!|wZb#}}T" 01 1 r
M*MMj  
 !:; ; Bt-9::67ggi@iUQA$R((i@@[ 72V As   H-H2H2H7c                   ,   e Zd ZU dZ ej
                  e      Zeee	f   e
d<    ej
                  e      Zeee	f   e
d<   e	 	 ddeee	f   dee   ded	eedf   fd
       Zedefd       Zd	eeee	f   ddf   fdZdd	ej,                  ee	f   fdZy)r   zzContainer for
    - common properties (see http://w3c.github.io/csvw/metadata/#common-properties)
    - @-properties.
    )rN   common_propsat_propsNd	type_namestrictrD   c                 
   |rt        |t              syt        j                  |       D ci c]  }|j                  | }}|xs | j
                  }i i i }}}|xs i j                         D ]  \  }	}
|	j                  d      r4|	dk(  rt        |
      }
|	dk(  r|
|k7  rt        d|
 d|       |
||	dd <   Kd|	v rt        |
      ||	<   ^|r |	|vrt        j                  d	|	 d|        |
||	<    t        d||d
|S c c}w )z_
        Partitions properties in d into `common_props`, `at_props` and the remaining.
        Nro   ru   rt   zInvalid @type property z for r	   rw   zInvalid property r   r    )r[   rh   rK   rL   rP   __name__r   rQ   r   r_   r   r]   r^   )clsr   r   r   frL   caddr   r;   s              rX   partition_propertiesz$DescriptionBase.partition_properties  s    Z4(%0%7%7%<=%<!&&!)%<=-	r2b1W"OO%DAq||C :)!,A<AN$'>qcyk%RSS!AB%,Q/!qMM$5aSi["IJBqE & 5Q5"55# >s   D c                 0     | di | j                  |      S )zInitialize instance from dict.r   )r   )r   r   s     rX   	fromvaluezDescriptionBase.fromvalue-  s     1S--a011rY   c              #   n  K   fdfd}t        | j                  j                               D ]  \  }}d|z    ||      f  t        | j                  j                               D ]  \  }}| ||      f  t	        |       j                         D ]  \  }}|dvs| ||      f  y w)Nc                 D    t        | d      r| j                        S | S )NrG   rH   )rS   rG   )r;   rB   s    rX   _asdict_singlez8DescriptionBase._iter_dict_items.<locals>._asdict_single3  s#    <CAx<P188-88WVWWrY   c                 v    t        | t        t        f      r| D cg c]
  } |       c}S  |       S c c}w N)r[   rf   tuple)r;   rz   r   s     rX   _asdict_multiplez:DescriptionBase._iter_dict_items.<locals>._asdict_multiple6  s;    !dE]+567Qrr*Q77!!$$ 8s   6ro   rH   r   )sortedr   r   r   r   )selfrB   r   r   r;   r   s    `   @rX   _iter_dict_itemsz DescriptionBase._iter_dict_items2  s     	X	%
 4==..01DAq'+A... 2 4,,2245DAq%a((( 6 %TGMMODAq44)!,,, Ps   B!B5&B5c                 X    t        j                  d | j                  |      D              S )zSerialization as dict.c              3   @   K   | ]  \  }}|d k(  s|g i fvr||f  yw)nullNr   )rx   r   r;   s      rX   r{   z)DescriptionBase.asdict.<locals>.<genexpr>K  s2      '5Ctq!V"b 1 FCs   )rI   rJ   r   )r   rB   s     rX   rG   zDescriptionBase.asdictE  s/     && '5#44]C'5 5 	5rY   )NT)T)r   
__module____qualname____doc__rK   rV   rh   r   r\   r   __annotations__r   classmethodr   r   r}   r   r   r   r   r   rI   rJ   rG   r   rY   rX   r   r     s     $5;#4#4T#JL$sCx.J0{00FHd38nF (,	6T3Y6  }6 	6
 
tTz	6 6< 2$ 2 2-5c?DRV;V1W -&5K,C,CCH,M 5rY   r   r   c                     t        | t              st        j                  d       i S t        j                  | dd      }|d= |d= |j                  d      rd|d	<   |S )
zZSlightly massage the a dialect specification into something accepted by our Dialect class.zInvalid dialect specDialectF)r   r   r   r   headerRowCountTheader)r[   rh   r]   r^   r   r   get)r   partitioneds     rX   r   r   P  sc    a,-	!66qIV[6\KJN#'( $HrY   qnamec                     t         j                         D ]0  \  }}| j                  |dz         s| j                  |dz   |      c S  y)zNTurn a qname into an http URL by replacing the prefix with the associated URL.rw   N)r   r   rQ   re   )r   prefixuris      rX   	qname2urlr   ]  sE    !'')FSL)==#s33 * rY   tgr   
link_filesc           
         | j                   }d| j                  j                  dd       dg}|r.|r,|j                  d|j                   d|j                   d       |j                  t        | j                  j                         D ci c]  \  }}|dk7  s|| c}}             | j                  D ]'  }|j                  t        t        | ||                   ) dj                  |      S c c}}w )z
    Render the metadata of a dataset as markdown.

    :param link_files: If True, links to data files will be added, assuming the markdown is stored     in the same directory as the metadata file.
    :return: `str` with markdown formatted text
    z# zdc:titleDataset
z> [!NOTE]
> Described by [](z).
)_fnamer   r   appendrP   _propertiesr   tablesextendrf   _iter_table2markdownjoin)r   r   fnamerU   r   r;   tables          rX   metadata2markdownr   e  s     IIE##J	:;2>
?C

0Buzzl$OPJJ{R__-B-B-DX-DTQZAqD-DXYZ

4,R
CDE 99S>	 Ys   C1C1c                 H    t        |       }|r|r	d| d|  dS d|  d| dS | S )Nz	<a href="z">z</a>[r   ))r   )r   htmlurls      rX   _qname2linkr   y  sA    
E
C
se2eWD115'C5""LrY   c                 v   t        | t              r dj                  fd| D              }d| dS t        | t              rng }| j	                         D ]D  \  }}|j                  dt        |d       dt        j                  t        |             d	       F d
dj                  |       dS t        |       S )z=
    For inclusion in tables we must use HTML for lists.
    rc   c              3   @   K   | ]  }d t        |       d  yw)z<li>keyz</li>N)_htmlify)rx   itemr   s     rX   r{   z_htmlify.<locals>.<genexpr>  s#     LXd45U;s   z<ol>z</ol>z<dt>T)r   z	</dt><dd>z</dd>z<dl>z</dl>)
r[   rf   r   rh   r   r   r   r   escaper\   )rT   r   lisr   r   r;   s    `    rX   r   r     s     #tggLLLcU%  #tIIKDAqLL4AD 9:)DKKPSTUPVDWCXX]^_  bggen%U++s8OrY   c           	      *   dt         t        t        f   fd}t        j                  |       j                         D ci c]  \  }}|s	|| } }}g }| j                  dd       }|r|j                  |dz          | j                  dd       }|r|j                   ||             | rS|j                  d       | j                         D ]/  \  }}|j                  t        |       dt        ||              1 dj                  |      dz   S c c}}w )	Nimgc                     t        | t              rd| i} d| j                  d      xs d d| j                  d       dS )Nzhttps://schema.org/contentUrlz![zhttps://schema.org/captionrc   r   )
)r[   r\   r   )r   s    rX   _imgz_properties.<locals>._img  sQ    c32C8CSWW9:@bA BGG;<=SB 	CrY   dc:descriptionr   zhttps://schema.org/imagezproperty | value
 --- | --- | r   )r   r\   rh   copydeepcopyr   popr   r   r   r   )propsr   r   r;   rU   descr   s          rX   r   r     s    C%T	" C #mmE288:@:daaQT:E@
C99%t,D

4$;
)).
5C


49

12KKMDAqJJ+a.)XaQ-?,@AB "99S>D   As   
D	Dc              #     K   |j                   j                  D ci c]a  }t        |j                        dk(  rG|j                  d   |j                  j                  d   |j                  j
                  j                  fc }}dt        |j                  j                         d}| j                  }|rt|rr|j                  j                  |j                  j                        j                         r5|d|j                  j                   d|j                  j                   dz  }n||j                  j                  z  }d|z   dz    t        |j                         |j                  d	      }|j!                         r)d
t#        j$                  |j!                                d d d d |j                   j&                  D ]%  }t)        |||j                   j*                         ' y c c}w w)Nr	   r   z## <a name="table-z"></a>Table r   r   r   r   dialectz
**CSV dialect**: `z`
z
### Columns
z&Name/Property | Datatype | Descriptionz --- | --- | --- )tableSchemaforeignKeysr|   columnReference	referenceresourcestringr   r   r   parentjoinpathexistsr   r   inheritrG   jsondumpscolumns_colrow
primaryKey)	r   r   r   fkfksr   r   r   cols	            rX   r   r     s     ##//Q/B3r7I7I3Ja3O 	1 < <Q ?AVAVA]A]^^/  Q "$uyy'7'7"8!9FFIIEu!6!6uyy7G7G!H!O!O!QAeii&&'r%))*:*:);3??%))"""
-$

e((
))mmI&G~~$TZZ0@%A$B#FF

22
  ((c3 1 1 < <== )#Qs   G<A&G7E;G<c           	         d| j                   r| j                   j                  nd d}| j                   r| j                   j                  rt        j                  d| j                   j                        rD|dz  }|dj                  d | j                   j                  j                  d      D              z  }n6| j                   j                  dk(  r|d| j                   j                   dz  }| j                   j                  r|d	| j                   j                   z  }| j                   j                  r|d
| j                   j                   z  }| j                  rd| d| j                   d}| j                  j                  dd      j                  dd      }|r| j                  |v r|r|dz   n|}|dz  }| j                  |v r3|r|dz   n|}|| j                     \  }}|d| d| dt        |       dz  }dj                  | j                  rd| j                   d| j                   dnd| j                   d||g      S )N`r   z[\w\s]+(\|[\w\s]+)*z<br>Valid choices:<br>rc   c              3   (   K   | ]
  }d | d  yw)z `r   Nr   )rx   ws     rX   r{   z_colrow.<locals>.<genexpr>  s     P1OA1#Qi1Os   |z<br>Regex: `z	<br>&ge; z	<br>&le; zlist of z (separated by `z`)r   r    z<br>zPrimary keyzReferences [z::z	](#table-r   r   r   r   )datatypebaseformatre	fullmatchr   splitminimummaximum	separatorr   r   re   rP   r   propertyUrl)r   r   pkdtr   cnametnames          rX   r   r     s   #,,S\\H=Q	?B
||<<||2CLL4G4GH..bggP1D1D1J1J31OPPP""h.S\\%8%8$9;;<<Icll22344B<<Icll22344B
}}t+CMM?"= 0"5==dCHD	chh"n"&vD
xx3"&vD388}u,ugRwiU}AFF::.1oo!CHH:R(*QsxxjPQ?TVX\^ _ _rY   )TT)Fr   )1r   r   r   r   r   r   r]   rI   collections.abcr   rK   typingr   r   r   r   language_tagsr   utilsr
   r   csvw.metadatar   __all__r~   r   r   
NumberTyper   r   r   r}   rh   r\   r   r   rf   r   r   	dataclassr   r   r   r   r   r   r   r   r   r   rY   rX   <module>r     sW   
       %  6 6  (Q 3w./
/
(/	8/ 3/ 
.	/
 	
%/ (/ (/ "/ 	
2/ 	
*/ &/ ./ -/ 
&/ 
'/  (!/" 	
-#/$ 2%/& 4'/( -)/* 
&+/, 	
(-/. 	
$//0 *1/2 	
3/4 
&5/6 
+7/8 	
-9/: (;/< 
'=/> 
(?/@ 	
'A/B 	
<C/D &E/F 32(&*	+/&.101]/
`O^ 57_ d D TXY\^aYaTb  # dCo 6 5sD;Q 44An G5 G5 G5T
T#s(^ 
 
S Xc] , D S (!,>,_rY   