Changeset 34952


Ignore:
Timestamp:
2021-03-01T23:47:30+13:00 (3 years ago)
Author:
davidb
Message:

Country-label to URI lookup introduced

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/model-sites-dev/eurovision-lod/collect/eurovision/prepare/voting-excel/xlsx-tocountry-jsonmetadata.py

    r34919 r34952  
    1212
    1313import util
     14import csvutil
    1415import xlsxutil
    1516
     
    6768
    6869
    69 def fileset_voting_for_esc_country_in_year(to_country_year_votes):
     70def fileset_voting_for_esc_country_in_year(to_country_year_votes,countrylabel_to_uri_mapping):
    7071
    7172    # Looking to build data-structure (for output as JSON) in the form
     
    104105    tl_to_country_id = re.sub(r'\s+', '', tl_to_country) + str(tl_year)
    105106
    106     metadata_array.append({ "name": "Final","content": tl_final })
    107        
     107    metadata_array.append({ "name": "Country","content": tl_to_country })
     108    metadata_array.append({ "name": "Year",   "content": tl_year })
     109    metadata_array.append({ "name": "Final",  "content": tl_final })
     110
     111    # tl_to_country_lc = tl_to_country.lower()
     112    tl_to_country_uri = countrylabel_to_uri_mapping.get(tl_to_country)
     113    if (tl_to_country_uri != None):
     114        metadata_array.append({ "name": "CountryDBURI","content": tl_to_country_uri })
     115    else:
     116        util.eprint("Warning: Failed to find DBpedia Country URI match for: " + tl_to_country)
     117               
    108118    for to_country_year_vote in to_country_year_votes:
    109119        to_country   = to_country_year_vote.get('To country')
     
    150160
    151161
    152 def gs_directory_metadata(to_country_year_voting_groups):
     162def gs_directory_metadata(to_country_year_voting_groups,countrylabel_to_uri_mapping):
    153163    # Next step is to express the grouped to-country voting data
    154164    # in the Greenstone JSON metadata format:
     
    178188    for to_country_year_votes in to_country_year_voting_groups:
    179189       
    180         fileset = fileset_voting_for_esc_country_in_year(to_country_year_votes)
     190        fileset = fileset_voting_for_esc_country_in_year(to_country_year_votes,countrylabel_to_uri_mapping)
    181191        directory_metadata.append(fileset)
    182192
     
    229239    if (json_output_filename == None):
    230240        json_output_filename = os.path.splitext(excel_input_filename)[0]+'.json'
    231        
     241
     242    countrylabel_to_uri_mapping = csvutil.load_and_tidy_csv("dbpedia--european-countries.csv")
     243   
    232244    worksheet = xlsxutil.load_xslx_sheet(excel_input_filename,sheetname)
    233245
     
    261273    print()
    262274    print("Generating Greenstone JSON to-country voting metadata received by:")
    263     greenstone_metadata_json = gs_directory_metadata(to_country_year_voting_groups)
     275    greenstone_metadata_json = gs_directory_metadata(to_country_year_voting_groups,countrylabel_to_uri_mapping)
    264276   
    265277    print("Saving output as: " + json_output_filename)   
Note: See TracChangeset for help on using the changeset viewer.