3
d              *   @   s   d Z ddlmZ ddlZddlZddlZddlZddlmZm	Z	m
Z
 dd d9D Zd0Zd1Zd1Zi fd2d3Zd4d5 Zd6d7 Zed8kre  dS ):z
A commandline tool for drawing RDFS Class diagrams in Graphviz DOT
format

You can draw the graph of an RDFS file directly:

.. code-block: bash

   rdf2dot my_rdfs_file.rdf | dot -Tpng | display
    )absolute_importN)XSDRDFRDFSc             C   s   g | ]}t | qS  )r   ).0xr   r   7/tmp/pip-build-7vycvbft/rdflib/rdflib/tools/rdfs2dot.py
<listcomp>   s    r
   anyURIbase64BinarybooleanbytedatedateTimedecimaldoubledurationfloatgDaygMonth	gMonthDaygYear
gYearMonth	hexBinaryIDIDREFIDREFSintintegerlanguagelongNameNCNamenegativeIntegerNMTOKENNMTOKENSnonNegativeIntegernonPositiveIntegernormalizedStringpositiveIntegerQNameshortstringtimetokenunsignedByteunsignedIntunsignedLongunsignedShortZblueZblackc          
      s  t jt}i   fdd}dd }|jd x | jtjtjD ]}||}q>W x<| j	tj
D ],\}}||}||}|jd||tf  q\W x| jtjtjD ]}xtj| j|tj| j|tjD ]v\}	}
|
tks|
tjkr||
| }|
tjkrd}|||	 j||| |f q|jd||	||
t||| f  qW qW xd j D ]X\}}|jd	||f  d
d t|| D }d}|j||t||| dj|f  qLW |jd dS )zT
    Convert the RDFS schema in a graph
    writes the dot output to the stream
    c                s    |  krdt    | <  |  S )Nznode%d)len)r   )nodesr   r	   node/   s    zrdfs2dot.<locals>.nodec          	   S   s<   |j | tj}|d kr8y|jj| d }W n   Y nX |S )N   )valuer   labelZnamespace_managerZcompute_qname)r   glr   r   r	   r9   5   s    zrdfs2dot.<locals>.labelz/digraph { 
 node [ fontname="DejaVu Sans" ] ; 
z	%s -> %s [ color=%s ] ;
literalz$	%s -> %s [ color=%s, label="%s" ];
z# %s %s
c             S   s   g | ]}d | qS )z,<tr><td align='left'>%s</td><td>%s</td></tr>r   )r   r   r   r   r	   r
   Y   s   zrdfs2dot.<locals>.<listcomp>z8%s [ shape=none, color=%s label=< <table color='#666666'z/ cellborder="0" cellspacing='0' border="1"><tr>z-<td colspan="2" bgcolor='grey'><B>%s</B></td>z</tr>%s</table> > ] 
 z}
Nzg%s [ shape=none, color=%s label=< <table color='#666666' cellborder="0" cellspacing='0' border="1"><tr>z%s [ shape=none, color=%s label=< <table color='#666666' cellborder="0" cellspacing='0' border="1"><tr><td colspan="2" bgcolor='grey'><B>%s</B></td>z%s [ shape=none, color=%s label=< <table color='#666666' cellborder="0" cellspacing='0' border="1"><tr><td colspan="2" bgcolor='grey'><B>%s</B></td></tr>%s</table> > ] 
)collectionsdefaultdictsetwriteZsubjectsr   typer   ZClassZsubject_objectsZ
subClassOfISACOLORZProperty	itertoolsproductobjectsdomainrangeXSDTERMSLiteraladd	EDGECOLORitemssorted	NODECOLORjoin)r:   streamoptsfieldsr6   r9   r   nyabr;   ufZopstrr   )r5   r	   rdfs2dot&   s<    


$

& (rZ   c               C   s   t jjd d S )Nz
rdfs2dot.py [-f <format>] files...
Read RDF files given on STDOUT, writes a graph of the RDFS schema in
DOT language to stdout
-f specifies parser to use, if not given,

)sysstderrrA   r   r   r   r	   _helpd   s    r]   c               C   s   t jjjtt d S )N)rdflibextrasZcmdlineutilsmainrZ   r]   r   r   r   r	   r`   n   s    r`   __main__))r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   )__doc__
__future__r   Zrdflib.extras.cmdlineutilsr^   r[   rD   r>   r   r   r   rI   rL   rO   rC   rZ   r]   r`   __name__r   r   r   r	   <module>
   s,         >
