

def runQuery(argumentString):
    arguments = argumentString.split()
    query = ' '.join([arg for arg in arguments if (not arg.startswith('-'))])
    if ('?' in query):
        query = query.replace('?', '*')
    if ('@' in query):
        query = query.replace('@', '=>')
    params = [arg for arg in arguments if arg.startswith('-')]
    (corpus, startYear, endYear, smoothing) = ('eng_2012', 1800, 2000, 3)
    (printHelp, caseInsensitive, allData) = (False, False, False)
    (toSave, toPrint, toPlot) = (True, True, False)
    for param in params:
        if ('-nosave' in param):
            toSave = False
        elif ('-noprint' in param):
            toPrint = False
        elif ('-plot' in param):
            toPlot = True
        elif ('-corpus' in param):
            corpus = param.split('=')[1].strip()
        elif ('-startYear' in param):
            startYear = int(param.split('=')[1])
        elif ('-endYear' in param):
            endYear = int(param.split('=')[1])
        elif ('-smoothing' in param):
            smoothing = int(param.split('=')[1])
        elif ('-caseInsensitive' in param):
            caseInsensitive = True
        elif ('-alldata' in param):
            allData = True
        elif ('-help' in param):
            printHelp = True
        else:
            print(('Did not recognize the following argument: %s' % param))
    if printHelp:
        print('See README file.')
    else:
        if (('*' in query) and (caseInsensitive is True)):
            caseInsensitive = False
            notifyUser = True
            warningMessage = (('*NOTE: Wildcard and case-insensitive ' + "searches can't be combined, so the ") + 'case-insensitive option was ignored.')
        elif (('_INF' in query) and (caseInsensitive is True)):
            caseInsensitive = False
            notifyUser = True
            warningMessage = (('*NOTE: Inflected form and case-insensitive ' + "searches can't be combined, so the ") + 'case-insensitive option was ignored.')
        else:
            notifyUser = False
        (url, urlquery, df) = getNgrams(query, corpus, startYear, endYear, smoothing, caseInsensitive)
        if (not s):
            if (caseInsensitive is True):
                for col in df.columns:
                    if (col.count('(All)') == 1):
                        df[col.replace(' (All)', '')] = df.pop(col)
                    elif ((col.count(':chi_') == 1) or corpus.startswith('chi_')):
                        pass
                    elif ((col.count(':ger_') == 1) or corpus.startswith('ger_')):
                        pass
                    elif ((col.count(':heb_') == 1) or corpus.startswith('heb_')):
                        pass
                    elif ((col.count('(All)') == 0) and (col != 'year')):
                        if (col not in urlquery.split(',')):
                            df.pop(col)
            if ('_INF' in query):
                for col in df.columns:
                    if ('_INF' in col):
                        df.pop(col)
            if ('*' in query):
                for col in df.columns:
                    if ('*' in col):
                        df.pop(col)
        if toPrint:
            print(','.join(df.columns.tolist()))
            for row in df.iterrows():
                try:
                    print((('%d,' % int(row[1].values[0])) + ','.join([('%.12f' % s) for s in row[1].values[1:]])))
                except:
                    print(','.join([str(s) for s in row[1].values]))
        queries = ''.join(urlquery.replace(',', '_').split())
        if ('*' in queries):
            queries = queries.replace('*', 'WILDCARD')
        if (caseInsensitive is True):
            word_case = 'caseInsensitive'
        else:
            word_case = 'caseSensitive'
        filename = ('%s-%s-%d-%d-%d-%s.csv' % (queries, corpus, startYear, endYear, smoothing, word_case))
        if toSave:
            for col in df.columns:
                if ('&gt;' in col):
                    df[col.replace('&gt;', '>')] = df.pop(col)
            df.to_csv(filename, index=False)
            print(('Data saved to %s' % filename))
        if toPlot:
            try:
                subprocess.call(['python', 'xkcd.py', filename])
            except:
                if (not toSave):
                    print((('Currently, if you want to create a plot you ' + 'must also save the data. Rerun your query, ') + 'removing the -nosave option.'))
                else:
                    print(('Plotting Failed: %s' % filename))
        if notifyUser:
            print(warningMessage)

dataset/ETHPy150Open econpy/google-ngrams/getngrams.py runQuery/VarMisuse@487/718 `allData`->`s`