<jupyter_start><jupyter_text>Preparing the final result<jupyter_code>rdf = pd.read_csv('data/result.csv')

rdf.head()
rdf.to_excel('data/result.xlsx', index=None, header=True)
rdf_cpy = rdf.copy()
rdf_cpy.columns = ['text','h_name','t_name','final_relation']

rdf_cpy.head()
rels = rdf_cpy['final_relation'].unique()

mapping = []
for r in rels:
    
    if r in ['winner',
                 'sport',
                 'successful candidate','occupation']:
        label = '/people/person/nationality'
        
    elif r in ['work location','part of','participant','participant of',
                      'participating team',
                      'sports season of league or competition',
                      'followed by',
                      'follows','location',
                      'location of formation','notable work']:
        label = '/time/event/locations'
        
    elif r in ['child',
                      'competition class']:
        label = '/people/person/children'
        
    elif r in ['director',
                      'head of government',
                      'member of',
                      'member of political party',
                      'licensed to broadcast to']:
        label = '/business/company/advisors'
        
    elif r in ['distributor',
                      'field of work',
                      'performer',
                      'place served by transport hub','operator']:
        label = '/business/location'
        
    elif r in ['position played on team / speciality']:
        label = '/business/company/majorshareholders'
        
    elif r in ['country of citizenship']:
        label = '/people/person/place_lived'
        
    elif r in ['developer']:
        label = '/business/company/place_founded'
        
    elif r in ['residence',
                      'occupant']:
        label = '/location/neighborhood/neighborhood_of'
        
    #elif any(r in ['']):
    #    label = '/people/deceasedperson/place_of_death'
        
    elif r in ['after a work by',
                      'composer',
                      'instrument']:
        label = '/film/film/featured_film_locations'
        
   # elif any(r in ['']):
   #     label = '/location/region/capital'
        
    elif r in ['publisher',
                      'record label',
                      'screenwriter',
                      'owned by']:
        label = '/business/company/founders'
        
    #elif any(r in ['']):
    #    label = '/people/ethnicity/geographic_distribution'
        
    elif r in ['applies to jurisdiction',
                      'headquarters location',
                      'position held',
                      'located in the administrative territorial entity']:
        label = '/location/country/administrative_divisions'
        
    #elif any(r in ['']):
    #    label = '/people/deceasedperson/place_of_burial'
        
    elif r in ['country']:
        label = '/location/country/capital'
        
    elif r in ['characters',
                      'subsidiary',
                      'instance of',
                      'manufacturer',
                      'main subject']:
        label = '/business/person/company'
        
    elif r in ['architect','constellation','heritage designation','league','genre',
                      'has part',
                      'tributary',
                      'located in or next to body of water',
                      'located on terrain feature',
                      'mountain range','mouth of the watercourse']:
        label = '/location/location/contains'
        
    elif r in ['contains administrative territorial entity','military branch','military rank']:
        label = '/location/administrative_division/country'
        
    #elif any(r in ['']):
    #    label = '/location/us_county/county_seat'
        
    elif r in ['religion']:
        label = '/people/person/religion'
        
    elif r in ['sibling','father','spouse','mother']:
        label = '/people/person/place_of_birth'
        
    elif r in ['country of origin','language of work or name']:
        label = '/people/person/ethnicity'
    else:
        label = 'NA'
        
    mapping.append({'rel':r,'label':label})
    
mapping
def get_mapping(val):
    match = 'NA'
    for m in mapping:
        if m['rel'] == val:
            match = m['label']
            
    return match
get_mapping('developer')
rdf_cpy['relation'] = rdf_cpy['final_relation'].apply(lambda x: get_mapping(x))

rdf_cpy.head()
rdf_cpy.to_excel('data/result_final.xlsx', index=None, header=True)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12361983113227971, 'fraction_numerical': 0.0, 'mean_word_length': 1.6767091541135573, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '364641', 'license': 'Apache-2.0', 'n_tokens_mistral': 1306, 'n_tokens_neox': 1233, 'n_words': 301, 'path': 'ai-hackathon/entity/entity-nlp-inference.ipynb', 'repo_name': 'rishuatgithub/MLPy', 'size': '4619'}