littlewine / ZeCo2

MIT License
3 stars 0 forks source link

from utils import qid_to_str #4

Open zlmaker opened 1 year ago

zlmaker commented 1 year ago

in "from utils import qid_to_str" , where from "utils"?

littlewine commented 1 year ago

thanks for the issue. here is the code of qid_to_str:

from paths import path_queries
import pickle
import pandas as pd

def qid_to_str(qids, dataset):
    """Convert integer qids to str"""
    qid_series = pd.Series(qids)
    qid_series = qid_series.astype(str)
    if dataset=='cast19':
        qid_series = qid_series.apply(lambda x: str(x[:2])+'_'+str(x[2:]))
    elif dataset=='cast21':
        qid_series = qid_series.apply(lambda x: str(x[:3])+'_'+str(x[3:]))
    elif dataset=='cast20':
        with open(path_queries['cast20']['qid_mapping'], 'rb') as f:
            qid_mapping = pickle.load(f)
        qid_series = qid_series.apply(lambda x: qid_mapping[x])
    return qid_series

note that you need to pass as an argument a mapping for the queries. sorry, I wrote the code very much in a hurry back then, so it's pretty messy.