Demo entry 6657814

weight

   

Submitted by flagmt on Nov 04, 2017 at 19:58
Language: Python 3. Code size: 997 Bytes.

# calculate and return a weight value for each candidate
def get_weight(geo_type, query):
    # wiki_data returns the highest wordcount from among the Wikipedia pages returned via the API search on query
    num_words = wiki_data(query)
    # add 5 to insure no zero values
    num_words = num_words + 5
    # select multiplier, w, depending on feature type
    if geo_type == 'Stream' or geo_type == 'Valley':
        w = 9.0
    elif geo_type == 'Post Office' or geo_type == 'Populated Place' or geo_type == 'Airport' or geo_type == 'Civil':
        w = 12.0
    elif geo_type == 'Rapids':
        w = 20.0
        # rapid names tend to have high ambiguity, so help out a bit with extra 'tuning'
        num_words = num_words + 2500
    else:
        # no other matches suggest little chance this candidate is the one we want
        w = 0.25
    # calculate and return weight as the log of the product of w and num_words
    weight = log((w*num_words), 10)
    return weight

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).