예제 #1
0
def uploaded_file( filename ):
    upload = app.config['UPLOAD_FOLDER']
    project = request.args.get('project')
    inp = InputFile(upload, project, filename)
    filebase = inp.basename 
    filedir = inp.filedir
    
    def get_tables( filedir, suffix = '.table.json'):
        tablelist = list( filter( lambda x : x.endswith(suffix) , os.listdir( filedir ) ) )
        #if len( tablelist ) == 0:
        #    analyze(path)

        for tf in filter( lambda x : x.endswith(suffix) , os.listdir( filedir ) ):
            with codecs.open( os.path.join(filedir,tf) )  as file:
                table = json.load( file )
                yield table #_to_df(table).to_html()

    tables = get_tables( filedir, suffix = '.table.json')
    dfs = (table_to_df(table).to_html() for table in tables )


    #Create HTML
    notices = ['Extraction Results for ' + filename, 'Ordered by lines']    
    headers = []
    meta_data = []
    for t in get_tables( filedir, suffix = '.table.json') :
        meta_data.append( {'begin_line' : t['begin_line'], 'end_line' : t['end_line']} )
        if 'header' in t:
            headers.append(t['header'])
        else:
            headers.append('-')

    chart_path = os.path.join(filedir, "chart"  + '.png' )
    return render_template('viewer.html',
        title=TITLE + ' - ' + filename,
        base_scripts=scripts, filename=filename, project=project,
        css=css, notices = notices, tables = dfs, headers=headers, meta_data=meta_data, chart=chart_path)
예제 #2
0
파일: test.py 프로젝트: ahirner/TabulaRazr
#print i, underqualified, last_qualified, consecutive#, "" or row
test_file = "testcases/test_input1.txt"
test_string = read_lines( test_file )
rows = [row_feature(l) for l in test_string]

for b, e in filter_row_spans(rows, row_qualifies):
    print(b, row_to_string(rows[b]), " --> ", e, row_to_string(rows[e]))
    #for i in range(b,e):
    #    print i, len(rows[i]), row_to_string(rows[i])

print("#######################")

tables = indexed_tables_from_rows(rows)
for begin_line, t in tables.items():
    df = table_to_df(t)

    #for d in t['data']: print row_to_string(d)

    for j in range(t['begin_line']-4, t['begin_line']):
        pass

    for j in range(t['begin_line'], t['end_line']):
        pass #print len(rows[j]), test_string[j], "|".join([c['type']+'_'+c['subtype'] for c in rows[j]])
    print(t['header'])
    display(df)


try:
    from IPython.display import display
    test_file = "testcases/test_input6.txt"