<jupyter_start><jupyter_text>Code for visualizations<jupyter_code>import sys
sys.path.append('./graphparser/')
import graphparser as gp
import pandas as pd
import custom_meter_graph as cmg
import logging,sys,codecs,re
reload (gp)
reload (cmg)#,pd,cmg)
pp = gp.GraphParser('settings/urdu-meter.yaml',blank=' ')<jupyter_output>Couldn't import dot_parser, loading of dot files will not be possible.<jupyter_text>Classical Meter Example (<NAME>)<jupyter_code>meter = '=-===-===-===-='
scanner = cmg.CustomMeterGraph(meter)
df = pd.DataFrame(columns = [x for x in meter])
df

for i,x in enumerate(['naqsh faryaadii hai kis kii sho;xii-e ta;hriir kaa', 
                      'kaa;ga;zii hai pairahan har paikar-e ta.sviir kaa']):
    scan = scanner.graph_scan(x)[0]#'naqsh faryaadii hai kis kii sho;xii-e ta;hriir kaa')[0]
    matched_tokens=[''.join(m.matched_tokens) for m in scan.matches]
    orig_tokens=[''.join(m.orig_tokens) for m in scan.matches]
    phonetic_tokens = [m.ipa for m in scan.matches]
    df.loc['line '+str(i+1)]=orig_tokens
    df.loc['line '+str(i+1)+ ' IPA']=phonetic_tokens
df.sort_index(inplace=True)
df

def draw_meter(m, rankdir='TB'):
    import networkx as nx
    from IPython.display import Image

    g = m.DG

    for i,n in g.node.iteritems():
        labels = {'0': 'start', '=': u'=', '-': u'-'}
        n['label'] = labels[ n['type'] ]

        if n['type']=='0':
            n['color'] = 'green'
            n['shape'] = 'diamond'
        elif n['type']=='=':
            n['shape'] = 'oval'
        else:
            assert(n['type']=='-')
            n['shape'] = 'circle'
        if 'ending' in n or 'meter_type' in n:
            n['color'] = 'red' 
        
    d = nx.to_pydot(g )
    d.set_rankdir(rankdir)


    #d.set_label(0,  'hi')
    png_str = d.create_png()
    return png_str

    #Image(data=png_str)
#    return Image


from IPython.display import Image

scanner_classical = cmg.CustomMeterGraph('=-===-===-=(-)')
png = draw_meter(scanner_classical,rankdir='LR')

with open('classical_meter.png','w') as f: 
    f.write(png)#draw_meter(scanner))

Image(filename='classical_meter.png')# draw_meter(scanner) )<jupyter_output><empty_output><jupyter_text>Modern Meter Example<jupyter_code>scanner_modern = cmg.CustomMeterGraph('[=-==]+=-=(-)')
png = draw_meter(scanner_modern,rankdir='LR')

with open('modern_meter.png','w') as f: 
    f.write(png)#draw_meter(scanner))

Image(filename='modern_meter.png')# draw_meter(scanner) )<jupyter_output><empty_output><jupyter_text>Classical Meters of Mirza Ghalib as Graph<jupyter_code>import meter_graph as mg
ghalib_meters = mg.MeterGraph()
ghalib_png = draw_meter(ghalib_meters)
with open('ghalib_meters.png','w') as f: 
    f.write(ghalib_png)#draw_meter(scanner))

Image(filename='ghalib_meters.png')<jupyter_output><empty_output><jupyter_text>Graph of Free-verse "Hindi" Meter<jupyter_code>import scanning

meter = scanning.get_hindi_scanner()
#hindi_scanner = cmg.CustomMeterGraph('[=|=-=-|-=-=][=|--|-=-=]+=(-)]')

hindi_pngdraw_meter(meter))
with open('hindi_meter.png','w') as f: 
    f.write(hindi_png)#draw_meter(scanner))

Image(filename='hindi_meter.png')<jupyter_output><empty_output><jupyter_text>Example from Miraji of "Hindi meter" Verses<jupyter_code>hindi_scanner = cmg.CustomMeterGraph('=[=|--]+=(-)]')
lines = [' bas dekhaa aur phir bhuul gayaa',' jab ;husn nigaaho;n me;n aayaa']
df  = []
def count(x):
    count=0
    for c in x:
        if c=='=':
            count+=2 
        else: 
            count+=1
    return count
for x in lines:
    scan = hindi_scanner.graph_scan(x)[0].scan
    df.append({ 'text':x, 'scan': scan, 'count':count(scan)})

pd.DataFrame(df, columns=['text','scan','count'])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1718332442544094, 'fraction_numerical': 0.002939604489577766, 'mean_word_length': 4.205841446453407, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '68183', 'license': 'MIT', 'n_tokens_mistral': 1510, 'n_tokens_neox': 1427, 'n_words': 271, 'path': '.ipynb_checkpoints/Graphics-checkpoint.ipynb', 'repo_name': 'seanpue/chicago2015', 'size': '3748'}