Ejemplo n.º 1
0
def access(environ, start_response):
    db, dbname, path_components, q = wsgi_response(environ,start_response)
    config = f.WebConfig()
    incoming_address = environ['REMOTE_ADDR']
    hostname = socket.gethostname()
    return render_template(db=db,dbname=dbname, config=config,form=True, client_address=incoming_address, q=q,
                           hostname=environ['HTTP_HOST'], report='access', template_name='access_denied.mako')
Ejemplo n.º 2
0
def landing_page(environ,start_response):
    db, dbname, path_components, q = wsgi_response(environ,start_response)
    config = f.WebConfig()
    path = os.getcwd()
    concatenate_files(path, "landing_page", debug=db.locals["debug"])
    return render_template(db=db,dbname=dbname,form=True, q=q, template_name='landing_page.mako',
                           config=config, report="landing_page", ressources=f.concatenate.report_files)
Ejemplo n.º 3
0
def navigation(environ,start_response):
    db, dbname, path_components, q = wsgi_response(environ,start_response)
    path = os.getcwd().replace('functions/', '')
    obj = db[path_components]
    #if obj.philo_type == 'doc' and q['doc_page']:
    #    page_text = f.get_page_text(db, obj, q['doc_page'], path, q['byte'])
    #    #page_text = obj.get_page() This does not fetch the right page, just the first page of the object
    #    if page_text:
    #        doc_id = str(obj.philo_id[0]) + ' %'
    #        prev_page, next_page = get_neighboring_pages(db, doc_id, q['doc_page'])    
    #        return render_template(obj=obj,page_text=page_text,prev_page=prev_page,next_page=next_page,
    #                               dbname=dbname,current_page=q['doc_page'],f=f,navigate_doc=navigate_doc,
    #                               db=db,q=q,template_name='pages.mako')
    #    else:
    #        path_components += ['2']
    #        obj = db[path_components]
    #if has_pages(obj, db):
    #    page_num = get_page_num(obj,db)
    #    if page_num:
    #        page_text = f.get_page_text(db, obj, q['doc_page'], path, q['byte'])
    #        if page_text:  ## In case the page does not contain any text
    #            doc_id = str(obj.philo_id[0]) + ' %'
    #            prev_page, next_page = get_neighboring_pages(db, doc_id, page_num)
    #            return render_template(obj=obj,page_text=page_text,prev_page=prev_page,next_page=next_page,
    #                                    dbname=dbname,current_page=page_num,f=f,navigate_doc=navigate_doc,
    #                                    db=db,q=q,template_name='pages.mako')
    if obj.philo_type == 'doc':
        return render_template(obj=obj,philo_id=obj.philo_id[0],dbname=dbname,f=f,navigate_doc=navigate_doc,
                       db=db,q=q,template_name='t_o_c_template.mako')
    obj_text = f.get_text_obj(obj, path, query_args=q['byte'])
    #obj_text = obj_pager(db, obj, obj_text)  ## this creates virtual pages
    prev = ' '.join(obj.prev.split()[:7])
    next = ' '.join(obj.next.split()[:7])
    return render_template(obj=obj,philo_id=obj.philo_id[0],dbname=dbname,f=f,navigate_doc=navigate_doc,
                       db=db,q=q,obj_text=obj_text,prev=prev,next=next,template_name='object.mako')
Ejemplo n.º 4
0
def navigation(environ,start_response):
    db, dbname, path_components, q = wsgi_response(environ,start_response)
    path = os.getcwd().replace('functions/', '')
    obj = db[path_components]
    print >> sys.stderr, "OBJ", obj.philo_type
    if obj.philo_type == 'doc' and q['doc_page']:
        page_text = f.get_page_text(db, obj.philo_id[0], q['doc_page'], obj.filename, path, q['byte'])
        if page_text:
            doc_id = str(obj.philo_id[0]) + ' %'
            prev_page, next_page = get_neighboring_pages(db, doc_id, q['doc_page'])    
            return render_template(obj=obj,page_text=page_text,prev_page=prev_page,next_page=next_page,
                                   dbname=dbname,current_page=q['doc_page'],f=f,navigate_doc=navigate_doc,
                                   db=db,q=q,template_name='pages.mako')
        else:
            path_components += ['2']
            obj = db[path_components]
    if has_pages(obj, db):
        page_num = get_page_num(obj,db)
        if page_num:
            page_text = f.get_page_text(db, obj.philo_id[0], page_num, obj.filename, path, '')
            if page_text:  ## In case the page does not contain any text
                doc_id = str(obj.philo_id[0]) + ' %'
                prev_page, next_page = get_neighboring_pages(db, doc_id, page_num)
                return render_template(obj=obj,page_text=page_text,prev_page=prev_page,next_page=next_page,
                                        dbname=dbname,current_page=page_num,f=f,navigate_doc=navigate_doc,
                                        db=db,q=q,template_name='pages.mako')
    if obj.philo_type == 'doc':
        return render_template(obj=obj,philo_id=obj.philo_id[0],dbname=dbname,f=f,navigate_doc=navigate_doc,
                       db=db,q=q,template_name='toc.mako')
    obj_text = f.get_text_obj(obj, path, query_args=q['byte'])
    #obj_text = obj_pager(db, obj, obj_text)  ## this creates virtual pages
    prev = ' '.join(obj.prev.split()[:7])
    next = ' '.join(obj.next.split()[:7])
    return render_template(obj=obj,philo_id=obj.philo_id[0],dbname=dbname,f=f,navigate_doc=navigate_doc,
                       db=db,q=q,obj_text=obj_text,prev=prev,next=next,template_name='object.mako')
Ejemplo n.º 5
0
def concordance(environ, start_response):
    db, dbname, path_components, q = wsgi_response(environ, start_response)
    path = os.getcwd().replace('functions/', '')
    config = f.WebConfig()
    if q['format'] == "json":
        hits = db.query(q["q"], q["method"], q["arg"], **q["metadata"])
        start, end, n = f.link.page_interval(q['results_per_page'], hits,
                                             q["start"], q["end"])
        formatted_results = []
        for i in hits[start - 1:end]:
            text = fetch_concordance(i, path, config.concordance_length)
            full_metadata = {}
            for metadata in config.metadata:
                full_metadata[metadata] = i[metadata]
            result = {
                "citation": f.cite.make_abs_doc_cite_mobile(db, i),
                "shrtcit": f.cite.make_abs_doc_shrtcit_mobile(db, i),
                "text": text,
                "hit_count": len(hits),
                "philo_id": i.philo_id,
                "start": start,
                "offsets": i.bytes
            }
            formatted_results.append(result)
        return json.dumps(formatted_results)
    if q['q'] == '':
        return bibliography(f, path, db, dbname, q, environ)
    else:
        hits = db.query(q["q"], q["method"], q["arg"], **q["metadata"])
        return render_concordance(hits, db, dbname, q, path, config)
Ejemplo n.º 6
0
def navigation(start_response, environ):
    db, dbname, path_components, q = wsgi_response(start_response, environ)
    path = os.getcwd().replace('functions/', '')
    obj = db[path_components]
    if obj.philo_type == 'doc':
        return render_template(obj=obj,dbname=dbname,f=f,navigate_doc=navigate_doc,db=db,q=q,form=False,template_name='navigation.mako')
    else:
        return render_template(obj=obj,dbname=dbname,f=f,navigate_obj=navigate_obj,db=db,q=q,form=False,template_name='object.mako')
Ejemplo n.º 7
0
def error(environ, start_response):
    try:
        db, dbname, path_components, q = wsgi_response(environ, start_response)
    except AssertionError:
        myname = environ["SCRIPT_FILENAME"]
        dbname = os.path.basename(myname.replace("/dispatcher.py", ""))
        db, path_components, q = parse_cgi(environ)
    return error_handling(db, dbname, q)
Ejemplo n.º 8
0
def error(environ,start_response):
    try:
        db, dbname, path_components, q = wsgi_response(environ,start_response)
    except AssertionError:
        myname = environ["SCRIPT_FILENAME"]
        dbname = os.path.basename(myname.replace("/dispatcher.py",""))
        db, path_components, q = parse_cgi(environ)
    return error_handling(db, dbname, q)
Ejemplo n.º 9
0
def collocation(environ,start_response):
    db, dbname, path_components, q = wsgi_response(environ,start_response)
    path = os.getcwd().replace('functions/', '')
    config = f.WebConfig()
    if q['q'] == '':
        return bibliography(f,path, db, dbname,q,environ) ## the default should be an error message
    hits = db.query(q["q"],q["method"],q["arg"],**q["metadata"])
    return render_collocation(hits, db, dbname, q, path, config)
Ejemplo n.º 10
0
def collocation(environ, start_response):
    db, dbname, path_components, q = wsgi_response(environ, start_response)
    path = os.getcwd().replace('functions/', '')
    config = f.WebConfig()
    if q['q'] == '':
        return bibliography(f, path, db, dbname, q,
                            environ)  ## the default should be an error message
    hits = db.query(q["q"], q["method"], q["arg"], **q["metadata"])
    return render_collocation(hits, db, dbname, q, path, config)
Ejemplo n.º 11
0
def concordance(start_response, environ):
    db, dbname, path_components, q = wsgi_response(start_response, environ)
    path = os.getcwd().replace('functions/', '')
    if q['q'] == '':
        return bibliography(f,path, db, dbname,q,environ)
    else:
        hits = db.query(q["q"],q["method"],q["arg"],**q["metadata"])
        return render_template(results=hits,db=db,dbname=dbname,q=q,fetch_concordance=fetch_concordance,f=f,
                                path=path, results_per_page=q['results_per_page'], template_name="concordance.mako")
Ejemplo n.º 12
0
def kwic(environ,start_response):
    db, dbname, path_components, q = wsgi_response(environ,start_response)
    path = os.getcwd().replace('functions/', '')
    if q['q'] == '':
        return bibliography(f,path, db, dbname,q,environ)
    else:
        hits = db.query(q["q"],q["method"],q["arg"],**q["metadata"])
        return render_template(results=hits,db=db,dbname=dbname,q=q,fetch_kwic=fetch_kwic,f=f,
                                path=path, results_per_page=q['results_per_page'], template_name='kwic.mako')
Ejemplo n.º 13
0
def relevance(start_response, environ):
    db, dbname, path_components, q = wsgi_response(start_response, environ)
    path = os.getcwd().replace('functions/', '')
    if q['q'] == '':
        return bibliography(f,path, db, dbname,q,environ)
    else:
        results = retrieve_hits(q, db)
    return render_template(results=results,db=db,dbname=dbname,q=q,fetch_relevance=fetch_relevance,f=f,format=format,
                                path=path, results_per_page=q['results_per_page'], template_name='relevance.mako')
def concordance_from_collocation(start_response, environ):
    db, dbname, path_components, q = wsgi_response(start_response, environ)
    path = os.getcwd().replace('functions/', '')
    if q['q'] == '':
        return bibliography(f,path, db, dbname,q,environ)
    else:
        hits = db.query(q["q"],q["method"],q["arg"],**q["metadata"])
        return render_template(results=hits,db=db,dbname=dbname,q=q,fetch_colloc_concordance=fetch_colloc_concordance,
                               fetch_concordance=fetch_concordance,f=f,path=path, results_per_page=q['results_per_page'],
                               template_name="concordance_from_collocation.mako")
Ejemplo n.º 15
0
def time_series(environ,start_response):
    db, dbname, path_components, q = wsgi_response(environ,start_response)
    path = os.getcwd().replace('functions/', '')
    config = f.WebConfig()
    if q['q'] == '':
        return bibliography(f,path, db, dbname,q,environ)
    else:
        q = handle_dates(q, db)
        hits = db.query(q["q"],q["method"],q["arg"],**q["metadata"])
        return render_time_series(hits, db, dbname, q, path, config)
Ejemplo n.º 16
0
def theme_rheme(start_response, environ):
    db, dbname, path_components, q = wsgi_response(start_response, environ)
    path = os.getcwd().replace('functions/', '')
    if q['q'] == '':
        return bibliography(f,path, db, dbname,q,environ)
    else:
        hits = db.query(q["q"],q["method"],q["arg"],**q["metadata"])
        new_hits, full_report = adjust_results(hits, path, q)
        return render_template(results=new_hits,full_report=full_report,db=db,dbname=dbname,q=q,f=f,path=path,
                               results_per_page=q['results_per_page'], template_name="theme_rheme.mako")
Ejemplo n.º 17
0
def navigation(environ, start_response):
    db, dbname, path_components, q = wsgi_response(environ, start_response)
    path = os.getcwd().replace('functions/', '')
    obj = db[path_components]
    config = f.WebConfig()
    prev = ' '.join(obj.prev.split()[:7])
    next = ' '.join(obj.next.split()[:7])
    current = obj.philo_id[:7]
    if q['format'] == "json":
        if check_philo_virtual(db, path_components):
            obj = db[path_components[:-1]]
        obj_text = f.get_text_obj(obj, path, query_args=q['byte'])
        return json.dumps({
            'current':
            current,
            'text':
            obj_text,
            'prev':
            prev,
            'next':
            next,
            'shrtcit':
            f.cite.make_abs_doc_shrtcit_mobile(db, obj),
            'citation':
            f.cite.make_abs_doc_cite_mobile(db, obj)
        })
    if obj.philo_type == 'doc':
        concatenate_files(path, "t_o_c", debug=db.locals["debug"])
        return render_template(obj=obj,
                               philo_id=obj.philo_id[0],
                               dbname=dbname,
                               f=f,
                               navigate_doc=navigate_doc,
                               db=db,
                               q=q,
                               config=config,
                               template_name='t_o_c.mako',
                               report="t_o_c",
                               ressources=f.concatenate.report_files)
    obj_text = f.get_text_obj(obj, path, query_args=q['byte'])
    concatenate_files(path, "navigation", debug=db.locals["debug"])
    return render_template(obj=obj,
                           philo_id=obj.philo_id[0],
                           dbname=dbname,
                           f=f,
                           navigate_doc=navigate_doc,
                           db=db,
                           q=q,
                           obj_text=obj_text,
                           prev=prev,
                           next=next,
                           config=config,
                           template_name='object.mako',
                           report="navigation",
                           ressources=f.concatenate.report_files)
Ejemplo n.º 18
0
def collocation(environ,start_response):
    db, dbname, path_components, q = wsgi_response(environ,start_response)
    path = os.getcwd().replace('functions/', '')
    if q['q'] == '':
        return bibliography(f,path, db, dbname,q,environ) ## the default should be an error message
    hits = db.query(q["q"],q["method"],q["arg"],**q["metadata"])
    all_colloc, left_colloc, right_colloc = fetch_collocation(hits, path, q, db)
    hit_len = len(hits)
    return render_template(all_colloc=all_colloc, left_colloc=left_colloc, right_colloc=right_colloc,
                           db=db,dbname=dbname,q=q,link=link_to_concordance,f=f,path=path,
                           results_per_page=q['results_per_page'],hit_len=hit_len,
                           order=sort_to_display,dumps=json.dumps,template_name='collocation.mako')
Ejemplo n.º 19
0
def pagination(environ,start_response):
    db, dbname, path_components, q = wsgi_response(environ,start_response)
    path = os.getcwd().replace('functions/', '')
    doc_page = q['doc_page']
    philo_id = q['philo_id']
    filename = q['filename']
    bytes = q['byte']
    page_text = f.get_page_text(db, philo_id, doc_page, filename, path, bytes)
    prev_page, next_page = get_neighboring_pages(db, philo_id, doc_page)
    return render_template(page_text=page_text,db=db,dbname=dbname,current_page=doc_page,
                           prev_page=prev_page,next_page=next_page,pagination=pagination,
                           filename=filename, philo_id=philo_id,bytes=bytes,template_name="doc_page.mako")
Ejemplo n.º 20
0
def landing_page(environ, start_response):
    db, dbname, path_components, q = wsgi_response(environ, start_response)
    config = f.WebConfig()
    path = os.getcwd()
    concatenate_files(path, "landing_page", debug=db.locals["debug"])
    return render_template(db=db,
                           dbname=dbname,
                           form=True,
                           q=q,
                           template_name='landing_page.mako',
                           config=config,
                           report="landing_page",
                           ressources=f.concatenate.report_files)
Ejemplo n.º 21
0
def frequency(environ,start_response):
    db, dbname, path_components, q = wsgi_response(environ,start_response)
    hits = db.query(q["q"],q["method"],q["arg"],**q["metadata"])
    # if we have a json report, directly dump the table in a json wrapper.
    # if you want to change the URL value of a key, do it in generate_frequency() below.
    field, counts = generate_frequency(hits,q,db)

    l = len(counts)
    wrapper = {"length":l,"result":[],"field":field}
    for label, i in sorted(counts.iteritems(), key=lambda x: x[1]['count'], reverse=True):
        table_row = {"label":label,"count":i['count'],"url":i['url']}
        wrapper["result"].append(table_row)
    return json.dumps(wrapper,indent=1)
Ejemplo n.º 22
0
def access(environ, start_response):
    db, dbname, path_components, q = wsgi_response(environ, start_response)
    config = f.WebConfig()
    incoming_address = environ['REMOTE_ADDR']
    hostname = socket.gethostname()
    return render_template(db=db,
                           dbname=dbname,
                           config=config,
                           form=True,
                           client_address=incoming_address,
                           q=q,
                           hostname=environ['HTTP_HOST'],
                           report='access',
                           template_name='access_denied.mako')
Ejemplo n.º 23
0
def bibliography(environ, start_response):
    db, dbname, path_components, q = wsgi_response(environ,start_response)
    path = os.getcwd().replace('functions/', '')
    if q['format'] == "json":
        wrapper = []
        hits = fetch_bibliography(f,path, db, dbname,q,environ)
        hit_count = len(hits)
        for i in hits[0:100]:
            in_citation = f.cite.make_abs_doc_cite_biblio_mobile(db,i)
            citation, text = in_citation.split('|')
            wrapper.append({'philo_id': i.philo_id, 'citation': citation, 'hit_count': hit_count, 'text': text})
        return json.dumps(wrapper)
    else:
        return fetch_bibliography(f,path, db, dbname,q,environ)
Ejemplo n.º 24
0
def frequency(environ, start_response):
    db, dbname, path_components, q = wsgi_response(environ, start_response)
    hits = db.query(q["q"], q["method"], q["arg"], **q["metadata"])
    # if we have a json report, directly dump the table in a json wrapper.
    # if you want to change the URL value of a key, do it in generate_frequency() below.
    field, counts = generate_frequency(hits, q, db)

    l = len(counts)
    wrapper = {"length": l, "result": [], "field": field}
    for label, i in sorted(counts.iteritems(),
                           key=lambda x: x[1]['count'],
                           reverse=True):
        table_row = {"label": label, "count": i['count'], "url": i['url']}
        wrapper["result"].append(table_row)
    return json.dumps(wrapper, indent=1)
Ejemplo n.º 25
0
def kwic(environ,start_response):
    db, dbname, path_components, q = wsgi_response(environ,start_response)
    path = os.getcwd().replace('functions/', '')
    config = f.WebConfig()
    if q['format'] == "json":
        hits = db.query(q["q"],q["method"],q["arg"],**q["metadata"])
        start, end, n = f.link.page_interval(q['results_per_page'], hits, q["start"], q["end"])
        kwic_results = fetch_kwic(hits, path, q, f.link.byte_query, db, start-1, end, length=250)
        formatted_results = [{"citation": i[0],
                              "text": i[1], "philo_id": i[2], "start":start, "hit_count": len(hits)} for i in kwic_results]
        return json.dumps(formatted_results)
    if q['q'] == '':
        return bibliography(f,path, db, dbname,q,environ)
    else:
        hits = db.query(q["q"],q["method"],q["arg"],**q["metadata"])
        return render_kwic(hits, db, dbname, q, path, config)
Ejemplo n.º 26
0
def frequency(start_response, environ):
    db, dbname, path_components, q = wsgi_response(start_response, environ)
    hits = db.query(q["q"],q["method"],q["arg"],**q["metadata"])
    if q["format"] == "json":
        # if we have a json report, directly dump the table in a json wrapper.
        # if you want to change the URL value of a key, do it in generate_frequency() below.
        field, counts = generate_frequency(hits,q,db)

        l = len(counts)
        wrapper = {"length":l,"result":[],"field":field}
        for label,count,url in counts:
            table_row = {"label":label,"count":count,"url":url}
            wrapper["result"].append(table_row)
        return json.dumps(wrapper,indent=1)
        
    else:
        return render_template(results=hits,db=db,dbname=dbname,q=q,generate_frequency=generate_frequency,f=f, template_name='frequency.mako')
Ejemplo n.º 27
0
def theme_rheme(start_response, environ):
    db, dbname, path_components, q = wsgi_response(start_response, environ)
    path = os.getcwd().replace('functions/', '')
    if q['q'] == '':
        return bibliography(f, path, db, dbname, q, environ)
    else:
        hits = db.query(q["q"], q["method"], q["arg"], **q["metadata"])
        new_hits, full_report = adjust_results(hits, path, q)
        return render_template(results=new_hits,
                               full_report=full_report,
                               db=db,
                               dbname=dbname,
                               q=q,
                               f=f,
                               path=path,
                               results_per_page=q['results_per_page'],
                               template_name="theme_rheme.mako")
Ejemplo n.º 28
0
def collocation(start_response, environ):
    db, dbname, path_components, q = wsgi_response(start_response, environ)
    path = os.getcwd().replace('functions/', '')
    if q['q'] == '':
        return bibliography(f, path, db, dbname, q,
                            environ)  ## the default should be an error message
    else:
        hits = db.query(q["q"], q["method"], q["arg"], **q["metadata"])
    return render_template(results=hits,
                           db=db,
                           dbname=dbname,
                           q=q,
                           fetch_collocation=fetch_collocation,
                           link=link_to_concordance,
                           f=f,
                           path=path,
                           results_per_page=q['results_per_page'],
                           template_name='collocation.mako')
Ejemplo n.º 29
0
def bibliography(environ, start_response):
    db, dbname, path_components, q = wsgi_response(environ, start_response)
    path = os.getcwd().replace('functions/', '')
    if q['format'] == "json":
        wrapper = []
        hits = fetch_bibliography(f, path, db, dbname, q, environ)
        hit_count = len(hits)
        for i in hits[0:100]:
            in_citation = f.cite.make_abs_doc_cite_biblio_mobile(db, i)
            citation, text = in_citation.split('|')
            wrapper.append({
                'philo_id': i.philo_id,
                'citation': citation,
                'hit_count': hit_count,
                'text': text
            })
        return json.dumps(wrapper)
    else:
        return fetch_bibliography(f, path, db, dbname, q, environ)
Ejemplo n.º 30
0
def frequencies(environ,start_response):
    db, dbname, path_components, q = wsgi_response(environ,start_response)
    print >> sys.stderr, "Q",q
    path = os.getcwd().replace('functions/', '')
#    results = prominent_features(q, db)
    res = ""
    count = 0;
    res = []
    for result in make_frequency_query(db,q["metadata"]):
#        print >> sys.stderr,result
        res.append(result)
        count += 1;
        if count > 1000:
            break
    #hits = db.query(q["q"],q["method"],q["arg"],**q["metadata"])
    #return render_template(results=hits,db=db,dbname=dbname,q=q,fetch_concordance=fetch_concordance,
    #                       f=f, path=path, results_per_page=q['results_per_page'],
    #                       template_name="concordance.mako")
    return render_template(results=res,db=db,dbname=dbname,q=q,f=f,template_name="frequencies.mako", report="frequencies")
Ejemplo n.º 31
0
def concordance(environ,start_response):
    db, dbname, path_components, q = wsgi_response(environ,start_response)
    path = os.getcwd().replace('functions/', '')
    config = f.WebConfig()
    if q['format'] == "json":
        hits = db.query(q["q"],q["method"],q["arg"],**q["metadata"])
        start, end, n = f.link.page_interval(q['results_per_page'], hits, q["start"], q["end"])
        formatted_results = []
        for i in hits[start-1:end]:
            text = fetch_concordance(i, path, config.concordance_length)
            full_metadata = {}
            for metadata in config.metadata:
                full_metadata[metadata] = i[metadata]
            result = {"citation": f.cite.make_abs_doc_cite_mobile(db,i), "shrtcit": f.cite.make_abs_doc_shrtcit_mobile(db,i), "text": text, "hit_count": len(hits), "philo_id": i.philo_id, "start":start, "offsets": i.bytes}
            formatted_results.append(result)
        return json.dumps(formatted_results)
    if q['q'] == '':
        return bibliography(f,path, db, dbname,q,environ)
    else:
        hits = db.query(q["q"],q["method"],q["arg"],**q["metadata"])
        return render_concordance(hits, db, dbname, q, path, config)
def concordance_from_collocation(environ,start_response):
    db, dbname, path_components, q = wsgi_response(environ,start_response)
    path = os.getcwd().replace('functions/', '')
    config = f.WebConfig()
    if q['q'] == '':
        return bibliography(f,path, db, dbname,q,environ)
    else:
        hits = db.query(q["q"],q["method"],q["arg"],**q["metadata"])
        colloc_results = fetch_colloc_concordance(hits, path, q, db, config)
        biblio_criteria = []
        for k,v in q["metadata"].iteritems():
            if v:
                if k in config.metadata_aliases:
                    k = config.metadata_aliases[k]
                biblio_criteria.append('<span class="biblio_criteria">%s: <b>%s</b></span>' % (k.title(), v.decode('utf-8', 'ignore'), ))
        biblio_criteria = ' '.join(biblio_criteria)
        concatenate_files(path, "concordance_from_collocation", debug=db.locals["debug"])
        return render_template(results=colloc_results,db=db,dbname=dbname,q=q,colloc_concordance=colloc_concordance,
                               f=f,path=path, results_per_page=q['results_per_page'], config=config,report="concordance_from_collocation",
                               biblio_criteria=biblio_criteria, template_name="concordance_from_collocation.mako",
                               ressources=f.concatenate.report_files)
Ejemplo n.º 33
0
def navigation(start_response, environ):
    db, dbname, path_components, q = wsgi_response(start_response, environ)
    path = os.getcwd().replace('functions/', '')
    obj = db[path_components]
    if obj.philo_type == 'doc':
        return render_template(obj=obj,
                               dbname=dbname,
                               f=f,
                               navigate_doc=navigate_doc,
                               db=db,
                               q=q,
                               form=False,
                               template_name='navigation.mako')
    else:
        return render_template(obj=obj,
                               dbname=dbname,
                               f=f,
                               navigate_obj=navigate_obj,
                               db=db,
                               q=q,
                               form=False,
                               template_name='object.mako')
Ejemplo n.º 34
0
def navigation(environ,start_response):
    db, dbname, path_components, q = wsgi_response(environ,start_response)
    path = os.getcwd().replace('functions/', '')
    obj = db[path_components]
    config = f.WebConfig()
    prev = ' '.join(obj.prev.split()[:7])
    next = ' '.join(obj.next.split()[:7])
    current = obj.philo_id[:7]
    if q['format'] == "json":
        if check_philo_virtual(db, path_components):
            obj = db[path_components[:-1]]
        obj_text = f.get_text_obj(obj, path, query_args=q['byte'])
        return json.dumps({'current': current, 'text': obj_text, 'prev': prev, 'next': next, 'shrtcit':  f.cite.make_abs_doc_shrtcit_mobile(db,obj), 'citation': f.cite.make_abs_doc_cite_mobile(db,obj)})
    if obj.philo_type == 'doc':
        concatenate_files(path, "t_o_c", debug=db.locals["debug"])
        return render_template(obj=obj,philo_id=obj.philo_id[0],dbname=dbname,f=f,navigate_doc=navigate_doc,
                       db=db,q=q,config=config,template_name='t_o_c.mako', report="t_o_c",
                       ressources=f.concatenate.report_files)
    obj_text = f.get_text_obj(obj, path, query_args=q['byte'])
    concatenate_files(path, "navigation", debug=db.locals["debug"])
    return render_template(obj=obj,philo_id=obj.philo_id[0],dbname=dbname,f=f,navigate_doc=navigate_doc,
                       db=db,q=q,obj_text=obj_text,prev=prev,next=next,config=config,
                       template_name='object.mako', report="navigation", ressources=f.concatenate.report_files)
Ejemplo n.º 35
0
def frequency(start_response, environ):
    db, dbname, path_components, q = wsgi_response(start_response, environ)
    hits = db.query(q["q"], q["method"], q["arg"], **q["metadata"])
    if q["format"] == "json":
        # if we have a json report, directly dump the table in a json wrapper.
        # if you want to change the URL value of a key, do it in generate_frequency() below.
        field, counts = generate_frequency(hits, q, db)

        l = len(counts)
        wrapper = {"length": l, "result": [], "field": field}
        for label, count, url in counts:
            table_row = {"label": label, "count": count, "url": url}
            wrapper["result"].append(table_row)
        return json.dumps(wrapper, indent=1)

    else:
        return render_template(results=hits,
                               db=db,
                               dbname=dbname,
                               q=q,
                               generate_frequency=generate_frequency,
                               f=f,
                               template_name='frequency.mako')
def concordance_from_collocation(environ, start_response):
    db, dbname, path_components, q = wsgi_response(environ, start_response)
    path = os.getcwd().replace('functions/', '')
    config = f.WebConfig()
    if q['q'] == '':
        return bibliography(f, path, db, dbname, q, environ)
    else:
        hits = db.query(q["q"], q["method"], q["arg"], **q["metadata"])
        colloc_results = fetch_colloc_concordance(hits, path, q, db, config)
        biblio_criteria = []
        for k, v in q["metadata"].iteritems():
            if v:
                if k in config.metadata_aliases:
                    k = config.metadata_aliases[k]
                biblio_criteria.append(
                    '<span class="biblio_criteria">%s: <b>%s</b></span>' % (
                        k.title(),
                        v.decode('utf-8', 'ignore'),
                    ))
        biblio_criteria = ' '.join(biblio_criteria)
        concatenate_files(path,
                          "concordance_from_collocation",
                          debug=db.locals["debug"])
        return render_template(
            results=colloc_results,
            db=db,
            dbname=dbname,
            q=q,
            colloc_concordance=colloc_concordance,
            f=f,
            path=path,
            results_per_page=q['results_per_page'],
            config=config,
            report="concordance_from_collocation",
            biblio_criteria=biblio_criteria,
            template_name="concordance_from_collocation.mako",
            ressources=f.concatenate.report_files)
Ejemplo n.º 37
0
def form(environ,start_response):
    db, dbname, path_components, q = wsgi_response(environ,start_response)
    return render_template(db=db,dbname=dbname,form=True, template_name='form.mako')
Ejemplo n.º 38
0
def form(start_response, environ):
    db, dbname, path_components, q = wsgi_response(start_response, environ)
    return render_template(db=db,
                           dbname=dbname,
                           form=True,
                           template_name='form.mako')
Ejemplo n.º 39
0
def time_series(environ,start_response):
    db, dbname, path_components, q = wsgi_response(environ,start_response)
    frequencies, relative_frequencies = generate_frequency(q, db)
    #frequencies, relative_frequencies = time_frequency(q, db)
    return render_template(frequencies=frequencies,relative_frequencies=relative_frequencies,
                           db=db,dbname=dbname,q=q,f=f, template_name='time_series.mako')
def collocation(environ,start_response):
    db, dbname, path_components, q = wsgi_response(environ,start_response)
    path = os.getcwd().replace('functions/', '')
    if q['q'] == '':
        return bibliography(f,path, db, dbname,q,environ) ## the default should be an error message
    else:
        hits = db.query(q["q"],q["method"],q["arg"],**q["metadata"])
    return render_template(results=hits,db=db,dbname=dbname,q=q,fetch_collocation=fetch_collocation,link=link_to_concordance,
                           f=f,path=path, results_per_page=q['results_per_page'], template_name='collocation.mako')