

def getNgrams(query, corpus, startYear, endYear, smoothing, caseInsensitive):
    params = dict(content=query, year_start=startYear, year_end=endYear, corpus=corpora[corpus], smoothing=smoothing, case_insensitive=caseInsensitive)
    if (params['case_insensitive'] is False):
        params.pop('case_insensitive')
    if ('?' in params['content']):
        params['content'] = params['content'].replace('?', '*')
    if ('@' in params['content']):
        params['content'] = params['content'].replace('@', '=>')
    req = requests.get('http://books.google.com/ngrams/graph', params=params)
    res = re.findall('var data = (.*?);\\n', req.text)
    if res:
        data = {qry['ngram']: qry['timeseries'] for qry in literal_eval(res[0])}
        df = DataFrame(data)
        df.insert(0, 'year', list(range(startYear, (endYear + 1))))
    else:
        df = DataFrame()
    return (req.url, params['content'], df)

dataset/ETHPy150Open econpy/google-ngrams/getngrams.py getNgrams/original